Plugin Directory

Changeset 729135


Ignore:
Timestamp:
06/21/2013 01:15:04 AM (13 years ago)
Author:
titopandub
Message:

Fix Twitter API

Location:
evergreen-post-tweeter/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • evergreen-post-tweeter/trunk/Include/ept-oauth.php

    r725789 r729135  
    222222    }
    223223
     224    function do_get_request_oauth($url, $oauth_header)
     225    {
     226        EPT_DEBUG('Doing GET request, OAUTH header is ' . $oauth_header);
     227        $request = new WP_Http;
     228        EPT_DEBUG('..using WP transport');
     229
     230        $params['method'] = 'GET';
     231        $params['headers'] = array('Authorization' => $oauth_header);
     232
     233        $result = $request->request($url, $params);
     234
     235        if (!is_wp_error($result)) {
     236
     237            EPT_DEBUG('..WP transport returned a status code of ' . $result['response']['code']);
     238
     239            $this->response_code = $result['response']['code'];
     240
     241            if ($result['response']['code'] == '200') {
     242                return $result['body'];
     243            } else {
     244                EPT_DEBUG('..RESPONSE was ' . print_r($result['response'], true));
     245
     246                switch ($result['response']['code']) {
     247                    case 403:
     248                        $this->duplicate_tweet = true;
     249                        break;
     250                }
     251
     252                $error_message_found = preg_match('#<error>(.*)</error>#i', $result['body'], $matches);
     253                if ($error_message_found) {
     254                    $this->error_message = $matches[1];
     255                }
     256                return $result;
     257            }
     258        } else {
     259            EPT_DEBUG("..WP transport returned an error, " . $result->get_error_message());
     260        }
     261    }
     262
    224263    function get_nonce() {
    225264        return md5(mt_rand() + mt_rand());
     
    263302    }
    264303
    265     function do_oauth($url, $params, $token_secret = '') {
    266         $sig_string = $this->create_signature_base_string(false, $url, $params);
    267 
     304    function do_oauth($url, $params, $token_secret = '', $method = 'post') {
     305        if ($method == 'post') {
     306            $sig_string = $this->create_signature_base_string(false, $url, $params);
     307        } else if ($method == 'get') {
     308            $sig_string = $this->create_signature_base_string(true, 'https://api.twitter.com/1.1/users/show.json', $params);
     309        }
    268310        //$hash = hash_hmac( 'sha1', $sig_string, EPT_OAUTH_CONSUMER_SECRET . '&' . $token_secret, true );
    269311        $hash = $this->hmac_sha1($this->oauth_consumer_secret . '&' . $token_secret, $sig_string);
     
    285327
    286328        $header .= implode($all_params, ", ");
    287 
    288         return $this->do_request($url, $header, $other_params);
     329        if ($method == 'post') {
     330            return $this->do_request($url, $header, $other_params);
     331        } else {
     332            return $this->do_get_request_oauth($url, $header);
     333        }
    289334    }
    290335
     
    376421        return EPT_OAUTH_AUTHORIZE_URL . '?oauth_token=' . $token;
    377422    }
    378 
    379     function get_user_info($user_id) {
    380         $url = 'https://api.twitter.com/1.1/users/show.json?user_id=' . $user_id;
    381 
    382         $result = $this->do_get_request($url);
     423    // making new user info
     424    function get_user_info($screen_name, $token, $token_secret) {
     425        $params = array();
     426
     427        $params['oauth_consumer_key'] =$this->oauth_consumer_key;
     428        $params['oauth_signature_method'] = 'HMAC-SHA1';
     429        $params['oauth_timestamp'] = time() + $this->oauth_time_offset;
     430        $params['oauth_nonce'] = $this->get_nonce();
     431        $params['oauth_version'] = '1.0';
     432        $params['oauth_token'] = $token;
     433        $params['screen_name'] = $screen_name;
     434
     435        $url = 'https://api.twitter.com/1.1/users/show.json?screen_name=' . $screen_name;
     436
     437        $result = $this->do_oauth($url, $params, $token_secret, 'get');
    383438        if ($result) {
    384439            $new_params = json_decode($result, true);
    385440            return $new_params;
     441        } else {
     442            return $result;
    386443        }
    387444    }
  • evergreen-post-tweeter/trunk/ept-admin.php

    r725789 r729135  
    2727                $settings['oauth_access_token_secret'] = $result['oauth_token_secret'];
    2828                $settings['user_id'] = $result['user_id'];
    29 
    30                 $result = $ept_oauth->get_user_info($result['user_id']);
     29                $settings['screen_name'] = $result['screen_name'];
     30
     31                $result = $ept_oauth->get_user_info($result['screen_name'], $settings['oauth_access_token'], $settings['oauth_access_token_secret']);
    3132                if ($result) {
    32                     $settings['profile_image_url'] = $result['user']['profile_image_url'];
    33                     $settings['screen_name'] = $result['user']['screen_name'];
    34                     if (isset($result['user']['location'])) {
    35                         $settings['location'] = $result['user']['location'];
     33                    $settings['profile_image_url'] = $result['profile_image_url'];
     34                    $settings['screen_name'] = $result['screen_name'];
     35                    if (isset($result['location'])) {
     36                        $settings['location'] = $result['location'];
    3637                    } else {
    3738                        $settings['location'] = false;
    3839                    }
    3940                }
    40 
     41               
    4142                ept_save_settings($settings);
    4243                echo '<script language="javascript">window.open ("' . get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=Evergreen","_self")</script>';
     
    170171                update_option('ept_opt_use_url_shortner', true);
    171172            } else {
    172 
    173173                update_option('ept_opt_use_url_shortner', false);
    174174            }
     
    261261            }
    262262
     263            //use Pause Tweet?
     264            if (isset($_POST['ept_opt_use_pause_tweet'])) {
     265                update_option('ept_opt_use_pause_tweet', true);
     266            } else {
     267
     268                update_option('ept_opt_use_pause_tweet', false);
     269            }
     270
    263271            //pause auto tweet - start time
    264272            if (isset($_POST['ept_opt_start_pause_time'])) {
     
    457465            $maxAgeLimit = ept_opt_MAX_AGE_LIMIT;
    458466        }
     467
     468        //use pause tweet?
     469        $use_pause_tweet = get_option('ept_opt_use_pause_tweet');
     470        if (!isset($use_pause_tweet)) {
     471            $use_pause_tweet = "";
     472        } elseif ($use_pause_tweet)
     473            $use_pause_tweet = "checked";
     474        else
     475            $use_pause_tweet="";
    459476
    460477        //pause auto tweet - start time
     
    633650
    634651                        <div class="option">
    635                             <label class="ttip">' . __('Start Time to Pause Tweet: ', 'Evergreen') . ': </label>
    636                                 <input type="text" id="ept_opt_start_pause_time" value="' . $ept_opt_start_pause_time . '" name="ept_opt_start_pause_time" />
    637                                 <strong>Default 22:00</strong>
     652                            <label for="ept_opt_use_pause_tweet">' . __('Prevent Automatic Tweeting Between Certain Hours?: ', 'Evergreen') . '</label>
     653                            <input onchange="return showPauseTweet()" type="checkbox" name="ept_opt_use_pause_tweet" id="ept_opt_use_pause_tweet" ' . $use_pause_tweet . ' />
    638654                        </div>
    639655
    640                         <div class="option">
    641                             <label class="ttip">' . __('End Time to Pause Tweet: ', 'Evergreen') . ': </label>
    642                                 <input type="text" id="ept_opt_end_pause_time" value="' . $ept_opt_end_pause_time . '" name="ept_opt_end_pause_time" />
    643                                 <strong>Default 05:00</strong>
     656                        <div id="pausetweet">
     657                            <div class="option">
     658                                <label class="ttip">' . __('Start Time to Pause Tweet: ', 'Evergreen') . ': </label>
     659                                    <input type="text" id="ept_opt_start_pause_time" value="' . $ept_opt_start_pause_time . '" name="ept_opt_start_pause_time" />
     660                                    <strong>Default 22:00</strong>
     661                            </div>
     662
     663                            <div class="option">
     664                                <label class="ttip">' . __('End Time to Pause Tweet: ', 'Evergreen') . ': </label>
     665                                    <input type="text" id="ept_opt_end_pause_time" value="' . $ept_opt_end_pause_time . '" name="ept_opt_end_pause_time" />
     666                                    <strong>Default 05:00</strong>
     667                            </div>
    644668                        </div>
    645669                                       
     
    750774        }
    751775}
     776
     777function showPauseTweet()
     778{
     779                       
     780
     781    if((document.getElementById("ept_opt_use_pause_tweet").checked))
     782        {
     783            document.getElementById("pausetweet").style.display="block";
     784        }
     785        else
     786        {
     787            document.getElementById("pausetweet").style.display="none";
     788        }
     789}
    752790function setFormAction()
    753791{
     
    766804showURLAPI();
    767805showshortener();
     806showPauseTweet();
    768807
    769808</script>');
  • evergreen-post-tweeter/trunk/ept-core.php

    r725789 r729135  
    141141    //check last tweet time against set interval and span
    142142    //also check if it isn't in pause time
    143     if (ept_opt_update_time() && ept_in_pause_time()) {
     143    if (ept_opt_update_time() && ! ept_in_pause_time()) {
    144144        update_option('ept_opt_last_update', time());
    145145        ept_opt_tweet_old_post();
     
    615615function ept_in_pause_time()
    616616{
     617    $ept_opt_use_pause_tweet = get_option('ept_opt_use_pause_tweet');
     618
    617619    //pause auto tweet - start time
    618620    $ept_opt_start_pause_time = get_option('ept_opt_start_pause_time');
     
    627629    }
    628630
     631    if (! $ept_opt_use_pause_tweet) {
     632        return false;
     633    }
     634
    629635    if (strtotime($ept_opt_start_pause_time) > strtotime($ept_opt_end_pause_time))
    630636        if (strtotime($ept_opt_start_pause_time) < current_time('timestamp', 0) ||
    631637            current_time('timestamp', 0) < strtotime($ept_opt_end_pause_time)) {
     638            $ret = true;
     639        } else {
    632640            $ret = false;
    633         } else {
    634             $ret = true;
    635641        }
    636642    else {
    637643        if (strtotime($ept_opt_start_pause_time) < current_time('timestamp', 0) &&
    638644            current_time('timestamp', 0) < strtotime($ept_opt_end_pause_time)) {
     645            $ret = true;
     646        } else {
    639647            $ret = false;
    640         } else {
    641             $ret = true;
    642648        }
    643649    }
     
    718724    update_option('ept_opt_use_inline_hashtags','');
    719725    update_option('ept_opt_use_url_shortner','');
     726    update_option('ept_opt_use_pause_tweet','');
    720727    update_option('ept_cat_tweet', '');
    721728    update_option('ept_tag_tweet', '');
  • evergreen-post-tweeter/trunk/evergreen.php

    r725789 r729135  
    33Plugin Name: Evergreen Post Tweeter
    44Plugin URI: http://www.leavingworkbehind.com/evergreen-post-tweeter/
    5 Description: WARNING!! This plugin is currently not functional but that we'll have a patch up ASAP!!! Evergreen Post Tweeter enables you to automatically tweet out links to old posts based upon a tag or tags.
     5Description: Evergreen Post Tweeter enables you to automatically tweet out links to old posts based upon a tag or tags.
    66Author: Tom Ewer
    7 Version: 1.5.2
     7Version: 1.5.3
    88Author URI: http://www.leavingworkbehind.com/about-me/
    99*/ 
  • evergreen-post-tweeter/trunk/readme.txt

    r725789 r729135  
    1313
    1414== Description ==
    15 
    16 WARNING!! This plugin is currently not functional but that we'll have a patch up ASAP!!!
    1715
    1816Evergreen Post Tweeter enables you to automatically and periodically tweet out links to old posts based upon a tag or tags.
     
    5856== Upgrade Notice ==
    5957
     58= 1.5.3 =
     59* Fix Twitter API.
     60
    6061= 1.5.2 =
    6162* Fix bug on pause time option.
     
    8384== Changelog ==
    8485
     86= 1.5.3 =
     87* Fix Twitter API.
     88
    8589= 1.5.2 =
    8690* Fix bug on pause time option.
Note: See TracChangeset for help on using the changeset viewer.