/
api_nucleus.inc.php
executable file
·339 lines (280 loc) · 10.2 KB
/
api_nucleus.inc.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
<?php
/*
* Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
* Copyright (C) 2002-2013 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 file contains definitions for the functions in the Nucleus API
*
* NOTE: These functions are deprecated and will most likely be removed!
*/
// prevent direct access
if (!isset($member))
exit;
// nucleus.addItem
$f_nucleus_addItem_sig = array(array(
// return type
$xmlrpcString, // itemid of the new item
// params:
$xmlrpcString, // blogid
$xmlrpcString, // username
$xmlrpcString, // password
$xmlrpcString, // title
$xmlrpcString, // body
$xmlrpcString, // extended part
$xmlrpcBoolean, // publish boolean (set to false to create draft)
$xmlrpcBoolean, // closed boolean (set to true to disable comments)
));
$f_nucleus_addItem_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false";
function f_nucleus_addItem($m) {
$blogid = _getScalar($m,0);
$username = _getScalar($m,1);
$password = _getScalar($m,2);
$title = _getScalar($m,3);
$body = _getScalar($m,4);
$more = _getScalar($m,5);
$publish = _getScalar($m,6);
$closed = _getScalar($m,7);
return _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed);
}
// nucleus.addDatedItem (the time of the item can be given here, for offline blogging)
$f_nucleus_addDatedItem_sig = array(array(
// return type
$xmlrpcString, // itemid of the new item
// params:
$xmlrpcString, // blogid
$xmlrpcString, // username
$xmlrpcString, // password
$xmlrpcString, // title
$xmlrpcString, // body
$xmlrpcString, // extended part
$xmlrpcBoolean, // publish boolean (set to false to create draft)
$xmlrpcBoolean, // closed boolean (set to true to disable comments)
$xmlrpcInt // item time (unix timestamp)
));
$f_nucleus_addDatedItem_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false. The timestamp of the item needs to be given as a Unix timestamp";
function f_nucleus_addDatedItem($m) {
$blogid = _getScalar($m,0);
$username = _getScalar($m,1);
$password = _getScalar($m,2);
$title = _getScalar($m,3);
$body = _getScalar($m,4);
$more = _getScalar($m,5);
$publish = _getScalar($m,6);
$closed = _getScalar($m,7);
$timestamp = _getScalar($m,8);
// use '1' as $future param to make sure the date does not get erased
return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 1);
}
// nucleus.editItem
$f_nucleus_editItem_sig = array(array(
// return type
$xmlrpcBoolean, // true or false
// params:
$xmlrpcString, // itemid
$xmlrpcString, // username
$xmlrpcString, // password
$xmlrpcString, // title
$xmlrpcString, // body
$xmlrpcString, // extended part
$xmlrpcBoolean, // publish boolean (set to false if you want a draft to stay draft)
$xmlrpcBoolean, // closed boolean (set to true to disable comments)
));
$f_nucleus_editItem_doc = "Edits an item of a blog";
function f_nucleus_editItem($m) {
global $manager;
$itemid = intval(_getScalar($m,0));
$username = _getScalar($m,1);
$password = _getScalar($m,2);
$title = _getScalar($m,3);
$content = _getScalar($m,4);
$more = _getScalar($m,5);
$publish = _getScalar($m,6);
$closed = _getScalar($m,7);
// get old title and extended part
if (!$manager->existsItem($itemid,1,1))
return _error(6,"No such item ($itemid)");
$old =& $manager->getItem($itemid,1,1);
$wasdraft = ($old['draft']) ? 1 : 0;
return _edititem($itemid, $username, $password, $old['catid'], $title, $content, $more, $wasdraft, $publish, $closed);
}
// nucleus.getUsersBlogs
$f_nucleus_getUsersBlogs_sig = array(array(
// return type
$xmlrpcArray, // array containing structs containing blog info
// params:
$xmlrpcString, // username
$xmlrpcString, // password
));
$f_nucleus_getUsersBlogs_doc = "Returns a list of all the blogs where the given member is on the team";
function f_nucleus_getUsersBlogs($m) {
$username = _getScalar($m,0);
$password = _getScalar($m,1);
return _getUsersBlogs($username, $password);
}
// nucleus.getRecentItems
$f_nucleus_getRecentItems_sig = array(array(
// return type
$xmlrpcArray, // array of strucs (representing items)
// params
$xmlrpcString, // blogid
$xmlrpcString, // username
$xmlrpcString, // password
$xmlrpcInt, // amount of items to return (max = 20)
));
$f_nucleus_getRecentItems_doc = "Returns a maximum of 20 recent items for a given webblog";
function f_nucleus_getRecentItems($m) {
$blogid = _getScalar($m, 0);
$username = _getScalar($m, 1);
$password = _getScalar($m, 2);
$amount = _getScalar($m, 3);
return _getRecentItems($blogid, $username, $password, $amount);
}
// nucleus.getItem
$f_nucleus_getItem_sig = array(array(
// return type
$xmlrpcStruct, // A struct representing the item
// params
$xmlrpcString, // itemid
$xmlrpcString, // username
$xmlrpcString, // password
));
$f_nucleus_getItem_doc = "Returns an item";
function f_nucleus_getItem($m) {
$postid = _getScalar($m, 0);
$username = _getScalar($m, 1);
$password = _getScalar($m, 2);
return _getItem($postid, $username, $password);
}
// nucleus.deleteItem
$f_nucleus_deleteItem_sig = array(array(
// return type
$xmlrpcBoolean, // boolean (ok or not ok)
// params
$xmlrpcString, // itemid
$xmlrpcString, // username
$xmlrpcString, // password
));
$f_nucleus_deleteItem_doc = "Deletes an item";
function f_nucleus_deleteItem($m) {
$itemid = _getScalar($m,0);
$username = _getScalar($m, 1);
$password = _getScalar($m, 2);
return _deleteItem($itemid, $username, $password);
}
/**
* Returns a list of recent items (Nucleus Version)
* ($amount = max 20);
*/
function _getRecentItems($blogid, $username, $password, $amount) {
$blogid = intval($blogid);
$amount = intval($amount);
// 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");
$amount = intval($amount);
if (($amount < 1) or ($amount > 20))
return _error(5,"Amount parameter must be in range 1..20");
// 3. create and return list of recent items
// Struct returned has dateCreated, userid, blogid and content
$structarray = array(); // the array in which the structs will be stored
$query = "SELECT ibody, iauthor, ibody, imore, ititle, iclosed, idraft, itime"
.' FROM '.sql_table('item')
." WHERE iblog=$blogid"
." ORDER BY itime DESC"
." LIMIT $amount";
$r = sql_query($query);
while ($obj = sql_fetch_object($r)) {
$newstruct = new xmlrpcval(array(
"publishDate" => new xmlrpcval(iso8601_encode(strtotime($obj->itime)),"dateTime.iso8601"),
"userid" => new xmlrpcval($obj->iauthor,"string"),
"blogid" => new xmlrpcval($blogid,"string"),
"title" => new xmlrpcval($obj->ititle,"string"),
"body" => new xmlrpcval($obj->ibody,"string"),
"more" => new xmlrpcval($obj->imore,"string"),
"draft" => new xmlrpcval($obj->idraft,"boolean"),
"closed" => new xmlrpcval($obj->iclosed,"boolean"),
),'struct');
array_push($structarray, $newstruct);
}
return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
}
/**
* Returns one item (Nucleus version)
*/
function _getItem($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");
// 3. return the item
// Structure returned has dateCreated, userid, blogid and content
$item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
$blog = new BLOG($blogid);
if ($blog->convertBreaks())
$item['body'] = removeBreaks($item['body']);
$newstruct = new xmlrpcval(array(
"publishDate" => new xmlrpcval(iso8601_encode($item['timestamp']),"dateTime.iso8601"),
"userid" => new xmlrpcval($item['authorid'],"string"),
"blogid" => new xmlrpcval($blogid,"string"),
"title" => new xmlrpcval($item['title'],"string"),
"body" => new xmlrpcval($item['body'],"string"),
"more" => new xmlrpcval($item['more'],"string"),
"draft" => new xmlrpcval($item['draft'],"boolean"),
"closed" => new xmlrpcval($item['closed'],"boolean"),
),'struct');
return new xmlrpcresp($newstruct);
}
if (!isset($functionDefs))
$functionDefs = array();
$functionDefs = array_merge($functionDefs,
array(
"nucleus.addItem" =>
array( "function" => "f_nucleus_addItem",
"signature" => $f_nucleus_addItem_sig,
"docstring" => $f_nucleus_addItem_doc),
"nucleus.editItem" =>
array( "function" => "f_nucleus_editItem",
"signature" => $f_nucleus_editItem_sig,
"docstring" => $f_nucleus_editItem_doc),
"nucleus.addDatedItem" =>
array( "function" => "f_nucleus_addDatedItem",
"signature" => $f_nucleus_addDatedItem_sig,
"docstring" => $f_nucleus_addDatedItem_doc),
"nucleus.deleteItem" =>
array( "function" => "f_nucleus_deleteItem",
"signature" => $f_nucleus_deleteItem_sig,
"docstring" => $f_nucleus_deleteItem_doc),
"nucleus.getUsersBlogs" =>
array( "function" => "f_nucleus_getUsersBlogs",
"signature" => $f_nucleus_getUsersBlogs_sig,
"docstring" => $f_nucleus_getUsersBlogs_doc),
"nucleus.getRecentItems" =>
array( "function" => "f_nucleus_getRecentItems",
"signature" => $f_nucleus_getRecentItems_sig,
"docstring" => $f_nucleus_getRecentItems_doc),
"nucleus.getItem" =>
array( "function" => "f_nucleus_getItem",
"signature" => $f_nucleus_getItem_sig,
"docstring" => $f_nucleus_getItem_doc)
)
);
?>