[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
[3730] | 12 | if (!defined('DC_RC_PATH')) {return;} |
---|
[0] | 13 | |
---|
| 14 | class dcXmlRpc extends xmlrpcIntrospectionServer |
---|
| 15 | { |
---|
[3730] | 16 | public $core; |
---|
| 17 | private $blog_id; |
---|
| 18 | private $blog_loaded = false; |
---|
| 19 | private $debug = false; |
---|
| 20 | private $debug_file = '/tmp/dotclear-xmlrpc.log'; |
---|
| 21 | private $trace_args = true; |
---|
| 22 | private $trace_response = true; |
---|
[2566] | 23 | |
---|
[3730] | 24 | public function __construct($core, $blog_id) |
---|
| 25 | { |
---|
| 26 | parent::__construct(); |
---|
[2566] | 27 | |
---|
[3730] | 28 | $this->core = &$core; |
---|
| 29 | $this->blog_id = $blog_id; |
---|
[2566] | 30 | |
---|
[3730] | 31 | # Blogger methods |
---|
| 32 | $this->addCallback('blogger.newPost', array($this, 'blogger_newPost'), |
---|
| 33 | array('string', 'string', 'string', 'string', 'string', 'string', 'integer'), |
---|
| 34 | 'New post'); |
---|
[2566] | 35 | |
---|
[3730] | 36 | $this->addCallback('blogger.editPost', array($this, 'blogger_editPost'), |
---|
| 37 | array('boolean', 'string', 'string', 'string', 'string', 'string', 'integer'), |
---|
| 38 | 'Edit a post'); |
---|
[2566] | 39 | |
---|
[3730] | 40 | $this->addCallback('blogger.getPost', array($this, 'blogger_getPost'), |
---|
| 41 | array('struct', 'string', 'integer', 'string', 'string'), |
---|
| 42 | 'Return a posts by ID'); |
---|
[2566] | 43 | |
---|
[3730] | 44 | $this->addCallback('blogger.deletePost', array($this, 'blogger_deletePost'), |
---|
| 45 | array('string', 'string', 'string', 'string', 'string', 'integer'), |
---|
| 46 | 'Delete a post'); |
---|
[2566] | 47 | |
---|
[3730] | 48 | $this->addCallback('blogger.getRecentPosts', array($this, 'blogger_getRecentPosts'), |
---|
| 49 | array('array', 'string', 'string', 'string', 'string', 'integer'), |
---|
| 50 | 'Return a list of recent posts'); |
---|
[2566] | 51 | |
---|
[3730] | 52 | $this->addCallback('blogger.getUsersBlogs', array($this, 'blogger_getUserBlogs'), |
---|
| 53 | array('struct', 'string', 'string', 'string'), |
---|
| 54 | "Return user's blog"); |
---|
[2566] | 55 | |
---|
[3730] | 56 | $this->addCallback('blogger.getUserInfo', array($this, 'blogger_getUserInfo'), |
---|
| 57 | array('struct', 'string', 'string', 'string'), |
---|
| 58 | 'Return User Info'); |
---|
[2566] | 59 | |
---|
[3730] | 60 | # Metaweblog methods |
---|
| 61 | $this->addCallback('metaWeblog.newPost', array($this, 'mw_newPost'), |
---|
| 62 | array('string', 'string', 'string', 'string', 'struct', 'boolean'), |
---|
| 63 | 'Creates a new post, and optionnaly publishes it.'); |
---|
[2566] | 64 | |
---|
[3730] | 65 | $this->addCallback('metaWeblog.editPost', array($this, 'mw_editPost'), |
---|
| 66 | array('boolean', 'string', 'string', 'string', 'struct', 'boolean'), |
---|
| 67 | 'Updates information about an existing entry'); |
---|
[2566] | 68 | |
---|
[3730] | 69 | $this->addCallback('metaWeblog.getPost', array($this, 'mw_getPost'), |
---|
| 70 | array('struct', 'string', 'string', 'string'), |
---|
| 71 | 'Returns information about a specific post'); |
---|
[2566] | 72 | |
---|
[3730] | 73 | $this->addCallback('metaWeblog.getRecentPosts', array($this, 'mw_getRecentPosts'), |
---|
| 74 | array('array', 'string', 'string', 'string', 'integer'), |
---|
| 75 | 'List of most recent posts in the system'); |
---|
[2566] | 76 | |
---|
[3730] | 77 | $this->addCallback('metaWeblog.getCategories', array($this, 'mw_getCategories'), |
---|
| 78 | array('array', 'string', 'string', 'string'), |
---|
| 79 | 'List of all categories defined in the weblog'); |
---|
[2566] | 80 | |
---|
[3730] | 81 | $this->addCallback('metaWeblog.newMediaObject', array($this, 'mw_newMediaObject'), |
---|
| 82 | array('struct', 'string', 'string', 'string', 'struct'), |
---|
| 83 | 'Upload a file on the web server'); |
---|
[2566] | 84 | |
---|
[3730] | 85 | # MovableType methods |
---|
| 86 | $this->addCallback('mt.getRecentPostTitles', array($this, 'mt_getRecentPostTitles'), |
---|
| 87 | array('array', 'string', 'string', 'string', 'integer'), |
---|
| 88 | 'List of most recent posts in the system'); |
---|
[2566] | 89 | |
---|
[3730] | 90 | $this->addCallback('mt.getCategoryList', array($this, 'mt_getCategoryList'), |
---|
| 91 | array('array', 'string', 'string', 'string'), |
---|
| 92 | 'List of all categories defined in the weblog'); |
---|
[2566] | 93 | |
---|
[3730] | 94 | $this->addCallback('mt.getPostCategories', array($this, 'mt_getPostCategories'), |
---|
| 95 | array('array', 'string', 'string', 'string'), |
---|
| 96 | 'List of all categories to which the post is assigned'); |
---|
[2566] | 97 | |
---|
[3730] | 98 | $this->addCallback('mt.setPostCategories', array($this, 'mt_setPostCategories'), |
---|
| 99 | array('boolean', 'string', 'string', 'string', 'array'), |
---|
| 100 | 'Sets the categories for a post'); |
---|
[2566] | 101 | |
---|
[3730] | 102 | $this->addCallback('mt.publishPost', array($this, 'mt_publishPost'), |
---|
| 103 | array('boolean', 'string', 'string', 'string'), |
---|
| 104 | 'Retrieve pings list for a post'); |
---|
[2566] | 105 | |
---|
[3730] | 106 | $this->addCallback('mt.supportedMethods', array($this, 'listMethods'), |
---|
| 107 | array(), 'Retrieve information about the XML-RPC methods supported by the server.'); |
---|
[2566] | 108 | |
---|
[3730] | 109 | $this->addCallback('mt.supportedTextFilters', array($this, 'mt_supportedTextFilters'), |
---|
| 110 | array(), 'Retrieve information about supported text filters.'); |
---|
[2566] | 111 | |
---|
[3730] | 112 | # WordPress methods |
---|
| 113 | $this->addCallback('wp.getUsersBlogs', array($this, 'wp_getUsersBlogs'), |
---|
| 114 | array('array', 'string', 'string'), |
---|
| 115 | 'Retrieve the blogs of the user.'); |
---|
[2566] | 116 | |
---|
[3730] | 117 | $this->addCallback('wp.getPage', array($this, 'wp_getPage'), |
---|
| 118 | array('struct', 'integer', 'integer', 'string', 'string'), |
---|
| 119 | 'Get the page identified by the page ID.'); |
---|
[2566] | 120 | |
---|
[3730] | 121 | $this->addCallback('wp.getPages', array($this, 'wp_getPages'), |
---|
| 122 | array('array', 'integer', 'string', 'string', 'integer'), |
---|
| 123 | 'Get an array of all the pages on a blog.'); |
---|
[2566] | 124 | |
---|
[3730] | 125 | $this->addCallback('wp.newPage', array($this, 'wp_newPage'), |
---|
| 126 | array('integer', 'integer', 'string', 'string', 'struct', 'boolean'), |
---|
| 127 | 'Create a new page.'); |
---|
[2566] | 128 | |
---|
[3730] | 129 | $this->addCallback('wp.deletePage', array($this, 'wp_deletePage'), |
---|
| 130 | array('boolean', 'integer', 'string', 'string', 'integer'), |
---|
| 131 | 'Removes a page from the blog.'); |
---|
[2566] | 132 | |
---|
[3730] | 133 | $this->addCallback('wp.editPage', array($this, 'wp_editPage'), |
---|
| 134 | array('boolean', 'integer', 'integer', 'string', 'string', 'struct', 'boolean'), |
---|
| 135 | 'Make changes to a blog page.'); |
---|
[2566] | 136 | |
---|
[3730] | 137 | $this->addCallback('wp.getPageList', array($this, 'wp_getPageList'), |
---|
| 138 | array('array', 'integer', 'string', 'string'), |
---|
| 139 | 'Get an array of all the pages on a blog. Just the minimum details, lighter than wp.getPages.'); |
---|
[2566] | 140 | |
---|
[3730] | 141 | $this->addCallback('wp.getAuthors', array($this, 'wp_getAuthors'), |
---|
| 142 | array('array', 'integer', 'string', 'string'), |
---|
| 143 | 'Get an array of users for the blog.'); |
---|
[2566] | 144 | |
---|
[3730] | 145 | $this->addCallback('wp.getCategories', array($this, 'wp_getCategories'), |
---|
| 146 | array('array', 'integer', 'string', 'string'), |
---|
| 147 | 'Get an array of available categories on a blog.'); |
---|
[2566] | 148 | |
---|
[3730] | 149 | $this->addCallback('wp.getTags', array($this, 'wp_getTags'), |
---|
| 150 | array('array', 'integer', 'string', 'string'), |
---|
| 151 | 'Get list of all tags for the blog.'); |
---|
[2566] | 152 | |
---|
[3730] | 153 | $this->addCallback('wp.newCategory', array($this, 'wp_newCategory'), |
---|
| 154 | array('integer', 'integer', 'string', 'string', 'struct'), |
---|
| 155 | 'Create a new category.'); |
---|
[2566] | 156 | |
---|
[3730] | 157 | $this->addCallback('wp.deleteCategory', array($this, 'wp_deleteCategory'), |
---|
| 158 | array('boolean', 'integer', 'string', 'string', 'integer'), |
---|
| 159 | 'Delete a category with a given ID.'); |
---|
[2566] | 160 | |
---|
[3730] | 161 | $this->addCallback('wp.suggestCategories', array($this, 'wp_suggestCategories'), |
---|
| 162 | array('array', 'integer', 'string', 'string', 'string', 'integer'), |
---|
| 163 | 'Get an array of categories that start with a given string.'); |
---|
[2566] | 164 | |
---|
[3730] | 165 | $this->addCallback('wp.uploadFile', array($this, 'wp_uploadFile'), |
---|
| 166 | array('struct', 'integer', 'string', 'string', 'struct'), |
---|
| 167 | 'Upload a file'); |
---|
[2566] | 168 | |
---|
[3730] | 169 | $this->addCallback('wp.getPostStatusList', array($this, 'wp_getPostStatusList'), |
---|
| 170 | array('array', 'integer', 'string', 'string'), |
---|
| 171 | 'Retrieve all of the post statuses.'); |
---|
[2566] | 172 | |
---|
[3730] | 173 | $this->addCallback('wp.getPageStatusList', array($this, 'wp_getPageStatusList'), |
---|
| 174 | array('array', 'integer', 'string', 'string'), |
---|
| 175 | 'Retrieve all of the pages statuses.'); |
---|
[2566] | 176 | |
---|
[3730] | 177 | $this->addCallback('wp.getPageTemplates', array($this, 'wp_getPageTemplates'), |
---|
| 178 | array('struct', 'integer', 'string', 'string'), |
---|
| 179 | 'Retrieve page templates.'); |
---|
[2566] | 180 | |
---|
[3730] | 181 | $this->addCallback('wp.getOptions', array($this, 'wp_getOptions'), |
---|
| 182 | array('struct', 'integer', 'string', 'string', 'array'), |
---|
| 183 | 'Retrieve blog options'); |
---|
[2566] | 184 | |
---|
[3730] | 185 | $this->addCallback('wp.setOptions', array($this, 'wp_setOptions'), |
---|
| 186 | array('struct', 'integer', 'string', 'string', 'struct'), |
---|
| 187 | 'Update blog options'); |
---|
[2566] | 188 | |
---|
[3730] | 189 | $this->addCallback('wp.getComment', array($this, 'wp_getComment'), |
---|
| 190 | array('struct', 'integer', 'string', 'string', 'integer'), |
---|
| 191 | "Gets a comment, given it's comment ID."); |
---|
[2566] | 192 | |
---|
[3730] | 193 | $this->addCallback('wp.getCommentCount', array($this, 'wp_getCommentCount'), |
---|
| 194 | array('array', 'integer', 'string', 'string', 'integer'), |
---|
| 195 | 'Retrieve comment count.'); |
---|
[2566] | 196 | |
---|
[3730] | 197 | $this->addCallback('wp.getComments', array($this, 'wp_getComments'), |
---|
| 198 | array('array', 'integer', 'string', 'string', 'struct'), |
---|
| 199 | 'Gets a set of comments for a given post.'); |
---|
[2566] | 200 | |
---|
[3730] | 201 | $this->addCallback('wp.deleteComment', array($this, 'wp_deleteComment'), |
---|
| 202 | array('boolean', 'integer', 'string', 'string', 'integer'), |
---|
| 203 | 'Delete a comment with given ID.'); |
---|
[2566] | 204 | |
---|
[3730] | 205 | $this->addCallback('wp.editComment', array($this, 'wp_editComment'), |
---|
| 206 | array('boolean', 'integer', 'string', 'string', 'integer', 'struct'), |
---|
| 207 | 'Edit a comment with given ID.'); |
---|
[2566] | 208 | |
---|
[3730] | 209 | $this->addCallback('wp.newComment', array($this, 'wp_newComment'), |
---|
| 210 | array('integer', 'integer', 'string', 'string', 'integer', 'struct'), |
---|
| 211 | 'Create a new comment for a given post ID.'); |
---|
[2566] | 212 | |
---|
[3730] | 213 | $this->addCallback('wp.getCommentStatusList', array($this, 'wp_getCommentStatusList'), |
---|
| 214 | array('array', 'integer', 'string', 'string'), |
---|
| 215 | 'Retrieve all of the comment statuses.'); |
---|
[2566] | 216 | |
---|
[3730] | 217 | # Pingback support |
---|
| 218 | $this->addCallback('pingback.ping', array($this, 'pingback_ping'), |
---|
| 219 | array('string', 'string', 'string'), |
---|
| 220 | 'Notify a link to a post.'); |
---|
| 221 | } |
---|
[2566] | 222 | |
---|
[3730] | 223 | public function serve($data = false, $encoding = 'UTF-8') |
---|
| 224 | { |
---|
| 225 | parent::serve(false, $encoding); |
---|
| 226 | } |
---|
[2566] | 227 | |
---|
[3730] | 228 | public function call($methodname, $args) |
---|
| 229 | { |
---|
| 230 | try { |
---|
| 231 | $rsp = @parent::call($methodname, $args); |
---|
| 232 | $this->debugTrace($methodname, $args, $rsp); |
---|
| 233 | return $rsp; |
---|
| 234 | } catch (Exception $e) { |
---|
| 235 | $this->debugTrace($methodname, $args, array($e->getMessage(), $e->getCode())); |
---|
| 236 | throw $e; |
---|
| 237 | } |
---|
| 238 | } |
---|
[2566] | 239 | |
---|
[3730] | 240 | private function debugTrace($methodname, $args, $rsp) |
---|
| 241 | { |
---|
| 242 | if (!$this->debug) { |
---|
| 243 | return; |
---|
| 244 | } |
---|
[2566] | 245 | |
---|
[3730] | 246 | if (($fp = @fopen($this->debug_file, 'a')) !== false) { |
---|
| 247 | fwrite($fp, '[' . date('r') . ']' . ' ' . $methodname); |
---|
[2566] | 248 | |
---|
[3730] | 249 | if ($this->trace_args) { |
---|
| 250 | fwrite($fp, "\n- args ---\n" . var_export($args, 1)); |
---|
| 251 | } |
---|
[2566] | 252 | |
---|
[3730] | 253 | if ($this->trace_response) { |
---|
| 254 | fwrite($fp, "\n- response ---\n" . var_export($rsp, 1)); |
---|
| 255 | } |
---|
| 256 | fwrite($fp, "\n"); |
---|
| 257 | fclose($fp); |
---|
| 258 | } |
---|
| 259 | } |
---|
[2566] | 260 | |
---|
[3730] | 261 | /* Internal methods |
---|
| 262 | --------------------------------------------------- */ |
---|
| 263 | private function setUser($user_id, $pwd) |
---|
| 264 | { |
---|
| 265 | if (empty($pwd) || $this->core->auth->checkUser($user_id, $pwd) !== true) { |
---|
| 266 | throw new Exception('Login error'); |
---|
| 267 | } |
---|
[2566] | 268 | |
---|
[3730] | 269 | return true; |
---|
| 270 | } |
---|
[2566] | 271 | |
---|
[3730] | 272 | private function setBlog($bypass = false) |
---|
| 273 | { |
---|
| 274 | if (!$this->blog_id) { |
---|
| 275 | throw new Exception('No blog ID given.'); |
---|
| 276 | } |
---|
[2566] | 277 | |
---|
[3730] | 278 | if ($this->blog_loaded) { |
---|
| 279 | return true; |
---|
| 280 | } |
---|
[2566] | 281 | |
---|
[3730] | 282 | $this->core->setBlog($this->blog_id); |
---|
| 283 | $this->blog_loaded = true; |
---|
[2566] | 284 | |
---|
[3730] | 285 | if (!$this->core->blog->id) { |
---|
| 286 | $this->core->blog = null; |
---|
| 287 | throw new Exception('Blog does not exist.'); |
---|
| 288 | } |
---|
[2566] | 289 | |
---|
[3730] | 290 | if (!$bypass && |
---|
| 291 | (!$this->core->blog->settings->system->enable_xmlrpc || |
---|
| 292 | !$this->core->auth->check('usage,contentadmin', $this->core->blog->id))) { |
---|
| 293 | $this->core->blog = null; |
---|
| 294 | throw new Exception('Not enough permissions on this blog.'); |
---|
| 295 | } |
---|
[2566] | 296 | |
---|
[3730] | 297 | foreach ($this->core->plugins->getModules() as $id => $m) { |
---|
| 298 | $this->core->plugins->loadNsFile($id, 'xmlrpc'); |
---|
| 299 | } |
---|
[2566] | 300 | |
---|
[3730] | 301 | return true; |
---|
| 302 | } |
---|
[2566] | 303 | |
---|
[3730] | 304 | private function getPostRS($post_id, $user, $pwd, $post_type = 'post') |
---|
| 305 | { |
---|
| 306 | $this->setUser($user, $pwd); |
---|
| 307 | $this->setBlog(); |
---|
| 308 | $rs = $this->core->blog->getPosts(array( |
---|
| 309 | 'post_id' => (integer) $post_id, |
---|
| 310 | 'post_type' => $post_type |
---|
| 311 | )); |
---|
[2566] | 312 | |
---|
[3730] | 313 | if ($rs->isEmpty()) { |
---|
| 314 | throw new Exception('This entry does not exist'); |
---|
| 315 | } |
---|
[2566] | 316 | |
---|
[3730] | 317 | return $rs; |
---|
| 318 | } |
---|
[2566] | 319 | |
---|
[3730] | 320 | private function getCatID($cat_url) |
---|
| 321 | { |
---|
| 322 | $rs = $this->core->blog->getCategories(array('cat_url' => $cat_url)); |
---|
[2566] | 323 | |
---|
[3730] | 324 | return $rs->isEmpty() ? null : $rs->cat_id; |
---|
| 325 | } |
---|
[2566] | 326 | |
---|
[3730] | 327 | /* Generic methods |
---|
| 328 | --------------------------------------------------- */ |
---|
| 329 | private function newPost($blog_id, $user, $pwd, $content, $struct = array(), $publish = true) |
---|
| 330 | { |
---|
| 331 | $this->setUser($user, $pwd); |
---|
| 332 | $this->setBlog(); |
---|
[2566] | 333 | |
---|
[3730] | 334 | $title = !empty($struct['title']) ? $struct['title'] : ''; |
---|
| 335 | $excerpt = !empty($struct['mt_excerpt']) ? $struct['mt_excerpt'] : ''; |
---|
| 336 | $description = !empty($struct['description']) ? $struct['description'] : null; |
---|
| 337 | $dateCreated = !empty($struct['dateCreated']) ? $struct['dateCreated'] : null; |
---|
| 338 | $open_comment = isset($struct['mt_allow_comments']) ? $struct['mt_allow_comments'] : 1; |
---|
| 339 | $open_tb = isset($struct['mt_allow_pings']) ? $struct['mt_allow_pings'] : 1; |
---|
[2566] | 340 | |
---|
[3730] | 341 | if ($description !== null) { |
---|
| 342 | $content = $description; |
---|
| 343 | } |
---|
[2566] | 344 | |
---|
[3730] | 345 | if (!$title) { |
---|
| 346 | $title = text::cutString(html::clean($content), 25) . '...'; |
---|
| 347 | } |
---|
[2566] | 348 | |
---|
[3730] | 349 | $excerpt_xhtml = $this->core->callFormater('xhtml', $excerpt); |
---|
| 350 | $content_xhtml = $this->core->callFormater('xhtml', $content); |
---|
[2566] | 351 | |
---|
[3730] | 352 | if (empty($content)) { |
---|
| 353 | throw new Exception('Cannot create an empty entry'); |
---|
| 354 | } |
---|
[2566] | 355 | |
---|
[3730] | 356 | $cur = $this->core->con->openCursor($this->core->prefix . 'post'); |
---|
[2566] | 357 | |
---|
[3730] | 358 | $cur->user_id = $this->core->auth->userID(); |
---|
| 359 | $cur->post_lang = $this->core->auth->getInfo('user_lang'); |
---|
| 360 | $cur->post_title = trim($title); |
---|
| 361 | $cur->post_content = $content; |
---|
| 362 | $cur->post_excerpt = $excerpt; |
---|
| 363 | $cur->post_content_xhtml = $content_xhtml; |
---|
| 364 | $cur->post_excerpt_xhtml = $excerpt_xhtml; |
---|
| 365 | $cur->post_open_comment = (integer) ($open_comment == 1); |
---|
| 366 | $cur->post_open_tb = (integer) ($open_tb == 1); |
---|
| 367 | $cur->post_status = (integer) $publish; |
---|
| 368 | $cur->post_format = 'xhtml'; |
---|
[2566] | 369 | |
---|
[3730] | 370 | if ($dateCreated) { |
---|
| 371 | if ($dateCreated instanceof xmlrpcDate) { |
---|
| 372 | $cur->post_dt = date('Y-m-d H:i:00', $dateCreated->getTimestamp()); |
---|
| 373 | } elseif (is_string($dateCreated) && @strtotime($dateCreated)) { |
---|
| 374 | $cur->post_dt = date('Y-m-d H:i:00', strtotime($dateCreated)); |
---|
| 375 | } |
---|
| 376 | } |
---|
[2566] | 377 | |
---|
[3730] | 378 | # Categories in an array |
---|
| 379 | if (isset($struct['categories']) && is_array($struct['categories'])) { |
---|
| 380 | $categories = $struct['categories']; |
---|
| 381 | $cat_id = !empty($categories[0]) ? $categories[0] : null; |
---|
[2566] | 382 | |
---|
[3730] | 383 | $cur->cat_id = $this->getCatID($cat_id); |
---|
| 384 | } |
---|
[2566] | 385 | |
---|
[3730] | 386 | if (isset($struct['wp_slug'])) { |
---|
| 387 | $cur->post_url = $struct['wp_slug']; |
---|
| 388 | } |
---|
[2566] | 389 | |
---|
[3730] | 390 | if (isset($struct['wp_password'])) { |
---|
| 391 | $cur->post_password = $struct['wp_password']; |
---|
| 392 | } |
---|
[2566] | 393 | |
---|
[3730] | 394 | $cur->post_type = 'post'; |
---|
| 395 | if (!empty($struct['post_type'])) { |
---|
| 396 | $cur->post_type = $struct['post_type']; |
---|
| 397 | } |
---|
[2566] | 398 | |
---|
[3730] | 399 | if ($cur->post_type == 'post') { |
---|
| 400 | # --BEHAVIOR-- xmlrpcBeforeNewPost |
---|
| 401 | $this->core->callBehavior('xmlrpcBeforeNewPost', $this, $cur, $content, $struct, $publish); |
---|
[2566] | 402 | |
---|
[3730] | 403 | $post_id = $this->core->blog->addPost($cur); |
---|
[2566] | 404 | |
---|
[3730] | 405 | # --BEHAVIOR-- xmlrpcAfterNewPost |
---|
| 406 | $this->core->callBehavior('xmlrpcAfterNewPost', $this, $post_id, $cur, $content, $struct, $publish); |
---|
| 407 | } elseif ($cur->post_type == 'page') { |
---|
| 408 | if (isset($struct['wp_page_order'])) { |
---|
| 409 | $cur->post_position = (integer) $struct['wp_page_order']; |
---|
| 410 | } |
---|
[2566] | 411 | |
---|
[3730] | 412 | $this->core->blog->settings->system->post_url_format = '{t}'; |
---|
[2566] | 413 | |
---|
[3730] | 414 | $post_id = $this->core->blog->addPost($cur); |
---|
| 415 | } else { |
---|
| 416 | throw new Exception('Invalid post type', 401); |
---|
| 417 | } |
---|
[2566] | 418 | |
---|
[3730] | 419 | return (string) $post_id; |
---|
| 420 | } |
---|
[2566] | 421 | |
---|
[3730] | 422 | private function editPost($post_id, $user, $pwd, $content, $struct = array(), $publish = true) |
---|
| 423 | { |
---|
| 424 | $post_id = (integer) $post_id; |
---|
[2566] | 425 | |
---|
[3730] | 426 | $post_type = 'post'; |
---|
| 427 | if (!empty($struct['post_type'])) { |
---|
| 428 | $post_type = $struct['post_type']; |
---|
| 429 | } |
---|
[2566] | 430 | |
---|
[3730] | 431 | $post = $this->getPostRS($post_id, $user, $pwd, $post_type); |
---|
[2566] | 432 | |
---|
[3730] | 433 | $title = (!empty($struct['title'])) ? $struct['title'] : ''; |
---|
| 434 | $excerpt = (!empty($struct['mt_excerpt'])) ? $struct['mt_excerpt'] : ''; |
---|
| 435 | $description = (!empty($struct['description'])) ? $struct['description'] : null; |
---|
| 436 | $dateCreated = !empty($struct['dateCreated']) ? $struct['dateCreated'] : null; |
---|
| 437 | $open_comment = (isset($struct['mt_allow_comments'])) ? $struct['mt_allow_comments'] : 1; |
---|
| 438 | $open_tb = (isset($struct['mt_allow_pings'])) ? $struct['mt_allow_pings'] : 1; |
---|
[2566] | 439 | |
---|
[3730] | 440 | if ($description !== null) { |
---|
| 441 | $content = $description; |
---|
| 442 | } |
---|
[2566] | 443 | |
---|
[3730] | 444 | if (!$title) { |
---|
| 445 | $title = text::cutString(html::clean($content), 25) . '...'; |
---|
| 446 | } |
---|
[2566] | 447 | |
---|
[3730] | 448 | $excerpt_xhtml = $this->core->callFormater('xhtml', $excerpt); |
---|
| 449 | $content_xhtml = $this->core->callFormater('xhtml', $content); |
---|
[2566] | 450 | |
---|
[3730] | 451 | if (empty($content)) { |
---|
| 452 | throw new Exception('Cannot create an empty entry'); |
---|
| 453 | } |
---|
[2566] | 454 | |
---|
[3730] | 455 | $cur = $this->core->con->openCursor($this->core->prefix . 'post'); |
---|
[2566] | 456 | |
---|
[3730] | 457 | $cur->post_type = $post_type; |
---|
| 458 | $cur->post_title = trim($title); |
---|
| 459 | $cur->post_content = $content; |
---|
| 460 | $cur->post_excerpt = $excerpt; |
---|
| 461 | $cur->post_content_xhtml = $content_xhtml; |
---|
| 462 | $cur->post_excerpt_xhtml = $excerpt_xhtml; |
---|
| 463 | $cur->post_open_comment = (integer) ($open_comment == 1); |
---|
| 464 | $cur->post_open_tb = (integer) ($open_tb == 1); |
---|
| 465 | $cur->post_status = (integer) $publish; |
---|
| 466 | $cur->post_format = 'xhtml'; |
---|
| 467 | $cur->post_url = $post->post_url; |
---|
[2566] | 468 | |
---|
[3730] | 469 | if ($dateCreated) { |
---|
| 470 | if ($dateCreated instanceof xmlrpcDate) { |
---|
| 471 | $cur->post_dt = date('Y-m-d H:i:00', $dateCreated->getTimestamp()); |
---|
| 472 | } elseif (is_string($dateCreated) && @strtotime($dateCreated)) { |
---|
| 473 | $cur->post_dt = date('Y-m-d H:i:00', strtotime($dateCreated)); |
---|
| 474 | } |
---|
| 475 | } else { |
---|
| 476 | $cur->post_dt = $post->post_dt; |
---|
| 477 | } |
---|
[2566] | 478 | |
---|
[3730] | 479 | # Categories in an array |
---|
| 480 | if (isset($struct['categories']) && is_array($struct['categories'])) { |
---|
| 481 | $categories = $struct['categories']; |
---|
| 482 | $cat_id = !empty($categories[0]) ? $categories[0] : null; |
---|
[2566] | 483 | |
---|
[3730] | 484 | $cur->cat_id = $this->getCatID($cat_id); |
---|
| 485 | } |
---|
[2566] | 486 | |
---|
[3730] | 487 | if (isset($struct['wp_slug'])) { |
---|
| 488 | $cur->post_url = $struct['wp_slug']; |
---|
| 489 | } |
---|
[2566] | 490 | |
---|
[3730] | 491 | if (isset($struct['wp_password'])) { |
---|
| 492 | $cur->post_password = $struct['wp_password']; |
---|
| 493 | } |
---|
[2566] | 494 | |
---|
[3730] | 495 | if ($cur->post_type == 'post') { |
---|
| 496 | # --BEHAVIOR-- xmlrpcBeforeEditPost |
---|
| 497 | $this->core->callBehavior('xmlrpcBeforeEditPost', $this, $post_id, $cur, $content, $struct, $publish); |
---|
[2566] | 498 | |
---|
[3730] | 499 | $this->core->blog->updPost($post_id, $cur); |
---|
[2566] | 500 | |
---|
[3730] | 501 | # --BEHAVIOR-- xmlrpcAfterEditPost |
---|
| 502 | $this->core->callBehavior('xmlrpcAfterEditPost', $this, $post_id, $cur, $content, $struct, $publish); |
---|
| 503 | } elseif ($cur->post_type == 'page') { |
---|
| 504 | if (isset($struct['wp_page_order'])) { |
---|
| 505 | $cur->post_position = (integer) $struct['wp_page_order']; |
---|
| 506 | } |
---|
[2566] | 507 | |
---|
[3730] | 508 | $this->core->blog->settings->system->post_url_format = '{t}'; |
---|
[2566] | 509 | |
---|
[3730] | 510 | $this->core->blog->updPost($post_id, $cur); |
---|
| 511 | } else { |
---|
| 512 | throw new Exception('Invalid post type', 401); |
---|
| 513 | } |
---|
[2566] | 514 | |
---|
[3730] | 515 | return true; |
---|
| 516 | } |
---|
[2566] | 517 | |
---|
[3730] | 518 | private function getPost($post_id, $user, $pwd, $type = 'mw') |
---|
| 519 | { |
---|
| 520 | $post_id = (integer) $post_id; |
---|
[2566] | 521 | |
---|
[3730] | 522 | $post = $this->getPostRS($post_id, $user, $pwd); |
---|
[2566] | 523 | |
---|
[3730] | 524 | $res = new ArrayObject(); |
---|
[2566] | 525 | |
---|
[3730] | 526 | $res['dateCreated'] = new xmlrpcDate($post->getTS()); |
---|
| 527 | $res['userid'] = $post->user_id; |
---|
| 528 | $res['postid'] = $post->post_id; |
---|
[2566] | 529 | |
---|
[3730] | 530 | if ($post->cat_id) { |
---|
| 531 | $res['categories'] = array($post->cat_url); |
---|
| 532 | } |
---|
[2566] | 533 | |
---|
[3730] | 534 | if ($type == 'blogger') { |
---|
| 535 | $res['content'] = $post->post_content_xhtml; |
---|
| 536 | } |
---|
[2566] | 537 | |
---|
[3730] | 538 | if ($type == 'mt' || $type == 'mw') { |
---|
| 539 | $res['title'] = $post->post_title; |
---|
| 540 | } |
---|
[2566] | 541 | |
---|
[3730] | 542 | if ($type == 'mw') { |
---|
| 543 | $res['description'] = $post->post_content_xhtml; |
---|
| 544 | $res['link'] = $res['permaLink'] = $post->getURL(); |
---|
| 545 | $res['mt_excerpt'] = $post->post_excerpt_xhtml; |
---|
| 546 | $res['mt_text_more'] = ''; |
---|
| 547 | $res['mt_allow_comments'] = (integer) $post->post_open_comment; |
---|
| 548 | $res['mt_allow_pings'] = (integer) $post->post_open_tb; |
---|
| 549 | $res['mt_convert_breaks'] = ''; |
---|
| 550 | $res['mt_keywords'] = ''; |
---|
| 551 | } |
---|
[2566] | 552 | |
---|
[3730] | 553 | # --BEHAVIOR-- xmlrpcGetPostInfo |
---|
| 554 | $this->core->callBehavior('xmlrpcGetPostInfo', $this, $type, array(&$res)); |
---|
[2566] | 555 | |
---|
[3730] | 556 | return $res; |
---|
| 557 | } |
---|
[2566] | 558 | |
---|
[3730] | 559 | private function deletePost($post_id, $user, $pwd) |
---|
| 560 | { |
---|
| 561 | $post_id = (integer) $post_id; |
---|
[2566] | 562 | |
---|
[3730] | 563 | $this->getPostRS($post_id, $user, $pwd); |
---|
| 564 | $this->core->blog->delPost($post_id); |
---|
[2566] | 565 | |
---|
[3730] | 566 | return true; |
---|
| 567 | } |
---|
[2566] | 568 | |
---|
[3730] | 569 | private function getRecentPosts($blog_id, $user, $pwd, $nb_post, $type = 'mw') |
---|
| 570 | { |
---|
| 571 | $this->setUser($user, $pwd); |
---|
| 572 | $this->setBlog(); |
---|
[2566] | 573 | |
---|
[3730] | 574 | $nb_post = (integer) $nb_post; |
---|
[2566] | 575 | |
---|
[3730] | 576 | if ($nb_post > 50) { |
---|
| 577 | throw new Exception('Cannot retrieve more than 50 entries'); |
---|
| 578 | } |
---|
[2566] | 579 | |
---|
[3730] | 580 | $params = array(); |
---|
| 581 | $params['limit'] = $nb_post; |
---|
[2566] | 582 | |
---|
[3730] | 583 | $posts = $this->core->blog->getPosts($params); |
---|
[2566] | 584 | |
---|
[3730] | 585 | $res = array(); |
---|
| 586 | while ($posts->fetch()) { |
---|
| 587 | $tres = array(); |
---|
[2566] | 588 | |
---|
[3730] | 589 | $tres['dateCreated'] = new xmlrpcDate($posts->getTS()); |
---|
| 590 | $tres['userid'] = $posts->user_id; |
---|
| 591 | $tres['postid'] = $posts->post_id; |
---|
[2566] | 592 | |
---|
[3730] | 593 | if ($posts->cat_id) { |
---|
| 594 | $tres['categories'] = array($posts->cat_url); |
---|
| 595 | } |
---|
[2566] | 596 | |
---|
[3730] | 597 | if ($type == 'blogger') { |
---|
| 598 | $tres['content'] = $posts->post_content_xhtml; |
---|
| 599 | } |
---|
[2566] | 600 | |
---|
[3730] | 601 | if ($type == 'mt' || $type == 'mw') { |
---|
| 602 | $tres['title'] = $posts->post_title; |
---|
| 603 | } |
---|
[2566] | 604 | |
---|
[3730] | 605 | if ($type == 'mw') { |
---|
| 606 | $tres['description'] = $posts->post_content_xhtml; |
---|
| 607 | $tres['link'] = $tres['permaLink'] = $posts->getURL(); |
---|
| 608 | $tres['mt_excerpt'] = $posts->post_excerpt_xhtml; |
---|
| 609 | $tres['mt_text_more'] = ''; |
---|
| 610 | $tres['mt_allow_comments'] = (integer) $posts->post_open_comment; |
---|
| 611 | $tres['mt_allow_pings'] = (integer) $posts->post_open_tb; |
---|
| 612 | $tres['mt_convert_breaks'] = ''; |
---|
| 613 | $tres['mt_keywords'] = ''; |
---|
| 614 | } |
---|
[2566] | 615 | |
---|
[3730] | 616 | # --BEHAVIOR-- xmlrpcGetPostInfo |
---|
| 617 | $this->core->callBehavior('xmlrpcGetPostInfo', $this, $type, array(&$tres)); |
---|
[2566] | 618 | |
---|
[3730] | 619 | $res[] = $tres; |
---|
| 620 | } |
---|
[2566] | 621 | |
---|
[3730] | 622 | return $res; |
---|
| 623 | } |
---|
[2566] | 624 | |
---|
[3730] | 625 | private function getUserBlogs($user, $pwd) |
---|
| 626 | { |
---|
| 627 | $this->setUser($user, $pwd); |
---|
| 628 | $this->setBlog(); |
---|
[2566] | 629 | |
---|
[3730] | 630 | return array(array( |
---|
| 631 | 'url' => $this->core->blog->url, |
---|
| 632 | 'blogid' => '1', |
---|
| 633 | 'blogName' => $this->core->blog->name |
---|
| 634 | )); |
---|
| 635 | } |
---|
[2566] | 636 | |
---|
[3730] | 637 | private function getUserInfo($user, $pwd) |
---|
| 638 | { |
---|
| 639 | $this->setUser($user, $pwd); |
---|
[2566] | 640 | |
---|
[3730] | 641 | return array( |
---|
| 642 | 'userid' => $this->core->auth->userID(), |
---|
| 643 | 'firstname' => $this->core->auth->getInfo('user_firstname'), |
---|
| 644 | 'lastname' => $this->core->auth->getInfo('user_name'), |
---|
| 645 | 'nickname' => $this->core->auth->getInfo('user_displayname'), |
---|
| 646 | 'email' => $this->core->auth->getInfo('user_email'), |
---|
| 647 | 'url' => $this->core->auth->getInfo('user_url') |
---|
| 648 | ); |
---|
| 649 | } |
---|
[2566] | 650 | |
---|
[3730] | 651 | private function getCategories($blog_id, $user, $pwd) |
---|
| 652 | { |
---|
| 653 | $this->setUser($user, $pwd); |
---|
| 654 | $this->setBlog(); |
---|
| 655 | $rs = $this->core->blog->getCategories(); |
---|
[2566] | 656 | |
---|
[3730] | 657 | $res = array(); |
---|
[2566] | 658 | |
---|
[3730] | 659 | $l = $rs->level; |
---|
| 660 | $stack = array('', $rs->cat_url); |
---|
[2566] | 661 | |
---|
[3730] | 662 | while ($rs->fetch()) { |
---|
| 663 | $d = $rs->level - $l; |
---|
| 664 | if ($d == 0) { |
---|
| 665 | array_pop($stack); |
---|
| 666 | $parent = end($stack); |
---|
| 667 | } elseif ($d > 0) { |
---|
| 668 | $parent = end($stack); |
---|
| 669 | } elseif ($d < 0) { |
---|
| 670 | $D = abs($d); |
---|
| 671 | for ($i = 0; $i <= $D; $i++) { |
---|
| 672 | array_pop($stack); |
---|
| 673 | } |
---|
| 674 | $parent = end($stack); |
---|
| 675 | } |
---|
[2566] | 676 | |
---|
[3730] | 677 | $res[] = array( |
---|
| 678 | 'categoryId' => $rs->cat_url, |
---|
| 679 | 'parentId' => $parent, |
---|
| 680 | 'description' => $rs->cat_title, |
---|
| 681 | 'categoryName' => $rs->cat_url, |
---|
| 682 | 'htmlUrl' => $this->core->blog->url . |
---|
| 683 | $this->core->url->getURLFor('category', $rs->cat_url), |
---|
| 684 | 'rssUrl' => $this->core->blog->url . |
---|
| 685 | $this->core->url->getURLFor('feed', 'category/' . $rs->cat_url . '/rss2') |
---|
| 686 | ); |
---|
[2566] | 687 | |
---|
[3730] | 688 | $stack[] = $rs->cat_url; |
---|
| 689 | $l = $rs->level; |
---|
| 690 | } |
---|
[2566] | 691 | |
---|
[3730] | 692 | return $res; |
---|
| 693 | } |
---|
[2566] | 694 | |
---|
[3730] | 695 | private function getPostCategories($post_id, $user, $pwd) |
---|
| 696 | { |
---|
| 697 | $post_id = (integer) $post_id; |
---|
[2566] | 698 | |
---|
[3730] | 699 | $post = $this->getPostRS($post_id, $user, $pwd); |
---|
[2566] | 700 | |
---|
[3730] | 701 | return array( |
---|
| 702 | array( |
---|
| 703 | 'categoryName' => $post->cat_url, |
---|
| 704 | 'categoryId' => (string) $post->cat_url, |
---|
| 705 | 'isPrimary' => true |
---|
| 706 | ) |
---|
| 707 | ); |
---|
| 708 | } |
---|
[2566] | 709 | |
---|
[3730] | 710 | private function setPostCategories($post_id, $user, $pwd, $categories) |
---|
| 711 | { |
---|
| 712 | $post_id = (integer) $post_id; |
---|
[2566] | 713 | |
---|
[3730] | 714 | $post = $this->getPostRS($post_id, $user, $pwd); |
---|
[2566] | 715 | |
---|
[3730] | 716 | $cat_id = (!empty($categories[0]['categoryId'])) ? $categories[0]['categoryId'] : null; |
---|
[2566] | 717 | |
---|
[3730] | 718 | foreach ($categories as $v) { |
---|
| 719 | if (isset($v['isPrimary']) && $v['isPrimary']) { |
---|
| 720 | $cat_id = $v['categoryId']; |
---|
| 721 | break; |
---|
| 722 | } |
---|
| 723 | } |
---|
[2566] | 724 | |
---|
[3730] | 725 | # w.bloggar sends -1 for no category. |
---|
| 726 | if ($cat_id == -1) { |
---|
| 727 | $cat_id = null; |
---|
| 728 | } |
---|
[2566] | 729 | |
---|
[3730] | 730 | if ($cat_id) { |
---|
| 731 | $cat_id = $this->getCatID($cat_id); |
---|
| 732 | } |
---|
[2566] | 733 | |
---|
[3730] | 734 | $this->core->blog->updPostCategory($post_id, (integer) $cat_id); |
---|
[2566] | 735 | |
---|
[3730] | 736 | return true; |
---|
| 737 | } |
---|
[2566] | 738 | |
---|
[3730] | 739 | private function publishPost($post_id, $user, $pwd) |
---|
| 740 | { |
---|
| 741 | $post_id = (integer) $post_id; |
---|
[2566] | 742 | |
---|
[3730] | 743 | $this->getPostRS($post_id, $user, $pwd); |
---|
[2566] | 744 | |
---|
[3730] | 745 | # --BEHAVIOR-- xmlrpcBeforePublishPost |
---|
| 746 | $this->core->callBehavior('xmlrpcBeforePublishPost', $this, $post_id); |
---|
[2566] | 747 | |
---|
[3730] | 748 | $this->core->blog->updPostStatus($post_id, 1); |
---|
[2566] | 749 | |
---|
[3730] | 750 | # --BEHAVIOR-- xmlrpcAfterPublishPost |
---|
| 751 | $this->core->callBehavior('xmlrpcAfterPublishPost', $this, $post_id); |
---|
[2566] | 752 | |
---|
[3730] | 753 | return true; |
---|
| 754 | } |
---|
[2566] | 755 | |
---|
[3730] | 756 | private function newMediaObject($blog_id, $user, $pwd, $file) |
---|
| 757 | { |
---|
| 758 | if (empty($file['name'])) { |
---|
| 759 | throw new Exception('No file name'); |
---|
| 760 | } |
---|
[2566] | 761 | |
---|
[3730] | 762 | if (empty($file['bits'])) { |
---|
| 763 | throw new Exception('No file content'); |
---|
| 764 | } |
---|
[2566] | 765 | |
---|
[3730] | 766 | $file_name = $file['name']; |
---|
| 767 | $file_bits = $file['bits']; |
---|
[2566] | 768 | |
---|
[3730] | 769 | $this->setUser($user, $pwd); |
---|
| 770 | $this->setBlog(); |
---|
[2566] | 771 | |
---|
[3730] | 772 | $media = new dcMedia($this->core); |
---|
[2566] | 773 | |
---|
[3730] | 774 | $dir_name = path::clean(dirname($file_name)); |
---|
| 775 | $file_name = basename($file_name); |
---|
[2566] | 776 | |
---|
[3730] | 777 | $dir_name = preg_replace('!^/!', '', $dir_name); |
---|
| 778 | if ($dir_name != '') { |
---|
| 779 | $dir = explode('/', $dir_name); |
---|
| 780 | $cwd = './'; |
---|
| 781 | foreach ($dir as $v) { |
---|
| 782 | $v = files::tidyFileName($v); |
---|
| 783 | $cwd .= $v . '/'; |
---|
| 784 | $media->makeDir($v); |
---|
| 785 | $media->chdir($cwd); |
---|
| 786 | } |
---|
| 787 | } |
---|
[2566] | 788 | |
---|
[3730] | 789 | $media_id = $media->uploadBits($file_name, $file_bits); |
---|
[2566] | 790 | |
---|
[3730] | 791 | $f = $media->getFile($media_id); |
---|
| 792 | return array( |
---|
| 793 | 'file' => $file_name, |
---|
| 794 | 'url' => $f->file_url, |
---|
| 795 | 'type' => files::getMimeType($file_name) |
---|
| 796 | ); |
---|
| 797 | } |
---|
[2566] | 798 | |
---|
[3730] | 799 | private function translateWpStatus($s) |
---|
| 800 | { |
---|
| 801 | $status = array( |
---|
| 802 | 'draft' => -2, |
---|
| 803 | 'pending' => -2, |
---|
| 804 | 'private' => 0, |
---|
| 805 | 'publish' => 1, |
---|
| 806 | 'scheduled' => -1 |
---|
| 807 | ); |
---|
[2566] | 808 | |
---|
[3730] | 809 | if (is_int($s)) { |
---|
| 810 | $status = array_flip($status); |
---|
| 811 | return isset($status[$s]) ? $status[$s] : $status[-2]; |
---|
| 812 | } else { |
---|
| 813 | return isset($status[$s]) ? $status[$s] : $status['pending']; |
---|
| 814 | } |
---|
| 815 | } |
---|
[2566] | 816 | |
---|
[3730] | 817 | private function translateWpCommentstatus($s) |
---|
| 818 | { |
---|
| 819 | $status = array( |
---|
| 820 | 'hold' => -1, |
---|
| 821 | 'approve' => 0, |
---|
| 822 | 'spam' => -2 |
---|
| 823 | ); |
---|
[2566] | 824 | |
---|
[3730] | 825 | if (is_int($s)) { |
---|
| 826 | $status = array_flip($status); |
---|
| 827 | return isset($status[$s]) ? $status[$s] : $status[0]; |
---|
| 828 | } else { |
---|
| 829 | return isset($status[$s]) ? $status[$s] : $status['approve']; |
---|
| 830 | } |
---|
| 831 | } |
---|
[2566] | 832 | |
---|
[3730] | 833 | private function translateWpOptions($options = array()) |
---|
| 834 | { |
---|
| 835 | $timezone = 0; |
---|
| 836 | if ($this->core->blog->settings->system->blog_timezone) { |
---|
| 837 | $timezone = dt::getTimeOffset($this->core->blog->settings->system->blog_timezone) / 3600; |
---|
| 838 | } |
---|
[2566] | 839 | |
---|
[3730] | 840 | $res = array( |
---|
| 841 | 'software_name' => array( |
---|
| 842 | 'desc' => 'Software Name', |
---|
| 843 | 'readonly' => true, |
---|
| 844 | 'value' => 'Dotclear' |
---|
| 845 | ), |
---|
| 846 | 'software_version' => array( |
---|
| 847 | 'desc' => 'Software Version', |
---|
| 848 | 'readonly' => true, |
---|
| 849 | 'value' => DC_VERSION |
---|
| 850 | ), |
---|
| 851 | 'blog_url' => array( |
---|
| 852 | 'desc' => 'Blog URL', |
---|
| 853 | 'readonly' => true, |
---|
| 854 | 'value' => $this->core->blog->url |
---|
| 855 | ), |
---|
| 856 | 'time_zone' => array( |
---|
| 857 | 'desc' => 'Time Zone', |
---|
| 858 | 'readonly' => true, |
---|
| 859 | 'value' => (string) $timezone |
---|
| 860 | ), |
---|
| 861 | 'blog_title' => array( |
---|
| 862 | 'desc' => 'Blog Title', |
---|
| 863 | 'readonly' => false, |
---|
| 864 | 'value' => $this->core->blog->name |
---|
| 865 | ), |
---|
| 866 | 'blog_tagline' => array( |
---|
| 867 | 'desc' => 'Blog Tagline', |
---|
| 868 | 'readonly' => false, |
---|
| 869 | 'value' => $this->core->blog->desc |
---|
| 870 | ), |
---|
| 871 | 'date_format' => array( |
---|
| 872 | 'desc' => 'Date Format', |
---|
| 873 | 'readonly' => false, |
---|
| 874 | 'value' => $this->core->blog->settings->system->date_format |
---|
| 875 | ), |
---|
| 876 | 'time_format' => array( |
---|
| 877 | 'desc' => 'Time Format', |
---|
| 878 | 'readonly' => false, |
---|
| 879 | 'value' => $this->core->blog->settings->system->time_format |
---|
| 880 | ) |
---|
| 881 | ); |
---|
[2566] | 882 | |
---|
[3730] | 883 | if (!empty($options)) { |
---|
| 884 | $r = array(); |
---|
| 885 | foreach ($options as $v) { |
---|
| 886 | if (isset($res[$v])) { |
---|
| 887 | $r[$v] = $res[$v]; |
---|
| 888 | } |
---|
| 889 | } |
---|
| 890 | return $r; |
---|
| 891 | } |
---|
[2566] | 892 | |
---|
[3730] | 893 | return $res; |
---|
| 894 | } |
---|
[2566] | 895 | |
---|
[3730] | 896 | private function getPostStatusList($blog_id, $user, $pwd) |
---|
| 897 | { |
---|
| 898 | $this->setUser($user, $pwd); |
---|
| 899 | $this->setBlog(); |
---|
[2566] | 900 | |
---|
[3730] | 901 | return array( |
---|
| 902 | 'draft' => 'Draft', |
---|
| 903 | 'pending' => 'Pending Review', |
---|
| 904 | 'private' => 'Private', |
---|
| 905 | 'publish' => 'Published', |
---|
| 906 | 'scheduled' => 'Scheduled' |
---|
| 907 | ); |
---|
| 908 | } |
---|
[2566] | 909 | |
---|
[3730] | 910 | private function getPageStatusList($blog_id, $user, $pwd) |
---|
| 911 | { |
---|
| 912 | $this->setUser($user, $pwd); |
---|
| 913 | $this->setBlog(); |
---|
| 914 | $this->checkPagesPermission(); |
---|
[2566] | 915 | |
---|
[3730] | 916 | return array( |
---|
| 917 | 'draft' => 'Draft', |
---|
| 918 | 'private' => 'Private', |
---|
| 919 | 'published' => 'Published', |
---|
| 920 | 'scheduled' => 'Scheduled' |
---|
| 921 | ); |
---|
| 922 | } |
---|
[2566] | 923 | |
---|
[3730] | 924 | private function checkPagesPermission() |
---|
| 925 | { |
---|
| 926 | if (!$this->core->plugins->moduleExists('pages')) { |
---|
| 927 | throw new Exception('Pages management is not available on this blog.'); |
---|
| 928 | } |
---|
[2566] | 929 | |
---|
[3730] | 930 | if (!$this->core->auth->check('pages,contentadmin', $this->core->blog->id)) { |
---|
| 931 | throw new Exception('Not enough permissions to edit pages.', 401); |
---|
| 932 | } |
---|
| 933 | } |
---|
[2566] | 934 | |
---|
[3730] | 935 | private function getPages($blog_id, $user, $pwd, $limit = null, $id = null) |
---|
| 936 | { |
---|
| 937 | $this->setUser($user, $pwd); |
---|
| 938 | $this->setBlog(); |
---|
| 939 | $this->checkPagesPermission(); |
---|
[2566] | 940 | |
---|
[3730] | 941 | $params = array( |
---|
| 942 | 'post_type' => 'page', |
---|
| 943 | 'order' => 'post_position ASC, post_title ASC' |
---|
| 944 | ); |
---|
[2566] | 945 | |
---|
[3730] | 946 | if ($id) { |
---|
| 947 | $params['post_id'] = (integer) $id; |
---|
| 948 | } |
---|
| 949 | if ($limit) { |
---|
| 950 | $params['limit'] = $limit; |
---|
| 951 | } |
---|
[2566] | 952 | |
---|
[3730] | 953 | $posts = $this->core->blog->getPosts($params); |
---|
[2566] | 954 | |
---|
[3730] | 955 | $res = array(); |
---|
| 956 | while ($posts->fetch()) { |
---|
| 957 | $tres = array( |
---|
| 958 | "dateCreated" => new xmlrpcDate($posts->getTS()), |
---|
| 959 | "userid" => $posts->user_id, |
---|
| 960 | "page_id" => $posts->post_id, |
---|
| 961 | "page_status" => $this->translateWpStatus((integer) $posts->post_status), |
---|
| 962 | "description" => $posts->post_content_xhtml, |
---|
| 963 | "title" => $posts->post_title, |
---|
| 964 | "link" => $posts->getURL(), |
---|
| 965 | "permaLink" => $posts->getURL(), |
---|
| 966 | "categories" => array(), |
---|
| 967 | "excerpt" => $posts->post_excerpt_xhtml, |
---|
| 968 | "text_more" => '', |
---|
| 969 | "mt_allow_comments" => (integer) $posts->post_open_comment, |
---|
| 970 | "mt_allow_pings" => (integer) $posts->post_open_tb, |
---|
| 971 | "wp_slug" => $posts->post_url, |
---|
| 972 | "wp_password" => $posts->post_password, |
---|
| 973 | "wp_author" => $posts->getAuthorCN(), |
---|
| 974 | "wp_page_parent_id" => 0, |
---|
| 975 | "wp_page_parent_title" => '', |
---|
| 976 | "wp_page_order" => $posts->post_position, |
---|
| 977 | "wp_author_id" => $posts->user_id, |
---|
| 978 | "wp_author_display_name" => $posts->getAuthorCN(), |
---|
| 979 | "date_created_gmt" => new xmlrpcDate(dt::iso8601($posts->getTS(), $posts->post_tz)), |
---|
| 980 | "custom_fields" => array(), |
---|
| 981 | "wp_page_template" => 'default' |
---|
| 982 | ); |
---|
[2566] | 983 | |
---|
[3730] | 984 | # --BEHAVIOR-- xmlrpcGetPageInfo |
---|
| 985 | $this->core->callBehavior('xmlrpcGetPageInfo', $this, array(&$tres)); |
---|
[2566] | 986 | |
---|
[3730] | 987 | $res[] = $tres; |
---|
| 988 | } |
---|
[2566] | 989 | |
---|
[3730] | 990 | return $res; |
---|
| 991 | } |
---|
[2566] | 992 | |
---|
[3730] | 993 | private function newPage($blog_id, $user, $pwd, $struct, $publish) |
---|
| 994 | { |
---|
| 995 | $this->setUser($user, $pwd); |
---|
| 996 | $this->setBlog(); |
---|
| 997 | $this->checkPagesPermission(); |
---|
[2566] | 998 | |
---|
[3730] | 999 | $struct['post_type'] = 'page'; |
---|
[2566] | 1000 | |
---|
[3730] | 1001 | return $this->newPost($blog_id, $user, $pwd, null, $struct, $publish); |
---|
| 1002 | } |
---|
[2566] | 1003 | |
---|
[3730] | 1004 | private function editPage($page_id, $user, $pwd, $struct, $publish) |
---|
| 1005 | { |
---|
| 1006 | $this->setUser($user, $pwd); |
---|
| 1007 | $this->setBlog(); |
---|
| 1008 | $this->checkPagesPermission(); |
---|
[2566] | 1009 | |
---|
[3730] | 1010 | $struct['post_type'] = 'page'; |
---|
[2566] | 1011 | |
---|
[3730] | 1012 | return $this->editPost($page_id, $user, $pwd, null, $struct, $publish); |
---|
| 1013 | } |
---|
[2566] | 1014 | |
---|
[3730] | 1015 | private function deletePage($page_id, $user, $pwd) |
---|
| 1016 | { |
---|
| 1017 | $this->setUser($user, $pwd); |
---|
| 1018 | $this->setBlog(); |
---|
| 1019 | $this->checkPagesPermission(); |
---|
[2566] | 1020 | |
---|
[3730] | 1021 | $page_id = (integer) $page_id; |
---|
[2566] | 1022 | |
---|
[3730] | 1023 | $this->getPostRS($page_id, $user, $pwd, 'page'); |
---|
| 1024 | $this->core->blog->delPost($page_id); |
---|
[2566] | 1025 | |
---|
[3730] | 1026 | return true; |
---|
| 1027 | } |
---|
[2566] | 1028 | |
---|
[3730] | 1029 | private function getAuthors($user, $pwd) |
---|
| 1030 | { |
---|
| 1031 | $this->setUser($user, $pwd); |
---|
| 1032 | $this->setBlog(); |
---|
[2566] | 1033 | |
---|
[3730] | 1034 | $rs = $this->core->getBlogPermissions($this->core->blog->id); |
---|
| 1035 | $res = array(); |
---|
[2566] | 1036 | |
---|
[3730] | 1037 | foreach ($rs as $k => $v) { |
---|
| 1038 | $res[] = array( |
---|
| 1039 | 'user_id' => $k, |
---|
| 1040 | 'user_login' => $k, |
---|
| 1041 | 'display_name' => dcUtils::getUserCN($k, $v['name'], $v['firstname'], $v['displayname']) |
---|
| 1042 | ); |
---|
| 1043 | } |
---|
| 1044 | return $res; |
---|
| 1045 | } |
---|
[2566] | 1046 | |
---|
[3730] | 1047 | private function getTags($user, $pwd) |
---|
| 1048 | { |
---|
| 1049 | $this->setUser($user, $pwd); |
---|
| 1050 | $this->setBlog(); |
---|
[2566] | 1051 | |
---|
[3730] | 1052 | $tags = $this->core->meta->getMeta('tag'); |
---|
| 1053 | $tags->sort('meta_id_lower', 'asc'); |
---|
[2566] | 1054 | |
---|
[3730] | 1055 | $res = array(); |
---|
| 1056 | $url = $this->core->blog->url . |
---|
| 1057 | $this->core->url->getURLFor('tag', '%s'); |
---|
| 1058 | $f_url = $this->core->blog->url . |
---|
| 1059 | $this->core->url->getURLFor('tag_feed', '%s'); |
---|
| 1060 | while ($tags->fetch()) { |
---|
| 1061 | $res[] = array( |
---|
| 1062 | 'tag_id' => $tags->meta_id, |
---|
| 1063 | 'name' => $tags->meta_id, |
---|
| 1064 | 'count' => $tags->count, |
---|
| 1065 | 'slug' => $tags->meta_id, |
---|
| 1066 | 'html_url' => sprintf($url, $tags->meta_id), |
---|
| 1067 | 'rss_url' => sprintf($f_url, $tags->meta_id) |
---|
| 1068 | ); |
---|
| 1069 | } |
---|
| 1070 | return $res; |
---|
| 1071 | } |
---|
[2566] | 1072 | |
---|
[3730] | 1073 | private function newCategory($user, $pwd, $struct) |
---|
| 1074 | { |
---|
| 1075 | $this->setUser($user, $pwd); |
---|
| 1076 | $this->setBlog(); |
---|
[2566] | 1077 | |
---|
[3730] | 1078 | if (empty($struct['name'])) { |
---|
| 1079 | throw new Exception('You mus give a category name.'); |
---|
| 1080 | } |
---|
[2566] | 1081 | |
---|
[3730] | 1082 | $cur = $this->core->con->openCursor($this->core->prefix . 'category'); |
---|
| 1083 | $cur->cat_title = $struct['name']; |
---|
[2566] | 1084 | |
---|
[3730] | 1085 | if (!empty($struct['slug'])) { |
---|
| 1086 | $cur->cat_url = $struct['slug']; |
---|
| 1087 | } |
---|
| 1088 | if (!empty($struct['category_description'])) { |
---|
| 1089 | $cur->cat_desc = $struct['category_description']; |
---|
| 1090 | if (html::clean($cur->cat_desc) == $cur->cat_desc) { |
---|
| 1091 | $cur->cat_desc = '<p>' . $cur->cat_desc . '</p>'; |
---|
| 1092 | } |
---|
| 1093 | } |
---|
[2566] | 1094 | |
---|
[3730] | 1095 | $parent = !empty($struct['category_parent']) ? (integer) $struct['category_parent'] : 0; |
---|
[2566] | 1096 | |
---|
[3730] | 1097 | $id = $this->core->blog->addCategory($cur, $parent); |
---|
| 1098 | $rs = $this->core->blog->getCategory($id); |
---|
| 1099 | return $rs->cat_url; |
---|
| 1100 | } |
---|
[2566] | 1101 | |
---|
[3730] | 1102 | private function deleteCategory($user, $pwd, $cat_id) |
---|
| 1103 | { |
---|
| 1104 | $this->setUser($user, $pwd); |
---|
| 1105 | $this->setBlog(); |
---|
[2566] | 1106 | |
---|
[3730] | 1107 | $c = $this->core->blog->getCategories(array('cat_url' => $cat_id)); |
---|
| 1108 | if ($c->isEmpty()) { |
---|
| 1109 | throw new Exception(__('This category does not exist.')); |
---|
| 1110 | } |
---|
| 1111 | $cat_id = $c->cat_id; |
---|
| 1112 | unset($c); |
---|
[2566] | 1113 | |
---|
[3730] | 1114 | $this->core->blog->delCategory((integer) $cat_id); |
---|
| 1115 | return true; |
---|
| 1116 | } |
---|
[2566] | 1117 | |
---|
[3730] | 1118 | private function searchCategories($user, $pwd, $category, $limit) |
---|
| 1119 | { |
---|
| 1120 | $this->setUser($user, $pwd); |
---|
| 1121 | $this->setBlog(); |
---|
[2566] | 1122 | |
---|
[3730] | 1123 | $strReq = 'SELECT cat_id, cat_title, cat_url ' . |
---|
| 1124 | 'FROM ' . $this->core->prefix . 'category ' . |
---|
| 1125 | "WHERE blog_id = '" . $this->core->con->escape($this->core->blog->id) . "' " . |
---|
| 1126 | "AND LOWER(cat_title) LIKE LOWER('%" . $this->core->con->escape($category) . "%') " . |
---|
| 1127 | ($limit > 0 ? $this->core->con->limit($limit) : ''); |
---|
[2566] | 1128 | |
---|
[3730] | 1129 | $rs = $this->core->con->select($strReq); |
---|
[2566] | 1130 | |
---|
[3730] | 1131 | $res = array(); |
---|
| 1132 | while ($rs->fetch()) { |
---|
| 1133 | $res[] = array( |
---|
| 1134 | 'category_id' => $rs->cat_url, |
---|
| 1135 | 'category_name' => $rs->cat_url |
---|
| 1136 | ); |
---|
| 1137 | } |
---|
| 1138 | return $res; |
---|
| 1139 | } |
---|
[2566] | 1140 | |
---|
[3730] | 1141 | private function countComments($user, $pwd, $post_id) |
---|
| 1142 | { |
---|
| 1143 | $this->setUser($user, $pwd); |
---|
| 1144 | $this->setBlog(); |
---|
[2566] | 1145 | |
---|
[3730] | 1146 | $res = array( |
---|
| 1147 | 'approved' => 0, |
---|
| 1148 | 'awaiting_moderation' => 0, |
---|
| 1149 | 'spam' => 0, |
---|
| 1150 | 'total' => 0 |
---|
| 1151 | ); |
---|
| 1152 | $rs = $this->core->blog->getComments(array('post_id' => $post_id)); |
---|
[2566] | 1153 | |
---|
[3730] | 1154 | while ($rs->fetch()) { |
---|
| 1155 | $res['total']++; |
---|
| 1156 | if ($rs->comment_status == 1) { |
---|
| 1157 | $res['approved']++; |
---|
| 1158 | } elseif ($rs->comment_status == -2) { |
---|
| 1159 | $res['spam']++; |
---|
| 1160 | } else { |
---|
| 1161 | $res['awaiting_moderation']++; |
---|
| 1162 | } |
---|
| 1163 | } |
---|
| 1164 | return $res; |
---|
| 1165 | } |
---|
[2566] | 1166 | |
---|
[3730] | 1167 | private function getComments($user, $pwd, $struct, $id = null) |
---|
| 1168 | { |
---|
| 1169 | $this->setUser($user, $pwd); |
---|
| 1170 | $this->setBlog(); |
---|
[2566] | 1171 | |
---|
[3730] | 1172 | $params = array(); |
---|
[2566] | 1173 | |
---|
[3730] | 1174 | if (!empty($struct['status'])) { |
---|
| 1175 | $params['comment_status'] = $this->translateWpCommentstatus($struct['status']); |
---|
| 1176 | } |
---|
[2566] | 1177 | |
---|
[3730] | 1178 | if (!empty($struct['post_id'])) { |
---|
| 1179 | $params['post_id'] = (integer) $struct['post_id']; |
---|
| 1180 | } |
---|
[2566] | 1181 | |
---|
[3730] | 1182 | if (isset($id)) { |
---|
| 1183 | $params['comment_id'] = $id; |
---|
| 1184 | } |
---|
[2566] | 1185 | |
---|
[3730] | 1186 | $offset = !empty($struct['offset']) ? (integer) $struct['offset'] : 0; |
---|
| 1187 | $limit = !empty($struct['number']) ? (integer) $struct['number'] : 10; |
---|
| 1188 | $params['limit'] = array($offset, $limit); |
---|
[2566] | 1189 | |
---|
[3730] | 1190 | $rs = $this->core->blog->getComments($params); |
---|
| 1191 | $res = array(); |
---|
| 1192 | while ($rs->fetch()) { |
---|
| 1193 | $res[] = array( |
---|
| 1194 | 'date_created_gmt' => new xmlrpcDate($rs->getTS()), |
---|
| 1195 | 'user_id' => $rs->user_id, |
---|
| 1196 | 'comment_id' => $rs->comment_id, |
---|
| 1197 | 'parent' => 0, |
---|
| 1198 | 'status' => $this->translateWpCommentstatus((integer) $rs->comment_status), |
---|
| 1199 | 'content' => $rs->comment_content, |
---|
| 1200 | 'link' => $rs->getPostURL() . '#c' . $rs->comment_id, |
---|
| 1201 | 'post_id' => $rs->post_id, |
---|
| 1202 | 'post_title' => $rs->post_title, |
---|
| 1203 | 'author' => $rs->comment_author, |
---|
| 1204 | 'author_url' => $rs->comment_site, |
---|
| 1205 | 'author_email' => $rs->comment_email, |
---|
| 1206 | 'author_ip' => $rs->comment_ip |
---|
| 1207 | ); |
---|
| 1208 | } |
---|
| 1209 | return $res; |
---|
| 1210 | } |
---|
[2566] | 1211 | |
---|
[3730] | 1212 | private function addComment($user, $pwd, $post_id, $struct) |
---|
| 1213 | { |
---|
| 1214 | $this->setUser($user, $pwd); |
---|
| 1215 | $this->setBlog(); |
---|
[2566] | 1216 | |
---|
[3730] | 1217 | if (empty($struct['content'])) { |
---|
| 1218 | throw new Exception('Sorry, you cannot post an empty comment', 401); |
---|
| 1219 | } |
---|
[2566] | 1220 | |
---|
[3730] | 1221 | if (is_numeric($post_id)) { |
---|
| 1222 | $p['post_id'] = $post_id; |
---|
| 1223 | } else { |
---|
| 1224 | $p['post_url'] = $post_id; |
---|
| 1225 | } |
---|
| 1226 | $rs = $this->core->blog->getPosts($p); |
---|
| 1227 | if ($rs->isEmpty()) { |
---|
| 1228 | throw new Exception('Sorry, no such post.', 404); |
---|
| 1229 | } |
---|
[2566] | 1230 | |
---|
[3730] | 1231 | $cur = $this->core->con->openCursor($this->core->prefix . 'comment'); |
---|
[2566] | 1232 | |
---|
[3730] | 1233 | $cur->comment_author = $this->core->auth->getInfo('user_cn'); |
---|
| 1234 | $cur->comment_email = $this->core->auth->getInfo('user_email'); |
---|
| 1235 | $cur->comment_site = $this->core->auth->getInfo('user_url'); |
---|
[2566] | 1236 | |
---|
[3730] | 1237 | $cur->comment_content = $struct['content']; |
---|
| 1238 | $cur->post_id = (integer) $post_id; |
---|
[2566] | 1239 | |
---|
[3730] | 1240 | $id = $this->core->blog->addComment($cur); |
---|
| 1241 | return $id; |
---|
| 1242 | } |
---|
[2566] | 1243 | |
---|
[3730] | 1244 | private function updComment($user, $pwd, $comment_id, $struct) |
---|
| 1245 | { |
---|
| 1246 | $this->setUser($user, $pwd); |
---|
| 1247 | $this->setBlog(); |
---|
[2566] | 1248 | |
---|
[3730] | 1249 | $cur = $this->core->con->openCursor($this->core->prefix . 'comment'); |
---|
[2566] | 1250 | |
---|
[3730] | 1251 | if (isset($struct['status'])) { |
---|
| 1252 | $cur->comment_status = $this->translateWpCommentstatus($struct['status']); |
---|
| 1253 | } |
---|
[2566] | 1254 | |
---|
[3730] | 1255 | if (isset($struct['date_created_gmt'])) { |
---|
| 1256 | if ($struct['date_created_gmt'] instanceof xmlrpcDate) { |
---|
| 1257 | $cur->comment_dt = date('Y-m-d H:i:00', $struct['date_created_gmt']->getTimestamp()); |
---|
| 1258 | } elseif (is_string($struct['date_created_gmt']) && @strtotime($struct['date_created_gmt'])) { |
---|
| 1259 | $cur->comment_dt = date('Y-m-d H:i:00', strtotime($struct['date_created_gmt'])); |
---|
| 1260 | } |
---|
| 1261 | $cur->comment_dt = $struct['date_created_gmt']; |
---|
| 1262 | } |
---|
[2566] | 1263 | |
---|
[3730] | 1264 | if (isset($struct['content'])) { |
---|
| 1265 | $cur->comment_content = $struct['content']; |
---|
| 1266 | } |
---|
[2566] | 1267 | |
---|
[3730] | 1268 | if (isset($struct['author'])) { |
---|
| 1269 | $cur->comment_author = $struct['author']; |
---|
| 1270 | } |
---|
[2566] | 1271 | |
---|
[3730] | 1272 | if (isset($struct['author_url'])) { |
---|
| 1273 | $cur->comment_site = $struct['author_url']; |
---|
| 1274 | } |
---|
[2566] | 1275 | |
---|
[3730] | 1276 | if (isset($struct['author_email'])) { |
---|
| 1277 | $cur->comment_email = $struct['author_email']; |
---|
| 1278 | } |
---|
[2566] | 1279 | |
---|
[3730] | 1280 | $this->core->blog->updComment($comment_id, $cur); |
---|
| 1281 | return true; |
---|
| 1282 | } |
---|
[2566] | 1283 | |
---|
[3730] | 1284 | private function delComment($user, $pwd, $comment_id) |
---|
| 1285 | { |
---|
| 1286 | $this->setUser($user, $pwd); |
---|
| 1287 | $this->setBlog(); |
---|
[2566] | 1288 | |
---|
[3730] | 1289 | $this->core->blog->delComment($comment_id); |
---|
| 1290 | return true; |
---|
| 1291 | } |
---|
[2566] | 1292 | |
---|
[3730] | 1293 | /* Blogger methods |
---|
| 1294 | --------------------------------------------------- */ |
---|
| 1295 | public function blogger_newPost($appkey, $blogid, $username, $password, $content, $publish) |
---|
| 1296 | { |
---|
| 1297 | return $this->newPost($blogid, $username, $password, $content, array(), $publish); |
---|
| 1298 | } |
---|
[2566] | 1299 | |
---|
[3730] | 1300 | public function blogger_editPost($appkey, $postid, $username, $password, $content, $publish) |
---|
| 1301 | { |
---|
| 1302 | return $this->editPost($postid, $username, $password, $content, array(), $publish); |
---|
| 1303 | } |
---|
[2566] | 1304 | |
---|
[3730] | 1305 | public function blogger_getPost($appkey, $postid, $username, $password) |
---|
| 1306 | { |
---|
| 1307 | return $this->getPost($postid, $username, $password, 'blogger'); |
---|
| 1308 | } |
---|
[2566] | 1309 | |
---|
[3730] | 1310 | public function blogger_deletePost($appkey, $postid, $username, $password, $publish) |
---|
| 1311 | { |
---|
| 1312 | return $this->deletePost($postid, $username, $password); |
---|
| 1313 | } |
---|
[2566] | 1314 | |
---|
[3730] | 1315 | public function blogger_getRecentPosts($appkey, $blogid, $username, $password, $numberOfPosts) |
---|
| 1316 | { |
---|
| 1317 | return $this->getRecentPosts($blogid, $username, $password, $numberOfPosts, 'blogger'); |
---|
| 1318 | } |
---|
[2566] | 1319 | |
---|
[3730] | 1320 | public function blogger_getUserBlogs($appkey, $username, $password) |
---|
| 1321 | { |
---|
| 1322 | return $this->getUserBlogs($username, $password); |
---|
| 1323 | } |
---|
[2566] | 1324 | |
---|
[3730] | 1325 | public function blogger_getUserInfo($appkey, $username, $password) |
---|
| 1326 | { |
---|
| 1327 | return $this->getUserInfo($username, $password); |
---|
| 1328 | } |
---|
[2566] | 1329 | |
---|
[3730] | 1330 | /* Metaweblog methods |
---|
| 1331 | ------------------------------------------------------- */ |
---|
| 1332 | public function mw_newPost($blogid, $username, $password, $content, $publish) |
---|
| 1333 | { |
---|
| 1334 | return $this->newPost($blogid, $username, $password, '', $content, $publish); |
---|
| 1335 | } |
---|
[2566] | 1336 | |
---|
[3730] | 1337 | public function mw_editPost($postid, $username, $password, $content, $publish) |
---|
| 1338 | { |
---|
| 1339 | return $this->editPost($postid, $username, $password, '', $content, $publish); |
---|
| 1340 | } |
---|
[2566] | 1341 | |
---|
[3730] | 1342 | public function mw_getPost($postid, $username, $password) |
---|
| 1343 | { |
---|
| 1344 | return $this->getPost($postid, $username, $password, 'mw'); |
---|
| 1345 | } |
---|
[2566] | 1346 | |
---|
[3730] | 1347 | public function mw_getRecentPosts($blogid, $username, $password, $numberOfPosts) |
---|
| 1348 | { |
---|
| 1349 | return $this->getRecentPosts($blogid, $username, $password, $numberOfPosts, 'mw'); |
---|
| 1350 | } |
---|
[2566] | 1351 | |
---|
[3730] | 1352 | public function mw_getCategories($blogid, $username, $password) |
---|
| 1353 | { |
---|
| 1354 | return $this->getCategories($blogid, $username, $password); |
---|
| 1355 | } |
---|
[2566] | 1356 | |
---|
[3730] | 1357 | public function mw_newMediaObject($blogid, $username, $password, $file) |
---|
| 1358 | { |
---|
| 1359 | return $this->newMediaObject($blogid, $username, $password, $file); |
---|
| 1360 | } |
---|
[2566] | 1361 | |
---|
[3730] | 1362 | /* MovableType methods |
---|
| 1363 | --------------------------------------------------- */ |
---|
| 1364 | public function mt_getRecentPostTitles($blogid, $username, $password, $numberOfPosts) |
---|
| 1365 | { |
---|
| 1366 | return $this->getRecentPosts($blogid, $username, $password, $numberOfPosts, 'mt'); |
---|
| 1367 | } |
---|
[2566] | 1368 | |
---|
[3730] | 1369 | public function mt_getCategoryList($blogid, $username, $password) |
---|
| 1370 | { |
---|
| 1371 | return $this->getCategories($blogid, $username, $password); |
---|
| 1372 | } |
---|
[2566] | 1373 | |
---|
[3730] | 1374 | public function mt_getPostCategories($postid, $username, $password) |
---|
| 1375 | { |
---|
| 1376 | return $this->getPostCategories($postid, $username, $password); |
---|
| 1377 | } |
---|
[2566] | 1378 | |
---|
[3730] | 1379 | public function mt_setPostCategories($postid, $username, $password, $categories) |
---|
| 1380 | { |
---|
| 1381 | return $this->setPostCategories($postid, $username, $password, $categories); |
---|
| 1382 | } |
---|
[2566] | 1383 | |
---|
[3730] | 1384 | public function mt_publishPost($postid, $username, $password) |
---|
| 1385 | { |
---|
| 1386 | return $this->publishPost($postid, $username, $password); |
---|
| 1387 | } |
---|
[2566] | 1388 | |
---|
[3730] | 1389 | public function mt_supportedTextFilters() |
---|
| 1390 | { |
---|
| 1391 | return array(); |
---|
| 1392 | } |
---|
[2566] | 1393 | |
---|
[3730] | 1394 | /* WordPress methods |
---|
| 1395 | --------------------------------------------------- */ |
---|
| 1396 | public function wp_getUsersBlogs($username, $password) |
---|
| 1397 | { |
---|
| 1398 | return $this->getUserBlogs($username, $password); |
---|
| 1399 | } |
---|
[2566] | 1400 | |
---|
[3730] | 1401 | public function wp_getPage($blogid, $pageid, $username, $password) |
---|
| 1402 | { |
---|
| 1403 | $res = $this->getPages($blogid, $username, $password, null, $pageid); |
---|
[2566] | 1404 | |
---|
[3730] | 1405 | if (empty($res)) { |
---|
| 1406 | throw new Exception('Sorry, no such page', 404); |
---|
| 1407 | } |
---|
[2566] | 1408 | |
---|
[3730] | 1409 | return $res[0]; |
---|
| 1410 | } |
---|
[2566] | 1411 | |
---|
[3730] | 1412 | public function wp_getPages($blogid, $username, $password, $num = 10) |
---|
| 1413 | { |
---|
| 1414 | return $this->getPages($blogid, $username, $password, $num); |
---|
| 1415 | } |
---|
[2566] | 1416 | |
---|
[3730] | 1417 | public function wp_newPage($blogid, $username, $password, $content, $publish) |
---|
| 1418 | { |
---|
| 1419 | return $this->newPage($blogid, $username, $password, $content, $publish); |
---|
| 1420 | } |
---|
[2566] | 1421 | |
---|
[3730] | 1422 | public function wp_deletePage($blogid, $username, $password, $pageid) |
---|
| 1423 | { |
---|
| 1424 | return $this->deletePage($pageid, $username, $password); |
---|
| 1425 | } |
---|
[2566] | 1426 | |
---|
[3730] | 1427 | public function wp_editPage($blogid, $pageid, $username, $password, $content, $publish) |
---|
| 1428 | { |
---|
| 1429 | return $this->editPage($pageid, $username, $password, $content, $publish); |
---|
| 1430 | } |
---|
[2566] | 1431 | |
---|
[3730] | 1432 | public function wp_getPageList($blogid, $username, $password) |
---|
| 1433 | { |
---|
| 1434 | $A = $this->getPages($blogid, $username, $password); |
---|
| 1435 | $res = array(); |
---|
| 1436 | foreach ($A as $v) { |
---|
| 1437 | $res[] = array( |
---|
| 1438 | 'page_id' => $v['page_id'], |
---|
| 1439 | 'page_title' => $v['title'], |
---|
| 1440 | 'page_parent_id' => $v['wp_page_parent_id'], |
---|
| 1441 | 'dateCreated' => $v['dateCreated'], |
---|
| 1442 | 'date_created_gmt' => $v['date_created_gmt'] |
---|
| 1443 | ); |
---|
| 1444 | } |
---|
| 1445 | return $res; |
---|
| 1446 | } |
---|
[2566] | 1447 | |
---|
[3730] | 1448 | public function wp_getAuthors($blogid, $username, $password) |
---|
| 1449 | { |
---|
| 1450 | return $this->getAuthors($username, $password); |
---|
| 1451 | } |
---|
[2566] | 1452 | |
---|
[3730] | 1453 | public function wp_getCategories($blogid, $username, $password) |
---|
| 1454 | { |
---|
| 1455 | return $this->getCategories($blogid, $username, $password); |
---|
| 1456 | } |
---|
[2566] | 1457 | |
---|
[3730] | 1458 | public function wp_getTags($blogid, $username, $password) |
---|
| 1459 | { |
---|
| 1460 | return $this->getTags($username, $password); |
---|
| 1461 | } |
---|
[2566] | 1462 | |
---|
[3730] | 1463 | public function wp_newCategory($blogid, $username, $password, $content) |
---|
| 1464 | { |
---|
| 1465 | return $this->newCategory($username, $password, $content); |
---|
| 1466 | } |
---|
[2566] | 1467 | |
---|
[3730] | 1468 | public function wp_deleteCategory($blogid, $username, $password, $categoryid) |
---|
| 1469 | { |
---|
| 1470 | return $this->deleteCategory($username, $password, $categoryid); |
---|
| 1471 | } |
---|
[2566] | 1472 | |
---|
[3730] | 1473 | public function wp_suggestCategories($blogid, $username, $password, $category, $max_results = 0) |
---|
| 1474 | { |
---|
| 1475 | return $this->searchCategories($username, $password, $category, $max_results); |
---|
| 1476 | } |
---|
[2566] | 1477 | |
---|
[3730] | 1478 | public function wp_uploadFile($blogid, $username, $password, $file) |
---|
| 1479 | { |
---|
| 1480 | return $this->newMediaObject($blogid, $username, $password, $file); |
---|
| 1481 | } |
---|
[2566] | 1482 | |
---|
[3730] | 1483 | public function wp_getPostStatusList($blogid, $username, $password) |
---|
| 1484 | { |
---|
| 1485 | return $this->getPostStatusList($blogid, $username, $password); |
---|
| 1486 | } |
---|
[2566] | 1487 | |
---|
[3730] | 1488 | public function wp_getPageStatusList($blogid, $username, $password) |
---|
| 1489 | { |
---|
| 1490 | return $this->getPostStatusList($blogid, $username, $password); |
---|
| 1491 | } |
---|
[2566] | 1492 | |
---|
[3730] | 1493 | public function wp_getPageTemplates($blogid, $username, $password) |
---|
| 1494 | { |
---|
| 1495 | return array('Default' => 'default'); |
---|
| 1496 | } |
---|
[2566] | 1497 | |
---|
[3730] | 1498 | public function wp_getOptions($blogid, $username, $password, $options = array()) |
---|
| 1499 | { |
---|
| 1500 | $this->setUser($username, $password); |
---|
| 1501 | $this->setBlog(); |
---|
[2566] | 1502 | |
---|
[3730] | 1503 | return $this->translateWpOptions($options); |
---|
| 1504 | } |
---|
[2566] | 1505 | |
---|
[3730] | 1506 | public function wp_setOptions($blogid, $username, $password, $options) |
---|
| 1507 | { |
---|
| 1508 | $this->setUser($username, $password); |
---|
| 1509 | $this->setBlog(); |
---|
[2566] | 1510 | |
---|
[3730] | 1511 | if (!$this->core->auth->check('admin', $this->core->blog->id)) { |
---|
| 1512 | throw new Exception('Not enough permissions to edit options.', 401); |
---|
| 1513 | } |
---|
[2566] | 1514 | |
---|
[3730] | 1515 | $opt = $this->translateWpOptions(); |
---|
[2566] | 1516 | |
---|
[3730] | 1517 | $done = array(); |
---|
| 1518 | $blog_changes = false; |
---|
| 1519 | $cur = $this->core->con->openCursor($this->core->prefix . 'blog'); |
---|
[2566] | 1520 | |
---|
[3730] | 1521 | $this->core->blog->settings->addNamespace('system'); |
---|
[2566] | 1522 | |
---|
[3730] | 1523 | foreach ($options as $name => $value) { |
---|
| 1524 | if (!isset($opt[$name]) || $opt[$name]['readonly']) { |
---|
| 1525 | continue; |
---|
| 1526 | } |
---|
[2566] | 1527 | |
---|
[3730] | 1528 | switch ($name) { |
---|
| 1529 | case 'blog_title': |
---|
| 1530 | $blog_changes = true; |
---|
| 1531 | $cur->blog_name = $value; |
---|
| 1532 | $done[] = $name; |
---|
| 1533 | break; |
---|
| 1534 | case 'blog_tagline': |
---|
| 1535 | $blog_changes = true; |
---|
| 1536 | $cur->blog_desc = $value; |
---|
| 1537 | $done[] = $name; |
---|
| 1538 | break; |
---|
| 1539 | case 'date_format': |
---|
| 1540 | $this->core->blog->settings->system->put('date_format', $value); |
---|
| 1541 | $done[] = $name; |
---|
| 1542 | break; |
---|
| 1543 | case 'time_format': |
---|
| 1544 | $this->core->blog->settings->system->put('time_format', $value); |
---|
| 1545 | $done[] = $name; |
---|
| 1546 | break; |
---|
| 1547 | } |
---|
| 1548 | } |
---|
[2566] | 1549 | |
---|
[3730] | 1550 | if ($blog_changes) { |
---|
| 1551 | $this->core->updBlog($this->core->blog->id, $cur); |
---|
| 1552 | $this->core->setBlog($this->core->blog->id); |
---|
| 1553 | } |
---|
[2566] | 1554 | |
---|
[3730] | 1555 | return $this->translateWpOptions($done); |
---|
| 1556 | } |
---|
[2566] | 1557 | |
---|
[3730] | 1558 | public function wp_getComment($blogid, $username, $password, $commentid) |
---|
| 1559 | { |
---|
| 1560 | $res = $this->getComments($username, $password, array(), $commentid); |
---|
[2566] | 1561 | |
---|
[3730] | 1562 | if (empty($res)) { |
---|
| 1563 | throw new Exception('Sorry, no such comment', 404); |
---|
| 1564 | } |
---|
[2566] | 1565 | |
---|
[3730] | 1566 | return $res[0]; |
---|
| 1567 | } |
---|
[2566] | 1568 | |
---|
[3730] | 1569 | public function wp_getCommentCount($blogid, $username, $password, $postid) |
---|
| 1570 | { |
---|
| 1571 | return $this->countComments($username, $password, $postid); |
---|
| 1572 | } |
---|
[2566] | 1573 | |
---|
[3730] | 1574 | public function wp_getComments($blogid, $username, $password, $struct) |
---|
| 1575 | { |
---|
| 1576 | return $this->getComments($username, $password, $struct); |
---|
| 1577 | } |
---|
[2566] | 1578 | |
---|
[3730] | 1579 | public function wp_deleteComment($blogid, $username, $password, $commentid) |
---|
| 1580 | { |
---|
| 1581 | return $this->delComment($username, $password, $commentid); |
---|
| 1582 | } |
---|
[2566] | 1583 | |
---|
[3730] | 1584 | public function wp_editComment($blogid, $username, $password, $commentid, $content) |
---|
| 1585 | { |
---|
| 1586 | return $this->updComment($username, $password, $commentid, $content); |
---|
| 1587 | } |
---|
[2566] | 1588 | |
---|
[3730] | 1589 | public function wp_newComment($blogid, $username, $password, $postid, $content) |
---|
| 1590 | { |
---|
| 1591 | return $this->addComment($username, $password, $postid, $content); |
---|
| 1592 | } |
---|
[2566] | 1593 | |
---|
[3730] | 1594 | public function wp_getCommentStatusList($blogid, $username, $password) |
---|
| 1595 | { |
---|
| 1596 | $this->setUser($username, $password); |
---|
| 1597 | $this->setBlog(); |
---|
[2566] | 1598 | |
---|
[3730] | 1599 | return array( |
---|
| 1600 | 'hold' => 'Unapproved', |
---|
| 1601 | 'approve' => 'Approved', |
---|
| 1602 | 'spam' => 'Spam' |
---|
| 1603 | ); |
---|
| 1604 | } |
---|
[2566] | 1605 | |
---|
[3730] | 1606 | /* Pingback support |
---|
| 1607 | --------------------------------------------------- */ |
---|
| 1608 | public function pingback_ping($from_url, $to_url) |
---|
| 1609 | { |
---|
| 1610 | dcTrackback::checkURLs($from_url, $to_url); |
---|
[2566] | 1611 | |
---|
[3730] | 1612 | $args = array('type' => 'pingback', 'from_url' => $from_url, 'to_url' => $to_url); |
---|
[1674] | 1613 | |
---|
[3730] | 1614 | # Time to get things done... |
---|
| 1615 | $this->setBlog(true); |
---|
[1687] | 1616 | |
---|
[3730] | 1617 | # --BEHAVIOR-- publicBeforeReceiveTrackback |
---|
| 1618 | $this->core->callBehavior('publicBeforeReceiveTrackback', $this->core, $args); |
---|
[2566] | 1619 | |
---|
[3730] | 1620 | $tb = new dcTrackback($this->core); |
---|
| 1621 | return $tb->receivePingback($from_url, $to_url); |
---|
| 1622 | } |
---|
[0] | 1623 | } |
---|