Changeset 2566:9bf417837888 for inc/core/class.dc.xmlrpc.php
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- File:
-
- 1 edited
-
inc/core/class.dc.xmlrpc.php (modified) (71 diffs)
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.xmlrpc.php
r1968 r2566 21 21 private $trace_args = true; 22 22 private $trace_response = true; 23 23 24 24 public function __construct($core,$blog_id) 25 25 { 26 26 parent::__construct(); 27 27 28 28 $this->core =& $core; 29 29 $this->blog_id = $blog_id; 30 30 31 31 # Blogger methods 32 32 $this->addCallback('blogger.newPost',array($this,'blogger_newPost'), 33 33 array('string','string','string','string','string','string','integer'), 34 34 'New post'); 35 35 36 36 $this->addCallback('blogger.editPost',array($this,'blogger_editPost'), 37 37 array('boolean','string','string','string','string','string','integer'), 38 38 'Edit a post'); 39 39 40 40 $this->addCallback('blogger.getPost',array($this,'blogger_getPost'), 41 41 array('struct','string','integer','string','string'), 42 42 'Return a posts by ID'); 43 43 44 44 $this->addCallback('blogger.deletePost',array($this,'blogger_deletePost'), 45 45 array('string','string','string','string','string','integer'), 46 46 'Delete a post'); 47 47 48 48 $this->addCallback('blogger.getRecentPosts',array($this,'blogger_getRecentPosts'), 49 49 array('array','string','string','string','string','integer'), 50 50 'Return a list of recent posts'); 51 51 52 52 $this->addCallback('blogger.getUsersBlogs',array($this,'blogger_getUserBlogs'), 53 53 array('struct','string','string','string'), 54 54 "Return user's blog"); 55 55 56 56 $this->addCallback('blogger.getUserInfo',array($this,'blogger_getUserInfo'), 57 57 array('struct','string','string','string'), 58 58 'Return User Info'); 59 59 60 60 # Metaweblog methods 61 61 $this->addCallback('metaWeblog.newPost',array($this,'mw_newPost'), 62 62 array('string','string','string','string','struct','boolean'), 63 63 'Creates a new post, and optionnaly publishes it.'); 64 64 65 65 $this->addCallback('metaWeblog.editPost',array($this,'mw_editPost'), 66 66 array('boolean','string','string','string','struct','boolean'), 67 67 'Updates information about an existing entry'); 68 68 69 69 $this->addCallback('metaWeblog.getPost',array($this,'mw_getPost'), 70 70 array('struct','string','string','string'), 71 71 'Returns information about a specific post'); 72 72 73 73 $this->addCallback('metaWeblog.getRecentPosts',array($this,'mw_getRecentPosts'), 74 74 array('array','string','string','string','integer'), 75 75 'List of most recent posts in the system'); 76 76 77 77 $this->addCallback('metaWeblog.getCategories',array($this,'mw_getCategories'), 78 78 array('array','string','string','string'), 79 79 'List of all categories defined in the weblog'); 80 80 81 81 $this->addCallback('metaWeblog.newMediaObject',array($this,'mw_newMediaObject'), 82 82 array('struct','string','string','string','struct'), 83 83 'Upload a file on the web server'); 84 84 85 85 # MovableType methods 86 86 $this->addCallback('mt.getRecentPostTitles',array($this,'mt_getRecentPostTitles'), 87 87 array('array','string','string','string','integer'), 88 88 'List of most recent posts in the system'); 89 89 90 90 $this->addCallback('mt.getCategoryList',array($this,'mt_getCategoryList'), 91 91 array('array','string','string','string'), 92 92 'List of all categories defined in the weblog'); 93 93 94 94 $this->addCallback('mt.getPostCategories',array($this,'mt_getPostCategories'), 95 95 array('array','string','string','string'), 96 96 'List of all categories to which the post is assigned'); 97 97 98 98 $this->addCallback('mt.setPostCategories',array($this,'mt_setPostCategories'), 99 99 array('boolean','string','string','string','array'), 100 100 'Sets the categories for a post'); 101 101 102 102 $this->addCallback('mt.publishPost',array($this,'mt_publishPost'), 103 103 array('boolean','string','string','string'), 104 104 'Retrieve pings list for a post'); 105 105 106 106 $this->addCallback('mt.supportedMethods',array($this,'listMethods'), 107 107 array(),'Retrieve information about the XML-RPC methods supported by the server.'); 108 108 109 109 $this->addCallback('mt.supportedTextFilters',array($this,'mt_supportedTextFilters'), 110 110 array(),'Retrieve information about supported text filters.'); 111 111 112 112 # WordPress methods 113 113 $this->addCallback('wp.getUsersBlogs',array($this,'wp_getUsersBlogs'), 114 114 array('array','string','string'), 115 115 'Retrieve the blogs of the user.'); 116 116 117 117 $this->addCallback('wp.getPage',array($this,'wp_getPage'), 118 118 array('struct','integer','integer','string','string'), 119 119 'Get the page identified by the page ID.'); 120 120 121 121 $this->addCallback('wp.getPages',array($this,'wp_getPages'), 122 122 array('array','integer','string','string','integer'), 123 123 'Get an array of all the pages on a blog.'); 124 124 125 125 $this->addCallback('wp.newPage',array($this,'wp_newPage'), 126 126 array('integer','integer','string','string','struct','boolean'), 127 127 'Create a new page.'); 128 128 129 129 $this->addCallback('wp.deletePage',array($this,'wp_deletePage'), 130 130 array('boolean','integer','string','string','integer'), 131 131 'Removes a page from the blog.'); 132 132 133 133 $this->addCallback('wp.editPage',array($this,'wp_editPage'), 134 134 array('boolean','integer','integer','string','string','struct','boolean'), 135 135 'Make changes to a blog page.'); 136 136 137 137 $this->addCallback('wp.getPageList',array($this,'wp_getPageList'), 138 138 array('array','integer','string','string'), 139 139 'Get an array of all the pages on a blog. Just the minimum details, lighter than wp.getPages.'); 140 140 141 141 $this->addCallback('wp.getAuthors',array($this,'wp_getAuthors'), 142 142 array('array','integer','string','string'), 143 143 'Get an array of users for the blog.'); 144 144 145 145 $this->addCallback('wp.getCategories',array($this,'wp_getCategories'), 146 146 array('array','integer','string','string'), 147 147 'Get an array of available categories on a blog.'); 148 148 149 149 $this->addCallback('wp.getTags',array($this,'wp_getTags'), 150 150 array('array','integer','string','string'), 151 151 'Get list of all tags for the blog.'); 152 152 153 153 $this->addCallback('wp.newCategory',array($this,'wp_newCategory'), 154 154 array('integer','integer','string','string','struct'), 155 155 'Create a new category.'); 156 156 157 157 $this->addCallback('wp.deleteCategory',array($this,'wp_deleteCategory'), 158 158 array('boolean','integer','string','string','integer'), 159 159 'Delete a category with a given ID.'); 160 160 161 161 $this->addCallback('wp.suggestCategories',array($this,'wp_suggestCategories'), 162 162 array('array','integer','string','string','string','integer'), 163 163 'Get an array of categories that start with a given string.'); 164 164 165 165 $this->addCallback('wp.uploadFile',array($this,'wp_uploadFile'), 166 166 array('struct','integer','string','string','struct'), 167 167 'Upload a file'); 168 168 169 169 $this->addCallback('wp.getPostStatusList',array($this,'wp_getPostStatusList'), 170 170 array('array','integer','string','string'), 171 171 'Retrieve all of the post statuses.'); 172 172 173 173 $this->addCallback('wp.getPageStatusList',array($this,'wp_getPageStatusList'), 174 174 array('array','integer','string','string'), 175 175 'Retrieve all of the pages statuses.'); 176 176 177 177 $this->addCallback('wp.getPageTemplates',array($this,'wp_getPageTemplates'), 178 178 array('struct','integer','string','string'), 179 179 'Retrieve page templates.'); 180 180 181 181 $this->addCallback('wp.getOptions',array($this,'wp_getOptions'), 182 182 array('struct','integer','string','string','array'), 183 183 'Retrieve blog options'); 184 184 185 185 $this->addCallback('wp.setOptions',array($this,'wp_setOptions'), 186 186 array('struct','integer','string','string','struct'), 187 187 'Update blog options'); 188 188 189 189 $this->addCallback('wp.getComment',array($this,'wp_getComment'), 190 190 array('struct','integer','string','string','integer'), 191 191 "Gets a comment, given it's comment ID."); 192 192 193 193 $this->addCallback('wp.getCommentCount',array($this,'wp_getCommentCount'), 194 194 array('array','integer','string','string','integer'), 195 195 'Retrieve comment count.'); 196 196 197 197 $this->addCallback('wp.getComments',array($this,'wp_getComments'), 198 198 array('array','integer','string','string','struct'), 199 199 'Gets a set of comments for a given post.'); 200 200 201 201 $this->addCallback('wp.deleteComment',array($this,'wp_deleteComment'), 202 202 array('boolean','integer','string','string','integer'), 203 203 'Delete a comment with given ID.'); 204 204 205 205 $this->addCallback('wp.editComment',array($this,'wp_editComment'), 206 206 array('boolean','integer','string','string','integer','struct'), 207 207 'Edit a comment with given ID.'); 208 208 209 209 $this->addCallback('wp.newComment',array($this,'wp_newComment'), 210 210 array('integer','integer','string','string','integer','struct'), 211 211 'Create a new comment for a given post ID.'); 212 212 213 213 $this->addCallback('wp.getCommentStatusList',array($this,'wp_getCommentStatusList'), 214 214 array('array','integer','string','string'), 215 215 'Retrieve all of the comment statuses.'); 216 216 217 217 # Pingback support 218 218 $this->addCallback('pingback.ping',array($this,'pingback_ping'), … … 220 220 'Notify a link to a post.'); 221 221 } 222 222 223 223 public function serve($data=false,$encoding='UTF-8') 224 224 { 225 225 parent::serve(false,$encoding); 226 226 } 227 227 228 228 public function call($methodname,$args) 229 229 { … … 237 237 } 238 238 } 239 239 240 240 private function debugTrace($methodname,$args,$rsp) 241 241 { … … 243 243 return; 244 244 } 245 245 246 246 if (($fp = @fopen($this->debug_file,'a')) !== false) 247 247 { 248 248 fwrite($fp,'['.date('r').']'.' '.$methodname); 249 249 250 250 if ($this->trace_args) { 251 251 fwrite($fp,"\n- args ---\n".var_export($args,1)); 252 252 } 253 253 254 254 if ($this->trace_response) { 255 255 fwrite($fp,"\n- response ---\n".var_export($rsp,1)); … … 259 259 } 260 260 } 261 261 262 262 /* Internal methods 263 263 --------------------------------------------------- */ … … 267 267 return true; 268 268 } 269 269 270 270 if ($this->core->auth->checkUser($user_id,$pwd) !== true) { 271 271 throw new Exception('Login error'); 272 272 } 273 273 274 274 return true; 275 275 } 276 276 277 277 private function setBlog($bypass = false) 278 278 { … … 280 280 throw new Exception('No blog ID given.'); 281 281 } 282 282 283 283 if ($this->blog_loaded) { 284 284 return true; 285 285 } 286 286 287 287 $this->core->setBlog($this->blog_id); 288 288 $this->blog_loaded = true; 289 289 290 290 if (!$this->core->blog->id) { 291 291 $this->core->blog = null; 292 292 throw new Exception('Blog does not exist.'); 293 293 } 294 294 295 295 if (!$bypass && 296 296 (!$this->core->blog->settings->system->enable_xmlrpc || … … 299 299 throw new Exception('Not enough permissions on this blog.'); 300 300 } 301 301 302 302 foreach ($this->core->plugins->getModules() as $id => $m) { 303 303 $this->core->plugins->loadNsFile($id,'xmlrpc'); 304 304 } 305 305 306 306 return true; 307 307 } 308 308 309 309 private function getPostRS($post_id,$user,$pwd,$post_type='post') 310 310 { … … 315 315 'post_type' => $post_type 316 316 )); 317 317 318 318 if ($rs->isEmpty()) { 319 319 throw new Exception('This entry does not exist'); 320 320 } 321 321 322 322 return $rs; 323 323 } 324 324 325 325 private function getCatID($cat_url) 326 326 { 327 327 $rs = $this->core->blog->getCategories(array('cat_url' => $cat_url)); 328 328 329 329 return $rs->isEmpty() ? null : $rs->cat_id; 330 330 } 331 331 332 332 /* Generic methods 333 333 --------------------------------------------------- */ … … 336 336 $this->setUser($user,$pwd); 337 337 $this->setBlog(); 338 338 339 339 $title = !empty($struct['title']) ? $struct['title'] : ''; 340 340 $excerpt = !empty($struct['mt_excerpt']) ? $struct['mt_excerpt'] : ''; … … 343 343 $open_comment = isset($struct['mt_allow_comments']) ? $struct['mt_allow_comments'] : 1; 344 344 $open_tb = isset($struct['mt_allow_pings']) ? $struct['mt_allow_pings'] : 1; 345 345 346 346 if ($description !== null) { 347 347 $content = $description; 348 348 } 349 349 350 350 if (!$title) { 351 351 $title = text::cutString(html::clean($content),25).'...'; 352 352 } 353 353 354 354 $excerpt_xhtml = $this->core->callFormater('xhtml',$excerpt); 355 355 $content_xhtml = $this->core->callFormater('xhtml',$content); 356 356 357 357 if (empty($content)) { 358 358 throw new Exception('Cannot create an empty entry'); 359 359 } 360 360 361 361 $cur = $this->core->con->openCursor($this->core->prefix.'post'); 362 362 363 363 $cur->user_id = $this->core->auth->userID(); 364 364 $cur->post_lang = $this->core->auth->getInfo('user_lang'); … … 372 372 $cur->post_status = (integer) $publish; 373 373 $cur->post_format = 'xhtml'; 374 374 375 375 if ($dateCreated) { 376 376 if ($dateCreated instanceof xmlrpcDate) { … … 380 380 } 381 381 } 382 382 383 383 # Categories in an array 384 384 if (isset($struct['categories']) && is_array($struct['categories'])) … … 386 386 $categories = $struct['categories']; 387 387 $cat_id = !empty($categories[0]) ? $categories[0] : null; 388 388 389 389 $cur->cat_id = $this->getCatID($cat_id); 390 390 } 391 391 392 392 if (isset($struct['wp_slug'])) { 393 393 $cur->post_url = $struct['wp_slug']; 394 394 } 395 395 396 396 if (isset($struct['wp_password'])) { 397 397 $cur->post_password = $struct['wp_password']; 398 398 } 399 399 400 400 $cur->post_type = 'post'; 401 401 if (!empty($struct['post_type'])) { 402 402 $cur->post_type = $struct['post_type']; 403 403 } 404 404 405 405 if ($cur->post_type == 'post') 406 406 { 407 407 # --BEHAVIOR-- xmlrpcBeforeNewPost 408 408 $this->core->callBehavior('xmlrpcBeforeNewPost',$this,$cur,$content,$struct,$publish); 409 409 410 410 $post_id = $this->core->blog->addPost($cur); 411 411 412 412 # --BEHAVIOR-- xmlrpcAfterNewPost 413 413 $this->core->callBehavior('xmlrpcAfterNewPost',$this,$post_id,$cur,$content,$struct,$publish); … … 418 418 $cur->post_position = (integer) $struct['wp_page_order']; 419 419 } 420 420 421 421 $this->core->blog->settings->system->post_url_format = '{t}'; 422 422 423 423 $post_id = $this->core->blog->addPost($cur); 424 424 } … … 427 427 throw new Exception('Invalid post type',401); 428 428 } 429 429 430 430 return (string) $post_id; 431 431 } 432 432 433 433 private function editPost($post_id,$user,$pwd,$content,$struct=array(),$publish=true) 434 434 { 435 435 $post_id = (integer) $post_id; 436 436 437 437 $post_type = 'post'; 438 438 if (!empty($struct['post_type'])) { 439 439 $post_type = $struct['post_type']; 440 440 } 441 441 442 442 $post = $this->getPostRS($post_id,$user,$pwd,$post_type); 443 443 444 444 $title = (!empty($struct['title'])) ? $struct['title'] : ''; 445 445 $excerpt = (!empty($struct['mt_excerpt'])) ? $struct['mt_excerpt'] : ''; … … 448 448 $open_comment = (isset($struct['mt_allow_comments'])) ? $struct['mt_allow_comments'] : 1; 449 449 $open_tb = (isset($struct['mt_allow_pings'])) ? $struct['mt_allow_pings'] : 1; 450 450 451 451 if ($description !== null) { 452 452 $content = $description; 453 453 } 454 454 455 455 if (!$title) { 456 456 $title = text::cutString(html::clean($content),25).'...'; 457 457 } 458 458 459 459 $excerpt_xhtml = $this->core->callFormater('xhtml',$excerpt); 460 460 $content_xhtml = $this->core->callFormater('xhtml',$content); 461 461 462 462 if (empty($content)) { 463 463 throw new Exception('Cannot create an empty entry'); 464 464 } 465 465 466 466 $cur = $this->core->con->openCursor($this->core->prefix.'post'); 467 467 468 468 $cur->post_type = $post_type; 469 469 $cur->post_title = trim($title); … … 477 477 $cur->post_format = 'xhtml'; 478 478 $cur->post_url = $post->post_url; 479 480 479 480 481 481 if ($dateCreated) { 482 482 if ($dateCreated instanceof xmlrpcDate) { … … 488 488 $cur->post_dt = $post->post_dt; 489 489 } 490 490 491 491 # Categories in an array 492 492 if (isset($struct['categories']) && is_array($struct['categories'])) … … 494 494 $categories = $struct['categories']; 495 495 $cat_id = !empty($categories[0]) ? $categories[0] : null; 496 496 497 497 $cur->cat_id = $this->getCatID($cat_id); 498 498 } 499 499 500 500 if (isset($struct['wp_slug'])) { 501 501 $cur->post_url = $struct['wp_slug']; 502 502 } 503 503 504 504 if (isset($struct['wp_password'])) { 505 505 $cur->post_password = $struct['wp_password']; 506 506 } 507 507 508 508 if ($cur->post_type == 'post') 509 509 { 510 510 # --BEHAVIOR-- xmlrpcBeforeEditPost 511 511 $this->core->callBehavior('xmlrpcBeforeEditPost',$this,$post_id,$cur,$content,$struct,$publish); 512 512 513 513 $this->core->blog->updPost($post_id,$cur); 514 514 515 515 # --BEHAVIOR-- xmlrpcAfterEditPost 516 516 $this->core->callBehavior('xmlrpcAfterEditPost',$this,$post_id,$cur,$content,$struct,$publish); … … 521 521 $cur->post_position = (integer) $struct['wp_page_order']; 522 522 } 523 523 524 524 $this->core->blog->settings->system->post_url_format = '{t}'; 525 525 526 526 $this->core->blog->updPost($post_id,$cur); 527 527 } … … 530 530 throw new Exception('Invalid post type',401); 531 531 } 532 532 533 533 return true; 534 534 } 535 535 536 536 private function getPost($post_id,$user,$pwd,$type='mw') 537 537 { 538 538 $post_id = (integer) $post_id; 539 539 540 540 $post = $this->getPostRS($post_id,$user,$pwd); 541 541 542 542 $res = new ArrayObject(); 543 543 544 544 $res['dateCreated'] = new xmlrpcDate($post->getTS()); 545 545 $res['userid'] = $post->user_id; 546 546 $res['postid'] = $post->post_id; 547 547 548 548 if ($post->cat_id) { 549 549 $res['categories'] = array($post->cat_url); 550 550 } 551 551 552 552 if ($type == 'blogger') { 553 553 $res['content'] = $post->post_content_xhtml; 554 554 } 555 555 556 556 if ($type == 'mt' || $type == 'mw') { 557 557 $res['title'] = $post->post_title; 558 558 } 559 559 560 560 if ($type == 'mw') { 561 561 $res['description'] = $post->post_content_xhtml; … … 568 568 $res['mt_keywords'] = ''; 569 569 } 570 570 571 571 # --BEHAVIOR-- xmlrpcGetPostInfo 572 572 $this->core->callBehavior('xmlrpcGetPostInfo',$this,$type,array(&$res)); 573 573 574 574 return $res; 575 575 } 576 576 577 577 private function deletePost($post_id,$user,$pwd) 578 578 { 579 579 $post_id = (integer) $post_id; 580 580 581 581 $this->getPostRS($post_id,$user,$pwd); 582 582 $this->core->blog->delPost($post_id); 583 583 584 584 return true; 585 585 } 586 586 587 587 private function getRecentPosts($blog_id,$user,$pwd,$nb_post,$type='mw') 588 588 { 589 589 $this->setUser($user,$pwd); 590 590 $this->setBlog(); 591 591 592 592 $nb_post = (integer) $nb_post; 593 593 594 594 if ($nb_post > 50) { 595 595 throw new Exception('Cannot retrieve more than 50 entries'); 596 596 } 597 597 598 598 $params = array(); 599 599 $params['limit'] = $nb_post; 600 600 601 601 $posts = $this->core->blog->getPosts($params); 602 602 603 603 $res = array(); 604 604 while ($posts->fetch()) 605 605 { 606 606 $tres = array(); 607 607 608 608 $tres['dateCreated'] = new xmlrpcDate($posts->getTS()); 609 609 $tres['userid'] = $posts->user_id; 610 610 $tres['postid'] = $posts->post_id; 611 611 612 612 if ($posts->cat_id) { 613 613 $tres['categories'] = array($posts->cat_url); 614 614 } 615 615 616 616 if ($type == 'blogger') { 617 617 $tres['content'] = $posts->post_content_xhtml; 618 618 } 619 619 620 620 if ($type == 'mt' || $type == 'mw') { 621 621 $tres['title'] = $posts->post_title; 622 622 } 623 623 624 624 if ($type == 'mw') { 625 625 $tres['description'] = $posts->post_content_xhtml; … … 632 632 $tres['mt_keywords'] = ''; 633 633 } 634 634 635 635 # --BEHAVIOR-- xmlrpcGetPostInfo 636 636 $this->core->callBehavior('xmlrpcGetPostInfo',$this,$type,array(&$tres)); 637 637 638 638 $res[] = $tres; 639 639 } 640 640 641 641 return $res; 642 642 } 643 643 644 644 private function getUserBlogs($user,$pwd) 645 645 { 646 646 $this->setUser($user,$pwd); 647 647 $this->setBlog(); 648 648 649 649 return array(array( 650 650 'url' => $this->core->blog->url, … … 653 653 )); 654 654 } 655 655 656 656 private function getUserInfo($user,$pwd) 657 657 { 658 658 $this->setUser($user,$pwd); 659 659 660 660 return array( 661 661 'userid' => $this->core->auth->userID(), … … 667 667 ); 668 668 } 669 669 670 670 private function getCategories($blog_id,$user,$pwd) 671 671 { … … 673 673 $this->setBlog(); 674 674 $rs = $this->core->blog->getCategories(); 675 675 676 676 $res = array(); 677 677 678 678 $l = $rs->level; 679 679 $stack = array('',$rs->cat_url); 680 680 681 681 while ($rs->fetch()) 682 682 { … … 694 694 $parent = end($stack); 695 695 } 696 696 697 697 $res[] = array( 698 698 'categoryId' => $rs->cat_url, … … 705 705 $this->core->url->getURLFor('feed','category/'.$rs->cat_url.'/rss2') 706 706 ); 707 707 708 708 $stack[] = $rs->cat_url; 709 709 $l = $rs->level; 710 710 } 711 711 712 712 return $res; 713 713 } 714 714 715 715 private function getPostCategories($post_id,$user,$pwd) 716 716 { 717 717 $post_id = (integer) $post_id; 718 718 719 719 $post = $this->getPostRS($post_id,$user,$pwd); 720 720 721 721 return array( 722 722 array( … … 727 727 ); 728 728 } 729 729 730 730 private function setPostCategories($post_id,$user,$pwd,$categories) 731 731 { 732 732 $post_id = (integer) $post_id; 733 733 734 734 $post = $this->getPostRS($post_id,$user,$pwd); 735 735 736 736 $cat_id = (!empty($categories[0]['categoryId'])) ? $categories[0]['categoryId'] : null; 737 737 738 738 foreach($categories as $v) 739 739 { … … 743 743 } 744 744 } 745 745 746 746 # w.bloggar sends -1 for no category. 747 747 if ($cat_id == -1) { 748 748 $cat_id = null; 749 749 } 750 750 751 751 if ($cat_id) { 752 752 $cat_id = $this->getCatID($cat_id); 753 753 } 754 754 755 755 $this->core->blog->updPostCategory($post_id,(integer) $cat_id); 756 756 757 757 return true; 758 758 } 759 759 760 760 private function publishPost($post_id,$user,$pwd) 761 761 { 762 762 $post_id = (integer) $post_id; 763 763 764 764 $this->getPostRS($post_id,$user,$pwd); 765 765 766 766 # --BEHAVIOR-- xmlrpcBeforePublishPost 767 767 $this->core->callBehavior('xmlrpcBeforePublishPost',$this,$post_id); 768 768 769 769 $this->core->blog->updPostStatus($post_id,1); 770 770 771 771 # --BEHAVIOR-- xmlrpcAfterPublishPost 772 772 $this->core->callBehavior('xmlrpcAfterPublishPost',$this,$post_id); 773 773 774 774 return true; 775 775 } 776 776 777 777 private function newMediaObject($blog_id,$user,$pwd,$file) 778 778 { … … 780 780 throw new Exception('No file name'); 781 781 } 782 782 783 783 if (empty($file['bits'])) { 784 784 throw new Exception('No file content'); 785 785 } 786 786 787 787 $file_name = $file['name']; 788 788 $file_bits = base64_decode($file['bits']); 789 790 $this->setUser($user,$pwd); 791 $this->setBlog(); 792 789 790 $this->setUser($user,$pwd); 791 $this->setBlog(); 792 793 793 $media = new dcMedia($this->core); 794 794 795 795 $dir_name = path::clean(dirname($file_name)); 796 796 $file_name = basename($file_name); 797 797 798 798 $dir_name = preg_replace('!^/!','',$dir_name); 799 799 if ($dir_name != '') … … 809 809 } 810 810 } 811 811 812 812 $media_id = $media->uploadBits($file_name,$file_bits); 813 813 814 814 $f = $media->getFile($media_id); 815 815 return array( … … 819 819 ); 820 820 } 821 821 822 822 private function translateWpStatus($s) 823 823 { … … 829 829 'scheduled' => -1 830 830 ); 831 831 832 832 if (is_int($s)) { 833 833 $status = array_flip($status); … … 837 837 } 838 838 } 839 839 840 840 private function translateWpCommentstatus($s) 841 841 { … … 845 845 'spam' => -2 846 846 ); 847 847 848 848 if (is_int($s)) { 849 849 $status = array_flip($status); … … 853 853 } 854 854 } 855 855 856 856 private function translateWpOptions($options=array()) 857 857 { … … 860 860 $timezone = dt::getTimeOffset($this->core->blog->settings->system->blog_timezone)/3600; 861 861 } 862 862 863 863 $res = array ( 864 864 'software_name' => array ( … … 903 903 ) 904 904 ); 905 905 906 906 if (!empty($options)) 907 907 { … … 914 914 return $r; 915 915 } 916 916 917 917 return $res; 918 918 } 919 919 920 920 private function getPostStatusList($blog_id,$user,$pwd) 921 921 { 922 922 $this->setUser($user,$pwd); 923 923 $this->setBlog(); 924 924 925 925 return array( 926 926 'draft' => 'Draft', … … 931 931 ); 932 932 } 933 933 934 934 private function getPageStatusList($blog_id,$user,$pwd) 935 935 { … … 937 937 $this->setBlog(); 938 938 $this->checkPagesPermission(); 939 939 940 940 return array( 941 941 'draft' => 'Draft', … … 945 945 ); 946 946 } 947 947 948 948 private function checkPagesPermission() 949 949 { … … 951 951 throw new Exception('Pages management is not available on this blog.'); 952 952 } 953 953 954 954 if (!$this->core->auth->check('pages,contentadmin',$this->core->blog->id)) { 955 955 throw new Exception('Not enough permissions to edit pages.',401); 956 956 } 957 957 } 958 958 959 959 private function getPages($blog_id,$user,$pwd,$limit=null,$id=null) 960 960 { … … 962 962 $this->setBlog(); 963 963 $this->checkPagesPermission(); 964 964 965 965 $params = array( 966 966 'post_type' => 'page', 967 967 'order' => 'post_position ASC, post_title ASC' 968 968 ); 969 969 970 970 if ($id) { 971 971 $params['post_id'] = (integer) $id; … … 974 974 $params['limit'] = $limit; 975 975 } 976 976 977 977 $posts = $this->core->blog->getPosts($params); 978 978 979 979 $res = array(); 980 980 while ($posts->fetch()) … … 1006 1006 "wp_page_template" => 'default' 1007 1007 ); 1008 1008 1009 1009 # --BEHAVIOR-- xmlrpcGetPageInfo 1010 1010 $this->core->callBehavior('xmlrpcGetPageInfo',$this,array(&$tres)); 1011 1011 1012 1012 $res[] = $tres; 1013 1013 } 1014 1014 1015 1015 return $res; 1016 1016 } 1017 1017 1018 1018 private function newPage($blog_id,$user,$pwd,$struct,$publish) 1019 1019 { … … 1021 1021 $this->setBlog(); 1022 1022 $this->checkPagesPermission(); 1023 1023 1024 1024 $struct['post_type'] = 'page'; 1025 1025 1026 1026 return $this->newPost($blog_id,$user,$pwd,null,$struct,$publish); 1027 1027 } 1028 1028 1029 1029 private function editPage($page_id,$user,$pwd,$struct,$publish) 1030 1030 { … … 1032 1032 $this->setBlog(); 1033 1033 $this->checkPagesPermission(); 1034 1034 1035 1035 $struct['post_type'] = 'page'; 1036 1036 1037 1037 return $this->editPost($page_id,$user,$pwd,null,$struct,$publish); 1038 1038 } 1039 1039 1040 1040 private function deletePage($page_id,$user,$pwd) 1041 1041 { … … 1043 1043 $this->setBlog(); 1044 1044 $this->checkPagesPermission(); 1045 1045 1046 1046 $page_id = (integer) $page_id; 1047 1047 1048 1048 $this->getPostRS($page_id,$user,$pwd,'page'); 1049 1049 $this->core->blog->delPost($page_id); 1050 1050 1051 1051 return true; 1052 1052 } 1053 1053 1054 1054 private function getAuthors($user,$pwd) 1055 1055 { 1056 1056 $this->setUser($user,$pwd); 1057 1057 $this->setBlog(); 1058 1058 1059 1059 $rs = $this->core->getBlogPermissions($this->core->blog->id); 1060 1060 $res = array(); 1061 1061 1062 1062 foreach($rs as $k => $v) 1063 1063 { … … 1070 1070 return $res; 1071 1071 } 1072 1072 1073 1073 private function getTags($user,$pwd) 1074 1074 { 1075 1075 $this->setUser($user,$pwd); 1076 1076 $this->setBlog(); 1077 1077 1078 1078 $tags = $this->core->meta->getMeta('tag'); 1079 1079 $tags->sort('meta_id_lower','asc'); 1080 1080 1081 1081 $res = array(); 1082 1082 $url = $this->core->blog->url. … … 1097 1097 return $res; 1098 1098 } 1099 1099 1100 1100 private function newCategory($user,$pwd,$struct) 1101 1101 { 1102 1102 $this->setUser($user,$pwd); 1103 1103 $this->setBlog(); 1104 1104 1105 1105 if (empty($struct['name'])) { 1106 1106 throw new Exception('You mus give a category name.'); 1107 1107 } 1108 1108 1109 1109 $cur = $this->core->con->openCursor($this->core->prefix.'category'); 1110 1110 $cur->cat_title = $struct['name']; 1111 1111 1112 1112 if (!empty($struct['slug'])) { 1113 1113 $cur->cat_url = $struct['slug']; … … 1119 1119 } 1120 1120 } 1121 1121 1122 1122 $parent = !empty($struct['category_parent']) ? (integer) $struct['category_parent'] : 0; 1123 1123 1124 1124 $id = $this->core->blog->addCategory($cur,$parent); 1125 1125 $rs = $this->core->blog->getCategory($id); 1126 1126 return $rs->cat_url; 1127 1127 } 1128 1128 1129 1129 private function deleteCategory($user,$pwd,$cat_id) 1130 1130 { 1131 1131 $this->setUser($user,$pwd); 1132 1132 $this->setBlog(); 1133 1133 1134 1134 $c = $this->core->blog->getCategories(array('cat_url' => $cat_id)); 1135 1135 if ($c->isEmpty()) { … … 1138 1138 $cat_id = $c->cat_id; 1139 1139 unset($c); 1140 1140 1141 1141 $this->core->blog->delCategory((integer) $cat_id); 1142 1142 return true; 1143 1143 } 1144 1144 1145 1145 private function searchCategories($user,$pwd,$category,$limit) 1146 1146 { 1147 1147 $this->setUser($user,$pwd); 1148 1148 $this->setBlog(); 1149 1149 1150 1150 $strReq = 'SELECT cat_id, cat_title, cat_url '. 1151 1151 'FROM '.$this->core->prefix.'category '. … … 1153 1153 "AND LOWER(cat_title) LIKE LOWER('%".$this->core->con->escape($category)."%') ". 1154 1154 ($limit > 0 ? $this->core->con->limit($limit) : ''); 1155 1155 1156 1156 $rs = $this->core->con->select($strReq); 1157 1157 1158 1158 $res = array(); 1159 1159 while ($rs->fetch()) … … 1166 1166 return $res; 1167 1167 } 1168 1168 1169 1169 private function countComments($user,$pwd,$post_id) 1170 1170 { 1171 1171 $this->setUser($user,$pwd); 1172 1172 $this->setBlog(); 1173 1173 1174 1174 $res = array( 1175 1175 'approved' => 0, … … 1179 1179 ); 1180 1180 $rs = $this->core->blog->getComments(array('post_id' => $post_id)); 1181 1181 1182 1182 while ($rs->fetch()) { 1183 1183 $res['total']++; … … 1192 1192 return $res; 1193 1193 } 1194 1194 1195 1195 private function getComments($user,$pwd,$struct,$id=null) 1196 1196 { 1197 1197 $this->setUser($user,$pwd); 1198 1198 $this->setBlog(); 1199 1199 1200 1200 $params = array(); 1201 1201 1202 1202 if (!empty($struct['status'])) { 1203 1203 $params['comment_status'] = $this->translateWpCommentstatus($struct['status']); 1204 1204 } 1205 1205 1206 1206 if (!empty($struct['post_id'])) { 1207 1207 $params['post_id'] = (integer) $struct['post_id']; 1208 1208 } 1209 1209 1210 1210 if (isset($id)) { 1211 1211 $params['comment_id'] = $id; 1212 1212 } 1213 1213 1214 1214 $offset = !empty($struct['offset']) ? (integer) $struct['offset'] : 0; 1215 1215 $limit = !empty($struct['number']) ? (integer) $struct['number'] : 10; 1216 1216 $params['limit'] = array($offset,$limit); 1217 1217 1218 1218 $rs = $this->core->blog->getComments($params); 1219 1219 $res = array(); … … 1238 1238 return $res; 1239 1239 } 1240 1240 1241 1241 private function addComment($user,$pwd,$post_id,$struct) 1242 1242 { 1243 1243 $this->setUser($user,$pwd); 1244 1244 $this->setBlog(); 1245 1245 1246 1246 if (empty($struct['content'])) { 1247 1247 throw new Exception('Sorry, you cannot post an empty comment',401); 1248 1248 } 1249 1249 1250 1250 if (is_numeric($post_id)) { 1251 1251 $p['post_id'] = $post_id; … … 1257 1257 throw new Exception('Sorry, no such post.',404); 1258 1258 } 1259 1259 1260 1260 $cur = $this->core->con->openCursor($this->core->prefix.'comment'); 1261 1261 1262 1262 $cur->comment_author = $this->core->auth->getInfo('user_cn'); 1263 1263 $cur->comment_email = $this->core->auth->getInfo('user_email'); 1264 1264 $cur->comment_site = $this->core->auth->getInfo('user_url'); 1265 1265 1266 1266 $cur->comment_content = $struct['content']; 1267 1267 $cur->post_id = (integer) $post_id; 1268 1268 1269 1269 $id = $this->core->blog->addComment($cur); 1270 1270 return $id; 1271 1271 } 1272 1272 1273 1273 private function updComment($user,$pwd,$comment_id,$struct) 1274 1274 { 1275 1275 $this->setUser($user,$pwd); 1276 1276 $this->setBlog(); 1277 1277 1278 1278 $cur = $this->core->con->openCursor($this->core->prefix.'comment'); 1279 1279 1280 1280 if (isset($struct['status'])) { 1281 1281 $cur->comment_status = $this->translateWpCommentstatus($struct['status']); 1282 1282 } 1283 1283 1284 1284 if (isset($struct['date_created_gmt'])) { 1285 1285 if ($struct['date_created_gmt'] instanceof xmlrpcDate) { … … 1290 1290 $cur->comment_dt = $struct['date_created_gmt']; 1291 1291 } 1292 1292 1293 1293 if (isset($struct['content'])) { 1294 1294 $cur->comment_content = $struct['content']; 1295 1295 } 1296 1296 1297 1297 if (isset($struct['author'])) { 1298 1298 $cur->comment_author = $struct['author']; 1299 1299 } 1300 1300 1301 1301 if (isset($struct['author_url'])) { 1302 1302 $cur->comment_site = $struct['author_url']; 1303 1303 } 1304 1304 1305 1305 if (isset($struct['author_email'])) { 1306 1306 $cur->comment_email = $struct['author_email']; 1307 1307 } 1308 1308 1309 1309 $this->core->blog->updComment($comment_id,$cur); 1310 1310 return true; 1311 1311 } 1312 1312 1313 1313 private function delComment($user,$pwd,$comment_id) 1314 1314 { 1315 1315 $this->setUser($user,$pwd); 1316 1316 $this->setBlog(); 1317 1317 1318 1318 $this->core->blog->delComment($comment_id); 1319 1319 return true; 1320 1320 } 1321 1321 1322 1322 /* Blogger methods 1323 1323 --------------------------------------------------- */ … … 1326 1326 return $this->newPost($blogid,$username,$password,$content,array(),$publish); 1327 1327 } 1328 1328 1329 1329 public function blogger_editPost($appkey,$postid,$username,$password,$content,$publish) 1330 1330 { 1331 1331 return $this->editPost($postid,$username,$password,$content,array(),$publish); 1332 1332 } 1333 1333 1334 1334 public function blogger_getPost($appkey,$postid,$username,$password) 1335 1335 { 1336 1336 return $this->getPost($postid,$username,$password,'blogger'); 1337 1337 } 1338 1338 1339 1339 public function blogger_deletePost($appkey,$postid,$username,$password,$publish) 1340 1340 { 1341 1341 return $this->deletePost($postid,$username,$password); 1342 1342 } 1343 1343 1344 1344 public function blogger_getRecentPosts($appkey,$blogid,$username,$password,$numberOfPosts) 1345 1345 { 1346 1346 return $this->getRecentPosts($blogid,$username,$password,$numberOfPosts,'blogger'); 1347 1347 } 1348 1348 1349 1349 public function blogger_getUserBlogs($appkey,$username,$password) 1350 1350 { 1351 1351 return $this->getUserBlogs($username,$password); 1352 1352 } 1353 1353 1354 1354 public function blogger_getUserInfo($appkey,$username,$password) 1355 1355 { 1356 1356 return $this->getUserInfo($username,$password); 1357 1357 } 1358 1359 1358 1359 1360 1360 /* Metaweblog methods 1361 1361 ------------------------------------------------------- */ … … 1364 1364 return $this->newPost($blogid,$username,$password,'',$content,$publish); 1365 1365 } 1366 1366 1367 1367 public function mw_editPost($postid,$username,$password,$content,$publish) 1368 1368 { 1369 1369 return $this->editPost($postid,$username,$password,'',$content,$publish); 1370 1370 } 1371 1371 1372 1372 public function mw_getPost($postid,$username,$password) 1373 1373 { 1374 1374 return $this->getPost($postid,$username,$password,'mw'); 1375 1375 } 1376 1376 1377 1377 public function mw_getRecentPosts($blogid,$username,$password,$numberOfPosts) 1378 1378 { 1379 1379 return $this->getRecentPosts($blogid,$username,$password,$numberOfPosts,'mw'); 1380 1380 } 1381 1381 1382 1382 public function mw_getCategories($blogid,$username,$password) 1383 1383 { 1384 1384 return $this->getCategories($blogid,$username,$password); 1385 1385 } 1386 1386 1387 1387 public function mw_newMediaObject($blogid,$username,$password,$file) 1388 1388 { 1389 1389 return $this->newMediaObject($blogid,$username,$password,$file); 1390 1390 } 1391 1391 1392 1392 /* MovableType methods 1393 1393 --------------------------------------------------- */ … … 1396 1396 return $this->getRecentPosts($blogid,$username,$password,$numberOfPosts,'mt'); 1397 1397 } 1398 1398 1399 1399 public function mt_getCategoryList($blogid,$username,$password) 1400 1400 { 1401 1401 return $this->getCategories($blogid,$username,$password); 1402 1402 } 1403 1403 1404 1404 public function mt_getPostCategories($postid,$username,$password) 1405 1405 { 1406 1406 return $this->getPostCategories($postid,$username,$password); 1407 1407 } 1408 1408 1409 1409 public function mt_setPostCategories($postid,$username,$password,$categories) 1410 1410 { 1411 1411 return $this->setPostCategories($postid,$username,$password,$categories); 1412 1412 } 1413 1413 1414 1414 public function mt_publishPost($postid,$username,$password) 1415 1415 { 1416 1416 return $this->publishPost($postid,$username,$password); 1417 1417 } 1418 1418 1419 1419 public function mt_supportedTextFilters() 1420 1420 { 1421 1421 return array(); 1422 1422 } 1423 1423 1424 1424 /* WordPress methods 1425 1425 --------------------------------------------------- */ … … 1428 1428 return $this->getUserBlogs($username,$password); 1429 1429 } 1430 1430 1431 1431 public function wp_getPage($blogid,$pageid,$username,$password) 1432 1432 { 1433 1433 $res = $this->getPages($blogid,$username,$password,null,$pageid); 1434 1434 1435 1435 if (empty($res)) { 1436 1436 throw new Exception('Sorry, no such page',404); 1437 1437 } 1438 1438 1439 1439 return $res[0]; 1440 1440 } 1441 1441 1442 1442 public function wp_getPages($blogid,$username,$password,$num=10) 1443 1443 { 1444 1444 return $this->getPages($blogid,$username,$password,$num); 1445 1445 } 1446 1446 1447 1447 public function wp_newPage($blogid,$username,$password,$content,$publish) 1448 1448 { 1449 1449 return $this->newPage($blogid,$username,$password,$content,$publish); 1450 1450 } 1451 1451 1452 1452 public function wp_deletePage($blogid,$username,$password,$pageid) 1453 1453 { 1454 1454 return $this->deletePage($pageid,$username,$password); 1455 1455 } 1456 1456 1457 1457 public function wp_editPage($blogid,$pageid,$username,$password,$content,$publish) 1458 1458 { 1459 1459 return $this->editPage($pageid,$username,$password,$content,$publish); 1460 1460 } 1461 1461 1462 1462 public function wp_getPageList($blogid,$username,$password) 1463 1463 { … … 1475 1475 return $res; 1476 1476 } 1477 1477 1478 1478 public function wp_getAuthors($blogid,$username,$password) 1479 1479 { 1480 1480 return $this->getAuthors($username,$password); 1481 1481 } 1482 1482 1483 1483 public function wp_getCategories($blogid,$username,$password) 1484 1484 { 1485 1485 return $this->getCategories($blogid,$username,$password); 1486 1486 } 1487 1487 1488 1488 public function wp_getTags($blogid,$username,$password) 1489 1489 { 1490 1490 return $this->getTags($username,$password); 1491 1491 } 1492 1492 1493 1493 public function wp_newCategory($blogid,$username,$password,$content) 1494 1494 { 1495 1495 return $this->newCategory($username,$password,$content); 1496 1496 } 1497 1497 1498 1498 public function wp_deleteCategory($blogid,$username,$password,$categoryid) 1499 1499 { 1500 1500 return $this->deleteCategory($username,$password,$categoryid); 1501 1501 } 1502 1502 1503 1503 public function wp_suggestCategories($blogid,$username,$password,$category,$max_results=0) 1504 1504 { 1505 1505 return $this->searchCategories($username,$password,$category,$max_results); 1506 1506 } 1507 1507 1508 1508 public function wp_uploadFile($blogid,$username,$password,$file) 1509 1509 { 1510 1510 return $this->newMediaObject($blogid,$username,$password,$file); 1511 1511 } 1512 1512 1513 1513 public function wp_getPostStatusList($blogid,$username,$password) 1514 1514 { 1515 1515 return $this->getPostStatusList($blogid,$username,$password); 1516 1516 } 1517 1517 1518 1518 public function wp_getPageStatusList($blogid,$username,$password) 1519 1519 { 1520 1520 return $this->getPostStatusList($blogid,$username,$password); 1521 1521 } 1522 1522 1523 1523 public function wp_getPageTemplates($blogid,$username,$password) 1524 1524 { 1525 1525 return array('Default' => 'default'); 1526 1526 } 1527 1527 1528 1528 public function wp_getOptions($blogid,$username,$password,$options=array()) 1529 1529 { 1530 1530 $this->setUser($username,$password); 1531 1531 $this->setBlog(); 1532 1532 1533 1533 return $this->translateWpOptions($options); 1534 1534 } 1535 1535 1536 1536 public function wp_setOptions($blogid,$username,$password,$options) 1537 1537 { 1538 1538 $this->setUser($username,$password); 1539 1539 $this->setBlog(); 1540 1540 1541 1541 if (!$this->core->auth->check('admin',$this->core->blog->id)) { 1542 1542 throw new Exception('Not enough permissions to edit options.',401); 1543 1543 } 1544 1544 1545 1545 $opt = $this->translateWpOptions(); 1546 1546 1547 1547 $done = array(); 1548 1548 $blog_changes = false; 1549 1549 $cur = $this->core->con->openCursor($this->core->prefix.'blog'); 1550 1550 1551 1551 $this->core->blog->settings->addNamespace('system'); 1552 1552 1553 1553 foreach ($options as $name => $value) 1554 1554 { … … 1556 1556 continue; 1557 1557 } 1558 1558 1559 1559 switch ($name) 1560 1560 { … … 1579 1579 } 1580 1580 } 1581 1581 1582 1582 if ($blog_changes) { 1583 1583 $this->core->updBlog($this->core->blog->id,$cur); 1584 1584 $this->core->setBlog($this->core->blog->id); 1585 1585 } 1586 1586 1587 1587 return $this->translateWpOptions($done); 1588 1588 } 1589 1589 1590 1590 public function wp_getComment($blogid,$username,$password,$commentid) 1591 1591 { 1592 1592 $res = $this->getComments($username,$password,array(),$commentid); 1593 1593 1594 1594 if (empty($res)) { 1595 1595 throw new Exception('Sorry, no such comment',404); 1596 1596 } 1597 1597 1598 1598 return $res[0]; 1599 1599 } 1600 1600 1601 1601 public function wp_getCommentCount($blogid,$username,$password,$postid) 1602 1602 { 1603 1603 return $this->countComments($username,$password,$postid); 1604 1604 } 1605 1605 1606 1606 public function wp_getComments($blogid,$username,$password,$struct) 1607 1607 { 1608 1608 return $this->getComments($username,$password,$struct); 1609 1609 } 1610 1610 1611 1611 public function wp_deleteComment($blogid,$username,$password,$commentid) 1612 1612 { 1613 1613 return $this->delComment($username,$password,$commentid); 1614 1614 } 1615 1615 1616 1616 public function wp_editComment($blogid,$username,$password,$commentid,$content) 1617 1617 { 1618 1618 return $this->updComment($username,$password,$commentid,$content); 1619 1619 } 1620 1620 1621 1621 public function wp_newComment($blogid,$username,$password,$postid,$content) 1622 1622 { 1623 1623 return $this->addComment($username,$password,$postid,$content); 1624 1624 } 1625 1625 1626 1626 public function wp_getCommentStatusList($blogid,$username,$password) 1627 1627 { 1628 1628 $this->setUser($username,$password); 1629 1629 $this->setBlog(); 1630 1630 1631 1631 return array( 1632 1632 'hold' => 'Unapproved', … … 1652 1652 throw new Exception(__('LOL!'), 0); 1653 1653 } 1654 1654 1655 1655 # Time to get things done... 1656 1656 $this->setBlog(true); … … 1659 1659 } 1660 1660 } 1661 ?>
Note: See TracChangeset
for help on using the changeset viewer.
