OSDN Git Service

Merge branch 'skinnable-master'
[nucleus-jp/nucleus-next.git] / nucleus / xmlrpc / api_nucleus.inc.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2009 The Nucleus Group
5  *
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)
11  */
12
13 /**
14  * This file contains definitions for the functions in the Nucleus API
15  *
16  * NOTE: These functions are deprecated and will most likely be removed!
17  *
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 $
21  */
22
23         // nucleus.addItem
24         $f_nucleus_addItem_sig = array(array(
25                         // return type
26                         $xmlrpcString,  // itemid of the new item
27
28                         // params:
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)
37
38                 ));
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);
49
50                 return _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed);
51         }
52
53         // nucleus.addDatedItem (the time of the item can be given here, for offline blogging)
54         $f_nucleus_addDatedItem_sig = array(array(
55                         // return type
56                         $xmlrpcString,  // itemid of the new item
57
58                         // params:
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)
68
69                 ));
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);
81
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);
84         }
85
86         // nucleus.editItem
87         $f_nucleus_editItem_sig = array(array(
88                         // return type
89                         $xmlrpcBoolean, // true or false
90
91                         // params:
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)
100                 ));
101         $f_nucleus_editItem_doc = "Edits an item of a blog";
102         function f_nucleus_editItem($m) {
103                 global $manager;
104
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);
113
114                 // get old title and extended part
115                 if (!$manager->existsItem($itemid,1,1))
116                         return _error(6,"No such item ($itemid)");
117
118                 $old =& $manager->getItem($itemid,1,1);
119                 $wasdraft = ($old['draft']) ? 1 : 0;
120
121                 return _edititem($itemid, $username, $password, $old['catid'], $title, $content, $more, $wasdraft, $publish, $closed);
122         }
123
124
125         // nucleus.getUsersBlogs
126         $f_nucleus_getUsersBlogs_sig = array(array(
127                         // return type
128                         $xmlrpcArray,   // array containing structs containing blog info
129
130                         // params:
131                         $xmlrpcString,  // username
132                         $xmlrpcString,  // password
133                 ));
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);
138
139                 return _getUsersBlogs($username, $password);
140         }
141
142         // nucleus.getRecentItems
143         $f_nucleus_getRecentItems_sig = array(array(
144                         // return type
145                         $xmlrpcArray,   // array of strucs (representing items)
146
147                         // params
148                         $xmlrpcString,  // blogid
149                         $xmlrpcString,  // username
150                         $xmlrpcString,  // password
151                         $xmlrpcInt,     // amount of items to return (max = 20)
152                 ));
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);
159
160                 return _getRecentItems($blogid, $username, $password, $amount);
161         }
162
163         // nucleus.getItem
164         $f_nucleus_getItem_sig = array(array(
165                         // return type
166                         $xmlrpcStruct,  // A struct representing the item
167
168                         // params
169                         $xmlrpcString,  // itemid
170                         $xmlrpcString,  // username
171                         $xmlrpcString,  // password
172                 ));
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);
178
179                 return _getItem($postid, $username, $password);
180         }
181
182         // nucleus.deleteItem
183         $f_nucleus_deleteItem_sig = array(array(
184                         // return type
185                         $xmlrpcBoolean, // boolean (ok or not ok)
186
187                         // params
188                         $xmlrpcString,  // itemid
189                         $xmlrpcString,  // username
190                         $xmlrpcString,  // password
191                 ));
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);
197
198                 return _deleteItem($itemid, $username, $password);
199         }
200
201
202         /**
203           * Returns a list of recent items (Nucleus Version)
204           * ($amount = max 20);
205           */
206         function _getRecentItems($blogid, $username, $password, $amount) {
207                 $blogid = intval($blogid);
208                 $amount = intval($amount);
209
210                 // 1. login
211                 $mem = new Member();
212                 if (!$mem->login($username, $password))
213                         return _error(1,"Could not log in");
214
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");
223
224                 // 3. create and return list of recent items
225                 // Struct returned has dateCreated, userid, blogid and content
226
227                 $structarray = array();         // the array in which the structs will be stored
228
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"
233                            ." LIMIT $amount";
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"),
245                         ),'struct');
246                         array_push($structarray, $newstruct);
247                 }
248
249                 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
250
251         }
252
253
254
255         /**
256           * Returns one item (Nucleus version)
257           */
258         function _getItem($itemid, $username, $password) {
259                 global $manager;
260
261                 // 1. login
262                 $mem = new Member();
263                 if (!$mem->login($username, $password))
264                         return _error(1,"Could not log in");
265
266                 // 2. check if allowed
267                 if (!$manager->existsItem($itemid,1,1))
268                         return _error(6,"No such item ($itemid)");
269                 $blogid = getBlogIDFromItemID($itemid);
270
271                 if (!$mem->teamRights($blogid))
272                         return _error(3,"Not a team member");
273
274                 // 3. return the item
275                 // Structure returned has dateCreated, userid, blogid and content
276
277                 $item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
278
279                 $blog =& $manager->getBlog($blogid);
280                 if ($blog->convertBreaks())
281                         $item['body'] = removeBreaks($item['body']);
282
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"),
292                 ),'struct');
293
294                 return new xmlrpcresp($newstruct);
295
296
297         }
298
299
300         $functionDefs = array_merge($functionDefs,
301                 array(
302                         "nucleus.addItem" =>
303                         array( "function" => "f_nucleus_addItem",
304                                 "signature" => $f_nucleus_addItem_sig,
305                                 "docstring" => $f_nucleus_addItem_doc),
306
307                         "nucleus.editItem" =>
308                         array( "function" => "f_nucleus_editItem",
309                                 "signature" => $f_nucleus_editItem_sig,
310                                 "docstring" => $f_nucleus_editItem_doc),
311
312                         "nucleus.addDatedItem" =>
313                         array( "function" => "f_nucleus_addDatedItem",
314                                 "signature" => $f_nucleus_addDatedItem_sig,
315                                 "docstring" => $f_nucleus_addDatedItem_doc),
316
317                         "nucleus.deleteItem" =>
318                         array( "function" => "f_nucleus_deleteItem",
319                                 "signature" => $f_nucleus_deleteItem_sig,
320                                 "docstring" => $f_nucleus_deleteItem_doc),
321
322                         "nucleus.getUsersBlogs" =>
323                         array( "function" => "f_nucleus_getUsersBlogs",
324                                 "signature" => $f_nucleus_getUsersBlogs_sig,
325                                 "docstring" => $f_nucleus_getUsersBlogs_doc),
326
327                         "nucleus.getRecentItems" =>
328                         array( "function" => "f_nucleus_getRecentItems",
329                                 "signature" => $f_nucleus_getRecentItems_sig,
330                                 "docstring" => $f_nucleus_getRecentItems_doc),
331
332                         "nucleus.getItem" =>
333                         array( "function" => "f_nucleus_getItem",
334                                 "signature" => $f_nucleus_getItem_sig,
335                                 "docstring" => $f_nucleus_getItem_doc)
336                 )
337
338         );
339
340 ?>