OSDN Git Service

Subversion由来のタグを削除
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / xmlrpc / api_nucleus.inc.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2012 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  * This file contains definitions for the functions in the Nucleus API
13  *
14  * NOTE: These functions are deprecated and will most likely be removed!
15  */
16
17         // nucleus.addItem
18         $f_nucleus_addItem_sig = array(array(
19                         // return type
20                         $xmlrpcString,  // itemid of the new item
21
22                         // params:
23                         $xmlrpcString,  // blogid
24                         $xmlrpcString,  // username
25                         $xmlrpcString,  // password
26                         $xmlrpcString,  // title
27                         $xmlrpcString,  // body
28                         $xmlrpcString,  // extended part
29                         $xmlrpcBoolean, // publish boolean (set to false to create draft)
30                         $xmlrpcBoolean, // closed boolean (set to true to disable comments)
31
32                 ));
33         $f_nucleus_addItem_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false";
34         function f_nucleus_addItem($m) {
35                 $blogid = _getScalar($m,0);
36                 $username = _getScalar($m,1);
37                 $password = _getScalar($m,2);
38                 $title = _getScalar($m,3);
39                 $body = _getScalar($m,4);
40                 $more = _getScalar($m,5);
41                 $publish = _getScalar($m,6);
42                 $closed = _getScalar($m,7);
43
44                 return _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed);
45         }
46
47         // nucleus.addDatedItem (the time of the item can be given here, for offline blogging)
48         $f_nucleus_addDatedItem_sig = array(array(
49                         // return type
50                         $xmlrpcString,  // itemid of the new item
51
52                         // params:
53                         $xmlrpcString,  // blogid
54                         $xmlrpcString,  // username
55                         $xmlrpcString,  // password
56                         $xmlrpcString,  // title
57                         $xmlrpcString,  // body
58                         $xmlrpcString,  // extended part
59                         $xmlrpcBoolean, // publish boolean (set to false to create draft)
60                         $xmlrpcBoolean, // closed boolean (set to true to disable comments)
61                         $xmlrpcInt      // item time (unix timestamp)
62
63                 ));
64         $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";
65         function f_nucleus_addDatedItem($m) {
66                 $blogid = _getScalar($m,0);
67                 $username = _getScalar($m,1);
68                 $password = _getScalar($m,2);
69                 $title = _getScalar($m,3);
70                 $body = _getScalar($m,4);
71                 $more = _getScalar($m,5);
72                 $publish = _getScalar($m,6);
73                 $closed = _getScalar($m,7);
74                 $timestamp = _getScalar($m,8);
75
76                 // use '1' as $future param to make sure the date does not get erased
77                 return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 1);
78         }
79
80         // nucleus.editItem
81         $f_nucleus_editItem_sig = array(array(
82                         // return type
83                         $xmlrpcBoolean, // true or false
84
85                         // params:
86                         $xmlrpcString,  // itemid
87                         $xmlrpcString,  // username
88                         $xmlrpcString,  // password
89                         $xmlrpcString,  // title
90                         $xmlrpcString,  // body
91                         $xmlrpcString,  // extended part
92                         $xmlrpcBoolean, // publish boolean (set to false if you want a draft to stay draft)
93                         $xmlrpcBoolean, // closed boolean (set to true to disable comments)
94                 ));
95         $f_nucleus_editItem_doc = "Edits an item of a blog";
96         function f_nucleus_editItem($m) {
97                 global $manager;
98
99                 $itemid = intval(_getScalar($m,0));
100                 $username = _getScalar($m,1);
101                 $password = _getScalar($m,2);
102                 $title = _getScalar($m,3);
103                 $content = _getScalar($m,4);
104                 $more = _getScalar($m,5);
105                 $publish = _getScalar($m,6);
106                 $closed = _getScalar($m,7);
107
108                 // get old title and extended part
109                 if (!$manager->existsItem($itemid,1,1))
110                         return _error(6,"No such item ($itemid)");
111
112                 $old =& $manager->getItem($itemid,1,1);
113                 $wasdraft = ($old['draft']) ? 1 : 0;
114
115                 return _edititem($itemid, $username, $password, $old['catid'], $title, $content, $more, $wasdraft, $publish, $closed);
116         }
117
118
119         // nucleus.getUsersBlogs
120         $f_nucleus_getUsersBlogs_sig = array(array(
121                         // return type
122                         $xmlrpcArray,   // array containing structs containing blog info
123
124                         // params:
125                         $xmlrpcString,  // username
126                         $xmlrpcString,  // password
127                 ));
128         $f_nucleus_getUsersBlogs_doc = "Returns a list of all the blogs where the given member is on the team";
129         function f_nucleus_getUsersBlogs($m) {
130                 $username = _getScalar($m,0);
131                 $password = _getScalar($m,1);
132
133                 return _getUsersBlogs($username, $password);
134         }
135
136         // nucleus.getRecentItems
137         $f_nucleus_getRecentItems_sig = array(array(
138                         // return type
139                         $xmlrpcArray,   // array of strucs (representing items)
140
141                         // params
142                         $xmlrpcString,  // blogid
143                         $xmlrpcString,  // username
144                         $xmlrpcString,  // password
145                         $xmlrpcInt,     // amount of items to return (max = 20)
146                 ));
147         $f_nucleus_getRecentItems_doc = "Returns a maximum of 20 recent items for a given webblog";
148         function f_nucleus_getRecentItems($m) {
149                 $blogid = _getScalar($m, 0);
150                 $username = _getScalar($m, 1);
151                 $password = _getScalar($m, 2);
152                 $amount = _getScalar($m, 3);
153
154                 return _getRecentItems($blogid, $username, $password, $amount);
155         }
156
157         // nucleus.getItem
158         $f_nucleus_getItem_sig = array(array(
159                         // return type
160                         $xmlrpcStruct,  // A struct representing the item
161
162                         // params
163                         $xmlrpcString,  // itemid
164                         $xmlrpcString,  // username
165                         $xmlrpcString,  // password
166                 ));
167         $f_nucleus_getItem_doc = "Returns an item";
168         function f_nucleus_getItem($m) {
169                 $postid = _getScalar($m, 0);
170                 $username = _getScalar($m, 1);
171                 $password = _getScalar($m, 2);
172
173                 return _getItem($postid, $username, $password);
174         }
175
176         // nucleus.deleteItem
177         $f_nucleus_deleteItem_sig = array(array(
178                         // return type
179                         $xmlrpcBoolean, // boolean (ok or not ok)
180
181                         // params
182                         $xmlrpcString,  // itemid
183                         $xmlrpcString,  // username
184                         $xmlrpcString,  // password
185                 ));
186         $f_nucleus_deleteItem_doc = "Deletes an item";
187         function f_nucleus_deleteItem($m) {
188                 $itemid = _getScalar($m,0);
189                 $username = _getScalar($m, 1);
190                 $password = _getScalar($m, 2);
191
192                 return _deleteItem($itemid, $username, $password);
193         }
194
195
196         /**
197           * Returns a list of recent items (Nucleus Version)
198           * ($amount = max 20);
199           */
200         function _getRecentItems($blogid, $username, $password, $amount) {
201                 $blogid = intval($blogid);
202                 $amount = intval($amount);
203
204                 // 1. login
205                 $mem = new MEMBER();
206                 if (!$mem->login($username, $password))
207                         return _error(1,"Could not log in");
208
209                 // 2. check if allowed
210                 if (!BLOG::existsID($blogid))
211                         return _error(2,"No such blog ($blogid)");
212                 if (!$mem->teamRights($blogid))
213                         return _error(3,"Not a team member");
214                 $amount = intval($amount);
215                 if (($amount < 1) or ($amount > 20))
216                         return _error(5,"Amount parameter must be in range 1..20");
217
218                 // 3. create and return list of recent items
219                 // Struct returned has dateCreated, userid, blogid and content
220
221                 $structarray = array();         // the array in which the structs will be stored
222
223                 $query = "SELECT ibody, iauthor, ibody, imore, ititle, iclosed, idraft, itime"
224                            .' FROM '.sql_table('item')
225                            ." WHERE iblog=$blogid"
226                            ." ORDER BY itime DESC"
227                            ." LIMIT $amount";
228                 $r = sql_query($query);
229                 while ($obj = sql_fetch_object($r)) {
230                         $newstruct = new xmlrpcval(array(
231                                 "publishDate" => new xmlrpcval(iso8601_encode(strtotime($obj->itime)),"dateTime.iso8601"),
232                                 "userid" => new xmlrpcval($obj->iauthor,"string"),
233                                 "blogid" => new xmlrpcval($blogid,"string"),
234                                 "title" => new xmlrpcval($obj->ititle,"string"),
235                                 "body" => new xmlrpcval($obj->ibody,"string"),
236                                 "more" => new xmlrpcval($obj->imore,"string"),
237                                 "draft" => new xmlrpcval($obj->idraft,"boolean"),
238                                 "closed" => new xmlrpcval($obj->iclosed,"boolean"),
239                         ),'struct');
240                         array_push($structarray, $newstruct);
241                 }
242
243                 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
244
245         }
246
247
248
249         /**
250           * Returns one item (Nucleus version)
251           */
252         function _getItem($itemid, $username, $password) {
253                 global $manager;
254
255                 // 1. login
256                 $mem = new MEMBER();
257                 if (!$mem->login($username, $password))
258                         return _error(1,"Could not log in");
259
260                 // 2. check if allowed
261                 if (!$manager->existsItem($itemid,1,1))
262                         return _error(6,"No such item ($itemid)");
263                 $blogid = getBlogIDFromItemID($itemid);
264
265                 if (!$mem->teamRights($blogid))
266                         return _error(3,"Not a team member");
267
268                 // 3. return the item
269                 // Structure returned has dateCreated, userid, blogid and content
270
271                 $item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
272
273                 $blog = new BLOG($blogid);
274                 if ($blog->convertBreaks())
275                         $item['body'] = removeBreaks($item['body']);
276
277                 $newstruct = new xmlrpcval(array(
278                         "publishDate" => new xmlrpcval(iso8601_encode($item['timestamp']),"dateTime.iso8601"),
279                         "userid" => new xmlrpcval($item['authorid'],"string"),
280                         "blogid" => new xmlrpcval($blogid,"string"),
281                         "title" => new xmlrpcval($item['title'],"string"),
282                         "body" => new xmlrpcval($item['body'],"string"),
283                         "more" => new xmlrpcval($item['more'],"string"),
284                         "draft" => new xmlrpcval($item['draft'],"boolean"),
285                         "closed" => new xmlrpcval($item['closed'],"boolean"),
286                 ),'struct');
287
288                 return new xmlrpcresp($newstruct);
289
290
291         }
292
293
294         $functionDefs = array_merge($functionDefs,
295                 array(
296                         "nucleus.addItem" =>
297                         array( "function" => "f_nucleus_addItem",
298                                 "signature" => $f_nucleus_addItem_sig,
299                                 "docstring" => $f_nucleus_addItem_doc),
300
301                         "nucleus.editItem" =>
302                         array( "function" => "f_nucleus_editItem",
303                                 "signature" => $f_nucleus_editItem_sig,
304                                 "docstring" => $f_nucleus_editItem_doc),
305
306                         "nucleus.addDatedItem" =>
307                         array( "function" => "f_nucleus_addDatedItem",
308                                 "signature" => $f_nucleus_addDatedItem_sig,
309                                 "docstring" => $f_nucleus_addDatedItem_doc),
310
311                         "nucleus.deleteItem" =>
312                         array( "function" => "f_nucleus_deleteItem",
313                                 "signature" => $f_nucleus_deleteItem_sig,
314                                 "docstring" => $f_nucleus_deleteItem_doc),
315
316                         "nucleus.getUsersBlogs" =>
317                         array( "function" => "f_nucleus_getUsersBlogs",
318                                 "signature" => $f_nucleus_getUsersBlogs_sig,
319                                 "docstring" => $f_nucleus_getUsersBlogs_doc),
320
321                         "nucleus.getRecentItems" =>
322                         array( "function" => "f_nucleus_getRecentItems",
323                                 "signature" => $f_nucleus_getRecentItems_sig,
324                                 "docstring" => $f_nucleus_getRecentItems_doc),
325
326                         "nucleus.getItem" =>
327                         array( "function" => "f_nucleus_getItem",
328                                 "signature" => $f_nucleus_getItem_sig,
329                                 "docstring" => $f_nucleus_getItem_doc)
330                 )
331
332         );
333
334 ?>