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