Dotclear

source: inc/core/class.dc.xmlrpc.php @ 1688:4491482ebb64

Revision 1688:4491482ebb64, 45.3 KB checked in by Florent Cotton <florent.cotton@…>, 11 years ago (diff)

Réception des pingbacks : petit soucis pour les traitements ensuite. Laissons les URLs dans leur état normal.

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

Sites map