Plugin Directory

Changeset 736685


Ignore:
Timestamp:
07/05/2013 01:51:22 PM (12 years ago)
Author:
simonwheatley
Message:

New code for v0.6

Location:
tweet-watcher/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • tweet-watcher/trunk/class-tweet-watcher.php

    r603533 r736685  
    235235        foreach ( $users as $user_id => & $user ) {
    236236            $args = array( 'include_entities' => 'true', 'count' => 100 );
    237             if ( isset( $user[ 'last_mention_id' ] ) ) {
     237            if ( isset( $user[ 'last_mention_id' ] ) && $user[ 'last_mention_id' ] ) {
    238238                $args[ 'since_id' ] = $user[ 'last_mention_id' ];
    239239            }
     
    241241                $queued_mentions = (array) get_option( 'twtwchr_queued_mentions', array() );
    242242                foreach ( $mentions as & $mention ) {
     243                    // error_log( "TW: Queue $mention->id_str" );
    243244                    array_unshift( $queued_mentions, $mention );
    244245                }
     
    259260        foreach ( $users as $user_id => & $user ) {
    260261            $args = array( 'include_entities' => 'true', 'include_rts' => 'true', 'contributor_details' => 'true', 'count' => 100 );
    261             if ( isset( $user[ 'last_tweet_id' ] ) ) {
     262            if ( isset( $user[ 'last_tweet_id' ] ) && $user[ 'last_tweet_id' ] ) {
    262263                $args[ 'since_id' ] = $user[ 'last_tweet_id' ];
    263264            }
    264             if ( $mentions = $this->oauth->get_tweets( $user_id, $args ) ) {
     265            if ( $tweets = $this->oauth->get_tweets( $user_id, $args ) ) {
    265266                $queued_tweets = (array) get_option( 'twtwchr_queued_tweets', array() );
    266                 foreach ( $mentions as & $mention ) {
    267                     array_unshift( $queued_tweets, $mention );
     267                foreach ( $tweets as & $tweet ) {
     268                    array_unshift( $queued_tweets, $tweet );
    268269                }
    269270                update_option( 'twtwchr_queued_tweets', $queued_tweets );
    270                 $last_tweet = array_shift( $mentions );
     271                $last_tweet = array_shift( $tweets );
    271272                $this->oauth->set_user_property( $user_id, 'last_tweet_id', $last_tweet->id_str );
    272273            }
  • tweet-watcher/trunk/class-twitter-oauth.php

    r601914 r736685  
    3030        $params = array_merge( $params, $override_params );
    3131       
    32         $response = $this->do_oauth( 'https://api.twitter.com/1/statuses/mentions.json', 'GET', $params, $user[ 'oauth_token_secret' ] );
     32        $response = $this->do_oauth( 'https://api.twitter.com/1.1/statuses/mentions.json', 'GET', $params, $user[ 'oauth_token_secret' ] );
    3333        return json_decode( wp_remote_retrieve_body( $response ) );
    3434    }
     
    5151        $params = array_merge( $params, $override_params );
    5252       
    53         $response = $this->do_oauth( 'https://api.twitter.com/1/statuses/user_timeline.json', 'GET', $params, $user[ 'oauth_token_secret' ] );
     53        $response = $this->do_oauth( 'https://api.twitter.com/1.1/statuses/user_timeline.json', 'GET', $params, $user[ 'oauth_token_secret' ] );
     54        return json_decode( wp_remote_retrieve_body( $response ) );
     55    }
     56   
     57    function get_tweet_as_user( $user_id, $tweet_id_str, $override_params = array() ) {
     58        // https://api.twitter.com/1/statuses/show.json?id=XXX
     59       
     60        if ( ! $user = $this->get_user( $user_id ) )
     61            return new WP_Error( 'twtwchr_twitter_error', __( 'No user exists for that User ID. (Error 200)', 'twtwchr' ) );
     62
     63        $params = array();
     64        $params['id'] = $tweet_id_str;
     65        $params['user_id'] = $user_id;
     66        $params['oauth_consumer_key'] = $this->oauth_consumer_key;
     67        $params['oauth_nonce'] = $this->get_nonce();
     68        $params['oauth_signature_method'] = 'HMAC-SHA1';
     69        $params['oauth_timestamp'] = time() + $this->oauth_time_offset;
     70        $params['oauth_token'] = $user[ 'oauth_token' ];
     71        $params['oauth_version'] = '1.0';
     72       
     73        $params = array_merge( $params, $override_params );
     74       
     75        $response = $this->do_oauth( 'https://api.twitter.com/1/statuses/show.json', 'GET', $params, $user[ 'oauth_token_secret' ] );
    5476        return json_decode( wp_remote_retrieve_body( $response ) );
    5577    }
     
    235257        if ( ! isset( $users[ $user_id ] ) )
    236258            return false;
     259        $user = & $users[ $user_id ][ 'last_tweet_id' ];
    237260        return $users[ $user_id ];
    238261    }
    239262   
    240263    function get_users() {
    241         return $this->get_property( 'users', array() );
     264        $users = $this->get_property( 'users', array() );
     265        foreach ( $users as & $user ) {
     266            $user[ 'last_tweet_id' ] = isset( $user[ 'last_tweet_id' ] ) ? $user[ 'last_tweet_id' ] : null;
     267            $user[ 'last_mention_id' ] = isset( $user[ 'last_mention_id' ] ) ? $user[ 'last_mention_id' ] : null;
     268        }
     269        return $users;
    242270    }
    243271   
  • tweet-watcher/trunk/readme.txt

    r603533 r736685  
    44Requires at least: 3.4.2
    55Tested up to: 3.4.2
    6 Stable tag: 0.3
     6Stable tag: 0.6
    77 
    88A WordPress plugin which authenticates with a number of Twitter accounts and watches their mention and tweet stream, firing actions for each mention or tweet.
     
    1616
    1717== Changelog ==
     18
     19= 0.6 =
     20
     21Friday 05 July 2013
     22
     23* BUGFIX: Don't set `since_id` if it's not available, as Twitter will object
     24* FIDDLING: Rename `$mention` to `$tweet` when talking about tweets not mentions
     25* BUGFIX: User Twitter API v1.1, so it actually works
     26
     27= 0.5 =
     28
     29Wednesday 5 December 2012
     30
     31* BUGFIX: Removed some PHP notices from settings page for unset indexes on the $user array
     32* BUGFIX: Remove stray error_log call.
    1833
    1934= 0.4 =
  • tweet-watcher/trunk/templates-admin/settings.php

    r603533 r736685  
    4141    <?php endif; ?>
    4242       
    43     <p><a href="<?php echo esc_url( $auth_url ); ?>" class="button button-primary">Authenticate a new acccount</a></p>
     43    <p><a href="<?php echo esc_url( $auth_url ); ?>" class="button button-primary">Authenticate a new account</a></p>
    4444   
    4545</div>
  • tweet-watcher/trunk/tweet-watcher.php

    r603533 r736685  
    55Plugin URI: https://github.com/simonwheatley/Tweet-Watcher/
    66Description: Authenticates with a number of Twitter accounts and fires actions for each mention or tweet.
    7 Version: 0.4
     7Version: 0.6
    88Author: Simon Wheatley (Code for the People)
    99Author URI: http://codeforthepeople.com/
     
    4242    return __FILE__;
    4343}
    44 
    45 ?>
Note: See TracChangeset for help on using the changeset viewer.