/
xmlrpc.php
411 lines (315 loc) · 12.1 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
<?php
// (c) Copyright 2002-2012 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id: xmlrpc.php 39982 2012-02-28 20:49:45Z pkdille $
include_once('tiki-setup.php');
require_once('XML/Server.php');
include_once('lib/blogs/bloglib.php');
if ($prefs['feature_xmlrpc'] != 'y') {
die;
}
$map = array (
'blogger.newPost' => array( 'function' => 'newPost'),
'blogger.getUserInfo' => array( 'function' => 'getUserInfo'),
'blogger.getPost' => array( 'function' => 'getPost'),
'blogger.editPost' => array( 'function' => 'editPost'),
'blogger.deletePost' => array( 'function' => 'deletePost'),
'blogger.getRecentPosts' => array( 'function' => 'getRecentPosts'),
'blogger.getUserInfo' => array( 'function' => 'getUserInfo'),
'blogger.getUsersBlogs' => array( 'function' => 'getUserBlogs')
);
$s = new XML_RPC_Server($map);
function check_individual($user,$blogid,$permName)
{
global $userlib;
// If the user is admin he can do everything
if ($userlib->user_has_permission($user, 'tiki_p_blog_admin')) return true;
// If no individual permissions for the object then ok
if (!$userlib->object_has_one_permission($blogid, 'blog')) return true;
// If the object has individual permissions then check
// Now get all the permissions that are set for this type of permissions 'image gallery'
if ($userlib->object_has_permission($user, $blogid, 'blog', $permName)) {
return true;
} else {
return false;
}
}
/* Validates the user and returns user information */
function getUserInfo($params)
{
global $tikilib, $userlib;
$appkeyp = $params->getParam(0);
$appkey = $appkeyp->scalarval();
$usernamep = $params->getParam(1);
$username = $usernamep->scalarval();
$passwordp = $params->getParam(2);
$password = $passwordp->scalarval();
list($ok, $username, $e) = $userlib->validate_user($username, $password, '', '');
if ($ok) {
$myStruct = new XML_RPC_Value(
array(
'nickname' => new XML_RPC_Value($username),
'firstname' => new XML_RPC_Value('none'),
'lastname' => new XML_RPC_Value('none'),
'email' => new XML_RPC_Value('none'),
'userid' => new XML_RPC_Value('$username'),
'url' => new XML_RPC_Value('none')
),
'struct'
);
return new XML_RPC_Response($myStruct);
} else {
return new XML_RPC_Response(0, 101, 'Invalid username or password');
}
}
/* Posts a new submission to the CMS */
function newPost($params)
{
global $tikilib, $userlib, $bloglib;
$appkeyp = $params->getParam(0);
$appkey = $appkeyp->scalarval();
$blogidp = $params->getParam(1);
$blogid = $blogidp->scalarval();
$usernamep = $params->getParam(2);
$username = $usernamep->scalarval();
$passwordp = $params->getParam(3);
$password = $passwordp->scalarval();
$passp = $params->getParam(4);
$content = $passp->scalarval();
$passp = $params->getParam(5);
$publish = $passp->scalarval();
// Fix for w.bloggar
preg_match('/<title>(.*)</title>/', $content, $title);
$title = $title[1];
$content = preg_replace('#<title>(.*)</title>#', '', $content);
// Now check if the user is valid and if the user can post a submission
list($ok, $username, $e) = $userlib->validate_user($username, $password, '', '');
if (!$ok) {
return new XML_RPC_Response(0, 101, 'Invalid username or password');
}
// Get individual permissions for this weblog if they exist
if (!check_individual($username, $blogid, 'tiki_p_blog_post') ) {
return new XML_RPC_Response(0, 101, 'User is not allowed to post to this weblog due to individual restrictions for this weblog');
}
// If the blog is not public then check if the user is the owner
if (!$userlib->user_has_permission($username, 'tiki_p_blog_admin')) {
if (!$userlib->user_has_permission($username, 'tiki_p_blog_post')) {
return new XML_RPC_Response(0, 101, 'User is not allowed to post');
}
global $bloglib; require_once('lib/blogs/bloglib.php');
$blog_info = $bloglib->get_blog($blogid);
if ($blog_info['public']!='y') {
if ($username != $blog_info['user']) {
return new XML_RPC_Response(0, 101, 'User is not allowed to post');
}
}
}
// User ok and can submit then submit the post
$id = $bloglib->blog_post($blogid, $content, '', $username, $title);
return new XML_RPC_Response(new XML_RPC_Value("$id"));
}
// :TODO: editPost
function editPost($params)
{
global $tikilib, $userlib, $bloglib;
$appkeyp = $params->getParam(0);
$appkey = $appkeyp->scalarval();
$blogidp = $params->getParam(1);
$postid = $blogidp->scalarval();
$usernamep = $params->getParam(2);
$username = $usernamep->scalarval();
$passwordp = $params->getParam(3);
$password = $passwordp->scalarval();
$passp = $params->getParam(4);
$content = $passp->scalarval();
$passp = $params->getParam(5);
$publish = $passp->scalarval();
// Fix for w.bloggar
preg_match('/<title>(.*)</title>/', $content, $title);
$title = $title[1];
$content = preg_replace('#<title>(.*)</title>#', '', $content);
// Now check if the user is valid and if the user can post a submission
list($ok, $username, $e) = $userlib->validate_user($username, $password, '', '');
if (!$ok) {
return new XML_RPC_Response(0, 101, 'Invalid username or password');
}
if (!check_individual($username, $blogid, 'tiki_p_blog_post') ) {
return new XML_RPC_Response(0, 101, 'User is not allowed to post to this weblog due to individual restrictions for this weblog therefor the user cannot edit a post');
}
if (!$userlib->user_has_permission($username, 'tiki_p_blog_post')) {
return new XML_RPC_Response(0, 101, 'User is not allowed to post');
}
// Now get the post information
$post_data = $bloglib->get_post($postid);
if (!$post_data) {
return new XML_RPC_Response(0, 101, 'Post not found');
}
if ($post_data['user']!=$username) {
if (!$userlib->user_has_permission($username, 'tiki_p_blog_admin')) {
return new XML_RPC_Response(0, 101, 'Permission denied to edit that post since the post does not belong to the user');
}
}
$id = $bloglib->update_post($postid, $blogid, $content, $username, $title);
return new XML_RPC_Response(new XML_RPC_Value(1, 'boolean'));
}
// :TODO: deletePost
function deletePost($params)
{
global $tikilib, $userlib, $bloglib;
$appkeyp = $params->getParam(0);
$appkey = $appkeyp->scalarval();
$blogidp = $params->getParam(1);
$postid = $blogidp->scalarval();
$usernamep = $params->getParam(2);
$username = $usernamep->scalarval();
$passwordp = $params->getParam(3);
$password = $passwordp->scalarval();
$passp = $params->getParam(4);
$publish = $passp->scalarval();
// Now check if the user is valid and if the user can post a submission
list($ok, $username, $e) = $userlib->validate_user($username, $password, '', '');
if (!$ok) {
return new XML_RPC_Response(0, 101, 'Invalid username or password');
}
// Now get the post information
$post_data = $bloglib->get_post($postid);
if (!$post_data) {
return new XML_RPC_Response(0, 101, 'Post not found');
}
if ($post_data['user']!=$username) {
if (!$userlib->user_has_permission($username, 'tiki_p_blog_admin')) {
return new XML_RPC_Response(0, 101, 'Permission denied to edit that post');
}
}
$id = $bloglib->remove_post($postid);
return new XML_RPC_Response(new XML_RPC_Value(1, 'boolean'));
}
// :TODO: getTemplate
// :TODO: setTemplate
// :TODO: getPost
function getPost($params)
{
global $tikilib, $userlib, $bloglib;
$appkeyp = $params->getParam(0);
$appkey = $appkeyp->scalarval();
$blogidp = $params->getParam(1);
$postid = $blogidp->scalarval();
$usernamep = $params->getParam(2);
$username = $usernamep->scalarval();
$passwordp = $params->getParam(3);
$password = $passwordp->scalarval();
// Now check if the user is valid and if the user can post a submission
list($ok, $username, $e) = $userlib->validate_user($username, $password, '', '');
if (!$ok) {
return new XML_RPC_Response(0, 101, 'Invalid username or password');
}
if (!check_individual($username, $blogid, 'tiki_p_blog_post') ) {
return new XML_RPC_Response(0, 101, 'User is not allowed to post to this weblog due to individual restrictions for this weblog');
}
if (!$userlib->user_has_permission($username, 'tiki_p_blog_post')) {
return new XML_RPC_Response(0, 101, 'User is not allowed to post');
}
if (!$userlib->user_has_permission($username, 'tiki_p_read_blog')) {
return new XML_RPC_Response(0, 101, 'Permission denied to read this blog');
}
// Now get the post information
$post_data = $bloglib->get_post($postid);
if (!$post_data) {
return new XML_RPC_Response(0, 101, 'Post not found');
}
$dateCreated=$tikilib->get_iso8601_datetime($post_data['created']);
// added dateTime type for blogger compliant xml tag Joerg Knobloch <joerg@happypenguins.net>
$myStruct=new XML_RPC_Value(
array(
'userid' => new XML_RPC_Value($username),
'dateCreated' => new XML_RPC_Value($dateCreated, 'dateTime.iso8601'),
// Fix for w.Bloggar
'content' => new XML_RPC_Value('<title>' . $post_data['title'] . '</title>' . $post_data['data']),
'postid' => new XML_RPC_Value($post_data['postId'])
),
'struct'
);
// User ok and can submit then submit an article
return new XML_RPC_Response($myStruct);
}
// :TODO: getRecentPosts
function getRecentPosts($params)
{
global $tikilib, $userlib, $bloglib;
$appkeyp = $params->getParam(0);
$appkey = $appkeyp->scalarval();
$blogidp = $params->getParam(1);
$blogid = $blogidp->scalarval();
$usernamep = $params->getParam(2);
$username = $usernamep->scalarval();
$passwordp = $params->getParam(3);
$password = $passwordp->scalarval();
$passp = $params->getParam(4);
$number = $passp->scalarval();
// Now check if the user is valid and if the user can post a submission
list($ok, $username, $e) = $userlib->validate_user($username, $password, '', '');
if (!$ok) {
return new XML_RPC_Response(0, 101, 'Invalid username or password');
}
if (!check_individual($username, $blogid, 'tiki_p_blog_post') ) {
return new XML_RPC_Response(0, 101, 'User is not allowed to post to this weblog due to individual restrictions for this weblog therefore the user cannot edit a post');
}
if (!$userlib->user_has_permission($username, 'tiki_p_blog_post')) {
return new XML_RPC_Response(0, 101, 'User is not allowed to post');
}
// Now get the post information
$posts = $bloglib->list_blog_posts($blogid, false, 0, $number, 'created_desc', '', '');
if (count($posts)==0) {
return new XML_RPC_Response(0, 101, 'No posts');
}
$arrayval = Array();
foreach ($posts['data'] as $post) {
$dateCreated = $tikilib->get_iso8601_datetime($post['created']);
$myStruct = new XML_RPC_Value(
array(
'userid' => new XML_RPC_Value($username),
'dateCreated' => new XML_RPC_Value($dateCreated, 'dateTime.iso8601'),
// Fix for w.Bloggar
'content' => new XML_RPC_Value('<title>' . $post['title'] . '</title>' . $post['data']),
'postid' => new XML_RPC_Value($post['postId'])
),
'struct'
);
$arrayval[] = $myStruct;
}
// User ok and can submit then submit an article
$myVal = new XML_RPC_Value($arrayval, 'array');
return new XML_RPC_Response($myVal);
}
// :TODO: tiki.tikiPost
/* Get the topics where the user can post a new */
function getUserBlogs($params)
{
global $tikilib, $userlib, $bloglib;
$appkeyp = $params->getParam(0);
$appkey=$appkeyp->scalarval();
$usernamep = $params->getParam(1);
$username = $usernamep->scalarval();
$passwordp = $params->getParam(2);
$password = $passwordp->scalarval();
$arrayVal = Array();
require_once('lib/blogs/bloglib.php');
$blogs = $bloglib->list_user_blogs($username, true);
$foo = parse_url($_SERVER['REQUEST_URI']);
$foo1 = $tikilib->httpPrefix() . str_replace('xmlrpc', 'tiki-view_blog', $foo['path']);
foreach ($blogs as $blog) {
$myStruct = new XML_RPC_Value(
array(
'blogName' => new XML_RPC_Value($blog['title']),
'url' => new XML_RPC_Value($foo1 . '?blogId=' . $blog['blogId']),
'blogid' => new XML_RPC_Value($blog['blogId'])
),
'struct'
);
$arrayVal[] = $myStruct;
}
$myVal = new XML_RPC_Value($arrayVal, 'array');
return new XML_RPC_Response($myVal);
}