Plugin Directory

Changeset 596258


Ignore:
Timestamp:
09/08/2012 11:26:34 AM (14 years ago)
Author:
ArnaudBan
Message:

Width modification

Accept an empty value = maximum value = 500px (twitter limitation)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • widget-embed-lastest-tweets/trunk/widget-embed-latest-tweets.php

    r594946 r596258  
    44 * Plugin URI: http://www.arnaudbanvillet.com/blog/portfolio/widget-embed-latest-tweets/
    55 * Description: A Widget to show your latest tweets. Use the oEmbed methode and some cache. It is simple, elegant and it works. Just type your user name and the numbers of tweets you want to show.
    6  * Version: 0.3.2
     6 * Version: 0.4
    77 * Author: Arnaud Banvillet
    88 * Author URI: http://www.arnaudbanvillet.com
     
    129129
    130130        $maxwidth = strip_tags($new_instance['maxwidth']);
    131         if( is_numeric( $maxwidth ) )
     131        if( is_numeric( $maxwidth ) || empty( $maxwidth ))
    132132            $instance['maxwidth'] = $maxwidth;
    133133
     
    174174
    175175        <p>
    176             <label for="<?php echo $this->get_field_id('maxwidth'); ?>"><?php _e('Maximum Width :', 'ab-welt-locales') ?></label>
    177             <input id="<?php echo $this->get_field_id('maxwidth'); ?>" name="<?php echo $this->get_field_name('maxwidth'); ?>" type="number" step="1" min="20" max="1000" value="<?php echo $maxwidth; ?>" />
     176            <label for="<?php echo $this->get_field_id('maxwidth'); ?>"><?php _e('Width :', 'ab-welt-locales') ?></label>
     177            <input id="<?php echo $this->get_field_id('maxwidth'); ?>" name="<?php echo $this->get_field_name('maxwidth'); ?>" type="number" step="1" min="250" max="550" value="<?php echo $maxwidth; ?>" />
     178            <br />
     179            <span class="description"><?php _e('Twitter says :This value is constrained to be between 250 and 550 pixels') ?></span>
     180
    178181        </p>
    179182
     
    231234        if( $oauth_methode ){
    232235            $connection = new TwitterOAuth($twitter_oauth_var[consumer_key], $twitter_oauth_var[consumer_secret], $twitter_oauth_var[token_key],$twitter_oauth_var[token_secret]);
    233 
    234236            $last_tweet = $connection->get('http://api.twitter.com/1/statuses/user_timeline.json', $options );
    235237
     
    259261
    260262                    $options['id'] = $id;
     263
     264                    if( empty( $maxwidth) ){
     265                        unset( $options['maxwidth']);
     266                    }
     267
    261268                    $last_tweet_html = $connection->get('https://api.twitter.com/1/statuses/oembed.json', $options);
    262269
     
    269276                    // We use the GET statuses/oembed API to get the html to display
    270277                    // https://dev.twitter.com/docs/api/1/get/statuses/oembed
    271                     $last_tweet_html = @file_get_contents('https://api.twitter.com/1/statuses/oembed.json?id=' . $id . '&align=' . $align . '&hide_thread='. $hide_thread .'&lang=' . $lang . '&maxwidth=' .$maxwidth);
     278                    $option_string = 'id=' . $id . '&align=' . $align . '&hide_thread='. $hide_thread .'&lang=' . $lang;
     279
     280                    if( is_numeric( $maxwidth) ){
     281                        $option_string .= '&maxwidth=' . $maxwidth;
     282                    }
     283
     284                    $last_tweet_html = @file_get_contents('https://api.twitter.com/1/statuses/oembed.json?' . $option_string);
    272285                    $last_tweet_html = json_decode($last_tweet_html);
    273286
Note: See TracChangeset for help on using the changeset viewer.