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 1860 2012-05-19 03:47:59Z sakamocchi $
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 =& $manager->getBlog($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) {
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 =& $manager->getBlog($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 = DB::getResult($query);
303 foreach ( $r as $row ) {
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 =& $manager->getBlog($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)