Changeset 907818
- Timestamp:
- 05/04/2014 05:39:00 PM (12 years ago)
- Location:
- widget-embed-lastest-tweets
- Files:
-
- 8 edited
- 1 copied
-
tags/0.6 (copied) (copied from widget-embed-lastest-tweets/trunk)
-
tags/0.6/js/welt-scripts.js (modified) (4 diffs)
-
tags/0.6/readme.txt (modified) (5 diffs)
-
tags/0.6/welt-option.php (modified) (9 diffs)
-
tags/0.6/widget-embed-latest-tweets.php (modified) (13 diffs)
-
trunk/js/welt-scripts.js (modified) (4 diffs)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/welt-option.php (modified) (9 diffs)
-
trunk/widget-embed-latest-tweets.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
widget-embed-lastest-tweets/tags/0.6/js/welt-scripts.js
r768501 r907818 3 3 * The script to load tweet in ajax 4 4 */ 5 6 5 7 6 jQuery(document).ready( function(){ … … 12 11 13 12 var widget_id = current_widget.attr('id'); 13 var widget_data = current_widget.data(); 14 14 widget_id = widget_id.replace('welt-', ''); 15 15 16 16 var data = { 17 17 action: 'welt_display_tweets', 18 widget_id: widget_id 18 widget_id: widget_id, 19 widget_data: widget_data 19 20 }; 20 21 … … 24 25 function(response) { 25 26 current_widget.append(response); 27 twttr.widgets.load(); 26 28 } 27 29 ); … … 29 31 }); 30 32 }); 33 -
widget-embed-lastest-tweets/tags/0.6/readme.txt
r768501 r907818 2 2 Contributors: ArnaudBan 3 3 Tags: twitter, widget, embed 4 Requires at least: 3 5 Tested up to: 3. 64 Requires at least: 3.5 5 Tested up to: 3.9 6 6 Stable tag: trunk 7 7 License: GPLv2 … … 9 9 10 10 A Widget to show your latest Tweets. 11 Visit the option page " Plugins->Widget Embed Latest Tweet" to authentify yourself11 Visit the option page "Settings->Widget Embed Latest Tweet" to authentify yourself 12 12 13 13 … … 17 17 18 18 This plugin uses the Twitter API version 1.1. You have to authentify yourself ! 19 Visit the option page " Plugins->Widget Embed Latest Tweet" to do so.19 Visit the option page "Settings->Widget Embed Latest Tweet" to do so. 20 20 21 21 Options : … … 43 43 1. Upload `/widget-embed-latest-tweets/` to the `/wp-content/plugins/` directory 44 44 2. Activate the plugin through the 'Plugins' menu in WordPress 45 3. Visit the option page " Plugins->Widget Embed Latest Tweet" and follow the instructions45 3. Visit the option page "Settings->Widget Embed Latest Tweet" and follow the instructions 46 46 4. Go to the Widget page, drag and drop the "Widget embed lastest Tweets" widget where you want it to show 47 47 5. Enter at least your Twitter username … … 60 60 61 61 == Changelog == 62 63 = 0.6 = 64 65 * Change text domaine to be ready for wordpress.org "language packs" 66 * Less scripts downloded 67 * Make the widget usable with the widget preview manager 62 68 63 69 = 0.5 = -
widget-embed-lastest-tweets/tags/0.6/welt-option.php
r768501 r907818 10 10 function welt_add_option() { 11 11 //add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function); 12 add_ plugins_page('Widget Embed Latest Tweet', 'Widget Embed Latest Tweet', 'manage_options', 'welt_options_page', 'welt_options_page_display');12 add_options_page('Widget Embed Latest Tweet', 'Widget Embed Latest Tweet', 'manage_options', 'welt_options_page', 'welt_options_page_display'); 13 13 } 14 14 … … 17 17 ?> 18 18 <div class="wrap"> 19 <?php screen_icon(); ?> 19 20 20 <h2>Widget Embed Latest Tweet</h2> 21 21 22 22 <form action="options.php" method="post"> 23 23 <?php 24 //Output Error25 settings_errors();26 24 27 25 //Output nonce, action, and option_page … … 46 44 register_setting('welt_options_group', 'welt_twitter_oauth_var', 'welt_twitter_oauth_var_validate'); 47 45 48 //On créer une section dans nos options49 46 //add_settings_section( $id, $title, $callback, $page ); 50 add_settings_section('welt_twitter_oauth_section', __('Twitter connection', ' ab-welt-locales'), 'welt_twitter_oauth_section_text', 'welt_options_page');47 add_settings_section('welt_twitter_oauth_section', __('Twitter connection', 'widget-embed-lastest-tweets'), 'welt_twitter_oauth_section_text', 'welt_options_page'); 51 48 52 49 //Register a settings field to a settings page and section. 53 50 //add_settings_field( $id, $title, $callback, $page, $section, $args ); 54 add_settings_field('welt_twitter_consumer_key', ' Twitter consumer Key', 'welt_twitter_consumer_key_display', 'welt_options_page', 'welt_twitter_oauth_section');55 add_settings_field('welt_twitter_consumer_secret', ' Twitter consumer Secret', 'welt_twitter_consumer_secret_display', 'welt_options_page', 'welt_twitter_oauth_section');56 add_settings_field('welt_twitter_access_token', ' Twitter Access Token', 'welt_twitter_access_token_display', 'welt_options_page', 'welt_twitter_oauth_section');57 add_settings_field('welt_twitter_access_token_secret', ' Twitter Access Token Secret', 'welt_twitter_access_token_secret_display', 'welt_options_page', 'welt_twitter_oauth_section');51 add_settings_field('welt_twitter_consumer_key', 'API key', 'welt_twitter_consumer_key_display', 'welt_options_page', 'welt_twitter_oauth_section'); 52 add_settings_field('welt_twitter_consumer_secret', 'API secret', 'welt_twitter_consumer_secret_display', 'welt_options_page', 'welt_twitter_oauth_section'); 53 add_settings_field('welt_twitter_access_token', 'Access token', 'welt_twitter_access_token_display', 'welt_options_page', 'welt_twitter_oauth_section'); 54 add_settings_field('welt_twitter_access_token_secret', 'Access token secret', 'welt_twitter_access_token_secret_display', 'welt_options_page', 'welt_twitter_oauth_section'); 58 55 } 59 56 … … 61 58 function welt_twitter_oauth_section_text() { 62 59 ?> 63 <h4><?php _e('Why', ' ab-welt-locales'); ?> ?</h4>60 <h4><?php _e('Why', 'widget-embed-lastest-tweets'); ?> ?</h4> 64 61 <p> 65 <?php _e('Twitter\'s API version 1.1 require it', ' ab-welt-locales'); ?>62 <?php _e('Twitter\'s API version 1.1 require it', 'widget-embed-lastest-tweets'); ?> 66 63 </p> 67 64 68 <h4><?php _e('How', ' ab-welt-locales'); ?> ?</h4>65 <h4><?php _e('How', 'widget-embed-lastest-tweets'); ?> ?</h4> 69 66 70 67 <p> 71 <?php _e('Create a new application with your Twitter account. It is very simple, go to this page :', ' ab-welt-locales'); ?>68 <?php _e('Create a new application with your Twitter account. It is very simple, go to this page :', 'widget-embed-lastest-tweets'); ?> 72 69 <a href="https://dev.twitter.com/apps" title="dev Twitter apps">https://dev.twitter.com/apps</a> 73 70 </p> 74 71 <p> 75 <?php _e('Once your application is created ask to create an access token ( Click the blue button at the bottom of the page of your Twitter application ).', ' ab-welt-locales') ?>72 <?php _e('Once your application is created ask to create an access token ( Click the blue button at the bottom of the page of your Twitter application ).', 'widget-embed-lastest-tweets') ?> 76 73 </p> 77 74 <p> 78 <?php _e('You should now have all the information asked bellow !', ' ab-welt-locales') ?>75 <?php _e('You should now have all the information asked bellow !', 'widget-embed-lastest-tweets') ?> 79 76 </p> 80 77 <?php … … 84 81 85 82 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 86 $consumer_key = $twitter_oauth_var['consumer_key'];87 //Attention le "name" du input doit correspondre au nom de l'option 83 $consumer_key = isset( $twitter_oauth_var['consumer_key'] ) ? $twitter_oauth_var['consumer_key'] : ''; 84 88 85 ?> 89 86 <input id='welt_twitter_oauth_var[consumer_key]' name='welt_twitter_oauth_var[consumer_key]' type='text' value='<?php echo $consumer_key; ?>' class="widefat"/> … … 93 90 94 91 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 95 $consumer_secret = $twitter_oauth_var['consumer_secret']; 96 //Attention le "name" du input doit correspondre au nom de l'option 92 $consumer_secret = isset( $twitter_oauth_var['consumer_secret'] ) ? $twitter_oauth_var['consumer_secret'] : ''; 97 93 ?> 98 <input id='welt_twitter_oauth_var[consumer_secret]' name='welt_twitter_oauth_var[consumer_secret]' type=' text' value='<?php echo $consumer_secret; ?>' class="widefat"/>94 <input id='welt_twitter_oauth_var[consumer_secret]' name='welt_twitter_oauth_var[consumer_secret]' type='password' value='<?php echo $consumer_secret; ?>' class="widefat"/> 99 95 <?php 100 96 } … … 102 98 103 99 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 104 $token_key = $twitter_oauth_var['token_key']; 105 //Attention le "name" du input doit correspondre au nom de l'option 100 $token_key = isset( $twitter_oauth_var['token_key'] ) ? $twitter_oauth_var['token_key'] : ''; 106 101 ?> 107 102 <input id='welt_twitter_oauth_var[token_key]' name='welt_twitter_oauth_var[token_key]' type='text' value='<?php echo $token_key; ?>' class="widefat"/> … … 111 106 112 107 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 113 $token_secret = $twitter_oauth_var['token_secret']; 114 //Attention le "name" du input doit correspondre au nom de l'option 108 $token_secret = isset( $twitter_oauth_var['token_secret'] ) ? $twitter_oauth_var['token_secret'] : ''; 115 109 ?> 116 110 <input id='welt_twitter_oauth_var[token_secret]' name='welt_twitter_oauth_var[token_secret]' type='text' value='<?php echo $token_secret; ?>' class="widefat"/> … … 123 117 124 118 foreach ($twitter_variable as $option => $value) { 119 125 120 if( !empty( $value ) ){ 126 $valid_option[$option] = $value; 121 122 $valid_option[$option] = sanitize_text_field( $value ); 127 123 } 124 128 125 } 129 126 -
widget-embed-lastest-tweets/tags/0.6/widget-embed-latest-tweets.php
r768501 r907818 4 4 * Plugin URI: http://arnaudban.me/blog/portfolio/widget-embed-latest-tweets/ 5 5 * 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. 56 * Version: 0.6 7 7 * Author: Arnaud Banvillet 8 8 * Author URI: http://arnaudban.me 9 9 * License: GPL2 10 * 11 * Text Domain: widget-embed-lastest-tweets 12 * Domain Path: /languages 10 13 * 11 14 * Copyright 2012 Arnaud Banvillet (email : arnaud.banvillet@gmail.com ) … … 31 34 'title' => 'Latest Tweets', 32 35 'count' => 3, 36 'maxwidth' => '', 33 37 'align' => 'none', 34 38 'hide_thread' => true, … … 48 52 'welt_last_tweets', // Base ID 49 53 'Widget embed latest Tweets', // Name 50 array('description' => __('Show your latest Tweets', ' ab-welt-locales'))// Args54 array('description' => __('Show your latest Tweets', 'widget-embed-lastest-tweets'))// Args 51 55 ); 52 56 } … … 75 79 echo $before_widget; 76 80 77 if ( !empty( $title ) ) 81 if ( !empty( $title ) ){ 78 82 echo $before_title . $title . $after_title; 79 80 if( !empty( $screen_name ) ) 81 echo '<div id="welt-' . $this->id . '" class="welt-tweet-wrapper"></div>'; 83 } 84 85 if( !empty( $screen_name ) ){ 86 87 if( $this->is_preview() ){ 88 89 $data = ' '; 90 foreach ($instance as $key => $value) { 91 92 if( !empty( $value ) ){ 93 $data .= "data-{$key}='$value' "; 94 } 95 } 96 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>"; 102 } 103 } 82 104 83 105 echo $after_widget; … … 99 121 $instance = wp_parse_args($instance, $this->defaut); 100 122 101 $instance['title'] = strip_tags($new_instance['title']); 102 103 $instance['screen_name'] = strip_tags($new_instance['screen_name']); 104 105 $count = strip_tags($new_instance['count']); 106 107 if( is_numeric($count)) 123 $instance['title'] = sanitize_text_field($new_instance['title']); 124 125 $instance['screen_name'] = sanitize_text_field($new_instance['screen_name']); 126 127 $count = intval( $new_instance['count'] ); 128 if( $count != 0 ){ 108 129 $instance['count'] = $count ; 109 110 $maxwidth = strip_tags($new_instance['maxwidth']); 111 if( is_numeric( $maxwidth ) || empty( $maxwidth )) 112 $instance['maxwidth'] = $maxwidth; 113 114 115 if(in_array($new_instance['align'], $this->align_possible_value )) 130 } 131 132 $maxwidth = intval($new_instance['maxwidth']); 133 $instance['maxwidth'] = $maxwidth != 0 ? $maxwidth : ''; 134 135 if( in_array($new_instance['align'], $this->align_possible_value ) ){ 116 136 $instance['align'] = $new_instance['align']; 117 118 $instance['hide_thread'] = $new_instance['hide_thread'] == 'hide_thread'; 119 $instance['hide_media'] = $new_instance['hide_media'] == 'hide_media'; 120 $instance['exclude_replies'] = $new_instance['exclude_replies'] == 'exclude_replies'; 121 122 $instance['lang'] = strip_tags($new_instance['lang']); 123 124 //When everythings is check, set the transient 125 welt_set_tweet_transient( $this->id, $instance , true ); 137 } 138 139 $instance['hide_thread'] = isset( $new_instance['hide_thread'] ) && $new_instance['hide_thread'] == 'hide_thread'; 140 $instance['hide_media'] = isset( $new_instance['hide_media'] ) && $new_instance['hide_media'] == 'hide_media'; 141 $instance['exclude_replies'] = isset( $new_instance['exclude_replies'] ) && $new_instance['exclude_replies'] == 'exclude_replies'; 142 143 $instance['lang'] = sanitize_text_field($new_instance['lang']); 144 145 // When everythings is check and we are not in the customizer, set the transient 146 if( ! $this->is_preview() ){ 147 welt_set_tweet_transient( $this->id, $instance , true ); 148 } 149 126 150 127 151 return $instance; … … 140 164 extract($instance); 141 165 142 ?> 143 <p> 144 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title'); ?> :</label> 145 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> 146 </p> 147 148 <p> 149 <label for="<?php echo $this->get_field_id('screen_name'); ?>"><?php _e('Twitter Username', 'ab-welt-locales') ?> :</label> 150 <input class="widefat" id="<?php echo $this->get_field_id('screen_name'); ?>" name="<?php echo $this->get_field_name('screen_name'); ?>" type="text" value="<?php if( isset($screen_name) ) echo $screen_name; ?>" /> 151 </p> 152 153 <p> 154 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Number of Tweet to display', 'ab-welt-locales') ?> :</label> 155 <input id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="number" step="1" min="1" max="20" value="<?php echo $count; ?>" /> 156 </p> 157 158 <p> 159 <label for="<?php echo $this->get_field_id('maxwidth'); ?>"><?php _e('Width') ?> :</label> 160 <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; ?>" /> 161 <br /> 162 <span class="description"><?php _e('Twitter says :This value is constrained to be between 250 and 550 pixels', 'ab-welt-locales') ?></span> 163 164 </p> 165 166 <p> 167 <label for="<?php echo $this->get_field_id('align'); ?>"><?php _e('Alignment') ?> :</label> 168 <select id="<?php echo $this->get_field_id('align'); ?>" name="<?php echo $this->get_field_name('align'); ?>"> 169 <?php foreach( $this->align_possible_value as $value ) { ?> 170 <option value="<?php echo $value ?>" <?php selected($value, $align, true) ?>><?php echo $value ?></option> 171 <?php } ?> 172 </select> 173 </p> 174 175 <p> 176 <label for="<?php echo $this->get_field_id('hide_thread'); ?>"><?php _e('Hide Thread', 'ab-welt-locales') ?> :</label> 177 <input id="<?php echo $this->get_field_id('hide_thread'); ?>" name="<?php echo $this->get_field_name('hide_thread'); ?>" type="checkbox" <?php checked( $hide_thread ) ?> value="hide_thread"/> 178 <br /> 179 <span class="description"><?php _e('Hide the original message in the case that the embedded Tweet is a reply', 'ab-welt-locales') ?></span> 180 </p> 181 <p> 182 <label for="<?php echo $this->get_field_id('hide_media'); ?>"><?php _e('Hide Media', 'ab-welt-locales') ?> :</label> 183 <input id="<?php echo $this->get_field_id('hide_media'); ?>" name="<?php echo $this->get_field_name('hide_media'); ?>" type="checkbox" <?php checked( $hide_media ) ?> value="hide_media"/> 184 <br /> 185 <span class="description"><?php _e('Hide the images in the Tweet' , 'ab-welt-locales') ?></span> 186 </p> 187 188 <p> 189 <label for="<?php echo $this->get_field_id('exclude_replies'); ?>"><?php _e('Exclude replies', 'ab-welt-locales') ?> :</label> 190 <input id="<?php echo $this->get_field_id('exclude_replies'); ?>" name="<?php echo $this->get_field_name('exclude_replies'); ?>" type="checkbox" <?php checked( $exclude_replies ) ?> value="exclude_replies"/> 191 <br /> 192 <span class="description"><?php _e('They will not show but they will count in the number of tweets' , 'ab-welt-locales') ?></span> 193 </p> 194 195 <p> 196 <label for="<?php echo $this->get_field_id('lang'); ?>"><?php _e('Language', 'ab-welt-locales') ?> :</label> 197 <input id="<?php echo $this->get_field_id('lang'); ?>" name="<?php echo $this->get_field_name('lang'); ?>" type="text" value="<?php echo $lang; ?>" size="2"/> 198 <br /> 199 <span class="description"><?php _e('Two firsts caractere only. Example : "fr" for french', 'ab-welt-locales') ?></span> 200 </p> 201 <?php 166 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 167 168 // Are all the options there ? 169 if( is_array( $twitter_oauth_var ) && count($twitter_oauth_var) == 4 ){ 170 171 ?> 172 <p> 173 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title'); ?> :</label> 174 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> 175 </p> 176 177 <p> 178 <label for="<?php echo $this->get_field_id('screen_name'); ?>"><?php _e('Twitter Username', 'widget-embed-lastest-tweets') ?> :</label> 179 <input class="widefat" id="<?php echo $this->get_field_id('screen_name'); ?>" name="<?php echo $this->get_field_name('screen_name'); ?>" type="text" value="<?php if( isset($screen_name) ) echo $screen_name; ?>" /> 180 </p> 181 182 <p> 183 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Number of Tweet to display', 'widget-embed-lastest-tweets') ?> :</label> 184 <input id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="number" step="1" min="1" max="20" value="<?php echo $count; ?>" /> 185 </p> 186 187 <p> 188 <label for="<?php echo $this->get_field_id('maxwidth'); ?>"><?php _e('Width') ?> :</label> 189 <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; ?>" /> 190 <br /> 191 <span class="description"><?php _e('Twitter says :This value is constrained to be between 250 and 550 pixels', 'widget-embed-lastest-tweets') ?></span> 192 193 </p> 194 195 <p> 196 <label for="<?php echo $this->get_field_id('align'); ?>"><?php _e('Alignment') ?> :</label> 197 <select id="<?php echo $this->get_field_id('align'); ?>" name="<?php echo $this->get_field_name('align'); ?>"> 198 <?php foreach( $this->align_possible_value as $value ) { ?> 199 <option value="<?php echo $value ?>" <?php selected($value, $align, true) ?>><?php echo $value ?></option> 200 <?php } ?> 201 </select> 202 </p> 203 204 <p> 205 <label for="<?php echo $this->get_field_id('hide_thread'); ?>"><?php _e('Hide Thread', 'widget-embed-lastest-tweets') ?> :</label> 206 <input id="<?php echo $this->get_field_id('hide_thread'); ?>" name="<?php echo $this->get_field_name('hide_thread'); ?>" type="checkbox" <?php checked( $hide_thread ) ?> value="hide_thread"/> 207 <br /> 208 <span class="description"><?php _e('Hide the original message in the case that the embedded Tweet is a reply', 'widget-embed-lastest-tweets') ?></span> 209 </p> 210 <p> 211 <label for="<?php echo $this->get_field_id('hide_media'); ?>"><?php _e('Hide Media', 'widget-embed-lastest-tweets') ?> :</label> 212 <input id="<?php echo $this->get_field_id('hide_media'); ?>" name="<?php echo $this->get_field_name('hide_media'); ?>" type="checkbox" <?php checked( $hide_media ) ?> value="hide_media"/> 213 <br /> 214 <span class="description"><?php _e('Hide the images in the Tweet' , 'widget-embed-lastest-tweets') ?></span> 215 </p> 216 217 <p> 218 <label for="<?php echo $this->get_field_id('exclude_replies'); ?>"><?php _e('Exclude replies', 'widget-embed-lastest-tweets') ?> :</label> 219 <input id="<?php echo $this->get_field_id('exclude_replies'); ?>" name="<?php echo $this->get_field_name('exclude_replies'); ?>" type="checkbox" <?php checked( $exclude_replies ) ?> value="exclude_replies"/> 220 <br /> 221 <span class="description"><?php _e('They will not show but they will count in the number of tweets' , 'widget-embed-lastest-tweets') ?></span> 222 </p> 223 224 <p> 225 <label for="<?php echo $this->get_field_id('lang'); ?>"><?php _e('Language', 'widget-embed-lastest-tweets') ?> :</label> 226 <input id="<?php echo $this->get_field_id('lang'); ?>" name="<?php echo $this->get_field_name('lang'); ?>" type="text" value="<?php echo $lang; ?>" size="2"/> 227 <br /> 228 <span class="description"><?php _e('Two firsts caractere only. Example : "fr" for french', 'widget-embed-lastest-tweets') ?></span> 229 </p> 230 <?php 231 232 } else { 233 ?> 234 <p> 235 <?php printf( __('You have to enter your <a href="%s">Twitter connections information first</a>', 'widget-embed-lastest-tweets'), 'options-general.php?page=welt_options_page' ) ?> 236 </p> 237 <?php 238 } 202 239 } 203 240 … … 214 251 * @param boolean $update 215 252 */ 216 function welt_set_tweet_transient( $widget_id, $options , $update = false){253 function welt_set_tweet_transient( $widget_id, $options ){ 217 254 218 255 $return_value = false; 219 256 257 $last_tweet = welt_get_latest_tweet( $options ); 258 259 if( $last_tweet && is_array( $last_tweet ) ){ 260 261 set_transient('last_tweet_' . $widget_id , $last_tweet, 60 * 5); 262 263 foreach ($last_tweet as $tweet_id) { 264 265 $tweet_html = welt_get_tweet_html( $tweet_id, $options ); 266 267 if( $tweet_html ){ 268 set_transient('last_tweet_html_' . $tweet_id, $tweet_html, ( 24 * WEEK_IN_SECONDS ) ); // 6 mouths 269 } 270 271 } 272 } else { 273 274 delete_transient( 'last_tweet_' . $widget_id ); 275 } 276 } 277 278 /** 279 * Get twitter connection based on the option 280 * 281 */ 282 function welt_get_twitter_connection(){ 283 220 284 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 221 285 286 $connection = false; 222 287 //Check if wee use the authentification methode. We need to have all the key and secret. 223 288 if( is_array( $twitter_oauth_var ) && count($twitter_oauth_var) == 4 ){ 224 289 225 290 $connection = new TwitterOAuth($twitter_oauth_var['consumer_key'], $twitter_oauth_var['consumer_secret'], $twitter_oauth_var['token_key'],$twitter_oauth_var['token_secret']); 291 292 } 293 294 return $connection; 295 } 296 297 /** 298 * get the lastest tweet 299 */ 300 function welt_get_latest_tweet( $options ){ 301 302 $connection = welt_get_twitter_connection(); 303 304 // If the connection is ok let get the twitter information 305 if( $connection ){ 306 226 307 $last_tweet = $connection->get('https://api.twitter.com/1.1/statuses/user_timeline.json', $options ); 227 308 … … 229 310 if( isset( $last_tweet->errors ) ){ 230 311 231 delete_transient( 'last_tweet_' . $widget_id );232 312 $return_value = $last_tweet->errors[0]->message; 313 error_log($last_tweet->errors[0]->message); 233 314 234 315 // If there is nothing 235 316 } elseif( $last_tweet == false || empty( $last_tweet )){ 236 317 237 delete_transient( 'last_tweet_' . $widget_id );238 318 $return_value = false; 239 319 … … 241 321 } else { 242 322 243 $return_value = $last_tweet; 244 245 set_transient('last_tweet_' . $widget_id , $last_tweet, 60 * 5); 246 247 foreach ($last_tweet as $tweet) { 248 249 $id = $tweet->id_str; 250 251 252 if( $update || ! get_transient('last_tweet_html_' . $id)){ 253 254 255 $options['id'] = $id; 256 257 if( empty( $maxwidth) ){ 258 unset( $options['maxwidth']); 259 } 260 261 $last_tweet_html = $connection->get('https://api.twitter.com/1.1/statuses/oembed.json', $options); 262 263 264 set_transient('last_tweet_html_' . $id, $last_tweet_html ); 265 266 } 323 $return_value = array(); 324 foreach ( $last_tweet as $tweet) { 325 $return_value[] = $tweet->id_str; 267 326 } 268 } 327 328 } 329 330 } else { 331 332 $return_value = 'Connection error'; 333 334 } 335 336 return $return_value; 337 } 338 339 function welt_get_tweet_html( $tweet_id, $options ){ 340 341 $connection = welt_get_twitter_connection(); 342 343 // If the connection is ok let get the twitter information 344 if( $connection ){ 345 $options['id'] = $tweet_id; 346 $options['omit_script'] = true; 347 348 if( empty( $maxwidth) ){ 349 unset( $options['maxwidth']); 350 } 351 352 $tweet = $connection->get('https://api.twitter.com/1.1/statuses/oembed.json', $options); 353 354 if( isset( $tweet->errors ) ){ 355 356 $return_value = 'false'; 357 error_log( $last_tweet->errors[0]->message ); 358 359 } else { 360 361 $return_value = $tweet->html; 362 } 363 364 } else { 365 366 $return_value = 'false'; 269 367 } 270 368 … … 282 380 $tweet_html = ''; 283 381 284 $last_tweet = get_transient('last_tweet_' . $widget_id); 285 286 287 if( false === $last_tweet ) { 288 289 // Get the widget instance 290 $all_instance_widget = get_option('widget_welt_last_tweets'); 291 292 $widget_real_id = str_replace('welt_last_tweets-', '', $widget_id); 293 294 $instance = $all_instance_widget[$widget_real_id]; 295 296 // Set the transient for this widget 297 $last_tweet = welt_set_tweet_transient( $widget_id, $instance, false ); 298 299 } 300 301 if( is_string( $last_tweet ) ){ // It is a error 302 303 echo $last_tweet; 304 305 } elseif ( $last_tweet != false ){ 306 307 foreach ($last_tweet as $tweet) { 308 309 $tweet_id = $tweet->id_str; 310 311 $last_tweet_html = get_transient('last_tweet_html_' . $tweet_id); 312 313 $tweet_html .= $last_tweet_html->html; 314 315 } 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 316 396 } else { 317 $tweet_html = __('Error: Twitter did not respond. Please wait a few minutes and refresh this page.', 'ab-welt-locales'); 318 } 319 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 412 $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); 418 419 foreach ($last_tweet as $tweet_id) { 420 421 // retrocompatibility 422 if( is_object( $tweet_id ) ){ 423 $tweet_id = $tweet_id->id_str; 424 } 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, $options ); 431 432 if( $tweet_html_transient ){ 433 set_transient('last_tweet_html_' . $tweet_id, $tweet_html, ( 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 446 } 447 } 448 449 } 320 450 321 451 echo $tweet_html; … … 332 462 function welt_enqueue_scripts(){ 333 463 // welt 334 wp_register_script('welt_script', plugins_url('/js/welt-scripts.js', __FILE__) , array( 'jquery' ), '20130129', true ); 464 wp_register_script('welt_twitter_script', '//platform.twitter.com/widgets.js' , array(), '1.1', true ); 465 wp_register_script('welt_script', plugins_url('/js/welt-scripts.js', __FILE__) , array( 'jquery', 'welt_twitter_script' ), '20130129', true ); 335 466 336 467 } … … 347 478 } 348 479 349 load_plugin_textdomain( ' ab-welt-locales', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );480 load_plugin_textdomain( 'widget-embed-lastest-tweets', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 350 481 } 351 482 add_action('plugins_loaded', 'welt_plugin_init'); … … 358 489 // Add settings link on plugin page 359 490 function welt_add_settings_link($links) { 360 $settings_link = '<a href=" plugins.php?page=welt_options_page">' . __('Settings') . '</a>';491 $settings_link = '<a href="options-general.php?page=welt_options_page">' . __('Settings') . '</a>'; 361 492 array_unshift($links, $settings_link); 362 493 return $links; -
widget-embed-lastest-tweets/trunk/js/welt-scripts.js
r768501 r907818 3 3 * The script to load tweet in ajax 4 4 */ 5 6 5 7 6 jQuery(document).ready( function(){ … … 12 11 13 12 var widget_id = current_widget.attr('id'); 13 var widget_data = current_widget.data(); 14 14 widget_id = widget_id.replace('welt-', ''); 15 15 16 16 var data = { 17 17 action: 'welt_display_tweets', 18 widget_id: widget_id 18 widget_id: widget_id, 19 widget_data: widget_data 19 20 }; 20 21 … … 24 25 function(response) { 25 26 current_widget.append(response); 27 twttr.widgets.load(); 26 28 } 27 29 ); … … 29 31 }); 30 32 }); 33 -
widget-embed-lastest-tweets/trunk/readme.txt
r768501 r907818 2 2 Contributors: ArnaudBan 3 3 Tags: twitter, widget, embed 4 Requires at least: 3 5 Tested up to: 3. 64 Requires at least: 3.5 5 Tested up to: 3.9 6 6 Stable tag: trunk 7 7 License: GPLv2 … … 9 9 10 10 A Widget to show your latest Tweets. 11 Visit the option page " Plugins->Widget Embed Latest Tweet" to authentify yourself11 Visit the option page "Settings->Widget Embed Latest Tweet" to authentify yourself 12 12 13 13 … … 17 17 18 18 This plugin uses the Twitter API version 1.1. You have to authentify yourself ! 19 Visit the option page " Plugins->Widget Embed Latest Tweet" to do so.19 Visit the option page "Settings->Widget Embed Latest Tweet" to do so. 20 20 21 21 Options : … … 43 43 1. Upload `/widget-embed-latest-tweets/` to the `/wp-content/plugins/` directory 44 44 2. Activate the plugin through the 'Plugins' menu in WordPress 45 3. Visit the option page " Plugins->Widget Embed Latest Tweet" and follow the instructions45 3. Visit the option page "Settings->Widget Embed Latest Tweet" and follow the instructions 46 46 4. Go to the Widget page, drag and drop the "Widget embed lastest Tweets" widget where you want it to show 47 47 5. Enter at least your Twitter username … … 60 60 61 61 == Changelog == 62 63 = 0.6 = 64 65 * Change text domaine to be ready for wordpress.org "language packs" 66 * Less scripts downloded 67 * Make the widget usable with the widget preview manager 62 68 63 69 = 0.5 = -
widget-embed-lastest-tweets/trunk/welt-option.php
r768501 r907818 10 10 function welt_add_option() { 11 11 //add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function); 12 add_ plugins_page('Widget Embed Latest Tweet', 'Widget Embed Latest Tweet', 'manage_options', 'welt_options_page', 'welt_options_page_display');12 add_options_page('Widget Embed Latest Tweet', 'Widget Embed Latest Tweet', 'manage_options', 'welt_options_page', 'welt_options_page_display'); 13 13 } 14 14 … … 17 17 ?> 18 18 <div class="wrap"> 19 <?php screen_icon(); ?> 19 20 20 <h2>Widget Embed Latest Tweet</h2> 21 21 22 22 <form action="options.php" method="post"> 23 23 <?php 24 //Output Error25 settings_errors();26 24 27 25 //Output nonce, action, and option_page … … 46 44 register_setting('welt_options_group', 'welt_twitter_oauth_var', 'welt_twitter_oauth_var_validate'); 47 45 48 //On créer une section dans nos options49 46 //add_settings_section( $id, $title, $callback, $page ); 50 add_settings_section('welt_twitter_oauth_section', __('Twitter connection', ' ab-welt-locales'), 'welt_twitter_oauth_section_text', 'welt_options_page');47 add_settings_section('welt_twitter_oauth_section', __('Twitter connection', 'widget-embed-lastest-tweets'), 'welt_twitter_oauth_section_text', 'welt_options_page'); 51 48 52 49 //Register a settings field to a settings page and section. 53 50 //add_settings_field( $id, $title, $callback, $page, $section, $args ); 54 add_settings_field('welt_twitter_consumer_key', ' Twitter consumer Key', 'welt_twitter_consumer_key_display', 'welt_options_page', 'welt_twitter_oauth_section');55 add_settings_field('welt_twitter_consumer_secret', ' Twitter consumer Secret', 'welt_twitter_consumer_secret_display', 'welt_options_page', 'welt_twitter_oauth_section');56 add_settings_field('welt_twitter_access_token', ' Twitter Access Token', 'welt_twitter_access_token_display', 'welt_options_page', 'welt_twitter_oauth_section');57 add_settings_field('welt_twitter_access_token_secret', ' Twitter Access Token Secret', 'welt_twitter_access_token_secret_display', 'welt_options_page', 'welt_twitter_oauth_section');51 add_settings_field('welt_twitter_consumer_key', 'API key', 'welt_twitter_consumer_key_display', 'welt_options_page', 'welt_twitter_oauth_section'); 52 add_settings_field('welt_twitter_consumer_secret', 'API secret', 'welt_twitter_consumer_secret_display', 'welt_options_page', 'welt_twitter_oauth_section'); 53 add_settings_field('welt_twitter_access_token', 'Access token', 'welt_twitter_access_token_display', 'welt_options_page', 'welt_twitter_oauth_section'); 54 add_settings_field('welt_twitter_access_token_secret', 'Access token secret', 'welt_twitter_access_token_secret_display', 'welt_options_page', 'welt_twitter_oauth_section'); 58 55 } 59 56 … … 61 58 function welt_twitter_oauth_section_text() { 62 59 ?> 63 <h4><?php _e('Why', ' ab-welt-locales'); ?> ?</h4>60 <h4><?php _e('Why', 'widget-embed-lastest-tweets'); ?> ?</h4> 64 61 <p> 65 <?php _e('Twitter\'s API version 1.1 require it', ' ab-welt-locales'); ?>62 <?php _e('Twitter\'s API version 1.1 require it', 'widget-embed-lastest-tweets'); ?> 66 63 </p> 67 64 68 <h4><?php _e('How', ' ab-welt-locales'); ?> ?</h4>65 <h4><?php _e('How', 'widget-embed-lastest-tweets'); ?> ?</h4> 69 66 70 67 <p> 71 <?php _e('Create a new application with your Twitter account. It is very simple, go to this page :', ' ab-welt-locales'); ?>68 <?php _e('Create a new application with your Twitter account. It is very simple, go to this page :', 'widget-embed-lastest-tweets'); ?> 72 69 <a href="https://dev.twitter.com/apps" title="dev Twitter apps">https://dev.twitter.com/apps</a> 73 70 </p> 74 71 <p> 75 <?php _e('Once your application is created ask to create an access token ( Click the blue button at the bottom of the page of your Twitter application ).', ' ab-welt-locales') ?>72 <?php _e('Once your application is created ask to create an access token ( Click the blue button at the bottom of the page of your Twitter application ).', 'widget-embed-lastest-tweets') ?> 76 73 </p> 77 74 <p> 78 <?php _e('You should now have all the information asked bellow !', ' ab-welt-locales') ?>75 <?php _e('You should now have all the information asked bellow !', 'widget-embed-lastest-tweets') ?> 79 76 </p> 80 77 <?php … … 84 81 85 82 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 86 $consumer_key = $twitter_oauth_var['consumer_key'];87 //Attention le "name" du input doit correspondre au nom de l'option 83 $consumer_key = isset( $twitter_oauth_var['consumer_key'] ) ? $twitter_oauth_var['consumer_key'] : ''; 84 88 85 ?> 89 86 <input id='welt_twitter_oauth_var[consumer_key]' name='welt_twitter_oauth_var[consumer_key]' type='text' value='<?php echo $consumer_key; ?>' class="widefat"/> … … 93 90 94 91 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 95 $consumer_secret = $twitter_oauth_var['consumer_secret']; 96 //Attention le "name" du input doit correspondre au nom de l'option 92 $consumer_secret = isset( $twitter_oauth_var['consumer_secret'] ) ? $twitter_oauth_var['consumer_secret'] : ''; 97 93 ?> 98 <input id='welt_twitter_oauth_var[consumer_secret]' name='welt_twitter_oauth_var[consumer_secret]' type=' text' value='<?php echo $consumer_secret; ?>' class="widefat"/>94 <input id='welt_twitter_oauth_var[consumer_secret]' name='welt_twitter_oauth_var[consumer_secret]' type='password' value='<?php echo $consumer_secret; ?>' class="widefat"/> 99 95 <?php 100 96 } … … 102 98 103 99 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 104 $token_key = $twitter_oauth_var['token_key']; 105 //Attention le "name" du input doit correspondre au nom de l'option 100 $token_key = isset( $twitter_oauth_var['token_key'] ) ? $twitter_oauth_var['token_key'] : ''; 106 101 ?> 107 102 <input id='welt_twitter_oauth_var[token_key]' name='welt_twitter_oauth_var[token_key]' type='text' value='<?php echo $token_key; ?>' class="widefat"/> … … 111 106 112 107 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 113 $token_secret = $twitter_oauth_var['token_secret']; 114 //Attention le "name" du input doit correspondre au nom de l'option 108 $token_secret = isset( $twitter_oauth_var['token_secret'] ) ? $twitter_oauth_var['token_secret'] : ''; 115 109 ?> 116 110 <input id='welt_twitter_oauth_var[token_secret]' name='welt_twitter_oauth_var[token_secret]' type='text' value='<?php echo $token_secret; ?>' class="widefat"/> … … 123 117 124 118 foreach ($twitter_variable as $option => $value) { 119 125 120 if( !empty( $value ) ){ 126 $valid_option[$option] = $value; 121 122 $valid_option[$option] = sanitize_text_field( $value ); 127 123 } 124 128 125 } 129 126 -
widget-embed-lastest-tweets/trunk/widget-embed-latest-tweets.php
r768501 r907818 4 4 * Plugin URI: http://arnaudban.me/blog/portfolio/widget-embed-latest-tweets/ 5 5 * 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. 56 * Version: 0.6 7 7 * Author: Arnaud Banvillet 8 8 * Author URI: http://arnaudban.me 9 9 * License: GPL2 10 * 11 * Text Domain: widget-embed-lastest-tweets 12 * Domain Path: /languages 10 13 * 11 14 * Copyright 2012 Arnaud Banvillet (email : arnaud.banvillet@gmail.com ) … … 31 34 'title' => 'Latest Tweets', 32 35 'count' => 3, 36 'maxwidth' => '', 33 37 'align' => 'none', 34 38 'hide_thread' => true, … … 48 52 'welt_last_tweets', // Base ID 49 53 'Widget embed latest Tweets', // Name 50 array('description' => __('Show your latest Tweets', ' ab-welt-locales'))// Args54 array('description' => __('Show your latest Tweets', 'widget-embed-lastest-tweets'))// Args 51 55 ); 52 56 } … … 75 79 echo $before_widget; 76 80 77 if ( !empty( $title ) ) 81 if ( !empty( $title ) ){ 78 82 echo $before_title . $title . $after_title; 79 80 if( !empty( $screen_name ) ) 81 echo '<div id="welt-' . $this->id . '" class="welt-tweet-wrapper"></div>'; 83 } 84 85 if( !empty( $screen_name ) ){ 86 87 if( $this->is_preview() ){ 88 89 $data = ' '; 90 foreach ($instance as $key => $value) { 91 92 if( !empty( $value ) ){ 93 $data .= "data-{$key}='$value' "; 94 } 95 } 96 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>"; 102 } 103 } 82 104 83 105 echo $after_widget; … … 99 121 $instance = wp_parse_args($instance, $this->defaut); 100 122 101 $instance['title'] = strip_tags($new_instance['title']); 102 103 $instance['screen_name'] = strip_tags($new_instance['screen_name']); 104 105 $count = strip_tags($new_instance['count']); 106 107 if( is_numeric($count)) 123 $instance['title'] = sanitize_text_field($new_instance['title']); 124 125 $instance['screen_name'] = sanitize_text_field($new_instance['screen_name']); 126 127 $count = intval( $new_instance['count'] ); 128 if( $count != 0 ){ 108 129 $instance['count'] = $count ; 109 110 $maxwidth = strip_tags($new_instance['maxwidth']); 111 if( is_numeric( $maxwidth ) || empty( $maxwidth )) 112 $instance['maxwidth'] = $maxwidth; 113 114 115 if(in_array($new_instance['align'], $this->align_possible_value )) 130 } 131 132 $maxwidth = intval($new_instance['maxwidth']); 133 $instance['maxwidth'] = $maxwidth != 0 ? $maxwidth : ''; 134 135 if( in_array($new_instance['align'], $this->align_possible_value ) ){ 116 136 $instance['align'] = $new_instance['align']; 117 118 $instance['hide_thread'] = $new_instance['hide_thread'] == 'hide_thread'; 119 $instance['hide_media'] = $new_instance['hide_media'] == 'hide_media'; 120 $instance['exclude_replies'] = $new_instance['exclude_replies'] == 'exclude_replies'; 121 122 $instance['lang'] = strip_tags($new_instance['lang']); 123 124 //When everythings is check, set the transient 125 welt_set_tweet_transient( $this->id, $instance , true ); 137 } 138 139 $instance['hide_thread'] = isset( $new_instance['hide_thread'] ) && $new_instance['hide_thread'] == 'hide_thread'; 140 $instance['hide_media'] = isset( $new_instance['hide_media'] ) && $new_instance['hide_media'] == 'hide_media'; 141 $instance['exclude_replies'] = isset( $new_instance['exclude_replies'] ) && $new_instance['exclude_replies'] == 'exclude_replies'; 142 143 $instance['lang'] = sanitize_text_field($new_instance['lang']); 144 145 // When everythings is check and we are not in the customizer, set the transient 146 if( ! $this->is_preview() ){ 147 welt_set_tweet_transient( $this->id, $instance , true ); 148 } 149 126 150 127 151 return $instance; … … 140 164 extract($instance); 141 165 142 ?> 143 <p> 144 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title'); ?> :</label> 145 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> 146 </p> 147 148 <p> 149 <label for="<?php echo $this->get_field_id('screen_name'); ?>"><?php _e('Twitter Username', 'ab-welt-locales') ?> :</label> 150 <input class="widefat" id="<?php echo $this->get_field_id('screen_name'); ?>" name="<?php echo $this->get_field_name('screen_name'); ?>" type="text" value="<?php if( isset($screen_name) ) echo $screen_name; ?>" /> 151 </p> 152 153 <p> 154 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Number of Tweet to display', 'ab-welt-locales') ?> :</label> 155 <input id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="number" step="1" min="1" max="20" value="<?php echo $count; ?>" /> 156 </p> 157 158 <p> 159 <label for="<?php echo $this->get_field_id('maxwidth'); ?>"><?php _e('Width') ?> :</label> 160 <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; ?>" /> 161 <br /> 162 <span class="description"><?php _e('Twitter says :This value is constrained to be between 250 and 550 pixels', 'ab-welt-locales') ?></span> 163 164 </p> 165 166 <p> 167 <label for="<?php echo $this->get_field_id('align'); ?>"><?php _e('Alignment') ?> :</label> 168 <select id="<?php echo $this->get_field_id('align'); ?>" name="<?php echo $this->get_field_name('align'); ?>"> 169 <?php foreach( $this->align_possible_value as $value ) { ?> 170 <option value="<?php echo $value ?>" <?php selected($value, $align, true) ?>><?php echo $value ?></option> 171 <?php } ?> 172 </select> 173 </p> 174 175 <p> 176 <label for="<?php echo $this->get_field_id('hide_thread'); ?>"><?php _e('Hide Thread', 'ab-welt-locales') ?> :</label> 177 <input id="<?php echo $this->get_field_id('hide_thread'); ?>" name="<?php echo $this->get_field_name('hide_thread'); ?>" type="checkbox" <?php checked( $hide_thread ) ?> value="hide_thread"/> 178 <br /> 179 <span class="description"><?php _e('Hide the original message in the case that the embedded Tweet is a reply', 'ab-welt-locales') ?></span> 180 </p> 181 <p> 182 <label for="<?php echo $this->get_field_id('hide_media'); ?>"><?php _e('Hide Media', 'ab-welt-locales') ?> :</label> 183 <input id="<?php echo $this->get_field_id('hide_media'); ?>" name="<?php echo $this->get_field_name('hide_media'); ?>" type="checkbox" <?php checked( $hide_media ) ?> value="hide_media"/> 184 <br /> 185 <span class="description"><?php _e('Hide the images in the Tweet' , 'ab-welt-locales') ?></span> 186 </p> 187 188 <p> 189 <label for="<?php echo $this->get_field_id('exclude_replies'); ?>"><?php _e('Exclude replies', 'ab-welt-locales') ?> :</label> 190 <input id="<?php echo $this->get_field_id('exclude_replies'); ?>" name="<?php echo $this->get_field_name('exclude_replies'); ?>" type="checkbox" <?php checked( $exclude_replies ) ?> value="exclude_replies"/> 191 <br /> 192 <span class="description"><?php _e('They will not show but they will count in the number of tweets' , 'ab-welt-locales') ?></span> 193 </p> 194 195 <p> 196 <label for="<?php echo $this->get_field_id('lang'); ?>"><?php _e('Language', 'ab-welt-locales') ?> :</label> 197 <input id="<?php echo $this->get_field_id('lang'); ?>" name="<?php echo $this->get_field_name('lang'); ?>" type="text" value="<?php echo $lang; ?>" size="2"/> 198 <br /> 199 <span class="description"><?php _e('Two firsts caractere only. Example : "fr" for french', 'ab-welt-locales') ?></span> 200 </p> 201 <?php 166 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 167 168 // Are all the options there ? 169 if( is_array( $twitter_oauth_var ) && count($twitter_oauth_var) == 4 ){ 170 171 ?> 172 <p> 173 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title'); ?> :</label> 174 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> 175 </p> 176 177 <p> 178 <label for="<?php echo $this->get_field_id('screen_name'); ?>"><?php _e('Twitter Username', 'widget-embed-lastest-tweets') ?> :</label> 179 <input class="widefat" id="<?php echo $this->get_field_id('screen_name'); ?>" name="<?php echo $this->get_field_name('screen_name'); ?>" type="text" value="<?php if( isset($screen_name) ) echo $screen_name; ?>" /> 180 </p> 181 182 <p> 183 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Number of Tweet to display', 'widget-embed-lastest-tweets') ?> :</label> 184 <input id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="number" step="1" min="1" max="20" value="<?php echo $count; ?>" /> 185 </p> 186 187 <p> 188 <label for="<?php echo $this->get_field_id('maxwidth'); ?>"><?php _e('Width') ?> :</label> 189 <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; ?>" /> 190 <br /> 191 <span class="description"><?php _e('Twitter says :This value is constrained to be between 250 and 550 pixels', 'widget-embed-lastest-tweets') ?></span> 192 193 </p> 194 195 <p> 196 <label for="<?php echo $this->get_field_id('align'); ?>"><?php _e('Alignment') ?> :</label> 197 <select id="<?php echo $this->get_field_id('align'); ?>" name="<?php echo $this->get_field_name('align'); ?>"> 198 <?php foreach( $this->align_possible_value as $value ) { ?> 199 <option value="<?php echo $value ?>" <?php selected($value, $align, true) ?>><?php echo $value ?></option> 200 <?php } ?> 201 </select> 202 </p> 203 204 <p> 205 <label for="<?php echo $this->get_field_id('hide_thread'); ?>"><?php _e('Hide Thread', 'widget-embed-lastest-tweets') ?> :</label> 206 <input id="<?php echo $this->get_field_id('hide_thread'); ?>" name="<?php echo $this->get_field_name('hide_thread'); ?>" type="checkbox" <?php checked( $hide_thread ) ?> value="hide_thread"/> 207 <br /> 208 <span class="description"><?php _e('Hide the original message in the case that the embedded Tweet is a reply', 'widget-embed-lastest-tweets') ?></span> 209 </p> 210 <p> 211 <label for="<?php echo $this->get_field_id('hide_media'); ?>"><?php _e('Hide Media', 'widget-embed-lastest-tweets') ?> :</label> 212 <input id="<?php echo $this->get_field_id('hide_media'); ?>" name="<?php echo $this->get_field_name('hide_media'); ?>" type="checkbox" <?php checked( $hide_media ) ?> value="hide_media"/> 213 <br /> 214 <span class="description"><?php _e('Hide the images in the Tweet' , 'widget-embed-lastest-tweets') ?></span> 215 </p> 216 217 <p> 218 <label for="<?php echo $this->get_field_id('exclude_replies'); ?>"><?php _e('Exclude replies', 'widget-embed-lastest-tweets') ?> :</label> 219 <input id="<?php echo $this->get_field_id('exclude_replies'); ?>" name="<?php echo $this->get_field_name('exclude_replies'); ?>" type="checkbox" <?php checked( $exclude_replies ) ?> value="exclude_replies"/> 220 <br /> 221 <span class="description"><?php _e('They will not show but they will count in the number of tweets' , 'widget-embed-lastest-tweets') ?></span> 222 </p> 223 224 <p> 225 <label for="<?php echo $this->get_field_id('lang'); ?>"><?php _e('Language', 'widget-embed-lastest-tweets') ?> :</label> 226 <input id="<?php echo $this->get_field_id('lang'); ?>" name="<?php echo $this->get_field_name('lang'); ?>" type="text" value="<?php echo $lang; ?>" size="2"/> 227 <br /> 228 <span class="description"><?php _e('Two firsts caractere only. Example : "fr" for french', 'widget-embed-lastest-tweets') ?></span> 229 </p> 230 <?php 231 232 } else { 233 ?> 234 <p> 235 <?php printf( __('You have to enter your <a href="%s">Twitter connections information first</a>', 'widget-embed-lastest-tweets'), 'options-general.php?page=welt_options_page' ) ?> 236 </p> 237 <?php 238 } 202 239 } 203 240 … … 214 251 * @param boolean $update 215 252 */ 216 function welt_set_tweet_transient( $widget_id, $options , $update = false){253 function welt_set_tweet_transient( $widget_id, $options ){ 217 254 218 255 $return_value = false; 219 256 257 $last_tweet = welt_get_latest_tweet( $options ); 258 259 if( $last_tweet && is_array( $last_tweet ) ){ 260 261 set_transient('last_tweet_' . $widget_id , $last_tweet, 60 * 5); 262 263 foreach ($last_tweet as $tweet_id) { 264 265 $tweet_html = welt_get_tweet_html( $tweet_id, $options ); 266 267 if( $tweet_html ){ 268 set_transient('last_tweet_html_' . $tweet_id, $tweet_html, ( 24 * WEEK_IN_SECONDS ) ); // 6 mouths 269 } 270 271 } 272 } else { 273 274 delete_transient( 'last_tweet_' . $widget_id ); 275 } 276 } 277 278 /** 279 * Get twitter connection based on the option 280 * 281 */ 282 function welt_get_twitter_connection(){ 283 220 284 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 221 285 286 $connection = false; 222 287 //Check if wee use the authentification methode. We need to have all the key and secret. 223 288 if( is_array( $twitter_oauth_var ) && count($twitter_oauth_var) == 4 ){ 224 289 225 290 $connection = new TwitterOAuth($twitter_oauth_var['consumer_key'], $twitter_oauth_var['consumer_secret'], $twitter_oauth_var['token_key'],$twitter_oauth_var['token_secret']); 291 292 } 293 294 return $connection; 295 } 296 297 /** 298 * get the lastest tweet 299 */ 300 function welt_get_latest_tweet( $options ){ 301 302 $connection = welt_get_twitter_connection(); 303 304 // If the connection is ok let get the twitter information 305 if( $connection ){ 306 226 307 $last_tweet = $connection->get('https://api.twitter.com/1.1/statuses/user_timeline.json', $options ); 227 308 … … 229 310 if( isset( $last_tweet->errors ) ){ 230 311 231 delete_transient( 'last_tweet_' . $widget_id );232 312 $return_value = $last_tweet->errors[0]->message; 313 error_log($last_tweet->errors[0]->message); 233 314 234 315 // If there is nothing 235 316 } elseif( $last_tweet == false || empty( $last_tweet )){ 236 317 237 delete_transient( 'last_tweet_' . $widget_id );238 318 $return_value = false; 239 319 … … 241 321 } else { 242 322 243 $return_value = $last_tweet; 244 245 set_transient('last_tweet_' . $widget_id , $last_tweet, 60 * 5); 246 247 foreach ($last_tweet as $tweet) { 248 249 $id = $tweet->id_str; 250 251 252 if( $update || ! get_transient('last_tweet_html_' . $id)){ 253 254 255 $options['id'] = $id; 256 257 if( empty( $maxwidth) ){ 258 unset( $options['maxwidth']); 259 } 260 261 $last_tweet_html = $connection->get('https://api.twitter.com/1.1/statuses/oembed.json', $options); 262 263 264 set_transient('last_tweet_html_' . $id, $last_tweet_html ); 265 266 } 323 $return_value = array(); 324 foreach ( $last_tweet as $tweet) { 325 $return_value[] = $tweet->id_str; 267 326 } 268 } 327 328 } 329 330 } else { 331 332 $return_value = 'Connection error'; 333 334 } 335 336 return $return_value; 337 } 338 339 function welt_get_tweet_html( $tweet_id, $options ){ 340 341 $connection = welt_get_twitter_connection(); 342 343 // If the connection is ok let get the twitter information 344 if( $connection ){ 345 $options['id'] = $tweet_id; 346 $options['omit_script'] = true; 347 348 if( empty( $maxwidth) ){ 349 unset( $options['maxwidth']); 350 } 351 352 $tweet = $connection->get('https://api.twitter.com/1.1/statuses/oembed.json', $options); 353 354 if( isset( $tweet->errors ) ){ 355 356 $return_value = 'false'; 357 error_log( $last_tweet->errors[0]->message ); 358 359 } else { 360 361 $return_value = $tweet->html; 362 } 363 364 } else { 365 366 $return_value = 'false'; 269 367 } 270 368 … … 282 380 $tweet_html = ''; 283 381 284 $last_tweet = get_transient('last_tweet_' . $widget_id); 285 286 287 if( false === $last_tweet ) { 288 289 // Get the widget instance 290 $all_instance_widget = get_option('widget_welt_last_tweets'); 291 292 $widget_real_id = str_replace('welt_last_tweets-', '', $widget_id); 293 294 $instance = $all_instance_widget[$widget_real_id]; 295 296 // Set the transient for this widget 297 $last_tweet = welt_set_tweet_transient( $widget_id, $instance, false ); 298 299 } 300 301 if( is_string( $last_tweet ) ){ // It is a error 302 303 echo $last_tweet; 304 305 } elseif ( $last_tweet != false ){ 306 307 foreach ($last_tweet as $tweet) { 308 309 $tweet_id = $tweet->id_str; 310 311 $last_tweet_html = get_transient('last_tweet_html_' . $tweet_id); 312 313 $tweet_html .= $last_tweet_html->html; 314 315 } 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 316 396 } else { 317 $tweet_html = __('Error: Twitter did not respond. Please wait a few minutes and refresh this page.', 'ab-welt-locales'); 318 } 319 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 412 $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); 418 419 foreach ($last_tweet as $tweet_id) { 420 421 // retrocompatibility 422 if( is_object( $tweet_id ) ){ 423 $tweet_id = $tweet_id->id_str; 424 } 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, $options ); 431 432 if( $tweet_html_transient ){ 433 set_transient('last_tweet_html_' . $tweet_id, $tweet_html, ( 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 446 } 447 } 448 449 } 320 450 321 451 echo $tweet_html; … … 332 462 function welt_enqueue_scripts(){ 333 463 // welt 334 wp_register_script('welt_script', plugins_url('/js/welt-scripts.js', __FILE__) , array( 'jquery' ), '20130129', true ); 464 wp_register_script('welt_twitter_script', '//platform.twitter.com/widgets.js' , array(), '1.1', true ); 465 wp_register_script('welt_script', plugins_url('/js/welt-scripts.js', __FILE__) , array( 'jquery', 'welt_twitter_script' ), '20130129', true ); 335 466 336 467 } … … 347 478 } 348 479 349 load_plugin_textdomain( ' ab-welt-locales', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );480 load_plugin_textdomain( 'widget-embed-lastest-tweets', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 350 481 } 351 482 add_action('plugins_loaded', 'welt_plugin_init'); … … 358 489 // Add settings link on plugin page 359 490 function welt_add_settings_link($links) { 360 $settings_link = '<a href=" plugins.php?page=welt_options_page">' . __('Settings') . '</a>';491 $settings_link = '<a href="options-general.php?page=welt_options_page">' . __('Settings') . '</a>'; 361 492 array_unshift($links, $settings_link); 362 493 return $links;
Note: See TracChangeset
for help on using the changeset viewer.