3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2005 The Nucleus Group
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
10 * (see nucleus/documentation/index.html#license for more info)
\r
12 * $Id: api_blogger.inc.php,v 1.3 2005-03-16 08:12:06 kimitake Exp $
\r
13 * $NucleusJP: api_blogger.inc.php,v 1.3 2005/03/12 06:19:06 kimitake Exp $
\r
17 * This file contains definitions for the methods in the Blogger API
\r
22 $f_blogger_newPost_sig = array(array(
\r
24 $xmlrpcString, // itemid of the new item
\r
27 $xmlrpcString, // appkey (ignored)
\r
28 $xmlrpcString, // blogid
\r
29 $xmlrpcString, // username
\r
30 $xmlrpcString, // password
\r
31 $xmlrpcString, // content
\r
32 $xmlrpcBoolean, // publish boolean (set to false to create draft)
\r
35 $f_blogger_newPost_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false";
\r
36 function f_blogger_newPost($m) {
\r
37 $blogid = _getScalar($m,1);
\r
38 $username = _getScalar($m,2);
\r
39 $password = _getScalar($m,3);
\r
40 $content = _getScalar($m,4);
\r
41 $publish = _getScalar($m,5);
\r
43 $title = blogger_extractTitle($content);
\r
44 $category = blogger_extractCategory($content);
\r
45 $content = blogger_removeSpecialTags($content);
\r
47 return _addItem($blogid, $username, $password, $title, $content, '', $publish, 0, $category);
\r
51 $f_blogger_editPost_sig = array(array(
\r
53 $xmlrpcBoolean, // true or false
\r
56 $xmlrpcString, // appkey (ignored)
\r
57 $xmlrpcString, // postid
\r
58 $xmlrpcString, // username
\r
59 $xmlrpcString, // password
\r
60 $xmlrpcString, // content
\r
61 $xmlrpcBoolean, // publish boolean (only considered when dealing with a draft)
\r
64 $f_blogger_editPost_doc = "Edits an item of a blog";
\r
65 function f_blogger_editPost($m) {
\r
68 $itemid = intval(_getScalar($m,1));
\r
69 $username = _getScalar($m,2);
\r
70 $password = _getScalar($m,3);
\r
71 $content = _getScalar($m,4);
\r
72 $publish = _getScalar($m,5);
\r
74 $title = blogger_extractTitle($content);
\r
75 $category = blogger_extractCategory($content);
\r
76 $content = blogger_removeSpecialTags($content);
\r
78 // get old title and extended part
\r
79 if (!$manager->existsItem($itemid,1,1))
\r
80 return _error(6,"No such item ($itemid)");
\r
81 $old =& $manager->getItem($itemid,1,1);
\r
83 $blogid = getBlogIDFromItemID($itemid);
\r
85 $blog = new BLOG($blogid);
\r
86 $catid = $blog->getCategoryIdFromName($category);
\r
88 if ($old['draft'] && $publish) {
\r
95 return _edititem($itemid, $username, $password, $catid, $title, $content, $old['more'], $wasdraft, $publish, $old['closed']);
\r
99 // blogger.getUsersBlogs
\r
100 $f_blogger_getUsersBlogs_sig = array(array(
\r
102 $xmlrpcArray, // array containing structs containing blog info
\r
105 $xmlrpcString, // appkey (ignored)
\r
106 $xmlrpcString, // username
\r
107 $xmlrpcString, // password
\r
109 $f_blogger_getUsersBlogs_doc = "Returns a list of all the blogs where the given member is on the team";
\r
110 function f_blogger_getUsersBlogs($m) {
\r
111 $username = _getScalar($m,1);
\r
112 $password = _getScalar($m,2);
\r
114 return _getUsersBlogs($username, $password);
\r
117 // blogger.getRecentPosts
\r
118 $f_blogger_getRecentPosts_sig = array(array(
\r
120 $xmlrpcArray, // array of strucs (representing items)
\r
123 $xmlrpcString, // appkey (ignored)
\r
124 $xmlrpcString, // blogid
\r
125 $xmlrpcString, // username
\r
126 $xmlrpcString, // password
\r
127 $xmlrpcInt, // amount of items to return (max = 20)
\r
129 $f_blogger_getRecentPosts_doc = "Returns a maximum of 20 recent items";
\r
130 function f_blogger_getRecentPosts($m) {
\r
131 $blogid = _getScalar($m, 1);
\r
132 $username = _getScalar($m, 2);
\r
133 $password = _getScalar($m, 3);
\r
134 $amount = _getScalar($m, 4);
\r
136 return _getRecentItemsBlogger($blogid, $username, $password, $amount);
\r
141 $f_blogger_getPost_sig = array(array(
\r
143 $xmlrpcStruct, // A struct representing the item
\r
146 $xmlrpcString, // appkey (ignored)
\r
147 $xmlrpcString, // postid
\r
148 $xmlrpcString, // username
\r
149 $xmlrpcString, // password
\r
151 $f_blogger_getPost_doc = "Returns an item (only the item body!)";
\r
152 function f_blogger_getPost($m) {
\r
153 $postid = _getScalar($m, 1);
\r
154 $username = _getScalar($m, 2);
\r
155 $password = _getScalar($m, 3);
\r
157 return _getItemBlogger($postid, $username, $password);
\r
161 // blogger.deletePost
\r
162 $f_blogger_deletePost_sig = array(array(
\r
164 $xmlrpcBoolean, // boolean (ok or not ok)
\r
167 $xmlrpcString, // appkey (ignored)
\r
168 $xmlrpcString, // postid
\r
169 $xmlrpcString, // username
\r
170 $xmlrpcString, // password
\r
171 $xmlrpcBoolean, // publish (ignored)
\r
173 $f_blogger_deletePost_doc = "Deletes an item";
\r
174 function f_blogger_deletePost($m) {
\r
175 $postid = _getScalar($m,1);
\r
176 $username = _getScalar($m, 2);
\r
177 $password = _getScalar($m, 3);
\r
179 return _deleteItem($postid, $username, $password);
\r
182 // blogger.getTemplate
\r
183 $f_blogger_getTemplate_sig = array(array(
\r
185 $xmlrpcString, // the template
\r
188 $xmlrpcString, // appkey (ignored)
\r
189 $xmlrpcString, // blogid
\r
190 $xmlrpcString, // username
\r
191 $xmlrpcString, // password
\r
192 $xmlrpcString, // type of template (main/archiveIndex)
\r
194 $f_blogger_getTemplate_doc = "Returns the required part of the default skin for the given blog";
\r
195 function f_blogger_getTemplate($m) {
\r
196 $blogid = _getScalar($m,1);
\r
197 $username = _getScalar($m,2);
\r
198 $password = _getScalar($m,3);
\r
199 $type = _getScalar($m,4);
\r
205 case "archiveIndex":
\r
206 $type = "archivelist";
\r
210 return _getSkinPart($blogid, $username, $password, $type);
\r
213 // blogger.setTemplate
\r
214 $f_blogger_setTemplate_sig = array(array(
\r
216 $xmlrpcBoolean, // OK or not OK
\r
219 $xmlrpcString, // appkey (ignored)
\r
220 $xmlrpcString, // blogid
\r
221 $xmlrpcString, // username
\r
222 $xmlrpcString, // password
\r
223 $xmlrpcString, // template contents
\r
224 $xmlrpcString, // type of template (main/archiveIndex)
\r
226 $f_blogger_setTemplate_doc = "Changes a part of the default skin for the selected blog";
\r
227 function f_blogger_setTemplate($m) {
\r
228 $blogid = _getScalar($m,1);
\r
229 $username = _getScalar($m,2);
\r
230 $password = _getScalar($m,3);
\r
231 $content = _getScalar($m,4);
\r
232 $type = _getScalar($m,5);
\r
238 case "archiveIndex":
\r
239 $type = "archivelist";
\r
243 return _setSkinPart($blogid, $username, $password, $content, $type);
\r
246 // blogger.getUserInfo
\r
247 $f_blogger_getUserInfo_sig = array(array(
\r
249 $xmlrpcStruct, // Struct
\r
252 $xmlrpcString, // appkey (ignored)
\r
253 $xmlrpcString, // username
\r
254 $xmlrpcString, // password
\r
256 $f_blogger_getUserInfo_doc = "Returns info on the user";
\r
257 function f_blogger_getUserInfo($m) {
\r
258 $username = _getScalar($m,1);
\r
259 $password = _getScalar($m,2);
\r
261 return _getUserInfo($username, $password);
\r
266 * Returns a list of recent items
\r
268 function _getRecentItemsBlogger($blogid, $username, $password, $amount) {
\r
270 $blogid = intval($blogid);
\r
271 $amount = intval($amount);
\r
274 $mem = new MEMBER();
\r
275 if (!$mem->login($username, $password))
\r
276 return _error(1,"Could not log in");
\r
278 // 2. check if allowed
\r
279 if (!BLOG::existsID($blogid))
\r
280 return _error(2,"No such blog ($blogid)");
\r
281 if (!$mem->teamRights($blogid))
\r
282 return _error(3,"Not a team member");
\r
283 $amount = intval($amount);
\r
284 if (($amount < 1) or ($amount > 20))
\r
285 return _error(5,"Amount parameter must be in range 1..20");
\r
287 // 3. create and return list of recent items
\r
288 // Struct returned has dateCreated, userid, blogid and content
\r
290 $blog = new BLOG($blogid);
\r
292 $structarray = array(); // the array in which the structs will be stored
\r
294 $query = "SELECT mname, ibody, iauthor, ibody, inumber, ititle as title, itime, cname as category"
\r
295 .' FROM '.sql_table('item').', '.sql_table('category').', '.sql_table('member')
\r
296 ." WHERE iblog=$blogid and icat=catid and iauthor=mnumber"
\r
297 ." ORDER BY itime DESC"
\r
299 $r = sql_query($query);
\r
301 while ($row = mysql_fetch_assoc($r)) {
\r
303 // remove linebreaks if needed
\r
304 if ($blog->convertBreaks())
\r
305 $row['ibody'] = removeBreaks($row['ibody']);
\r
307 $content = blogger_specialTags($row) . $row['ibody'];
\r
309 $newstruct = new xmlrpcval(array(
\r
310 "userid" => new xmlrpcval($row['iauthor'],"string"),
\r
311 "dateCreated" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"),
\r
312 "blogid" => new xmlrpcval($blogid,"string"),
\r
313 "content" => new xmlrpcval($content,"string"),
\r
314 "postid" => new xmlrpcval($row['inumber'],"string"),
\r
315 "authorName" => new xmlrpcval($row['mname'],'string'),
\r
316 "title" => new xmlrpcval($row['title'],'string'),
\r
318 array_push($structarray, $newstruct);
\r
321 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
\r
326 * Returns one item (Blogger version)
\r
328 function _getItemBlogger($itemid, $username, $password) {
\r
332 $mem = new MEMBER();
\r
333 if (!$mem->login($username, $password))
\r
334 return _error(1,"Could not log in");
\r
336 // 2. check if allowed
\r
337 if (!$manager->existsItem($itemid,1,1))
\r
338 return _error(6,"No such item ($itemid)");
\r
339 $blogid = getBlogIDFromItemID($itemid);
\r
340 if (!$mem->teamRights($blogid))
\r
341 return _error(3,"Not a team member");
\r
343 // 3. return the item
\r
344 // Structure returned has dateCreated, userid, blogid and content
\r
346 $item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
\r
347 $blog = new BLOG($blogid);
\r
350 $item['category'] = $blog->getCategoryName($item['catid']);
\r
352 // remove linebreaks if needed
\r
353 if ($blog->convertBreaks())
\r
354 $item['body'] = removeBreaks($item['body']);
\r
356 $content = blogger_specialTags($item) . $item['body'];
\r
358 $newstruct = new xmlrpcval(array(
\r
359 "dateCreated" => new xmlrpcval(iso8601_encode($item['timestamp']),"dateTime.iso8601"),
\r
360 "userid" => new xmlrpcval($item['authorid'],"string"),
\r
361 "blogid" => new xmlrpcval($blogid,"string"),
\r
362 "content" => new xmlrpcval($content,"string")
\r
365 return new xmlrpcresp($newstruct);
\r
371 function blogger_extractTitle($body) {
\r
372 return blogger_matchTag('title',$body);
\r
375 function blogger_extractCategory($body) {
\r
376 return blogger_matchTag('category',$body);
\r
379 function blogger_matchTag($tag, $body) {
\r
380 if (preg_match("/<" . $tag .">(.+?)<\/".$tag.">/is",$body,$match))
\r
386 function blogger_removeSpecialTags($body) {
\r
387 $body = preg_replace("/<title>(.+?)<\/title>/","",$body);
\r
388 $body = preg_replace("/<category>(.+?)<\/category>/","",$body);
\r
389 return trim($body);
\r
392 function blogger_specialTags($item) {
\r
393 $result = "<title>". $item['title']."</title>";
\r
394 $result .= "<category>".$item['category']."</category>";
\r
400 $functionDefs = array_merge($functionDefs,
\r
402 "blogger.getUsersBlogs" =>
\r
403 array( "function" => "f_blogger_getUsersBlogs",
\r
404 "signature" => $f_blogger_getUsersBlogs_sig,
\r
405 "docstring" => $f_blogger_getUsersBlogs_doc),
\r
407 "blogger.newPost" =>
\r
408 array( "function" => "f_blogger_newPost",
\r
409 "signature" => $f_blogger_newPost_sig,
\r
410 "docstring" => $f_blogger_newPost_doc),
\r
412 "blogger.editPost" =>
\r
413 array( "function" => "f_blogger_editPost",
\r
414 "signature" => $f_blogger_editPost_sig,
\r
415 "docstring" => $f_blogger_editPost_doc),
\r
417 "blogger.deletePost" =>
\r
418 array( "function" => "f_blogger_deletePost",
\r
419 "signature" => $f_blogger_deletePost_sig,
\r
420 "docstring" => $f_blogger_deletePost_doc),
\r
422 "blogger.getPost" =>
\r
423 array( "function" => "f_blogger_getPost",
\r
424 "signature" => $f_blogger_getPost_sig,
\r
425 "docstring" => $f_blogger_getPost_doc),
\r
427 "blogger.getRecentPosts" =>
\r
428 array( "function" => "f_blogger_getRecentPosts",
\r
429 "signature" => $f_blogger_getRecentPosts_sig,
\r
430 "docstring" => $f_blogger_getRecentPosts_doc),
\r
432 "blogger.getUserInfo" =>
\r
433 array( "function" => "f_blogger_getUserInfo",
\r
434 "signature" => $f_blogger_getUserInfo_sig,
\r
435 "docstring" => $f_blogger_getUserInfo_doc),
\r
437 "blogger.getTemplate" =>
\r
438 array( "function" => "f_blogger_getTemplate",
\r
439 "signature" => $f_blogger_getTemplate_sig,
\r
440 "docstring" => $f_blogger_getTemplate_doc),
\r
442 "blogger.setTemplate" =>
\r
443 array( "function" => "f_blogger_setTemplate",
\r
444 "signature" => $f_blogger_setTemplate_sig,
\r
445 "docstring" => $f_blogger_setTemplate_doc)
\r