[ Index ]

PHP Cross Reference of Nucleus CMS 3.32

title

Body

[close]

/nucleus/xmlrpc/ -> api_mt.inc.php (source)

   1  <?php
   2  
   3  /*
   4   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
   5   * Copyright (C) 2002-2007 The Nucleus Group
   6   *
   7   * This program is free software; you can redistribute it and/or
   8   * modify it under the terms of the GNU General Public License
   9   * as published by the Free Software Foundation; either version 2
  10   * of the License, or (at your option) any later version.
  11   * (see nucleus/documentation/index.html#license for more info)
  12   */
  13  /**
  14   * This file contains definitions for the methods in the Movable Type API
  15   *
  16   * Wouter Demuynck 2003-08-31
  17   *
  18   * @license http://nucleuscms.org/license.txt GNU General Public License
  19   * @copyright Copyright (C) 2002-2007 The Nucleus Group
  20   */
  21  
  22      // mt.supportedMethods
  23      $f_mt_supportedMethods_sig = array(array(
  24              // return type
  25              $xmlrpcArray // array of strings
  26          ));
  27      $f_mt_supportedMethods_doc = 'returns an array of supported methods';
  28  	function f_mt_supportedMethods($m) {
  29          $res = new xmlrpcresp(new xmlrpcval(
  30              array(
  31                  new xmlrpcval('mt.supportedMethods', 'string'),
  32                  new xmlrpcval('mt.supportedTextFilters', 'string'),
  33                  new xmlrpcval('mt.publishPost', 'string'),
  34                  new xmlrpcval('mt.getCategoryList', 'string'),
  35                  new xmlrpcval('mt.getPostCategories', 'string'),
  36                  new xmlrpcval('mt.setPostCategories', 'string'),
  37                  new xmlrpcval('mt.getRecentPostTitles', 'string'),
  38                  new xmlrpcval('mt.getTrackbackPings','string'),
  39              ), 'array')
  40          );
  41          return $res;
  42      }
  43  
  44      // mt.supportedTextFilters
  45      $f_mt_supportedTextFilters_sig = array(array(
  46              // return type
  47              $xmlrpcArray    // array of structs
  48          ));
  49      $f_mt_supportedTextFilters_doc = 'returns the supported text filters';
  50  	function f_mt_supportedTextFilters($m) {
  51          $res = new xmlrpcresp(new xmlrpcval(
  52              array(
  53                  // no text filters in nucleus
  54              ), 'array')
  55          );
  56          return $res;
  57      }
  58  
  59      // mt.getCategoryList
  60      $f_mt_getCategoryList_sig = array(array(
  61              // return type
  62              $xmlrpcArray,        // array of structs
  63  
  64              // params
  65              $xmlrpcString,        // blogid
  66              $xmlrpcString,        // username
  67              $xmlrpcString        // password
  68  
  69          ));
  70      $f_mt_getCategoryList_doc = 'Returns a list of all categories defined in the weblog';
  71  	function f_mt_getCategoryList($m) {
  72          $blogid =    _getScalar($m,0);
  73          $username =    _getScalar($m,1);
  74          $password =    _getScalar($m,2);
  75  
  76          return _mt_categoryList($blogid, $username, $password);
  77      }
  78  
  79      // mt.publishPost
  80      $f_mt_publishPost_sig = array(array(
  81              // return type
  82              $xmlrpcBoolean,        // true
  83  
  84              // params
  85              $xmlrpcString,        // itemid
  86              $xmlrpcString,        // username
  87              $xmlrpcString        // password
  88          ));
  89      $f_mt_publishPost_doc = 'Transfers an item from the "draft" state to the "published" state. For items that were published earlier, does nothing.';
  90  	function f_mt_publishPost($m) {
  91          $itemid        = intval(_getScalar($m, 0));
  92          $username    = _getScalar($m, 1);
  93          $password    = _getScalar($m, 2);
  94  
  95          return _mt_publishPost($itemid, $username, $password);
  96      }
  97  
  98      // mt.getPostCategories
  99      $f_mt_getPostCategories_sig = array(array(
 100          // return
 101          $xmlrpcArray,        // array of structs
 102          // parameters
 103          $xmlrpcString,        // itemid
 104          $xmlrpcString,        // username
 105          $xmlrpcString        // password
 106      ));
 107      $f_mt_getPostCategories_doc = 'Returns a list of all categories to which the post is assigned.';
 108  	function f_mt_getPostCategories($m) {
 109          $itemid        = intval(_getScalar($m, 0));
 110          $username    = _getScalar($m, 1);
 111          $password    = _getScalar($m, 2);
 112  
 113          return _mt_getPostCategories($itemid, $username, $password);
 114      }
 115  
 116      // mt.setPostCategories
 117      $f_mt_setPostCategories_sig = array(array(
 118          // return
 119          $xmlrpcBoolean,        // true
 120          // parameters
 121          $xmlrpcString,        // itemid
 122          $xmlrpcString,        // username
 123          $xmlrpcString,        // password
 124          $xmlrpcArray        // categories
 125      ));
 126      $f_mt_setPostCategories_doc = 'Sets the categories for a post. Only the primary category will be stored';
 127  	function f_mt_setPostCategories($m) {
 128          $itemid        = intval(_getScalar($m, 0));
 129          $username    = _getScalar($m, 1);
 130          $password    = _getScalar($m, 2);
 131  
 132          $categories = $m->getParam(3);
 133          $iSize = $categories->arraysize();
 134  
 135          $category = '';
 136          for ($i=0;$i<$iSize;$i++) {
 137              $struct = $categories->arraymem($i);
 138              $bPrimary = $struct->structmem('isPrimary');
 139              if ($bPrimary)
 140                  $bPrimary = $bPrimary->scalarval();
 141              else if (!$category)
 142                  $bPrimary = 1;    // "Using isPrimary to set the primary category is optional--
 143                                  // in the absence of this flag, the first struct in the array
 144                                  // will be assigned the primary category for the post." (MT doc)
 145              if ($bPrimary) {
 146                  $category = $struct->structmem('categoryId');
 147                  $category = $category->scalarval();
 148              }
 149  
 150          }
 151  
 152          return _mt_setPostCategories($itemid, $username, $password, $category);
 153      }
 154  
 155      // mt.getRecentPostTitles
 156      $f_mt_getRecentPostTitles_sig = array(array(
 157          // return
 158          $xmlrpcArray,        // array of structs
 159          // params
 160          $xmlrpcString,        // blogid
 161          $xmlrpcString,        // userid
 162          $xmlrpcString,        // password,
 163          $xmlrpcInt            // number of posts
 164      ));
 165      $f_mt_getRecentPostTitles_doc = 'Returns a bandwidth-friendly list of the most recent posts in the system.';
 166  	function f_mt_getRecentPostTitles($m) {
 167          $blogid        = intval(_getScalar($m, 0));
 168          $username    = _getScalar($m, 1);
 169          $password    = _getScalar($m, 2);
 170          $iAmount    = intval(_getScalar($m, 3));
 171  
 172          return _mt_getRecentPostTitles($blogid, $username, $password, $iAmount);
 173      }
 174  
 175      // mt.getTrackbackPings
 176      $f_mt_getTrackbackPings_sig = array(array(
 177          // return
 178          $xmlrpcArray,        // array of structs
 179          // params
 180          $xmlrpcString        // postid
 181      ));
 182      $f_mt_getTrackbackPings_doc = '(this is currently just a placeholder. It returns an empty array.)';
 183  	function f_mt_getTrackbackPings($m) {
 184          global $manager;
 185          
 186          $itemid = intval(_getScalar($m, 0));
 187  
 188          $trackbacks = array ();
 189          $tbstruct   = array ();
 190              
 191          $manager->notify('RetrieveTrackback', array ('tb_id' => $itemid, 'trackbacks' => & $trackbacks));
 192                  
 193          while (list(,$v) = each ($trackbacks)) {
 194              $tbstruct[] = new xmlrpcval(
 195                  array(
 196                      "pingTitle" => new xmlrpcval($v['title'], "string"),
 197                      "pingURL"   => new xmlrpcval($v['url'], "string"),
 198                      "pingIP"    => new xmlrpcval($v['ip'], "string")
 199                  )
 200              ,'struct');            
 201          }        
 202                  
 203          return new xmlrpcresp(new xmlrpcval( $tbstruct , "array"));
 204      }
 205  
 206      $functionDefs = array_merge($functionDefs,
 207          array(
 208               "mt.supportedMethods" =>
 209               array( "function" => "f_mt_supportedMethods",
 210                  "signature" => $f_mt_supportedMethods_sig,
 211                  "docstring" => $f_mt_supportedMethods_doc),
 212  
 213               "mt.supportedTextFilters" =>
 214               array( "function" => "f_mt_supportedTextFilters",
 215                  "signature" => $f_mt_supportedTextFilters_sig,
 216                  "docstring" => $f_mt_supportedTextFilters_doc),
 217  
 218               "mt.getCategoryList" =>
 219               array( "function" => "f_mt_getCategoryList",
 220                  "signature" => $f_mt_getCategoryList_sig,
 221                  "docstring" => $f_mt_getCategoryList_doc),
 222  
 223               "mt.publishPost" =>
 224               array( "function" => "f_mt_publishPost",
 225                  "signature" => $f_mt_publishPost_sig,
 226                  "docstring" => $f_mt_publishPost_doc),
 227  
 228               "mt.getPostCategories" =>
 229               array( "function" => "f_mt_getPostCategories",
 230                  "signature" => $f_mt_getPostCategories_sig,
 231                  "docstring" => $f_mt_getPostCategories_doc),
 232  
 233               "mt.setPostCategories" =>
 234               array( "function" => "f_mt_setPostCategories",
 235                  "signature" => $f_mt_setPostCategories_sig,
 236                  "docstring" => $f_mt_setPostCategories_doc),
 237  
 238               "mt.getRecentPostTitles" =>
 239               array( "function" => "f_mt_getRecentPostTitles",
 240                  "signature" => $f_mt_getRecentPostTitles_sig,
 241                  "docstring" => $f_mt_getRecentPostTitles_doc),
 242  
 243               "mt.getTrackbackPings" =>
 244               array( "function" => "f_mt_getTrackbackPings",
 245                  "signature" => $f_mt_getTrackbackPings_sig,
 246                  "docstring" => $f_mt_getTrackbackPings_doc)
 247  
 248          )
 249      );
 250  
 251  	function _mt_setPostCategories($itemid, $username, $password, $category) {
 252          global $manager;
 253  
 254          // login
 255          $mem = new MEMBER();
 256          if (!$mem->login($username, $password))
 257              return _error(1,"Could not log in");
 258  
 259          // check if item exists
 260          if (!$manager->existsItem($itemid,1,1))
 261              return _error(6,"No such item ($itemid)");
 262  
 263          $blogid = getBlogIDFromItemID($itemid);
 264          $blog = new BLOG($blogid);
 265  
 266          if (!$mem->canAlterItem($itemid))
 267              return _error(7,"Not allowed to alter item");
 268  
 269          $old =& $manager->getItem($itemid,1,1);
 270  
 271          $catid = $blog->getCategoryIdFromName($category);
 272  
 273          $publish = 0;
 274          if ($old['draft'] && $publish) {
 275              $wasdraft = 1;
 276              $publish = 1;
 277          } else {
 278              $wasdraft = 0;
 279          }
 280  
 281          return _edititem($itemid, $username, $password, $catid, $old['title'], $old['body'], $old['more'], $wasdraft, $publish, $old['closed']);
 282      }
 283  
 284  
 285  	function _mt_getPostCategories($itemid, $username, $password) {
 286          global $manager;
 287  
 288          // login
 289          $mem = new MEMBER();
 290          if (!$mem->login($username, $password))
 291              return _error(1,"Could not log in");
 292  
 293          // check if item exists
 294          if (!$manager->existsItem($itemid,1,1))
 295              return _error(6,"No such item ($itemid)");
 296  
 297          $blogid = getBlogIDFromItemID($itemid);
 298          $blog = new BLOG($blogid);
 299  
 300          if (!$mem->canAlterItem($itemid))
 301              return _error(7, 'You are not allowed to request this information');
 302  
 303          $info =& $manager->getItem($itemid,1,1);
 304          $catName = $blog->getCategoryName($info['catid']);
 305  
 306          $struct = new xmlrpcval(
 307              array(
 308                  'categoryId' => new xmlrpcval($catName, 'string'),
 309                  'categoryName' => new xmlrpcval($catName, 'string'),
 310                  'isPrimary'    => new xmlrpcval(1, 'boolean')
 311              ), 'struct'
 312          );
 313  
 314          return new xmlrpcresp(new xmlrpcval(array($struct), 'array'));
 315  
 316      }
 317  
 318  	function _mt_publishPost($itemid, $username, $password) {
 319          global $manager;
 320  
 321          if (!$manager->existsItem($itemid,1,1))
 322              return _error(6,"No such item ($itemid)");
 323  
 324          // get item data
 325          $blogid = getBlogIDFromItemID($itemid);
 326          $blog = new BLOG($blogid);
 327          $old =& $manager->getItem($itemid,1,1);
 328  
 329          return _edititem($itemid, $username, $password, $old['catid'], $old['title'], $old['body'], $old['more'], $old['draft'], 1, $old['closed']);
 330      }
 331  
 332  
 333  	function _mt_categoryList($blogid, $username, $password) {
 334          // 1. login
 335          $mem = new MEMBER();
 336          if (!$mem->login($username, $password))
 337              return _error(1,"Could not log in");
 338  
 339          // check if on team and blog exists
 340          if (!BLOG::existsID($blogid))
 341              return _error(2,"No such blog ($blogid)");
 342          if (!$mem->teamRights($blogid))
 343              return _error(3,"Not a team member");
 344  
 345          $b = new BLOG($blogid);
 346  
 347          $categorystruct = array();
 348  
 349          $query =  "SELECT cname, cdesc, catid"
 350                  . ' FROM '.sql_table('category')
 351                  . " WHERE cblog=" . intval($blogid)
 352                  . " ORDER BY cname";
 353          $r = sql_query($query);
 354  
 355          while ($obj = mysql_fetch_object($r)) {
 356  
 357              $categorystruct[] = new xmlrpcval(
 358                  array(
 359                      "categoryName" => new xmlrpcval($obj->cname,"string"),
 360                      "categoryId" => new xmlrpcval($obj->cname,"string")
 361                  )
 362              ,'struct');
 363  
 364          }
 365  
 366  
 367          return new xmlrpcresp(new xmlrpcval( $categorystruct , "array"));
 368  
 369      }
 370  
 371  	function _mt_getRecentPostTitles($blogid, $username, $password, $iAmount)
 372      {
 373          $blogid = intval($blogid);
 374          $iAmount = intval($iAmount);
 375  
 376          // 1. login
 377          $mem = new MEMBER();
 378          if (!$mem->login($username, $password))
 379              return _error(1,"Could not log in");
 380  
 381          // 2. check if allowed
 382          if (!BLOG::existsID($blogid))
 383              return _error(2,"No such blog ($blogid)");
 384          if (!$mem->teamRights($blogid))
 385              return _error(3,"Not a team member");
 386          $iAmount = intval($iAmount);
 387          if ($iAmount < 1)
 388              return _error(5,"Amount parameter must be positive");
 389  
 390          // 3. create and return list of recent items
 391          // Struct returned has dateCreated, userid, postid and title
 392  
 393          $blog = new BLOG($blogid);
 394  
 395          $structarray = array();        // the array in which the structs will be stored
 396  
 397          $query = "SELECT inumber, ititle as title, itime, iauthor"
 398                 .' FROM '.sql_table('item')
 399                 ." WHERE iblog=$blogid"
 400                 ." ORDER BY itime DESC"
 401                 ." LIMIT $iAmount";
 402          $r = sql_query($query);
 403  
 404          while ($row = mysql_fetch_assoc($r)) {
 405  
 406              $newstruct = new xmlrpcval(array(
 407                  "dateCreated" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"),
 408                  "postid" => new xmlrpcval($row['inumber'],"string"),
 409                  "title" => new xmlrpcval($row['title'],"string"),
 410                  "userid" => new xmlrpcval($row['iauthor'],"string")
 411              ),'struct');
 412  
 413              array_push($structarray, $newstruct);
 414          }
 415  
 416          return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
 417  
 418      }
 419  
 420  
 421  
 422  ?>


Generated: Tue Feb 12 15:34:36 2008 Cross-referenced by PHPXref 0.7