b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/twitter_plugin/_twitter.plugin.php - 631 lines - 20029 bytes - Summary - Text - Print

Description: This file implements the Twitter plugin. For the most recent and complete Plugin API documentation see {@link Plugin} in ../evocore/_plugin.class.php.

   1  <?php
   2  /**
   3   * This file implements the Twitter plugin.
   4   *
   5   * For the most recent and complete Plugin API documentation
   6   * see {@link Plugin} in ../evocore/_plugin.class.php.
   7   *
   8   * This file is part of the b2evolution project - {@link http://b2evolution.net/}
   9   *
  10   * @copyright (c)2009-2014 by Francois PLANQUE - {@link http://fplanque.net/}
  11   * @copyright (c)2007 by Lee Turner - {@link http://leeturner.org/}.
  12   *
  13   * @license GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  14   *
  15   * @package plugins
  16   *
  17   * @author Lee Turner
  18   * @author fplanque: Francois PLANQUE.
  19   *
  20   * @todo dh> use OAuth instead of username/password: http://apiwiki.twitter.com/Authentication
  21   *
  22   * @version $Id: _twitter.plugin.php 6136 2014-03-08 07:59:48Z manuel $
  23   */
  24  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  25  
  26  // Twitter params initialization
  27  define( 'TWITTER_CONSUMER_KEY', 'z680vsCAnATc0ZQNgMVwbg' );
  28  define( 'TWITTER_CONSUMER_SECRET', 'OBo8xI6pvTR1KI0LBHEkjpPPd6nN99tq4SAY8qrBp8' );
  29  
  30  //test app
  31  //define( 'TWITTER_CONSUMER_KEY', 'PTJjBJraSkghuFVXQysPTg' );
  32  //define( 'TWITTER_CONSUMER_SECRET', 'pcGfALMLaOF6VCaG6FwVO5hI1jtTPEgbLyj6Yo0DN04' );
  33  
  34  /**
  35   * Twitter Plugin
  36   *
  37   * This plugin will post to your twitter account when you have added a post to your blog.
  38   *
  39   * @todo use OAuth -- http://www.jaisenmathai.com/blog/2009/03/31/how-to-quickly-integrate-with-twitters-oauth-api-using-php/
  40   * @todo Tblue> Do not use cURL, or at least do not depend on it! We could
  41   *              clone/modify {@link fetch_remote_page()} to be able to do
  42   *              HTTP POST requests.
  43   */
  44  class twitter_plugin extends Plugin
  45  {
  46      /**
  47       * Variables below MUST be overriden by plugin implementations,
  48       * either in the subclass declaration or in the subclass constructor.
  49       */
  50      var $code = 'evo_twitter';
  51      var $priority = 50;
  52      var $version = '5.0.0';
  53      var $author = 'b2evolution Group';
  54  
  55      /*
  56       * These variables MAY be overriden.
  57       */
  58      var $group = 'ping';
  59      var $number_of_installs = 1;
  60      var $message_length_limit = 140; // The maximum allowed number of characters in a message
  61  
  62      /**
  63       * Init
  64       *
  65       * This gets called after a plugin has been registered/instantiated.
  66       */
  67  	function PluginInit( & $params )
  68      {
  69          // Check php version
  70          if( version_compare( phpversion(), '5.0.0', '<' ) )
  71          { // the plugin is not supported
  72              $this->set_status( 'disabled' );
  73              return false;
  74          }
  75  
  76          if( !extension_loaded( 'curl' ) )
  77          { // the plugin is not supported
  78              $this->set_status( 'disabled' );
  79              return false;
  80          }
  81  
  82          $this->name = T_('Twitter plugin');
  83          $this->short_desc = $this->T_('Post to your Twitter account when you post to your blog');
  84          $this->long_desc = $this->T_('Posts to your Twitter account to update Twitter.com with details of your blog post.');
  85  
  86          $this->ping_service_name = 'twitter.com';
  87          $this->ping_service_note = $this->T_('Update your twitter account with details about the new post.');
  88      }
  89  
  90  
  91      /**
  92       * We require b2evo 3.2.0 or above.
  93       */
  94  	function GetDependencies()
  95      {
  96          return array(
  97                  'requires' => array(
  98                      'app_min' => '3.2.0-beta',
  99                  ),
 100              );
 101      }
 102  
 103  
 104      /**
 105       * Check if the plugin can be enabled:
 106       *
 107       * @return string|NULL
 108       */
 109  	function BeforeEnable()
 110      {
 111  
 112          if( empty($this->code) )
 113          {
 114              return T_('The twitter plugin needs a non-empty code.');
 115          }
 116  
 117          if( version_compare( phpversion(), '5.0.0', '<' ) )
 118          {
 119              return T_('The twitter plugin requires PHP 5.');
 120          }
 121  
 122          if( !extension_loaded( 'curl' ) )
 123          {
 124              return T_( 'The twitter plugin requires the PHP curl extension.');
 125          }
 126  
 127          // OK:
 128          return true;
 129      }
 130  
 131  
 132      /**
 133       * Post to Twitter.
 134       *
 135       * @return boolean Was the ping successful?
 136       */
 137  	function ItemSendPing( & $params )
 138      {
 139          $content = array(
 140                  'title'        => $params['Item']->dget('title', 'xml'),
 141                  'excerpt'    => $params['Item']->dget('excerpt', 'xml'),
 142                  'url'        => $params['Item']->get_tinyurl(),
 143              );
 144  
 145          return $this->send_a_tweet( $content, $params['Item'], $params['xmlrpcresp'] );
 146      }
 147  
 148      /**
 149       * Allowing the user to specify their twitter account name and password.
 150       *
 151       * @return array See {@link Plugin::GetDefaultSettings()}.
 152       */
 153  	function GetDefaultUserSettings( & $params )
 154      {
 155          $info = NULL;
 156          if( isset( $params['user_ID'] ) )
 157          { // initialize info only once, when needs to display the link (user_ID is set)
 158              $info = $this->get_twitter_link( 'user', $params['user_ID'] );
 159          }
 160          return array(
 161                  'twitter_contact' => array(
 162                      'label' => T_('Twitter account status'),
 163                      'info' => $info,
 164                      'type' => 'info',
 165                  ),
 166                  'twitter_msg_format' => array(
 167                      'label' => T_( 'Message format' ),
 168                      'type' => 'text',
 169                      'size' => 30,
 170                      'maxlength' => 140,
 171                      'defaultvalue' => T_( 'Just posted $title$ $url$ #b2p' ),
 172                      'note' => T_('$title$, $excerpt$ and $url$ will be replaced appropriately.'),
 173                  ),
 174              );
 175      }
 176  
 177  
 178      /**
 179       * Define here default collection/blog settings that are to be made available in the backoffice.
 180       *
 181       * @todo: ideally we'd want a warning if the twitter ping is not enabled
 182       *
 183       * @return array See {@link Plugin::GetDefaultSettings()}.
 184       */
 185  	function get_coll_setting_definitions( & $params )
 186      {
 187          $info = NULL;
 188          if( isset( $params['blog_ID'] ) )
 189          { // initialize info only once, when needs to display the link
 190              $info = $this->get_twitter_link( 'blog', $params['blog_ID'] );
 191          }
 192          return array(
 193                  'twitter_contact' => array(
 194                      'label' => T_('Twitter account status'),
 195                      'info' => $info,
 196                      'type' => 'info',
 197                  ),
 198                  'twitter_msg_format' => array(
 199                      'label' => T_( 'Message format' ),
 200                      'type' => 'text',
 201                      'size' => 30,
 202                      'maxlength' => 140,
 203                      'defaultvalue' => T_( 'Just posted $title$ $url$ #b2p' ),
 204                      'note' => T_('$title$, $excerpt$ and $url$ will be replaced appropriately.'),
 205                  ),
 206              );
 207      }
 208  
 209  
 210      /**
 211       * Get link to twitter oAuth
 212       *
 213       * @param string target type can be "blog" or "user", depends if we set blog or user setting
 214       * @param string current blog id or edited user id
 215       * @return string twitter oAuth link
 216       */
 217  	function get_twitter_link( $target_type, $target_id )
 218      {
 219          global $Blog;
 220  
 221          require_once  'twitteroauth/twitteroauth.php';
 222  
 223          // Uses either plugin CollSettings or UserSettings
 224          $oauth = $this->get_oauth_info( array(
 225                  'type'    => $target_type,
 226                  'ID'    => $target_id,
 227              ) );
 228  
 229          if( !empty( $oauth['token'] ) )
 230          { // already linked
 231              if( empty( $oauth['contact'] ) )
 232              {
 233                  $oauth['contact'] = $this->get_twitter_contact( $oauth['token'], $oauth['token_secret'] );
 234                  if( ! empty( $oauth['contact'] ) )
 235                  {
 236                      if( $target_type == 'blog' )
 237                      { // CollSettings
 238                          $this->set_coll_setting( 'twitter_contact', $oauth['contact'], $Blog->ID );
 239                          $Blog->dbupdate();
 240                      }
 241                      else if( $target_type == 'user' )
 242                      { // UserSettings
 243                          $this->UserSettings->set( 'twitter_contact', $oauth['contact'], $target_id );
 244                          $this->UserSettings->dbupdate();
 245                      }
 246                  }
 247              }
 248              $result = T_('Linked to').': @'.$oauth['contact'].'. ';
 249          }
 250  
 251          // create new connection
 252          $connection = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
 253  
 254          // set callback url
 255          $callback = $this->get_htsrv_url( 'twitter_callback', array( 'target_type' => $target_type, 'target_id' => $target_id ), '&', true );
 256  
 257          $req_token = $connection->getRequestToken( $callback );
 258  
 259          if( $req_token == NULL )
 260          {
 261              return T_( 'Connection is not available!' );
 262          }
 263  
 264          $token = $req_token['oauth_token'];
 265  
 266          /* Save temporary credentials to session. */
 267          global $Session;
 268          $Session->delete( 'oauth_token' );
 269          $Session->delete( 'oauth_token_secret' );
 270          $Session->set( 'oauth_token', $req_token['oauth_token'] );
 271          $Session->set( 'oauth_token_secret', $req_token['oauth_token_secret'] );
 272          $Session->dbsave();
 273  
 274          if( empty( $result ) )
 275          { // wasn't linked to twitter
 276              $result = '<a href='.$connection->getAuthorizeURL( $req_token, false ).'>'.T_( 'Click here to link to your twitter account' ).'</a>';
 277          }
 278          else
 279          {
 280              $result = $result.'<a href='.$connection->getAuthorizeURL( $req_token, false ).'>'.T_( 'Link to another account' ).'</a>';
 281              $unlink_url = $this->get_htsrv_url( 'unlink_account', array( 'target_type' => $target_type, 'target_id' => $target_id ), '&' );
 282              $unlink_url = $unlink_url.'&'.url_crumb( $target_type );
 283              $result = $result.' / '.'<a href="'.$unlink_url.'">'.T_( 'Unlink this account' ).'</a>';
 284          }
 285  
 286          return $result;
 287      }
 288  
 289  
 290      /**
 291       * Get twitter contact display name
 292       *
 293       * @access private
 294       *
 295       * @param string oauth_token
 296       * @param string oauth tokensecret
 297       * @return string contact display name on success, empty string on error
 298       */
 299  	function get_twitter_contact( $oauth_token, $oauth_token_secret )
 300      {
 301          $connection = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, $oauth_token, $oauth_token_secret );
 302          // get linked user account
 303          $account = $connection->get('account/verify_credentials');
 304          if( empty( $account->errors ) )
 305          {
 306              if( is_array( $account ) )
 307              { // Get only first account
 308                  $account = $account[0];
 309              }
 310              return $account->screen_name;
 311          }
 312          return '';
 313      }
 314  
 315  
 316      /**
 317       * Return the list of Htsrv (HTTP-Services) provided by the plugin.
 318       *
 319       * This implements the plugin interface for the list of methods that are valid to
 320       * get called through htsrv/call_plugin.php.
 321       *
 322       * @return array
 323       */
 324  	function GetHtsrvMethods()
 325      {
 326          return array( 'unlink_account', 'twitter_callback' );
 327      }
 328  
 329  
 330      /**
 331       * This callback method save the user's twitter oAuth, after the user allowed the b2evo_twitter plugin.
 332       * It's the twitter site callback.
 333       */
 334  	function htsrv_twitter_callback( $params )
 335      {
 336          global $Session, $Messages, $admin_url;
 337  
 338          if( ! isset( $params['target_type'] ) || ! isset( $params['target_id'] ) )
 339          {
 340              bad_request_die( 'Missing target params!' );
 341          }
 342  
 343          $target_type = $params['target_type'];
 344          $target_id = $params['target_id'];
 345  
 346          if( $target_type == 'blog' )
 347          { // redirect to blog settings
 348              $redirect_to = url_add_param( $admin_url, 'ctrl=coll_settings&tab=plugin_settings&blog='.$target_id );
 349          }
 350          else if ($target_type == 'user' )
 351          { // redirect to user advanced preferences form
 352              $redirect_to = url_add_param( $admin_url, 'ctrl=user&user_tab=advanced&user_ID='.$target_id );
 353          }
 354          else
 355          {
 356              debug_die( 'Target type has incorrect value!' );
 357          }
 358  
 359          $req_token = param( 'oauth_token', 'string', '' );
 360          $oauth_verifier = param( 'oauth_verifier', 'string', '' );
 361          $oauth_token = $Session->get( 'oauth_token' );
 362  
 363          // check tokens
 364          //if (isset($_REQUEST['oauth_token']) && $Session->get( 'oauth_token' ) !== $_REQUEST['oauth_token']) {
 365          if( ( !empty( $req_token ) && ( $oauth_token !== $req_token ) ) || empty( $target_type ) || empty( $target_id ) )
 366          {
 367              $Messages->add( T_( 'An error occurred during twitter plugin initialization. Please try again.' ), 'error' );
 368              /* Remove no longer needed request tokens */
 369              $Session->delete( 'oauth_token' );
 370              $Session->delete( 'oauth_token_secret' );
 371              $Session->dbsave();
 372              header_redirect( $redirect_to );
 373          }
 374  
 375          if( empty( $oauth_verifier ) )
 376          { // twitter refused the connection
 377              $denied = param( 'denied', 'string', '' );
 378              if( empty( $denied ) )
 379              {
 380                  $Messages->add( T_( 'Twitter did not answer. Twitter may be overloaded. Please try again.' ), 'error' );
 381              }
 382              else
 383              { // user didn't allow the connection
 384                  $Messages->add( T_( 'Twitter denied the connection.' ), 'error' );
 385              }
 386              header_redirect( $redirect_to ); // !!!! Where to redirect
 387          }
 388  
 389          require_once  'twitteroauth/twitteroauth.php';
 390          $connection = new TwitterOAuth( TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, $oauth_token, $Session->get( 'oauth_token_secret' ) );
 391  
 392          //get access token
 393          $access_token = $connection->getAccessToken( $oauth_verifier );
 394  
 395          // get oauth params
 396          $token = $access_token['oauth_token'];
 397          $secret = $access_token['oauth_token_secret'];
 398          $contact = $this->get_twitter_contact( $token, $secret );
 399          if( $target_type == 'blog' )
 400          { // blog settings
 401              $this->set_coll_setting( 'twitter_token', $token, $target_id );
 402              $this->set_coll_setting( 'twitter_secret', $secret, $target_id );
 403              $this->set_coll_setting( 'twitter_contact', $contact, $target_id );
 404              // save Collection settings
 405              $BlogCache = & get_BlogCache();
 406              $Blog = & $BlogCache->get_by_ID( $target_id, false, false );
 407              $Blog->dbupdate();
 408          }
 409          else if( $target_type == 'user' )
 410          { // user advanced preferences
 411              $this->UserSettings->set( 'twitter_token', $token, $target_id );
 412              $this->UserSettings->set( 'twitter_secret', $secret, $target_id );
 413              $this->UserSettings->set( 'twitter_contact', $contact, $target_id );
 414              $this->UserSettings->dbupdate();
 415          }
 416  
 417          /* Remove no longer needed request tokens */
 418          $Session->delete( 'oauth_token' );
 419          $Session->delete( 'oauth_token_secret' );
 420          $Session->dbsave();
 421  
 422          $Messages->add( T_( 'Twitter plugin was initialized successfully!' ), 'success' );
 423          header_redirect( $redirect_to );
 424      }
 425  
 426  
 427      /**
 428       * This callback method removes the twitter user oAuth data from DB.
 429       */
 430  	function htsrv_unlink_account( $params )
 431      {
 432          global $current_User, $Messages, $admin_url, $Session;
 433  
 434          if( ! isset( $params['target_type'] ) || ! isset( $params['target_id'] ) )
 435          {
 436              bad_request_die( 'Missing target params!' );
 437          }
 438  
 439          $target_type = $params['target_type'];
 440          $target_id = $params['target_id'];
 441  
 442          // Check that this action request is not a CSRF hacked request:
 443          $Session->assert_received_crumb( $target_type );
 444  
 445          if( $target_type == 'blog' )
 446          { // Blog settings
 447              $redirect_to = url_add_param( $admin_url, 'ctrl=coll_settings&tab=plugin_settings&blog='.$target_id );
 448  
 449              $BlogCache = & get_BlogCache();
 450              $Blog = $BlogCache->get_by_ID( $target_id );
 451  
 452              $this->delete_coll_setting( 'twitter_token', $target_id );
 453              $this->delete_coll_setting( 'twitter_secret', $target_id );
 454              $this->delete_coll_setting( 'twitter_contact', $target_id );
 455  
 456              $Blog->dbupdate();
 457          }
 458          else if ($target_type == 'user' )
 459          { // User settings
 460              $redirect_to = url_add_param( $admin_url, 'ctrl=user&user_tab=advanced&user_ID='.$target_id );
 461  
 462              if( isset( $current_User ) && ( !$current_User->check_perm( 'users', 'edit' ) ) && ( $target_id != $current_User->ID ) )
 463              { // user is only allowed to update him/herself
 464                  $Messages->add( T_('You are only allowed to update your own profile!'), 'error' );
 465                  header_redirect( $redirect_to );
 466                  // We have EXITed already at this point!!
 467              }
 468  
 469              $this->UserSettings->delete( 'twitter_token', $target_id );
 470              $this->UserSettings->delete( 'twitter_secret', $target_id );
 471              $this->UserSettings->delete( 'twitter_contact', $target_id );
 472              $this->UserSettings->dbupdate();
 473          }
 474          else
 475          {
 476              debug_die( 'Target type has incorrect value!' );
 477          }
 478  
 479          $Messages->add( T_('Your twitter account has been unlinked.'), 'success' );
 480          header_redirect( $redirect_to );
 481          // We have EXITed already at this point!!
 482      }
 483  
 484  
 485  	function get_oauth_info( $params = array() )
 486      {
 487          $params = array_merge( array(
 488                  'type'        => '',
 489                  'ID'        => '',
 490                  'blog_ID'    => '',
 491                  'user_ID'    => '',
 492              ), $params );
 493  
 494          if( $params['type'] == 'blog' )
 495          {    // Get from CollSettings
 496              $blog_ID = $params['ID'];
 497              $try_user = false;
 498          }
 499          elseif( $params['type'] == 'user' )
 500          {    // Get from UserSettings
 501              $user_ID = $params['ID'];
 502              $try_user = true;
 503          }
 504          else
 505          {    // Get from any
 506              $blog_ID = $params['blog_ID'];
 507              $user_ID = $params['user_ID'];
 508              $try_user = true;
 509          }
 510  
 511          $r = array();
 512  
 513          if( ! empty($blog_ID) )
 514          {    // CollSettings
 515              $BlogCache = & get_Cache('BlogCache');
 516              $Blog = & $BlogCache->get_by_ID( $blog_ID, false, false );
 517              if( !empty( $Blog ) )
 518              {
 519                  $r['token'] = $this->get_coll_setting( 'twitter_token', $Blog );
 520                  if( !empty($r['token']) )
 521                  {    // There is already a linked twitter user in this Blog, get token secret
 522                      $r['token_secret'] = $this->get_coll_setting( 'twitter_secret', $Blog );
 523                      $r['contact'] = $this->get_coll_setting( 'twitter_contact', $Blog );
 524                      $r['msg_format'] = $this->get_coll_setting( 'twitter_msg_format', $Blog );
 525  
 526                      $try_user = false; // Do not overwrite
 527                  }
 528              }
 529          }
 530  
 531          if( $try_user && ! empty($user_ID) )
 532          {    // UserSettings
 533              $r['token'] = $this->UserSettings->get( 'twitter_token', $user_ID );
 534              if( !empty( $r['token'] ) )
 535              {    // There is already a linked twitter user in this User, get token secret
 536                  $r['token_secret'] = $this->UserSettings->get( 'twitter_secret', $user_ID );
 537                  $r['contact'] = $this->UserSettings->get( 'twitter_contact', $user_ID );
 538                  $r['msg_format'] = $this->UserSettings->get( 'twitter_msg_format', $user_ID );
 539              }
 540          }
 541  
 542          return $r;
 543      }
 544  
 545  
 546  	function send_a_tweet( $content, & $Item, & $xmlrpcresp )
 547      {
 548          // Uses either plugin CollSettings or UserSettings
 549          $oauth = $this->get_oauth_info( array(
 550                  'user_ID'    => $Item->get_creator_User()->ID,
 551                  'blog_ID'    => $Item->get_Blog()->ID,
 552              ) );
 553  
 554          if( empty($oauth['msg_format']) || empty($oauth['token']) || empty($oauth['token_secret']) )
 555          { // Not found, fallback to Trying to get twitter account for User:
 556              $xmlrpcresp = T_('You must configure a twitter username/password before you can post to twitter.');
 557              return false;
 558          }
 559  
 560          $content = array_merge( array(
 561                      'title'        => '',
 562                      'excerpt'    => '',
 563                      'url'        => ''
 564                  ), $content );
 565  
 566          // Replace the title and exerpt, but before replacing decode the html entities
 567          $msg = str_replace(
 568                  array( '$title$', '$excerpt$' ),
 569                  array( html_entity_decode( $content['title'] ), html_entity_decode( $content['excerpt'] ) ),
 570                  $oauth['msg_format']
 571              );
 572  
 573          $msg_len = evo_strlen($msg);
 574          $full_url_len = evo_strlen( $content['url'] );
 575          $base_url_len = evo_strlen( $Item->get_Blog()->get_baseurl_root() );
 576  
 577          if( (evo_strpos($msg, '$url$') === 0) && ($base_url_len + $msg_len - 5) > $this->message_length_limit )
 578          {    // The message is too long and is starting with $url$
 579              $max_len = $this->message_length_limit + $full_url_len - $base_url_len;
 580              $msg = strmaxlen( str_replace( '$url$', $content['url'], $msg ), $max_len, '...' );
 581          }
 582          elseif( (evo_strpos(strrev($msg), 'p2b# $lru$') === 0) && ($base_url_len + $msg_len - 10) > $this->message_length_limit )
 583          {    // The message is too long and is ending on '$url$ #b2p'
 584              // Strip $url$, crop the message, and add URL to the end
 585              $max_len = $this->message_length_limit - $base_url_len -1; // save room for space character
 586              $msg = strmaxlen( str_replace( '$url$ #b2p', '', $msg ), $max_len, '...' );
 587              $msg .= ' '.$content['url'].' #b2p';
 588          }
 589          elseif( (evo_strpos(strrev($msg), '$lru$') === 0) && ($base_url_len + $msg_len - 5) > $this->message_length_limit )
 590          {    // Same as above, but without '#b2p' suffix
 591              $max_len = $this->message_length_limit - $base_url_len -1; // save room for space character
 592              $msg = strmaxlen( str_replace( '$url$', '', $msg ), $max_len, '...' );
 593              $msg .= ' '.$content['url'];
 594          }
 595          elseif( (evo_strpos($msg, '$url$') !== false) && ($base_url_len + $msg_len - 5) > $this->message_length_limit )
 596          {    // Message is too long and $url$ is somewhere in the middle
 597              // We can't do much, it will be rejected by Twitter
 598              // TODO: find a way to trim X chars before the URL and Y chars after
 599              $msg = str_replace( '$url$', $content['url'], $msg );
 600          }
 601          else
 602          {    // We don't want to add URL. Crop the message if needed
 603              $msg = strmaxlen( str_replace( '$url$', $content['url'], $msg ), $this->message_length_limit, '...' );
 604          }
 605  
 606          require_once  'twitteroauth/twitteroauth.php';
 607          $connection = new TwitterOAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, $oauth['token'], $oauth['token_secret'] );
 608          $result = $connection->post('statuses/update', array( 'status' => $msg ));
 609  
 610          if( empty($result) )
 611          {
 612              $xmlrpcresp = 'Unknown error while posting "'.htmlspecialchars( $msg ).'" to account @'.$oauth['contact'];
 613              return false;
 614          }
 615          elseif( !empty($result->error) )
 616          {
 617              $xmlrpcresp = $result->error;
 618              return false;
 619          }
 620  
 621          if( empty($oauth['contact']) )
 622          {
 623              $oauth['contact'] = $this->get_twitter_contact( $oauth['token'], $oauth['token_secret'] );
 624          }
 625  
 626          $xmlrpcresp = T_('Posted to account @').$oauth['contact'];
 627          return true;
 628      }
 629  }
 630  
 631  ?>

title

Description

title

Description

title

Description

title

title

Body