Changeset 836605
- Timestamp:
- 01/11/2014 11:20:10 AM (12 years ago)
- Location:
- inline-tweets
- Files:
-
- 41 added
- 2 deleted
- 3 edited
-
assets/banner-772x250.png (modified) (previous)
-
tags/2.0 (added)
-
tags/2.0/config.json (added)
-
tags/2.0/core (added)
-
tags/2.0/core/LatestTweetsSnippet.php (added)
-
tags/2.0/core/SingleTweetSnippet.php (added)
-
tags/2.0/core/Snippet.php (added)
-
tags/2.0/css (added)
-
tags/2.0/css/default.css (added)
-
tags/2.0/css/shared.css (added)
-
tags/2.0/img (added)
-
tags/2.0/img/loader.gif (added)
-
tags/2.0/inline-tweets.php (added)
-
tags/2.0/js (added)
-
tags/2.0/js/handler.js (added)
-
tags/2.0/js/settings.js (added)
-
tags/2.0/lib (added)
-
tags/2.0/lib/twitteroauth (added)
-
tags/2.0/lib/twitteroauth/OAuth.php (added)
-
tags/2.0/lib/twitteroauth/twitteroauth.php (added)
-
tags/2.0/php (added)
-
tags/2.0/php/settings.php (added)
-
tags/2.0/readme.txt (added)
-
trunk/config.json (added)
-
trunk/core (added)
-
trunk/core/LatestTweetsSnippet.php (added)
-
trunk/core/SingleTweetSnippet.php (added)
-
trunk/core/Snippet.php (added)
-
trunk/css (added)
-
trunk/css/default.css (added)
-
trunk/css/shared.css (added)
-
trunk/img (added)
-
trunk/img/loader.gif (added)
-
trunk/inline-tweets.php (modified) (7 diffs)
-
trunk/inline_tweets.js (deleted)
-
trunk/js (added)
-
trunk/js/handler.js (added)
-
trunk/js/settings.js (added)
-
trunk/lib (added)
-
trunk/lib/twitteroauth (added)
-
trunk/lib/twitteroauth/OAuth.php (added)
-
trunk/lib/twitteroauth/twitteroauth.php (added)
-
trunk/loader.gif (deleted)
-
trunk/php (added)
-
trunk/php/settings.php (added)
-
trunk/readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
inline-tweets/trunk/inline-tweets.php
r714432 r836605 19 19 // ============================================================================= 20 20 21 // ============================================================================= 22 // Plugin Main File 23 // ============================================================================= 24 21 25 /* 22 26 Plugin Name: Inline Tweets 23 Plugin URI: http:// projects.djekic.net/inline-tweets27 Plugin URI: http://milos.djekic.net/my-software/inline-tweets 24 28 Description: Embed latest tweet(s) or a specific tweet in any page, post or text widget and apply your custom styles. 25 Version: 1.1.229 Version: 2.0 26 30 Author: Miloš Đekić 27 31 Author URI: http://milos.djekic.net 28 32 */ 29 33 30 // timeout in minutes for caching API responses 31 define('INLINE_TWEETS_CACHE_TIMEOUT',5); 32 33 /** 34 * Determines time difference in minutes 35 * 36 * @param $to current time 37 * @param $from starting point in time 38 * 39 * @return float 40 */ 41 function inline_tweets_time_diff_in_minutes($to,$from) { 42 return round(abs($to - $from) / 60,2); 34 // check if direct access attempted 35 if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) 36 { 37 // forbid access 38 header('HTTP/1.1 403 Forbidden'); 39 exit('Direct access not allowed.'); 40 } 41 42 // define inline tweets version 43 define('INLINE_TWEETS','2.0'); 44 45 // load configuration 46 $inline_tweets_config = json_decode(file_get_contents(__DIR__ . '/config.json')); 47 48 // --------------------------------------------------------------------------------------------------------------------- 49 // Functions 50 // --------------------------------------------------------------------------------------------------------------------- 51 52 /** 53 * Loads options 54 * 55 * @return stdClass 56 */ 57 function inline_tweets_loadOptions() 58 { 59 // load options from database 60 $options = get_option('inline_tweets_options'); 61 62 // render json 63 $json = @json_decode($options); 64 65 // return options 66 return ($json === false || empty($json)) ? new stdClass() : $json; 67 } 68 69 /** 70 * Saves options 71 * 72 * @param stdClass $options 73 */ 74 function inline_tweets_saveOptions($options) 75 { 76 // update options in the database 77 update_option('inline_tweets_options',json_encode($options)); 43 78 } 44 79 … … 49 84 * @return string HTML 50 85 */ 51 function inline_tweets_inline_error($error = "Error") { 86 function inline_tweets_inline_error($error = "Error") 87 { 52 88 return '<div class="inline_tweets_error">'.$error.'</div>'; 53 89 } 54 90 55 91 /** 56 * Embeds tweet into an HTML entity 57 * 58 * @param $tweet 59 * @return string HTML 60 */ 61 function inline_tweets_embed_tweet($tweet) { 62 // get tweet content 63 $content = $tweet['text']; 64 65 // append tweet author 66 $content = '<a class="inline_tweets_author" href="http://twitter.com/'.$tweet['user']['screen_name'].'" target="_blank">'."@{$tweet['user']['screen_name']}".'</a> ' . $content; 67 68 // render tags 69 foreach($tweet["entities"]["hashtags"] as $tag) { 70 $content = str_replace("#{$tag['text']}",'<span class="inline_tweets_tag">'."#{$tag['text']}".'</span>',$content); 71 } 72 73 // render URLs 74 foreach($tweet["entities"]["urls"] as $url) { 75 $content = str_replace($url["url"],'<a class="inline_tweets_url" href="'.$url["expanded_url"].'" target="_blank">'.$url["url"].'</a>',$content); 76 } 77 78 // render mentions 79 foreach($tweet["entities"]["user_mentions"] as $mention) { 80 $content = str_replace("@{$mention['screen_name']}",'<a class="inline_tweets_mention" href="http://twitter.com/'.$mention['screen_name'].'" target="_blank">'."@{$mention['screen_name']}".'</a>',$content); 81 } 82 83 // add timestamp 84 $content .= ' <span class="inline_tweets_timestamp">' . date('M d',strtotime($tweet['created_at'])) . '</span>'; 85 86 // return rendered tweet content 87 return $content; 88 } 89 90 /** 91 * Performs a curl request to Twitter API to fetch tweet(s) 92 * 93 * @param $url 94 * @return mixed 95 */ 96 function inline_tweets_curl($url) { 97 // init curl 98 $ch = curl_init(); 99 100 // parametrize curl calls 101 curl_setopt($ch, CURLOPT_URL,$url); 102 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 103 104 // @since 1.0.1 - handle SSL issue 105 curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 106 curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 107 108 // get result 109 $result = curl_exec($ch); 110 111 // close curl stream 112 curl_close($ch); 92 * Checks if Twitter is configured 93 * 94 * @param stdClass $options 95 * @return bool 96 */ 97 function inline_tweets_twitterConfigured($options) 98 { 99 // go trough all configuration items 100 foreach(array('consumer_key','consumer_secret','oauth_token','oauth_token_secret') as $item) 101 { 102 // make sure item is present 103 if(!isset($options->{$item})) return false; 104 105 // make sure item is not blank 106 if(empty($options->{$item})) return false; 107 } 108 109 // all configuration items are present 110 return true; 111 } 112 113 /** 114 * Handles an inline tweet snippet 115 * 116 * @return stdClass result 117 */ 118 function inline_tweets_action_handleSnippet() 119 { 120 // get snippet text 121 $snippet_text = isset($_REQUEST['snippet']) ? $_REQUEST['snippet'] : ''; 122 123 // init result 124 $result = new stdClass(); 125 126 // load options 127 $options = inline_tweets_loadOptions(); 128 129 // make sure Twitter is configured 130 if(!inline_tweets_twitterConfigured($options)) 131 { 132 // set error text 133 $result->html = inline_tweets_inline_error('Inline Tweets not configured!'); 134 135 // stop execution and return result 136 return $result; 137 } 138 139 // include dependencies 140 include(__DIR__ . '/lib/twitteroauth/OAuth.php'); 141 include(__DIR__ . '/lib/twitteroauth/twitteroauth.php'); 142 include(__DIR__ . '/core/Snippet.php'); 143 144 // init Twitter library 145 $twitter = new TwitterOAuth($options->consumer_key,$options->consumer_secret,$options->oauth_token,$options->oauth_token_secret); 146 147 try 148 { 149 // create a snippet 150 $snippet = \InlineTweets\Snippet::create($snippet_text,$twitter,$options); 151 152 // render the snippet 153 $result->html = $snippet->render(); 154 } 155 catch (RuntimeException $e) 156 { 157 // set error text 158 $result->html = inline_tweets_inline_error($e->getMessage()); 159 160 // stop execution and return result 161 return $result; 162 } 113 163 114 164 // return result … … 117 167 118 168 /** 119 * Request handler intercepts requests to admin.php and checks if any actions 120 * should be performed ('inline_tweets_action' parameter is in the request array) 121 */ 122 function inline_tweets_request_handler() { 123 // check if inline_tweets action is to be performed 169 * Saves settings for inline tweets 170 * 171 * @return stdClass result 172 */ 173 function inline_tweets_action_saveSettings() 174 { 175 // load current settings 176 $settings = inline_tweets_loadOptions(); 177 178 // override from request 179 foreach($_REQUEST['settings'] as $key => $value) $settings->{$key} = $value; 180 181 // save settings 182 inline_tweets_saveOptions($settings); 183 184 // respond 185 return $settings; 186 } 187 188 // --------------------------------------------------------------------------------------------------------------------- 189 // Behaviour 190 // --------------------------------------------------------------------------------------------------------------------- 191 192 /** 193 * Intercepts all requests made to index.php and checks if an action should be performed 194 * (when 'inline_tweets_snippet' parameter exists in the request array) 195 */ 196 function inline_tweets_ajaxAction() 197 { 198 // make sure action is requested 124 199 if(empty($_REQUEST['inline_tweets_action'])) return; 125 200 126 // handle tweet 127 $result = inline_tweets_handle($_REQUEST['inline_tweets_action']); 128 129 // send response 201 // define action 202 $action = 'inline_tweets_action_' . $_REQUEST['inline_tweets_action']; 203 204 // make sure action exists 205 if(!function_exists($action)) return; 206 207 // perform action 208 $result = $action(); 209 210 // respond 130 211 header('Content-type: application/json'); 131 212 echo json_encode($result); 213 214 // stop execution 132 215 die; 133 }134 135 /**136 * Handles an inline tweet137 *138 * @param $inline_tweet [account:action:param]139 * @return stdClass data[url,result]140 */141 function inline_tweets_handle($inline_tweet) {142 // clear tags143 $inline_tweet = str_replace('[tweet]','',$inline_tweet);144 $inline_tweet = str_replace('[/tweet]','',$inline_tweet);145 146 // get embed data147 $embed_data = explode(':',$inline_tweet);148 149 // check data structure150 if(count($embed_data) < 2) return inline_tweets_inline_error("Invalid structure.");151 152 // init result153 $result = new stdClass();154 $result->url = "n/a";155 156 // check action157 switch($embed_data[0]) {158 case 'latest':159 // check structure160 if(count($embed_data) < 3) {161 $result->html = inline_tweets_inline_error("Invalid structure.");162 break;163 }164 165 // determine screen name166 $screen_name = $embed_data[1];167 168 // check screen name169 if(!preg_match('/^[A-Za-z0-9_]{1,15}$/', $screen_name)) {170 $result->html = inline_tweets_inline_error("Invalid Twitter username.");171 break;172 }173 174 // determine count175 $count = intval($embed_data[2]);176 177 // check count178 if($count == 0) {179 $result->html = inline_tweets_inline_error("Invalid tweets count.");180 break;181 }182 183 // form cache handle184 $result->cache_handle = "inline_tweets_latest_{$screen_name}_{$count}";185 186 // get cache entry187 $cache_entry = wp_cache_get($result->cache_handle);188 189 // check if cache entry exists and is young enough190 if($cache_entry !== false && inline_tweets_time_diff_in_minutes(time(),$cache_entry['timestamp']) <= INLINE_TWEETS_CACHE_TIMEOUT) {191 // get data from cache192 $data = $cache_entry['data'];193 194 // set from cache flag195 $result->from_cache = true;196 }197 else {198 // form URL199 $result->url = "https://api.twitter.com/1/statuses/user_timeline.json"200 ."?include_entities=true&include_rts=true&screen_name={$screen_name}&count={$count}";201 202 // get response from Twitter API203 $response = inline_tweets_curl($result->url);204 205 // decode from JSON to array206 $data = @json_decode($response,true);207 208 // check data and return inline error if data is false209 if($data == false) {210 $result->html = inline_tweets_inline_error("Unable to fetch tweet(s)");211 break;212 }213 214 // check if there was an API error215 if(isset($data["error"])) {216 $result->html = inline_tweets_inline_error($data["error"]);217 break;218 }219 220 // save to cache221 wp_cache_set($result->cache_handle,array('timestamp' => time(), 'data' => $data));222 223 // set from cache flag224 $result->from_cache = false;225 }226 227 // start creating content228 $content = ($count == 1) ? '' : '<ul class="inline_tweets_ul">';229 230 // go trough all fetched tweets231 foreach($data as $tweet) {232 // input embedded tweet233 $content .= ($count == 1) ? '<div class="inline_tweet">' : '<li class="inline_tweet inline_tweets_li">';234 $content .= inline_tweets_embed_tweet($tweet);235 $content .= ($count == 1) ? '</div>' : '</li>';236 }237 238 // finish content239 $content .= ($count == 1) ? '' : '</ul>';240 241 // save created content242 $result->html = $content; break;243 case 'status':244 // determine status id245 $id = ($embed_data[1]);246 247 // form cache handle248 $result->cache_handle = "inline_tweets_status_{$id}";249 250 // get cache entry251 $cache_entry = wp_cache_get($result->cache_handle);252 253 // check if cache entry exists and is young enough254 if($cache_entry !== false && inline_tweets_time_diff_in_minutes(time(),$cache_entry['timestamp']) <= INLINE_TWEETS_CACHE_TIMEOUT) {255 // get data from cache256 $data = $cache_entry['data'];257 258 // set from cache flag259 $result->from_cache = true;260 }261 else {262 // form URL263 $result->url = "https://api.twitter.com/1/statuses/show.json?id={$id}&include_entities=true";264 265 // get response from Twitter API266 $response = inline_tweets_curl($result->url);267 268 // decode from JSON to array269 $data = @json_decode($response,true);270 271 // check data and return inline error if data is false272 if($data == false) {273 $result->html = inline_tweets_inline_error("Unable to fetch tweet.");274 break;275 }276 277 // check if there was an API error278 if(isset($data["error"])) {279 $result->html = inline_tweets_inline_error($data["error"]);280 break;281 }282 283 // save to cache284 wp_cache_set($result->cache_handle,array('timestamp' => time(), 'data' => $data));285 286 // set from cache flag287 $result->from_cache = false;288 }289 290 // save tweet291 $result->html = '<div class="inline_tweet">' . inline_tweets_embed_tweet($data) . '</div>'; break;292 default: $result->html = inline_tweets_inline_error();293 }294 295 // return result296 return $result;297 216 } 298 217 … … 303 222 * @return String rendered content 304 223 */ 305 function inline_tweets_render($content) { 224 function inline_tweets_render($content) 225 { 306 226 // define regex for searching for inline tweets 307 227 $regex = '/\[tweet\](.*?)\[\/tweet\]/ism'; … … 314 234 315 235 // handle all matches 316 if(isset($inline_tweets[0])) foreach($inline_tweets[0] as $inline_tweets_data) { 317 // wrap inline tweet in placeholder div 318 $content = str_replace($inline_tweets_data,'<div class="inline_tweets_placeholder">'.$inline_tweets_data.'</div>',$content); 236 if(isset($inline_tweets[0])) foreach($inline_tweets[0] as $snippet) 237 { 238 // remove tags from the snippet 239 $cleared_snippet = str_replace('[tweet]','',$snippet); 240 $cleared_snippet = str_replace('[/tweet]','',$cleared_snippet); 241 242 // wrap inline tweet in placeholder div with a loader 243 $content = str_replace($snippet,'<div class="inline_tweets_placeholder" snippet="'.$cleared_snippet.'"><img src="'. plugins_url('/img/loader.gif',__FILE__) . '" /></div>',$content); 319 244 } 320 245 … … 324 249 325 250 /** 326 * Loads Inline Tweets script in header 327 */ 328 function inline_tweets_load_js_in_header() { 329 // load basic css styles 330 echo '<style type="text/css">div.inline_tweets_placeholder{text-align: center;}</style>'; 331 332 // set url param for the loader image 251 * Loads Inline Tweets front-end dependencies in header 252 */ 253 function inline_tweets_loadHeader() 254 { 255 global $inline_tweets_config; 256 257 // load options 258 $options = inline_tweets_loadOptions(); 259 260 // define styles 261 $styles = array_merge(array('shared'),$inline_tweets_config->styles); 262 263 // register styles 264 foreach($styles as $style) 265 wp_register_style("inline_tweets_{$style}", plugins_url("/css/{$style}.css", __FILE__ ), array(), INLINE_TWEETS, 'all'); 266 267 // set inline tweets url base 333 268 echo '<script type="text/javascript">var INLINE_TWEETS_BASE_URL = "' . get_bloginfo('siteurl') . '";</script>'; 334 335 // set url param for the loader image 336 echo '<script type="text/javascript">var INLINE_TWEETS_LOADER_URL = "' . plugins_url('/loader.gif',__FILE__) . '";</script>'; 337 338 // load handling script 339 wp_enqueue_script('inline_tweets', plugins_url('/inline_tweets.js',__FILE__)); 340 } 341 342 // register request handler 343 add_action('init', 'inline_tweets_request_handler', 9999); 269 270 // load shared style 271 wp_enqueue_style('inline_tweets_shared'); 272 273 // load style set in options (if not "none") 274 if(isset($options->style) && $options->style != 'none' && in_array($options->style,$inline_tweets_config->styles)) 275 wp_enqueue_style("inline_tweets_{$options->style}"); 276 277 // load the handling script 278 wp_enqueue_script('inline_tweets', plugins_url('/js/handler.js',__FILE__)); 279 } 280 281 /** 282 * Adds a menu item for accessing the settings page 283 */ 284 function inline_tweets_menuItem() 285 { 286 add_submenu_page( 287 'options-general.php', // parent 288 'Inline Tweets Settings', // page title 289 'Inline Tweets', // menu item title 290 'administrator', // permission 291 'inline-tweets-settings', // unique page name 292 'inline_tweets_renderSettingsPage' // rendering function 293 ); 294 } 295 296 /** 297 * Renders the settings page 298 */ 299 function inline_tweets_renderSettingsPage() 300 { 301 global $inline_tweets_config; 302 303 // load options 304 $options = inline_tweets_loadOptions(); 305 306 // set inline tweets url base 307 echo '<script type="text/javascript">var INLINE_TWEETS_BASE_URL = "' . get_bloginfo('siteurl') . '";</script>'; 308 309 // load the settings script 310 wp_enqueue_script('inline_tweets', plugins_url('/js/settings.js',__FILE__)); 311 312 // render the page 313 include(__DIR__ . '/php/settings.php'); 314 } 315 316 /** 317 * Adds a plugin action for accessing the settings page 318 * 319 * @param $links 320 * @return $links 321 */ 322 function inlineTweets_addPluginActionLink($links) { 323 // form the link 324 $link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=inline-tweets-settings">Settings</a>'; 325 326 // append the link 327 array_unshift($links, $link); 328 329 // return the action links 330 return $links; 331 } 332 333 // --------------------------------------------------------------------------------------------------------------------- 334 // Commands 335 // --------------------------------------------------------------------------------------------------------------------- 336 337 // register options 338 add_option('inline_tweets_options',''); 339 340 // register request handler for ajax calls 341 add_action('init', 'inline_tweets_ajaxAction', 9999); 344 342 345 343 // add rendering filter for posts/pages … … 350 348 351 349 // add head action to include inline-tweets script 352 add_action('wp_head', 'inline_tweets_load_js_in_header'); 350 add_action('wp_head', 'inline_tweets_loadHeader'); 351 352 // register menu item for settings 353 add_action('admin_menu', 'inline_tweets_menuItem'); 354 355 // add plugin action for accessing the settings page 356 add_action('plugin_action_links_'.plugin_basename(__FILE__),'inlineTweets_addPluginActionLink'); -
inline-tweets/trunk/readme.txt
r714432 r836605 2 2 3 3 Contributors: mdjekic 4 Donate link: http:// projects.djekic.net/inline-tweets4 Donate link: http://milos.djekic.net/my-software/inline-tweets 5 5 Tags: tweeter,tweets,inline,embed,styles 6 6 License: GPLv2 7 7 License URI: http://www.gnu.org/licenses/gpl-2.0.html 8 8 Requires at least: 2.7 9 Tested up to: 3. 5.110 Stable tag: 1.1.29 Tested up to: 3.8 10 Stable tag: 2.0 11 11 12 12 Embed latest tweet(s) or a specific tweet in any page, post or text widget and apply your custom styles. 13 13 14 15 16 14 17 == Description == 15 18 16 This simple plugin will help you embed tweets into your posts, pages and text widgets and apply your custom styles. 17 Just enter this simple syntax into your post, page or widget content: 18 19 = Latest Tweet(s) = 20 21 [tweet]latest:twitter_user:count[/tweet] 22 23 Replace "twitter_user" with a Twitter username and "count" with the number of latest tweets to fetch. Example: 24 25 [tweet]latest:milos_djekic:5[/tweet] 26 27 = Specific Tweet = 28 29 [tweet]status:status_id[/tweet] 30 31 Replace "status_id" with a Twitter status id. Example: 32 33 [tweet]status:316942284857962497[/tweet] 34 35 = Styling = 36 37 Inline tweets are displayed with a set of CSS class attributes that you can customise in your own 38 style sheets. Some basic classes are: 39 40 * "inline_tweets_author" - rendered when displaying tweet author - <a href="http://twitter.com/twitter" class="inline_tweets_author">@twitter</a> 41 * "inline_tweets_tag" - rendered when displaying hashtags - <span class="inline_tweets_tag">#hashtag</span> 42 * "inline_tweets_url" rendered when displaying URLs - <a href="http://google.com" class="inline_tweets_url">google.com</a> 43 * "inline_tweets_mention" - rendered when displaying mentions - <a href="http://twitter.com/twitter" class="inline_tweets_mention">@twitter</a> 44 * "inline_tweets_timestamp" - rendered when displaying tweet timestamp - <span class="inline_tweets_timestamp">Mar 12</span> 45 46 Tweets are contained in a "div" element with a class attribute "inline_tweet". If there is more than one tweet, 47 they are contained in a "li" element with the same class (and an extra class - "inline_tweets_li"). All "li" elements 48 are contained in a "ul" element with a class "inline_tweets_ul". If there were errors, they will be displayed in a "div" 49 element with a class "inline_tweets_error". 50 51 If you wish to exclude some information from the display - for example: tweet timestamp - all you have to do is 52 set "display" property to "none" for the class "inline_tweets_timestamp" in your custom style sheet. 19 This simple plugin will enable you to embed tweets into your posts, pages and text widgets and apply YOUR CUSTOM STYLES. It comes down to adding a simple snippet into your post, page or text widget content. Here's an example: 20 21 `[tweet]latest|user=WordPress,count=5[/tweet]` 22 23 This snippet will display five last tweets made by @WordPress with an intuitive HTML markup to which you can easily apply your custom CSS: 24 25 `.inline_tweet { background-color: whitesmoke; border: 2px solid black; }` 26 27 Fetching tweets will be done in the background and will not slow down the displaying of your website or blog. You will see an unobtrusive transition placeholder before the tweets are loaded. 28 29 You like that? Take a look at the [How to use](http://wordpress.org/plugins/inline-tweets/how-to-use/) and [Markup and Styling](http://wordpress.org/plugins/inline-tweets/markup-and-styling/) pages to learn what you can do. 53 30 54 31 = Caching = 55 32 56 Caching will improve performance when fetching tweets and ensure th e plugin operates within Twitter API limits.57 To enable caching, please install [W3 Total Cache](http://wordpress.org/extend/plugins/w3-total-cache/) and enable 58 'Object Cache' in plugin settings. 59 60 Visit the [project page](http://projects.djekic.net/inline-tweets/) to learn more on styling inline tweets.33 Caching will improve performance when fetching tweets and ensure that the plugin operates within Twitter API limits. To enable caching, please install [W3 Total Cache](http://wordpress.org/extend/plugins/w3-total-cache/) and enable 'Object Cache' in plugin settings. 34 35 = Configuration = 36 37 SinceTwitter introduced it's API version 1.1 you need to create a Twitter application to be able to use it and thus to use this plugin. It's not hard, you will spend a couple of minutes to create an app and obtain tokens and keys you will use for configuring Inline Tweets. You will have to do that only once, so no problem. 61 38 62 39 = Author = 63 40 64 [Miloš Đekić](http://milos.djekic.net) is a software enthusiast from Belgrade, 65 Serbia. He loves to create useful software. 41 [Miloš Đekić](http://milos.djekic.net) is a software solutions architect from Belgrade, Serbia. He loves to create useful software. 42 43 = Credits = 44 45 Credits should be given when credits are due. Inline tweets use a great Twitter API wrapper library created by [Abraham Williams](https://abrah.am/) to communicate with Twitter. You can find it [here](https://github.com/abraham/twitteroauth) 46 47 48 66 49 67 50 == Installation == … … 69 52 Just follow this simple guidelines. 70 53 71 = Installation steps = 54 Installation steps 72 55 73 56 1. Upload 'inline-tweets' to the '/wp-content/plugins/' directory 74 57 1. Activate the plugin through the 'Plugins' menu in WordPress 75 1. Include inline tweet syntax in your pages or posts 76 1. Customize inline tweets with your custom CSS 58 1. Visit plugin settings page to configure your Twitter keys and tokens 59 1. Include inline tweet snippets in your pages, posts or widgets 60 1. Customize inline tweets with your own CSS 77 61 1. That's it. Enjoy! 62 63 64 65 66 == How to use == 67 68 The usage depends on what you want to display. Only a couple of ways of displaying tweets exists but the list of applications will be expanded in the future. Make sure you take a look at the "Snippet Options" and learn how to take control over what is displayed and how. 69 70 = Single Tweet = 71 72 This is useful when you want to embed a tweet in your blog article or page. Just use this snippet: 73 74 `[tweet]single|id=tweet_id[/tweet]` 75 76 Replace "tweet_id" with the ID of the Twitter status you want to display. That's it. 77 78 = Latest Tweets = 79 80 This will probably be the most common application of the plugin. If you want to display a list of your (or someone elses) latest tweets in your sidebar and/or pages/articles, use this snippet 81 82 `[tweet]latest|user=twitter_user[/tweet]` 83 84 Replace "twitter_user" with the username of the account whose tweets you want to display. You can limit the number of tweets that will be fetched and displayed by adding a "count" param. Take a look at the following example: 85 86 `[tweet]latest|user=twitter_user,count=10[/tweet]` 87 88 Note: Default number of tweets that will be fetched is 5 and the maximum you can set is 25. If you set more that the maximum you will get the default 5 tweets. 89 90 = Display Options = 91 92 There are various options to help you customise what will be displayed by the plugin for a particular snippet. You can include a custom option by adding the option string after a comma sign. 93 94 Here's a list of all options with examples: 95 96 **time_format** 97 98 You can select the time format inline. Have in mind that if the format you set is not supported the time will be displayed in default format Here's an example: 99 100 `[tweet]latest|user=twitter_user,time_format=M Y[/tweet]` 101 102 **hide_author** 103 104 You can easily remove the author from display by simply adding the option: 105 106 `[tweet]single|id=tweet_id,hide_author[/tweet]` 107 108 **hide_avatar** 109 110 You can easily remove the avatar from display by simply adding the option: 111 112 `[tweet]single|id=tweet_id,hide_avatar[/tweet]` 113 114 **hide_timestamp** 115 116 You can easily remove the timestamp from display by simply adding the option: 117 118 `[tweet]single|id=tweet_id,hide_timestamp[/tweet]` 119 120 **full_names** 121 122 By default tweets are displayed with their authors Twitter names. If "full_names" param is set they will be displayed with their full names: 123 124 `[tweet]latest|user=twitter_user,count=15,full_names[/tweet]` 125 126 127 128 129 == Markup and Styling == 130 131 Inline tweets are rendered with a reckognizable HTML markup that you can use to display them in virtually every way possible using CSS. For starters, every tweet is wrapped in an element with class "inline_tweet". Then every displayed element has it's own class and rules. 132 133 = Tweet Content = 134 135 **Author** 136 137 Author's Twitter name or full name is displayed as a link to his/her Twitter page: 138 139 <a class="inline_tweets_author" href="http://twitter.com/author" target="_blank">@author</a> 140 141 You can style the link by referencing the "inline_tweets_author" class (e.g. different color for plugin author than other users mentions). 142 143 **Avatar** 144 145 If displayed, the avatar is rendered as a link to author's Twitter page also, with the addition of an image element: 146 147 `<a class="inline_tweets_avatar" href="http://twitter.com/author" target="_blank"> 148 <img src="http://pbs.twimg.com/profile_images/author_image.jpeg"> 149 </a>` 150 151 You can style the link in terms of positioning and the image display by referencing the "inline_tweets_avatar" class. 152 153 **Mentions** 154 155 Mentions are also displayed as link to author Twitter pages and you cal easily style them by referencing the "inline_tweets_mention" class: 156 157 `<a class="inline_tweets_mention" href="http://twitter.com/mention" target="_blank">@mention</a` 158 159 **Hashtags** 160 161 Hashtags are wrapped in span elements enabling you to apply your custom styles (e.g. display in bold or italic) by referencing the "inline_tweets_tag" class: 162 163 `<span class="inline_tweets_tag">#tag</span>` 164 165 **Timestamp** 166 167 If you decide to display the timestamp, you can easily style it - in terms of positioning for starters - by referencing the "inline_tweets_timestamp" class. Here's how the timestamp is rendered: 168 169 `<span class="inline_tweets_timestamp">Jan 2014</span>` 170 171 = Single Tweet = 172 173 Here's an example of how a single tweet is displayed: 174 175 `<div class="inline_tweet"> 176 <a class="inline_tweets_author" href="http://twitter.com/ArchdukeM" target="_blank">@ArchdukeM</a> 177 <a class="inline_tweets_avatar" href="http://twitter.com/ArchdukeM" target="_blank"> 178 <img src="http://pbs.twimg.com/profile_images/image.jpeg"> 179 </a> 180 "She represented everything I loved about the English. She was totally deranged." 181 <span class="inline_tweets_timestamp">Jan 2014</span> 182 </div>` 183 184 = Multiple Tweets = 185 186 When more that one tweet is displayed it is rendered as a list. To cut it short, here's an example markup: 187 188 `<ul class="inline_tweets_ul"> 189 <li class="inline_tweet"> 190 CONTENT 191 </li> 192 </ul>` 193 194 Let's analyse the differences and the advantages. You have a ul element with a class "inline_tweets_ul" that you can use if you want to position the entire list, enable scrolling or whatever you want. Instead of a div element, there's a li element with the "inline_tweet" class for wrapping the tweet. Tweet content is rendered in the same way as single tweets. 195 196 197 78 198 79 199 == Screenshots == … … 82 202 2. Latest tweets displayed in the sidebar 83 203 204 205 206 84 207 == Changelog == 208 209 = 2.0 = 210 * A complete rewrite to support Twitter API 1.1 211 * User avatars in tweets 212 * Inline options in snippet (show/hide: author, avatar, timestamp; different timestamp formats, full author names) 85 213 86 214 = 1.1.2 = … … 102 230 = 1.0 = 103 231 * First version - inline tweets on. 232 233 234 235 236 == Upgrade Notice == 237 238 Inline Tweets now work with Twitter API 1.1! Upgrade to continue using the plugin with a lot of additional options.
Note: See TracChangeset
for help on using the changeset viewer.