OSDN Git Service

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