b2evolution PHP Cross Reference Blogging Systems

Source: /inc/xmlrpc/apis/_wordpress.api.php - 1549 lines - 44289 bytes - Summary - Text - Print

Description: XML-RPC : Wordpress API b2evolution - {@link http://b2evolution.net/} Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   1  <?php
   2  /**
   3   * XML-RPC : Wordpress API
   4   *
   5   * b2evolution - {@link http://b2evolution.net/}
   6   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
   7   * @copyright (c)2009-2014 by Francois PLANQUE - {@link http://fplanque.net/}
   8   *
   9   * @author waltercruz
  10   *
  11   * @see http://codex.wordpress.org/XML-RPC_wp
  12   *
  13   * @package xmlsrv
  14   * @version $Id: _wordpress.api.php 6136 2014-03-08 07:59:48Z manuel $
  15   */
  16  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  17  
  18  
  19  $wordpressgetusersblogs_doc = 'returns information about all the blogs a given user is a member of.';
  20  $wordpressgetusersblogs_sig = array(array($xmlrpcArray,$xmlrpcString,$xmlrpcString));
  21  /**
  22   * wp.getUsersBlogs
  23   *
  24   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getUsersBlogs
  25   *
  26   * Data is returned as an array of <struct>s containing the ID (blogid), name (blogName),
  27   * and URL (url) of each blog.
  28   *
  29   * Non official: Also return a boolean stating wether or not the user can edit the blog options
  30   * (isAdmin). Also return a value for xmlrpc url.
  31   *
  32   * @param xmlrpcmsg XML-RPC Message
  33   *                    0 username (string): Login for the Blogger user who's blogs will be retrieved.
  34   *                    1 password (string): Password for said username.
  35   *                        (currently not required by b2evo)
  36   * @return xmlrpcresp XML-RPC Response, an array of <struct>s containing for each blog:
  37   *                    - isAdmin (boolean)
  38   *                    - url (string)
  39   *                    - blogid (string)
  40   *                    - blogName (string)
  41   *                    - xmlrpc (string)
  42   */
  43  function wp_getusersblogs($m)
  44  {
  45      return _wp_or_blogger_getusersblogs( 'wp', $m );
  46  }
  47  
  48  
  49  $wordpressgetauthors_doc = 'Retrieve list of all authors.';
  50  $wordpressgetauthors_sig = array(array($xmlrpcArray,$xmlrpcInt,$xmlrpcString,$xmlrpcString));
  51  /**
  52   * wp.getAuthors
  53   *
  54   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getAuthors
  55   *
  56   * @param xmlrpcmsg XML-RPC Message
  57   *                    0 blogid (int): Unique identifier of the blog.
  58   *                    1 username (string): User login.
  59   *                    2 password (string): Password for said username.
  60  
  61   */
  62  function wp_getauthors($m)
  63  {
  64      // CHECK LOGIN:
  65      /**
  66       * @var User
  67       */
  68      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
  69      {    // Login failed, return (last) error:
  70          return xmlrpcs_resperror();
  71      }
  72  
  73      // GET BLOG:
  74      /**
  75       * @var Blog
  76       */
  77      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
  78      {    // Login failed, return (last) error:
  79          return xmlrpcs_resperror();
  80      }
  81  
  82      if( ! $current_User->check_perm('users', 'view') )
  83      {
  84          return xmlrpcs_resperror( 5, T_('You have no permission to view other users!') );
  85      }
  86  
  87      load_class( 'users/model/_userlist.class.php', 'UserList' );
  88      $UserList = new UserList( '', NULL, 'u_', array( 'join_group' => false, 'join_session' => false, 'join_country' => false, 'join_city' => false ) );
  89  
  90      // Run the query:
  91      $UserList->query();
  92  
  93      logIO( 'Found users: '.$UserList->result_num_rows );
  94  
  95      $data = array();
  96      while( $User = & $UserList->get_next() )
  97      {
  98          $data[] = new xmlrpcval(array(
  99                  'user_id' => new xmlrpcval( $User->ID, 'int' ),
 100                  'user_login' => new xmlrpcval( $User->login ),
 101                  'display_name' => new xmlrpcval( $User->get_preferred_name() ),
 102              ),'struct');
 103      }
 104  
 105      logIO( 'OK.' );
 106      return new xmlrpcresp( new xmlrpcval( $data, 'array' ) );
 107  }
 108  
 109  
 110  $wordpressgettags_doc = 'Get list of all tags.';
 111  $wordpressgettags_sig =  array(array($xmlrpcArray,$xmlrpcInt,$xmlrpcString,$xmlrpcString));
 112  /**
 113   * wp.getTags
 114   *
 115   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getTags
 116   *
 117   * @param xmlrpcmsg XML-RPC Message
 118   *                    0 blogid (int): Unique identifier of the blog.
 119   *                    1 username (string): User login.
 120   *                    2 password (string): Password for said username.
 121   */
 122  function wp_gettags( $m )
 123  {
 124      // CHECK LOGIN:
 125      /**
 126       * @var User
 127       */
 128      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 129      {    // Login failed, return (last) error:
 130          return xmlrpcs_resperror();
 131      }
 132  
 133      // GET BLOG:
 134      /**
 135       * @var Blog
 136       */
 137      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
 138      {    // Login failed, return (last) error:
 139          return xmlrpcs_resperror();
 140      }
 141  
 142      $data = array();
 143      $tags = get_tags( $Blog->ID );
 144  
 145      if( !empty($tags) )
 146      {
 147          logIO( 'Got '.count($tags).' tags' );
 148  
 149          load_funcs( '_core/_url.funcs.php' );
 150  
 151          $BlogCache = & get_BlogCache();
 152  
 153          foreach( $tags as $tag )
 154          {
 155              if( ($l_Blog = & $BlogCache->get_by_id( $tag->cat_blog_ID, false )) === false ) continue;
 156  
 157              $tag_url = $l_Blog->gen_tag_url($tag->tag_name);
 158  
 159              $data[] = new xmlrpcval(array(
 160                      'tag_id' => new xmlrpcval( $tag->tag_ID, 'int' ),
 161                      'name' => new xmlrpcval( $tag->tag_name ),
 162                      'count' => new xmlrpcval( $tag->tag_count, 'int'),
 163                      'slug' => new xmlrpcval(''), // not used in b2evolution
 164                      'html_url' => new xmlrpcval( $tag_url ),
 165                      'rss_url' => new xmlrpcval( url_add_param($tag_url, 'tempskin=_rss2', '&') ),
 166                  ),'struct');
 167          }
 168      }
 169  
 170      logIO( 'OK.' );
 171      return new xmlrpcresp( new xmlrpcval( $data, 'array' ) );
 172  }
 173  
 174  
 175  $wordpressgetpagelist_doc = 'Get an array of all the pages on a blog. Just the minimum details, lighter than wp.getPages.';
 176  $wordpressgetpagelist_sig =  array(array($xmlrpcArray,$xmlrpcInt,$xmlrpcString,$xmlrpcString));
 177  /**
 178   * wp.getPageList
 179   *
 180   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getPageList
 181   *
 182   * @param xmlrpcmsg XML-RPC Message
 183   *                    0 blogid (int): Unique identifier of the blog.
 184   *                    1 username (string): User login.
 185   *                    2 password (string): Password for said username.
 186   */
 187  function wp_getpagelist( $m )
 188  {
 189      // CHECK LOGIN:
 190      /**
 191       * @var User
 192       */
 193      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 194      {    // Login failed, return (last) error:
 195          return xmlrpcs_resperror();
 196      }
 197  
 198      // GET BLOG:
 199      /**
 200       * @var Blog
 201       */
 202      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
 203      {    // Login failed, return (last) error:
 204          return xmlrpcs_resperror();
 205      }
 206  
 207      // Get the pages to display:
 208      load_class( 'items/model/_itemlistlight.class.php', 'ItemListLight' );
 209      $MainList = new ItemListLight( $Blog, NULL, NULL, 0 );
 210  
 211      // Protected and private get checked by statuses_where_clause().
 212      $statuses = array( 'published', 'redirected', 'protected', 'private' );
 213      if( $current_User->check_perm( 'blog_ismember', 'view', false, $Blog->ID ) )
 214      {    // These statuses require member status:
 215          $statuses = array_merge( $statuses, array( 'draft', 'deprecated' ) );
 216      }
 217      logIO( 'Statuses: '.implode( ', ', $statuses ) );
 218  
 219      $MainList->set_filters( array(
 220              'visibility_array' => $statuses,
 221              'order' => 'DESC',
 222              'unit' => 'posts',
 223              'types' => '1000',
 224          ) );
 225  
 226      // Run the query:
 227      $MainList->query();
 228  
 229      logIO( 'Items:'.$MainList->result_num_rows );
 230  
 231      $data = array();
 232      while( $Item = & $MainList->get_item() )
 233      {
 234          logIO( 'Item:'.$Item->title.
 235                      ' - Issued: '.$Item->issue_date.
 236                      ' - Modified: '.$Item->datemodified );
 237  
 238          $data[] = new xmlrpcval(array(
 239                  'page_id' => new xmlrpcval($Item->ID, 'int'),
 240                  'page_title' => new xmlrpcval($Item->title),
 241                  'page_parent_id' => new xmlrpcval( (isset($Item->parent_ID) ? $Item->parent_ID : 0), 'int'),
 242                  'dateCreated' => new xmlrpcval( datetime_to_iso8601($Item->issue_date), 'dateTime.iso8601' ),
 243                  'date_created_gmt' => new xmlrpcval( datetime_to_iso8601($Item->issue_date, true), 'dateTime.iso8601' ),
 244              ),'struct');
 245      }
 246  
 247      logIO( 'OK.' );
 248      return new xmlrpcresp( new xmlrpcval( $data, 'array' ) );
 249  }
 250  
 251  
 252  $wordpressgetpages_doc = 'Get an array of all the pages on a blog.';
 253  $wordpressgetpages_sig =  array(array($xmlrpcArray,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcInt));
 254  /**
 255   * wp.getPages
 256   *
 257   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getPages
 258   *
 259   * @param xmlrpcmsg XML-RPC Message
 260   *                    0 blogid (int): Unique identifier of the blog.
 261   *                    1 username (string): User login.
 262   *                    2 password (string): Password for said username.
 263   *                    3 max_pages (int) optional, default=10.
 264   */
 265  function wp_getpages( $m )
 266  {
 267      logIO( 'wp_getpages start' );
 268  
 269      // CHECK LOGIN:
 270      /**
 271       * @var User
 272       */
 273      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 274      {    // Login failed, return (last) error:
 275          return xmlrpcs_resperror();
 276      }
 277  
 278      // GET BLOG:
 279      /**
 280       * @var Blog
 281       */
 282      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
 283      {    // Login failed, return (last) error:
 284          return xmlrpcs_resperror();
 285      }
 286  
 287      $limit = $m->getParam(3);
 288      $limit = abs($limit->scalarval());
 289  
 290      $items = xmlrpc_get_items( array(
 291              'limit' => $limit,
 292              'types' => '1000',
 293          ), $Blog );
 294  
 295      if( empty($items) )
 296      {
 297          return new xmlrpcresp( new xmlrpcval( array(), 'array' ) );
 298      }
 299  
 300      $data = array();
 301      foreach( $items as $item )
 302      {
 303          $data[] = new xmlrpcval( $item, 'struct' );
 304      }
 305  
 306      logIO( 'OK.' );
 307      return new xmlrpcresp( new xmlrpcval( $data, 'array' ) );
 308  }
 309  
 310  
 311  $wordpressgetpage_doc = 'Get the page identified by the page id.';
 312  $wordpressgetpage_sig =  array(array($xmlrpcArray,$xmlrpcInt,$xmlrpcInt,$xmlrpcString,$xmlrpcString));
 313  /**
 314   * wp.getPage
 315   *
 316   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getPage
 317   *
 318   * @param xmlrpcmsg XML-RPC Message
 319   *                    0 blogid (int): Unique identifier of the blog.
 320   *                    1 page_id (int): Requested page ID.
 321   *                    2 username (string): User login.
 322   *                    3 password (string): Password for said username.
 323   */
 324  function wp_getpage( $m )
 325  {
 326      logIO( 'wp_getpage start' );
 327  
 328      // CHECK LOGIN:
 329      /**
 330       * @var User
 331       */
 332      if( ! $current_User = & xmlrpcs_login( $m, 2, 3 ) )
 333      {    // Login failed, return (last) error:
 334          return xmlrpcs_resperror();
 335      }
 336  
 337      // GET BLOG:
 338      /**
 339       * @var Blog
 340       */
 341      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
 342      {    // Login failed, return (last) error:
 343          return xmlrpcs_resperror();
 344      }
 345  
 346      $item_ID = $m->getParam(1);
 347      $item_ID = abs($item_ID->scalarval());
 348  
 349      $items = xmlrpc_get_items( array(
 350              'item_ID' => $item_ID,
 351          ), $Blog );
 352  
 353      if( empty($items) )
 354      {
 355          return xmlrpcs_resperror( 6, 'Requested post/Item ('.$item_ID.') does not exist.' );
 356      }
 357  
 358      logIO( 'OK.' );
 359      return new xmlrpcresp( new xmlrpcval( $items[0], 'struct' ) );
 360  }
 361  
 362  $wordpressgetpagestatuslist_doc = 'Retrieve all of the WordPress supported page statuses.';
 363  $wordpressgetpoststatuslist_doc = 'Retrieve post statuses.';
 364  $wordpressgetpagestatuslist_sig =  array(array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString));
 365  /**
 366   * wp.getPageStatusList
 367   * wp.getPostStatusList
 368   *
 369   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getPageStatusList
 370   *
 371   * @param xmlrpcmsg XML-RPC Message
 372   *                    0 blogid (int): Unique identifier of the blog.
 373   *                    1 username (string): User login.
 374   *                    2 password (string): Password for said username.
 375   */
 376  function wp_getpagestatuslist( $m )
 377  {
 378      // CHECK LOGIN:
 379      /**
 380       * @var User
 381       */
 382      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 383      {    // Login failed, return (last) error:
 384          return xmlrpcs_resperror();
 385      }
 386  
 387      // GET BLOG:
 388      /**
 389       * @var Blog
 390       */
 391      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
 392      {    // Login failed, return (last) error:
 393          return xmlrpcs_resperror();
 394      }
 395  
 396      $status_list = array();
 397  
 398      if( $current_User->check_perm( 'blog_post!published', 'edit', false, $Blog->ID ) )
 399      {
 400          $status_list[ wp_or_b2evo_item_status('published', 'wp') ] = new xmlrpcval(T_('Published')) ;
 401      }
 402  
 403      if( $current_User->check_perm( 'blog_post!protected', 'edit', false, $Blog->ID ) )
 404      {    // Not supported by WP, maps to 'private'
 405          $status_list[ wp_or_b2evo_item_status('protected', 'wp') ] = new xmlrpcval(T_('Protected')) ;
 406      }
 407  
 408      if( $current_User->check_perm( 'blog_post!private', 'edit', false, $Blog->ID ) )
 409      {
 410          $status_list[ wp_or_b2evo_item_status('private', 'wp') ] = new xmlrpcval(T_('Private')) ;
 411      }
 412  
 413      if( $current_User->check_perm( 'blog_post!draft', 'edit', false, $Blog->ID ) )
 414      {
 415          $status_list[ wp_or_b2evo_item_status('draft', 'wp') ] = new xmlrpcval(T_('Draft')) ;
 416      }
 417  
 418      if( $current_User->check_perm( 'blog_post!deprecated', 'edit', false, $Blog->ID ) )
 419      {
 420          $status_list[ wp_or_b2evo_item_status('deprecated', 'wp') ] = new xmlrpcval(T_('Deprecated')) ;
 421      }
 422  
 423      if( $current_User->check_perm( 'blog_post!redirected', 'edit', false, $Blog->ID ) )
 424      {    // Not supported by WP, maps to 'published'
 425          $status_list[ wp_or_b2evo_item_status('redirected', 'wp') ] = new xmlrpcval(T_('Redirected')) ;
 426      }
 427      return new xmlrpcresp(  new xmlrpcval($status_list,'struct') );
 428  }
 429  
 430  
 431  $wordpressgetpostformats_doc = 'Retrieve post formats.';
 432  $wordpressgetpostformats_sig =  array(
 433          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString), // WP for iOS
 434          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcStruct), // WP specs
 435      );
 436  /**
 437   * wp.getPostFormats
 438   *
 439   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getPostFormats
 440   *
 441   * Note: by default (no filter) we return supported formats only.
 442   *
 443   * @param xmlrpcmsg XML-RPC Message
 444   *                    0 blogid (int): Unique identifier of the blog.
 445   *                    1 username (string): User login.
 446   *                    2 password (string): Password for said username.
 447   *                    3 filter (struct):
 448   *                         - show-supported
 449   */
 450  function wp_getpostformats( $m )
 451  {
 452      // CHECK LOGIN:
 453      /**
 454       * @var User
 455       */
 456      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 457      {    // Login failed, return (last) error:
 458          return xmlrpcs_resperror();
 459      }
 460  
 461      // GET BLOG:
 462      /**
 463       * @var Blog
 464       */
 465      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
 466      {    // Login failed, return (last) error:
 467          return xmlrpcs_resperror();
 468      }
 469  
 470      if( isset($m->params[3]) )
 471      {
 472          $xcontent = $m->getParam(3);
 473          $contentstruct = xmlrpc_decode_recurse($xcontent);
 474      }
 475  
 476      global $posttypes_reserved_IDs, $posttypes_perms;
 477  
 478      // Compile an array of post type IDs to exclude:
 479      $exclude_posttype_IDs = $posttypes_reserved_IDs;
 480  
 481      foreach( $posttypes_perms as $l_permname => $l_posttype_IDs )
 482      {
 483          if( ! $current_User->check_perm( 'blog_'.$l_permname, 'edit', false, $Blog->ID ) )
 484          {    // No permission to use this post type(s):
 485              $exclude_posttype_IDs = array_merge( $exclude_posttype_IDs, $l_posttype_IDs );
 486          }
 487      }
 488  
 489      $saved_global = $posttypes_reserved_IDs; // save
 490      $posttypes_reserved_IDs = $exclude_posttype_IDs;
 491  
 492      $ItemTypeCache = & get_ItemTypeCache();
 493  
 494      $supported = $ItemTypeCache->get_option_array();
 495      ksort($supported);
 496  
 497      $posttypes_reserved_IDs = $saved_global; // restore
 498  
 499      $all = $ItemTypeCache->get_option_array();
 500      ksort($all);
 501  
 502      logIO( "All item types:\n".var_export($all, true) );
 503      logIO( "Supported item types:\n".var_export($supported, true) );
 504  
 505      $all_types = $supported_types = array();
 506      foreach( $all as $k=>$v )
 507      {
 508          $all_types[ strval($k) ] = new xmlrpcval($v);
 509      }
 510  
 511      foreach( $supported as $k=>$v )
 512      {
 513          $supported_types[ strval($k) ] = new xmlrpcval($v);
 514      }
 515  
 516      if( !empty($contentstruct) && is_array($contentstruct) )
 517      {    // Make sure there's a filter 'show-supported' that evaluates to TRUE
 518          if( isset($contentstruct['show-supported']) && $contentstruct['show-supported'] )
 519          {    // Display both 'all' and 'supported' post types
 520              $types = array(
 521                      'all'        => new xmlrpcval($all_types, 'struct'),
 522                      'supported'    => php_xmlrpc_encode( array_keys($supported_types) ),
 523                  );
 524  
 525              logIO('OK.');
 526              return new xmlrpcresp( new xmlrpcval($types, 'struct') );
 527          }
 528      }
 529  
 530      logIO('OK.');
 531      return new xmlrpcresp( new xmlrpcval($supported_types, 'struct') );
 532  }
 533  
 534  
 535  $wordpressnewpage_doc = 'Create a new page';
 536  $wordpressnewpage_sig = array(
 537          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcStruct),
 538          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcStruct,$xmlrpcBoolean),
 539      );
 540  /**
 541   * wp.newPage
 542   *
 543   * @see http://codex.wordpress.org/XML-RPC_wp#wp.newPage
 544   *
 545   * @param xmlrpcmsg XML-RPC Message
 546   *                    0 blogid (string): Unique identifier of the blog the post will be added to.
 547   *                        Currently ignored in b2evo, in favor of the category.
 548   *                    1 username (string): Login for a Blogger user who has permission to edit the given
 549   *                        post (either the user who originally created it or an admin of the blog).
 550   *                    2 password (string): Password for said username.
 551   *                    3 struct (struct)
 552   *                    4 publish (bool)
 553   */
 554  function wp_newpage( $m )
 555  {    // Call metaWeblog.newPost
 556      return mw_newpost( $m, 'page' );
 557  }
 558  
 559  
 560  $wordpresseditpage_doc = 'Make changes to a blog page';
 561  $wordpresseditpage_sig = array(
 562          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcStruct),
 563          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcStruct,$xmlrpcBoolean),
 564      );
 565  /**
 566   * wp.editPage
 567   *
 568   * @see http://codex.wordpress.org/XML-RPC_wp#wp.editPage
 569   *
 570   * @param xmlrpcmsg XML-RPC Message
 571   *                    0 blogid (string): Unique identifier of the blog the post will be added to.
 572   *                        Currently ignored in b2evo, in favor of the category.
 573   *                    1 postid (string): Unique identifier of the post to edit
 574   *                    2 username (string): Login for a Blogger user who has permission to edit the given
 575   *                        post (either the user who originally created it or an admin of the blog).
 576   *                    3 password (string): Password for said username.
 577   *                    4 struct (struct)
 578   *                    5 publish (bool)
 579   */
 580  function wp_editpage( $m )
 581  {
 582      // Arrange args in the way mw_editpost() understands.
 583      array_shift($m->params);
 584  
 585      // Call metaWeblog.editPost
 586      return mw_editpost( $m, 'page' );
 587  }
 588  
 589  
 590  $wordpressdeletepage_doc = 'Removes a page from the blog';
 591  $wordpressdeletepage_sig = array(array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcInt));
 592  /**
 593   * wp.deletePage
 594   *
 595   * @see http://codex.wordpress.org/XML-RPC_wp#wp.deletePage
 596   *
 597   * @param xmlrpcmsg XML-RPC Message
 598   *                    0 blogid (string): Unique identifier of the blog the post will be added to.
 599   *                        Currently ignored in b2evo, in favor of the category.
 600   *                    1 username (string): Login for a Blogger user who has permission to edit the given
 601   *                        post (either the user who originally created it or an admin of the blog).
 602   *                    2 password (string): Password for said username.
 603   *                     3 postid (string): Unique identifier of the post to edit
 604   */
 605  function wp_deletepage( $m )
 606  {
 607      // CHECK LOGIN:
 608      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 609      {    // Login failed, return (last) error:
 610          return xmlrpcs_resperror();
 611      }
 612  
 613      // GET POST:
 614      /**
 615       * @var Item
 616       */
 617      if( ! $edited_Item = & xmlrpcs_get_Item( $m, 3 ) )
 618      {    // Failed, return (last) error:
 619          return xmlrpcs_resperror();
 620      }
 621  
 622      return xmlrpcs_delete_item( $edited_Item );
 623  }
 624  
 625  
 626  $wordpressUploadFile_doc = 'Uploads a file to the media library of the blog';
 627  $wordpressUploadFile_sig = array(array( $xmlrpcStruct, $xmlrpcInt, $xmlrpcString, $xmlrpcString, $xmlrpcStruct ));
 628  /**
 629   * wp.uploadFile
 630   *
 631   * @see http://codex.wordpress.org/XML-RPC_wp#wp.uploadFile
 632   *
 633   * @param xmlrpcmsg XML-RPC Message
 634   *                    0 blogid (int): Unique identifier of the blog.
 635   *                    1 username (string): User login.
 636   *                    2 password (string): Password for said username.
 637   *                    3 struct (struct)
 638   *                             - name : filename
 639   *                             - type : mimetype
 640   *                             - bits : base64 encoded file
 641   *                            - overwrite : boolean
 642   * @return xmlrpcresp XML-RPC Response
 643   */
 644  function wp_uploadfile($m)
 645  {
 646      return _wp_mw_newmediaobject( $m );
 647  }
 648  
 649  
 650  $wordpressgetcats_sig =  array(array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString));
 651  $wordpressgetcats_doc = 'Get categories of a post, MetaWeblog API-style';
 652  /**
 653   * wp.getCategories
 654   *
 655   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getCategories
 656   *
 657   * @param xmlrpcmsg XML-RPC Message
 658   *                    0 blogid (int): Unique identifier of the blog.
 659   *                    1 username (string): User login.
 660   *                    2 password (string): Password for said username.
 661   */
 662  function wp_getcategories( $m )
 663  {
 664      return _wp_mw_getcategories( $m );
 665  }
 666  
 667  
 668  $wordpresssuggestcats_sig =  array(
 669          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcString),
 670          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcString,$xmlrpcInt),
 671      );
 672  $wordpresssuggestcats_doc = 'Get an array of categories that start with a given string.';
 673  /**
 674   * wp.suggestCategories
 675   *
 676   * @see http://codex.wordpress.org/XML-RPC_wp#wp.suggestCategories
 677   *
 678   * @param xmlrpcmsg XML-RPC Message
 679   *                    0 blogid (int): Unique identifier of the blog.
 680   *                    1 username (string): User login.
 681   *                    2 password (string): Password for said username.
 682   *                    3 search (string): search string
 683   *                    4 max_results (int)
 684   */
 685  function wp_suggestcategories( $m )
 686  {
 687      // Note: we display all cats if search string is empty
 688      $params['search'] = '';
 689  
 690      if( isset($m->params[3]) )
 691      {
 692          $search = $m->getParam(3);
 693          $params['search'] = trim($search->scalarval());
 694      }
 695  
 696      if( isset($m->params[4]) )
 697      {
 698          $limit = $m->getParam(4);
 699          $params['limit'] = abs($limit->scalarval());
 700      }
 701  
 702      return _wp_mw_getcategories( $m, $params );
 703  }
 704  
 705  
 706  $wordpressnewcategory_sig =  array(
 707          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcStruct),
 708          array($xmlrpcStruct,$xmlrpcString,$xmlrpcString,$xmlrpcString,$xmlrpcStruct),
 709      );
 710  $wordpressnewcategory_doc = 'Create a new category.';
 711  /**
 712   * wp.newCategory
 713   *
 714   * @see http://codex.wordpress.org/XML-RPC_wp#wp.newCategory
 715   *
 716   * @param xmlrpcmsg XML-RPC Message
 717   *                    0 blogid (int): Unique identifier of the blog.
 718   *                    1 username (string): User login.
 719   *                    2 password (string): Password for said username.
 720   *                    3 params (struct):
 721   *                        - name (string)
 722   *                        - slug (string)
 723   *                        - parent_id (int)
 724   *                        - description (string)
 725   */
 726  function wp_newcategory( $m )
 727  {
 728      global $DB;
 729  
 730      // CHECK LOGIN:
 731      /**
 732       * @var User
 733       */
 734      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 735      {    // Login failed, return (last) error:
 736          return xmlrpcs_resperror();
 737      }
 738  
 739      // GET BLOG:
 740      /**
 741       * @var Blog
 742       */
 743      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
 744      {    // Login failed, return (last) error:
 745          return xmlrpcs_resperror();
 746      }
 747  
 748      if( ! $current_User->check_perm( 'blog_cats', '', false, $Blog->ID ) )
 749      {
 750          return xmlrpcs_resperror( 5, 'You are not allowed to add or edit categories in this blog.' );
 751      }
 752  
 753      $xcontent = $m->getParam(3);
 754      $contentstruct = xmlrpc_decode_recurse($xcontent);
 755  
 756      $slug = strtolower($contentstruct['name']);
 757      if( !empty($contentstruct['slug']) )
 758      {
 759          $slug = $contentstruct['slug'];
 760      }
 761  
 762      load_class('chapters/model/_chapter.class.php', 'Chapter');
 763  
 764      $new_Chapter = new Chapter(NULL, $Blog->ID);
 765      $new_Chapter->set('name', $contentstruct['name']);
 766      $new_Chapter->set('urlname', $slug);
 767      $new_Chapter->set('parent_ID', intval($contentstruct['parent_id']));
 768  
 769      if( !empty($contentstruct['description']) )
 770      {    // Set decription
 771          $new_Chapter->set('description', $contentstruct['description']);
 772      }
 773  
 774      $cat_ID = $new_Chapter->dbinsert();
 775  
 776      logIO( 'OK.' );
 777      return new xmlrpcresp( new xmlrpcval($cat_ID, 'int') );
 778  }
 779  
 780  
 781  $wordpressdeletecategory_doc = 'Remove category.';
 782  $wordpressdeletecategory_sig =  array(array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcInt));
 783  /**
 784   * wp.deleteCategory
 785   *
 786   * @see http://codex.wordpress.org/XML-RPC_wp#wp.deleteCategory
 787   *
 788   * @param xmlrpcmsg XML-RPC Message
 789   *                    0 blogid (int): Unique identifier of the blog.
 790   *                    1 username (string): User login.
 791   *                    2 password (string): Password for said username.
 792   *                    3 category_id (int): Category ID to delete
 793   */
 794  function wp_deletecategory( $m )
 795  {
 796      global $DB;
 797  
 798      // CHECK LOGIN:
 799      /**
 800       * @var User
 801       */
 802      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 803      {    // Login failed, return (last) error:
 804          return xmlrpcs_resperror();
 805      }
 806  
 807      // GET BLOG:
 808      /**
 809       * @var Blog
 810       */
 811      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
 812      {    // Login failed, return (last) error:
 813          return xmlrpcs_resperror();
 814      }
 815  
 816      if( ! $current_User->check_perm( 'blog_cats', 'edit', false, $Blog->ID ) )
 817      {    // Permission denied
 818          return xmlrpcs_resperror( 5, 'You are not allowed to delete categories in this blog.' );
 819      }
 820  
 821      /**
 822       * @var Comment
 823       */
 824      if( ! $edited_Chapter = & xmlrpcs_get_Chapter( $m, 3 ) )
 825      {    // Return (last) error:
 826          return xmlrpcs_resperror();
 827      }
 828  
 829      $restriction_Messages = $edited_Chapter->check_relations( 'delete_restrictions' );
 830      if( $restriction_Messages->count() )
 831      {
 832          return xmlrpcs_resperror( 5, $restriction_Messages->get_string( T_('The following relations prevent deletion:'),
 833                      T_('Please delete related objects before you proceed.'), "  //  \n", 'xmlrpc' ) );
 834      }
 835  
 836      $ok = (bool) $edited_Chapter->dbdelete();
 837  
 838      logIO( 'Category deleted: '.($ok ? 'yes' : 'no') );
 839  
 840      return new xmlrpcresp( new xmlrpcval( $ok, 'boolean' ) );
 841  }
 842  
 843  
 844  $wordpressgetcommentstatuslist_doc = 'Retrieve all of the comment status.';
 845  $wordpressgetcommentstatuslist_sig =  array(array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString));
 846  /**
 847   * wp.getCommentStatusList
 848   *
 849   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getCommentStatusList
 850   *
 851   * @param xmlrpcmsg XML-RPC Message
 852   *                    0 blogid (int): Unique identifier of the blog.
 853   *                    1 username (string): User login.
 854   *                    2 password (string): Password for said username.
 855   */
 856  function wp_getcommentstatuslist( $m )
 857  {
 858      // CHECK LOGIN:
 859      /**
 860       * @var User
 861       */
 862      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 863      {    // Login failed, return (last) error:
 864          return xmlrpcs_resperror();
 865      }
 866  
 867      // GET BLOG:
 868      /**
 869       * @var Blog
 870       */
 871      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
 872      {    // Login failed, return (last) error:
 873          return xmlrpcs_resperror();
 874      }
 875  
 876      $statuses = array();
 877      foreach( get_allowed_statuses() as $status )
 878      {
 879          switch($status)
 880          {
 881              case 'draft':
 882                  $statuses[] = new xmlrpcval('hold');
 883  
 884              case 'published':
 885                  $statuses[] = new xmlrpcval('approve');
 886  
 887              case 'deprecated':
 888                  $statuses[] = new xmlrpcval('spam');
 889          }
 890      }
 891  
 892      if( $current_User->check_perm('blog_comment!trash', '', false, $Blog->ID) )
 893      {
 894          $statuses[] = new xmlrpcval('trash');
 895      }
 896  
 897      return new xmlrpcresp( new xmlrpcval($statuses,'struct') );
 898  }
 899  
 900  
 901  $wordpressgetcomments_doc = 'Gets a set of comments for a given post.';
 902  $wordpressgetcomments_sig =  array(array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcStruct));
 903  /**
 904   * wp.getComments
 905   *
 906   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getComments
 907   *
 908   * @param xmlrpcmsg XML-RPC Message
 909   *                    0 blogid (int): Unique identifier of the blog.
 910   *                    1 username (string): User login.
 911   *                    2 password (string): Password for said username.
 912   *                    3 params (struct): Filter array
 913   *                        - post_id : The post where the comment is posted. Empty string shows all comments.
 914   *                        - status (defaults to published) : Filter by status (published, deprecated, draft, trash)
 915   *                        - number : Total number of comments to retrieve.
 916   *                        - offset : Not used
 917   */
 918  function wp_getcomments( $m )
 919  {
 920      // CHECK LOGIN:
 921      /**
 922       * @var User
 923       */
 924      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 925      {    // Login failed, return (last) error:
 926          return xmlrpcs_resperror();
 927      }
 928  
 929      // GET BLOG:
 930      /**
 931       * @var Blog
 932       */
 933      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
 934      {    // Login failed, return (last) error:
 935          return xmlrpcs_resperror();
 936      }
 937  
 938      $xcontent = $m->getParam(3);
 939      $contentstruct = xmlrpc_decode_recurse($xcontent);
 940  
 941      $limit = 10;
 942      $contentstruct['number'] = abs( intval($contentstruct['number']) );
 943      if( $contentstruct['number'] > 0 )
 944      {
 945          $limit = $contentstruct['number'];
 946      }
 947  
 948      $status = '';
 949      if( !empty($contentstruct['status']) )
 950      {
 951          $status = wp_or_b2evo_comment_status( $contentstruct['status'], 'b2evo' );
 952      }
 953  
 954      $item_ID = isset($contentstruct['post_id']) ? $contentstruct['post_id'] : 0;
 955  
 956      $comments = xmlrpc_get_comments( array(
 957              'limit'        => $limit,
 958              'statuses'    => $status,
 959              'item_ID'    => $item_ID,
 960          ), $Blog );
 961  
 962      if( empty($comments) )
 963      {
 964          return new xmlrpcresp( new xmlrpcval( array(), 'array' ) );
 965      }
 966  
 967      $data = array();
 968      foreach( $comments as $comment )
 969      {
 970          $data[] = new xmlrpcval( $comment, 'struct' );
 971      }
 972      logIO( 'OK.' );
 973  
 974      return new xmlrpcresp( new xmlrpcval( $data, 'array' ) );
 975  }
 976  
 977  
 978  $wordpressgetcomment_doc = 'Gets a comment, given it\'s comment ID';
 979  $wordpressgetcomment_sig =  array(array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcInt));
 980  /**
 981   * wp.getComments
 982   *
 983   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getComment
 984   *
 985   * @param xmlrpcmsg XML-RPC Message
 986   *                    0 blogid (int): Unique identifier of the blog.
 987   *                    1 username (string): User login.
 988   *                    2 password (string): Password for said username.
 989   *                    3 comment_id (int) : Requested comment ID
 990   */
 991  function wp_getcomment( $m )
 992  {
 993      // CHECK LOGIN:
 994      /**
 995       * @var User
 996       */
 997      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 998      {    // Login failed, return (last) error:
 999          return xmlrpcs_resperror();
1000      }
1001  
1002      // GET BLOG:
1003      /**
1004       * @var Blog
1005       */
1006      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
1007      {    // Login failed, return (last) error:
1008          return xmlrpcs_resperror();
1009      }
1010  
1011      $comment_ID = $m->getParam(3);
1012      $comment_ID = abs($comment_ID->scalarval());
1013  
1014      $comments = xmlrpc_get_comments( array(
1015              'comment_ID' => $comment_ID,
1016          ), $Blog );
1017  
1018      if( empty($comments) )
1019      {
1020          return xmlrpcs_resperror( 6, 'Requested comment ('.$comment_ID.') does not exist.' );
1021      }
1022  
1023      logIO( 'OK.' );
1024      return new xmlrpcresp( new xmlrpcval( $comments[0], 'struct' ) );
1025  }
1026  
1027  
1028  $wordpressgetcommentcount_doc = 'Retrieve comment count for a specific post.';
1029  $wordpressgetcommentcount_sig =  array(array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcInt));
1030  /**
1031   * wp.getCommentCount
1032   *
1033   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getCommentCount
1034   *
1035   * @param xmlrpcmsg XML-RPC Message
1036   *                    0 blogid (int): Unique identifier of the blog.
1037   *                    1 username (string): User login.
1038   *                    2 password (string): Password for said username.
1039   *                    3 post_id (int): The id of the post
1040   */
1041  function wp_getcommentcount( $m )
1042  {
1043      // CHECK LOGIN:
1044      /**
1045       * @var User
1046       */
1047      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
1048      {    // Login failed, return (last) error:
1049          return xmlrpcs_resperror();
1050      }
1051  
1052      // GET BLOG:
1053      /**
1054       * @var Blog
1055       */
1056      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
1057      {    // Login failed, return (last) error:
1058          return xmlrpcs_resperror();
1059      }
1060  
1061      $approved = $awaiting = $spam = $total = 0;
1062      if( $Blog->get_setting( 'allow_comments' ) != 'never' )
1063      {
1064          $item_ID = $m->getParam(3);
1065          $item_ID = $item_ID->scalarval();
1066  
1067          $approved    = generic_ctp_number($item_ID, 'feedbacks');
1068          $awaiting    = generic_ctp_number($item_ID, 'feedbacks', 'draft');
1069          $spam        = generic_ctp_number($item_ID, 'feedbacks', 'deprecated');
1070          $total        = generic_ctp_number($item_ID, 'feedbacks', 'total');
1071      }
1072  
1073      // Maybe we should do a check_perm here?
1074      $data = array(
1075              'approved'                => new xmlrpcval( $approved, 'int' ),
1076              'awaiting_moderation'    => new xmlrpcval( $awaiting, 'int' ),
1077              'spam'                    => new xmlrpcval( $spam,'int' ),
1078              'total_comment'            => new xmlrpcval( $total,'int' ),
1079          );
1080  
1081      logIO( "published: $approved, draft: $awaiting, deprecated: $spam, total: $total" );
1082  
1083      return new xmlrpcresp( new xmlrpcval( $data, 'struct' ) );
1084  }
1085  
1086  
1087  $wordpressnewcomment_sig =  array(array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcInt,$xmlrpcStruct));
1088  $wordpressnewcomment_doc = 'Create new comment.';
1089  /**
1090   * wp.newComment
1091   *
1092   * @see http://codex.wordpress.org/XML-RPC_wp#wp.newComment
1093   *
1094   * Leave the second and third parameter blank to send anonymous comments
1095   *
1096   * @param xmlrpcmsg XML-RPC Message
1097   *                    0 blogid (int): Unique identifier of the blog.
1098   *                    1 username (string): User login.
1099   *                    2 password (string): Password for said username.
1100   *                    3 post_id (int): Target post ID
1101   *                    4 params (struct):
1102   *                        - comment_parent (int)
1103   *                        - content (string)
1104   *                        - author (string)
1105   *                        - author_url (string)
1106   *                        - author_email (string)
1107   */
1108  function wp_newcomment( $m )
1109  {
1110      // GET BLOG:
1111      /**
1112       * @var Blog
1113       */
1114      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
1115      {    // Blog not found
1116          return xmlrpcs_resperror();
1117      }
1118  
1119      if( ! $commented_Item = & xmlrpcs_get_Item( $m, 3 ) )
1120      {    // Item not found
1121          return xmlrpcs_resperror();
1122      }
1123  
1124      $username = $m->getParam(1);
1125      $username = $username->scalarval();
1126  
1127      $password = $m->getParam(2);
1128      $password = $password->scalarval();
1129  
1130      $options = $m->getParam(4);
1131      $options = xmlrpc_decode_recurse($options);
1132  
1133      logIO( 'Params: '.var_export($options, true) );
1134  
1135      $User = NULL;
1136      if( !empty($password) || !empty($username) )
1137      {    // Not an anonymous comment, let's check username
1138  
1139          // CHECK LOGIN:
1140          /**
1141           * @var User
1142           */
1143          if( ! $User = & xmlrpcs_login( $m, 1, 2 ) )
1144          {    // Login failed, return (last) error:
1145              return xmlrpcs_resperror();
1146          }
1147      }
1148  
1149      $params = array(
1150              'User'                => & $User,
1151              'password'            => $password,
1152              'username'            => $username,
1153              'content'            => $options['content'],
1154              'comment_parent'    => intval($options['comment_parent']),
1155              'author'            => $options['author'],
1156              'author_url'        => $options['author_url'],
1157              'author_email'        => $options['author_email'],
1158          );
1159  
1160      return xmlrpcs_new_comment( $params, $commented_Item );
1161  }
1162  
1163  
1164  $wordpresseditcomment_sig =  array(array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcInt,$xmlrpcStruct));
1165  $wordpresseditcomment_doc = 'Edit comment.';
1166  /**
1167   * wp.editComment
1168   *
1169   * @see http://codex.wordpress.org/XML-RPC_wp#wp.editComment
1170   *
1171   * Leave the second and third parameter blank to send anonymous comments
1172   *
1173   * @param xmlrpcmsg XML-RPC Message
1174   *                    0 blogid (int): Unique identifier of the blog.
1175   *                    1 username (string): User login.
1176   *                    2 password (string): Password for said username.
1177   *                    3 comment_id (int): Target post ID
1178   *                    4 params (struct):
1179   *                        - status (string)
1180   *                        - date_created_gmt (string)
1181   *                        - content (string)
1182   *                        - author (string)
1183   *                        - author_url (string)
1184   *                        - author_email (string)
1185   */
1186  function wp_editcomment( $m )
1187  {
1188      // CHECK LOGIN:
1189      /**
1190       * @var User
1191       */
1192      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
1193      {    // Login failed, return (last) error:
1194          return xmlrpcs_resperror();
1195      }
1196  
1197      // GET BLOG:
1198      /**
1199       * @var Blog
1200       */
1201      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
1202      {    // Blog not found
1203          return xmlrpcs_resperror();
1204      }
1205  
1206      /**
1207       * @var Comment
1208       */
1209      if( ! $edited_Comment = & xmlrpcs_get_Comment( $m, 3 ) )
1210      {    // Return (last) error:
1211          return xmlrpcs_resperror();
1212      }
1213  
1214      if( ! $current_User->check_perm( 'comment!CURSTATUS', 'edit', false, $edited_Comment ) )
1215      {    // Permission denied
1216          return xmlrpcs_resperror(3);
1217      }
1218  
1219      $options = $m->getParam(4);
1220      $options = xmlrpc_decode_recurse($options);
1221  
1222      //logIO( 'Params: '.var_export($options, true) );
1223  
1224      $params = array(
1225              'status'        => wp_or_b2evo_comment_status($options['status'], 'b2evo'),
1226              'date'            => _mw_decode_date($options),
1227              'content'        => $options['content'],
1228              'author'        => isset($options['author']) ? $options['author'] : '',
1229              'author_url'    => isset($options['author_url']) ? $options['author_url'] : '',
1230              'author_email'    => isset($options['author_email']) ? $options['author_email'] : '',
1231          );
1232  
1233      return xmlrpcs_edit_comment( $params, $edited_Comment );
1234  }
1235  
1236  
1237  $wordpressdeletecomment_doc = 'Remove comment.';
1238  $wordpressdeletecomment_sig =  array(array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcInt));
1239  /**
1240   * wp.deleteComment
1241   *
1242   * @see http://codex.wordpress.org/XML-RPC_wp#wp.deleteComment
1243   *
1244   * @param xmlrpcmsg XML-RPC Message
1245   *                    0 blogid (int): Unique identifier of the blog.
1246   *                    1 username (string): User login.
1247   *                    2 password (string): Password for said username.
1248   *                    3 comment_id (int): Comment ID to delete
1249   */
1250  function wp_deletecomment( $m )
1251  {
1252      global $DB;
1253  
1254      // CHECK LOGIN:
1255      /**
1256       * @var User
1257       */
1258      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
1259      {    // Login failed, return (last) error:
1260          return xmlrpcs_resperror();
1261      }
1262  
1263      // GET BLOG:
1264      /**
1265       * @var Blog
1266       */
1267      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
1268      {    // Login failed, return (last) error:
1269          return xmlrpcs_resperror();
1270      }
1271  
1272      /**
1273       * @var Comment
1274       */
1275      if( ! $edited_Comment = & xmlrpcs_get_Comment( $m, 3 ) )
1276      {    // Return (last) error:
1277          return xmlrpcs_resperror();
1278      }
1279  
1280      if( ! $current_User->check_perm( 'comment!CURSTATUS', 'delete', false, $edited_Comment ) )
1281      {    // Permission denied
1282          return xmlrpcs_resperror(3);
1283      }
1284  
1285      $ok = (bool) $edited_Comment->dbdelete();
1286  
1287      logIO( 'Comment deleted: '.($ok ? 'yes' : 'no') );
1288  
1289      return new xmlrpcresp( new xmlrpcval( $ok, 'boolean' ) );
1290  }
1291  
1292  
1293  $wordpressgetoptions_doc = 'Retrieve blog options';
1294  $wordpressgetoptions_sig =  array(
1295          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString),
1296          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcStruct),
1297          array($xmlrpcStruct,$xmlrpcInt,$xmlrpcString,$xmlrpcString,$xmlrpcArray),
1298      );
1299  /**
1300   * wp.getOptions
1301   *
1302   * @see http://codex.wordpress.org/XML-RPC_wp#wp.getOptions
1303   *
1304   * Note: If passing in a struct, search for options listed within it.
1305   *
1306   * @param xmlrpcmsg XML-RPC Message
1307   *                    0 blogid (int): Unique identifier of the blog.
1308   *                    1 username (string): User login.
1309   *                    2 password (string): Password for said username.
1310   *                    3 options (struct)
1311   */
1312  function wp_getoptions( $m )
1313  {
1314      global $Settings;
1315  
1316      // CHECK LOGIN:
1317      /**
1318       * @var User
1319       */
1320      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
1321      {    // Login failed, return (last) error:
1322          return xmlrpcs_resperror();
1323      }
1324  
1325      // GET BLOG:
1326      /**
1327       * @var Blog
1328       */
1329      if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
1330      {    // Login failed, return (last) error:
1331          return xmlrpcs_resperror();
1332      }
1333  
1334      if( isset($m->params[3]) )
1335      {
1336          $options = $m->getParam(3);
1337          $options = xmlrpc_decode_recurse($options);
1338      }
1339  
1340      $defaults = array(
1341              'software_name'            => array( 'desc' => 'Software Name', 'value' => 'WordPress' ), // Pretend that we are running WP
1342              'software_version'        => array( 'desc' => 'Software Version', 'value' => '3.3.2' ),
1343              'blog_url'                => array( 'desc' => 'Site URL', 'value' => $Blog->gen_blogurl() ),
1344              'blog_title'            => array( 'desc' => 'Site TitleL', 'value' => $Blog->get('name') ),
1345              'blog_tagline'            => array( 'desc' => 'Site Tagline', 'value' => $Blog->get('tagline') ),
1346              'date_format'            => array( 'desc' => 'Date Format', 'value' => locale_datefmt() ),
1347              'time_format'            => array( 'desc' => 'Time Format', 'value' => locale_timefmt() ),
1348              'users_can_register'    => array( 'desc' => 'Allow new users to sign up', 'value' => $Settings->get('newusers_canregister') ),
1349  
1350              // We are using default thumbnail sizes from config
1351              'thumbnail_crop'        => array( 'desc' => 'Crop thumbnail to exact dimensions', 'value' => false ),
1352              'thumbnail_size_w'        => array( 'desc' => 'Thumbnail Width', 'value' => '160' ),
1353              'thumbnail_size_h'        => array( 'desc' => 'Thumbnail Height', 'value' => '160' ),
1354              'medium_size_w'            => array( 'desc' => 'Medium size image width', 'value' => '320' ),
1355              'medium_size_h'            => array( 'desc' => 'Medium size image height', 'value' => '320' ),
1356              'large_size_w'            => array( 'desc' => 'Large size image width', 'value' => '720' ),
1357              'large_size_h'            => array( 'desc' => 'Large size image height', 'value' => '500' ),
1358          );
1359  
1360      $data = array();
1361      if( empty($options) )
1362      {    // No specific options where asked for, return all of them
1363          foreach( $defaults as $k => $opt )
1364          {
1365              $data[$k] = new xmlrpcval(array(
1366                      'desc' => new xmlrpcval( $opt['desc'] ),
1367                      'readonly' => new xmlrpcval( true, 'boolean' ),
1368                      'value' => new xmlrpcval( $opt['value'] ),
1369                  ),'struct');
1370          }
1371          logIO('Retrieving all options');
1372      }
1373      else
1374      {
1375          foreach( $options as $k )
1376          {
1377              if( !isset($defaults[$k]) ) continue;
1378  
1379              $data[$k] = new xmlrpcval(array(
1380                      'desc' => new xmlrpcval( $defaults[$k]['desc'] ),
1381                      'readonly' => new xmlrpcval( true, 'boolean' ),
1382                      'value' => new xmlrpcval( $defaults[$k]['value'] ),
1383                  ),'struct');
1384  
1385              logIO( 'Retrieving option: '.$k );
1386          }
1387      }
1388      logIO('OK.');
1389  
1390      return new xmlrpcresp( new xmlrpcval( $data, 'struct' ) );
1391  }
1392  
1393  
1394  // ========= Items
1395  $xmlrpc_procs['wp.getPage'] = array( // OK
1396                  'function' => 'wp_getpage',
1397                  'signature' => $wordpressgetpage_sig,
1398                  'docstring' => $wordpressgetpage_doc);
1399  
1400  $xmlrpc_procs['wp.getPages'] = array( // OK
1401                  'function' => 'wp_getpages',
1402                  'signature' => $wordpressgetpages_sig,
1403                  'docstring' => $wordpressgetpages_doc);
1404  
1405  $xmlrpc_procs['wp.getPageList'] = array( // OK
1406                  'function' => 'wp_getpagelist',
1407                  'signature' => $wordpressgetpagelist_sig,
1408                  'docstring' => $wordpressgetpagelist_doc);
1409  
1410  $xmlrpc_procs['wp.getPageStatusList'] = array( // Incomplete (minor): protected and redirected
1411                  'function' => 'wp_getpagestatuslist',
1412                  'signature' => $wordpressgetpagestatuslist_sig,
1413                  'docstring' => $wordpressgetpagestatuslist_doc);
1414  
1415  $xmlrpc_procs['wp.getPostStatusList'] = array( // Alias to wp.getPageStatusList
1416                  'function' => 'wp_getpagestatuslist',
1417                  'signature' => $wordpressgetpagestatuslist_sig,
1418                  'docstring' => $wordpressgetpoststatuslist_doc);
1419  
1420  $xmlrpc_procs['wp.getPostFormats'] = array( // Incomplete (minor): 'show-supported'
1421                  'function' => 'wp_getpostformats',
1422                  'signature' => $wordpressgetpostformats_sig,
1423                  'docstring' => $wordpressgetpostformats_doc);
1424  
1425  $xmlrpc_procs['wp.newPage'] = array( // Untested
1426                  'function' => 'wp_newpage',
1427                  'signature' => $wordpressnewpage_sig,
1428                  'docstring' => $wordpressnewpage_doc);
1429  
1430  $xmlrpc_procs['wp.editPage'] = array( // Untested
1431                  'function' => 'wp_editpage',
1432                  'signature' => $wordpresseditpage_sig,
1433                  'docstring' => $wordpresseditpage_doc);
1434  
1435  $xmlrpc_procs['wp.deletePage'] = array( // OK
1436                  'function' => 'wp_deletepage',
1437                  'signature' => $wordpressdeletepage_sig,
1438                  'docstring' => $wordpressdeletepage_doc);
1439  
1440  /*
1441  $xmlrpc_procs['wp.getPageTemplates'] = array( // Useless in b2evo
1442                  'function' => 'wp_getpagetemplates',
1443                  'signature' => $wordpressgetpagetemplates_sig,
1444                  'docstring' => $wordpressgetpagetemplates_doc);
1445  */
1446  
1447  // ========= Categories
1448  $xmlrpc_procs['wp.getCategories'] = array( // OK
1449                  'function' => 'wp_getcategories',
1450                  'signature' => $wordpressgetcats_sig,
1451                  'docstring' => $wordpressgetcats_doc );
1452  
1453  $xmlrpc_procs['wp.newCategory'] = array( // OK
1454                  'function' => 'wp_newcategory',
1455                  'signature' => $wordpressnewcategory_sig,
1456                  'docstring' => $wordpressnewcategory_doc);
1457  
1458  $xmlrpc_procs['wp.deleteCategory'] = array( // OK
1459                  'function' => 'wp_deletecategory',
1460                  'signature' => $wordpressdeletecategory_sig,
1461                  'docstring' => $wordpressdeletecategory_doc);
1462  
1463  $xmlrpc_procs['wp.suggestCategories'] = array( // OK
1464                  'function' => 'wp_suggestcategories',
1465                  'signature' => $wordpresssuggestcats_sig,
1466                  'docstring' => $wordpresssuggestcats_doc);
1467  
1468  
1469  // ========= Comments
1470  $xmlrpc_procs['wp.getComment'] = array( // OK
1471                  'function' => 'wp_getcomment',
1472                  'signature' => $wordpressgetcomment_sig,
1473                  'docstring' => $wordpressgetcomment_doc);
1474  
1475  $xmlrpc_procs['wp.getComments'] = array( // OK
1476                  'function' => 'wp_getcomments',
1477                  'signature' => $wordpressgetcomments_sig,
1478                  'docstring' => $wordpressgetcomments_doc);
1479  
1480  $xmlrpc_procs['wp.getCommentStatusList'] = array( // OK
1481                  'function' => 'wp_getcommentstatuslist',
1482                  'signature' => $wordpressgetcommentstatuslist_sig,
1483                  'docstring' => $wordpressgetcommentstatuslist_doc);
1484  
1485  $xmlrpc_procs['wp.newComment'] = array( // OK
1486                  'function' => 'wp_newcomment',
1487                  'signature' => $wordpressnewcomment_sig,
1488                  'docstring' => $wordpressnewcomment_doc);
1489  
1490  $xmlrpc_procs['wp.editComment'] = array( // OK
1491                  'function' => 'wp_editcomment',
1492                  'signature' => $wordpresseditcomment_sig,
1493                  'docstring' => $wordpresseditcomment_doc);
1494  
1495  $xmlrpc_procs['wp.getCommentCount'] = array( // OK
1496                  'function' => 'wp_getcommentcount',
1497                  'signature' => $wordpressgetcommentcount_sig,
1498                  'docstring' => $wordpressgetcommentcount_doc);
1499  
1500  $xmlrpc_procs['wp.deleteComment'] = array( // OK
1501                  'function' => 'wp_deletecomment',
1502                  'signature' => $wordpressdeletecomment_sig,
1503                  'docstring' => $wordpressdeletecomment_doc);
1504  
1505  
1506  // ========= Other
1507  $xmlrpc_procs['wp.uploadFile'] = array( // OK
1508                  'function' => 'wp_uploadfile',
1509                  'signature' => $wordpressUploadFile_sig,
1510                  'docstring' => $wordpressUploadFile_doc);
1511  
1512  $xmlrpc_procs['wp.getTags'] = array( // OK
1513                  'function' => 'wp_gettags',
1514                  'signature' => $wordpressgettags_sig,
1515                  'docstring' => $wordpressgettags_doc);
1516  
1517  $xmlrpc_procs['wp.getUsersBlogs'] = array( // OK
1518                  'function' => 'wp_getusersblogs',
1519                  'signature' => $wordpressgetusersblogs_sig ,
1520                  'docstring' => $wordpressgetusersblogs_doc );
1521  
1522  $xmlrpc_procs['wp.getAuthors'] = array( // OK
1523                  'function' => 'wp_getauthors',
1524                  'signature' => $wordpressgetauthors_sig,
1525                  'docstring' => $wordpressgetauthors_doc);
1526  
1527  $xmlrpc_procs['wp.getOptions'] = array( // OK
1528                  'function' => 'wp_getoptions',
1529                  'signature' => $wordpressgetoptions_sig,
1530                  'docstring' => $wordpressgetoptions_doc);
1531  
1532  /*
1533  $xmlrpc_procs['wp.setOptions'] = array( // TODO
1534                  'function' => 'wp_setoptions',
1535                  'signature' => $wordpresssetoptions_sig,
1536                  'docstring' => $wordpresssetoptions_doc);
1537  
1538  $xmlrpc_procs['wp.getMediaItem'] = array( // TODO
1539                  'function' => 'wp_getmediaitem',
1540                  'signature' => $wordpressgetmediaitem_sig,
1541                  'docstring' => $wordpressgetmediaitem_doc);
1542  
1543  $xmlrpc_procs['wp.getMediaLibrary'] = array( // TODO
1544                  'function' => 'wp_getmedialibrary',
1545                  'signature' => $wordpressgetmedialibrary_sig,
1546                  'docstring' => $wordpressgetmedialibrary_doc);
1547  */
1548  
1549  ?>

title

Description

title

Description

title

Description

title

title

Body