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
|
<?php /* * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) * Copyright (C) 2002-2005 The Nucleus Group * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * (see nucleus/documentation/index.html#license for more info) */
/** * This script is provides an XML-RPC [1] interface to Nucleus [2]. * * At this time, the Blogger API [3], the metaWeblog API [4] and * parts of the Movable Type API [5] are implemented * * This script uses the the 'XML-RPC for PHP v1.02' implementation [6] * All other code was written by Wouter Demuynck [7] * * [1] http://www.xmlrpc.com/ * [2] http://nucleuscms.org/ * [3] http://plant.blogger.com/api/ * [4] http://www.xmlrpc.com/metaWeblogApi * [5] http://www.movabletype.org/docs/mtmanual_programmatic.html * [6] http://phpxmlrpc.sourceforge.net/ * [7] http://demuynck.org/ * * * The Blogger API: (more info in the documentation) * * blogger.newPost * blogger.editPost * blogger.getUsersBlogs * blogger.deletePost * blogger.getRecentPosts * blogger.getPost * blogger.getUserInfo * blogger.getTemplate * blogger.setTemplate * * Note: The getUserInfo response contains an empty 'lastname' and the full name as * 'firstname' * Note: Blogger API methods only affect the body field of items * * The metaWeblog API (more info in documentation) * * metaWeblog.newPost * metaWeblog.getPost * metaWeblog.editPost * metaWeblog.getCategories * metaWeblog.newMediaObject * metaWeblog.getRecentPosts * * Note: metaWeblog API methods only affect the body and title fields of items. * the extended part is left untouched (and empty for new posts) * * The Movable Type API * * mt.supportedMethods * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2005 The Nucleus Group * @version $Id: server.php,v 1.8.2.2 2005/08/21 07:43:01 dekarma Exp $ */ $CONF = array(); include("../../config.php"); // include Nucleus libs and code include($DIR_LIBS . "xmlrpc.inc.php"); include($DIR_LIBS . "xmlrpcs.inc.php");
/* define xmlrpc settings */ $xmlrpc_internalencoding = _CHARSET; $xmlrpc_defencoding = 'UTF-8';
/* definition of available methods */
$functionDefs = array();
// load server functions include('api_blogger.inc.php'); include('api_metaweblog.inc.php'); // include('api_nucleus.inc.php'); // uncomment if you still want to use the nucleus.* methods include('api_mt.inc.php');
// create server $s = new xmlrpc_server( $functionDefs );
/* ------------------------------ private functions ---------------------------------- */
/** * Adds an item to the given blog. Username and password are required to login */ function _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $catname = "") { $blog = new BLOG($blogid); $timestamp = $blog->getCorrectTime(); return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 0, $catname); }
/** * Adds item to blog, with time of item given */ function _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, $future, $catname = "") { // 1. login $mem = new MEMBER();
if (!$mem->login($username, $password)) return _error(1,"Could not log in");
// 2. check if allowed to add to blog if (!BLOG::existsID($blogid)) return _error(2,"No such blog ($blogid)"); if (!$mem->teamRights($blogid)) return _error(3,"Not a team member"); if (!trim($body)) return _error(4,"Cannot add empty items!");
// 3. calculate missing vars $blog = new BLOG($blogid);
// get category id (or id for default category when false category) $catid = $blog->getCategoryIdFromName($catname);
if ($publish == 1) $draft = 0; else $draft = 1; if ($closed != 1) $closed = 0;
// 4. add to blog $itemid = $blog->additem($catid, $title, $body, $more, $blogid, $mem->getID(), $timestamp, $closed, $draft);
// [TODO] ping weblogs.com ?
return new xmlrpcresp(new xmlrpcval($itemid,"string")); }
/** * Updates an item. Username and password are required to login */ function _edititem($itemid, $username, $password, $catid, $title, $body, $more, $wasdraft, $publish, $closed) { global $manager;
// 1. login $mem = new MEMBER(); if (!$mem->login($username, $password)) return _error(1,"Could not log in");
// 2. check if allowed to add to blog if (!$manager->existsItem($itemid,1,1)) return _error(6,"No such item ($itemid)"); if (!$mem->canAlterItem($itemid)) return _error(7,"Not allowed to alter item");
// 3. update item ITEM::update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, 0);
return new xmlrpcresp(new xmlrpcval(1,"boolean")); }
/** * Gives the list of blogs to which the user with given name and password has access */ function _getUsersBlogs($username, $password) { // 1. Try to login $mem = new MEMBER(); if (!$mem->login($username, $password)) return _error(1,"Could not log in");
// 2. Get list of blogs
$structarray = array(); $query = "SELECT bnumber, bname, burl" . ' FROM '.sql_table('blog').', '.sql_table('team') . " WHERE tblog=bnumber and tmember=" . $mem->getID() . " ORDER BY bname"; $r = sql_query($query);
while ($obj = mysql_fetch_object($r)) { if ($obj->burl) $blogurl = $obj->burl; else $blogurl = 'http://';
$newstruct = new xmlrpcval(array( "url" => new xmlrpcval($blogurl,"string"), "blogid" => new xmlrpcval($obj->bnumber,"string"), "blogName" => new xmlrpcval($obj->bname,"string") ),'struct'); array_push($structarray, $newstruct); }
return new xmlrpcresp(new xmlrpcval( $structarray , "array")); }
function _getUserInfo($username, $password) { // 1. login $mem = new MEMBER(); if (!$mem->login($username, $password)) return _error(1,"Could not log in");
// 3. return the info // Structure returned has nickname, userid, url, email, lastname, firstname
$newstruct = new xmlrpcval(array( "nickname" => new xmlrpcval($mem->getDisplayName(),"string"), "userid" => new xmlrpcval($mem->getID(),"string"), "url" => new xmlrpcval($mem->getURL(),"string"), "email" => new xmlrpcval($mem->getEmail(),"string"), "lastname" => new xmlrpcval("","string"), "firstname" => new xmlrpcval($mem->getRealName(),"string") ),'struct');
return new xmlrpcresp($newstruct);
}
/** * deletes an item */ function _deleteItem($itemid, $username, $password) { global $manager;
// 1. login $mem = new MEMBER(); if (!$mem->login($username, $password)) return _error(1,"Could not log in");
// 2. check if allowed if (!$manager->existsItem($itemid,1,1)) return _error(6,"No such item ($itemid)"); $blogid = getBlogIDFromItemID($itemid); if (!$mem->teamRights($blogid)) return _error(3,"Not a team member");
// delete the item ITEM::delete($itemid);
return new xmlrpcresp(new xmlrpcval(1,"boolean")); }
/** * Returns a template */ function _getSkinPart($blogid, $username, $password, $type) { // 1. login $mem = new MEMBER(); if (!$mem->login($username, $password)) return _error(1,"Could not log in");
// 2. check if allowed if (!BLOG::existsID($blogid)) return _error(2,"No such blog ($blogid)"); if (!$mem->teamRights($blogid)) return _error(3,"Not a team member");
// 3. return skin part $blog = new BLOG($blogid); $skin = new SKIN($blog->getDefaultSkin()); return new xmlrpcresp(new xmlrpcval($skin->getContent($type),"string"));
}
function _setSkinPart($blogid, $username, $password, $content, $type) { // 1. login $mem = new MEMBER(); if (!$mem->login($username, $password)) return _error(1,"Could not log in");
// 2. check if allowed if (!BLOG::existsID($blogid)) return _error(2,"No such blog ($blogid)"); if (!$mem->teamRights($blogid)) return _error(3,"Not a team member");
// 3. update skin part $blog = new BLOG($blogid); $skin = new SKIN($blog->getDefaultSkin()); $skin->update($type, $content);
return new xmlrpcresp(new xmlrpcval(1,'boolean')); }
/** * Some convenience methods */
function _getScalar($m, $idx) { $v = $m->getParam($idx); return $v->scalarval(); }
function _getStructVal($struct, $key) { $t = $struct->structmem($key); if (!$t) return ''; // no such struct value else return $t->scalarval(); }
function _getArrayVal($a, $idx) { $t = $a->arraymem($idx); return $t->scalarval(); }
/** * Returns an XML-RPC error response * $err is the error number (>0, will be added to $xmlrpcerruser) */ function _error($err, $msg) { global $xmlrpcerruser; return new xmlrpcresp(0, $xmlrpcerruser + $err, $msg); } ?>
|