3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2009 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-2009 The Nucleus Group
20 * @version $Id: api_nucleus.inc.php 1860 2012-05-19 03:47:59Z sakamocchi $
24 $f_nucleus_addItem_sig = array(array(
26 $xmlrpcString, // itemid of the new item
29 $xmlrpcString, // blogid
30 $xmlrpcString, // username
31 $xmlrpcString, // password
32 $xmlrpcString, // title
33 $xmlrpcString, // body
34 $xmlrpcString, // extended part
35 $xmlrpcBoolean, // publish boolean (set to false to create draft)
36 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
39 $f_nucleus_addItem_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false";
40 function f_nucleus_addItem($m) {
41 $blogid = _getScalar($m,0);
42 $username = _getScalar($m,1);
43 $password = _getScalar($m,2);
44 $title = _getScalar($m,3);
45 $body = _getScalar($m,4);
46 $more = _getScalar($m,5);
47 $publish = _getScalar($m,6);
48 $closed = _getScalar($m,7);
50 return _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed);
53 // nucleus.addDatedItem (the time of the item can be given here, for offline blogging)
54 $f_nucleus_addDatedItem_sig = array(array(
56 $xmlrpcString, // itemid of the new item
59 $xmlrpcString, // blogid
60 $xmlrpcString, // username
61 $xmlrpcString, // password
62 $xmlrpcString, // title
63 $xmlrpcString, // body
64 $xmlrpcString, // extended part
65 $xmlrpcBoolean, // publish boolean (set to false to create draft)
66 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
67 $xmlrpcInt // item time (unix timestamp)
70 $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";
71 function f_nucleus_addDatedItem($m) {
72 $blogid = _getScalar($m,0);
73 $username = _getScalar($m,1);
74 $password = _getScalar($m,2);
75 $title = _getScalar($m,3);
76 $body = _getScalar($m,4);
77 $more = _getScalar($m,5);
78 $publish = _getScalar($m,6);
79 $closed = _getScalar($m,7);
80 $timestamp = _getScalar($m,8);
82 // use '1' as $future param to make sure the date does not get erased
83 return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 1);
87 $f_nucleus_editItem_sig = array(array(
89 $xmlrpcBoolean, // true or false
92 $xmlrpcString, // itemid
93 $xmlrpcString, // username
94 $xmlrpcString, // password
95 $xmlrpcString, // title
96 $xmlrpcString, // body
97 $xmlrpcString, // extended part
98 $xmlrpcBoolean, // publish boolean (set to false if you want a draft to stay draft)
99 $xmlrpcBoolean, // closed boolean (set to true to disable comments)
101 $f_nucleus_editItem_doc = "Edits an item of a blog";
102 function f_nucleus_editItem($m) {
105 $itemid = intval(_getScalar($m,0));
106 $username = _getScalar($m,1);
107 $password = _getScalar($m,2);
108 $title = _getScalar($m,3);
109 $content = _getScalar($m,4);
110 $more = _getScalar($m,5);
111 $publish = _getScalar($m,6);
112 $closed = _getScalar($m,7);
114 // get old title and extended part
115 if (!$manager->existsItem($itemid,1,1))
116 return _error(6,"No such item ($itemid)");
118 $old =& $manager->getItem($itemid,1,1);
119 $wasdraft = ($old['draft']) ? 1 : 0;
121 return _edititem($itemid, $username, $password, $old['catid'], $title, $content, $more, $wasdraft, $publish, $closed);
125 // nucleus.getUsersBlogs
126 $f_nucleus_getUsersBlogs_sig = array(array(
128 $xmlrpcArray, // array containing structs containing blog info
131 $xmlrpcString, // username
132 $xmlrpcString, // password
134 $f_nucleus_getUsersBlogs_doc = "Returns a list of all the blogs where the given member is on the team";
135 function f_nucleus_getUsersBlogs($m) {
136 $username = _getScalar($m,0);
137 $password = _getScalar($m,1);
139 return _getUsersBlogs($username, $password);
142 // nucleus.getRecentItems
143 $f_nucleus_getRecentItems_sig = array(array(
145 $xmlrpcArray, // array of strucs (representing items)
148 $xmlrpcString, // blogid
149 $xmlrpcString, // username
150 $xmlrpcString, // password
151 $xmlrpcInt, // amount of items to return (max = 20)
153 $f_nucleus_getRecentItems_doc = "Returns a maximum of 20 recent items for a given webblog";
154 function f_nucleus_getRecentItems($m) {
155 $blogid = _getScalar($m, 0);
156 $username = _getScalar($m, 1);
157 $password = _getScalar($m, 2);
158 $amount = _getScalar($m, 3);
160 return _getRecentItems($blogid, $username, $password, $amount);
164 $f_nucleus_getItem_sig = array(array(
166 $xmlrpcStruct, // A struct representing the item
169 $xmlrpcString, // itemid
170 $xmlrpcString, // username
171 $xmlrpcString, // password
173 $f_nucleus_getItem_doc = "Returns an item";
174 function f_nucleus_getItem($m) {
175 $postid = _getScalar($m, 0);
176 $username = _getScalar($m, 1);
177 $password = _getScalar($m, 2);
179 return _getItem($postid, $username, $password);
182 // nucleus.deleteItem
183 $f_nucleus_deleteItem_sig = array(array(
185 $xmlrpcBoolean, // boolean (ok or not ok)
188 $xmlrpcString, // itemid
189 $xmlrpcString, // username
190 $xmlrpcString, // password
192 $f_nucleus_deleteItem_doc = "Deletes an item";
193 function f_nucleus_deleteItem($m) {
194 $itemid = _getScalar($m,0);
195 $username = _getScalar($m, 1);
196 $password = _getScalar($m, 2);
198 return _deleteItem($itemid, $username, $password);
203 * Returns a list of recent items (Nucleus Version)
204 * ($amount = max 20);
206 function _getRecentItems($blogid, $username, $password, $amount) {
207 $blogid = intval($blogid);
208 $amount = intval($amount);
212 if (!$mem->login($username, $password))
213 return _error(1,"Could not log in");
215 // 2. check if allowed
216 if (!Blog::existsID($blogid))
217 return _error(2,"No such blog ($blogid)");
218 if (!$mem->teamRights($blogid))
219 return _error(3,"Not a team member");
220 $amount = intval($amount);
221 if (($amount < 1) or ($amount > 20))
222 return _error(5,"Amount parameter must be in range 1..20");
224 // 3. create and return list of recent items
225 // Struct returned has dateCreated, userid, blogid and content
227 $structarray = array(); // the array in which the structs will be stored
229 $query = "SELECT ibody, iauthor, ibody, imore, ititle, iclosed, idraft, itime"
230 .' FROM '.sql_table('item')
231 ." WHERE iblog=$blogid"
232 ." ORDER BY itime DESC"
234 $r = DB::getResult($query);
235 foreach ( $r as $row ) {
236 $newstruct = new xmlrpcval(array(
237 "publishDate" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"),
238 "userid" => new xmlrpcval($row['iauthor'],"string"),
239 "blogid" => new xmlrpcval($blogid,"string"),
240 "title" => new xmlrpcval($row['ititle'],"string"),
241 "body" => new xmlrpcval($row['ibody'],"string"),
242 "more" => new xmlrpcval($row['imore'],"string"),
243 "draft" => new xmlrpcval($row['idraft'],"boolean"),
244 "closed" => new xmlrpcval($row['iclosed'],"boolean"),
246 array_push($structarray, $newstruct);
249 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
256 * Returns one item (Nucleus version)
258 function _getItem($itemid, $username, $password) {
263 if (!$mem->login($username, $password))
264 return _error(1,"Could not log in");
266 // 2. check if allowed
267 if (!$manager->existsItem($itemid,1,1))
268 return _error(6,"No such item ($itemid)");
269 $blogid = getBlogIDFromItemID($itemid);
271 if (!$mem->teamRights($blogid))
272 return _error(3,"Not a team member");
274 // 3. return the item
275 // Structure returned has dateCreated, userid, blogid and content
277 $item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
279 $blog =& $manager->getBlog($blogid);
280 if ($blog->convertBreaks())
281 $item['body'] = removeBreaks($item['body']);
283 $newstruct = new xmlrpcval(array(
284 "publishDate" => new xmlrpcval(iso8601_encode($item['timestamp']),"dateTime.iso8601"),
285 "userid" => new xmlrpcval($item['authorid'],"string"),
286 "blogid" => new xmlrpcval($blogid,"string"),
287 "title" => new xmlrpcval($item['title'],"string"),
288 "body" => new xmlrpcval($item['body'],"string"),
289 "more" => new xmlrpcval($item['more'],"string"),
290 "draft" => new xmlrpcval($item['draft'],"boolean"),
291 "closed" => new xmlrpcval($item['closed'],"boolean"),
294 return new xmlrpcresp($newstruct);
300 $functionDefs = array_merge($functionDefs,
303 array( "function" => "f_nucleus_addItem",
304 "signature" => $f_nucleus_addItem_sig,
305 "docstring" => $f_nucleus_addItem_doc),
307 "nucleus.editItem" =>
308 array( "function" => "f_nucleus_editItem",
309 "signature" => $f_nucleus_editItem_sig,
310 "docstring" => $f_nucleus_editItem_doc),
312 "nucleus.addDatedItem" =>
313 array( "function" => "f_nucleus_addDatedItem",
314 "signature" => $f_nucleus_addDatedItem_sig,
315 "docstring" => $f_nucleus_addDatedItem_doc),
317 "nucleus.deleteItem" =>
318 array( "function" => "f_nucleus_deleteItem",
319 "signature" => $f_nucleus_deleteItem_sig,
320 "docstring" => $f_nucleus_deleteItem_doc),
322 "nucleus.getUsersBlogs" =>
323 array( "function" => "f_nucleus_getUsersBlogs",
324 "signature" => $f_nucleus_getUsersBlogs_sig,
325 "docstring" => $f_nucleus_getUsersBlogs_doc),
327 "nucleus.getRecentItems" =>
328 array( "function" => "f_nucleus_getRecentItems",
329 "signature" => $f_nucleus_getRecentItems_sig,
330 "docstring" => $f_nucleus_getRecentItems_doc),
333 array( "function" => "f_nucleus_getItem",
334 "signature" => $f_nucleus_getItem_sig,
335 "docstring" => $f_nucleus_getItem_doc)