api_mt.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
00005  * Copyright (C) 2002-2007 The Nucleus Group
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * (see nucleus/documentation/index.html#license for more info)
00012  */
00023         // mt.supportedMethods
00024         $f_mt_supportedMethods_sig = array(array(
00025                         // return type
00026                         $xmlrpcArray // array of strings
00027                 ));
00028         $f_mt_supportedMethods_doc = 'returns an array of supported methods';
00029         function f_mt_supportedMethods($m) {
00030                 $res = new xmlrpcresp(new xmlrpcval(
00031                         array(
00032                                 new xmlrpcval('mt.supportedMethods', 'string'),
00033                                 new xmlrpcval('mt.supportedTextFilters', 'string'),
00034                                 new xmlrpcval('mt.publishPost', 'string'),
00035                                 new xmlrpcval('mt.getCategoryList', 'string'),
00036                                 new xmlrpcval('mt.getPostCategories', 'string'),
00037                                 new xmlrpcval('mt.setPostCategories', 'string'),
00038                                 new xmlrpcval('mt.getRecentPostTitles', 'string'),
00039                                 new xmlrpcval('mt.getTrackbackPings','string'),
00040                         ), 'array')
00041                 );
00042                 return $res;
00043         }
00044 
00045         // mt.supportedTextFilters
00046         $f_mt_supportedTextFilters_sig = array(array(
00047                         // return type
00048                         $xmlrpcArray    // array of structs
00049                 ));
00050         $f_mt_supportedTextFilters_doc = 'returns the supported text filters';
00051         function f_mt_supportedTextFilters($m) {
00052                 $res = new xmlrpcresp(new xmlrpcval(
00053                         array(
00054                                 // no text filters in nucleus
00055                         ), 'array')
00056                 );
00057                 return $res;
00058         }
00059 
00060         // mt.getCategoryList
00061         $f_mt_getCategoryList_sig = array(array(
00062                         // return type
00063                         $xmlrpcArray,           // array of structs
00064 
00065                         // params
00066                         $xmlrpcString,          // blogid
00067                         $xmlrpcString,          // username
00068                         $xmlrpcString           // password
00069 
00070                 ));
00071         $f_mt_getCategoryList_doc = 'Returns a list of all categories defined in the weblog';
00072         function f_mt_getCategoryList($m) {
00073                 $blogid =       _getScalar($m,0);
00074                 $username =     _getScalar($m,1);
00075                 $password =     _getScalar($m,2);
00076 
00077                 return _mt_categoryList($blogid, $username, $password);
00078         }
00079 
00080         // mt.publishPost
00081         $f_mt_publishPost_sig = array(array(
00082                         // return type
00083                         $xmlrpcBoolean,         // true
00084 
00085                         // params
00086                         $xmlrpcString,          // itemid
00087                         $xmlrpcString,          // username
00088                         $xmlrpcString           // password
00089                 ));
00090         $f_mt_publishPost_doc = 'Transfers an item from the "draft" state to the "published" state. For items that were published earlier, does nothing.';
00091         function f_mt_publishPost($m) {
00092                 $itemid         = intval(_getScalar($m, 0));
00093                 $username       = _getScalar($m, 1);
00094                 $password       = _getScalar($m, 2);
00095 
00096                 return _mt_publishPost($itemid, $username, $password);
00097         }
00098 
00099         // mt.getPostCategories
00100         $f_mt_getPostCategories_sig = array(array(
00101                 // return
00102                 $xmlrpcArray,           // array of structs
00103                 // parameters
00104                 $xmlrpcString,          // itemid
00105                 $xmlrpcString,          // username
00106                 $xmlrpcString           // password
00107         ));
00108         $f_mt_getPostCategories_doc = 'Returns a list of all categories to which the post is assigned.';
00109         function f_mt_getPostCategories($m) {
00110                 $itemid         = intval(_getScalar($m, 0));
00111                 $username       = _getScalar($m, 1);
00112                 $password       = _getScalar($m, 2);
00113 
00114                 return _mt_getPostCategories($itemid, $username, $password);
00115         }
00116 
00117         // mt.setPostCategories
00118         $f_mt_setPostCategories_sig = array(array(
00119                 // return
00120                 $xmlrpcBoolean,         // true
00121                 // parameters
00122                 $xmlrpcString,          // itemid
00123                 $xmlrpcString,          // username
00124                 $xmlrpcString,          // password
00125                 $xmlrpcArray            // categories
00126         ));
00127         $f_mt_setPostCategories_doc = 'Sets the categories for a post. Only the primary category will be stored';
00128         function f_mt_setPostCategories($m) {
00129                 $itemid         = intval(_getScalar($m, 0));
00130                 $username       = _getScalar($m, 1);
00131                 $password       = _getScalar($m, 2);
00132 
00133                 $categories = $m->getParam(3);
00134                 $iSize = $categories->arraysize();
00135 
00136                 $category = '';
00137                 for ($i=0;$i<$iSize;$i++) {
00138                         $struct = $categories->arraymem($i);
00139                         $bPrimary = $struct->structmem('isPrimary');
00140                         if ($bPrimary)
00141                                 $bPrimary = $bPrimary->scalarval();
00142                         else if (!$category)
00143                                 $bPrimary = 1;  // "Using isPrimary to set the primary category is optional--
00144                                                                 // in the absence of this flag, the first struct in the array
00145                                                                 // will be assigned the primary category for the post." (MT doc)
00146                         if ($bPrimary) {
00147                                 $category = $struct->structmem('categoryId');
00148                                 $category = $category->scalarval();
00149                         }
00150 
00151                 }
00152 
00153                 return _mt_setPostCategories($itemid, $username, $password, $category);
00154         }
00155 
00156         // mt.getRecentPostTitles
00157         $f_mt_getRecentPostTitles_sig = array(array(
00158                 // return
00159                 $xmlrpcArray,           // array of structs
00160                 // params
00161                 $xmlrpcString,          // blogid
00162                 $xmlrpcString,          // userid
00163                 $xmlrpcString,          // password,
00164                 $xmlrpcInt                      // number of posts
00165         ));
00166         $f_mt_getRecentPostTitles_doc = 'Returns a bandwidth-friendly list of the most recent posts in the system.';
00167         function f_mt_getRecentPostTitles($m) {
00168                 $blogid         = intval(_getScalar($m, 0));
00169                 $username       = _getScalar($m, 1);
00170                 $password       = _getScalar($m, 2);
00171                 $iAmount        = intval(_getScalar($m, 3));
00172 
00173                 return _mt_getRecentPostTitles($blogid, $username, $password, $iAmount);
00174         }
00175 
00176         // mt.getTrackbackPings
00177         $f_mt_getTrackbackPings_sig = array(array(
00178                 // return
00179                 $xmlrpcArray,           // array of structs
00180                 // params
00181                 $xmlrpcString           // postid
00182         ));
00183         $f_mt_getTrackbackPings_doc = '(this is currently just a placeholder. It returns an empty array.)';
00184         function f_mt_getTrackbackPings($m) {
00185                 global $manager;
00186                 
00187                 $itemid = intval(_getScalar($m, 0));
00188 
00189                 $trackbacks = array ();
00190                 $tbstruct   = array ();
00191                         
00192                 $manager->notify('RetrieveTrackback', array ('tb_id' => $itemid, 'trackbacks' => & $trackbacks));
00193                                 
00194                 while (list(,$v) = each ($trackbacks)) {
00195                         $tbstruct[] = new xmlrpcval(
00196                                 array(
00197                                         "pingTitle" => new xmlrpcval($v['title'], "string"),
00198                                         "pingURL"   => new xmlrpcval($v['url'], "string"),
00199                                         "pingIP"    => new xmlrpcval($v['ip'], "string")
00200                                 )
00201                         ,'struct');                     
00202                 }               
00203                                 
00204                 return new xmlrpcresp(new xmlrpcval( $tbstruct , "array"));
00205         }
00206 
00207         $functionDefs = array_merge($functionDefs,
00208                 array(
00209                          "mt.supportedMethods" =>
00210                          array( "function" => "f_mt_supportedMethods",
00211                                 "signature" => $f_mt_supportedMethods_sig,
00212                                 "docstring" => $f_mt_supportedMethods_doc),
00213 
00214                          "mt.supportedTextFilters" =>
00215                          array( "function" => "f_mt_supportedTextFilters",
00216                                 "signature" => $f_mt_supportedTextFilters_sig,
00217                                 "docstring" => $f_mt_supportedTextFilters_doc),
00218 
00219                          "mt.getCategoryList" =>
00220                          array( "function" => "f_mt_getCategoryList",
00221                                 "signature" => $f_mt_getCategoryList_sig,
00222                                 "docstring" => $f_mt_getCategoryList_doc),
00223 
00224                          "mt.publishPost" =>
00225                          array( "function" => "f_mt_publishPost",
00226                                 "signature" => $f_mt_publishPost_sig,
00227                                 "docstring" => $f_mt_publishPost_doc),
00228 
00229                          "mt.getPostCategories" =>
00230                          array( "function" => "f_mt_getPostCategories",
00231                                 "signature" => $f_mt_getPostCategories_sig,
00232                                 "docstring" => $f_mt_getPostCategories_doc),
00233 
00234                          "mt.setPostCategories" =>
00235                          array( "function" => "f_mt_setPostCategories",
00236                                 "signature" => $f_mt_setPostCategories_sig,
00237                                 "docstring" => $f_mt_setPostCategories_doc),
00238 
00239                          "mt.getRecentPostTitles" =>
00240                          array( "function" => "f_mt_getRecentPostTitles",
00241                                 "signature" => $f_mt_getRecentPostTitles_sig,
00242                                 "docstring" => $f_mt_getRecentPostTitles_doc),
00243 
00244                          "mt.getTrackbackPings" =>
00245                          array( "function" => "f_mt_getTrackbackPings",
00246                                 "signature" => $f_mt_getTrackbackPings_sig,
00247                                 "docstring" => $f_mt_getTrackbackPings_doc)
00248 
00249                 )
00250         );
00251 
00252         function _mt_setPostCategories($itemid, $username, $password, $category) {
00253                 global $manager;
00254 
00255                 // login
00256                 $mem = new MEMBER();
00257                 if (!$mem->login($username, $password))
00258                         return _error(1,"Could not log in");
00259 
00260                 // check if item exists
00261                 if (!$manager->existsItem($itemid,1,1))
00262                         return _error(6,"No such item ($itemid)");
00263 
00264                 $blogid = getBlogIDFromItemID($itemid);
00265                 $blog = new BLOG($blogid);
00266 
00267                 if (!$mem->canAlterItem($itemid))
00268                         return _error(7,"Not allowed to alter item");
00269 
00270                 $old =& $manager->getItem($itemid,1,1);
00271 
00272                 $catid = $blog->getCategoryIdFromName($category);
00273 
00274                 $publish = 0;
00275                 if ($old['draft'] && $publish) {
00276                         $wasdraft = 1;
00277                         $publish = 1;
00278                 } else {
00279                         $wasdraft = 0;
00280                 }
00281 
00282                 return _edititem($itemid, $username, $password, $catid, $old['title'], $old['body'], $old['more'], $wasdraft, $publish, $old['closed']);
00283         }
00284 
00285 
00286         function _mt_getPostCategories($itemid, $username, $password) {
00287                 global $manager;
00288 
00289                 // login
00290                 $mem = new MEMBER();
00291                 if (!$mem->login($username, $password))
00292                         return _error(1,"Could not log in");
00293 
00294                 // check if item exists
00295                 if (!$manager->existsItem($itemid,1,1))
00296                         return _error(6,"No such item ($itemid)");
00297 
00298                 $blogid = getBlogIDFromItemID($itemid);
00299                 $blog = new BLOG($blogid);
00300 
00301                 if (!$mem->canAlterItem($itemid))
00302                         return _error(7, 'You are not allowed to request this information');
00303 
00304                 $info =& $manager->getItem($itemid,1,1);
00305                 $catName = $blog->getCategoryName($info['catid']);
00306 
00307                 $struct = new xmlrpcval(
00308                         array(
00309                                 'categoryId' => new xmlrpcval($catName, 'string'),
00310                                 'categoryName' => new xmlrpcval($catName, 'string'),
00311                                 'isPrimary'     => new xmlrpcval(1, 'boolean')
00312                         ), 'struct'
00313                 );
00314 
00315                 return new xmlrpcresp(new xmlrpcval(array($struct), 'array'));
00316 
00317         }
00318 
00319         function _mt_publishPost($itemid, $username, $password) {
00320                 global $manager;
00321 
00322                 if (!$manager->existsItem($itemid,1,1))
00323                         return _error(6,"No such item ($itemid)");
00324 
00325                 // get item data
00326                 $blogid = getBlogIDFromItemID($itemid);
00327                 $blog = new BLOG($blogid);
00328                 $old =& $manager->getItem($itemid,1,1);
00329 
00330                 return _edititem($itemid, $username, $password, $old['catid'], $old['title'], $old['body'], $old['more'], $old['draft'], 1, $old['closed']);
00331         }
00332 
00333 
00334         function _mt_categoryList($blogid, $username, $password) {
00335                 // 1. login
00336                 $mem = new MEMBER();
00337                 if (!$mem->login($username, $password))
00338                         return _error(1,"Could not log in");
00339 
00340                 // check if on team and blog exists
00341                 if (!BLOG::existsID($blogid))
00342                         return _error(2,"No such blog ($blogid)");
00343                 if (!$mem->teamRights($blogid))
00344                         return _error(3,"Not a team member");
00345 
00346                 $b = new BLOG($blogid);
00347 
00348                 $categorystruct = array();
00349 
00350                 $query =  "SELECT cname, cdesc, catid"
00351                                 . ' FROM '.sql_table('category')
00352                                 . " WHERE cblog=" . intval($blogid)
00353                                 . " ORDER BY cname";
00354                 $r = sql_query($query);
00355 
00356                 while ($obj = mysql_fetch_object($r)) {
00357 
00358                         $categorystruct[] = new xmlrpcval(
00359                                 array(
00360                                         "categoryName" => new xmlrpcval($obj->cname,"string"),
00361                                         "categoryId" => new xmlrpcval($obj->cname,"string")
00362                                 )
00363                         ,'struct');
00364 
00365                 }
00366 
00367 
00368                 return new xmlrpcresp(new xmlrpcval( $categorystruct , "array"));
00369 
00370         }
00371 
00372         function _mt_getRecentPostTitles($blogid, $username, $password, $iAmount)
00373         {
00374                 $blogid = intval($blogid);
00375                 $iAmount = intval($iAmount);
00376 
00377                 // 1. login
00378                 $mem = new MEMBER();
00379                 if (!$mem->login($username, $password))
00380                         return _error(1,"Could not log in");
00381 
00382                 // 2. check if allowed
00383                 if (!BLOG::existsID($blogid))
00384                         return _error(2,"No such blog ($blogid)");
00385                 if (!$mem->teamRights($blogid))
00386                         return _error(3,"Not a team member");
00387                 $iAmount = intval($iAmount);
00388                 if ($iAmount < 1)
00389                         return _error(5,"Amount parameter must be positive");
00390 
00391                 // 3. create and return list of recent items
00392                 // Struct returned has dateCreated, userid, postid and title
00393 
00394                 $blog = new BLOG($blogid);
00395 
00396                 $structarray = array();         // the array in which the structs will be stored
00397 
00398                 $query = "SELECT inumber, ititle as title, itime, iauthor"
00399                            .' FROM '.sql_table('item')
00400                            ." WHERE iblog=$blogid"
00401                            ." ORDER BY itime DESC"
00402                            ." LIMIT $iAmount";
00403                 $r = sql_query($query);
00404 
00405                 while ($row = mysql_fetch_assoc($r)) {
00406 
00407                         $newstruct = new xmlrpcval(array(
00408                                 "dateCreated" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"),
00409                                 "postid" => new xmlrpcval($row['inumber'],"string"),
00410                                 "title" => new xmlrpcval($row['title'],"string"),
00411                                 "userid" => new xmlrpcval($row['iauthor'],"string")
00412                         ),'struct');
00413 
00414                         array_push($structarray, $newstruct);
00415                 }
00416 
00417                 return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
00418 
00419         }
00420 
00421 
00422 
00423 ?>



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