Dotclear

source: inc/core/class.dc.xmlrpc.php @ 877:e012da998f83

Revision 877:e012da998f83, 28.0 KB checked in by Dsls <dsls@…>, 13 years ago (diff)

Entries passwords will be a dedicated plugin.

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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          # MovableType methods
78          $this->addCallback('mt.getRecentPostTitles',array($this,'mt_getRecentPostTitles'),
79               array('array','string','string','string','integer'),
80               'List of most recent posts in the system');
81         
82          $this->addCallback('mt.publishPost',array($this,'mt_publishPost'),
83               array('boolean','string','string','string'),
84               'Retrieve pings list for a post');
85         
86          $this->addCallback('mt.supportedMethods',array($this,'listMethods'),
87               array(),'Retrieve information about the XML-RPC methods supported by the server.');
88         
89          $this->addCallback('mt.supportedTextFilters',array($this,'mt_supportedTextFilters'),
90               array(),'Retrieve information about supported text filters.');
91         
92          # WordPress methods
93          $this->addCallback('wp.getUsersBlogs',array($this,'wp_getUsersBlogs'),
94               array('array','string','string'),
95               'Retrieve the blogs of the user.');
96         
97          $this->addCallback('wp.getPage',array($this,'wp_getPage'),
98               array('struct','integer','integer','string','string'),
99               'Get the page identified by the page ID.');
100         
101          $this->addCallback('wp.getPages',array($this,'wp_getPages'),
102               array('array','integer','string','string','integer'),
103               'Get an array of all the pages on a blog.');
104         
105          $this->addCallback('wp.newPage',array($this,'wp_newPage'),
106               array('integer','integer','string','string','struct','boolean'),
107               'Create a new page.');
108         
109          $this->addCallback('wp.deletePage',array($this,'wp_deletePage'),
110               array('boolean','integer','string','string','integer'),
111               'Removes a page from the blog.');
112         
113          $this->addCallback('wp.editPage',array($this,'wp_editPage'),
114               array('boolean','integer','integer','string','string','struct','boolean'),
115               'Make changes to a blog page.');
116         
117          $this->addCallback('wp.getPageList',array($this,'wp_getPageList'),
118               array('array','integer','string','string'),
119               'Get an array of all the pages on a blog. Just the minimum details, lighter than wp.getPages.');
120         
121          $this->addCallback('wp.getAuthors',array($this,'wp_getAuthors'),
122               array('array','integer','string','string'),
123               'Get an array of users for the blog.');
124         
125          $this->addCallback('wp.getTags',array($this,'wp_getTags'),
126               array('array','integer','string','string'),
127               'Get list of all tags for the blog.');
128         
129          $this->addCallback('wp.uploadFile',array($this,'wp_uploadFile'),
130               array('struct','integer','string','string','struct'),
131               'Upload a file');
132         
133          $this->addCallback('wp.getPostStatusList',array($this,'wp_getPostStatusList'),
134               array('array','integer','string','string'),
135               'Retrieve all of the post statuses.');
136         
137          $this->addCallback('wp.getPageStatusList',array($this,'wp_getPageStatusList'),
138               array('array','integer','string','string'),
139               'Retrieve all of the pages statuses.');
140         
141          $this->addCallback('wp.getPageTemplates',array($this,'wp_getPageTemplates'),
142               array('struct','integer','string','string'),
143               'Retrieve page templates.');
144         
145          $this->addCallback('wp.getOptions',array($this,'wp_getOptions'),
146               array('struct','integer','string','string','array'),
147               'Retrieve blog options');
148         
149          $this->addCallback('wp.setOptions',array($this,'wp_setOptions'),
150               array('struct','integer','string','string','struct'),
151               'Update blog options');
152         
153     }
154     
155     public function serve($data=false,$encoding='UTF-8')
156     {
157          parent::serve(false,$encoding);
158     }
159     
160     public function call($methodname,$args)
161     {
162          try {
163               $rsp = @parent::call($methodname,$args);
164               $this->debugTrace($methodname,$args,$rsp);
165               return $rsp;
166          } catch (Exception $e) {
167               $this->debugTrace($methodname,$args,array($e->getMessage(),$e->getCode()));
168               throw $e;
169          }
170     }
171     
172     private function debugTrace($methodname,$args,$rsp)
173     {
174          if (!$this->debug) {
175               return;
176          }
177         
178          if (($fp = @fopen($this->debug_file,'a')) !== false)
179          {
180               fwrite($fp,'['.date('r').']'.' '.$methodname);
181               
182               if ($this->trace_args) {
183                    fwrite($fp,"\n- args ---\n".var_export($args,1));
184               }
185               
186               if ($this->trace_response) {
187                    fwrite($fp,"\n- response ---\n".var_export($rsp,1));
188               }
189               fwrite($fp,"\n");
190               fclose($fp);
191          }
192     }
193     
194     /* Internal methods
195     --------------------------------------------------- */
196     private function setUser($user_id,$pwd)
197     {
198          if ($this->core->auth->userID() == $user_id) {
199               return true;
200          }
201         
202          if ($this->core->auth->checkUser($user_id,$pwd) !== true) {
203               throw new Exception('Login error');
204          }
205         
206          return true;
207     }
208     
209     private function setBlog()
210     {
211          if (!$this->blog_id) {
212               throw new Exception('No blog ID given.');
213          }
214         
215          if ($this->blog_loaded) {
216               return true;
217          }
218         
219          $this->core->setBlog($this->blog_id);
220          $this->blog_loaded = true;
221         
222          if (!$this->core->blog->id) {
223               $this->core->blog = null;
224               throw new Exception('Blog does not exist.');
225          }
226         
227          if (!$this->core->blog->settings->system->enable_xmlrpc ||
228          !$this->core->auth->check('usage,contentadmin',$this->core->blog->id)) {
229               $this->core->blog = null;
230               throw new Exception('Not enough permissions on this blog.');
231          }
232         
233          foreach ($this->core->plugins->getModules() as $id => $m) {
234               $this->core->plugins->loadNsFile($id,'xmlrpc');
235          }
236         
237          return true;
238     }
239     
240     private function getPostRS($post_id,$user,$pwd,$post_type='post')
241     {
242          $this->setUser($user,$pwd);
243          $this->setBlog();
244          $posts = $this->core->blog->getPosts(array(
245               'post_id' => (integer) $post_id,
246               'post_type' => $post_type
247          ));
248         
249          if (count($posts) == 0) {
250               throw new Exception('This entry does not exist');
251          }
252         
253          return $posts;
254     }
255     
256     /* Generic methods
257     --------------------------------------------------- */
258     private function newPost($blog_id,$user,$pwd,$content,$struct=array(),$publish=true)
259     {
260          $this->setUser($user,$pwd);
261          $this->setBlog();
262         
263          $title = !empty($struct['title']) ? $struct['title'] : '';
264          $excerpt = !empty($struct['mt_excerpt']) ? $struct['mt_excerpt'] : '';
265          $description = !empty($struct['description']) ? $struct['description'] : null;
266          $dateCreated = !empty($struct['dateCreated']) ? $struct['dateCreated'] : null;
267         
268          if ($description !== null) {
269               $content = $description;
270          }
271         
272          if (!$title) {
273               $title = text::cutString(html::clean($content),25).'...';
274          }
275         
276          $excerpt_xhtml = $this->core->callFormater('xhtml',$excerpt);
277          $content_xhtml = $this->core->callFormater('xhtml',$content);
278         
279          if (empty($content)) {
280               throw new Exception('Cannot create an empty entry');
281          }
282         
283          $cur = $this->core->con->openCursor($this->core->prefix.'post');
284         
285          $cur->user_id = $this->core->auth->userID();
286          $cur->post_lang = $this->core->auth->getInfo('user_lang');
287          $cur->post_title = trim($title);
288          $cur->post_content = $content;
289          $cur->post_excerpt = $excerpt;
290          $cur->post_content_xhtml = $content_xhtml;
291          $cur->post_excerpt_xhtml = $excerpt_xhtml;
292          $cur->post_status = (integer) $publish;
293          $cur->post_format = 'xhtml';
294         
295          if ($dateCreated) {
296               if ($dateCreated instanceof xmlrpcDate) {
297                    $cur->post_dt = date('Y-m-d H:i:00',$dateCreated->getTimestamp());
298               } elseif (is_string($dateCreated) && @strtotime($dateCreated)) {
299                    $cur->post_dt = date('Y-m-d H:i:00',strtotime($dateCreated));
300               }
301          }
302         
303          if (isset($struct['wp_slug'])) {
304               $cur->post_url = $struct['wp_slug'];
305          }
306         
307          $cur->post_type = 'post';
308          if (!empty($struct['post_type'])) {
309               $cur->post_type = $struct['post_type'];
310          }
311         
312          if ($cur->post_type == 'post')
313          {
314               # --BEHAVIOR-- xmlrpcBeforeNewPost
315               $this->core->callBehavior('xmlrpcBeforeNewPost',$this,$cur,$content,$struct,$publish);
316               
317               $post_id = $this->core->blog->addPost($cur);
318               
319               # --BEHAVIOR-- xmlrpcAfterNewPost
320               $this->core->callBehavior('xmlrpcAfterNewPost',$this,$post_id,$cur,$content,$struct,$publish);
321          }
322          elseif ($cur->post_type == 'page')
323          {
324               if (isset($struct['wp_page_order'])) {
325                    $cur->post_position = (integer) $struct['wp_page_order'];
326               }
327               
328               $this->core->blog->settings->system->post_url_format = '{t}';
329               
330               $post_id = $this->core->blog->addPost($cur);
331          }
332          else
333          {
334               throw new Exception('Invalid post type',401);
335          }
336         
337          return (string) $post_id;
338     }
339     
340     private function editPost($post_id,$user,$pwd,$content,$struct=array(),$publish=true)
341     {
342          $post_id = (integer) $post_id;
343         
344          $post_type = 'post';
345          if (!empty($struct['post_type'])) {
346               $post_type = $struct['post_type'];
347          }
348         
349          $post = $this->getPostRS($post_id,$user,$pwd,$post_type);
350         
351          $title = (!empty($struct['title'])) ? $struct['title'] : '';
352          $excerpt = (!empty($struct['mt_excerpt'])) ? $struct['mt_excerpt'] : '';
353          $description = (!empty($struct['description'])) ? $struct['description'] : null;
354          $dateCreated = !empty($struct['dateCreated']) ? $struct['dateCreated'] : null;
355         
356          if ($description !== null) {
357               $content = $description;
358          }
359         
360          if (!$title) {
361               $title = text::cutString(html::clean($content),25).'...';
362          }
363         
364          $excerpt_xhtml = $this->core->callFormater('xhtml',$excerpt);
365          $content_xhtml = $this->core->callFormater('xhtml',$content);
366         
367          if (empty($content)) {
368               throw new Exception('Cannot create an empty entry');
369          }
370         
371          $cur = $this->core->con->openCursor($this->core->prefix.'post');
372         
373          $cur->post_type = $post_type;
374          $cur->post_title = trim($title);
375          $cur->post_content = $content;
376          $cur->post_excerpt = $excerpt;
377          $cur->post_content_xhtml = $content_xhtml;
378          $cur->post_excerpt_xhtml = $excerpt_xhtml;
379          $cur->post_status = (integer) $publish;
380          $cur->post_format = 'xhtml';
381          $cur->post_url = $post->post_url;
382         
383         
384          if ($dateCreated) {
385               if ($dateCreated instanceof xmlrpcDate) {
386                    $cur->post_dt = date('Y-m-d H:i:00',$dateCreated->getTimestamp());
387               } elseif (is_string($dateCreated) && @strtotime($dateCreated)) {
388                    $cur->post_dt = date('Y-m-d H:i:00',strtotime($dateCreated));
389               }
390          } else {
391               $cur->post_dt = $post->post_dt;
392          }
393         
394          if (isset($struct['wp_slug'])) {
395               $cur->post_url = $struct['wp_slug'];
396          }
397         
398          if ($cur->post_type == 'post')
399          {
400               # --BEHAVIOR-- xmlrpcBeforeEditPost
401               $this->core->callBehavior('xmlrpcBeforeEditPost',$this,$post_id,$cur,$content,$struct,$publish);
402               
403               $this->core->blog->updPost($post_id,$cur);
404               
405               # --BEHAVIOR-- xmlrpcAfterEditPost
406               $this->core->callBehavior('xmlrpcAfterEditPost',$this,$post_id,$cur,$content,$struct,$publish);
407          }
408          elseif ($cur->post_type == 'page')
409          {
410               if (isset($struct['wp_page_order'])) {
411                    $cur->post_position = (integer) $struct['wp_page_order'];
412               }
413               
414               $this->core->blog->settings->system->post_url_format = '{t}';
415               
416               $this->core->blog->updPost($post_id,$cur);
417          }
418          else
419          {
420               throw new Exception('Invalid post type',401);
421          }
422         
423          return true;
424     }
425     
426     private function getPost($post_id,$user,$pwd,$type='mw')
427     {
428          $post_id = (integer) $post_id;
429         
430          $post = $this->getPostRS($post_id,$user,$pwd);
431         
432          $res = new ArrayObject();
433         
434          $res['dateCreated'] = new xmlrpcDate($post->getTS());
435          $res['userid'] = $post->user_id;
436          $res['postid'] = $post->post_id;
437         
438          if ($type == 'blogger') {
439               $res['content'] = $post->post_content_xhtml;
440          }
441         
442          if ($type == 'mt' || $type == 'mw') {
443               $res['title'] = $post->post_title;
444          }
445         
446          if ($type == 'mw') {
447               $res['description'] = $post->post_content_xhtml;
448               $res['link'] = $res['permaLink'] = $post->getURL();
449               $res['mt_excerpt'] = $post->post_excerpt_xhtml;
450               $res['mt_text_more'] = '';
451               $res['mt_convert_breaks'] = '';
452               $res['mt_keywords'] = '';
453          }
454         
455          # --BEHAVIOR-- xmlrpcGetPostInfo
456          $this->core->callBehavior('xmlrpcGetPostInfo',$this,$type,array(&$res));
457         
458          return $res;
459     }
460     
461     private function deletePost($post_id,$user,$pwd)
462     {
463          $post_id = (integer) $post_id;
464         
465          $this->getPostRS($post_id,$user,$pwd);
466          $this->core->blog->delPost($post_id);
467         
468          return true;
469     }
470     
471     private function getRecentPosts($blog_id,$user,$pwd,$nb_post,$type='mw')
472     {
473          $this->setUser($user,$pwd);
474          $this->setBlog();
475         
476          $nb_post = (integer) $nb_post;
477         
478          if ($nb_post > 50) {
479               throw new Exception('Cannot retrieve more than 50 entries');
480          }
481         
482          $params = array();
483          $params['limit'] = $nb_post;
484         
485          $posts = $this->core->blog->getPosts($params);
486         
487          $res = array();
488          foreach ($posts as $p)
489          {
490               $tres = array();
491               
492               $tres['dateCreated'] = new xmlrpcDate($posts->getTS());
493               $tres['userid'] = $p->user_id;
494               $tres['postid'] = $p->post_id;
495               
496               if ($type == 'blogger') {
497                    $tres['content'] = $p->post_content_xhtml;
498               }
499               
500               if ($type == 'mt' || $type == 'mw') {
501                    $tres['title'] = $p->post_title;
502               }
503               
504               if ($type == 'mw') {
505                    $tres['description'] = $p->post_content_xhtml;
506                    $tres['link'] = $tres['permaLink'] = $p->getURL();
507                    $tres['mt_excerpt'] = $p->post_excerpt_xhtml;
508                    $tres['mt_text_more'] = '';
509                    $tres['mt_convert_breaks'] = '';
510                    $tres['mt_keywords'] = '';
511               }
512               
513               # --BEHAVIOR-- xmlrpcGetPostInfo
514               $this->core->callBehavior('xmlrpcGetPostInfo',$this,$type,array(&$tres));
515               
516               $res[] = $tres;
517          }
518         
519          return $res;
520     }
521     
522     private function getUserBlogs($user,$pwd)
523     {
524          $this->setUser($user,$pwd);
525          $this->setBlog();
526         
527          return array(array(
528               'url' => $this->core->blog->url,
529               'blogid' => '1',
530               'blogName' => $this->core->blog->name
531          ));
532     }
533     
534     private function getUserInfo($user,$pwd)
535     {
536          $this->setUser($user,$pwd);
537         
538          return array(
539               'userid' => $this->core->auth->userID(),
540               'firstname' => $this->core->auth->getInfo('user_firstname'),
541               'lastname' => $this->core->auth->getInfo('user_name'),
542               'nickname' => $this->core->auth->getInfo('user_displayname'),
543               'email' => $this->core->auth->getInfo('user_email'),
544               'url' => $this->core->auth->getInfo('user_url')
545          );
546     }
547     
548     private function publishPost($post_id,$user,$pwd)
549     {
550          $post_id = (integer) $post_id;
551         
552          $this->getPostRS($post_id,$user,$pwd);
553         
554          # --BEHAVIOR-- xmlrpcBeforePublishPost
555          $this->core->callBehavior('xmlrpcBeforePublishPost',$this,$post_id);
556         
557          $this->core->blog->updPostStatus($post_id,1);
558         
559          # --BEHAVIOR-- xmlrpcAfterPublishPost
560          $this->core->callBehavior('xmlrpcAfterPublishPost',$this,$post_id);
561         
562          return true;
563     }
564     
565     private function translateWpStatus($s)
566     {
567          $status = array(
568               'draft' => -2,
569               'pending' => -2,
570               'private' => 0,
571               'publish' => 1,
572               'scheduled' => -1
573          );
574         
575          if (is_int($s)) {
576               $status = array_flip($status);
577               return isset($status[$s]) ? $status[$s] : $status[-2];
578          } else {
579               return isset($status[$s]) ? $status[$s] : $status['pending'];
580          }
581     }
582     
583     
584     private function translateWpOptions($options=array())
585     {
586          $timezone = 0;
587          if ($this->core->blog->settings->system->blog_timezone) {
588               $timezone = dt::getTimeOffset($this->core->blog->settings->system->blog_timezone)/3600;
589          }
590         
591          $res = array (
592              'software_name' => array (
593                    'desc' => 'Software Name',
594                    'readonly' => true,
595                    'value' => 'Dotclear'
596               ),
597               'software_version' => array (
598                    'desc' => 'Software Version',
599                    'readonly' => true,
600                    'value' => DC_VERSION
601               ),
602               'blog_url' => array (
603                    'desc' => 'Blog URL',
604                    'readonly' => true,
605                    'value' => $this->core->blog->url
606               ),
607               'time_zone' => array (
608                    'desc' => 'Time Zone',
609                    'readonly' => true,
610                    'value' => (string) $timezone
611               ),
612               'blog_title' => array (
613                    'desc' => 'Blog Title',
614                    'readonly' => false,
615                    'value' => $this->core->blog->name
616               ),
617               'blog_tagline' => array (
618                    'desc' => 'Blog Tagline',
619                    'readonly' => false,
620                    'value' => $this->core->blog->desc
621               ),
622               'date_format' => array (
623                    'desc' => 'Date Format',
624                    'readonly' => false,
625                    'value' => $this->core->blog->settings->system->date_format
626               ),
627               'time_format' => array (
628                    'desc' => 'Time Format',
629                    'readonly' => false,
630                    'value' => $this->core->blog->settings->system->time_format
631               )
632          );
633         
634          if (!empty($options))
635          {
636               $r = array();
637               foreach ($options as $v) {
638                    if (isset($res[$v])) {
639                         $r[$v] = $res[$v];
640                    }
641               }
642               return $r;
643          }
644         
645          return $res;
646     }
647     
648     private function getPostStatusList($blog_id,$user,$pwd)
649     {
650          $this->setUser($user,$pwd);
651          $this->setBlog();
652         
653          return array(
654               'draft' => 'Draft',
655               'pending' => 'Pending Review',
656               'private' => 'Private',
657               'publish' => 'Published',
658               'scheduled' => 'Scheduled'
659          );
660     }
661     
662     private function getPageStatusList($blog_id,$user,$pwd)
663     {
664          $this->setUser($user,$pwd);
665          $this->setBlog();
666          $this->checkPagesPermission();
667         
668          return array(
669               'draft' => 'Draft',
670               'private' => 'Private',
671               'published' => 'Published',
672               'scheduled' => 'Scheduled'
673          );
674     }
675     
676     private function checkPagesPermission()
677     {
678          if (!$this->core->plugins->moduleExists('pages')) {
679               throw new Exception('Pages management is not available on this blog.');
680          }
681         
682          if (!$this->core->auth->check('pages,contentadmin',$this->core->blog->id)) {
683               throw new Exception('Not enough permissions to edit pages.',401);
684          }
685     }
686     
687     private function getPages($blog_id,$user,$pwd,$limit=null,$id=null)
688     {
689          $this->setUser($user,$pwd);
690          $this->setBlog();
691          $this->checkPagesPermission();
692         
693          $params = array(
694               'post_type' => 'page',
695               'order' => 'post_position ASC, post_title ASC'
696          );
697         
698          if ($id) {
699               $params['post_id'] = (integer) $id;
700          }
701          if ($limit) {
702               $params['limit'] = $limit;
703          }
704         
705          $posts = $this->core->blog->getPosts($params);
706         
707          $res = array();
708          foreach ($posts as $post)
709          {
710               $tres = array(
711                    "dateCreated"            => new xmlrpcDate($post->getTS()),
712                    "userid"                 => $post->user_id,
713                    "page_id"                => $post->post_id,
714                    "page_status"            => $this->translateWpStatus((integer) $post->post_status),
715                    "description"            => $post->post_content_xhtml,
716                    "title"                  => $post->post_title,
717                    "link"                   => $post->getURL(),
718                    "permaLink"              => $post->getURL(),
719                    "excerpt"                => $post->post_excerpt_xhtml,
720                    "text_more"              => '',
721                    "wp_slug"                => $post->post_url,
722                    "wp_author"              => $post->getAuthorCN(),
723                    "wp_page_parent_id"      => 0,
724                    "wp_page_parent_title"   => '',
725                    "wp_page_order"          => $post->post_position,
726                    "wp_author_id"           => $post->user_id,
727                    "wp_author_display_name" => $post->getAuthorCN(),
728                    "date_created_gmt"       => new xmlrpcDate(dt::iso8601($post->getTS(),$post->post_tz)),
729                    "custom_fields"          => array(),
730                    "wp_page_template"       => 'default'
731               );
732               
733               # --BEHAVIOR-- xmlrpcGetPageInfo
734               $this->core->callBehavior('xmlrpcGetPageInfo',$this,array(&$tres));
735               
736               $res[] = $tres;
737          }
738         
739          return $res;
740     }
741     
742     private function newPage($blog_id,$user,$pwd,$struct,$publish)
743     {
744          $this->setUser($user,$pwd);
745          $this->setBlog();
746          $this->checkPagesPermission();
747         
748          $struct['post_type'] = 'page';
749         
750          return $this->newPost($blog_id,$user,$pwd,null,$struct,$publish);
751     }
752     
753     private function editPage($page_id,$user,$pwd,$struct,$publish)
754     {
755          $this->setUser($user,$pwd);
756          $this->setBlog();
757          $this->checkPagesPermission();
758         
759          $struct['post_type'] = 'page';
760         
761          return $this->editPost($page_id,$user,$pwd,null,$struct,$publish);
762     }
763     
764     private function deletePage($page_id,$user,$pwd)
765     {
766          $this->setUser($user,$pwd);
767          $this->setBlog();
768          $this->checkPagesPermission();
769         
770          $page_id = (integer) $page_id;
771         
772          $this->getPostRS($page_id,$user,$pwd,'page');
773          $this->core->blog->delPost($page_id);
774         
775          return true;
776     }
777     
778     private function getAuthors($user,$pwd)
779     {
780          $this->setUser($user,$pwd);
781          $this->setBlog();
782         
783          $perms = $this->core->getBlogPermissions($this->core->blog->id);
784          $res = array();
785         
786          foreach($perms as $k => $v)
787          {
788               $res[] = array(
789                    'user_id' => $k,
790                    'user_login' => $k,
791                    'display_name' => dcUtils::getUserCN($k,$v['name'],$v['firstname'],$v['displayname'])
792               );
793          }
794          return $res;
795     }
796     
797     private function getTags($user,$pwd)
798     {
799          $this->setUser($user,$pwd);
800          $this->setBlog();
801         
802          $tags = $this->core->meta->getMeta('tag');
803          $tags->sort('meta_id_lower','asc');
804         
805          $res = array();
806          $url   = $this->core->blog->url.
807               $this->core->url->getURLFor('tag','%s');
808          $f_url = $this->core->blog->url.
809               $this->core->url->getURLFor('tag_feed','%s');
810          foreach ($tags as $tag)
811          {
812               $res[] = array(
813                    'tag_id'       => $tag->meta_id,
814                    'name'         => $tag->meta_id,
815                    'count'        => $tag->count,
816                    'slug'         => $tag->meta_id,
817                    'html_url'     => sprintf($url,$tag->meta_id),
818                    'rss_url'      => sprintf($f_url,$tag->meta_id)
819               );
820          }
821          return $res;
822     }
823     
824     /* Blogger methods
825     --------------------------------------------------- */
826     public function blogger_newPost($appkey,$blogid,$username,$password,$content,$publish)
827     {
828          return $this->newPost($blogid,$username,$password,$content,array(),$publish);
829     }
830     
831     public function blogger_editPost($appkey,$postid,$username,$password,$content,$publish)
832     {
833          return $this->editPost($postid,$username,$password,$content,array(),$publish);
834     }
835     
836     public function blogger_getPost($appkey,$postid,$username,$password)
837     {
838          return $this->getPost($postid,$username,$password,'blogger');
839     }
840     
841     public function blogger_deletePost($appkey,$postid,$username,$password,$publish)
842     {
843          return $this->deletePost($postid,$username,$password);
844     }
845     
846     public function blogger_getRecentPosts($appkey,$blogid,$username,$password,$numberOfPosts)
847     {
848          return $this->getRecentPosts($blogid,$username,$password,$numberOfPosts,'blogger');
849     }
850     
851     public function blogger_getUserBlogs($appkey,$username,$password)
852     {
853          return $this->getUserBlogs($username,$password);
854     }
855     
856     public function blogger_getUserInfo($appkey,$username,$password)
857     {
858          return $this->getUserInfo($username,$password);
859     }
860     
861     
862     /* Metaweblog methods
863     ------------------------------------------------------- */
864     public function mw_newPost($blogid,$username,$password,$content,$publish)
865     {
866          return $this->newPost($blogid,$username,$password,'',$content,$publish);
867     }
868     
869     public function mw_editPost($postid,$username,$password,$content,$publish)
870     {
871          return $this->editPost($postid,$username,$password,'',$content,$publish);
872     }
873     
874     public function mw_getPost($postid,$username,$password)
875     {
876          return $this->getPost($postid,$username,$password,'mw');
877     }
878     
879     public function mw_getRecentPosts($blogid,$username,$password,$numberOfPosts)
880     {
881          return $this->getRecentPosts($blogid,$username,$password,$numberOfPosts,'mw');
882     }
883     
884     /* MovableType methods
885     --------------------------------------------------- */
886     public function mt_getRecentPostTitles($blogid,$username,$password,$numberOfPosts)
887     {
888          return $this->getRecentPosts($blogid,$username,$password,$numberOfPosts,'mt');
889     }
890     
891     public function mt_publishPost($postid,$username,$password)
892     {
893          return $this->publishPost($postid,$username,$password);
894     }
895     
896     public function mt_supportedTextFilters()
897     {
898          return array();
899     }
900     
901     /* WordPress methods
902     --------------------------------------------------- */
903     public function wp_getUsersBlogs($username,$password)
904     {
905          return $this->getUserBlogs($username,$password);
906     }
907     
908     public function wp_getPage($blogid,$pageid,$username,$password)
909     {
910          $res = $this->getPages($blogid,$username,$password,null,$pageid);
911         
912          if (empty($res)) {
913               throw new Exception('Sorry, no such page',404);
914          }
915         
916          return $res[0];
917     }
918     
919     public function wp_getPages($blogid,$username,$password,$num=10)
920     {
921          return $this->getPages($blogid,$username,$password,$num);
922     }
923     
924     public function wp_newPage($blogid,$username,$password,$content,$publish)
925     {
926          return $this->newPage($blogid,$username,$password,$content,$publish);
927     }
928     
929     public function wp_deletePage($blogid,$username,$password,$pageid)
930     {
931          return $this->deletePage($pageid,$username,$password);
932     }
933     
934     public function wp_editPage($blogid,$pageid,$username,$password,$content,$publish)
935     {
936          return $this->editPage($pageid,$username,$password,$content,$publish);
937     }
938     
939     public function wp_getPageList($blogid,$username,$password)
940     {
941          $A = $this->getPages($blogid,$username,$password);
942          $res = array();
943          foreach ($A as $v) {
944               $res[] = array(
945                    'page_id' => $v['page_id'],
946                    'page_title' => $v['title'],
947                    'page_parent_id' => $v['wp_page_parent_id'],
948                    'dateCreated' => $v['dateCreated'],
949                    'date_created_gmt' => $v['date_created_gmt']
950               );
951          }
952          return $res;
953     }
954     
955     public function wp_getAuthors($blogid,$username,$password)
956     {
957          return $this->getAuthors($username,$password);
958     }
959     
960     public function wp_getTags($blogid,$username,$password)
961     {
962          return $this->getTags($username,$password);
963     }
964     
965     public function wp_getPostStatusList($blogid,$username,$password)
966     {
967          return $this->getPostStatusList($blogid,$username,$password);
968     }
969     
970     public function wp_getPageStatusList($blogid,$username,$password)
971     {
972          return $this->getPostStatusList($blogid,$username,$password);
973     }
974     
975     public function wp_getPageTemplates($blogid,$username,$password)
976     {
977          return array('Default' => 'default');
978     }
979     
980     public function wp_getOptions($blogid,$username,$password,$options=array())
981     {
982          $this->setUser($username,$password);
983          $this->setBlog();
984         
985          return $this->translateWpOptions($options);
986     }
987     
988     public function wp_setOptions($blogid,$username,$password,$options)
989     {
990          $this->setUser($username,$password);
991          $this->setBlog();
992         
993          if (!$this->core->auth->check('admin',$this->core->blog->id)) {
994               throw new Exception('Not enough permissions to edit options.',401);
995          }
996         
997          $opt = $this->translateWpOptions();
998         
999          $done = array();
1000          $blog_changes = false;
1001          $cur = $this->core->con->openCursor($this->core->prefix.'blog');
1002         
1003          $this->core->blog->settings->addNamespace('system');
1004         
1005          foreach ($options as $name => $value)
1006          {
1007               if (!isset($opt[$name]) || $opt[$name]['readonly']) {
1008                    continue;
1009               }
1010               
1011               switch ($name)
1012               {
1013                    case 'blog_title':
1014                         $blog_changes = true;
1015                         $cur->blog_name = $value;
1016                         $done[] = $name;
1017                         break;
1018                    case 'blog_tagline':
1019                         $blog_changes = true;
1020                         $cur->blog_desc = $value;
1021                         $done[] = $name;
1022                         break;
1023                    case 'date_format':
1024                         $this->core->blog->settings->system->put('date_format',$value);
1025                         $done[] = $name;
1026                         break;
1027                    case 'time_format':
1028                         $this->core->blog->settings->system->put('time_format',$value);
1029                         $done[] = $name;
1030                         break;
1031               }
1032          }
1033         
1034          if ($blog_changes) {
1035               $this->core->updBlog($this->core->blog->id,$cur);
1036               $this->core->setBlog($this->core->blog->id);
1037          }
1038         
1039          return $this->translateWpOptions($done);
1040     }
1041     
1042}
1043?>
Note: See TracBrowser for help on using the repository browser.

Sites map