b2evolution PHP Cross Reference Blogging Systems

Source: /inc/xmlrpc/apis/_blogger.api.php - 508 lines - 17342 bytes - Summary - Text - Print

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

   1  <?php
   2  /**
   3   * XML-RPC : Blogger API
   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   * @see http://b2evolution.net/man/blogger-api
  10   * @see http://www.blogger.com/developers/api/1_docs/
  11   * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/
  12   *
  13   * @package xmlsrv
  14   *
  15   * @version $Id: _blogger.api.php 6136 2014-03-08 07:59:48Z manuel $
  16   */
  17  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  18  
  19  
  20  $bloggernewpost_doc = 'Adds a post, blogger-api like';
  21  $bloggernewpost_sig = array(array($xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcBoolean));
  22  /**
  23   * blogger.newPost makes a new post to a designated blog.
  24   *
  25   * Optionally, will publish the blog after making the post. (In b2evo, this means the
  26   * new post will be in 'published' state).
  27   * On success, it returns the unique ID of the new post (usually a seven-digit number
  28   * at this time).
  29   * On error, it will return some error message.
  30   *
  31   * @see http://www.blogger.com/developers/api/1_docs/xmlrpc_newPost.html
  32   * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggernewpost.html
  33   *
  34   * @param xmlrpcmsg XML-RPC Message
  35   *                    0 appkey (string): Unique identifier/passcode of the application sending the post.
  36   *                        (See access info {@link http://www.blogger.com/developers/api/1_docs/#access} .)
  37   *                    1 blogid (string): Unique identifier of the blog the post will be added to.
  38   *                        Currently ignored in b2evo, in favor of the category.
  39   *                    2 username (string): Login for a Blogger user who has permission to post to the blog.
  40   *                    3 password (string): Password for said username.
  41   *                    4 content (string): Contents of the post.
  42   *                    5 publish (boolean): If true, the blog will be published immediately after the
  43   *                        post is made. (In b2evo,this means, the new post will be in 'published' state,
  44   *                        otherwise it would be in draft state).
  45   * @return xmlrpcresp XML-RPC Response
  46   */
  47  function blogger_newpost( $m )
  48  {
  49      global $Settings;
  50      // CHECK LOGIN:
  51      /**
  52       * @var User
  53       */
  54      if( ! $current_User = & xmlrpcs_login( $m, 2, 3 ) )
  55      {    // Login failed, return (last) error:
  56          return xmlrpcs_resperror();
  57      }
  58  
  59      // GET BLOG:
  60      /**
  61       * @var Blog
  62       */
  63      if( ! $Blog = & xmlrpcs_get_Blog( $m, 1 ) )
  64      {    // Login failed, return (last) error:
  65          return xmlrpcs_resperror();
  66      }
  67  
  68      $content = $m->getParam(4);
  69      $content = $content->scalarval();
  70  
  71      $publish  = $m->getParam(5);
  72      $publish = $publish->scalarval();
  73      $status = $publish ? 'published' : 'draft';
  74      logIO("Publish: $publish -> Status: $status");
  75  
  76      $title = xmlrpc_getposttitle( $content );
  77      $cat_IDs = xmlrpc_getpostcategories( $content );
  78  
  79      // Cleanup content from extra tags like <category> and <title>:
  80      $content = xmlrpc_removepostdata( $content );
  81  
  82      $params = array(
  83              'title'        => $title,
  84              'content'    => $content,
  85              'cat_IDs'    => $cat_IDs,
  86              'status'    => $status,
  87          );
  88  
  89      // COMPLETE VALIDATION & INSERT:
  90      return xmlrpcs_new_item( $params, $Blog );
  91  }
  92  
  93  
  94  $bloggereditpost_doc='Edits a post, blogger-api like';
  95  $bloggereditpost_sig=array(array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcBoolean));
  96  /**
  97   * blogger.editPost changes the contents of a given post.
  98   *
  99   * Optionally, will publish the blog the post belongs to after changing the post.
 100   * (In b2evo, this means the changed post will be moved to published state).
 101   * On success, it returns a boolean true value.
 102   * On error, it will return a fault with an error message.
 103   *
 104   * @see http://www.blogger.com/developers/api/1_docs/xmlrpc_editPost.html
 105   * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggereditpost.html
 106   *
 107   * @param xmlrpcmsg XML-RPC Message
 108   *                    0 appkey (string): Unique identifier/passcode of the application sending the post.
 109   *                        (See access info {@link http://www.blogger.com/developers/api/1_docs/#access} .)
 110   *                    1 postid (string): Unique identifier of the post to be changed.
 111   *                    2 username (string): Login for a Blogger user who has permission to edit the given
 112   *                        post (either the user who originally created it or an admin of the blog).
 113   *                    3 password (string): Password for said username.
 114   *                    4 content (string): New content of the post.
 115   *                    5 publish (boolean): If true, the blog will be published immediately after the
 116   *                        post is made. (In b2evo,this means, the new post will be in 'published' state,
 117   *                        otherwise it would be in draft state).
 118   * @return xmlrpcresp XML-RPC Response
 119   *
 120   * @todo check current status and permission on it
 121   */
 122  function blogger_editpost($m)
 123  {
 124      // CHECK LOGIN:
 125      /**
 126       * @var User
 127       */
 128      if( ! $current_User = & xmlrpcs_login( $m, 2, 3 ) )
 129      {    // Login failed, return (last) error:
 130          return xmlrpcs_resperror();
 131      }
 132  
 133      // GET POST:
 134      /**
 135       * @var Item
 136       */
 137      if( ! $edited_Item = & xmlrpcs_get_Item( $m, 1 ) )
 138      {    // Failed, return (last) error:
 139          return xmlrpcs_resperror();
 140      }
 141  
 142      // We need to be able to edit this post:
 143      if( ! $current_User->check_perm( 'item_post!CURSTATUS', 'edit', false, $edited_Item ) )
 144      {
 145          return xmlrpcs_resperror( 3 ); // Permission denied
 146      }
 147  
 148      $content = $m->getParam(4);
 149      $content = $content->scalarval();
 150  
 151      $publish = $m->getParam(5);
 152      $publish = $publish->scalarval();
 153      $status = $publish ? 'published' : 'draft';
 154      logIO("Publish: $publish -> Status: $status");
 155  
 156      $title = xmlrpc_getposttitle( $content );
 157      $cat_IDs = xmlrpc_getpostcategories( $content );
 158  
 159      // Cleanup content from extra tags like <category> and <title>:
 160      $content = xmlrpc_removepostdata( $content );
 161  
 162      $params = array(
 163              'title'        => $title,
 164              'content'    => $content,
 165              'cat_IDs'    => $cat_IDs,
 166              'status'    => $status,
 167          );
 168  
 169      // COMPLETE VALIDATION & INSERT:
 170      return xmlrpcs_edit_item( $edited_Item, $params );
 171  }
 172  
 173  
 174  
 175  
 176  $bloggerdeletepost_doc = 'Deletes a post, blogger-api like';
 177  $bloggerdeletepost_sig = array(
 178          array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcBoolean),
 179          array($xmlrpcBoolean, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString),
 180      );
 181  /**
 182   * blogger.deletePost deletes a given post.
 183   *
 184   * This API call is not documented on
 185   * {@link http://www.blogger.com/developers/api/1_docs/}
 186   * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggerdeletepost.html
 187   *
 188   * @param xmlrpcmsg XML-RPC Message
 189   *                    0 appkey (string): Unique identifier/passcode of the application sending the post.
 190   *                        (See access info {@link http://www.blogger.com/developers/api/1_docs/#access} .)
 191   *                    1 postid (string): Unique identifier of the post to be deleted.
 192   *                    2 username (string): Login for a Blogger user who has permission to edit the given
 193   *                        post (either the user who originally created it or an admin of the blog).
 194   *                    3 password (string): Password for said username.
 195   * @return xmlrpcresp XML-RPC Response
 196   */
 197  function blogger_deletepost($m)
 198  {
 199      // CHECK LOGIN:
 200      if( ! $current_User = & xmlrpcs_login( $m, 2, 3 ) )
 201      {    // Login failed, return (last) error:
 202          return xmlrpcs_resperror();
 203      }
 204  
 205      // GET POST:
 206      /**
 207       * @var Item
 208       */
 209      if( ! $edited_Item = & xmlrpcs_get_Item( $m, 1 ) )
 210      {    // Failed, return (last) error:
 211          return xmlrpcs_resperror();
 212      }
 213  
 214      return xmlrpcs_delete_item( $edited_Item );
 215  }
 216  
 217  
 218  
 219  $bloggergetusersblogs_doc='returns the user\'s blogs - this is a dummy function, just so that BlogBuddy and other blogs-retrieving apps work';
 220  $bloggergetusersblogs_sig=array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString));
 221  /**
 222   * blogger.getUsersBlogs returns information about all the blogs a given user is a member of.
 223   *
 224   * Data is returned as an array of <struct>s containing the ID (blogid), name (blogName),
 225   * and URL (url) of each blog.
 226   *
 227   * Non official: Also return a boolean stating wether or not the user can edit th eblog templates
 228   * (isAdmin).
 229   *
 230   * see {@link http://www.blogger.com/developers/api/1_docs/xmlrpc_getUsersBlogs.html}
 231   * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggergetusersblogs.html
 232   *
 233   * @param xmlrpcmsg XML-RPC Message
 234   *                    0 appkey (string): Unique identifier/passcode of the application sending the post.
 235   *                        (See access info {@link http://www.blogger.com/developers/api/1_docs/#access} .)
 236   *                    1 username (string): Login for the Blogger user who's blogs will be retrieved.
 237   *                    2 password (string): Password for said username.
 238   *                        (currently not required by b2evo)
 239   * @return xmlrpcresp XML-RPC Response, an array of <struct>s containing for each blog:
 240   *                    - ID (blogid),
 241   *                    - name (blogName),
 242   *                    - URL (url),
 243   *                    - bool: can user edit template? (isAdmin).
 244   */
 245  function blogger_getusersblogs($m)
 246  {
 247      logIO('blogger_getusersblogs start');
 248      return _wp_or_blogger_getusersblogs( 'blogger', $m );
 249  }
 250  
 251  
 252  
 253  
 254  $bloggergetuserinfo_doc='gives the info about a user';
 255  $bloggergetuserinfo_sig=array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString));
 256  /**
 257   * blogger.getUserInfo returns returns a struct containing user info.
 258   *
 259   * Data returned: userid, firstname, lastname, nickname, email, and url.
 260   *
 261   * see {@link http://www.blogger.com/developers/api/1_docs/xmlrpc_getUserInfo.html}
 262   * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggergetuserinfo.html
 263   *
 264   * @param xmlrpcmsg XML-RPC Message
 265   *                    0 appkey (string): Unique identifier/passcode of the application sending the post.
 266   *                        (See access info {@link http://www.blogger.com/developers/api/1_docs/#access} .)
 267   *                    1 username (string): Login for the Blogger user who's blogs will be retrieved.
 268   *                    2 password (string): Password for said username.
 269   *                        (currently not required by b2evo)
 270   * @return xmlrpcresp XML-RPC Response, a <struct> containing:
 271   *                    - userid,
 272   *                    - firstname,
 273   *                    - lastname,
 274   *                    - nickname,
 275   *                    - email,
 276   *                    - url
 277   */
 278  function blogger_getuserinfo($m)
 279  {
 280      // CHECK LOGIN:
 281      if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
 282      {    // Login failed, return (last) error:
 283          return xmlrpcs_resperror();
 284      }
 285  
 286      // INFO about logged in user
 287      $struct = new xmlrpcval( array(
 288              'nickname'  => new xmlrpcval( $current_User->get('nickname') ),
 289              'userid'    => new xmlrpcval( $current_User->ID ),
 290              'url'       => new xmlrpcval( $current_User->get('url') ),
 291              'email'     => new xmlrpcval( $current_User->get('email') ),
 292              'lastname'  => new xmlrpcval( $current_User->get('lastname') ),
 293              'firstname' => new xmlrpcval( $current_User->get('firstname') )
 294          ), 'struct' );
 295  
 296      logIO( 'OK.' );
 297      return new xmlrpcresp( $struct );
 298  }
 299  
 300  
 301  
 302  
 303  $bloggergetpost_doc = 'fetches a post, blogger-api like';
 304  $bloggergetpost_sig = array(array($xmlrpcStruct, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString));
 305  /**
 306   * blogger.getPost retieves a given post.
 307   *
 308   * This API call is not documented on
 309   * {@link http://www.blogger.com/developers/api/1_docs/}
 310   * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggergetpost.html
 311   *
 312   * @param xmlrpcmsg XML-RPC Message
 313   *                    0 appkey (string): Unique identifier/passcode of the application sending the post.
 314   *                        (See access info {@link http://www.blogger.com/developers/api/1_docs/#access} .)
 315   *                    1 postid (string): Unique identifier of the post to be deleted.
 316   *                    2 username (string): Login for a Blogger user who has permission to edit the given
 317   *                        post (either the user who originally created it or an admin of the blog).
 318   *                    3 password (string): Password for said username.
 319   * @return xmlrpcresp XML-RPC Response
 320   */
 321  function blogger_getpost($m)
 322  {
 323      // CHECK LOGIN:
 324      /**
 325       * @var User
 326       */
 327      if( ! $current_User = & xmlrpcs_login( $m, 2, 3 ) )
 328      {    // Login failed, return (last) error:
 329          return xmlrpcs_resperror();
 330      }
 331  
 332      // GET POST:
 333      /**
 334       * @var Item
 335       */
 336      if( ! $edited_Item = & xmlrpcs_get_Item( $m, 1 ) )
 337      {    // Failed, return (last) error:
 338          return xmlrpcs_resperror();
 339      }
 340  
 341      // CHECK PERMISSION:
 342      if( ! xmlrpcs_can_view_item( $edited_Item, $current_User ) )
 343      {
 344          return xmlrpcs_resperror( 3 );
 345      }
 346      logIO( 'Permission granted.' );
 347  
 348      $post_date = mysql2date( 'U', $edited_Item->issue_date );
 349      $post_date = gmdate('Ymd', $post_date).'T'.gmdate('H:i:s', $post_date);
 350  
 351      $content    = '<title>'.$edited_Item->title.'</title>';
 352      $content .= '<category>'.$edited_Item->main_cat_ID.'</category>';
 353      $content .= $edited_Item->content;
 354  
 355      $struct = new xmlrpcval( array(
 356                                      'userid'      => new xmlrpcval( $edited_Item->creator_user_ID ),
 357                                      'dateCreated' => new xmlrpcval( $post_date, 'dateTime.iso8601' ),
 358                                      'content'     => new xmlrpcval( $content ),
 359                                      'postid'      => new xmlrpcval( $edited_Item->ID )
 360                                  ), 'struct' );
 361  
 362      logIO( 'OK.' );
 363      return new xmlrpcresp($struct);
 364  }
 365  
 366  
 367  
 368  
 369  $bloggergetrecentposts_doc = 'fetches X most recent posts, blogger-api like';
 370  $bloggergetrecentposts_sig = array(array($xmlrpcArray, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcString, $xmlrpcInt));
 371  /**
 372   * blogger.getRecentPosts retieves X most recent posts.
 373   *
 374   * This API call is not documented on
 375   * {@link http://www.blogger.com/developers/api/1_docs/}
 376   * @see http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggergetrecentposts.html
 377   *
 378   * @param xmlrpcmsg XML-RPC Message
 379   *                    0 appkey (string): Unique identifier/passcode of the application sending the post.
 380   *                        (See access info {@link http://www.blogger.com/developers/api/1_docs/#access} .)
 381   *                    1 blogid (string): Unique identifier of the blog the post will be added to.
 382   *                        Currently ignored in b2evo, in favor of the category.
 383   *                    2 username (string): Login for a Blogger user who has permission to edit the given
 384   *                        post (either the user who originally created it or an admin of the blog).
 385   *                    3 password (string): Password for said username.
 386   *                    4 numposts (integer): number of posts to retrieve.
 387   * @return xmlrpcresp XML-RPC Response
 388   */
 389  function blogger_getrecentposts( $m )
 390  {
 391      global $xmlrpcerruser, $DB;
 392  
 393      // CHECK LOGIN:
 394      /**
 395       * @var User
 396       */
 397      if( ! $current_User = & xmlrpcs_login( $m, 2, 3 ) )
 398      {    // Login failed, return (last) error:
 399          return xmlrpcs_resperror();
 400      }
 401  
 402      // GET BLOG:
 403      /**
 404       * @var Blog
 405       */
 406      if( ! $Blog = & xmlrpcs_get_Blog( $m, 1 ) )
 407      {    // Login failed, return (last) error:
 408          return xmlrpcs_resperror();
 409      }
 410  
 411      $numposts = $m->getParam(4);
 412      $numposts = $numposts->scalarval();
 413  
 414  
 415      // Get the posts to display:
 416      load_class( 'items/model/_itemlist.class.php', 'ItemList' );
 417      $MainList = new ItemList2( $Blog, NULL, NULL, $numposts );
 418  
 419      // Protected and private get checked by statuses_where_clause().
 420      $statuses = array( 'published', 'redirected', 'protected', 'private' );
 421      if( $current_User->check_perm( 'blog_ismember', 'view', false, $Blog->ID ) )
 422      {    // These statuses require member status:
 423          $statuses = array_merge( $statuses, array( 'draft', 'deprecated' ) );
 424      }
 425      logIO( 'Statuses: '.implode( ', ', $statuses ) );
 426  
 427      $MainList->set_filters( array(
 428              'visibility_array' => $statuses,
 429              'order' => 'DESC',
 430              'unit' => 'posts',
 431          ) );
 432  
 433      // Run the query:
 434      $MainList->query();
 435  
 436  
 437      logIO( 'Items:'.$MainList->result_num_rows );
 438  
 439      $data = array();
 440      while( $Item = & $MainList->get_item() )
 441      {
 442          logIO( 'Item:'.$Item->title.
 443                      ' - Issued: '.$Item->issue_date.
 444                      ' - Modified: '.$Item->datemodified );
 445  
 446          $post_date = mysql2date('U', $Item->issue_date);
 447          $post_date = gmdate('Ymd', $post_date).'T'.gmdate('H:i:s', $post_date);
 448  
 449          $content    = '<title>'.$Item->title.'</title>';
 450          $content .= '<category>'.$Item->main_cat_ID.'</category>';
 451          $content .= $Item->content;
 452  
 453          // Load Item's creator User:
 454          $Item->get_creator_User();
 455          $authorname = $Item->creator_User->get('preferredname');
 456  
 457          $data[] = new xmlrpcval(array(
 458                                      'authorName' => new xmlrpcval($authorname),
 459                                      'userid' => new xmlrpcval($Item->creator_user_ID),
 460                                      'dateCreated' => new xmlrpcval($post_date,'dateTime.iso8601'),
 461                                      'content' => new xmlrpcval($content),
 462                                      'postid' => new xmlrpcval($Item->ID)
 463                                      ),'struct');
 464      }
 465  
 466      $resp = new xmlrpcval($data, 'array');
 467  
 468      logIO( 'OK.' );
 469      return new xmlrpcresp($resp);
 470  }
 471  
 472  
 473  $xmlrpc_procs['blogger.newPost'] = array(
 474                  'function' => 'blogger_newpost',
 475                  'signature' => $bloggernewpost_sig,
 476                  'docstring' => $bloggernewpost_doc );
 477  
 478  $xmlrpc_procs['blogger.editPost'] = array(
 479                  'function' => 'blogger_editpost',
 480                  'signature' => $bloggereditpost_sig,
 481                  'docstring' => $bloggereditpost_doc );
 482  
 483  $xmlrpc_procs['blogger.deletePost'] = array(
 484                  'function' => 'blogger_deletepost',
 485                  'signature' => $bloggerdeletepost_sig,
 486                  'docstring' => $bloggerdeletepost_doc );
 487  
 488  $xmlrpc_procs['blogger.getUsersBlogs'] = array(
 489                  'function' => 'blogger_getusersblogs',
 490                  'signature' => $bloggergetusersblogs_sig,
 491                  'docstring' => $bloggergetusersblogs_doc );
 492  
 493  $xmlrpc_procs['blogger.getUserInfo'] = array(
 494                  'function' => 'blogger_getuserinfo',
 495                  'signature' => $bloggergetuserinfo_sig,
 496                  'docstring' => $bloggergetuserinfo_doc );
 497  
 498  $xmlrpc_procs['blogger.getPost'] = array(
 499                  'function' => 'blogger_getpost',
 500                  'signature' => $bloggergetpost_sig,
 501                  'docstring' => $bloggergetpost_doc );
 502  
 503  $xmlrpc_procs['blogger.getRecentPosts'] = array(
 504                  'function' => 'blogger_getrecentposts',
 505                  'signature' => $bloggergetrecentposts_sig,
 506                  'docstring' => $bloggergetrecentposts_doc );
 507  
 508  ?>

title

Description

title

Description

title

Description

title

title

Body