| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
* Weblog class |
|---|
| 5 |
* |
|---|
| 6 |
* A class for representing an Elgg weblog. |
|---|
| 7 |
* |
|---|
| 8 |
* @author Misja Hoebe <misja@efobia.nl> |
|---|
| 9 |
* @version 0.4 |
|---|
| 10 |
* @copyright 2005, Misja Hoebe/Elgg project, GPL |
|---|
| 11 |
* @package RPC |
|---|
| 12 |
*/ |
|---|
| 13 |
Class Weblog extends ElggObject |
|---|
| 14 |
{ |
|---|
| 15 |
var $title; |
|---|
| 16 |
var $posts; |
|---|
| 17 |
|
|---|
| 18 |
var $blog_name; |
|---|
| 19 |
var $blog_username; |
|---|
| 20 |
var $owner; |
|---|
| 21 |
|
|---|
| 22 |
var $user_id; |
|---|
| 23 |
var $user_name; |
|---|
| 24 |
var $user_username; |
|---|
| 25 |
|
|---|
| 26 |
var $type = 'weblog'; |
|---|
| 27 |
var $community; |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
* Weblog class constructor |
|---|
| 31 |
* |
|---|
| 32 |
* <p>Will set all weblog properties, if the provided weblog id exist |
|---|
| 33 |
* (which effectively will be a user id, regardless if one is dealing |
|---|
| 34 |
* with a person or a community - for Elgg both are users).</p> |
|---|
| 35 |
* |
|---|
| 36 |
* @param int $user_id The user id. |
|---|
| 37 |
* @param int $blog_id The weblog id. |
|---|
| 38 |
*/ |
|---|
| 39 |
function Weblog($user_id, $blog_id) |
|---|
| 40 |
{ |
|---|
| 41 |
$this->community = false; |
|---|
| 42 |
|
|---|
| 43 |
// username/id conversions |
|---|
| 44 |
if (is_numeric($user_id)) |
|---|
| 45 |
{ |
|---|
| 46 |
$this->user_id = $user_id; |
|---|
| 47 |
} |
|---|
| 48 |
elseif (is_string($user_id)) |
|---|
| 49 |
{ |
|---|
| 50 |
$this->user_id = user_info_username('ident',$user_id); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
if (is_numeric($blog_id)) |
|---|
| 54 |
{ |
|---|
| 55 |
$this->ident = $blog_id; |
|---|
| 56 |
} |
|---|
| 57 |
elseif (is_string($blog_id)) |
|---|
| 58 |
{ |
|---|
| 59 |
$this->ident = user_info_username('ident',$blog_id); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
if (user_type($this->ident) == "person") |
|---|
| 64 |
{ |
|---|
| 65 |
if ($result = get_record('users','ident',$this->user_id)) { |
|---|
| 66 |
$this->user_name = $result->name; |
|---|
| 67 |
$this->user_username = $result->username; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
$posts = get_records_select('weblog_posts',"owner = ? AND weblog = ?",array($this->user_id,$this->user_id),'posted DESC'); |
|---|
| 71 |
|
|---|
| 72 |
$this->blog_name = $this->user_name; |
|---|
| 73 |
$this->blog_username = $this->user_username; |
|---|
| 74 |
$this->owner = $this->user_id; |
|---|
| 75 |
} |
|---|
| 76 |
else |
|---|
| 77 |
{ |
|---|
| 78 |
|
|---|
| 79 |
$this->community = true; |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
$this->owner = user_info('owner',$this->ident); |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
$sql_insert = ""; |
|---|
| 86 |
|
|---|
| 87 |
if ($this->owner != $this->user_id) |
|---|
| 88 |
{ |
|---|
| 89 |
$sql_insert = " and owner = $this->user_id "; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
if ($result = get_record('users','ident',$this->ident)) { |
|---|
| 93 |
$this->blog_name = $result->name; |
|---|
| 94 |
$this->blog_username = $result->username; |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
$posts = get_records_select('weblog_posts',"weblog = $this->ident $sql_insert",null,'posted DESC'); |
|---|
| 98 |
|
|---|
| 99 |
$user = run('users:instance', array('user_id' => $this->user_id)); |
|---|
| 100 |
|
|---|
| 101 |
$this->user_name = $user->getName(); |
|---|
| 102 |
$this->user_username = $user->getUserName(); |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
$this->posts = array(); |
|---|
| 106 |
if (is_array($posts) && sizeof($posts) > 0) |
|---|
| 107 |
{ |
|---|
| 108 |
foreach ($posts as $post) |
|---|
| 109 |
{ |
|---|
| 110 |
$this->posts[] = $post->ident; |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
else |
|---|
| 114 |
{ |
|---|
| 115 |
} |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
* Get weblog posts |
|---|
| 120 |
* |
|---|
| 121 |
* @return array An array with post id's. |
|---|
| 122 |
*/ |
|---|
| 123 |
function getPosts() |
|---|
| 124 |
{ |
|---|
| 125 |
return $this->posts; |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
* Return a post object. |
|---|
| 130 |
* |
|---|
| 131 |
* Utility function. This will return a post object for the given post id. |
|---|
| 132 |
* |
|---|
| 133 |
* @param int $post_id The post id. |
|---|
| 134 |
* @return Post A Post object. |
|---|
| 135 |
*/ |
|---|
| 136 |
function getPost($post_id) |
|---|
| 137 |
{ |
|---|
| 138 |
return run('posts:instance', array("id" => $post_id)); |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
* Return the weblog owner id |
|---|
| 143 |
* |
|---|
| 144 |
* @return int The weblog owner id. |
|---|
| 145 |
*/ |
|---|
| 146 |
function getOwner() |
|---|
| 147 |
{ |
|---|
| 148 |
return $this->owner; |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
* Check if the user is the weblog owner |
|---|
| 153 |
* |
|---|
| 154 |
* @return boolean |
|---|
| 155 |
*/ |
|---|
| 156 |
function isOwner() |
|---|
| 157 |
{ |
|---|
| 158 |
if ($this->owner == $this->user_id) |
|---|
| 159 |
{ |
|---|
| 160 |
return true; |
|---|
| 161 |
} |
|---|
| 162 |
else |
|---|
| 163 |
{ |
|---|
| 164 |
return false; |
|---|
| 165 |
} |
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
* Get the weblog title |
|---|
| 170 |
* |
|---|
| 171 |
* @return string The weblog title. |
|---|
| 172 |
*/ |
|---|
| 173 |
function getTitle() |
|---|
| 174 |
{ |
|---|
| 175 |
if ($this->community == true) |
|---|
| 176 |
{ |
|---|
| 177 |
return $this->user_name . " @ " . $this->blog_name; |
|---|
| 178 |
} |
|---|
| 179 |
else |
|---|
| 180 |
{ |
|---|
| 181 |
return $this->user_name . " :: Weblog"; |
|---|
| 182 |
} |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
* Get the weblog name |
|---|
| 187 |
* |
|---|
| 188 |
* Will be the weblog's owner's name. |
|---|
| 189 |
* |
|---|
| 190 |
* @return string The weblog owner name. |
|---|
| 191 |
*/ |
|---|
| 192 |
function getName() |
|---|
| 193 |
{ |
|---|
| 194 |
return $this->blog_name; |
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
* Get the weblog URL |
|---|
| 199 |
* |
|---|
| 200 |
* @return string The weblog URL. |
|---|
| 201 |
*/ |
|---|
| 202 |
function getUrl() |
|---|
| 203 |
{ |
|---|
| 204 |
return url . $this->blog_username . "/weblog/"; |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
* Get the Atom feed URL |
|---|
| 209 |
* |
|---|
| 210 |
* @return string The servce.feed URL. |
|---|
| 211 |
*/ |
|---|
| 212 |
function getAtomFeedUrl() |
|---|
| 213 |
{ |
|---|
| 214 |
return url . "atom/" . $this->ident; |
|---|
| 215 |
} |
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
* Get the Atom post URL |
|---|
| 219 |
* |
|---|
| 220 |
* @return string The service.post URL. |
|---|
| 221 |
*/ |
|---|
| 222 |
function getAtomPostUrl() |
|---|
| 223 |
{ |
|---|
| 224 |
return url . "atom/" . $this->ident; |
|---|
| 225 |
} |
|---|
| 226 |
} |
|---|
| 227 |
?> |
|---|
| 228 |
|
|---|