/
XmlRpc.php
2343 lines (2065 loc) · 78.8 KB
/
XmlRpc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* Typecho Blog Platform
*
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
* @version $Id$
*/
/**
* XmlRpc接口
*
* @author blankyao
* @category typecho
* @package Widget
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
*/
class Widget_XmlRpc extends Widget_Abstract_Contents implements Widget_Interface_Do
{
/**
* 当前错误
*
* @access private
* @var IXR_Error
*/
private $error;
/**
* wordpress风格的系统选项
*
* @access private
* @var array
*/
private $_wpOptions;
/**
* 已经使用过的组件列表
*
* @access private
* @var array
*/
private $_usedWidgetNameList = array();
/**
* 获取扩展字段
*
* @access private
* @param Widget_Abstract_Contents $content
* @return array
*/
private function getPostExtended(Widget_Abstract_Contents $content)
{
//根据客户端显示来判断是否显示html代码
$agent = $this->request->getAgent();
$text = '';
switch (true) {
case false !== strpos($agent, 'wp-iphone'): // wordpress iphone客户端
case false !== strpos($agent, 'wp-blackberry'): // 黑莓
case false !== strpos($agent, 'wp-andriod'): // andriod
case false !== strpos($agent, 'plain-text'): // 这是预留给第三方开发者的接口, 用于强行调用非所见即所得数据
case $this->options->xmlrpcMarkdown:
$text = $content->text;
break;
default:
$text = $content->content;
break;
}
$post = explode('<!--more-->', $text, 2);
return array(
$this->options->xmlrpcMarkdown? $post[0] : Typecho_Common::fixHtml($post[0]),
isset($post[1]) ? Typecho_Common::fixHtml($post[1]) : NULL
);
}
/**
* 将typecho的状态类型转换为wordperss的风格
*
* @access private
* @param string $status typecho的状态
* @param string $type 内容类型
* @return string
*/
private function typechoToWordpressStatus($status, $type = 'post')
{
if ('post' == $type) {
/** 文章状态 */
switch ($status) {
case 'waiting':
return 'pending';
case 'publish':
case 'draft':
case 'private':
return $status;
default:
return 'publish';
}
} else if ('page' == $type) {
switch ($status) {
case 'publish':
case 'draft':
case 'private':
return $status;
default:
return 'publish';
}
} else if ('comment' == $type) {
switch ($status) {
case 'publish':
case 'approved':
return 'approve';
case 'waiting':
return 'hold';
case 'spam':
return $status;
default:
return 'approve';
}
}
return '';
}
/**
* 将wordpress的状态类型转换为typecho的风格
*
* @access private
* @param string $status wordpress的状态
* @param string $type 内容类型
* @return string
*/
private function wordpressToTypechoStatus($status, $type = 'post')
{
if ('post' == $type) {
/** 文章状态 */
switch ($status) {
case 'pending':
return 'waiting';
case 'publish':
case 'draft':
case 'private':
case 'waiting':
return $status;
default:
return 'publish';
}
} else if ('page' == $type) {
switch ($status) {
case 'publish':
case 'draft':
case 'private':
return $status;
default:
return 'publish';
}
} else if ('comment' == $type) {
switch ($status) {
case 'approve':
case 'publish':
case 'approved':
return 'approved';
case 'hold':
case 'waiting':
return 'waiting';
case 'spam':
return $status;
default:
return 'approved';
}
}
return '';
}
/**
* 代理工厂方法,将类静态化放置到列表中
*
* @access public
* @param string $alias 组件别名
* @param mixed $params 传递的参数
* @param mixed $request 前端参数
* @param boolean $enableResponse 是否允许http回执
* @return object
* @throws Typecho_Exception
*/
private function singletonWidget($alias, $params = NULL, $request = NULL, $enableResponse = true)
{
$this->_usedWidgetNameList[] = $alias;
return Typecho_Widget::widget($alias, $params, $request, $enableResponse);
}
/**
* 如果这里没有重载, 每次都会被默认执行
*
* @access public
* @param boolen $run 是否执行
* @return void
*/
public function execute($run = false)
{
if ($run) {
parent::execute();
}
// 临时保护模块
$this->security->enable(false);
$this->_wpOptions = array(
// Read only options
'software_name' => array(
'desc' => _t( '软件名称' ),
'readonly' => true,
'value' => $this->options->software
),
'software_version' => array(
'desc' => _t( '软件版本' ),
'readonly' => true,
'value' => $this->options->version
),
'blog_url' => array(
'desc' => _t( '博客地址' ),
'readonly' => true,
'option' => 'siteUrl'
),
'home_url' => array(
'desc' => _t( '博客首页地址' ),
'readonly' => true,
'option' => 'siteUrl'
),
'login_url' => array(
'desc' => _t( '登录地址' ),
'readonly' => true,
'value' => $this->options->siteUrl.'admin/login.php'
),
'admin_url' => array(
'desc' => _t( '管理区域的地址' ),
'readonly' => true,
'value' => $this->options->siteUrl.'admin/'
),
'post_thumbnail' => array(
'desc' => _t( '文章缩略图' ),
'readonly' => true,
'value' => false
),
// Updatable options
'time_zone' => array(
'desc' => _t( '时区' ),
'readonly' => false,
'option' => 'timezone'
),
'blog_title' => array(
'desc' => _t( '博客标题' ),
'readonly' => false,
'option' => 'title'
),
'blog_tagline' => array(
'desc' => _t( '博客关键字' ),
'readonly' => false,
'option' => 'description'
),
'date_format' => array(
'desc' => _t( '日期格式' ),
'readonly' => false,
'option' => 'postDateFormat'
),
'time_format' => array(
'desc' => _t( '时间格式' ),
'readonly' => false,
'option' => 'postDateFormat'
),
'users_can_register' => array(
'desc' => _t( '是否允许注册' ),
'readonly' => false,
'option' => 'allowRegister'
)
);
}
/**
* 检查权限
*
* @access public
* @return void
*/
public function checkAccess($name, $password, $level = 'contributor')
{
if ($this->user->login($name, $password, true)) {
/** 验证权限 */
if ($this->user->pass($level, true)) {
$this->user->execute();
return true;
} else {
$this->error = new IXR_Error(403, _t('权限不足'));
return false;
}
} else {
$this->error = new IXR_Error(403, _t('无法登陆, 密码错误'));
return false;
}
}
/**
* 获取pageId指定的page
* about wp xmlrpc api, you can see http://codex.wordpress.org/XML-RPC
*
* @param int $blogId
* @param int $pageId
* @param string $userName
* @param string $password
* @access public
* @return struct $pageStruct
*/
public function wpGetPage($blogId, $pageId, $userName, $password)
{
/** 检查权限 */
if (!$this->checkAccess($userName, $password)) {
return $this->error;
}
/** 获取页面 */
try {
/** 由于Widget_Contents_Page_Edit是从request中获取参数, 因此我们需要强行设置flush一下request */
/** widget方法的第三个参数可以指定强行转换传入此widget的request参数 */
/** 此组件会进行复杂的权限检测 */
$page = $this->singletonWidget('Widget_Contents_Page_Edit', NULL, "cid={$pageId}");
} catch (Typecho_Widget_Exception $e) {
/** 截获可能会抛出的异常(参见 Widget_Contents_Page_Edit 的 execute 方法) */
return new IXR_Error($e->getCode(), $e->getMessage());
}
/** 对文章内容做截取处理,以获得description和text_more*/
list($excerpt, $more) = $this->getPostExtended($page);
$pageStruct = array(
'dateCreated' => new IXR_Date($this->options->timezone + $page->created),
'userid' => $page->authorId,
'page_id' => $page->cid,
'page_status' => $this->typechoToWordpressStatus($page->status, 'page'),
'description' => $excerpt,
'title' => $page->title,
'link' => $page->permalink,
'permaLink' => $page->permalink,
'categories' => $page->categories,
'excerpt' => $page->description,
'text_more' => $more,
'mt_allow_comments' => intval($page->allowComment),
'mt_allow_pings' => intval($page->allowPing),
'wp_slug' => $page->slug,
'wp_password' => $page->password,
'wp_author' => $page->author->name,
'wp_page_parent_id' => '0',
'wp_page_parent_title' => '',
'wp_page_order' => $page->order, //meta是描述字段, 在page时表示顺序
'wp_author_id' => $page->authorId,
'wp_author_display_name' => $page->author->screenName,
'date_created_gmt' => new IXR_Date($page->created),
'custom_fields' => array(),
'wp_page_template' => $page->template
);
return $pageStruct;
}
/**
* 获取所有的page
*
* @param int $blogId
* @param string $userName
* @param string $password
* @access public
* @return array(contains $pageStruct)
*/
public function wpGetPages($blogId, $userName, $password)
{
if (!$this->checkAccess($userName, $password)) {
return $this->error;
}
/** 过滤type为page的contents */
/** 同样需要flush一下, 需要取出所有status的页面 */
$pages = $this->singletonWidget('Widget_Contents_Page_Admin', NULL, 'status=all');
/** 初始化要返回的数据结构 */
$pageStructs = array();
while ($pages->next()) {
/** 对文章内容做截取处理,以获得description和text_more*/
list($excerpt, $more) = $this->getPostExtended($pages);
$pageStructs[] = array(
'dateCreated' => new IXR_Date($this->options->timezone + $pages->created),
'userid' => $pages->authorId,
'page_id' => intval($pages->cid),
/** todo:此处有疑问 */
'page_status' => $this->typechoToWordpressStatus($pages->status, 'page'),
'description' => $excerpt,
'title' => $pages->title,
'link' => $pages->permalink,
'permaLink' => $pages->permalink,
'categories' => $pages->categories,
'excerpt' => $pages->description,
'text_more' => $more,
'mt_allow_comments' => intval($pages->allowComment),
'mt_allow_pings' => intval($pages->allowPing),
'wp_slug' => $pages->slug,
'wp_password' => $pages->password,
'wp_author' => $pages->author->name,
'wp_page_parent_id' => 0,
'wp_page_parent_title' => '',
'wp_page_order' => intval($pages->order), //meta是描述字段, 在page时表示顺序
'wp_author_id' => $pages->authorId,
'wp_author_display_name' => $pages->author->screenName,
'date_created_gmt' => new IXR_Date($pages->created),
'custom_fields' => array(),
'wp_page_template' => $pages->template
);
}
return $pageStructs;
}
/**
* 撰写一个新page
*
* @param int $blogId
* @param string $userName
* @param string $password
* @param struct $content
* @param bool $publish
* @access public
* @return void
*/
public function wpNewPage($blogId, $userName, $password, $content, $publish)
{
if (!$this->checkAccess($userName, $password, 'editor')) {
return $this->error;
}
$content['post_type'] = 'page';
$this->mwNewPost($blogId, $userName, $password, $content, $publish);
}
/**
* 删除pageId指定的page
*
* @param int $blogId
* @param string $userName
* @param string $password
* @param int $pageId
* @access public
* @return bool
*/
public function wpDeletePage($blogId, $userName, $password, $pageId)
{
if (!$this->checkAccess($userName, $password, 'editor')) {
return $this->error;
}
/** 删除页面 */
try {
/** 此组件会进行复杂的权限检测 */
$this->singletonWidget('Widget_Contents_Page_Edit', NULL, "cid={$pageId}", false)->deletePage();
} catch (Typecho_Widget_Exception $e) {
/** 截获可能会抛出的异常(参见 Widget_Contents_Page_Edit 的 execute 方法) */
return new IXR_Error($e->getCode(), $e->getMessage());
}
return true;
}
/**
* 编辑pageId指定的page
*
* @param int $blogId
* @param int $pageId
* @param string $userName
* @param string $password
* @param struct $content
* @param bool $publish
* @access public
* @return bool
*/
public function wpEditPage($blogId, $pageId, $userName, $password, $content, $publish)
{
$content['type'] = 'page';
$this->mwEditPost($blogId, $pageId, $userName, $password, $content, $publish);
}
/**
* 编辑postId指定的post
*
* @param int $blogId
* @param string $userName
* @param string $password
* @param int $postId
* @param struct $content
* @access public
* @return bool
*/
public function wpEditPost($blogId, $userName, $password, $postId, $content)
{
$post = $this->singletonWidget('Widget_Archive', 'type=single', 'cid=' . $postId, false);
if ($post->type == 'attachment') {
$attachment['title'] = $content['post_title'];
$attachment['slug'] = $content['post_excerpt'];
$text = unserialize($post->text);
$text['description'] = $content['description'];
$attachment['text'] = serialize($text);
/** 更新数据 */
$updateRows = $this->update($attachment, $this->db->sql()->where('cid = ?', $postId));
return true;
}
return $this->mwEditPost($blogId, $postId, $userName, $password, $content);
}
/**
* 获取page列表,没有wpGetPages获得的详细
*
* @param int $blogId
* @param string $userName
* @param string $password
* @access public
* @return array
*/
public function wpGetPageList($blogId, $userName, $password)
{
if (!$this->checkAccess($userName, $password, 'editor')) {
return ($this->error);
}
$pages = $this->singletonWidget('Widget_Contents_Page_Admin', NULL, 'status=all');
/**初始化*/
$pageStructs = array();
while ($pages->next()) {
$pageStructs[] = array(
'dateCreated' => new IXR_Date($this->options->timezone + $pages->created),
'date_created_gmt' => new IXR_Date($this->options->timezone + $pages->created),
'page_id' => $pages->cid,
'page_title' => $pages->title,
'page_parent_id' => '0',
);
}
return $pageStructs;
}
/**
* 获得一个由blog所有作者的信息组成的数组
*
* @param int $blogId
* @param string $userName
* @param string $password
* @access public
* @return struct
*/
public function wpGetAuthors($blogId, $userName, $password)
{
if (!$this->checkAccess($userName, $password, 'editor')) {
return ($this->error);
}
/** 构建查询*/
$select = $this->db->select('table.users.uid', 'table.users.name', 'table.users.screenName')->from('table.users');
$authors = $this->db->fetchAll($select);
$authorStructs = array();
foreach ($authors as $author) {
$authorStructs[] = array(
'user_id' => $author['uid'],
'user_login' => $author['name'],
'display_name' => $author['screenName']
);
}
return $authorStructs;
}
/**
* 添加一个新的分类
*
* @param int $blogId
* @param string $userName
* @param string $password
* @param struct $category
* @access public
* @return void
*/
public function wpNewCategory($blogId, $userName, $password, $category)
{
if (!$this->checkAccess($userName, $password)) {
return ($this->error);
}
/** 开始接受数据 */
$input['name'] = $category['name'];
$input['slug'] = Typecho_Common::slugName(empty($category['slug']) ? $category['name'] : $category['slug']);
$input['parent'] = isset($category['parent_id']) ? $category['parent_id'] :
(isset($category['parent']) ? $category['parent'] : 0);
$input['description'] = isset($category['description']) ? $category['description'] : $category['name'];
$input['do'] = 'insert';
/** 调用已有组件 */
try {
/** 插入 */
$categoryWidget = $this->singletonWidget('Widget_Metas_Category_Edit', NULL, $input, false);
$categoryWidget->action();
return $categoryWidget->mid;
} catch (Typecho_Widget_Exception $e) {
return new IXR_Error($e->getCode(), $e->getMessage());
}
return new IXR_Error(403, _t('无法添加分类'));
}
/**
* 获取由给定的string开头的链接组成的数组
*
* @param int $blogId
* @param string $userName
* @param string $password
* @param string $category
* @param int $max_results
* @access public
* @return array
*/
public function wpSuggestCategories($blogId, $userName, $password, $category, $max_results)
{
if (!$this->checkAccess($userName, $password)) {
return ($this->error);
}
$meta = $this->singletonWidget('Widget_Abstract_Metas');
/** 构造出查询语句并且查询*/
$key = Typecho_Common::filterSearchQuery($category);
$key = '%' . $key . '%';
$select = $meta->select()->where('table.metas.type = ? AND (table.metas.name LIKE ? OR slug LIKE ?)', 'category', $key, $key);
/** 不要category push到contents的容器中 */
$categories = $this->db->fetchAll($select);
/** 初始化categorise数组*/
$categoryStructs = array();
foreach ($categories as $category) {
$categoryStructs[] = array(
'category_id' => $category['mid'],
'category_name' => $category['name'],
);
}
return $categoryStructs;
}
/**
* 获取用户
*
* @access public
* @param string $userName 用户名
* @param string $password 密码
* @return array
*/
public function wpGetUsersBlogs($userName, $password)
{
if (!$this->checkAccess($userName, $password)) {
return $this->error;
}
$struct = array();
$struct[] = array(
'isAdmin' => $this->user->pass('administrator', true),
'url' => $this->options->siteUrl,
'blogid' => '1',
'blogName' => $this->options->title,
'xmlrpc' => $this->options->xmlRpcUrl
);
return $struct;
}
/**
* 获取用户
*
* @access public
* @param string $userName 用户名
* @param string $password 密码
* @return array
*/
public function wpGetProfile($blogId, $userName, $password)
{
if (!$this->checkAccess($userName, $password)) {
return $this->error;
}
$struct = array(
'user_id' => $this->user->uid,
'username' => $this->user->name,
'first_name' => '',
'last_name' => '',
'registered' => new IXR_Date($this->options->timezone + $this->user->created),
'bio' => '',
'email' => $this->user->mail,
'nickname' => $this->user->screenName,
'url' => $this->user->url,
'display_name' => $this->user->screenName,
'roles' => $this->user->group
);
return $struct;
}
/**
* 获取标签列表
*
* @access public
* @param integer $blogId
* @param string $userName
* @param string $password
* @return array
*/
public function wpGetTags($blogId, $userName, $password)
{
/** 检查权限*/
if (!$this->checkAccess($userName, $password)) {
return $this->error;
}
$struct = array();
$tags = $this->singletonWidget('Widget_Metas_Tag_Cloud');
while ($tags->next()) {
$struct[] = array(
'tag_id' => $tags->mid,
'name' => $tags->name,
'count' => $tags->count,
'slug' => $tags->slug,
'html_url' => $tags->permalink,
'rss_url' => $tags->feedUrl
);
}
return $struct;
}
/**
* 删除分类
*
* @access public
* @param integer $blogId
* @param string $userName
* @param string $password
* @param integer $categoryId
* @return array
*/
public function wpDeleteCategory($blogId, $userName, $password, $categoryId)
{
/** 检查权限*/
if (!$this->checkAccess($userName, $password, 'editor')) {
return $this->error;
}
try {
$this->singletonWidget('Widget_Metas_Category_Edit', NULL, 'do=delete&mid=' . intval($categoryId), false);
return true;
} catch (Typecho_Exception $e) {
return false;
}
}
/**
* 获取评论数目
*
* @access public
* @param integer $blogId
* @param string $userName
* @param string $password
* @param integer $postId
* @return array
*/
public function wpGetCommentCount($blogId, $userName, $password, $postId)
{
/** 检查权限*/
if (!$this->checkAccess($userName, $password)) {
return $this->error;
}
$stat = $this->singletonWidget('Widget_Stat', NULL, 'cid=' . intval($postId), false);
return array(
'approved' => $stat->currentPublishedCommentsNum,
'awaiting_moderation' => $stat->currentWaitingCommentsNum,
'spam' => $stat->currentSpamCommentsNum,
'total_comments' => $stat->currentCommentsNum
);
}
/**
* 获取文章类型列表
*
* @access public
* @param integer $blogId
* @param string $userName
* @param string $password
* @return array
*/
public function wpGetPostFormats($blogId, $userName, $password)
{
/** 检查权限*/
if (!$this->checkAccess($userName, $password)) {
return $this->error;
}
return array(
'standard' => _t('标准')
);
}
/**
* 获取文章状态列表
*
* @access public
* @param integer $blogId
* @param string $userName
* @param string $password
* @return array
*/
public function wpGetPostStatusList($blogId, $userName, $password)
{
/** 检查权限*/
if (!$this->checkAccess($userName, $password)) {
return $this->error;
}
return array(
'draft' => _t('草稿'),
'pending' => _t('待审核'),
'publish' => _t('已发布')
);
}
/**
* 获取页面状态列表
*
* @access public
* @param integer $blogId
* @param string $userName
* @param string $password
* @return array
*/
public function wpGetPageStatusList($blogId, $userName, $password)
{
/** 检查权限*/
if (!$this->checkAccess($userName, $password, 'editor')) {
return $this->error;
}
return array(
'draft' => _t('草稿'),
'publish' => _t('已发布')
);
}
/**
* 获取评论状态列表
*
* @access public
* @param integer $blogId
* @param string $userName
* @param string $password
* @return array
*/
public function wpGetCommentStatusList($blogId, $userName, $password)
{
/** 检查权限*/
if (!$this->checkAccess($userName, $password)) {
return $this->error;
}
return array(
'hold' => _t('待审核'),
'approve' => _t('显示'),
'spam' => _t('垃圾')
);
}
/**
* 获取页面模板
*
* @access public
* @param integer $blogId
* @param string $userName
* @param string $password
* @return array
*/
public function wpGetPageTemplates($blogId, $userName, $password)
{
/** 检查权限*/
if (!$this->checkAccess($userName, $password, 'editor')) {
return $this->error;
}
$templates = array_flip($this->getTemplates());
$templates['Default'] = '';
return $templates;
}
/**
* 获取系统选项
*
* @access public
* @param integer $blogId
* @param string $userName
* @param string $password
* @param array $options
* @return array
*/
public function wpGetOptions($blogId, $userName, $password, $options = array())
{
/** 检查权限*/
if (!$this->checkAccess($userName, $password, 'administrator')) {
return $this->error;
}
$struct = array();
if (empty($options)) {
$options = array_keys($this->_wpOptions);
}
foreach ($options as $option) {
if (isset($this->_wpOptions[$option])) {
$struct[$option] = $this->_wpOptions[$option];
if (isset($struct[$option]['option'])) {
$struct[$option]['value'] = $this->options->{$struct[$option]['option']};
unset($struct[$option]['option']);
}
}
}
return $struct;
}
/**
* 设置系统选项
*
* @access public
* @param integer $blogId
* @param string $userName
* @param string $password
* @param array $options
* @return array
*/
public function wpSetOptions($blogId, $userName, $password, $options = array())
{
/** 检查权限*/
if (!$this->checkAccess($userName, $password, 'administrator')) {
return $this->error;
}
$struct = array();
foreach ($options as $option => $value) {
if (isset($this->_wpOptions[$option])) {
$struct[$option] = $this->_wpOptions[$option];
if (isset($struct[$option]['option'])) {
$struct[$option]['value'] = $this->options->{$struct[$option]['option']};
unset($struct[$option]['option']);
}
if (!$this->_wpOptions[$option]['readonly'] && isset($this->_wpOptions[$option]['option'])) {
if ($this->db->query($this->db->update('table.options')
->rows(array('value' => $value))
->where('name = ?', $this->_wpOptions[$option]['option'])) > 0) {
$struct[$option]['value'] = $value;
}
}
}
}
return $struct;
}
/**
* 获取评论
*
* @access public
* @param integer $blogId
* @param string $userName
* @param string $password
* @param integer $commentId
* @return array