Plugin Directory

Changeset 953529


Ignore:
Timestamp:
07/23/2014 02:48:55 PM (12 years ago)
Author:
ArnaudBan
Message:

version 0.6.4

Location:
widget-embed-lastest-tweets
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • widget-embed-lastest-tweets/tags/0.6.4/js/welt-scripts.js

    r907818 r953529  
    55
    66jQuery(document).ready( function(){
     7
     8    var all_welt_widgets = [];
    79
    810    jQuery('.welt-tweet-wrapper').each( function(){
     
    1416        widget_id = widget_id.replace('welt-', '');
    1517
    16         var data = {
    17             action: 'welt_display_tweets',
    18             widget_id: widget_id,
    19             widget_data: widget_data
    20         };
     18        all_welt_widgets.push( { widget_id : widget_id, widget_data : widget_data } );
    2119
    22         jQuery.post(
    23             weltAjaxurl,
    24             data,
    25             function(response) {
    26                 current_widget.append(response);
     20    });
     21
     22
     23    var data = {
     24        action: 'welt_display_tweets',
     25        all_welt_widgets: all_welt_widgets,
     26    };
     27
     28    jQuery.post(
     29        weltAjaxurl,
     30        data,
     31        function(response) {
     32
     33            if( response ){
     34                response = JSON.parse( response );
     35
     36                for( var i in response ){
     37
     38                    var widget_selector =  '#welt-' + i;
     39                    jQuery( widget_selector ).append( response[i] );
     40                }
     41
    2742                twttr.widgets.load();
    2843            }
    29         );
    30 
    31     });
     44        }
     45    );
    3246});
    3347
  • widget-embed-lastest-tweets/tags/0.6.4/readme.txt

    r946503 r953529  
    6161== Changelog ==
    6262
     63= 0.6.4 =
     64
     65* Only one AJAX calls to get Tweet data ( Thank you Christof Rodejohann )
     66* Some bugfix for the new widget preview in the customizer
     67
    6368= 0.6.3 =
    6469
    65 * fix : probleme with new tweet not showing
    66 Thank you Christof Rodejohann
     70* fix : probleme with new tweet not showing ( Thank you Christof Rodejohann )
    6771
    6872= 0.6.2 =
  • widget-embed-lastest-tweets/tags/0.6.4/widget-embed-latest-tweets.php

    r946507 r953529  
    44 * Plugin URI: http://arnaudban.me/blog/portfolio/widget-embed-latest-tweets/
    55 * Description: A Widget to show your latest Tweets. Use the oEmbed methode and some cache. Visit the option page "Plugins->Widget Embed Last Plugin" to authentify yourself
    6  * Version: 0.6.3
     6 * Version: 0.6.4
    77 * Author: Arnaud Banvillet
    88 * Author URI: http://arnaudban.me
     
    3737            'align'            => 'none',
    3838            'hide_thread'      => true,
    39             'lang'             => 'en',
    4039            'include_rts'      => true,
    4140            'hide_media'       => true,
     
    5453                        array('description' => __('Show your latest Tweets', 'widget-embed-lastest-tweets'))// Args
    5554        );
     55
     56        if( defined( 'WPLANG' ) ){
     57            $this->defaut['lang'] = substr( WPLANG, 0, 2 );
     58        } else {
     59            $this->defaut['lang'] = 'en';
     60        }
    5661    }
    5762
     
    8590        if( !empty( $screen_name ) ){
    8691
    87             if( method_exists('Widget', 'is_preview' ) && $this->is_preview() ){
    88 
    89                 $data = ' ';
     92            $data = ' ';
     93            if( method_exists('WP_Widget', 'is_preview' ) && $this->is_preview() ){
     94
    9095                foreach ($instance as $key => $value) {
    9196
     
    95100                }
    96101
    97                 echo "<div id='welt-{$this->id}' class='welt-tweet-wrapper'$data></div>";
    98 
    99             } else {
    100 
    101                 echo "<div id='welt-{$this->id}' class='welt-tweet-wrapper'></div>";
    102102            }
     103
     104            echo "<div id='welt-{$this->id}' class='welt-tweet-wrapper'$data></div>";
     105
    103106        }
    104107
     
    144147
    145148        // When everythings is check and we are not in the customizer, set the transient
    146         if( ! method_exists('Widget', 'is_preview' ) || ! $this->is_preview() ){
    147             welt_set_tweet_transient( $this->id, $instance , true );
    148         }
    149 
     149        if( ! method_exists('WP_Widget', 'is_preview' ) || ! $this->is_preview() ){
     150
     151                welt_set_tweet_transient( $this->id, $instance );
     152
     153        }
    150154
    151155        return $instance;
     
    168172        // Are all the options there ?
    169173        if( is_array( $twitter_oauth_var ) && count($twitter_oauth_var) == 4 ){
     174
     175
    170176
    171177            ?>
     
    253259function welt_set_tweet_transient( $widget_id, $options ){
    254260
    255     $return_value = false;
    256261
    257262    $last_tweet = welt_get_latest_tweet( $options );
     
    376381function welt_display_tweets( ){
    377382
    378     $widget_id = $_POST['widget_id'];
    379 
    380     $tweet_html = '';
    381 
    382     // In preview mode we passe all instance in data html attrribut
    383     if( isset( $_POST['widget_data'] ) && ! empty( $_POST['widget_data'] ) ){
    384 
    385         $instance = $_POST['widget_data'];
    386 
    387         $last_tweet = welt_get_latest_tweet( $instance );
    388 
    389         foreach ($last_tweet as $tweet_id) {
    390 
    391             $tweet_html .= welt_get_tweet_html( $tweet_id, $instance );
    392 
    393         }
    394 
    395 
    396     } else {
    397 
    398 
    399         $last_tweet = get_transient('last_tweet_' . $widget_id);
    400 
    401         if( false === $last_tweet ) {
    402 
    403             // Get the widget instance
    404             $all_instance_widget = get_option('widget_welt_last_tweets');
    405 
    406             $widget_real_id = str_replace('welt_last_tweets-', '', $widget_id);
    407 
    408             $instance = $all_instance_widget[$widget_real_id];
    409 
    410 
    411             // Set the transient for this widget
     383    $all_welt_widgets = $_POST['all_welt_widgets'];
     384
     385    $tweet_html = array();
     386
     387    foreach ($all_welt_widgets as $welt_widget ) {
     388
     389        $widget_id = $welt_widget['widget_id'];
     390        $widget_data = isset( $welt_widget['widget_data'] ) && ! empty( $welt_widget['widget_data'] ) ? $welt_widget['widget_data'] : false;
     391
     392        $tweet_html[ $widget_id ] = '';
     393
     394        // In preview mode we passe all instance in data html attrribut
     395        if( $widget_data ){
     396
     397            $instance = $widget_data;
     398
    412399            $last_tweet = welt_get_latest_tweet( $instance );
    413         }
    414 
    415         if( $last_tweet && is_array( $last_tweet ) ){
    416 
    417             set_transient('last_tweet_' . $widget_id , $last_tweet, 60 * 5);
    418400
    419401            foreach ($last_tweet as $tweet_id) {
    420402
    421                 // retrocompatibility
    422                 if( is_object( $tweet_id ) ){
    423                     $tweet_id = $tweet_id->id_str;
     403                $tweet_html[ $widget_id ] .= welt_get_tweet_html( $tweet_id, $instance );
     404
     405            }
     406
     407
     408        } else {
     409
     410
     411            $last_tweet = get_transient('last_tweet_' . $widget_id);
     412
     413            if( false === $last_tweet ) {
     414
     415                // Get the widget instance
     416                $instance = $instance = welt_get_widget_instance( $widget_id );
     417
     418
     419                // Set the transient for this widget
     420                $last_tweet = welt_get_latest_tweet( $instance );
     421            }
     422
     423            if( $last_tweet && is_array( $last_tweet ) ){
     424
     425                set_transient('last_tweet_' . $widget_id , $last_tweet, 60 * 5);
     426
     427                foreach ($last_tweet as $tweet_id) {
     428
     429                    // retrocompatibility
     430                    if( is_object( $tweet_id ) ){
     431                        $tweet_id = $tweet_id->id_str;
     432                    }
     433
     434                    $tweet_html_transient = get_transient('last_tweet_html_' . $tweet_id);
     435
     436                    if( false === $tweet_html_transient ){
     437
     438                        $instance = welt_get_widget_instance( $widget_id );
     439
     440                        $tweet_html_transient = welt_get_tweet_html( $tweet_id, $instance );
     441
     442                        if( $tweet_html_transient ){
     443                            set_transient('last_tweet_html_' . $tweet_id, $tweet_html_transient, ( 24 * WEEK_IN_SECONDS ) ); // 6 mouths
     444                            $tweet_html[ $widget_id ] .= $tweet_html_transient;
     445                        }
     446
     447                    } else {
     448
     449                        // retrocompatibility
     450                        if( is_object( $tweet_html_transient ) ){
     451                            $tweet_html_transient = $tweet_html_transient->html;
     452                        }
     453                        $tweet_html[ $widget_id ] .= $tweet_html_transient;
     454                    }
     455
    424456                }
    425 
    426                 $tweet_html_transient = get_transient('last_tweet_html_' . $tweet_id);
    427 
    428                 if( false === $tweet_html_transient ){
    429 
    430                     $tweet_html_transient = welt_get_tweet_html( $tweet_id, $instance );
    431 
    432                     if( $tweet_html_transient ){
    433                         set_transient('last_tweet_html_' . $tweet_id, $tweet_html_transient, ( 24 * WEEK_IN_SECONDS ) ); // 6 mouths
    434                         $tweet_html .= $tweet_html_transient;
    435                     }
    436 
    437                 } else {
    438 
    439                     // retrocompatibility
    440                     if( is_object( $tweet_html_transient ) ){
    441                         $tweet_html_transient = $tweet_html_transient->html;
    442                     }
    443                     $tweet_html .= $tweet_html_transient;
    444                 }
    445 
    446457            }
    447         }
    448 
    449     }
    450 
    451     echo $tweet_html;
     458
     459        }
     460    }
     461
     462
     463    echo json_encode( $tweet_html );
    452464    die;
    453465}
     
    456468add_action('wp_ajax_nopriv_welt_display_tweets', 'welt_display_tweets');
    457469
     470
     471/**
     472 * Return the instance of a widget base on his id
     473 */
     474function welt_get_widget_instance( $widget_id ){
     475
     476    // Get the widget instance
     477    $all_instance_widget = get_option('widget_welt_last_tweets');
     478
     479    $widget_real_id = str_replace('welt_last_tweets-', '', $widget_id);
     480
     481    return $all_instance_widget[$widget_real_id];
     482}
    458483
    459484/**
  • widget-embed-lastest-tweets/trunk/js/welt-scripts.js

    r907818 r953529  
    55
    66jQuery(document).ready( function(){
     7
     8    var all_welt_widgets = [];
    79
    810    jQuery('.welt-tweet-wrapper').each( function(){
     
    1416        widget_id = widget_id.replace('welt-', '');
    1517
    16         var data = {
    17             action: 'welt_display_tweets',
    18             widget_id: widget_id,
    19             widget_data: widget_data
    20         };
     18        all_welt_widgets.push( { widget_id : widget_id, widget_data : widget_data } );
    2119
    22         jQuery.post(
    23             weltAjaxurl,
    24             data,
    25             function(response) {
    26                 current_widget.append(response);
     20    });
     21
     22
     23    var data = {
     24        action: 'welt_display_tweets',
     25        all_welt_widgets: all_welt_widgets,
     26    };
     27
     28    jQuery.post(
     29        weltAjaxurl,
     30        data,
     31        function(response) {
     32
     33            if( response ){
     34                response = JSON.parse( response );
     35
     36                for( var i in response ){
     37
     38                    var widget_selector =  '#welt-' + i;
     39                    jQuery( widget_selector ).append( response[i] );
     40                }
     41
    2742                twttr.widgets.load();
    2843            }
    29         );
    30 
    31     });
     44        }
     45    );
    3246});
    3347
  • widget-embed-lastest-tweets/trunk/readme.txt

    r946503 r953529  
    6161== Changelog ==
    6262
     63= 0.6.4 =
     64
     65* Only one AJAX calls to get Tweet data ( Thank you Christof Rodejohann )
     66* Some bugfix for the new widget preview in the customizer
     67
    6368= 0.6.3 =
    6469
    65 * fix : probleme with new tweet not showing
    66 Thank you Christof Rodejohann
     70* fix : probleme with new tweet not showing ( Thank you Christof Rodejohann )
    6771
    6872= 0.6.2 =
  • widget-embed-lastest-tweets/trunk/widget-embed-latest-tweets.php

    r946507 r953529  
    44 * Plugin URI: http://arnaudban.me/blog/portfolio/widget-embed-latest-tweets/
    55 * Description: A Widget to show your latest Tweets. Use the oEmbed methode and some cache. Visit the option page "Plugins->Widget Embed Last Plugin" to authentify yourself
    6  * Version: 0.6.3
     6 * Version: 0.6.4
    77 * Author: Arnaud Banvillet
    88 * Author URI: http://arnaudban.me
     
    3737            'align'            => 'none',
    3838            'hide_thread'      => true,
    39             'lang'             => 'en',
    4039            'include_rts'      => true,
    4140            'hide_media'       => true,
     
    5453                        array('description' => __('Show your latest Tweets', 'widget-embed-lastest-tweets'))// Args
    5554        );
     55
     56        if( defined( 'WPLANG' ) ){
     57            $this->defaut['lang'] = substr( WPLANG, 0, 2 );
     58        } else {
     59            $this->defaut['lang'] = 'en';
     60        }
    5661    }
    5762
     
    8590        if( !empty( $screen_name ) ){
    8691
    87             if( method_exists('Widget', 'is_preview' ) && $this->is_preview() ){
    88 
    89                 $data = ' ';
     92            $data = ' ';
     93            if( method_exists('WP_Widget', 'is_preview' ) && $this->is_preview() ){
     94
    9095                foreach ($instance as $key => $value) {
    9196
     
    95100                }
    96101
    97                 echo "<div id='welt-{$this->id}' class='welt-tweet-wrapper'$data></div>";
    98 
    99             } else {
    100 
    101                 echo "<div id='welt-{$this->id}' class='welt-tweet-wrapper'></div>";
    102102            }
     103
     104            echo "<div id='welt-{$this->id}' class='welt-tweet-wrapper'$data></div>";
     105
    103106        }
    104107
     
    144147
    145148        // When everythings is check and we are not in the customizer, set the transient
    146         if( ! method_exists('Widget', 'is_preview' ) || ! $this->is_preview() ){
    147             welt_set_tweet_transient( $this->id, $instance , true );
    148         }
    149 
     149        if( ! method_exists('WP_Widget', 'is_preview' ) || ! $this->is_preview() ){
     150
     151                welt_set_tweet_transient( $this->id, $instance );
     152
     153        }
    150154
    151155        return $instance;
     
    168172        // Are all the options there ?
    169173        if( is_array( $twitter_oauth_var ) && count($twitter_oauth_var) == 4 ){
     174
     175
    170176
    171177            ?>
     
    253259function welt_set_tweet_transient( $widget_id, $options ){
    254260
    255     $return_value = false;
    256261
    257262    $last_tweet = welt_get_latest_tweet( $options );
     
    376381function welt_display_tweets( ){
    377382
    378     $widget_id = $_POST['widget_id'];
    379 
    380     $tweet_html = '';
    381 
    382     // In preview mode we passe all instance in data html attrribut
    383     if( isset( $_POST['widget_data'] ) && ! empty( $_POST['widget_data'] ) ){
    384 
    385         $instance = $_POST['widget_data'];
    386 
    387         $last_tweet = welt_get_latest_tweet( $instance );
    388 
    389         foreach ($last_tweet as $tweet_id) {
    390 
    391             $tweet_html .= welt_get_tweet_html( $tweet_id, $instance );
    392 
    393         }
    394 
    395 
    396     } else {
    397 
    398 
    399         $last_tweet = get_transient('last_tweet_' . $widget_id);
    400 
    401         if( false === $last_tweet ) {
    402 
    403             // Get the widget instance
    404             $all_instance_widget = get_option('widget_welt_last_tweets');
    405 
    406             $widget_real_id = str_replace('welt_last_tweets-', '', $widget_id);
    407 
    408             $instance = $all_instance_widget[$widget_real_id];
    409 
    410 
    411             // Set the transient for this widget
     383    $all_welt_widgets = $_POST['all_welt_widgets'];
     384
     385    $tweet_html = array();
     386
     387    foreach ($all_welt_widgets as $welt_widget ) {
     388
     389        $widget_id = $welt_widget['widget_id'];
     390        $widget_data = isset( $welt_widget['widget_data'] ) && ! empty( $welt_widget['widget_data'] ) ? $welt_widget['widget_data'] : false;
     391
     392        $tweet_html[ $widget_id ] = '';
     393
     394        // In preview mode we passe all instance in data html attrribut
     395        if( $widget_data ){
     396
     397            $instance = $widget_data;
     398
    412399            $last_tweet = welt_get_latest_tweet( $instance );
    413         }
    414 
    415         if( $last_tweet && is_array( $last_tweet ) ){
    416 
    417             set_transient('last_tweet_' . $widget_id , $last_tweet, 60 * 5);
    418400
    419401            foreach ($last_tweet as $tweet_id) {
    420402
    421                 // retrocompatibility
    422                 if( is_object( $tweet_id ) ){
    423                     $tweet_id = $tweet_id->id_str;
     403                $tweet_html[ $widget_id ] .= welt_get_tweet_html( $tweet_id, $instance );
     404
     405            }
     406
     407
     408        } else {
     409
     410
     411            $last_tweet = get_transient('last_tweet_' . $widget_id);
     412
     413            if( false === $last_tweet ) {
     414
     415                // Get the widget instance
     416                $instance = $instance = welt_get_widget_instance( $widget_id );
     417
     418
     419                // Set the transient for this widget
     420                $last_tweet = welt_get_latest_tweet( $instance );
     421            }
     422
     423            if( $last_tweet && is_array( $last_tweet ) ){
     424
     425                set_transient('last_tweet_' . $widget_id , $last_tweet, 60 * 5);
     426
     427                foreach ($last_tweet as $tweet_id) {
     428
     429                    // retrocompatibility
     430                    if( is_object( $tweet_id ) ){
     431                        $tweet_id = $tweet_id->id_str;
     432                    }
     433
     434                    $tweet_html_transient = get_transient('last_tweet_html_' . $tweet_id);
     435
     436                    if( false === $tweet_html_transient ){
     437
     438                        $instance = welt_get_widget_instance( $widget_id );
     439
     440                        $tweet_html_transient = welt_get_tweet_html( $tweet_id, $instance );
     441
     442                        if( $tweet_html_transient ){
     443                            set_transient('last_tweet_html_' . $tweet_id, $tweet_html_transient, ( 24 * WEEK_IN_SECONDS ) ); // 6 mouths
     444                            $tweet_html[ $widget_id ] .= $tweet_html_transient;
     445                        }
     446
     447                    } else {
     448
     449                        // retrocompatibility
     450                        if( is_object( $tweet_html_transient ) ){
     451                            $tweet_html_transient = $tweet_html_transient->html;
     452                        }
     453                        $tweet_html[ $widget_id ] .= $tweet_html_transient;
     454                    }
     455
    424456                }
    425 
    426                 $tweet_html_transient = get_transient('last_tweet_html_' . $tweet_id);
    427 
    428                 if( false === $tweet_html_transient ){
    429 
    430                     $tweet_html_transient = welt_get_tweet_html( $tweet_id, $instance );
    431 
    432                     if( $tweet_html_transient ){
    433                         set_transient('last_tweet_html_' . $tweet_id, $tweet_html_transient, ( 24 * WEEK_IN_SECONDS ) ); // 6 mouths
    434                         $tweet_html .= $tweet_html_transient;
    435                     }
    436 
    437                 } else {
    438 
    439                     // retrocompatibility
    440                     if( is_object( $tweet_html_transient ) ){
    441                         $tweet_html_transient = $tweet_html_transient->html;
    442                     }
    443                     $tweet_html .= $tweet_html_transient;
    444                 }
    445 
    446457            }
    447         }
    448 
    449     }
    450 
    451     echo $tweet_html;
     458
     459        }
     460    }
     461
     462
     463    echo json_encode( $tweet_html );
    452464    die;
    453465}
     
    456468add_action('wp_ajax_nopriv_welt_display_tweets', 'welt_display_tweets');
    457469
     470
     471/**
     472 * Return the instance of a widget base on his id
     473 */
     474function welt_get_widget_instance( $widget_id ){
     475
     476    // Get the widget instance
     477    $all_instance_widget = get_option('widget_welt_last_tweets');
     478
     479    $widget_real_id = str_replace('welt_last_tweets-', '', $widget_id);
     480
     481    return $all_instance_widget[$widget_real_id];
     482}
    458483
    459484/**
Note: See TracChangeset for help on using the changeset viewer.