3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2010 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 methods in the Blogger API
16 * @license http://nucleuscms.org/license.txt GNU General Public License
17 * @copyright Copyright (C) 2002-2010 The Nucleus Group
19 * $NucleusJP: api_blogger.inc.php,v 1.5 2006/07/17 20:03:45 kimitake Exp $
24 $f_blogger_newPost_sig = array(array(
26 $xmlrpcString, // itemid of the new item
29 $xmlrpcString, // appkey (ignored)
30 $xmlrpcString, // blogid
31 $xmlrpcString, // username
32 $xmlrpcString, // password
33 $xmlrpcString, // content
34 $xmlrpcBoolean, // publish boolean (set to false to create draft)
37 $f_blogger_newPost_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false";
38 function f_blogger_newPost($m) {
39 $blogid = _getScalar($m,1);
40 $username = _getScalar($m,2);
41 $password = _getScalar($m,3);
42 $content = _getScalar($m,4);
43 $publish = _getScalar($m,5);
45 $title = blogger_extractTitle($content);
46 $category = blogger_extractCategory($content);
47 $content = blogger_removeSpecialTags($content);
49 return _addItem($blogid, $username, $password, $title, $content, '', $publish, 0, $category);
53 $f_blogger_editPost_sig = array(array(
55 $xmlrpcBoolean, // true or false
58 $xmlrpcString, // appkey (ignored)
59 $xmlrpcString, // postid
60 $xmlrpcString, // username
61 $xmlrpcString, // password
62 $xmlrpcString, // content
63 $xmlrpcBoolean, // publish boolean (only considered when dealing with a draft)
66 $f_blogger_editPost_doc = "Edits an item of a blog";
67 function f_blogger_editPost($m) {
70 $itemid = intval(_getScalar($m,1));
71 $username = _getScalar($m,2);
72 $password = _getScalar($m,3);
73 $content = _getScalar($m,4);
74 $publish = _getScalar($m,5);
76 $title = blogger_extractTitle($content);
77 $category = blogger_extractCategory($content);
78 $content = blogger_removeSpecialTags($content);
80 // get old title and extended part
81 if (!$manager->existsItem($itemid,1,1))
82 return _error(6,"No such item ($itemid)");
83 $old =& $manager->getItem($itemid,1,1);
85 $blogid = getBlogIDFromItemID($itemid);
87 $blog = new BLOG($blogid);
88 $catid = $blog->getCategoryIdFromName($category);
90 if ($old['draft'] && $publish) {
97 return _edititem($itemid, $username, $password, $catid, $title, $content, $old['more'], $wasdraft, $publish, $old['closed']);
101 // blogger.getUsersBlogs
102 $f_blogger_getUsersBlogs_sig = array(array(
104 $xmlrpcArray, // array containing structs containing blog info
107 $xmlrpcString, // appkey (ignored)
108 $xmlrpcString, // username
109 $xmlrpcString, // password
111 $f_blogger_getUsersBlogs_doc = "Returns a list of all the blogs where the given member is on the team";
112 function f_blogger_getUsersBlogs($m) {
113 $username = _getScalar($m,1);
114 $password = _getScalar($m,2);
116 return _getUsersBlogs($username, $password);
119 // blogger.getRecentPosts
120 $f_blogger_getRecentPosts_sig = array(array(
122 $xmlrpcArray, // array of strucs (representing items)
125 $xmlrpcString, // appkey (ignored)
126 $xmlrpcString, // blogid
127 $xmlrpcString, // username
128 $xmlrpcString, // password
129 $xmlrpcInt, // amount of items to return (max = 20)
131 $f_blogger_getRecentPosts_doc = "Returns a maximum of 20 recent items";
132 function f_blogger_getRecentPosts($m) {
133 $blogid = _getScalar($m, 1);
134 $username = _getScalar($m, 2);
135 $password = _getScalar($m, 3);
136 $amount = _getScalar($m, 4);
138 return _getRecentItemsBlogger($blogid, $username, $password, $amount);
143 $f_blogger_getPost_sig = array(array(
145 $xmlrpcStruct, // A struct representing the item
148 $xmlrpcString, // appkey (ignored)
149 $xmlrpcString, // postid
150 $xmlrpcString, // username
151 $xmlrpcString, // password
153 $f_blogger_getPost_doc = "Returns an item (only the item body!)";
154 function f_blogger_getPost($m) {
155 $postid = _getScalar($m, 1);
156 $username = _getScalar($m, 2);
157 $password = _getScalar($m, 3);
159 return _getItemBlogger($postid, $username, $password);
163 // blogger.deletePost
164 $f_blogger_deletePost_sig = array(array(
166 $xmlrpcBoolean, // boolean (ok or not ok)
169 $xmlrpcString, // appkey (ignored)
170 $xmlrpcString, // postid
171 $xmlrpcString, // username
172 $xmlrpcString, // password
173 $xmlrpcBoolean, // publish (ignored)
175 $f_blogger_deletePost_doc = "Deletes an item";
176 function f_blogger_deletePost($m) {
177 $postid = _getScalar($m,1);
178 $username = _getScalar($m, 2);
179 $password = _getScalar($m, 3);
181 return _deleteItem($postid, $username, $password);
184 // blogger.getTemplate
185 $f_blogger_getTemplate_sig = array(array(
187 $xmlrpcString, // the template
190 $xmlrpcString, // appkey (ignored)
191 $xmlrpcString, // blogid
192 $xmlrpcString, // username
193 $xmlrpcString, // password
194 $xmlrpcString, // type of template (main/archiveIndex)
196 $f_blogger_getTemplate_doc = "Returns the required part of the default skin for the given blog";
197 function f_blogger_getTemplate($m) {
198 $blogid = _getScalar($m,1);
199 $username = _getScalar($m,2);
200 $password = _getScalar($m,3);
201 $type = _getScalar($m,4);
208 $type = "archivelist";
212 return _getSkinPart($blogid, $username, $password, $type);
215 // blogger.setTemplate
216 $f_blogger_setTemplate_sig = array(array(
218 $xmlrpcBoolean, // OK or not OK
221 $xmlrpcString, // appkey (ignored)
222 $xmlrpcString, // blogid
223 $xmlrpcString, // username
224 $xmlrpcString, // password
225 $xmlrpcString, // template contents
226 $xmlrpcString, // type of template (main/archiveIndex)
228 $f_blogger_setTemplate_doc = "Changes a part of the default skin for the selected blog";
229 function f_blogger_setTemplate($m) {
230 $blogid = _getScalar($m,1);
231 $username = _getScalar($m,2);
232 $password = _getScalar($m,3);
233 $content = _getScalar($m,4);
234 $type = _getScalar($m,5);
241 $type = "archivelist";
245 return _setSkinPart($blogid, $username, $password, $content, $type);
248 // blogger.getUserInfo
249 $f_blogger_getUserInfo_sig = array(array(
251 $xmlrpcStruct, // Struct
254 $xmlrpcString, // appkey (ignored)
255 $xmlrpcString, // username
256 $xmlrpcString, // password
258 $f_blogger_getUserInfo_doc = "Returns info on the user";
259 function f_blogger_getUserInfo($m) {
260 $username = _getScalar($m,1);
261 $password = _getScalar($m,2);
263 return _getUserInfo($username, $password);
268 * Returns a list of recent items
270 function _getRecentItemsBlogger($blogid, $username, $password, $amount) {
272 $blogid = intval($blogid);
273 $amount = intval($amount);
277 if (!$mem->login($username, $password))
278 return _error(1,"Could not log in");
280 // 2. check if allowed
281 if (!BLOG::existsID($blogid))
282 return _error(2,"No such blog ($blogid)");
283 if (!$mem->teamRights($blogid))
284 return _error(3,"Not a team member");
285 $amount = intval($amount);
286 if (($amount < 1) or ($amount > 20))
287 return _error(5,"Amount parameter must be in range 1..20");
289 // 3. create and return list of recent items
290 // Struct returned has dateCreated, userid, blogid and content
292 $blog = new BLOG($blogid);
294 $structarray = array(); // the array in which the structs will be stored
296 $query = "SELECT mname, ibody, iauthor, ibody, inumber, ititle as title, itime, cname as category"
297 .' FROM '.sql_table('item').', '.sql_table('category').', '.sql_table('member')
298 ." WHERE iblog=$blogid and icat=catid and iauthor=mnumber"
299 ." ORDER BY itime DESC"
301 $r = sql_query($query);
303 while ($row = sql_fetch_assoc($r)) {
305 // remove linebreaks if needed
306 if ($blog->convertBreaks())
307 $row['ibody'] = removeBreaks($row['ibody']);
309 $content = blogger_specialTags($row) . $row['ibody'];
311 $newstruct = new xmlrpcval(array(
312 "userid" => new xmlrpcval($row['iauthor'],"string"),
313 "dateCreated" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"),
314 "blogid" => new xmlrpcval($blogid,"string"),
315 "content" => new xmlrpcval($content,"string"),
316 "postid" => new xmlrpcval($row['inumber'],"string"),
317 "authorName" => new xmlrpcval($row['mname'],'string'),
318 "title" => new xmlrpcval($row['title'],'string'),
320 array_push($structarray, $newstruct);
323 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
328 * Returns one item (Blogger version)
330 function _getItemBlogger($itemid, $username, $password) {
335 if (!$mem->login($username, $password))
336 return _error(1,"Could not log in");
338 // 2. check if allowed
339 if (!$manager->existsItem($itemid,1,1))
340 return _error(6,"No such item ($itemid)");
341 $blogid = getBlogIDFromItemID($itemid);
342 if (!$mem->teamRights($blogid))
343 return _error(3,"Not a team member");
345 // 3. return the item
346 // Structure returned has dateCreated, userid, blogid and content
348 $item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
349 $blog = new BLOG($blogid);
352 $item['category'] = $blog->getCategoryName($item['catid']);
354 // remove linebreaks if needed
355 if ($blog->convertBreaks())
356 $item['body'] = removeBreaks($item['body']);
358 $content = blogger_specialTags($item) . $item['body'];
360 $newstruct = new xmlrpcval(array(
361 "dateCreated" => new xmlrpcval(iso8601_encode($item['timestamp']),"dateTime.iso8601"),
362 "userid" => new xmlrpcval($item['authorid'],"string"),
363 "blogid" => new xmlrpcval($blogid,"string"),
364 "content" => new xmlrpcval($content,"string")
367 return new xmlrpcresp($newstruct);
373 function blogger_extractTitle($body) {
374 return blogger_matchTag('title',$body);
377 function blogger_extractCategory($body) {
378 return blogger_matchTag('category',$body);
381 function blogger_matchTag($tag, $body) {
382 if (preg_match("/<" . $tag .">(.+?)<\/".$tag.">/is",$body,$match))
388 function blogger_removeSpecialTags($body) {
389 $body = preg_replace("/<title>(.+?)<\/title>/","",$body);
390 $body = preg_replace("/<category>(.+?)<\/category>/","",$body);
394 function blogger_specialTags($item) {
395 $result = "<title>". $item['title']."</title>";
396 $result .= "<category>".$item['category']."</category>";
402 $functionDefs = array_merge($functionDefs,
404 "blogger.getUsersBlogs" =>
405 array( "function" => "f_blogger_getUsersBlogs",
406 "signature" => $f_blogger_getUsersBlogs_sig,
407 "docstring" => $f_blogger_getUsersBlogs_doc),
410 array( "function" => "f_blogger_newPost",
411 "signature" => $f_blogger_newPost_sig,
412 "docstring" => $f_blogger_newPost_doc),
414 "blogger.editPost" =>
415 array( "function" => "f_blogger_editPost",
416 "signature" => $f_blogger_editPost_sig,
417 "docstring" => $f_blogger_editPost_doc),
419 "blogger.deletePost" =>
420 array( "function" => "f_blogger_deletePost",
421 "signature" => $f_blogger_deletePost_sig,
422 "docstring" => $f_blogger_deletePost_doc),
425 array( "function" => "f_blogger_getPost",
426 "signature" => $f_blogger_getPost_sig,
427 "docstring" => $f_blogger_getPost_doc),
429 "blogger.getRecentPosts" =>
430 array( "function" => "f_blogger_getRecentPosts",
431 "signature" => $f_blogger_getRecentPosts_sig,
432 "docstring" => $f_blogger_getRecentPosts_doc),
434 "blogger.getUserInfo" =>
435 array( "function" => "f_blogger_getUserInfo",
436 "signature" => $f_blogger_getUserInfo_sig,
437 "docstring" => $f_blogger_getUserInfo_doc),
439 "blogger.getTemplate" =>
440 array( "function" => "f_blogger_getTemplate",
441 "signature" => $f_blogger_getTemplate_sig,
442 "docstring" => $f_blogger_getTemplate_doc),
444 "blogger.setTemplate" =>
445 array( "function" => "f_blogger_setTemplate",
446 "signature" => $f_blogger_setTemplate_sig,
447 "docstring" => $f_blogger_setTemplate_doc)