[ Index ]

PHP Cross Reference of Nucleus CMS v3.51 code documentation

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-2009 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-2009 The Nucleus Group

  20   * @version $Id: api_mt.inc.php 1388 2009-07-18 06:31:28Z shizuki $

  21   */
  22  
  23      // mt.supportedMethods

  24      $f_mt_supportedMethods_sig = array(array(
  25              // return type

  26              $xmlrpcArray // array of strings
  27          ));
  28      $f_mt_supportedMethods_doc = 'returns an array of supported methods';
  29  	function f_mt_supportedMethods($m) {
  30          $res = new xmlrpcresp(new xmlrpcval(
  31              array(
  32                  new xmlrpcval('mt.supportedMethods', 'string'),
  33                  new xmlrpcval('mt.supportedTextFilters', 'string'),
  34                  new xmlrpcval('mt.publishPost', 'string'),
  35                  new xmlrpcval('mt.getCategoryList', 'string'),
  36                  new xmlrpcval('mt.getPostCategories', 'string'),
  37                  new xmlrpcval('mt.setPostCategories', 'string'),
  38                  new xmlrpcval('mt.getRecentPostTitles', 'string'),
  39                  new xmlrpcval('mt.getTrackbackPings','string'),
  40              ), 'array')
  41          );
  42          return $res;
  43      }
  44  
  45      // mt.supportedTextFilters

  46      $f_mt_supportedTextFilters_sig = array(array(
  47              // return type

  48              $xmlrpcArray    // array of structs
  49          ));
  50      $f_mt_supportedTextFilters_doc = 'returns the supported text filters';
  51  	function f_mt_supportedTextFilters($m) {
  52          $res = new xmlrpcresp(new xmlrpcval(
  53              array(
  54                  // no text filters in nucleus

  55              ), 'array')
  56          );
  57          return $res;
  58      }
  59  
  60      // mt.getCategoryList

  61      $f_mt_getCategoryList_sig = array(array(
  62              // return type

  63              $xmlrpcArray,        // array of structs
  64  
  65              // params

  66              $xmlrpcString,        // blogid
  67              $xmlrpcString,        // username
  68              $xmlrpcString        // password
  69  
  70          ));
  71      $f_mt_getCategoryList_doc = 'Returns a list of all categories defined in the weblog';
  72  	function f_mt_getCategoryList($m) {
  73          $blogid =    _getScalar($m,0);
  74          $username =    _getScalar($m,1);
  75          $password =    _getScalar($m,2);
  76  
  77          return _mt_categoryList($blogid, $username, $password);
  78      }
  79  
  80      // mt.publishPost

  81      $f_mt_publishPost_sig = array(array(
  82              // return type

  83              $xmlrpcBoolean,        // true
  84  
  85              // params

  86              $xmlrpcString,        // itemid
  87              $xmlrpcString,        // username
  88              $xmlrpcString        // password
  89          ));
  90      $f_mt_publishPost_doc = 'Transfers an item from the "draft" state to the "published" state. For items that were published earlier, does nothing.';
  91  	function f_mt_publishPost($m) {
  92          $itemid        = intval(_getScalar($m, 0));
  93          $username    = _getScalar($m, 1);
  94          $password    = _getScalar($m, 2);
  95  
  96          return _mt_publishPost($itemid, $username, $password);
  97      }
  98  
  99      // mt.getPostCategories

 100      $f_mt_getPostCategories_sig = array(array(
 101          // return

 102          $xmlrpcArray,        // array of structs
 103          // parameters

 104          $xmlrpcString,        // itemid
 105          $xmlrpcString,        // username
 106          $xmlrpcString        // password
 107      ));
 108      $f_mt_getPostCategories_doc = 'Returns a list of all categories to which the post is assigned.';
 109  	function f_mt_getPostCategories($m) {
 110          $itemid        = intval(_getScalar($m, 0));
 111          $username    = _getScalar($m, 1);
 112          $password    = _getScalar($m, 2);
 113  
 114          return _mt_getPostCategories($itemid, $username, $password);
 115      }
 116  
 117      // mt.setPostCategories

 118      $f_mt_setPostCategories_sig = array(array(
 119          // return

 120          $xmlrpcBoolean,        // true
 121          // parameters

 122          $xmlrpcString,        // itemid
 123          $xmlrpcString,        // username
 124          $xmlrpcString,        // password
 125          $xmlrpcArray        // categories
 126      ));
 127      $f_mt_setPostCategories_doc = 'Sets the categories for a post. Only the primary category will be stored';
 128  	function f_mt_setPostCategories($m) {
 129          $itemid        = intval(_getScalar($m, 0));
 130          $username    = _getScalar($m, 1);
 131          $password    = _getScalar($m, 2);
 132  
 133          $categories = $m->getParam(3);
 134          $iSize = $categories->arraysize();
 135  
 136          $category = '';
 137          for ($i=0;$i<$iSize;$i++) {
 138              $struct = $categories->arraymem($i);
 139              $bPrimary = $struct->structmem('isPrimary');
 140              if ($bPrimary)
 141                  $bPrimary = $bPrimary->scalarval();
 142              else if (!$category)
 143                  $bPrimary = 1;    // "Using isPrimary to set the primary category is optional--

 144                                  // in the absence of this flag, the first struct in the array

 145                                  // will be assigned the primary category for the post." (MT doc)

 146              if ($bPrimary) {
 147                  $category = $struct->structmem('categoryId');
 148                  $category = $category->scalarval();
 149              }
 150  
 151          }
 152  
 153          return _mt_setPostCategories($itemid, $username, $password, $category);
 154      }
 155  
 156      // mt.getRecentPostTitles

 157      $f_mt_getRecentPostTitles_sig = array(array(
 158          // return

 159          $xmlrpcArray,        // array of structs
 160          // params

 161          $xmlrpcString,        // blogid
 162          $xmlrpcString,        // userid
 163          $xmlrpcString,        // password,
 164          $xmlrpcInt            // number of posts
 165      ));
 166      $f_mt_getRecentPostTitles_doc = 'Returns a bandwidth-friendly list of the most recent posts in the system.';
 167  	function f_mt_getRecentPostTitles($m) {
 168          $blogid        = intval(_getScalar($m, 0));
 169          $username    = _getScalar($m, 1);
 170          $password    = _getScalar($m, 2);
 171          $iAmount    = intval(_getScalar($m, 3));
 172  
 173          return _mt_getRecentPostTitles($blogid, $username, $password, $iAmount);
 174      }
 175  
 176      // mt.getTrackbackPings

 177      $f_mt_getTrackbackPings_sig = array(array(
 178          // return

 179          $xmlrpcArray,        // array of structs
 180          // params

 181          $xmlrpcString        // postid
 182      ));
 183      $f_mt_getTrackbackPings_doc = '(this is currently just a placeholder. It returns an empty array.)';
 184  	function f_mt_getTrackbackPings($m) {
 185          global $manager;
 186          
 187          $itemid = intval(_getScalar($m, 0));
 188  
 189          $trackbacks = array ();
 190          $tbstruct   = array ();
 191              
 192          $manager->notify('RetrieveTrackback', array ('tb_id' => $itemid, 'trackbacks' => & $trackbacks));
 193                  
 194          while (list(,$v) = each ($trackbacks)) {
 195              $tbstruct[] = new xmlrpcval(
 196                  array(
 197                      "pingTitle" => new xmlrpcval($v['title'], "string"),
 198                      "pingURL"   => new xmlrpcval($v['url'], "string"),
 199                      "pingIP"    => new xmlrpcval($v['ip'], "string")
 200                  )
 201              ,'struct');            
 202          }        
 203                  
 204          return new xmlrpcresp(new xmlrpcval( $tbstruct , "array"));
 205      }
 206  
 207      $functionDefs = array_merge($functionDefs,
 208          array(
 209               "mt.supportedMethods" =>
 210               array( "function" => "f_mt_supportedMethods",
 211                  "signature" => $f_mt_supportedMethods_sig,
 212                  "docstring" => $f_mt_supportedMethods_doc),
 213  
 214               "mt.supportedTextFilters" =>
 215               array( "function" => "f_mt_supportedTextFilters",
 216                  "signature" => $f_mt_supportedTextFilters_sig,
 217                  "docstring" => $f_mt_supportedTextFilters_doc),
 218  
 219               "mt.getCategoryList" =>
 220               array( "function" => "f_mt_getCategoryList",
 221                  "signature" => $f_mt_getCategoryList_sig,
 222                  "docstring" => $f_mt_getCategoryList_doc),
 223  
 224               "mt.publishPost" =>
 225               array( "function" => "f_mt_publishPost",
 226                  "signature" => $f_mt_publishPost_sig,
 227                  "docstring" => $f_mt_publishPost_doc),
 228  
 229               "mt.getPostCategories" =>
 230               array( "function" => "f_mt_getPostCategories",
 231                  "signature" => $f_mt_getPostCategories_sig,
 232                  "docstring" => $f_mt_getPostCategories_doc),
 233  
 234               "mt.setPostCategories" =>
 235               array( "function" => "f_mt_setPostCategories",
 236                  "signature" => $f_mt_setPostCategories_sig,
 237                  "docstring" => $f_mt_setPostCategories_doc),
 238  
 239               "mt.getRecentPostTitles" =>
 240               array( "function" => "f_mt_getRecentPostTitles",
 241                  "signature" => $f_mt_getRecentPostTitles_sig,
 242                  "docstring" => $f_mt_getRecentPostTitles_doc),
 243  
 244               "mt.getTrackbackPings" =>
 245               array( "function" => "f_mt_getTrackbackPings",
 246                  "signature" => $f_mt_getTrackbackPings_sig,
 247                  "docstring" => $f_mt_getTrackbackPings_doc)
 248  
 249          )
 250      );
 251  
 252  	function _mt_setPostCategories($itemid, $username, $password, $category) {
 253          global $manager;
 254  
 255          // login

 256          $mem = new MEMBER();
 257          if (!$mem->login($username, $password))
 258              return _error(1,"Could not log in");
 259  
 260          // check if item exists

 261          if (!$manager->existsItem($itemid,1,1))
 262              return _error(6,"No such item ($itemid)");
 263  
 264          $blogid = getBlogIDFromItemID($itemid);
 265          $blog = new BLOG($blogid);
 266  
 267          if (!$mem->canAlterItem($itemid))
 268              return _error(7,"Not allowed to alter item");
 269  
 270          $old =& $manager->getItem($itemid,1,1);
 271  
 272          $catid = $blog->getCategoryIdFromName($category);
 273  
 274          $publish = 0;
 275          if ($old['draft'] && $publish) {
 276              $wasdraft = 1;
 277              $publish = 1;
 278          } else {
 279              $wasdraft = 0;
 280          }
 281  
 282          return _edititem($itemid, $username, $password, $catid, $old['title'], $old['body'], $old['more'], $wasdraft, $publish, $old['closed']);
 283      }
 284  
 285  
 286  	function _mt_getPostCategories($itemid, $username, $password) {
 287          global $manager;
 288  
 289          // login

 290          $mem = new MEMBER();
 291          if (!$mem->login($username, $password))
 292              return _error(1,"Could not log in");
 293  
 294          // check if item exists

 295          if (!$manager->existsItem($itemid,1,1))
 296              return _error(6,"No such item ($itemid)");
 297  
 298          $blogid = getBlogIDFromItemID($itemid);
 299          $blog = new BLOG($blogid);
 300  
 301          if (!$mem->canAlterItem($itemid))
 302              return _error(7, 'You are not allowed to request this information');
 303  
 304          $info =& $manager->getItem($itemid,1,1);
 305          $catName = $blog->getCategoryName($info['catid']);
 306  
 307          $struct = new xmlrpcval(
 308              array(
 309                  'categoryId' => new xmlrpcval($catName, 'string'),
 310                  'categoryName' => new xmlrpcval($catName, 'string'),
 311                  'isPrimary'    => new xmlrpcval(1, 'boolean')
 312              ), 'struct'
 313          );
 314  
 315          return new xmlrpcresp(new xmlrpcval(array($struct), 'array'));
 316  
 317      }
 318  
 319  	function _mt_publishPost($itemid, $username, $password) {
 320          global $manager;
 321  
 322          if (!$manager->existsItem($itemid,1,1))
 323              return _error(6,"No such item ($itemid)");
 324  
 325          // get item data

 326          $blogid = getBlogIDFromItemID($itemid);
 327          $blog = new BLOG($blogid);
 328          $old =& $manager->getItem($itemid,1,1);
 329  
 330          return _edititem($itemid, $username, $password, $old['catid'], $old['title'], $old['body'], $old['more'], $old['draft'], 1, $old['closed']);
 331      }
 332  
 333  
 334  	function _mt_categoryList($blogid, $username, $password) {
 335          // 1. login

 336          $mem = new MEMBER();
 337          if (!$mem->login($username, $password))
 338              return _error(1,"Could not log in");
 339  
 340          // check if on team and blog exists

 341          if (!BLOG::existsID($blogid))
 342              return _error(2,"No such blog ($blogid)");
 343          if (!$mem->teamRights($blogid))
 344              return _error(3,"Not a team member");
 345  
 346          $b = new BLOG($blogid);
 347  
 348          $categorystruct = array();
 349  
 350          $query =  "SELECT cname, cdesc, catid"
 351                  . ' FROM '.sql_table('category')
 352                  . " WHERE cblog=" . intval($blogid)
 353                  . " ORDER BY cname";
 354          $r = sql_query($query);
 355  
 356          while ($obj = sql_fetch_object($r)) {
 357  
 358              $categorystruct[] = new xmlrpcval(
 359                  array(
 360                      "categoryName" => new xmlrpcval($obj->cname,"string"),
 361                      "categoryId" => new xmlrpcval($obj->cname,"string")
 362                  )
 363              ,'struct');
 364  
 365          }
 366  
 367  
 368          return new xmlrpcresp(new xmlrpcval( $categorystruct , "array"));
 369  
 370      }
 371  
 372  	function _mt_getRecentPostTitles($blogid, $username, $password, $iAmount)
 373      {
 374          $blogid = intval($blogid);
 375          $iAmount = intval($iAmount);
 376  
 377          // 1. login

 378          $mem = new MEMBER();
 379          if (!$mem->login($username, $password))
 380              return _error(1,"Could not log in");
 381  
 382          // 2. check if allowed

 383          if (!BLOG::existsID($blogid))
 384              return _error(2,"No such blog ($blogid)");
 385          if (!$mem->teamRights($blogid))
 386              return _error(3,"Not a team member");
 387          $iAmount = intval($iAmount);
 388          if ($iAmount < 1)
 389              return _error(5,"Amount parameter must be positive");
 390  
 391          // 3. create and return list of recent items

 392          // Struct returned has dateCreated, userid, postid and title

 393  
 394          $blog = new BLOG($blogid);
 395  
 396          $structarray = array();        // the array in which the structs will be stored

 397  
 398          $query = "SELECT inumber, ititle as title, itime, iauthor"
 399                 .' FROM '.sql_table('item')
 400                 ." WHERE iblog=$blogid"
 401                 ." ORDER BY itime DESC"
 402                 ." LIMIT $iAmount";
 403          $r = sql_query($query);
 404  
 405          while ($row = sql_fetch_assoc($r)) {
 406  
 407              $newstruct = new xmlrpcval(array(
 408                  "dateCreated" => new xmlrpcval(iso8601_encode(strtotime($row['itime'])),"dateTime.iso8601"),
 409                  "postid" => new xmlrpcval($row['inumber'],"string"),
 410                  "title" => new xmlrpcval($row['title'],"string"),
 411                  "userid" => new xmlrpcval($row['iauthor'],"string")
 412              ),'struct');
 413  
 414              array_push($structarray, $newstruct);
 415          }
 416  
 417          return new xmlrpcresp(new xmlrpcval( $structarray , "array"));
 418  
 419      }
 420  
 421  
 422  
 423  ?>


Generated: Sun Aug 1 03:56:06 2010
Open Source related documentation for developers.