b2evolution PHP Cross Reference Blogging Systems

Source: /inc/xmlrpc/apis/_mt.api.php - 319 lines - 9502 bytes - Summary - Text - Print

Description: XML-RPC : Movable Type API (partial)

   1  <?php
   2  /**
   3   * XML-RPC : Movable Type API (partial)
   4   *
   5   * b2evolution - {@link http://b2evolution.net/}
   6   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
   7   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   8   *
   9   * @author tor
  10   * @author tblue246 (Tilman BLUMENBACH)
  11   * @author waltercruz
  12   *
  13   * @see http://b2evolution.net/man/movabletype-api
  14   *
  15   * @package xmlsrv
  16   *
  17   * @version $Id: _mt.api.php 6136 2014-03-08 07:59:48Z manuel $
  18   */
  19  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  20  
  21  
  22  
  23  $mt_supportedMethods_sig = array( array( $xmlrpcArray ) );
  24  $mt_supportedMethods_doc = 'Returns methods supported by the server.';
  25  function mt_supportedMethods()
  26  {
  27      return new xmlrpcresp( new xmlrpcval( array(
  28                      new xmlrpcval( 'mt.supportedMethods', 'string' ),
  29                      new xmlrpcval( 'mt.setPostCategories', 'string' ),
  30                      new xmlrpcval( 'mt.getPostCategories', 'string' ),
  31                      new xmlrpcval( 'mt.getCategoryList', 'string' ),
  32                      new xmlrpcval( 'mt.publishPost', 'string' ),
  33                  ), 'array' ) );
  34  }
  35  
  36  
  37  
  38  $mt_setPostCategories_sig = array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcArray));
  39  $mt_setPostCategories_doc = 'Sets the categories for a post.';
  40  /**
  41   * mt.setPostCategories : set cats for a post
  42   *
  43   * @param xmlrpcmsg XML-RPC Message
  44   *                    0 postid (string): Unique identifier of the post to edit
  45   *                    1 username (string): Login for a Blogger user who is member of the blog.
  46   *                    2 password (string): Password for said username.
  47   */
  48  function mt_setPostCategories($m)
  49  {
  50      // CHECK LOGIN:
  51      /**
  52       * @var User
  53       */
  54      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
  55      {    // Login failed, return (last) error:
  56          return xmlrpcs_resperror();
  57      }
  58  
  59      // GET POST:
  60      /**
  61       * @var Item
  62       */
  63      if( ! $edited_Item = & xmlrpcs_get_Item( $m, 0 ) )
  64      {    // Failed, return (last) error:
  65          return xmlrpcs_resperror();
  66      }
  67  
  68      if( ! $current_User->check_perm( 'item_post!CURSTATUS', 'edit', false, $edited_Item ) )
  69      {    // Permission denied
  70          return xmlrpcs_resperror( 3 );
  71      }
  72  
  73      $xcontent = $m->getParam(3); // This is now an array of structs
  74      $contentstruct = xmlrpc_decode_recurse($xcontent);
  75      logIO('Decoded xcontent');
  76  
  77      $categories = array();
  78      $category = NULL;
  79      foreach( $contentstruct as $catstruct )
  80      {
  81          logIO( 'Category ID: '.$catstruct['categoryId'] ) ;
  82          if( !empty($catstruct['isPrimary']) )
  83          {
  84              $category = $catstruct['categoryId'];
  85              logIO('got primary category and there should only be one... '.$category);
  86          }
  87          $categories[] = $catstruct['categoryId'];
  88      }
  89  
  90      if( empty( $categories ) )
  91      {
  92          return xmlrpcs_resperror( 4, 'No categories specified.' );
  93      }
  94      else if( empty( $category ) )
  95      {    // Use first one as default:
  96          $category = $categories[0];
  97      }
  98  
  99      // Check if category exists and can be used:
 100      $Blog = & $edited_Item->get_Blog();
 101      if( ! xmlrpcs_check_cats( $category, $Blog, $categories ) )
 102      {    // Error:
 103          return xmlrpcs_resperror();
 104      }
 105  
 106      // CHECK PERMISSION: (we need perm on all categories, especially if they are in different blogs)
 107      if( ! $current_User->check_perm( 'cats_post!'.$edited_Item->status, 'edit', false, $categories ) )
 108      {    // Permission denied
 109          return xmlrpcs_resperror( 3 );    // User error 3
 110      }
 111      logIO( 'Permission granted.' );
 112  
 113      logIO( 'Main Cat: '.$category.' - Other: '.implode(',',$categories) );
 114  
 115      // UPDATE POST CATEGORIES IN DB:
 116      $edited_Item->set( 'main_cat_ID', $category );
 117      $edited_Item->set( 'extra_cat_IDs', $categories );
 118  
 119      if( $edited_Item->dbupdate() === false )
 120      {
 121          logIO( 'Update failed.' );
 122          return xmlrpcs_resperror( 99, 'Update failed.' );
 123      }
 124  
 125      logIO( 'OK.' );
 126      return new xmlrpcresp( new xmlrpcval( 1, 'boolean' ) );
 127  }
 128  
 129  
 130  
 131  $mt_getPostCategories_sig = array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString));
 132  $mt_getPostCategories_doc = 'Returns a list of all categories to which the post is assigned.';
 133  /**
 134   * mt.getPostCategories : Get the categories for a given post.
 135   *
 136   * @param xmlrpcmsg XML-RPC Message
 137   *                    0 postid (string): Unique identifier of the post to query
 138   *                    1 username (string): Login for a Blogger user who is member of the blog.
 139   *                    2 password (string): Password for said username.
 140   */
 141  function mt_getPostCategories($m)
 142  {
 143      global $DB;
 144  
 145      // CHECK LOGIN:
 146      /**
 147       * @var User
 148       */
 149      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 150      {    // Login failed, return (last) error:
 151          return xmlrpcs_resperror();
 152      }
 153  
 154      // GET POST:
 155      /**
 156       * @var Item
 157       */
 158      if( ! $edited_Item = & xmlrpcs_get_Item( $m, 0 ) )
 159      {    // Failed, return (last) error:
 160          return xmlrpcs_resperror();
 161      }
 162  
 163      // CHECK PERMISSION (user needs to be able to view the post):
 164      if( ! xmlrpcs_can_view_item( $edited_Item, $current_User ) )
 165      {    // Permission denied
 166          return xmlrpcs_resperror( 3 );    // User error 3
 167      }
 168  
 169      // Tblue> TODO: We could save one DB query by using our own custom query
 170      //              instead of postcats_get_byID().
 171      $categories = postcats_get_byID( $edited_Item->ID ); // Secondary categories
 172      $iSize = count($categories); // The number of objects ie categories
 173      logIO('mt_getPostCategories  no. of categories... '.$iSize);// works
 174      $struct = array();
 175      for( $i=0; $i<$iSize; $i++)
 176      {
 177          logIO('mt_getPostCategories categories  ...'.$categories[$i]);
 178          // In database cat_ID and cat_name from tablecategories
 179          $sql = 'SELECT * FROM T_categories WHERE  cat_ID = '.$categories[$i];
 180          logIO('mt_getPostCategories  sql...'.$sql);
 181          $rows = $DB->get_results( $sql );
 182          foreach( $rows as $row )
 183          {
 184              $Categoryname =  $row->cat_name;
 185              logIO('mt_getPostCategories Categoryname  ...'.$Categoryname);
 186          }
 187  
 188          // Is this the primary cat?
 189          $isPrimary = ($categories[$i] == $edited_Item->main_cat_ID) ? 1 : 0;
 190  
 191          $struct[$i] = new xmlrpcval(array('categoryId' => new xmlrpcval($categories[$i]),    // Look up name from ID separately
 192                                          'categoryName' => new xmlrpcval($Categoryname),
 193                                          'isPrimary' => new xmlrpcval($isPrimary, 'boolean'),
 194                                          ),'struct');
 195      }
 196  
 197       logIO( 'OK.' );
 198      return new xmlrpcresp(new xmlrpcval($struct, 'array') );
 199  }
 200  
 201  
 202  
 203  $mt_getCategoryList_sig =  array(array($xmlrpcArray,$xmlrpcString,$xmlrpcString,$xmlrpcString));
 204  $mt_getCategoryList_doc = 'Get category list';
 205  /**
 206   * mt.getCategoryList
 207   *
 208   * @see http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtgetcategorylist.html
 209   *
 210   * @param xmlrpcmsg XML-RPC Message
 211   *                    0 blogid (string): Unique identifier of the blog to query
 212   *                    1 username (string): Login for a Blogger user who is member of the blog.
 213   *                    2 password (string): Password for said username.
 214   */
 215  function mt_getCategoryList($m)
 216  {
 217      logIO('mt_getCategoryList start');
 218      return _b2_or_mt_get_categories('mt', $m);
 219  }
 220  
 221  $mt_publishPost_sig =  array(array($xmlrpcBoolean,$xmlrpcString,$xmlrpcString,$xmlrpcString));
 222  $mt_publishPost_doc = 'Published a post';
 223  /**
 224   * mt.publishPost
 225   *
 226   * @see http://www.sixapart.com/developers/xmlrpc/movable_type_api/mtpublishpost.html
 227   *
 228   * @param xmlrpcmsg XML-RPC Message
 229   *                    0 postid (string): Unique identifier of the post to publish
 230   *                    1 username (string): Login for a user who is member of the blog.
 231   *                    2 password (string): Password for said username.
 232   */
 233  function mt_publishPost($m)
 234  {
 235      global $localtimenow, $DB;
 236  
 237      // CHECK LOGIN:
 238      /**
 239       * @var User
 240       */
 241      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 242      {    // Login failed, return (last) error:
 243          return xmlrpcs_resperror();
 244      }
 245      logIO( 'mt_publishPost: Login OK' );
 246  
 247      // GET POST:
 248      /**
 249       * @var Item
 250       */
 251      if( ! $edited_Item = & xmlrpcs_get_Item( $m, 0 ) )
 252      {    // Failed, return (last) error:
 253          return xmlrpcs_resperror();
 254      }
 255  
 256      if( ! $current_User->check_perm( 'item_post!published', 'edit', false, $edited_Item )
 257          /*|| ! $current_User->check_perm( 'edit_timestamp' )*/ )
 258      {
 259          return xmlrpcs_resperror( 3 ); // Permission denied
 260      }
 261      logIO('mt_publishPost: Permission granted');
 262  
 263      logIO( 'mt_publishPost: Old post status: '.$edited_Item->status );
 264      $edited_Item->set( 'status', 'published' );
 265      //$edited_Item->set( 'datestart', date('Y-m-d H:i:s', $localtimenow) );
 266  
 267      if( $edited_Item->dbupdate() === false )
 268      {    // Could not update item...
 269          return xmlrpcs_resperror( 99, 'Database error: '.$DB->last_error ); // DB error
 270      }
 271      logIO('mt_publishPost: Item published.');
 272  
 273      // Execute or schedule notifications & pings:
 274      logIO( 'mt_publishPost: Handling notifications...' );
 275      $edited_Item->handle_post_processing( false, false );
 276  
 277      logIO( 'mt_publishPost: OK.' );
 278  
 279      return new xmlrpcresp( new xmlrpcval( 1, 'boolean' ) );
 280  }
 281  
 282  
 283  $xmlrpc_procs['mt.supportedMethods'] = array(
 284                  'function' => 'mt_supportedMethods',
 285                  'signature' => $mt_supportedMethods_sig,
 286                  'docstring' => $mt_supportedMethods_doc );
 287  
 288  $xmlrpc_procs['mt.getCategoryList'] = array(
 289                  'function' => 'mt_getCategoryList',
 290                  'signature' => $mt_getCategoryList_sig,
 291                  'docstring' => $mt_getCategoryList_doc );
 292  
 293  $xmlrpc_procs['mt.setPostCategories'] = array(
 294                  'function' => 'mt_setPostCategories',
 295                  'signature' => $mt_setPostCategories_sig,
 296                  'docstring' => $mt_setPostCategories_doc );
 297  
 298  $xmlrpc_procs['mt.getPostCategories'] = array(
 299                  'function' => 'mt_getPostCategories',
 300                  'signature' => $mt_getPostCategories_sig,
 301                  'docstring' => $mt_getPostCategories_doc );
 302  
 303  $xmlrpc_procs['mt.publishPost'] = array(
 304                  'function' => 'mt_publishPost',
 305                  'signature' => $mt_publishPost_sig,
 306                  'docstring' => $mt_publishPost_doc );
 307  
 308  
 309  /*
 310      Missing:
 311  
 312      - mt.supportedTextFilters
 313      - mt.getTrackbackPings
 314      - mt.getRecentPostTitles
 315  
 316      http://www.sixapart.com/developers/xmlrpc/movable_type_api/
 317  */
 318  
 319  ?>

title

Description

title

Description

title

Description

title

title

Body