3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2011 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)
14 * This file contains definitions for the functions in the Nucleus API
16 * NOTE: These functions are deprecated and will most likely be removed!
18 * @license http://nucleuscms.org/license.txt GNU General Public License
19 * @copyright Copyright (C) 2002-2011 The Nucleus Group
21 * $NucleusJP: api_nucleus.inc.php,v 1.5 2006/07/17 20:03:45 kimitake Exp $
25 $f_nucleus_addItem_sig = array(array(
27 $xmlrpcString, // itemid of the new item
30 $xmlrpcString, // blogid
31 $xmlrpcString, // username
32 $xmlrpcString, // password
33 $xmlrpcString, // title
34 $xmlrpcString, // body
35 $xmlrpcString, // extended part
36 $xmlrpcBoolean, // publish boolean (set to false to create draft)
37 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
40 $f_nucleus_addItem_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false";
41 function f_nucleus_addItem($m) {
42 $blogid = _getScalar($m,0);
43 $username = _getScalar($m,1);
44 $password = _getScalar($m,2);
45 $title = _getScalar($m,3);
46 $body = _getScalar($m,4);
47 $more = _getScalar($m,5);
48 $publish = _getScalar($m,6);
49 $closed = _getScalar($m,7);
51 return _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed);
54 // nucleus.addDatedItem (the time of the item can be given here, for offline blogging)
55 $f_nucleus_addDatedItem_sig = array(array(
57 $xmlrpcString, // itemid of the new item
60 $xmlrpcString, // blogid
61 $xmlrpcString, // username
62 $xmlrpcString, // password
63 $xmlrpcString, // title
64 $xmlrpcString, // body
65 $xmlrpcString, // extended part
66 $xmlrpcBoolean, // publish boolean (set to false to create draft)
67 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
68 $xmlrpcInt // item time (unix timestamp)
71 $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";
72 function f_nucleus_addDatedItem($m) {
73 $blogid = _getScalar($m,0);
74 $username = _getScalar($m,1);
75 $password = _getScalar($m,2);
76 $title = _getScalar($m,3);
77 $body = _getScalar($m,4);
78 $more = _getScalar($m,5);
79 $publish = _getScalar($m,6);
80 $closed = _getScalar($m,7);
81 $timestamp = _getScalar($m,8);
83 // use '1' as $future param to make sure the date does not get erased
84 return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 1);
88 $f_nucleus_editItem_sig = array(array(
90 $xmlrpcBoolean, // true or false
93 $xmlrpcString, // itemid
94 $xmlrpcString, // username
95 $xmlrpcString, // password
96 $xmlrpcString, // title
97 $xmlrpcString, // body
98 $xmlrpcString, // extended part
99 $xmlrpcBoolean, // publish boolean (set to false if you want a draft to stay draft)
100 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
102 $f_nucleus_editItem_doc = "Edits an item of a blog";
103 function f_nucleus_editItem($m) {
106 $itemid = intval(_getScalar($m,0));
107 $username = _getScalar($m,1);
108 $password = _getScalar($m,2);
109 $title = _getScalar($m,3);
110 $content = _getScalar($m,4);
111 $more = _getScalar($m,5);
112 $publish = _getScalar($m,6);
113 $closed = _getScalar($m,7);
115 // get old title and extended part
116 if (!$manager->existsItem($itemid,1,1))
117 return _error(6,"No such item ($itemid)");
119 $old =& $manager->getItem($itemid,1,1);
120 $wasdraft = ($old['draft']) ? 1 : 0;
122 return _edititem($itemid, $username, $password, $old['catid'], $title, $content, $more, $wasdraft, $publish, $closed);
126 // nucleus.getUsersBlogs
127 $f_nucleus_getUsersBlogs_sig = array(array(
129 $xmlrpcArray, // array containing structs containing blog info
132 $xmlrpcString, // username
133 $xmlrpcString, // password
135 $f_nucleus_getUsersBlogs_doc = "Returns a list of all the blogs where the given member is on the team";
136 function f_nucleus_getUsersBlogs($m) {
137 $username = _getScalar($m,0);
138 $password = _getScalar($m,1);
140 return _getUsersBlogs($username, $password);
143 // nucleus.getRecentItems
144 $f_nucleus_getRecentItems_sig = array(array(
146 $xmlrpcArray, // array of strucs (representing items)
149 $xmlrpcString, // blogid
150 $xmlrpcString, // username
151 $xmlrpcString, // password
152 $xmlrpcInt, // amount of items to return (max = 20)
154 $f_nucleus_getRecentItems_doc = "Returns a maximum of 20 recent items for a given webblog";
155 function f_nucleus_getRecentItems($m) {
156 $blogid = _getScalar($m, 0);
157 $username = _getScalar($m, 1);
158 $password = _getScalar($m, 2);
159 $amount = _getScalar($m, 3);
161 return _getRecentItems($blogid, $username, $password, $amount);
165 $f_nucleus_getItem_sig = array(array(
167 $xmlrpcStruct, // A struct representing the item
170 $xmlrpcString, // itemid
171 $xmlrpcString, // username
172 $xmlrpcString, // password
174 $f_nucleus_getItem_doc = "Returns an item";
175 function f_nucleus_getItem($m) {
176 $postid = _getScalar($m, 0);
177 $username = _getScalar($m, 1);
178 $password = _getScalar($m, 2);
180 return _getItem($postid, $username, $password);
183 // nucleus.deleteItem
184 $f_nucleus_deleteItem_sig = array(array(
186 $xmlrpcBoolean, // boolean (ok or not ok)
189 $xmlrpcString, // itemid
190 $xmlrpcString, // username
191 $xmlrpcString, // password
193 $f_nucleus_deleteItem_doc = "Deletes an item";
194 function f_nucleus_deleteItem($m) {
195 $itemid = _getScalar($m,0);
196 $username = _getScalar($m, 1);
197 $password = _getScalar($m, 2);
199 return _deleteItem($itemid, $username, $password);
204 * Returns a list of recent items (Nucleus Version)
205 * ($amount = max 20);
207 function _getRecentItems($blogid, $username, $password, $amount) {
208 $blogid = intval($blogid);
209 $amount = intval($amount);
213 if (!$mem->login($username, $password))
214 return _error(1,"Could not log in");
216 // 2. check if allowed
217 if (!BLOG::existsID($blogid))
218 return _error(2,"No such blog ($blogid)");
219 if (!$mem->teamRights($blogid))
220 return _error(3,"Not a team member");
221 $amount = intval($amount);
222 if (($amount < 1) or ($amount > 20))
223 return _error(5,"Amount parameter must be in range 1..20");
225 // 3. create and return list of recent items
226 // Struct returned has dateCreated, userid, blogid and content
228 $structarray = array(); // the array in which the structs will be stored
230 $query = "SELECT ibody, iauthor, ibody, imore, ititle, iclosed, idraft, itime"
231 .' FROM '.sql_table('item')
232 ." WHERE iblog=$blogid"
233 ." ORDER BY itime DESC"
235 $r = sql_query($query);
236 while ($obj = sql_fetch_object($r)) {
237 $newstruct = new xmlrpcval(array(
238 "publishDate" => new xmlrpcval(iso8601_encode(strtotime($obj->itime)),"dateTime.iso8601"),
239 "userid" => new xmlrpcval($obj->iauthor,"string"),
240 "blogid" => new xmlrpcval($blogid,"string"),
241 "title" => new xmlrpcval($obj->ititle,"string"),
242 "body" => new xmlrpcval($obj->ibody,"string"),
243 "more" => new xmlrpcval($obj->imore,"string"),
244 "draft" => new xmlrpcval($obj->idraft,"boolean"),
245 "closed" => new xmlrpcval($obj->iclosed,"boolean"),
247 array_push($structarray, $newstruct);
250 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
257 * Returns one item (Nucleus version)
259 function _getItem($itemid, $username, $password) {
264 if (!$mem->login($username, $password))
265 return _error(1,"Could not log in");
267 // 2. check if allowed
268 if (!$manager->existsItem($itemid,1,1))
269 return _error(6,"No such item ($itemid)");
270 $blogid = getBlogIDFromItemID($itemid);
272 if (!$mem->teamRights($blogid))
273 return _error(3,"Not a team member");
275 // 3. return the item
276 // Structure returned has dateCreated, userid, blogid and content
278 $item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
280 $blog = new BLOG($blogid);
281 if ($blog->convertBreaks())
282 $item['body'] = removeBreaks($item['body']);
284 $newstruct = new xmlrpcval(array(
285 "publishDate" => new xmlrpcval(iso8601_encode($item['timestamp']),"dateTime.iso8601"),
286 "userid" => new xmlrpcval($item['authorid'],"string"),
287 "blogid" => new xmlrpcval($blogid,"string"),
288 "title" => new xmlrpcval($item['title'],"string"),
289 "body" => new xmlrpcval($item['body'],"string"),
290 "more" => new xmlrpcval($item['more'],"string"),
291 "draft" => new xmlrpcval($item['draft'],"boolean"),
292 "closed" => new xmlrpcval($item['closed'],"boolean"),
295 return new xmlrpcresp($newstruct);
301 $functionDefs = array_merge($functionDefs,
304 array( "function" => "f_nucleus_addItem",
305 "signature" => $f_nucleus_addItem_sig,
306 "docstring" => $f_nucleus_addItem_doc),
308 "nucleus.editItem" =>
309 array( "function" => "f_nucleus_editItem",
310 "signature" => $f_nucleus_editItem_sig,
311 "docstring" => $f_nucleus_editItem_doc),
313 "nucleus.addDatedItem" =>
314 array( "function" => "f_nucleus_addDatedItem",
315 "signature" => $f_nucleus_addDatedItem_sig,
316 "docstring" => $f_nucleus_addDatedItem_doc),
318 "nucleus.deleteItem" =>
319 array( "function" => "f_nucleus_deleteItem",
320 "signature" => $f_nucleus_deleteItem_sig,
321 "docstring" => $f_nucleus_deleteItem_doc),
323 "nucleus.getUsersBlogs" =>
324 array( "function" => "f_nucleus_getUsersBlogs",
325 "signature" => $f_nucleus_getUsersBlogs_sig,
326 "docstring" => $f_nucleus_getUsersBlogs_doc),
328 "nucleus.getRecentItems" =>
329 array( "function" => "f_nucleus_getRecentItems",
330 "signature" => $f_nucleus_getRecentItems_sig,
331 "docstring" => $f_nucleus_getRecentItems_doc),
334 array( "function" => "f_nucleus_getItem",
335 "signature" => $f_nucleus_getItem_sig,
336 "docstring" => $f_nucleus_getItem_doc)