3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2009 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-2009 The Nucleus Group
18 * @version $Id: api_blogger.inc.php 1388 2009-07-18 06:31:28Z shizuki $
23 $f_blogger_newPost_sig = array(array(
25 $xmlrpcString, // itemid of the new item
28 $xmlrpcString, // appkey (ignored)
29 $xmlrpcString, // blogid
30 $xmlrpcString, // username
31 $xmlrpcString, // password
32 $xmlrpcString, // content
33 $xmlrpcBoolean, // publish boolean (set to false to create draft)
36 $f_blogger_newPost_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false";
37 function f_blogger_newPost($m) {
38 $blogid = _getScalar($m,1);
39 $username = _getScalar($m,2);
40 $password = _getScalar($m,3);
41 $content = _getScalar($m,4);
42 $publish = _getScalar($m,5);
44 $title = blogger_extractTitle($content);
45 $category = blogger_extractCategory($content);
46 $content = blogger_removeSpecialTags($content);
48 return _addItem($blogid, $username, $password, $title, $content, '', $publish, 0, $category);
52 $f_blogger_editPost_sig = array(array(
54 $xmlrpcBoolean, // true or false
57 $xmlrpcString, // appkey (ignored)
58 $xmlrpcString, // postid
59 $xmlrpcString, // username
60 $xmlrpcString, // password
61 $xmlrpcString, // content
62 $xmlrpcBoolean, // publish boolean (only considered when dealing with a draft)
65 $f_blogger_editPost_doc = "Edits an item of a blog";
66 function f_blogger_editPost($m) {
69 $itemid = intval(_getScalar($m,1));
70 $username = _getScalar($m,2);
71 $password = _getScalar($m,3);
72 $content = _getScalar($m,4);
73 $publish = _getScalar($m,5);
75 $title = blogger_extractTitle($content);
76 $category = blogger_extractCategory($content);
77 $content = blogger_removeSpecialTags($content);
79 // get old title and extended part
80 if (!$manager->existsItem($itemid,1,1))
81 return _error(6,"No such item ($itemid)");
82 $old =& $manager->getItem($itemid,1,1);
84 $blogid = getBlogIDFromItemID($itemid);
86 $blog = new BLOG($blogid);
87 $catid = $blog->getCategoryIdFromName($category);
89 if ($old['draft'] && $publish) {
96 return _edititem($itemid, $username, $password, $catid, $title, $content, $old['more'], $wasdraft, $publish, $old['closed']);
100 // blogger.getUsersBlogs
101 $f_blogger_getUsersBlogs_sig = array(array(
103 $xmlrpcArray, // array containing structs containing blog info
106 $xmlrpcString, // appkey (ignored)
107 $xmlrpcString, // username
108 $xmlrpcString, // password
110 $f_blogger_getUsersBlogs_doc = "Returns a list of all the blogs where the given member is on the team";
111 function f_blogger_getUsersBlogs($m) {
112 $username = _getScalar($m,1);
113 $password = _getScalar($m,2);
115 return _getUsersBlogs($username, $password);
118 // blogger.getRecentPosts
119 $f_blogger_getRecentPosts_sig = array(array(
121 $xmlrpcArray, // array of strucs (representing items)
124 $xmlrpcString, // appkey (ignored)
125 $xmlrpcString, // blogid
126 $xmlrpcString, // username
127 $xmlrpcString, // password
128 $xmlrpcInt, // amount of items to return (max = 20)
130 $f_blogger_getRecentPosts_doc = "Returns a maximum of 20 recent items";
131 function f_blogger_getRecentPosts($m) {
132 $blogid = _getScalar($m, 1);
133 $username = _getScalar($m, 2);
134 $password = _getScalar($m, 3);
135 $amount = _getScalar($m, 4);
137 return _getRecentItemsBlogger($blogid, $username, $password, $amount);
142 $f_blogger_getPost_sig = array(array(
144 $xmlrpcStruct, // A struct representing the item
147 $xmlrpcString, // appkey (ignored)
148 $xmlrpcString, // postid
149 $xmlrpcString, // username
150 $xmlrpcString, // password
152 $f_blogger_getPost_doc = "Returns an item (only the item body!)";
153 function f_blogger_getPost($m) {
154 $postid = _getScalar($m, 1);
155 $username = _getScalar($m, 2);
156 $password = _getScalar($m, 3);
158 return _getItemBlogger($postid, $username, $password);
162 // blogger.deletePost
163 $f_blogger_deletePost_sig = array(array(
165 $xmlrpcBoolean, // boolean (ok or not ok)
168 $xmlrpcString, // appkey (ignored)
169 $xmlrpcString, // postid
170 $xmlrpcString, // username
171 $xmlrpcString, // password
172 $xmlrpcBoolean, // publish (ignored)
174 $f_blogger_deletePost_doc = "Deletes an item";
175 function f_blogger_deletePost($m) {
176 $postid = _getScalar($m,1);
177 $username = _getScalar($m, 2);
178 $password = _getScalar($m, 3);
180 return _deleteItem($postid, $username, $password);
183 // blogger.getTemplate
184 $f_blogger_getTemplate_sig = array(array(
186 $xmlrpcString, // the template
189 $xmlrpcString, // appkey (ignored)
190 $xmlrpcString, // blogid
191 $xmlrpcString, // username
192 $xmlrpcString, // password
193 $xmlrpcString, // type of template (main/archiveIndex)
195 $f_blogger_getTemplate_doc = "Returns the required part of the default skin for the given blog";
196 function f_blogger_getTemplate($m) {
197 $blogid = _getScalar($m,1);
198 $username = _getScalar($m,2);
199 $password = _getScalar($m,3);
200 $type = _getScalar($m,4);
207 $type = "archivelist";
211 return _getSkinPart($blogid, $username, $password, $type);
214 // blogger.setTemplate
215 $f_blogger_setTemplate_sig = array(array(
217 $xmlrpcBoolean, // OK or not OK
220 $xmlrpcString, // appkey (ignored)
221 $xmlrpcString, // blogid
222 $xmlrpcString, // username
223 $xmlrpcString, // password
224 $xmlrpcString, // template contents
225 $xmlrpcString, // type of template (main/archiveIndex)
227 $f_blogger_setTemplate_doc = "Changes a part of the default skin for the selected blog";
228 function f_blogger_setTemplate($m) {
229 $blogid = _getScalar($m,1);
230 $username = _getScalar($m,2);
231 $password = _getScalar($m,3);
232 $content = _getScalar($m,4);
233 $type = _getScalar($m,5);
240 $type = "archivelist";
244 return _setSkinPart($blogid, $username, $password, $content, $type);
247 // blogger.getUserInfo
248 $f_blogger_getUserInfo_sig = array(array(
250 $xmlrpcStruct, // Struct
253 $xmlrpcString, // appkey (ignored)
254 $xmlrpcString, // username
255 $xmlrpcString, // password
257 $f_blogger_getUserInfo_doc = "Returns info on the user";
258 function f_blogger_getUserInfo($m) {
259 $username = _getScalar($m,1);
260 $password = _getScalar($m,2);
262 return _getUserInfo($username, $password);
267 * Returns a list of recent items
269 function _getRecentItemsBlogger($blogid, $username, $password, $amount) {
271 $blogid = intval($blogid);
272 $amount = intval($amount);
276 if (!$mem->login($username, $password))
277 return _error(1,"Could not log in");
279 // 2. check if allowed
280 if (!BLOG::existsID($blogid))
281 return _error(2,"No such blog ($blogid)");
282 if (!$mem->teamRights($blogid))
283 return _error(3,"Not a team member");
284 $amount = intval($amount);
285 if (($amount < 1) or ($amount > 20))
286 return _error(5,"Amount parameter must be in range 1..20");
288 // 3. create and return list of recent items
289 // Struct returned has dateCreated, userid, blogid and content
291 $blog = new BLOG($blogid);
293 $structarray = array(); // the array in which the structs will be stored
295 $query = "SELECT mname, ibody, iauthor, ibody, inumber, ititle as title, itime, cname as category"
296 .' FROM '.sql_table('item').', '.sql_table('category').', '.sql_table('member')
297 ." WHERE iblog=$blogid and icat=catid and iauthor=mnumber"
298 ." ORDER BY itime DESC"
300 $r = sql_query($query);
302 while ($row = sql_fetch_assoc($r)) {
304 // remove linebreaks if needed
305 if ($blog->convertBreaks())
306 $row['ibody'] = removeBreaks($row['ibody']);
308 $content = blogger_specialTags($row) . $row['ibody'];
310 $newstruct = new xmlrpcval(array(
311 "userid" => new xmlrpcval($row['iauthor'],"string"),
312 "dateCreated" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"),
313 "blogid" => new xmlrpcval($blogid,"string"),
314 "content" => new xmlrpcval($content,"string"),
315 "postid" => new xmlrpcval($row['inumber'],"string"),
316 "authorName" => new xmlrpcval($row['mname'],'string'),
317 "title" => new xmlrpcval($row['title'],'string'),
319 array_push($structarray, $newstruct);
322 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
327 * Returns one item (Blogger version)
329 function _getItemBlogger($itemid, $username, $password) {
334 if (!$mem->login($username, $password))
335 return _error(1,"Could not log in");
337 // 2. check if allowed
338 if (!$manager->existsItem($itemid,1,1))
339 return _error(6,"No such item ($itemid)");
340 $blogid = getBlogIDFromItemID($itemid);
341 if (!$mem->teamRights($blogid))
342 return _error(3,"Not a team member");
344 // 3. return the item
345 // Structure returned has dateCreated, userid, blogid and content
347 $item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
348 $blog = new BLOG($blogid);
351 $item['category'] = $blog->getCategoryName($item['catid']);
353 // remove linebreaks if needed
354 if ($blog->convertBreaks())
355 $item['body'] = removeBreaks($item['body']);
357 $content = blogger_specialTags($item) . $item['body'];
359 $newstruct = new xmlrpcval(array(
360 "dateCreated" => new xmlrpcval(iso8601_encode($item['timestamp']),"dateTime.iso8601"),
361 "userid" => new xmlrpcval($item['authorid'],"string"),
362 "blogid" => new xmlrpcval($blogid,"string"),
363 "content" => new xmlrpcval($content,"string")
366 return new xmlrpcresp($newstruct);
372 function blogger_extractTitle($body) {
373 return blogger_matchTag('title',$body);
376 function blogger_extractCategory($body) {
377 return blogger_matchTag('category',$body);
380 function blogger_matchTag($tag, $body) {
381 if (preg_match("/<" . $tag .">(.+?)<\/".$tag.">/is",$body,$match))
387 function blogger_removeSpecialTags($body) {
388 $body = preg_replace("/<title>(.+?)<\/title>/","",$body);
389 $body = preg_replace("/<category>(.+?)<\/category>/","",$body);
393 function blogger_specialTags($item) {
394 $result = "<title>". $item['title']."</title>";
395 $result .= "<category>".$item['category']."</category>";
401 $functionDefs = array_merge($functionDefs,
403 "blogger.getUsersBlogs" =>
404 array( "function" => "f_blogger_getUsersBlogs",
405 "signature" => $f_blogger_getUsersBlogs_sig,
406 "docstring" => $f_blogger_getUsersBlogs_doc),
409 array( "function" => "f_blogger_newPost",
410 "signature" => $f_blogger_newPost_sig,
411 "docstring" => $f_blogger_newPost_doc),
413 "blogger.editPost" =>
414 array( "function" => "f_blogger_editPost",
415 "signature" => $f_blogger_editPost_sig,
416 "docstring" => $f_blogger_editPost_doc),
418 "blogger.deletePost" =>
419 array( "function" => "f_blogger_deletePost",
420 "signature" => $f_blogger_deletePost_sig,
421 "docstring" => $f_blogger_deletePost_doc),
424 array( "function" => "f_blogger_getPost",
425 "signature" => $f_blogger_getPost_sig,
426 "docstring" => $f_blogger_getPost_doc),
428 "blogger.getRecentPosts" =>
429 array( "function" => "f_blogger_getRecentPosts",
430 "signature" => $f_blogger_getRecentPosts_sig,
431 "docstring" => $f_blogger_getRecentPosts_doc),
433 "blogger.getUserInfo" =>
434 array( "function" => "f_blogger_getUserInfo",
435 "signature" => $f_blogger_getUserInfo_sig,
436 "docstring" => $f_blogger_getUserInfo_doc),
438 "blogger.getTemplate" =>
439 array( "function" => "f_blogger_getTemplate",
440 "signature" => $f_blogger_getTemplate_sig,
441 "docstring" => $f_blogger_getTemplate_doc),
443 "blogger.setTemplate" =>
444 array( "function" => "f_blogger_setTemplate",
445 "signature" => $f_blogger_setTemplate_sig,
446 "docstring" => $f_blogger_setTemplate_doc)