-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetaweblog.php
1507 lines (1346 loc) · 52.6 KB
/
metaweblog.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
ini_set("display_errors", 1);
//22/10/2009 9.58.12
//general list of implementaion and
// TODO admin log implementation to log out all the traffic
// TODO error handling (not really sure how can be done, at least in log)
// TODO better ACL configuration (getperms) and admin panel to configure ACL (example this user has rw access to news?) wraps ACL configuration
// TODO custom content plugin support
// TODO sintax to write in custom field of custom (ie sort of: {field_name:value}) this one need WLW customization OR use the wordpress plugin see http://windowslivewire.spaces.live.com/blog/cns!2F7EB29B42641D59!41603.entry AND http://codex.wordpress.org/Custom_Fields
// TODO better admin preferences panel (for example to choise to use content plugin instead of pages)
// TODO full manual/instructions to explain configuration of plugin and WLW
//check e107 instance
if (!defined('e107_INIT'))
{
require_once("../../class2.php");
}
//check if plugin is installed
if (!e107::isInstalled('metaweblog'))
{
e107::redirect();
}
if((e_QUERY == 'rsd') || isset($_GET['rsd'])) // http://archipelago.phrasewise.com/rsd
{
header('Content-Type: text/xml; charset=UTF-8', true);
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rsd version=\"1.0\" xmlns=\"http://archipelago.phrasewise.com/rsd\">
<service>
<engineName>e107</engineName>
<engineLink>http://www.e107.org/</engineLink>
<homePageLink>".SITEURL."</homePageLink>
<apis>
<api name=\"WordPress\" blogID=\"1\" preferred=\"true\" apiLink=\"".SITEURLBASE.e_PLUGIN_ABS."metaweblog/metaweblog.php\" />
<api name=\"Movable Type\" blogID=\"1\" preferred=\"false\" apiLink=\"". SITEURLBASE.e_PLUGIN_ABS."metaweblog/metaweblog.php\" />
<api name=\"MetaWeblog\" blogID=\"1\" preferred=\"false\" apiLink=\"". SITEURLBASE.e_PLUGIN_ABS."metaweblog/metaweblog.php\" />
<api name=\"Blogger\" blogID=\"1\" preferred=\"false\" apiLink=\"". SITEURLBASE.e_PLUGIN_ABS."metaweblog/metaweblog.php\" />
</apis>
</service>
</rsd>";
exit;
}
// These three files are from the PHP-XMLRPC library.
include_once (e_PLUGIN.'metaweblog/xmlrpc/xmlrpc.inc.php');
include_once (e_PLUGIN.'metaweblog/xmlrpc/xmlrpcs.inc.php');
include_once (e_PLUGIN.'metaweblog/xmlrpc/xmlrpc_wrappers.inc.php');
//general note: XMLRPC method functions parameters
//have this rule: 1st parameter is the type of the OUT data (result: array,struct,etc), from 2nd are the IN parameters
//default caracter encoding !IMPORTANT
$xmlrpc_internalencoding = 'UTF-8';
// VARIABLES FOR SOME REASONS $pref seems to not work in code? so we define local variables
define('eXMLRPC_FILES_UPLOAD_PATH', e_NEWSIMAGE);
define('eXMLRPC_FILES_SITEBASE_URL', e_NEWSIMAGE_ABS);
define('eXMLRPC_BLOG_XMLRPC', e_PLUGIN_ABS.'metaweblog/metaweblog.php');
define('eXMLRPC_NEWS_RENDER_TYPE_LOC', $pref['eXMLRPC_NEWS_RENDER_TYPE']);
define('eXMLRPC_BLOG_ID_LOC', $pref['eXMLRPC_BLOG_ID']);
define('eXMLRPC_BLOG_NAME_LOC', SITENAME ); // $pref['eXMLRPC_BLOG_NAME']
/*
* Used to test usage of object methods in dispatch maps
*/
class xmlrpc_server_methods_container
{
}
//13/08/2009 17.08.11
//to add function to check users priledges for $area...
function userLogin($username, $password, $area)
{
$sql = e107::getDb();
$query = 'SELECT user_perms FROM #user WHERE user_loginname = \''.$username.'\' AND user_password = \''.md5($password).'\'';
$sql->db_Select_gen($query);
$row = $sql->db_Fetch();
//variable to store user permissions
$perms = explode('.', $row['user_perms']);
$haspe = in_array($area, $perms);
//if neededs permissions are founds or user is the main site admin
if (($haspe != false) || ($row['user_perms'] == 0))
{
return true;
}
else
{
return false;
}
}
$getUsersBlogs_sig = array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString));
$getUsersBlogs_doc = 'Returns a list of weblogs to which an author has posting privileges.';
function getUsersBlogs($xmlrpcmsg)
{
$structArray = array();
$structArray[] = new xmlrpcval(array(
'isAdmin'=> new xmlrpcval(true, 'boolean'),
'url'=> new xmlrpcval(SITEURL, 'string'),
'blogid'=> new xmlrpcval(eXMLRPC_BLOG_ID_LOC, 'string'),
'blogName'=> new xmlrpcval(eXMLRPC_BLOG_NAME_LOC, 'string'),
'xmlrpc'=> new xmlrpcval(eXMLRPC_BLOG_XMLRPC, 'string')
),'struct');
return new xmlrpcresp(new xmlrpcval($structArray, 'array'));
}
/*
*************************
***** NEW POST *********
*************************
*/
$newPost_sig = array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcStruct, $xmlrpcBoolean));
$newPost_doc = 'Post a new item to the blog.';
function newPost($xmlrpcmsg)
{
$blogid = $xmlrpcmsg->getParam(0)->scalarval();
$username = $xmlrpcmsg->getParam(1)->scalarval();
$password = $xmlrpcmsg->getParam(2)->scalarval();
if (userLogin($username, $password, 'H') == true)
{
$content = $xmlrpcmsg->getParam(3);
$title = $content->structMem('title')->scalarval();
$description = '[html]'.htmlspecialchars_decode($content->structMem('description')->scalarval()).'[/html]';
//22/10/2009 14.48.04 added mt_text_more ie news_extended
//check if we have something...
$tempTextMore = checkXmlElementS($content->serialize(), 'mt_text_more');
if($tempTextMore == 1){
$mt_text_more = '[html]'.$content->structMem('mt_text_more')->scalarval().'[/html]';
}
//if date is null will be replaced with current datetime (wordpress like)
//check with simplexml for the parameter dateCreated? XMLRPC-PHP seems to not have such functions??
$tempDate = checkXmlElementS($content->serialize(), 'dateCreated');
if ($tempDate == 1)
{
$dateCreated = $content->structMem('dateCreated')->serialize(); // Not all clients send dateCreated info. So add if statement here if you want to use it.
$timestamp = iso8601_decode($dateCreated); // To convert to unix timestamp
}
else
{
$timestamp = time();
}
//21/10/2009 17.17.46 added $mt_excerpt
//add in the news summary
//check if we have something...
$tempExcerpt = checkXmlElementS($content->serialize(), 'mt_excerpt');
if($tempExcerpt == 1){
$mt_excerpt = $content->structMem('mt_excerpt')->scalarval();
}
//22/10/2009 11.51.54 added $mt_allow_comments
//add the news_allow_comments flag
//check if we have something...
$tempAllowComments = checkXmlElementS($content->serialize(), 'mt_allow_comments');
if($tempAllowComments == 1){
$mt_allow_comments = $content->structMem('mt_allow_comments')->scalarval();
}
//26/10/2009 14.30.41 added mt_keywords ie tags
//check if we have something...
$tempKeywords = checkXmlElementS($content->serialize(), 'mt_keywords');
if($tempKeywords == 1){
$mt_keywords = $content->structMem('mt_keywords')->scalarval();
}
//author from e107
$query = 'SELECT u.user_id FROM `#user` AS u WHERE u.user_loginname = \''.$username.'\' AND u.user_password = \''.md5($password).'\'';
$sql = e107::getDb();
$sql->db_Select_gen($query);
$row = $sql->db_Fetch();
$author = $row['user_id'];
if ($content->structMem('categories')->arraySize() > 0)
{
$categories = $content->structMem('categories')->arrayMem(0)->scalarval();
//try to read out the id of the category
if ($categories != '')
{
$query = 'SELECT c.category_id FROM `#news_category` AS c WHERE c.category_name = \''.$categories.'\'';
$sql->db_Select_gen($query);
$row = $sql->db_Fetch();
$categories = $row['category_id'];
}
}
$published = $xmlrpcmsg->getParam(4)->scalarval();
// TODO use:
// $ix = new news;
// $ret = $ix->submit_item($arrayvalues);
//post data with new fuctions
$data = array();
$data['data']['news_title'] = $title;
$data['_FIELD_TYPES']['news_title'] = 'todb';
$data['data']['news_body'] = $description;
$data['_FIELD_TYPES']['news_body'] = 'todb';
$data['data']['news_extended'] = $mt_text_more;
$data['_FIELD_TYPES']['news_extended'] = 'todb';
$data['data']['news_datestamp'] = $timestamp;
$data['_FIELD_TYPES']['news_datestamp'] = 'int';
$data['data']['news_author'] = $author;
$data['_FIELD_TYPES']['news_author'] = 'int';
$data['data']['news_category'] = $categories; //category id is taken by a query against news categories
$data['_FIELD_TYPES']['news_category'] = 'int';
$data['data']['news_allow_comments'] = $mt_allow_comments;
$data['_FIELD_TYPES']['news_allow_comments'] = 'int';
$data['data']['news_start'] = ''; //NOT AVAIBLE MAKE A CUSTOM FIELD?
$data['_FIELD_TYPES']['news_start'] = 'int';
$data['data']['news_end'] = ''; //NOT AVAIBLE MAKE A CUSTOM FIELD?
$data['_FIELD_TYPES']['news_end'] = 'int';
//$data['data']['news_class'] = $news['news_class'];
//$data['_FIELD_TYPES']['news_class'] = 'todb';
$data['data']['news_render_type'] = eXMLRPC_NEWS_RENDER_TYPE_LOC; //from preferences
$data['_FIELD_TYPES']['news_render_type'] = 'int';
//news_comment_total
$data['data']['news_summary'] = $mt_excerpt; //NOT AVAIBLE MAKE A CUSTOM FIELD?
$data['_FIELD_TYPES']['news_summary'] = 'todb';
$data['data']['news_thumbnail'] = ''; //NOT APPLICABLE?
$data['_FIELD_TYPES']['news_thumbnail'] = 'todb';
$data['data']['news_sticky'] = ''; //NOT AVAIBLE MAKE A CUSTOM FIELD?
$data['_FIELD_TYPES']['news_sticky'] = 'int';
$data['data']['news_meta_keywords'] = $mt_keywords;
$data['_FIELD_TYPES']['news_meta_keywords'] = 'todb';
$data['data']['news_meta_description'] = ''; //NOT AVAIBLE MAKE A CUSTOM FIELD?
$data['_FIELD_TYPES']['news_meta_description'] = 'todb';
$postid = $sql->db_Insert('news', $data);
return new xmlrpcresp( new xmlrpcval($postid, 'string')); // Return the id of the post just inserted into the DB. See mysql_insert_id() in the PHP manual.
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** EDIT POST *********
*************************
*/
$editPost_sig = array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcStruct, $xmlrpcBoolean));
$editPost_doc = 'Edit item on the blog.';
function editPost($xmlrpcmsg)
{
$postid = $xmlrpcmsg->getParam(0)->scalarval();
$username = $xmlrpcmsg->getParam(1)->scalarval();
$password = $xmlrpcmsg->getParam(2)->scalarval();
if (userLogin($username, $password, 'H') == true)
{
$content = $xmlrpcmsg->getParam(3);
$title = $content->structMem('title')->scalarval();
$description = '[html]'.$content->structMem('description')->scalarval().'[/html]';
//22/10/2009 14.48.04 added mt_text_more ie news_extended
//check if we have something...
$tempTextMore = checkXmlElementS($content->serialize(), 'mt_text_more');
if($tempTextMore == 1){
$mt_text_more = '[html]'.$content->structMem('mt_text_more')->scalarval().'[/html]';
}
//if date is null will be replaced with current datetime (wordpress like)
//check with simplexml for the parameter dateCreated? XMLRPC-PHP seems to not have such functions??
$tempDate = checkXmlElementS($content->serialize(), 'dateCreated');
if ($tempDate == 1)
{
$dateCreated = $content->structMem('dateCreated')->serialize(); // Not all clients send dateCreated info. So add if statement here if you want to use it.
$timestamp = iso8601_decode($dateCreated); // To convert to unix timestamp
}
else
{
$timestamp = time();
}
//22/10/2009 11.51.54 added $mt_excerpt
//add the news summary
//check if we have something...
$tempExcerpt = checkXmlElementS($content->serialize(), 'mt_excerpt');
if($tempExcerpt == 1){
$mt_excerpt = $content->structMem('mt_excerpt')->scalarval();
}
//22/10/2009 11.51.54 added $mt_allow_comments
//add the news_allow_comments flag
//check if we have something...
$tempAllowComments = checkXmlElementS($content->serialize(), 'mt_allow_comments');
if($tempAllowComments == 1){
$mt_allow_comments = $content->structMem('mt_allow_comments')->scalarval();
}
//26/10/2009 14.30.41 added mt_keywords ie tags
//check if we have something...
$tempKeywords = checkXmlElementS($content->serialize(), 'mt_keywords');
if($tempKeywords == 1){
$mt_keywords = $content->structMem('mt_keywords')->scalarval();
}
//author from e107
$query = 'SELECT u.user_id FROM `#user` AS u WHERE u.user_loginname = \''.$username.'\' AND u.user_password = \''.md5($password).'\'';
$sql = new db();
$sql->db_Select_gen($query);
$row = $sql->db_Fetch();
$author = $row['user_id'];
if ($content->structMem('categories')->arraySize() > 0)
{
$categories = $content->structMem('categories')->arrayMem(0)->scalarval();
//try to read out the id of the category
if ($categories != '')
{
$query = 'SELECT c.category_id FROM `#news_category` AS c WHERE c.category_name = \''.$categories.'\'';
$sql->db_Select_gen($query);
$row = $sql->db_Fetch();
$categories = $row['category_id'];
}
}
$published = $xmlrpcmsg->getParam(4)->scalarval();
// TODO use:
// $ix = new news;
// $ret = $ix->submit_item($arrayvalues);
//edit data with new fuctions
$data = array();
//to update we need to set news id...
$data['data']['news_id'] = $postid;
$data['_FIELD_TYPES']['news_id'] = 'int';
$data['data']['news_title'] = $title;
$data['_FIELD_TYPES']['news_title'] = 'todb';
$data['data']['news_body'] = $description;
$data['_FIELD_TYPES']['news_body'] = 'todb';
$data['data']['news_extended'] = $mt_text_more;
$data['_FIELD_TYPES']['news_extended'] = 'todb';
$data['data']['news_datestamp'] = $timestamp;
$data['_FIELD_TYPES']['news_datestamp'] = 'int';
$data['data']['news_author'] = $author;
$data['_FIELD_TYPES']['news_author'] = 'int';
$data['data']['news_category'] = $categories; //category id is taken by a query against news categories
$data['_FIELD_TYPES']['news_category'] = 'int';
$data['data']['news_allow_comments'] = $mt_allow_comments;
$data['_FIELD_TYPES']['news_allow_comments'] = 'int';
$data['data']['news_start'] = ''; //NOT AVAIBLE MAKE A CUSTOM FIELD?
$data['_FIELD_TYPES']['news_start'] = 'int';
$data['data']['news_end'] = ''; //NOT AVAIBLE MAKE A CUSTOM FIELD?
$data['_FIELD_TYPES']['news_end'] = 'int';
//$data['data']['news_class'] = $news['news_class'];
//$data['_FIELD_TYPES']['news_class'] = 'todb';
$data['data']['news_render_type'] = eXMLRPC_NEWS_RENDER_TYPE_LOC; //from preferences
$data['_FIELD_TYPES']['news_render_type'] = 'int';
//news_comment_total
$data['data']['news_summary'] = $mt_excerpt; //NOT AVAIBLE MAKE A CUSTOM FIELD?
$data['_FIELD_TYPES']['news_summary'] = 'todb';
$data['data']['news_thumbnail'] = ''; //NOT APPLICABLE?
$data['_FIELD_TYPES']['news_thumbnail'] = 'todb';
$data['data']['news_sticky'] = ''; //NOT AVAIBLE MAKE A CUSTOM FIELD?
$data['_FIELD_TYPES']['news_sticky'] = 'int';
$data['data']['news_meta_keywords'] = $mt_keywords;
$data['_FIELD_TYPES']['news_meta_keywords'] = 'todb';
$data['data']['news_meta_description'] = ''; //NOT AVAIBLE MAKE A CUSTOM FIELD?
$data['_FIELD_TYPES']['news_meta_description'] = 'todb';
$postid = $sql->db_Update('news', $data);
return new xmlrpcresp( new xmlrpcval(true, 'boolean'));
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** GET POST *********
*************************
*/
$getPost_sig = array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString));
$getPost_doc = 'Get an item on the blog.';
function getPost($xmlrpcmsg)
{
$postid = $xmlrpcmsg->getParam(0)->scalarval();
$username = $xmlrpcmsg->getParam(1)->scalarval();
$password = $xmlrpcmsg->getParam(2)->scalarval();
if (userLogin($username, $password, 'H') == true)
{
$query = 'SELECT n.*, c.category_name FROM `#news` AS n
LEFT JOIN `#news_category` AS c ON c.category_id = n.news_category
WHERE n.news_id=\''.$postid.'\' LIMIT 1';
//link back to the page important!
$link = SITEURL.'news.php?'.$postid;
$sql = e107::getDb();
$sql->db_Select_gen($query);
while ($row = $sql->db_Fetch())
{
return new xmlrpcresp( new xmlrpcval(array(
'postid'=> new xmlrpcval($row['news_id'], 'string'),
'dateCreated'=> new xmlrpcval(iso8601_encode($row['news_datestamp']),'dateTime.iso8601'),
'title'=> new xmlrpcval($row['news_title'], 'string'),
'mt_excerpt'=> new xmlrpcval($row['news_summary'], 'string'),
'mt_keywords'=> new xmlrpcval($row['news_meta_keywords'], 'string'),
'mt_allow_comments'=> new xmlrpcval($row['news_allow_comments'], 'string'),
'description'=> new xmlrpcval(str_replace('[html]', '', str_replace('[/html]', '', $row['news_body'])), 'string'),
'mt_text_more'=> new xmlrpcval(str_replace('[html]', '', str_replace('[/html]', '', $row['news_extended'])), 'string'),
'categories'=> new xmlrpcval(array( new xmlrpcval($row['category_name'], 'string')), 'array'),
'publish'=> new xmlrpcval(1, 'boolean'), //e107 does not have this flag?
'link'=> new xmlrpcval($link, 'string'), 'permaLink'=> new xmlrpcval($link, 'string')), 'struct'));
}
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** DELETE POST *******
*************************
*/
function deletePost($xmlrpcmsg)
{
$postid = $xmlrpcmsg->getParam(1)->scalarval();
$username = $xmlrpcmsg->getParam(2)->scalarval();
$password = $xmlrpcmsg->getParam(3)->scalarval();
if (userLogin($username, $password, 'H') == true)
{
//TODO use: $sql->db_Delete();
$sql = e107::getDb();
//22/10/2009 15.06.16 delete news with new methods
$sql->db_Delete('news', 'news_id='.$postid);
return new xmlrpcresp( new xmlrpcval(true, 'boolean'));
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** GET RECENT POSTS **
*************************
*/
$getRecentPosts_sig = array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcInt));
$getRecentPosts_doc = 'Get the recent posts on the blog.';
function getRecentPosts($xmlrpcmsg)
{
$blogid = $xmlrpcmsg->getParam(0)->scalarval();
$username = $xmlrpcmsg->getParam(1)->scalarval();
$password = $xmlrpcmsg->getParam(2)->scalarval();
if (userLogin($username, $password, 'H') == true)
{
$numposts = $xmlrpcmsg->getParam(3)->scalarval();
$structArray = array();
$query = 'SELECT
n.*,
c.category_name
FROM `#news` AS n
LEFT JOIN `#news_category` AS c ON c.category_id = n.news_category
ORDER BY n.news_datestamp DESC
LIMIT '.$numposts;
$link = SITEURL.'news.php?'.$postid; //link back to the page important!
$sql = e107::getDb();
$sql->db_Select_gen($query);
while ($row = $sql->db_Fetch())
{
$structArray[] = new xmlrpcval(array(
'postid'=> new xmlrpcval($row['news_id'], 'string'),
'dateCreated'=> new xmlrpcval(iso8601_encode($row['news_datestamp']),'dateTime.iso8601'),
'title'=> new xmlrpcval($row['news_title'], 'string'),
'mt_excerpt'=> new xmlrpcval($row['news_summary'], 'string'),
'mt_keywords'=> new xmlrpcval($row['news_meta_keywords'], 'string'),
'mt_allow_comments'=> new xmlrpcval($row['news_allow_comments'], 'string'),
'description'=> new xmlrpcval(str_replace('[html]', '', str_replace('[/html]', '', $row['news_body'])), 'string'),
'mt_text_more'=> new xmlrpcval(str_replace('[html]', '', str_replace('[/html]', '', $row['news_extended'])), 'string'),
'categories'=> new xmlrpcval(array( new xmlrpcval($row['category_name'], 'string')), 'array'),
'publish'=> new xmlrpcval(1, 'boolean'), //e107 does not have this flag?
'link'=> new xmlrpcval($link, 'string'), 'permaLink'=> new xmlrpcval($link, 'string')
), 'struct'
);
}
return new xmlrpcresp( new xmlrpcval($structArray, 'array')); // Return type is struct[] (array of struct)
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** GET CATEGORIES ***
*************************
*/
$getCategories_sig = array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString));
$getCategories_doc = 'Get the categories on the blog.';
function getCategories($xmlrpcmsg)
{
$username = $xmlrpcmsg->getParam(1)->scalarval();
$password = $xmlrpcmsg->getParam(2)->scalarval();
if (userLogin($username, $password, 'H') == 1)
{
$structArray = array();
$query = 'SELECT n.* FROM `#news_category` AS n';
$sql = e107::getDb();
$sql->db_Select_gen($query);
while ($row = $sql->db_Fetch())
{
$structArray[] = new xmlrpcval(array(
'categoryId' => new xmlrpcval($row['category_id'], 'string'),
'parentId' => new xmlrpcval('', 'string'),
'description' => new xmlrpcval($row['category_name'], 'string'),
'categoryDescription' => new xmlrpcval('', 'string'),
'categoryName' => new xmlrpcval($row['category_name'], 'string'),
'htmlUrl' => new xmlrpcval('', 'string'),
'rssUrl' => new xmlrpcval('', 'string')), 'struct');
}
return new xmlrpcresp( new xmlrpcval($structArray, 'array')); // Return type is struct[] (array of struct)
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** NEW MEDIA OBJECT **
*************************
*/
$newMediaObject_sig = array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcStruct)
);
$newMediaObject_doc = 'Upload media files onto the blog server.';
function newMediaObject($xmlrpcmsg)
{
$username = $xmlrpcmsg->getParam(1)->scalarval();
$password = $xmlrpcmsg->getParam(2)->scalarval();
if (userLogin($username, $password, 'H') == true || userLogin($username, $password, '5') == true)
{
$file = $xmlrpcmsg->getParam(3);
$filename = $file->structMem('name')->scalarval();
$filename = substr($filename, (strrpos($filename, '/') + 1));
$type = $file->structMem('type')->scalarval(); // The type of the file
$bits = $file->structMem('bits')->serialize();
$bits = str_replace('<value><base64>', '', $bits);
$bits = str_replace('</base64></value>', '', $bits);
$uploaddir = eXMLRPC_FILES_UPLOAD_PATH; // Make sure this folder has been chmoded to 777.
if (fwrite(fopen($uploaddir.$filename, 'xb'), base64_decode($bits)) == false)
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'File Failed to Write');
}
else
{
return new xmlrpcresp( new xmlrpcval(array('url'=> new xmlrpcval(eXMLRPC_FILES_SITEBASE_URL.$filename, 'string')), 'struct'));
}
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
//21/08/2009 10.07.36
//WORDPRESS APIs
/*
*************************
***** GET PAGE *********
*************************
*/
$getPage_sig = array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString));
$getPage_doc = 'Get a page on the blog.';
function getPage($xmlrpcmsg)
{
$sql = e107::getDb();
$blog_id = $xmlrpcmsg->getParam(0)->scalarval();
$pageid = $xmlrpcmsg->getParam(1)->scalarval();
$username = $xmlrpcmsg->getParam(2)->scalarval();
$password = $xmlrpcmsg->getParam(3)->scalarval();
if (userLogin($username, $password, '5') == true)
{
$query = 'SELECT p.*, u.user_id, u.user_name FROM `#page` AS p LEFT JOIN `#user` AS u ON u.user_id = p.page_author WHERE p.page_id=\''.$pageid.'\' LIMIT 1';
$link = SITEURL.'page.php?'.$pageid; //link back to the page important!
$sql->db_Select_gen($query);
while ($row = $sql->db_Fetch())
{
return new xmlrpcresp( new xmlrpcval(array(
'dateCreated' => new xmlrpcval(iso8601_encode($row['page_datestamp']), 'dateTime.iso8601'),
'userid' => new xmlrpcval($row['user_id'], 'string'),
'page_id' => new xmlrpcval($row['page_id'], 'string'),
'page_status' => new xmlrpcval('', 'string'),
'description' => new xmlrpcval(str_replace('[html]', '', str_replace('[/html]', '', $row['page_text'])), 'string'),
'title' => new xmlrpcval($row['page_title'], 'string'),
'link' => new xmlrpcval($link, 'string'),
'permaLink' => new xmlrpcval($link, 'string'),
'categories' => new xmlrpcval('', 'string'),
'excerpt' => new xmlrpcval('', 'string'),
'text_more' => new xmlrpcval('', 'string'),
'mt_allow_comments' => new xmlrpcval($row['page_comment_flag'], 'boolean'),
'mt_allow_pings' => new xmlrpcval('', 'string'),
'wp_slug' => new xmlrpcval('', 'string'),
'wp_password' => new xmlrpcval($row['page_password'], 'string'),
'wp_author' => new xmlrpcval($row['user_name'], 'string'),
'wp_page_parent_id' => new xmlrpcval('', 'string'),
'wp_page_parent_title' => new xmlrpcval('', 'string'),
'wp_page_order' => new xmlrpcval('', 'string'),
'wp_author_id' => new xmlrpcval($row['user_id'], 'string'),
'wp_author_display_name'=> new xmlrpcval($row['user_name'], 'string'),
'date_created_gmt' => new xmlrpcval('', 'string'),
'custom_fields' => new xmlrpcval('', 'string'),
'wp_page_template' => new xmlrpcval('', 'string')),
'struct')
);
}
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** GET PAGES ********
*************************
*/
$getPages_sig = array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcInt));
$getPages_doc = 'Get pages on the blog.';
function getPages($xmlrpcmsg)
{
$sql = e107::getDb();
$blogid = $xmlrpcmsg->getParam(0)->scalarval();
$username = $xmlrpcmsg->getParam(1)->scalarval();
$password = $xmlrpcmsg->getParam(2)->scalarval();
if (userLogin($username, $password, '5') == true)
{
$numpages = $xmlrpcmsg->getParam(3)->scalarval();
$structArray = array();
$query = 'SELECT
p.*,
u.user_id,
u.user_name
FROM `#page` AS p
LEFT JOIN `#user` AS u ON u.user_id = p.page_author
ORDER BY p.page_datestamp DESC
LIMIT '.$numpages;
//link back to the page important!
$link = SITEURL.'page.php?'.$pageid;
$sql->db_Select_gen($query);
while ($row = $sql->db_Fetch())
{
$structArray[] = new xmlrpcval(array(
'dateCreated'=> new xmlrpcval(iso8601_encode($row['page_datestamp']), 'dateTime.iso8601'),
'userid'=> new xmlrpcval($row['user_id'], 'string'),
'page_id'=> new xmlrpcval($row['page_id'], 'string'),
'page_status'=> new xmlrpcval('', 'string'),
'description'=> new xmlrpcval(str_replace('[html]','', str_replace('[/html]', '', $row['page_text'])),'string'),
'title'=> new xmlrpcval($row['page_title'], 'string'),
'link'=> new xmlrpcval($link, 'string'),
'permaLink'=> new xmlrpcval($link, 'string'),
'categories'=> new xmlrpcval('', 'string'),
'excerpt'=> new xmlrpcval('', 'string'),
'text_more'=> new xmlrpcval('', 'string'),
'mt_allow_comments'=> new xmlrpcval($row['page_comment_flag'], 'boolean'),
'mt_allow_pings'=> new xmlrpcval('', 'string'),
'wp_slug'=> new xmlrpcval('', 'string'),
'wp_password'=> new xmlrpcval($row['page_password'],'string'),
'wp_author'=> new xmlrpcval($row['user_name'], 'string'),
'wp_page_parent_id'=> new xmlrpcval('', 'string'),
'wp_page_parent_title'=> new xmlrpcval('', 'string'),
'wp_page_order'=> new xmlrpcval('', 'string'),
'wp_author_id'=> new xmlrpcval($row['user_id'], 'string'),
'wp_author_display_name'=> new xmlrpcval($row['user_name'], 'string'),
'date_created_gmt'=> new xmlrpcval('', 'string'),
'custom_fields'=> new xmlrpcval('', 'string'),
'wp_page_template'=> new xmlrpcval('', 'string')),
'struct');
}
return new xmlrpcresp( new xmlrpcval($structArray, 'array')); // Return type is struct[] (array of struct)
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** NEW PAGE *********
*************************
*/
$newPage_sig = array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcStruct, $xmlrpcBoolean));
$newPage_doc = 'Post a new item to the blog.';
function newPage($xmlrpcmsg)
{
$sql = e107::getDb();
$blogid = $xmlrpcmsg->getParam(0)->scalarval();
$username = $xmlrpcmsg->getParam(1)->scalarval();
$password = $xmlrpcmsg->getParam(2)->scalarval();
if (userLogin($username, $password, '5') == true)
{
$content = $xmlrpcmsg->getParam(3);
$title = $content->structMem('title')->scalarval();
$description = '[html]'.htmlspecialchars_decode($content->structMem('description')->scalarval()).'[/html]';
//if date is null will be replaced with current datetime (wordpress like)
//check with simplexml for the parameter dateCreated? XMLRPC-PHP seems to not have such functions??
$tempDate = checkXmlElementS($content->serialize(), 'dateCreated');
if ($tempDate == 1)
{
$dateCreated = $content->structMem('dateCreated')->serialize(); // Not all clients send dateCreated info. So add if statement here if you want to use it.
$timestamp = iso8601_decode($dateCreated); // To convert to unix timestamp
}
else
{
$timestamp = time();
}
//21/10/2009 17.17.46 added $wp_password
//add password page
//check if we have something...
$tempPassword = checkXmlElementS($content->serialize(), 'wp_password');
if($tempPassword == 1){
$wp_password = $content->structMem('wp_password')->scalarval();
}
//author from e107
$query = 'SELECT u.user_id FROM `#user` AS u WHERE u.user_loginname = \''.$username.'\' AND u.user_password = \''.md5($password).'\'';
$sql->db_Select_gen($query);
$row = $sql->db_Fetch();
$author = $row['user_id'];
//21/08/2009 14.37.49 allow comments
//add comments flag
//check if we have something...
$tempAllowComments = checkXmlElementS($content->serialize(), 'mt_allow_comments');
if($tempAllowComments == 1){
$comments = $content->structMem('mt_allow_comments')->scalarval();
}
$published = $xmlrpcmsg->getParam(4)->scalarval();
//post data with new fuctions
$data['data']['page_title'] = $title;
$data['_FIELD_TYPES']['page_title'] = 'todb';
$data['data']['page_text'] = $description;
$data['_FIELD_TYPES']['page_text'] = 'todb';
$data['data']['page_datestamp'] = $timestamp;
$data['_FIELD_TYPES']['page_datestamp'] = 'int';
$data['data']['page_author'] = $author;
$data['_FIELD_TYPES']['page_author'] = 'int';
$data['data']['page_comment_flag'] = $comments;
$data['_FIELD_TYPES']['page_comment_flag'] = 'int';
$data['data']['page_password'] = $wp_password;
$data['_FIELD_TYPES']['page_password'] = 'todb';
$data['data']['page_class'] = 0;
$data['_FIELD_TYPES']['page_class'] = 'int';
$postid = $sql->db_Insert('page', $data);
return new xmlrpcresp( new xmlrpcval($postid, 'string')
); // Return the id of the post just inserted into the DB. See mysql_insert_id() in the PHP manual.
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** DELETE PAGE *******
*************************
*/
$deletePage_sig = array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString)
);
$deletePage_doc = "Delete a page from blog";
function deletePage($xmlrpcmsg)
{
$sql = e107::getDb();
$blogid = $xmlrpcmsg->getParam(0)->scalarval();
$username = $xmlrpcmsg->getParam(1)->scalarval();
$password = $xmlrpcmsg->getParam(2)->scalarval();
$pageid = $xmlrpcmsg->getParam(3)->scalarval();
if (userLogin($username, $password, 'H') == true)
{
//TODO Use db_Delete();
//23/10/2009 16.15.15 delete page with new methods
$sql->db_Delete('page', 'page_id='.$pageid);
return new xmlrpcresp( new xmlrpcval(true, 'boolean'));
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** EDIT PAGE *********
*************************
*/
$editPage_sig = array
(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcStruct, $xmlrpcBoolean));
$editPage_doc = 'Edit a page on the blog.';
function editPage($xmlrpcmsg)
{
$sql = e107::getDb();
$blogid = $xmlrpcmsg->getParam(0)->scalarval();
$pageid = $xmlrpcmsg->getParam(1)->scalarval();
$username = $xmlrpcmsg->getParam(2)->scalarval();
$password = $xmlrpcmsg->getParam(3)->scalarval();
if (userLogin($username, $password, 'H') == true)
{
$content = $xmlrpcmsg->getParam(4);
$title = $content->structMem('title')->scalarval();
$description = '[html]'.$content->structMem('description')->scalarval().'[/html]';
//if date is null will be replaced with current datetime (wordpress like)
//check with simplexml for the parameter dateCreated? XMLRPC-PHP seems to not have such functions??
$tempDate = checkXmlElementS($content->serialize(), 'dateCreated');
if ($tempDate == 1)
{
$dateCreated = $content->structMem('dateCreated')->serialize(); // Not all clients send dateCreated info. So add if statement here if you want to use it.
$timestamp = iso8601_decode($dateCreated); // To convert to unix timestamp
}
else
{
$timestamp = time();
}
//author from e107
$query = 'SELECT u.user_id FROM `#user` AS u WHERE u.user_loginname = \''.$username.'\' AND u.user_password = \''.md5($password).'\'';
$sql->db_Select_gen($query);
$row = $sql->db_Fetch();
$author = $row['user_id'];
//21/08/2009 14.37.49 allow comments
//add comments flag
//check if we have something...
$tempAllowComments = checkXmlElementS($content->serialize(), 'mt_allow_comments');
if($tempAllowComments == 1){
$comments = $content->structMem('mt_allow_comments')->scalarval();
}
$published = $xmlrpcmsg->getParam(5)->scalarval();
//edit data with new fuctions
$data['data']['page_id'] = $pageid;
$data['_FIELD_TYPES']['page_id'] = 'int';
$data['data']['page_title'] = $title;
$data['_FIELD_TYPES']['page_title'] = 'todb';
$data['data']['page_text'] = $description;
$data['_FIELD_TYPES']['page_text'] = 'todb';
$data['data']['page_datestamp'] = $timestamp;
$data['_FIELD_TYPES']['page_datestamp'] = 'int';
$data['data']['page_author'] = $author;
$data['_FIELD_TYPES']['page_author'] = 'int';
$data['data']['page_comment_flag'] = $comments;
$data['_FIELD_TYPES']['page_comment_flag'] = 'int';
$data['data']['page_password'] = $wp_password;
$data['_FIELD_TYPES']['page_password'] = 'todb';
$data['data']['page_class'] = 0;
$data['_FIELD_TYPES']['page_class'] = 'int';
$pageid = $sql->db_Update('page', $data);
return new xmlrpcresp( new xmlrpcval(true, 'boolean'));
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** GET PAGE LIST *****
*************************
*/
//21/08/2009 15.45.15 uhm... DON'T SURE ABOUT THIS :D
$getPageList_sig = array(array($xmlrpcArray, $xmlrpcString
, $xmlrpcString, $xmlrpcString));
$getPageList_doc = 'Get pages list on the blog.';
function getPageList($xmlrpcmsg)
{
$sql = e107::getDb();
$blogid = $xmlrpcmsg->getParam(0)->scalarval();
$username = $xmlrpcmsg->getParam(1)->scalarval();
$password = $xmlrpcmsg->getParam(2)->scalarval();
if (userLogin($username, $password, '5') == true)
{
$structArray = array();
$query = 'SELECT
p.*,
u.user_id,
u.user_name
FROM `#page` AS p
LEFT JOIN `#user` AS u ON u.user_id = p.page_author
ORDER BY p.page_datestamp DESC
LIMIT '.$numpages;
$sql->db_Select_gen($query);
while ($row = $sql->db_Fetch())
{
$structArray[] = new xmlrpcval(array(
'page_id'=> new xmlrpcval($row['page_id'], 'string'),
'page_title'=> new xmlrpcval($row['page_title'], 'string'),
'page_parent_title'=> new xmlrpcval('', 'string'),
'date_created_gmt'=> new xmlrpcval('', 'string'),
'dateCreated'=> new xmlrpcval(iso8601_encode($row['page_datestamp']),
'dateTime.iso8601')),
'struct');
}
return new xmlrpcresp( new xmlrpcval($structArray, 'array')); // Return type is struct[] (array of struct)
}
else
{
return new xmlrpcresp(0, $xmlrpcerruser + 1, 'Login Failed');
}
}
/*
*************************
***** NEW CATEGORY ******
*************************
*/
$newCategory_sig = array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcStruct));
$newCategory_doc = 'Create a new category on the blog.';
function newCategory($xmlrpcmsg)
{
$sql = e107::getDb();
$blogid = $xmlrpcmsg->getParam(0)->scalarval();
$username = $xmlrpcmsg->getParam(1)->scalarval();
$password = $xmlrpcmsg->getParam(2)->scalarval();
if (userLogin($username, $password, 'H') == true || userLogin($username, $password, '5') == true)
{
$content = $xmlrpcmsg->getParam(3);
$name = $content->structMem('name')->scalarval();
//21/08/2009 16.20.02 unused at this stage