3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2005 The Nucleus Group
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
10 * (see nucleus/documentation/index.html#license for more info)
\r
12 * $Id: api_nucleus.inc.php,v 1.3 2005-03-12 06:19:06 kimitake Exp $
\r
17 * This file contains definitions for the functions in the Nucleus API
\r
19 * NOTE: These functions are deprecated and will most likely be removed!
\r
23 $f_nucleus_addItem_sig = array(array(
\r
25 $xmlrpcString, // itemid of the new item
\r
28 $xmlrpcString, // blogid
\r
29 $xmlrpcString, // username
\r
30 $xmlrpcString, // password
\r
31 $xmlrpcString, // title
\r
32 $xmlrpcString, // body
\r
33 $xmlrpcString, // extended part
\r
34 $xmlrpcBoolean, // publish boolean (set to false to create draft)
\r
35 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
\r
38 $f_nucleus_addItem_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false";
\r
39 function f_nucleus_addItem($m) {
\r
40 $blogid = _getScalar($m,0);
\r
41 $username = _getScalar($m,1);
\r
42 $password = _getScalar($m,2);
\r
43 $title = _getScalar($m,3);
\r
44 $body = _getScalar($m,4);
\r
45 $more = _getScalar($m,5);
\r
46 $publish = _getScalar($m,6);
\r
47 $closed = _getScalar($m,7);
\r
49 return _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed);
\r
52 // nucleus.addDatedItem (the time of the item can be given here, for offline blogging)
\r
53 $f_nucleus_addDatedItem_sig = array(array(
\r
55 $xmlrpcString, // itemid of the new item
\r
58 $xmlrpcString, // blogid
\r
59 $xmlrpcString, // username
\r
60 $xmlrpcString, // password
\r
61 $xmlrpcString, // title
\r
62 $xmlrpcString, // body
\r
63 $xmlrpcString, // extended part
\r
64 $xmlrpcBoolean, // publish boolean (set to false to create draft)
\r
65 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
\r
66 $xmlrpcInt // item time (unix timestamp)
\r
69 $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";
\r
70 function f_nucleus_addDatedItem($m) {
\r
71 $blogid = _getScalar($m,0);
\r
72 $username = _getScalar($m,1);
\r
73 $password = _getScalar($m,2);
\r
74 $title = _getScalar($m,3);
\r
75 $body = _getScalar($m,4);
\r
76 $more = _getScalar($m,5);
\r
77 $publish = _getScalar($m,6);
\r
78 $closed = _getScalar($m,7);
\r
79 $timestamp = _getScalar($m,8);
\r
81 // use '1' as $future param to make sure the date does not get erased
\r
82 return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 1);
\r
86 $f_nucleus_editItem_sig = array(array(
\r
88 $xmlrpcBoolean, // true or false
\r
91 $xmlrpcString, // itemid
\r
92 $xmlrpcString, // username
\r
93 $xmlrpcString, // password
\r
94 $xmlrpcString, // title
\r
95 $xmlrpcString, // body
\r
96 $xmlrpcString, // extended part
\r
97 $xmlrpcBoolean, // publish boolean (set to false if you want a draft to stay draft)
\r
98 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
\r
100 $f_nucleus_editItem_doc = "Edits an item of a blog";
\r
101 function f_nucleus_editItem($m) {
\r
104 $itemid = intval(_getScalar($m,0));
\r
105 $username = _getScalar($m,1);
\r
106 $password = _getScalar($m,2);
\r
107 $title = _getScalar($m,3);
\r
108 $content = _getScalar($m,4);
\r
109 $more = _getScalar($m,5);
\r
110 $publish = _getScalar($m,6);
\r
111 $closed = _getScalar($m,7);
\r
113 // get old title and extended part
\r
114 if (!$manager->existsItem($itemid,1,1))
\r
115 return _error(6,"No such item ($itemid)");
\r
117 $old =& $manager->getItem($itemid,1,1);
\r
118 $wasdraft = ($old['draft']) ? 1 : 0;
\r
120 return _edititem($itemid, $username, $password, $old['catid'], $title, $content, $more, $wasdraft, $publish, $closed);
\r
124 // nucleus.getUsersBlogs
\r
125 $f_nucleus_getUsersBlogs_sig = array(array(
\r
127 $xmlrpcArray, // array containing structs containing blog info
\r
130 $xmlrpcString, // username
\r
131 $xmlrpcString, // password
\r
133 $f_nucleus_getUsersBlogs_doc = "Returns a list of all the blogs where the given member is on the team";
\r
134 function f_nucleus_getUsersBlogs($m) {
\r
135 $username = _getScalar($m,0);
\r
136 $password = _getScalar($m,1);
\r
138 return _getUsersBlogs($username, $password);
\r
141 // nucleus.getRecentItems
\r
142 $f_nucleus_getRecentItems_sig = array(array(
\r
144 $xmlrpcArray, // array of strucs (representing items)
\r
147 $xmlrpcString, // blogid
\r
148 $xmlrpcString, // username
\r
149 $xmlrpcString, // password
\r
150 $xmlrpcInt, // amount of items to return (max = 20)
\r
152 $f_nucleus_getRecentItems_doc = "Returns a maximum of 20 recent items for a given webblog";
\r
153 function f_nucleus_getRecentItems($m) {
\r
154 $blogid = _getScalar($m, 0);
\r
155 $username = _getScalar($m, 1);
\r
156 $password = _getScalar($m, 2);
\r
157 $amount = _getScalar($m, 3);
\r
159 return _getRecentItems($blogid, $username, $password, $amount);
\r
163 $f_nucleus_getItem_sig = array(array(
\r
165 $xmlrpcStruct, // A struct representing the item
\r
168 $xmlrpcString, // itemid
\r
169 $xmlrpcString, // username
\r
170 $xmlrpcString, // password
\r
172 $f_nucleus_getItem_doc = "Returns an item";
\r
173 function f_nucleus_getItem($m) {
\r
174 $postid = _getScalar($m, 0);
\r
175 $username = _getScalar($m, 1);
\r
176 $password = _getScalar($m, 2);
\r
178 return _getItem($postid, $username, $password);
\r
181 // nucleus.deleteItem
\r
182 $f_nucleus_deleteItem_sig = array(array(
\r
184 $xmlrpcBoolean, // boolean (ok or not ok)
\r
187 $xmlrpcString, // itemid
\r
188 $xmlrpcString, // username
\r
189 $xmlrpcString, // password
\r
191 $f_nucleus_deleteItem_doc = "Deletes an item";
\r
192 function f_nucleus_deleteItem($m) {
\r
193 $itemid = _getScalar($m,0);
\r
194 $username = _getScalar($m, 1);
\r
195 $password = _getScalar($m, 2);
\r
197 return _deleteItem($itemid, $username, $password);
\r
202 * Returns a list of recent items (Nucleus Version)
\r
203 * ($amount = max 20);
\r
205 function _getRecentItems($blogid, $username, $password, $amount) {
\r
206 $blogid = intval($blogid);
\r
207 $amount = intval($amount);
\r
210 $mem = new MEMBER();
\r
211 if (!$mem->login($username, $password))
\r
212 return _error(1,"Could not log in");
\r
214 // 2. check if allowed
\r
215 if (!BLOG::existsID($blogid))
\r
216 return _error(2,"No such blog ($blogid)");
\r
217 if (!$mem->teamRights($blogid))
\r
218 return _error(3,"Not a team member");
\r
219 $amount = intval($amount);
\r
220 if (($amount < 1) or ($amount > 20))
\r
221 return _error(5,"Amount parameter must be in range 1..20");
\r
223 // 3. create and return list of recent items
\r
224 // Struct returned has dateCreated, userid, blogid and content
\r
226 $structarray = array(); // the array in which the structs will be stored
\r
228 $query = "SELECT ibody, iauthor, ibody, imore, ititle, iclosed, idraft, itime"
\r
229 .' FROM '.sql_table('item')
\r
230 ." WHERE iblog=$blogid"
\r
231 ." ORDER BY itime DESC"
\r
233 $r = sql_query($query);
\r
234 while ($obj = mysql_fetch_object($r)) {
\r
235 $newstruct = new xmlrpcval(array(
\r
236 "publishDate" => new xmlrpcval(iso8601_encode(strtotime($obj->itime)),"dateTime.iso8601"),
\r
237 "userid" => new xmlrpcval($obj->iauthor,"string"),
\r
238 "blogid" => new xmlrpcval($blogid,"string"),
\r
239 "title" => new xmlrpcval($obj->ititle,"string"),
\r
240 "body" => new xmlrpcval($obj->ibody,"string"),
\r
241 "more" => new xmlrpcval($obj->imore,"string"),
\r
242 "draft" => new xmlrpcval($obj->idraft,"boolean"),
\r
243 "closed" => new xmlrpcval($obj->iclosed,"boolean"),
\r
245 array_push($structarray, $newstruct);
\r
248 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
\r
255 * Returns one item (Nucleus version)
\r
257 function _getItem($itemid, $username, $password) {
\r
261 $mem = new MEMBER();
\r
262 if (!$mem->login($username, $password))
\r
263 return _error(1,"Could not log in");
\r
265 // 2. check if allowed
\r
266 if (!$manager->existsItem($itemid,1,1))
\r
267 return _error(6,"No such item ($itemid)");
\r
268 $blogid = getBlogIDFromItemID($itemid);
\r
270 if (!$mem->teamRights($blogid))
\r
271 return _error(3,"Not a team member");
\r
273 // 3. return the item
\r
274 // Structure returned has dateCreated, userid, blogid and content
\r
276 $item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
\r
278 $blog = new BLOG($blogid);
\r
279 if ($blog->convertBreaks())
\r
280 $item['body'] = removeBreaks($item['body']);
\r
282 $newstruct = new xmlrpcval(array(
\r
283 "publishDate" => new xmlrpcval(iso8601_encode($item['timestamp']),"dateTime.iso8601"),
\r
284 "userid" => new xmlrpcval($item['authorid'],"string"),
\r
285 "blogid" => new xmlrpcval($blogid,"string"),
\r
286 "title" => new xmlrpcval($item['title'],"string"),
\r
287 "body" => new xmlrpcval($item['body'],"string"),
\r
288 "more" => new xmlrpcval($item['more'],"string"),
\r
289 "draft" => new xmlrpcval($item['draft'],"boolean"),
\r
290 "closed" => new xmlrpcval($ite['closed'],"boolean"),
\r
293 return new xmlrpcresp($newstruct);
\r
299 $functionDefs = array_merge($functionDefs,
\r
301 "nucleus.addItem" =>
\r
302 array( "function" => "f_nucleus_addItem",
\r
303 "signature" => $f_nucleus_addItem_sig,
\r
304 "docstring" => $f_nucleus_addItem_doc),
\r
306 "nucleus.editItem" =>
\r
307 array( "function" => "f_nucleus_editItem",
\r
308 "signature" => $f_nucleus_editItem_sig,
\r
309 "docstring" => $f_nucleus_editItem_doc),
\r
311 "nucleus.addDatedItem" =>
\r
312 array( "function" => "f_nucleus_addDatedItem",
\r
313 "signature" => $f_nucleus_addDatedItem_sig,
\r
314 "docstring" => $f_nucleus_addDatedItem_doc),
\r
316 "nucleus.deleteItem" =>
\r
317 array( "function" => "f_nucleus_deleteItem",
\r
318 "signature" => $f_nucleus_deleteItem_sig,
\r
319 "docstring" => $f_nucleus_deleteItem_doc),
\r
321 "nucleus.getUsersBlogs" =>
\r
322 array( "function" => "f_nucleus_getUsersBlogs",
\r
323 "signature" => $f_nucleus_getUsersBlogs_sig,
\r
324 "docstring" => $f_nucleus_getUsersBlogs_doc),
\r
326 "nucleus.getRecentItems" =>
\r
327 array( "function" => "f_nucleus_getRecentItems",
\r
328 "signature" => $f_nucleus_getRecentItems_sig,
\r
329 "docstring" => $f_nucleus_getRecentItems_doc),
\r
331 "nucleus.getItem" =>
\r
332 array( "function" => "f_nucleus_getItem",
\r
333 "signature" => $f_nucleus_getItem_sig,
\r
334 "docstring" => $f_nucleus_getItem_doc)
\r