| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
* |
|---|
| 5 |
* Full implementation except for the mt.getTrackbackPings call |
|---|
| 6 |
*/ |
|---|
| 7 |
|
|---|
| 8 |
function mt_getRecenPostTitles($params, $method) |
|---|
| 9 |
{ |
|---|
| 10 |
|
|---|
| 11 |
$nr_params = (int) 4; |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
if (count($params) != $nr_params) |
|---|
| 15 |
{ |
|---|
| 16 |
|
|---|
| 17 |
return new IXR_Error(-32602, "Invalid method parameters"); |
|---|
| 18 |
} |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
$blogid = $params[0]; |
|---|
| 23 |
$username = $params[1]; |
|---|
| 24 |
$password = $params[2]; |
|---|
| 25 |
$numberOfPosts = $params[3]; |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
$auth = run('rpc:auth', array("username" => $username, |
|---|
| 29 |
"password" => $password)); |
|---|
| 30 |
|
|---|
| 31 |
if ($auth['status'] == true) |
|---|
| 32 |
{ |
|---|
| 33 |
|
|---|
| 34 |
$weblog = run('weblogs:instance', array('user_id' => $username, |
|---|
| 35 |
'blog_id' => $blogid)); |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
if ($numberOfPosts >= 1) |
|---|
| 39 |
{ |
|---|
| 40 |
|
|---|
| 41 |
$posts = array_slice($weblog->getPosts(), 0, $numberOfPosts); |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
$result = array(); |
|---|
| 45 |
|
|---|
| 46 |
if (sizeof($posts) > 0) |
|---|
| 47 |
{ |
|---|
| 48 |
foreach($posts as $post_id) |
|---|
| 49 |
{ |
|---|
| 50 |
|
|---|
| 51 |
$post = $weblog->getPost($post_id); |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
$entry = array(); |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
$entry['dateCreated'] = new IXR_Date($post->getPosted()); |
|---|
| 58 |
$entry['userid'] = (int) $weblog->getIdent(); |
|---|
| 59 |
$entry['postid'] = (int) $post->getIdent(); |
|---|
| 60 |
$entry['title'] = $post->getTitle(); |
|---|
| 61 |
} |
|---|
| 62 |
return $entry; |
|---|
| 63 |
} |
|---|
| 64 |
else |
|---|
| 65 |
{ |
|---|
| 66 |
|
|---|
| 67 |
return new IXR_Error(806, "No Such Item"); |
|---|
| 68 |
} |
|---|
| 69 |
} |
|---|
| 70 |
else |
|---|
| 71 |
{ |
|---|
| 72 |
|
|---|
| 73 |
return new IXR_Error(805, "Amount parameter must be 1 or more"); |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
else |
|---|
| 77 |
{ |
|---|
| 78 |
|
|---|
| 79 |
return new IXR_Error($auth['code'], $auth['message']); |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
function mt_getCategoryList($params, $method) |
|---|
| 85 |
{ |
|---|
| 86 |
|
|---|
| 87 |
$nr_params = 3; |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
if (count($params) != $nr_params) |
|---|
| 91 |
{ |
|---|
| 92 |
|
|---|
| 93 |
return new IXR_Error(-32602, "Invalid method parameters"); |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
$username = $params[1]; |
|---|
| 98 |
$password = $params[2]; |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
$auth = run('rpc:auth', array("username" => $username, |
|---|
| 102 |
"password" => $password)); |
|---|
| 103 |
|
|---|
| 104 |
$cats = array(); |
|---|
| 105 |
|
|---|
| 106 |
if ($auth['status'] == true) |
|---|
| 107 |
{ |
|---|
| 108 |
|
|---|
| 109 |
$results = array(); |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
* Some clients _need_ the categories so just provide them with a default one. |
|---|
| 113 |
*/ |
|---|
| 114 |
|
|---|
| 115 |
$results['categoryId'] = '999'; |
|---|
| 116 |
$results['categoryName'] = 'Default category'; |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
$cats[] = $results; |
|---|
| 120 |
|
|---|
| 121 |
return $cats; |
|---|
| 122 |
} |
|---|
| 123 |
else |
|---|
| 124 |
{ |
|---|
| 125 |
|
|---|
| 126 |
return new IXR_Error($auth['code'], $auth['message']); |
|---|
| 127 |
} |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
* Unfortunately elgg doesn't do categories, so think of something else |
|---|
| 132 |
*/ |
|---|
| 133 |
function mt_getPostCategories($params, $method) |
|---|
| 134 |
{ |
|---|
| 135 |
|
|---|
| 136 |
$nr_params = 3; |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
if (count($params) != $nr_params) |
|---|
| 140 |
{ |
|---|
| 141 |
|
|---|
| 142 |
return new IXR_Error(-32602, "Invalid method parameters"); |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
$postId = (int) $params[0]; |
|---|
| 147 |
$username = $params[1]; |
|---|
| 148 |
$password = $params[2]; |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
$auth = run('rpc:auth', array("username" => $username, |
|---|
| 153 |
"password" => $password)); |
|---|
| 154 |
|
|---|
| 155 |
if ($auth['status'] == true) |
|---|
| 156 |
{ |
|---|
| 157 |
|
|---|
| 158 |
$results = array(); |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
* Som clients _need_ the categories so just provide them with a default one. |
|---|
| 162 |
*/ |
|---|
| 163 |
|
|---|
| 164 |
$results['categoryId'] = '999'; |
|---|
| 165 |
$results['categoryName'] = 'Default category'; |
|---|
| 166 |
|
|---|
| 167 |
return $results; |
|---|
| 168 |
} |
|---|
| 169 |
else |
|---|
| 170 |
{ |
|---|
| 171 |
|
|---|
| 172 |
return new IXR_Error($auth['code'], $auth['message']); |
|---|
| 173 |
} |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
* think of something else |
|---|
| 178 |
*/ |
|---|
| 179 |
function mt_setPostCategories($params, $method) |
|---|
| 180 |
{ |
|---|
| 181 |
|
|---|
| 182 |
$nr_params = 4; |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
if (count($params) != $nr_params) |
|---|
| 186 |
{ |
|---|
| 187 |
|
|---|
| 188 |
return new IXR_Error(-32602, "Invalid method parameters"); |
|---|
| 189 |
} |
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
$postId = $params[0]; |
|---|
| 193 |
$username = $params[1]; |
|---|
| 194 |
$password = $params[2]; |
|---|
| 195 |
$categories = $params[3]; |
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
$auth = run('rpc:auth', array("username" => $username, |
|---|
| 199 |
"password" => $password)); |
|---|
| 200 |
|
|---|
| 201 |
if ($auth['status'] == true) |
|---|
| 202 |
{ |
|---|
| 203 |
|
|---|
| 204 |
$tagIds = array(); |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
foreach($categories as $value) |
|---|
| 208 |
{ |
|---|
| 209 |
|
|---|
| 210 |
// (string) $value['categoryId'] |
|---|
| 211 |
// (boolean)$value['isPrimary'] |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
return true; |
|---|
| 216 |
} |
|---|
| 217 |
else |
|---|
| 218 |
{ |
|---|
| 219 |
|
|---|
| 220 |
return new IXR_Error($auth['code'], $auth['message']); |
|---|
| 221 |
} |
|---|
| 222 |
} |
|---|
| 223 |
|
|---|
| 224 |
function mt_supportedMethods() |
|---|
| 225 |
{ |
|---|
| 226 |
|
|---|
| 227 |
// on the library loading order. It will do for now. |
|---|
| 228 |
// Refactor to use the introsppection API |
|---|
| 229 |
|
|---|
| 230 |
$result = array(); |
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
foreach($GLOBALS['handlers'] as $key => $value) |
|---|
| 234 |
{ |
|---|
| 235 |
$result[] = $key; |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
return $result; |
|---|
| 239 |
} |
|---|
| 240 |
|
|---|
| 241 |
function mt_supportedTextFilters($params, $method) |
|---|
| 242 |
{ |
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
$result = array(); |
|---|
| 246 |
|
|---|
| 247 |
return $result; |
|---|
| 248 |
} |
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
function mt_publishPost($params, $method) |
|---|
| 252 |
{ |
|---|
| 253 |
|
|---|
| 254 |
$nr_params = 3; |
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
if ($params->getNumParams() != $nr_params) |
|---|
| 258 |
{ |
|---|
| 259 |
|
|---|
| 260 |
return new IXR_Error(-32602, "Invalid method parameters"); |
|---|
| 261 |
} |
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
$postId = $params[0]; |
|---|
| 265 |
$username = $params[1]; |
|---|
| 266 |
$password = $params[2]; |
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
$auth = run('rpc:auth', array("username" => $username, |
|---|
| 271 |
"password" => $password)); |
|---|
| 272 |
|
|---|
| 273 |
if ($auth['status'] == true) |
|---|
| 274 |
{ |
|---|
| 275 |
|
|---|
| 276 |
$access = "PUBLISH"; |
|---|
| 277 |
|
|---|
| 278 |
$post = run('posts:instance', array('id' => $postId)); |
|---|
| 279 |
|
|---|
| 280 |
$post->setAccess($access); |
|---|
| 281 |
|
|---|
| 282 |
if ($post->save() == true) |
|---|
| 283 |
{ |
|---|
| 284 |
return true; |
|---|
| 285 |
} |
|---|
| 286 |
else |
|---|
| 287 |
{ |
|---|
| 288 |
|
|---|
| 289 |
return new IXR_Error(-32500, "Unable to publish post"); |
|---|
| 290 |
} |
|---|
| 291 |
|
|---|
| 292 |
} |
|---|
| 293 |
else |
|---|
| 294 |
{ |
|---|
| 295 |
|
|---|
| 296 |
return new IXR_Error($auth['code'], $auth['message']); |
|---|
| 297 |
} |
|---|
| 298 |
} |
|---|
| 299 |
?> |
|---|
| 300 |
|
|---|