3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2012 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)
12 * This file contains definitions for the methods in the Blogger API
17 $f_blogger_newPost_sig = array(array(
19 $xmlrpcString, // itemid of the new item
22 $xmlrpcString, // appkey (ignored)
23 $xmlrpcString, // blogid
24 $xmlrpcString, // username
25 $xmlrpcString, // password
26 $xmlrpcString, // content
27 $xmlrpcBoolean, // publish boolean (set to false to create draft)
30 $f_blogger_newPost_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false";
31 function f_blogger_newPost($m) {
32 $blogid = _getScalar($m,1);
33 $username = _getScalar($m,2);
34 $password = _getScalar($m,3);
35 $content = _getScalar($m,4);
36 $publish = _getScalar($m,5);
38 $title = blogger_extractTitle($content);
39 $category = blogger_extractCategory($content);
40 $content = blogger_removeSpecialTags($content);
42 return _addItem($blogid, $username, $password, $title, $content, '', $publish, 0, $category);
46 $f_blogger_editPost_sig = array(array(
48 $xmlrpcBoolean, // true or false
51 $xmlrpcString, // appkey (ignored)
52 $xmlrpcString, // postid
53 $xmlrpcString, // username
54 $xmlrpcString, // password
55 $xmlrpcString, // content
56 $xmlrpcBoolean, // publish boolean (only considered when dealing with a draft)
59 $f_blogger_editPost_doc = "Edits an item of a blog";
60 function f_blogger_editPost($m) {
63 $itemid = intval(_getScalar($m,1));
64 $username = _getScalar($m,2);
65 $password = _getScalar($m,3);
66 $content = _getScalar($m,4);
67 $publish = _getScalar($m,5);
69 $title = blogger_extractTitle($content);
70 $category = blogger_extractCategory($content);
71 $content = blogger_removeSpecialTags($content);
73 // get old title and extended part
74 if (!$manager->existsItem($itemid,1,1))
75 return _error(6,"No such item ($itemid)");
76 $old =& $manager->getItem($itemid,1,1);
78 $blogid = getBlogIDFromItemID($itemid);
80 $blog = new BLOG($blogid);
81 $catid = $blog->getCategoryIdFromName($category);
83 if ($old['draft'] && $publish) {
90 return _edititem($itemid, $username, $password, $catid, $title, $content, $old['more'], $wasdraft, $publish, $old['closed']);
94 // blogger.getUsersBlogs
95 $f_blogger_getUsersBlogs_sig = array(array(
97 $xmlrpcArray, // array containing structs containing blog info
100 $xmlrpcString, // appkey (ignored)
101 $xmlrpcString, // username
102 $xmlrpcString, // password
104 $f_blogger_getUsersBlogs_doc = "Returns a list of all the blogs where the given member is on the team";
105 function f_blogger_getUsersBlogs($m) {
106 $username = _getScalar($m,1);
107 $password = _getScalar($m,2);
109 return _getUsersBlogs($username, $password);
112 // blogger.getRecentPosts
113 $f_blogger_getRecentPosts_sig = array(array(
115 $xmlrpcArray, // array of strucs (representing items)
118 $xmlrpcString, // appkey (ignored)
119 $xmlrpcString, // blogid
120 $xmlrpcString, // username
121 $xmlrpcString, // password
122 $xmlrpcInt, // amount of items to return (max = 20)
124 $f_blogger_getRecentPosts_doc = "Returns a maximum of 20 recent items";
125 function f_blogger_getRecentPosts($m) {
126 $blogid = _getScalar($m, 1);
127 $username = _getScalar($m, 2);
128 $password = _getScalar($m, 3);
129 $amount = _getScalar($m, 4);
131 return _getRecentItemsBlogger($blogid, $username, $password, $amount);
136 $f_blogger_getPost_sig = array(array(
138 $xmlrpcStruct, // A struct representing the item
141 $xmlrpcString, // appkey (ignored)
142 $xmlrpcString, // postid
143 $xmlrpcString, // username
144 $xmlrpcString, // password
146 $f_blogger_getPost_doc = "Returns an item (only the item body!)";
147 function f_blogger_getPost($m) {
148 $postid = _getScalar($m, 1);
149 $username = _getScalar($m, 2);
150 $password = _getScalar($m, 3);
152 return _getItemBlogger($postid, $username, $password);
156 // blogger.deletePost
157 $f_blogger_deletePost_sig = array(array(
159 $xmlrpcBoolean, // boolean (ok or not ok)
162 $xmlrpcString, // appkey (ignored)
163 $xmlrpcString, // postid
164 $xmlrpcString, // username
165 $xmlrpcString, // password
166 $xmlrpcBoolean, // publish (ignored)
168 $f_blogger_deletePost_doc = "Deletes an item";
169 function f_blogger_deletePost($m) {
170 $postid = _getScalar($m,1);
171 $username = _getScalar($m, 2);
172 $password = _getScalar($m, 3);
174 return _deleteItem($postid, $username, $password);
177 // blogger.getTemplate
178 $f_blogger_getTemplate_sig = array(array(
180 $xmlrpcString, // the template
183 $xmlrpcString, // appkey (ignored)
184 $xmlrpcString, // blogid
185 $xmlrpcString, // username
186 $xmlrpcString, // password
187 $xmlrpcString, // type of template (main/archiveIndex)
189 $f_blogger_getTemplate_doc = "Returns the required part of the default skin for the given blog";
190 function f_blogger_getTemplate($m) {
191 $blogid = _getScalar($m,1);
192 $username = _getScalar($m,2);
193 $password = _getScalar($m,3);
194 $type = _getScalar($m,4);
201 $type = "archivelist";
205 return _getSkinPart($blogid, $username, $password, $type);
208 // blogger.setTemplate
209 $f_blogger_setTemplate_sig = array(array(
211 $xmlrpcBoolean, // OK or not OK
214 $xmlrpcString, // appkey (ignored)
215 $xmlrpcString, // blogid
216 $xmlrpcString, // username
217 $xmlrpcString, // password
218 $xmlrpcString, // template contents
219 $xmlrpcString, // type of template (main/archiveIndex)
221 $f_blogger_setTemplate_doc = "Changes a part of the default skin for the selected blog";
222 function f_blogger_setTemplate($m) {
223 $blogid = _getScalar($m,1);
224 $username = _getScalar($m,2);
225 $password = _getScalar($m,3);
226 $content = _getScalar($m,4);
227 $type = _getScalar($m,5);
234 $type = "archivelist";
238 return _setSkinPart($blogid, $username, $password, $content, $type);
241 // blogger.getUserInfo
242 $f_blogger_getUserInfo_sig = array(array(
244 $xmlrpcStruct, // Struct
247 $xmlrpcString, // appkey (ignored)
248 $xmlrpcString, // username
249 $xmlrpcString, // password
251 $f_blogger_getUserInfo_doc = "Returns info on the user";
252 function f_blogger_getUserInfo($m) {
253 $username = _getScalar($m,1);
254 $password = _getScalar($m,2);
256 return _getUserInfo($username, $password);
261 * Returns a list of recent items
263 function _getRecentItemsBlogger($blogid, $username, $password, $amount) {
265 $blogid = intval($blogid);
266 $amount = intval($amount);
270 if (!$mem->login($username, $password))
271 return _error(1,"Could not log in");
273 // 2. check if allowed
274 if (!BLOG::existsID($blogid))
275 return _error(2,"No such blog ($blogid)");
276 if (!$mem->teamRights($blogid))
277 return _error(3,"Not a team member");
278 $amount = intval($amount);
279 if (($amount < 1) or ($amount > 20))
280 return _error(5,"Amount parameter must be in range 1..20");
282 // 3. create and return list of recent items
283 // Struct returned has dateCreated, userid, blogid and content
285 $blog = new BLOG($blogid);
287 $structarray = array(); // the array in which the structs will be stored
289 $query = "SELECT mname, ibody, iauthor, ibody, inumber, ititle as title, itime, cname as category"
290 .' FROM '.sql_table('item').', '.sql_table('category').', '.sql_table('member')
291 ." WHERE iblog=$blogid and icat=catid and iauthor=mnumber"
292 ." ORDER BY itime DESC"
294 $r = sql_query($query);
296 while ($row = sql_fetch_assoc($r)) {
298 // remove linebreaks if needed
299 if ($blog->convertBreaks())
300 $row['ibody'] = removeBreaks($row['ibody']);
302 $content = blogger_specialTags($row) . $row['ibody'];
304 $newstruct = new xmlrpcval(array(
305 "userid" => new xmlrpcval($row['iauthor'],"string"),
306 "dateCreated" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"),
307 "blogid" => new xmlrpcval($blogid,"string"),
308 "content" => new xmlrpcval($content,"string"),
309 "postid" => new xmlrpcval($row['inumber'],"string"),
310 "authorName" => new xmlrpcval($row['mname'],'string'),
311 "title" => new xmlrpcval($row['title'],'string'),
313 array_push($structarray, $newstruct);
316 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
321 * Returns one item (Blogger version)
323 function _getItemBlogger($itemid, $username, $password) {
328 if (!$mem->login($username, $password))
329 return _error(1,"Could not log in");
331 // 2. check if allowed
332 if (!$manager->existsItem($itemid,1,1))
333 return _error(6,"No such item ($itemid)");
334 $blogid = getBlogIDFromItemID($itemid);
335 if (!$mem->teamRights($blogid))
336 return _error(3,"Not a team member");
338 // 3. return the item
339 // Structure returned has dateCreated, userid, blogid and content
341 $item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
342 $blog = new BLOG($blogid);
345 $item['category'] = $blog->getCategoryName($item['catid']);
347 // remove linebreaks if needed
348 if ($blog->convertBreaks())
349 $item['body'] = removeBreaks($item['body']);
351 $content = blogger_specialTags($item) . $item['body'];
353 $newstruct = new xmlrpcval(array(
354 "dateCreated" => new xmlrpcval(iso8601_encode($item['timestamp']),"dateTime.iso8601"),
355 "userid" => new xmlrpcval($item['authorid'],"string"),
356 "blogid" => new xmlrpcval($blogid,"string"),
357 "content" => new xmlrpcval($content,"string")
360 return new xmlrpcresp($newstruct);
366 function blogger_extractTitle($body) {
367 return blogger_matchTag('title',$body);
370 function blogger_extractCategory($body) {
371 return blogger_matchTag('category',$body);
374 function blogger_matchTag($tag, $body) {
375 if (preg_match("/<" . $tag .">(.+?)<\/".$tag.">/is",$body,$match))
381 function blogger_removeSpecialTags($body) {
382 $body = preg_replace("/<title>(.+?)<\/title>/","",$body);
383 $body = preg_replace("/<category>(.+?)<\/category>/","",$body);
387 function blogger_specialTags($item) {
388 $result = "<title>". $item['title']."</title>";
389 $result .= "<category>".$item['category']."</category>";
395 $functionDefs = array_merge($functionDefs,
397 "blogger.getUsersBlogs" =>
398 array( "function" => "f_blogger_getUsersBlogs",
399 "signature" => $f_blogger_getUsersBlogs_sig,
400 "docstring" => $f_blogger_getUsersBlogs_doc),
403 array( "function" => "f_blogger_newPost",
404 "signature" => $f_blogger_newPost_sig,
405 "docstring" => $f_blogger_newPost_doc),
407 "blogger.editPost" =>
408 array( "function" => "f_blogger_editPost",
409 "signature" => $f_blogger_editPost_sig,
410 "docstring" => $f_blogger_editPost_doc),
412 "blogger.deletePost" =>
413 array( "function" => "f_blogger_deletePost",
414 "signature" => $f_blogger_deletePost_sig,
415 "docstring" => $f_blogger_deletePost_doc),
418 array( "function" => "f_blogger_getPost",
419 "signature" => $f_blogger_getPost_sig,
420 "docstring" => $f_blogger_getPost_doc),
422 "blogger.getRecentPosts" =>
423 array( "function" => "f_blogger_getRecentPosts",
424 "signature" => $f_blogger_getRecentPosts_sig,
425 "docstring" => $f_blogger_getRecentPosts_doc),
427 "blogger.getUserInfo" =>
428 array( "function" => "f_blogger_getUserInfo",
429 "signature" => $f_blogger_getUserInfo_sig,
430 "docstring" => $f_blogger_getUserInfo_doc),
432 "blogger.getTemplate" =>
433 array( "function" => "f_blogger_getTemplate",
434 "signature" => $f_blogger_getTemplate_sig,
435 "docstring" => $f_blogger_getTemplate_doc),
437 "blogger.setTemplate" =>
438 array( "function" => "f_blogger_setTemplate",
439 "signature" => $f_blogger_setTemplate_sig,
440 "docstring" => $f_blogger_setTemplate_doc)