api_nucleus.inc.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
00004  * Copyright (C) 2002-2007 The Nucleus Group
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * (see nucleus/documentation/index.html#license for more info)
00011  */
00012 
00024         // nucleus.addItem
00025         $f_nucleus_addItem_sig = array(array(
00026                         // return type
00027                         $xmlrpcString,  // itemid of the new item
00028 
00029                         // params:
00030                         $xmlrpcString,  // blogid
00031                         $xmlrpcString,  // username
00032                         $xmlrpcString,  // password
00033                         $xmlrpcString,  // title
00034                         $xmlrpcString,  // body
00035                         $xmlrpcString,  // extended part
00036                         $xmlrpcBoolean, // publish boolean (set to false to create draft)
00037                         $xmlrpcBoolean, // closed boolean (set to true to disable comments)
00038 
00039                 ));
00040         $f_nucleus_addItem_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false";
00041         function f_nucleus_addItem($m) {
00042                 $blogid = _getScalar($m,0);
00043                 $username = _getScalar($m,1);
00044                 $password = _getScalar($m,2);
00045                 $title = _getScalar($m,3);
00046                 $body = _getScalar($m,4);
00047                 $more = _getScalar($m,5);
00048                 $publish = _getScalar($m,6);
00049                 $closed = _getScalar($m,7);
00050 
00051                 return _addItem($blogid, $username, $password, $title, $body, $more, $publish, $closed);
00052         }
00053 
00054         // nucleus.addDatedItem (the time of the item can be given here, for offline blogging)
00055         $f_nucleus_addDatedItem_sig = array(array(
00056                         // return type
00057                         $xmlrpcString,  // itemid of the new item
00058 
00059                         // params:
00060                         $xmlrpcString,  // blogid
00061                         $xmlrpcString,  // username
00062                         $xmlrpcString,  // password
00063                         $xmlrpcString,  // title
00064                         $xmlrpcString,  // body
00065                         $xmlrpcString,  // extended part
00066                         $xmlrpcBoolean, // publish boolean (set to false to create draft)
00067                         $xmlrpcBoolean, // closed boolean (set to true to disable comments)
00068                         $xmlrpcInt      // item time (unix timestamp)
00069 
00070                 ));
00071         $f_nucleus_addDatedItem_doc = "Adds a new item to the given blog. Adds it as a draft when publish is false. The timestamp of the item needs to be given as a Unix timestamp";
00072         function f_nucleus_addDatedItem($m) {
00073                 $blogid = _getScalar($m,0);
00074                 $username = _getScalar($m,1);
00075                 $password = _getScalar($m,2);
00076                 $title = _getScalar($m,3);
00077                 $body = _getScalar($m,4);
00078                 $more = _getScalar($m,5);
00079                 $publish = _getScalar($m,6);
00080                 $closed = _getScalar($m,7);
00081                 $timestamp = _getScalar($m,8);
00082 
00083                 // use '1' as $future param to make sure the date does not get erased
00084                 return _addDatedItem($blogid, $username, $password, $title, $body, $more, $publish, $closed, $timestamp, 1);
00085         }
00086 
00087         // nucleus.editItem
00088         $f_nucleus_editItem_sig = array(array(
00089                         // return type
00090                         $xmlrpcBoolean, // true or false
00091 
00092                         // params:
00093                         $xmlrpcString,  // itemid
00094                         $xmlrpcString,  // username
00095                         $xmlrpcString,  // password
00096                         $xmlrpcString,  // title
00097                         $xmlrpcString,  // body
00098                         $xmlrpcString,  // extended part
00099                         $xmlrpcBoolean, // publish boolean (set to false if you want a draft to stay draft)
00100                         $xmlrpcBoolean, // closed boolean (set to true to disable comments)
00101                 ));
00102         $f_nucleus_editItem_doc = "Edits an item of a blog";
00103         function f_nucleus_editItem($m) {
00104                 global $manager;
00105 
00106                 $itemid = intval(_getScalar($m,0));
00107                 $username = _getScalar($m,1);
00108                 $password = _getScalar($m,2);
00109                 $title = _getScalar($m,3);
00110                 $content = _getScalar($m,4);
00111                 $more = _getScalar($m,5);
00112                 $publish = _getScalar($m,6);
00113                 $closed = _getScalar($m,7);
00114 
00115                 // get old title and extended part
00116                 if (!$manager->existsItem($itemid,1,1))
00117                         return _error(6,"No such item ($itemid)");
00118 
00119                 $old =& $manager->getItem($itemid,1,1);
00120                 $wasdraft = ($old['draft']) ? 1 : 0;
00121 
00122                 return _edititem($itemid, $username, $password, $old['catid'], $title, $content, $more, $wasdraft, $publish, $closed);
00123         }
00124 
00125 
00126         // nucleus.getUsersBlogs
00127         $f_nucleus_getUsersBlogs_sig = array(array(
00128                         // return type
00129                         $xmlrpcArray,   // array containing structs containing blog info
00130 
00131                         // params:
00132                         $xmlrpcString,  // username
00133                         $xmlrpcString,  // password
00134                 ));
00135         $f_nucleus_getUsersBlogs_doc = "Returns a list of all the blogs where the given member is on the team";
00136         function f_nucleus_getUsersBlogs($m) {
00137                 $username = _getScalar($m,0);
00138                 $password = _getScalar($m,1);
00139 
00140                 return _getUsersBlogs($username, $password);
00141         }
00142 
00143         // nucleus.getRecentItems
00144         $f_nucleus_getRecentItems_sig = array(array(
00145                         // return type
00146                         $xmlrpcArray,   // array of strucs (representing items)
00147 
00148                         // params
00149                         $xmlrpcString,  // blogid
00150                         $xmlrpcString,  // username
00151                         $xmlrpcString,  // password
00152                         $xmlrpcInt,     // amount of items to return (max = 20)
00153                 ));
00154         $f_nucleus_getRecentItems_doc = "Returns a maximum of 20 recent items for a given webblog";
00155         function f_nucleus_getRecentItems($m) {
00156                 $blogid = _getScalar($m, 0);
00157                 $username = _getScalar($m, 1);
00158                 $password = _getScalar($m, 2);
00159                 $amount = _getScalar($m, 3);
00160 
00161                 return _getRecentItems($blogid, $username, $password, $amount);
00162         }
00163 
00164         // nucleus.getItem
00165         $f_nucleus_getItem_sig = array(array(
00166                         // return type
00167                         $xmlrpcStruct,  // A struct representing the item
00168 
00169                         // params
00170                         $xmlrpcString,  // itemid
00171                         $xmlrpcString,  // username
00172                         $xmlrpcString,  // password
00173                 ));
00174         $f_nucleus_getItem_doc = "Returns an item";
00175         function f_nucleus_getItem($m) {
00176                 $postid = _getScalar($m, 0);
00177                 $username = _getScalar($m, 1);
00178                 $password = _getScalar($m, 2);
00179 
00180                 return _getItem($postid, $username, $password);
00181         }
00182 
00183         // nucleus.deleteItem
00184         $f_nucleus_deleteItem_sig = array(array(
00185                         // return type
00186                         $xmlrpcBoolean, // boolean (ok or not ok)
00187 
00188                         // params
00189                         $xmlrpcString,  // itemid
00190                         $xmlrpcString,  // username
00191                         $xmlrpcString,  // password
00192                 ));
00193         $f_nucleus_deleteItem_doc = "Deletes an item";
00194         function f_nucleus_deleteItem($m) {
00195                 $itemid = _getScalar($m,0);
00196                 $username = _getScalar($m, 1);
00197                 $password = _getScalar($m, 2);
00198 
00199                 return _deleteItem($itemid, $username, $password);
00200         }
00201 
00202 
00207         function _getRecentItems($blogid, $username, $password, $amount) {
00208                 $blogid = intval($blogid);
00209                 $amount = intval($amount);
00210 
00211                 // 1. login
00212                 $mem = new MEMBER();
00213                 if (!$mem->login($username, $password))
00214                         return _error(1,"Could not log in");
00215 
00216                 // 2. check if allowed
00217                 if (!BLOG::existsID($blogid))
00218                         return _error(2,"No such blog ($blogid)");
00219                 if (!$mem->teamRights($blogid))
00220                         return _error(3,"Not a team member");
00221                 $amount = intval($amount);
00222                 if (($amount < 1) or ($amount > 20))
00223                         return _error(5,"Amount parameter must be in range 1..20");
00224 
00225                 // 3. create and return list of recent items
00226                 // Struct returned has dateCreated, userid, blogid and content
00227 
00228                 $structarray = array();         // the array in which the structs will be stored
00229 
00230                 $query = "SELECT ibody, iauthor, ibody, imore, ititle, iclosed, idraft, itime"
00231                            .' FROM '.sql_table('item')
00232                            ." WHERE iblog=$blogid"
00233                            ." ORDER BY itime DESC"
00234                            ." LIMIT $amount";
00235                 $r = sql_query($query);
00236                 while ($obj = mysql_fetch_object($r)) {
00237                         $newstruct = new xmlrpcval(array(
00238                                 "publishDate" => new xmlrpcval(iso8601_encode(strtotime($obj->itime)),"dateTime.iso8601"),
00239                                 "userid" => new xmlrpcval($obj->iauthor,"string"),
00240                                 "blogid" => new xmlrpcval($blogid,"string"),
00241                                 "title" => new xmlrpcval($obj->ititle,"string"),
00242                                 "body" => new xmlrpcval($obj->ibody,"string"),
00243                                 "more" => new xmlrpcval($obj->imore,"string"),
00244                                 "draft" => new xmlrpcval($obj->idraft,"boolean"),
00245                                 "closed" => new xmlrpcval($obj->iclosed,"boolean"),
00246                         ),'struct');
00247                         array_push($structarray, $newstruct);
00248                 }
00249 
00250                 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
00251 
00252         }
00253 
00254 
00255 
00259         function _getItem($itemid, $username, $password) {
00260                 global $manager;
00261 
00262                 // 1. login
00263                 $mem = new MEMBER();
00264                 if (!$mem->login($username, $password))
00265                         return _error(1,"Could not log in");
00266 
00267                 // 2. check if allowed
00268                 if (!$manager->existsItem($itemid,1,1))
00269                         return _error(6,"No such item ($itemid)");
00270                 $blogid = getBlogIDFromItemID($itemid);
00271 
00272                 if (!$mem->teamRights($blogid))
00273                         return _error(3,"Not a team member");
00274 
00275                 // 3. return the item
00276                 // Structure returned has dateCreated, userid, blogid and content
00277 
00278                 $item =& $manager->getItem($itemid,1,1); // (also allow drafts and future items)
00279 
00280                 $blog = new BLOG($blogid);
00281                 if ($blog->convertBreaks())
00282                         $item['body'] = removeBreaks($item['body']);
00283 
00284                 $newstruct = new xmlrpcval(array(
00285                         "publishDate" => new xmlrpcval(iso8601_encode($item['timestamp']),"dateTime.iso8601"),
00286                         "userid" => new xmlrpcval($item['authorid'],"string"),
00287                         "blogid" => new xmlrpcval($blogid,"string"),
00288                         "title" => new xmlrpcval($item['title'],"string"),
00289                         "body" => new xmlrpcval($item['body'],"string"),
00290                         "more" => new xmlrpcval($item['more'],"string"),
00291                         "draft" => new xmlrpcval($item['draft'],"boolean"),
00292                         "closed" => new xmlrpcval($ite['closed'],"boolean"),
00293                 ),'struct');
00294 
00295                 return new xmlrpcresp($newstruct);
00296 
00297 
00298         }
00299 
00300 
00301         $functionDefs = array_merge($functionDefs,
00302                 array(
00303                         "nucleus.addItem" =>
00304                         array( "function" => "f_nucleus_addItem",
00305                                 "signature" => $f_nucleus_addItem_sig,
00306                                 "docstring" => $f_nucleus_addItem_doc),
00307 
00308                         "nucleus.editItem" =>
00309                         array( "function" => "f_nucleus_editItem",
00310                                 "signature" => $f_nucleus_editItem_sig,
00311                                 "docstring" => $f_nucleus_editItem_doc),
00312 
00313                         "nucleus.addDatedItem" =>
00314                         array( "function" => "f_nucleus_addDatedItem",
00315                                 "signature" => $f_nucleus_addDatedItem_sig,
00316                                 "docstring" => $f_nucleus_addDatedItem_doc),
00317 
00318                         "nucleus.deleteItem" =>
00319                         array( "function" => "f_nucleus_deleteItem",
00320                                 "signature" => $f_nucleus_deleteItem_sig,
00321                                 "docstring" => $f_nucleus_deleteItem_doc),
00322 
00323                         "nucleus.getUsersBlogs" =>
00324                         array( "function" => "f_nucleus_getUsersBlogs",
00325                                 "signature" => $f_nucleus_getUsersBlogs_sig,
00326                                 "docstring" => $f_nucleus_getUsersBlogs_doc),
00327 
00328                         "nucleus.getRecentItems" =>
00329                         array( "function" => "f_nucleus_getRecentItems",
00330                                 "signature" => $f_nucleus_getRecentItems_sig,
00331                                 "docstring" => $f_nucleus_getRecentItems_doc),
00332 
00333                         "nucleus.getItem" =>
00334                         array( "function" => "f_nucleus_getItem",
00335                                 "signature" => $f_nucleus_getItem_sig,
00336                                 "docstring" => $f_nucleus_getItem_doc)
00337                 )
00338 
00339         );
00340 
00341 ?>



Generated on Wed Jun 25 17:25:57 2008 by  doxygen 1.5.5