3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2012 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
12 * This file contains definitions for the functions in the Nucleus API
14 * NOTE: These functions are deprecated and will most likely be removed!
18 $f_nucleus_addItem_sig = array(array(
20 $xmlrpcString, // itemid of the new item
23 $xmlrpcString, // blogid
24 $xmlrpcString, // username
25 $xmlrpcString, // password
26 $xmlrpcString, // title
27 $xmlrpcString, // body
28 $xmlrpcString, // extended part
29 $xmlrpcBoolean, // publish boolean (set to false to create draft)
30 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
33 $f_nucleus_addItem_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false";
34 function f_nucleus_addItem($m) {
35 $blogid = _getScalar($m,0);
36 $username = _getScalar($m,1);
37 $password = _getScalar($m,2);
38 $title = _getScalar($m,3);
39 $body = _getScalar($m,4);
40 $more = _getScalar($m,5);
41 $publish = _getScalar($m,6);
42 $closed = _getScalar($m,7);
44 return _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed);
47 // nucleus.addDatedItem (the time of the item can be given here, for offline blogging)
48 $f_nucleus_addDatedItem_sig = array(array(
50 $xmlrpcString, // itemid of the new item
53 $xmlrpcString, // blogid
54 $xmlrpcString, // username
55 $xmlrpcString, // password
56 $xmlrpcString, // title
57 $xmlrpcString, // body
58 $xmlrpcString, // extended part
59 $xmlrpcBoolean, // publish boolean (set to false to create draft)
60 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
61 $xmlrpcInt // item time (unix timestamp)
64 $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";
65 function f_nucleus_addDatedItem($m) {
66 $blogid = _getScalar($m,0);
67 $username = _getScalar($m,1);
68 $password = _getScalar($m,2);
69 $title = _getScalar($m,3);
70 $body = _getScalar($m,4);
71 $more = _getScalar($m,5);
72 $publish = _getScalar($m,6);
73 $closed = _getScalar($m,7);
74 $timestamp = _getScalar($m,8);
76 // use '1' as $future param to make sure the date does not get erased
77 return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 1);
81 $f_nucleus_editItem_sig = array(array(
83 $xmlrpcBoolean, // true or false
86 $xmlrpcString, // itemid
87 $xmlrpcString, // username
88 $xmlrpcString, // password
89 $xmlrpcString, // title
90 $xmlrpcString, // body
91 $xmlrpcString, // extended part
92 $xmlrpcBoolean, // publish boolean (set to false if you want a draft to stay draft)
93 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
95 $f_nucleus_editItem_doc = "Edits an item of a blog";
96 function f_nucleus_editItem($m) {
99 $itemid = intval(_getScalar($m,0));
100 $username = _getScalar($m,1);
101 $password = _getScalar($m,2);
102 $title = _getScalar($m,3);
103 $content = _getScalar($m,4);
104 $more = _getScalar($m,5);
105 $publish = _getScalar($m,6);
106 $closed = _getScalar($m,7);
108 // get old title and extended part
109 if (!$manager->existsItem($itemid,1,1))
110 return _error(6,"No such item ($itemid)");
112 $old =& $manager->getItem($itemid,1,1);
113 $wasdraft = ($old['draft']) ? 1 : 0;
115 return _edititem($itemid, $username, $password, $old['catid'], $title, $content, $more, $wasdraft, $publish, $closed);
119 // nucleus.getUsersBlogs
120 $f_nucleus_getUsersBlogs_sig = array(array(
122 $xmlrpcArray, // array containing structs containing blog info
125 $xmlrpcString, // username
126 $xmlrpcString, // password
128 $f_nucleus_getUsersBlogs_doc = "Returns a list of all the blogs where the given member is on the team";
129 function f_nucleus_getUsersBlogs($m) {
130 $username = _getScalar($m,0);
131 $password = _getScalar($m,1);
133 return _getUsersBlogs($username, $password);
136 // nucleus.getRecentItems
137 $f_nucleus_getRecentItems_sig = array(array(
139 $xmlrpcArray, // array of strucs (representing items)
142 $xmlrpcString, // blogid
143 $xmlrpcString, // username
144 $xmlrpcString, // password
145 $xmlrpcInt, // amount of items to return (max = 20)
147 $f_nucleus_getRecentItems_doc = "Returns a maximum of 20 recent items for a given webblog";
148 function f_nucleus_getRecentItems($m) {
149 $blogid = _getScalar($m, 0);
150 $username = _getScalar($m, 1);
151 $password = _getScalar($m, 2);
152 $amount = _getScalar($m, 3);
154 return _getRecentItems($blogid, $username, $password, $amount);
158 $f_nucleus_getItem_sig = array(array(
160 $xmlrpcStruct, // A struct representing the item
163 $xmlrpcString, // itemid
164 $xmlrpcString, // username
165 $xmlrpcString, // password
167 $f_nucleus_getItem_doc = "Returns an item";
168 function f_nucleus_getItem($m) {
169 $postid = _getScalar($m, 0);
170 $username = _getScalar($m, 1);
171 $password = _getScalar($m, 2);
173 return _getItem($postid, $username, $password);
176 // nucleus.deleteItem
177 $f_nucleus_deleteItem_sig = array(array(
179 $xmlrpcBoolean, // boolean (ok or not ok)
182 $xmlrpcString, // itemid
183 $xmlrpcString, // username
184 $xmlrpcString, // password
186 $f_nucleus_deleteItem_doc = "Deletes an item";
187 function f_nucleus_deleteItem($m) {
188 $itemid = _getScalar($m,0);
189 $username = _getScalar($m, 1);
190 $password = _getScalar($m, 2);
192 return _deleteItem($itemid, $username, $password);
197 * Returns a list of recent items (Nucleus Version)
198 * ($amount = max 20);
200 function _getRecentItems($blogid, $username, $password, $amount) {
201 $blogid = intval($blogid);
202 $amount = intval($amount);
206 if (!$mem->login($username, $password))
207 return _error(1,"Could not log in");
209 // 2. check if allowed
210 if (!BLOG::existsID($blogid))
211 return _error(2,"No such blog ($blogid)");
212 if (!$mem->teamRights($blogid))
213 return _error(3,"Not a team member");
214 $amount = intval($amount);
215 if (($amount < 1) or ($amount > 20))
216 return _error(5,"Amount parameter must be in range 1..20");
218 // 3. create and return list of recent items
219 // Struct returned has dateCreated, userid, blogid and content
221 $structarray = array(); // the array in which the structs will be stored
223 $query = "SELECT ibody, iauthor, ibody, imore, ititle, iclosed, idraft, itime"
224 .' FROM '.sql_table('item')
225 ." WHERE iblog=$blogid"
226 ." ORDER BY itime DESC"
228 $r = sql_query($query);
229 while ($obj = sql_fetch_object($r)) {
230 $newstruct = new xmlrpcval(array(
231 "publishDate" => new xmlrpcval(iso8601_encode(strtotime($obj->itime)),"dateTime.iso8601"),
232 "userid" => new xmlrpcval($obj->iauthor,"string"),
233 "blogid" => new xmlrpcval($blogid,"string"),
234 "title" => new xmlrpcval($obj->ititle,"string"),
235 "body" => new xmlrpcval($obj->ibody,"string"),
236 "more" => new xmlrpcval($obj->imore,"string"),
237 "draft" => new xmlrpcval($obj->idraft,"boolean"),
238 "closed" => new xmlrpcval($obj->iclosed,"boolean"),
240 array_push($structarray, $newstruct);
243 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
250 * Returns one item (Nucleus version)
252 function _getItem($itemid, $username, $password) {
257 if (!$mem->login($username, $password))
258 return _error(1,"Could not log in");
260 // 2. check if allowed
261 if (!$manager->existsItem($itemid,1,1))
262 return _error(6,"No such item ($itemid)");
263 $blogid = getBlogIDFromItemID($itemid);
265 if (!$mem->teamRights($blogid))
266 return _error(3,"Not a team member");
268 // 3. return the item
269 // Structure returned has dateCreated, userid, blogid and content
271 $item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
273 $blog = new BLOG($blogid);
274 if ($blog->convertBreaks())
275 $item['body'] = removeBreaks($item['body']);
277 $newstruct = new xmlrpcval(array(
278 "publishDate" => new xmlrpcval(iso8601_encode($item['timestamp']),"dateTime.iso8601"),
279 "userid" => new xmlrpcval($item['authorid'],"string"),
280 "blogid" => new xmlrpcval($blogid,"string"),
281 "title" => new xmlrpcval($item['title'],"string"),
282 "body" => new xmlrpcval($item['body'],"string"),
283 "more" => new xmlrpcval($item['more'],"string"),
284 "draft" => new xmlrpcval($item['draft'],"boolean"),
285 "closed" => new xmlrpcval($item['closed'],"boolean"),
288 return new xmlrpcresp($newstruct);
294 $functionDefs = array_merge($functionDefs,
297 array( "function" => "f_nucleus_addItem",
298 "signature" => $f_nucleus_addItem_sig,
299 "docstring" => $f_nucleus_addItem_doc),
301 "nucleus.editItem" =>
302 array( "function" => "f_nucleus_editItem",
303 "signature" => $f_nucleus_editItem_sig,
304 "docstring" => $f_nucleus_editItem_doc),
306 "nucleus.addDatedItem" =>
307 array( "function" => "f_nucleus_addDatedItem",
308 "signature" => $f_nucleus_addDatedItem_sig,
309 "docstring" => $f_nucleus_addDatedItem_doc),
311 "nucleus.deleteItem" =>
312 array( "function" => "f_nucleus_deleteItem",
313 "signature" => $f_nucleus_deleteItem_sig,
314 "docstring" => $f_nucleus_deleteItem_doc),
316 "nucleus.getUsersBlogs" =>
317 array( "function" => "f_nucleus_getUsersBlogs",
318 "signature" => $f_nucleus_getUsersBlogs_sig,
319 "docstring" => $f_nucleus_getUsersBlogs_doc),
321 "nucleus.getRecentItems" =>
322 array( "function" => "f_nucleus_getRecentItems",
323 "signature" => $f_nucleus_getRecentItems_sig,
324 "docstring" => $f_nucleus_getRecentItems_doc),
327 array( "function" => "f_nucleus_getItem",
328 "signature" => $f_nucleus_getItem_sig,
329 "docstring" => $f_nucleus_getItem_doc)