WP twitter feeds - Version 1.4

Version Description

Download this release

Release Info

Developer vivacityinfotech.jaipur
Plugin Icon 128x128 WP twitter feeds
Version 1.4
Comparing to
See all releases

Code changes from version 1.3 to 1.4

README.txt CHANGED
@@ -5,7 +5,7 @@ Tags: wp twitter feeds,twitter feeds, twitter timeline,twitter widget,twitter w
5
  Requires at least: 3.0
6
  Tested up to: 3.9.1
7
  License: GPLv2 or later
8
- Stable tag: 1.3
9
 
10
 
11
  WP Twitter Feeds - A simple widget which lets you add your latest tweets in just a few clicks on your website.
@@ -24,7 +24,7 @@ The "WP Twitter Feeds" Widget will never require your Twitter password, because
24
  *Easy install
25
  *Very easy to configure.
26
  *Display Tweets with a Widget.
27
- *You can choose to show a profile image, border color and much more with your Tweets.
28
  *Multiple instance so you can use Twitter widget multiple places.
29
  *Different color Options.
30
  *Lightweight and loading fast
@@ -37,7 +37,7 @@ The "WP Twitter Feeds" Widget will never require your Twitter password, because
37
 
38
  Please take the time to let us and others know about your experiences by leaving a review, so that we can improve the plugin for you and other users.
39
 
40
- If you like the plugin please [Donate here](http://tinyurl.com/owxtkmt).
41
 
42
  = Want More? =
43
 
5
  Requires at least: 3.0
6
  Tested up to: 3.9.1
7
  License: GPLv2 or later
8
+ Stable tag: 1.4
9
 
10
 
11
  WP Twitter Feeds - A simple widget which lets you add your latest tweets in just a few clicks on your website.
24
  *Easy install
25
  *Very easy to configure.
26
  *Display Tweets with a Widget.
27
+ *Choose to show a profile image, Tweets border, Tweets theme and much more.
28
  *Multiple instance so you can use Twitter widget multiple places.
29
  *Different color Options.
30
  *Lightweight and loading fast
37
 
38
  Please take the time to let us and others know about your experiences by leaving a review, so that we can improve the plugin for you and other users.
39
 
40
+ If you like the plugin please [Donate here](http://bit.ly/1icl56K).
41
 
42
  = Want More? =
43
 
controller/twitter_widget.class.php CHANGED
@@ -1,360 +1,363 @@
1
- <?php class wptt_TwitterTweets extends WP_Widget{
2
-
3
- function form($instance){
4
- $defaults=$this->get_defaults();
5
- $instance = wp_parse_args( (array) $instance, $defaults );
6
- $widget_title = $instance['title'];
7
- $name = $instance['name'];
8
- $tweets_count = $instance['tweets_cnt'];
9
- $accessTokenSecret = trim($instance['accessTokenSecret']);
10
- $replies_excl = $instance['replies_excl'];
11
- $consumerSecret = trim($instance['consumerSecret']);
12
- $accessToken = trim($instance['accessToken']);
13
- $cache_transient = $instance['timeRef'];
14
- $alter_ago_time = $instance['timeAgo'];
15
- $twitterIntents = $instance['twitterIntents'];
16
- //$dataShowCount = $instance['dataShowCount'];
17
- $disp_screen_name = $instance['disp_scr_name'];
18
- $timeto_store = $instance['store_time'];
19
- $consumerKey = trim($instance['consumerKey']);
20
- $intents_text = $instance['twitterIntentsText'];
21
- $color_intents = $instance['intentColor'];
22
- $showAvatar = $instance['showAvatar'];
23
- $border_rad_avatar = $instance['border_rad'];
24
- $tweet_border = $instance['tweet_border'];
25
- $tweet_theme = $instance['tweet_theme'];
26
- if (!in_array('curl', get_loaded_extensions())) {
27
- echo '<p style="background-color:pink;padding:10px;border:1px solid red;"><strong>cURL is not installed!</strong></p>';
28
- }
29
- include('widget_html.php');
30
- }
31
- function get_defaults()
32
- {
33
- $data = array(
34
- 'title' => 'Latest Tweets'
35
- , 'name' => ''
36
- , 'tweets_cnt' => 3
37
- , 'tweet_theme' => 'light'
38
- , 'tweet_border' => 'true'
39
- , 'store_time' => 4
40
- , 'replies_excl' => true
41
- , 'disp_scr_name' => false
42
- , 'consumerKey' => ''
43
- , 'consumerSecret' => ''
44
- , 'accessToken' => ''
45
- , 'accessTokenSecret' => ''
46
- , 'dataLang' => 'en'
47
- , 'timeRef' => false
48
- , 'timeAgo' => true
49
- , 'twitterIntents' => false
50
- , 'twitterIntentsText' => false
51
- , 'intentColor' => "#999999"
52
- , 'showAvatar' => false
53
- , 'border_rad' => false
54
- );
55
- return $data;
56
- }
57
- function wpltf_enqueue_js($hook) {
58
- if( $hook != 'widgets.php' )
59
- return;
60
-
61
-
62
- global $wp_version;
63
- if ( 3.5 <= $wp_version ){
64
- wp_enqueue_style( 'wp-color-picker' );
65
- wp_enqueue_script( 'wp-color-picker' );
66
- }
67
- else {
68
- wp_enqueue_style( 'farbtastic' );
69
- wp_enqueue_script( 'farbtastic' );
70
- }
71
- wp_enqueue_script('admin_js', plugins_url( '/js/admin_script.js' , dirname(__FILE__) ), array('jquery'));
72
- wp_enqueue_script('user_validate', plugins_url( '/js/validate.js' , dirname(__FILE__) ), array('jquery'));
73
- }
74
- function sanitize_links($tweet) {
75
- if(isset($tweet->retweeted_status)) {
76
- $rt_section = current(explode(":", $tweet->text));
77
- $text = $rt_section.": ";
78
- $text .= $tweet->retweeted_status->text;
79
- } else {
80
- $text = $tweet->text;
81
- }
82
- $text = preg_replace('/((http)+(s)?:\/\/[^<>\s]+)/i', '<a href="$0" target="_blank" rel="nofollow">$0</a>', $text );
83
- $text = preg_replace('/[@]+([A-Za-z0-9-_]+)/', '<a href="http://twitter.com/$1" target="_blank" rel="nofollow">@$1</a>', $text );
84
- $text = preg_replace('/[#]+([A-Za-z0-9-_]+)/', '<a href="http://twitter.com/search?q=%23$1" target="_blank" rel="nofollow">$0</a>', $text );
85
- return $text;
86
-
87
- }
88
- function update($new_instance, $old_instance){
89
- $instance = $old_instance;
90
-
91
- $instance['title'] = strip_tags( $new_instance['title'] );
92
- $instance['name'] = strip_tags( $new_instance['name'] );
93
- $instance['tweets_cnt'] = $new_instance['tweets_cnt'];
94
- $instance['store_time'] = $new_instance['store_time'];
95
- //$instance['dataShowCount'] = $new_instance['dataShowCount'];
96
- $instance['disp_scr_name'] = $new_instance['disp_scr_name'];
97
- $instance['timeAgo'] = $new_instance['timeAgo'];
98
- $instance['twitterIntents'] = $new_instance['twitterIntents'];
99
- $instance['twitterIntentsText'] = $new_instance['twitterIntentsText'];
100
- $instance['intentColor'] = strip_tags( $new_instance['intentColor'] );
101
- $instance['consumerKey'] = trim($new_instance['consumerKey']);
102
- $instance['consumerSecret'] = trim($new_instance['consumerSecret']);
103
- $instance['accessToken'] = trim($new_instance['accessToken']);
104
- $instance['accessTokenSecret'] = trim($new_instance['accessTokenSecret']);
105
- $instance['replies_excl'] = $new_instance['replies_excl'];
106
- $instance['timeRef'] = $new_instance['timeRef'];
107
- $instance['showAvatar'] = $new_instance['showAvatar'];
108
- $instance['border_rad'] = $new_instance['border_rad'];
109
- $instance['tweet_border'] = $new_instance['tweet_border'];
110
- $instance['tweet_theme'] = $new_instance['tweet_theme'];
111
- return $instance;
112
- }
113
- function __construct() {
114
- add_action('admin_enqueue_scripts', array(&$this, 'wpltf_enqueue_js'));
115
- if(!is_admin())
116
- add_action( 'wp_enqueue_scripts', array( &$this, 'wpltf_register_styles' ) );
117
- $widget_data = array('classname' => 'wptt_TwitterTweets', 'description' => 'A simple widget which lets you add your latest tweets in just a few clicks on your website.' );
118
- $this->WP_Widget('wptt_TwitterTweets', 'WP Twitter Feeds', $widget_data);
119
- }
120
-
121
- function wpltf_register_styles() {
122
- if(!is_admin()){
123
- wp_register_style( 'wptt_front', plugins_url( 'wp-twitter-feeds/css/admin_style.min.css' ) );
124
- wp_enqueue_style( 'wptt_front' );
125
- }
126
- }
127
- function widget($args, $instance){
128
- extract($args, EXTR_SKIP);
129
-
130
- echo $before_widget;
131
- $wpltf_wdgt_title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
132
- $wpltf_wdgt_name = $instance['name'];
133
- $wpltf_wdgt_consumerSecret = trim($instance['consumerSecret']);
134
- $wpltf_wdgt_accessTokenSecret = trim($instance['accessTokenSecret']);
135
- $widget_replies_excl = isset( $instance['replies_excl'] ) ? $instance['replies_excl'] : false;
136
- $wpltf_wdgt_accessToken = trim($instance['accessToken']);
137
- $wpltf_wdgt_tweets_cnt = $instance['tweets_cnt'];
138
- $wpltf_wdgt_store_time = $instance['store_time'];
139
- $wpltf_wdgt_consumerKey = trim($instance['consumerKey']);
140
- //$wpltf_wdgt_dataShowCount = isset( $instance['dataShowCount'] ) ? $instance['dataShowCount'] : false;
141
- $wpltf_wdgt_disp_scr_name = isset( $instance['disp_scr_name'] ) ? $instance['disp_scr_name'] : false;
142
- $wpltf_wdgt_timeRef = isset( $instance['timeRef'] ) ? $instance['timeRef'] : false;
143
- $wpltf_wdgt_timeAgo = isset( $instance['timeAgo'] ) ? $instance['timeAgo'] : false;
144
- $wpltf_wdgt_twitterIntents = isset( $instance['twitterIntents'] ) ? $instance['twitterIntents'] : false;
145
- $wpltf_wdgt_twitterIntentsText = isset( $instance['twitterIntentsText'] ) ? $instance['twitterIntentsText'] : false;
146
- $wpltf_wdgt_intentColor = $instance['intentColor'];
147
- $wpltf_wdgt_showAvatar = isset( $instance['showAvatar'] ) ? $instance['showAvatar'] : false;
148
- $wpltf_wdgt_border_rad = isset( $instance['border_rad'] ) ? $instance['border_rad'] : false;
149
- $wpltf_wdgt_tewwt_border = isset( $instance['tweet_border'] ) ? $instance['tweet_border'] : 'false';
150
- $wpltf_wdgt_tweet_theme = isset( $instance['tweet_theme'] ) ? $instance['tweet_theme'] : 'light';
151
- if (!empty($wpltf_wdgt_title))
152
- echo $before_title . $wpltf_wdgt_title . $after_title;
153
- if($wpltf_wdgt_consumerKey=='' || $wpltf_wdgt_consumerSecret ==''|| $wpltf_wdgt_accessTokenSecret=='' || $wpltf_wdgt_accessToken=='' )
154
- {
155
- echo '<div class="isa_error">Bad Authentication data.<br/>Please enter valid API Keys.</div>';
156
- }
157
- else
158
- {
159
- $class='light';
160
- if(isset($wpltf_wdgt_tweet_theme) && $wpltf_wdgt_tweet_theme=='dark')
161
- $class='dark';
162
- if(isset($wpltf_wdgt_tewwt_border) && $wpltf_wdgt_tewwt_border=='true')
163
- {
164
- echo '<style>
165
- .fetched_tweets.light > li{border-color: rgb(238, 238, 238) rgb(221, 221, 221) rgb(187, 187, 187);
166
- border-width: 1px;
167
- border-style: solid;}
168
- .fetched_tweets.dark > li{
169
- border-color: #444;
170
- border-width: 1px;
171
- border-style: solid;}</style>';
172
- }
173
- ?> <ul class="fetched_tweets <?php echo $class;?>">
174
- <?php
175
-
176
- $tweets_count = $wpltf_wdgt_tweets_cnt;
177
- $name = $wpltf_wdgt_name;
178
- $timeto_store = $wpltf_wdgt_store_time;
179
- $consumerSecret = trim($wpltf_wdgt_consumerSecret);
180
- $accessToken = trim($wpltf_wdgt_accessToken);
181
- $accessTokenSecret = trim($wpltf_wdgt_accessTokenSecret);
182
- $replies_excl = $widget_replies_excl;
183
- $consumerKey = trim($wpltf_wdgt_consumerKey);
184
- //$dataShowCount = ($wpltf_wdgt_dataShowCount != "true") ? "false" : "true";
185
- $disp_screen_name = ($wpltf_wdgt_disp_scr_name != "true") ? "false" : "true";
186
- $intents_text = $wpltf_wdgt_twitterIntentsText;
187
- $color_intents = $wpltf_wdgt_intentColor;
188
- $cache_transient = $wpltf_wdgt_timeRef;
189
- $alter_ago_time = $wpltf_wdgt_timeAgo;
190
- $twitterIntents = $wpltf_wdgt_twitterIntents;
191
- $showAvatar = $wpltf_wdgt_showAvatar;
192
- $border_rad_avatar = $wpltf_wdgt_border_rad;
193
- $transName = 'list-tweets-'.$name;
194
- $backupName = $transName . '-backup';
195
- if(false === ($tweets = get_transient($transName) ) ) :
196
- include 'twitteroauth/twitteroauth.php';
197
-
198
- $api_call = new TwitterOAuth(
199
- $consumerKey,
200
- $consumerSecret,
201
- $accessToken,
202
- $accessTokenSecret
203
- );
204
- $totalToFetch = ($replies_excl) ? max(50, $tweets_count * 3) : $tweets_count;
205
-
206
- $fetchedTweets = $api_call->get(
207
- 'statuses/user_timeline',
208
- array(
209
- 'screen_name' => $name,
210
- 'count' => $totalToFetch,
211
- 'replies_excl' => $replies_excl
212
- )
213
- );
214
-
215
- if($api_call->http_code != 200) :
216
- $tweets = get_option($backupName);
217
-
218
- else :
219
- $limitToDisplay = min($tweets_count, count($fetchedTweets));
220
-
221
- for($i = 0; $i < $limitToDisplay; $i++) :
222
- $tweet = $fetchedTweets[$i];
223
- $name = $tweet->user->name;
224
- $screen_name = $tweet->user->screen_name;
225
- $permalink = 'http://twitter.com/'. $name .'/status/'. $tweet->id_str;
226
- $tweet_id = $tweet->id_str;
227
- $image = $tweet->user->profile_image_url;
228
- $text = $this->sanitize_links($tweet);
229
- $time = $tweet->created_at;
230
- $time = date_parse($time);
231
- $uTime = mktime($time['hour'], $time['minute'], $time['second'], $time['month'], $time['day'], $time['year']);
232
- $tweets[] = array(
233
- 'text' => $text,
234
- 'scr_name'=>$screen_name,
235
- 'favourite_count'=>$tweet->favorite_count,
236
- 'retweet_count'=>$tweet->retweet_count,
237
- 'name' => $name,
238
- 'permalink' => $permalink,
239
- 'image' => $image,
240
- 'time' => $uTime,
241
- 'tweet_id' => $tweet_id
242
- );
243
- endfor;
244
- set_transient($transName, $tweets, 60 * $timeto_store);
245
- update_option($backupName, $tweets);
246
- endif;
247
- endif;
248
- function twitter_time_diff( $from, $to = '' ) {
249
- $diff = human_time_diff($from,$to);
250
- $replace = array(
251
- ' hour' => 'h',
252
- ' hours' => 'h',
253
- ' day' => 'd',
254
- ' days' => 'd',
255
- ' minute' => 'm',
256
- ' minutes' => 'm',
257
- ' second' => 's',
258
- ' seconds' => 's',
259
- );
260
- return strtr($diff,$replace);
261
- }
262
- if($tweets) : ?>
263
- <?php foreach($tweets as $t) : ?>
264
- <li class="tweets_avatar">
265
- <?php
266
- echo '<div class="tweet_wrap"><div class="wdtf-user-card ltr">';
267
- if ($showAvatar){
268
-
269
- echo '<img ';
270
- echo 'width="45px" height="45px"';
271
- echo 'src="'.$t['image'].'" alt="Tweet Avatar" class="';
272
- echo ($border_rad_avatar) ? 'circular':'';
273
- echo '"/>';
274
- }
275
- if(!isset($screen_name)){$screen_name = $name;}
276
-
277
- if($disp_screen_name!='false')
278
- {
279
- echo '<div class="wdtf-screen-name">';
280
- echo "<span class=\"screen_name\">{$t['name']}</span><br>";
281
- echo "<a href=\"https://twitter.com/{$screen_name}\" target=\"_blank\" dir=\"ltr\">@{$screen_name}</a></div>";
282
-
283
- }
284
- echo '<div class="clear"></div></div>';
285
- ?>
286
- <div class="tweet_data">
287
- <?php echo $t['text']; ?>
288
- </div>
289
- <br/>
290
- <div class="clear"></div>
291
- <div class="times">
292
- <em>
293
-
294
- <a href="http://www.twitter.com/<?php echo $screen_name; ?>" target="_blank" title="Follow <?php echo $name; ?> on Twitter [Opens new window]">
295
- <?php
296
- if($cache_transient == "true"){
297
- $timeDisplay = twitter_time_diff($t['time'], current_time('timestamp'));
298
- }else{
299
- $timeDisplay = human_time_diff($t['time'], current_time('timestamp'));
300
- }
301
- if($alter_ago_time == "true"){
302
- $displayAgo = " ago";
303
- }
304
- printf(__('%1$s%2$s'), $timeDisplay, $displayAgo);
305
-
306
- ?>
307
- </a>
308
- </em>
309
- </div>
310
- <?php if($twitterIntents == "true"){
311
- ?>
312
- <div class="tweets-intent-data">
313
- <?php if($t['favourite_count']!=0 || $t['retweet_count']!=0){?>
314
- <span class="stats-narrow customisable-border"><span class="stats" data-scribe="component:stats">
315
- <?php if($t['retweet_count']!=0)
316
- {?>
317
- <a href="https://twitter.com/<?php echo $screen_name; ?>/statuses/<?php echo $t['tweet_id']; ?>" title="View Tweet on Twitter" data-scribe="element:favorite_count" target="_blank">
318
- <span class="stats-favorites">
319
- <strong><?php echo $t['retweet_count'];?></strong> retweet<?php if($t['retweet_count']>1)echo's';?>
320
- </span>
321
- </a>
322
- <?php } ?>
323
- <?php if($t['favourite_count']!=0)
324
- {?>
325
- <a href="https://twitter.com/<?php echo $screen_name; ?>/statuses/<?php echo $t['tweet_id']; ?>" title="View Tweet on Twitter" data-scribe="element:favorite_count" target="_blank">
326
- <span class="stats-favorites">
327
- <strong><?php echo $t['favourite_count'];?></strong> Favorite<?php if($t['favourite_count']>1)echo's';?>
328
- </span>
329
- </a>
330
- <?php }?>
331
-
332
- </span>
333
- </span>
334
- <div class="clear"></div>
335
- <div class="seperator_wpltf"></div>
336
- <?php }?>
337
- <ul class="tweet-actions " role="menu" >
338
- <li><a href="http://twitter.com/intent/tweet?in_reply_to=<?php echo $t['tweet_id']; ?>" data-lang="en" class="in-reply-to" title="Reply" target="_blank"><span aria-hidden="true" data-icon="&#xf079;" <?php echo ($color_intents) ? 'style="color:'.$color_intents.';"' :''; ?>></span></a></li>
339
- <li><a href="http://twitter.com/intent/retweet?tweet_id=<?php echo $t['tweet_id']; ?>" data-lang="en" class="retweet" title="Retweet" target="_blank"><span aria-hidden="true" data-icon="&#xf112;" <?php echo ($color_intents) ? 'style="color:'.$color_intents.';"' :''; ?>></span></a></li>
340
- <li><a href="http://twitter.com/intent/favorite?tweet_id=<?php echo $t['tweet_id']; ?>" data-lang="en" class="favorite" title="Favorite" target="_blank"><span aria-hidden="true" data-icon="&#xf005;" <?php echo ($color_intents) ? 'style="color:'.$color_intents.';"' :''; ?>></span></a></li>
341
- </ul>
342
- </div>
343
- <?php } ?>
344
- <div class="clear"></div>
345
- </div><div class="clear"></div>
346
- </li>
347
- <?php endforeach; ?>
348
-
349
- <?php else : ?>
350
- <li>Waiting for twitter.com...Try reloading the page again </li>
351
- <?php endif; ?>
352
- </ul>
353
- <?php
354
- }
355
- echo $after_widget;
356
- }
357
-
358
- }
359
-
360
- ?>
 
 
 
1
+ <?php class wptt_TwitterTweets extends WP_Widget{
2
+
3
+ function form($instance){
4
+ $defaults=$this->get_defaults();
5
+ $instance = wp_parse_args( (array) $instance, $defaults );
6
+ $widget_title = $instance['title'];
7
+ $name = $instance['name'];
8
+ $tweets_count = $instance['tweets_cnt'];
9
+ $accessTokenSecret = trim($instance['accessTokenSecret']);
10
+ $replies_excl = $instance['replies_excl'];
11
+ $consumerSecret = trim($instance['consumerSecret']);
12
+ $accessToken = trim($instance['accessToken']);
13
+ $cache_transient = $instance['timeRef'];
14
+ $alter_ago_time = $instance['timeAgo'];
15
+ $twitterIntents = $instance['twitterIntents'];
16
+ //$dataShowCount = $instance['dataShowCount'];
17
+ $disp_screen_name = $instance['disp_scr_name'];
18
+ $timeto_store = $instance['store_time'];
19
+ $consumerKey = trim($instance['consumerKey']);
20
+ $intents_text = $instance['twitterIntentsText'];
21
+ $color_intents = $instance['intentColor'];
22
+ $showAvatar = $instance['showAvatar'];
23
+ $border_rad_avatar = $instance['border_rad'];
24
+ $tweet_border = $instance['tweet_border'];
25
+ $tweet_theme = $instance['tweet_theme'];
26
+ if (!in_array('curl', get_loaded_extensions())) {
27
+ echo '<p style="background-color:pink;padding:10px;border:1px solid red;"><strong>cURL is not installed!</strong></p>';
28
+ }
29
+ include('widget_html.php');
30
+ }
31
+ function get_defaults()
32
+ {
33
+ $data = array(
34
+ 'title' => 'Latest Tweets'
35
+ , 'name' => ''
36
+ , 'tweets_cnt' => 3
37
+ , 'tweet_theme' => 'light'
38
+ , 'tweet_border' => 'true'
39
+ , 'store_time' => 4
40
+ , 'replies_excl' => true
41
+ , 'disp_scr_name' => false
42
+ , 'consumerKey' => ''
43
+ , 'consumerSecret' => ''
44
+ , 'accessToken' => ''
45
+ , 'accessTokenSecret' => ''
46
+ , 'dataLang' => 'en'
47
+ , 'timeRef' => false
48
+ , 'timeAgo' => true
49
+ , 'twitterIntents' => false
50
+ , 'twitterIntentsText' => false
51
+ , 'intentColor' => "#999999"
52
+ , 'showAvatar' => false
53
+ , 'border_rad' => false
54
+ );
55
+ return $data;
56
+ }
57
+ function wpltf_enqueue_js($hook) {
58
+ if( $hook != 'widgets.php' )
59
+ return;
60
+
61
+
62
+ global $wp_version;
63
+ if ( 3.5 <= $wp_version ){
64
+ wp_enqueue_style( 'wp-color-picker' );
65
+ wp_enqueue_script( 'wp-color-picker' );
66
+ }
67
+ else {
68
+ wp_enqueue_style( 'farbtastic' );
69
+ wp_enqueue_script( 'farbtastic' );
70
+ }
71
+ wp_enqueue_script('admin_js', plugins_url( '/js/admin_script.js' , dirname(__FILE__) ), array('jquery'));
72
+ wp_enqueue_script('user_validate', plugins_url( '/js/validate.js' , dirname(__FILE__) ), array('jquery'));
73
+ }
74
+ function sanitize_links($tweet) {
75
+ if(isset($tweet->retweeted_status)) {
76
+ $rt_section = current(explode(":", $tweet->text));
77
+ $text = $rt_section.": ";
78
+ $text .= $tweet->retweeted_status->text;
79
+ } else {
80
+ $text = $tweet->text;
81
+ }
82
+ $text = preg_replace('/((http)+(s)?:\/\/[^<>\s]+)/i', '<a href="$0" target="_blank" rel="nofollow">$0</a>', $text );
83
+ $text = preg_replace('/[@]+([A-Za-z0-9-_]+)/', '<a href="http://twitter.com/$1" target="_blank" rel="nofollow">@$1</a>', $text );
84
+ $text = preg_replace('/[#]+([A-Za-z0-9-_]+)/', '<a href="http://twitter.com/search?q=%23$1" target="_blank" rel="nofollow">$0</a>', $text );
85
+ return $text;
86
+
87
+ }
88
+ function update($new_instance, $old_instance){
89
+ $instance = $old_instance;
90
+
91
+ $instance['title'] = strip_tags( $new_instance['title'] );
92
+ $instance['name'] = strip_tags( $new_instance['name'] );
93
+ $instance['tweets_cnt'] = $new_instance['tweets_cnt'];
94
+ $instance['store_time'] = $new_instance['store_time'];
95
+ //$instance['dataShowCount'] = $new_instance['dataShowCount'];
96
+ $instance['disp_scr_name'] = $new_instance['disp_scr_name'];
97
+ $instance['timeAgo'] = $new_instance['timeAgo'];
98
+ $instance['twitterIntents'] = $new_instance['twitterIntents'];
99
+ $instance['twitterIntentsText'] = $new_instance['twitterIntentsText'];
100
+ $instance['intentColor'] = strip_tags( $new_instance['intentColor'] );
101
+ $instance['consumerKey'] = trim($new_instance['consumerKey']);
102
+ $instance['consumerSecret'] = trim($new_instance['consumerSecret']);
103
+ $instance['accessToken'] = trim($new_instance['accessToken']);
104
+ $instance['accessTokenSecret'] = trim($new_instance['accessTokenSecret']);
105
+ $instance['replies_excl'] = $new_instance['replies_excl'];
106
+ $instance['timeRef'] = $new_instance['timeRef'];
107
+ $instance['showAvatar'] = $new_instance['showAvatar'];
108
+ $instance['border_rad'] = $new_instance['border_rad'];
109
+ $instance['tweet_border'] = $new_instance['tweet_border'];
110
+ $instance['tweet_theme'] = $new_instance['tweet_theme'];
111
+ return $instance;
112
+ }
113
+ function __construct() {
114
+ add_action('admin_enqueue_scripts', array(&$this, 'wpltf_enqueue_js'));
115
+ if(!is_admin())
116
+ add_action( 'wp_enqueue_scripts', array( &$this, 'wpltf_register_styles' ) );
117
+ $widget_data = array('classname' => 'wptt_TwitterTweets', 'description' => 'A simple widget which lets you add your latest tweets in just a few clicks on your website.' );
118
+ $this->WP_Widget('wptt_TwitterTweets', 'WP Twitter Feeds', $widget_data);
119
+ }
120
+
121
+ function wpltf_register_styles() {
122
+ if(!is_admin()){
123
+ wp_register_style( 'wptt_front', plugins_url( 'wp-twitter-feeds/css/admin_style.min.css' ) );
124
+ wp_enqueue_style( 'wptt_front' );
125
+ }
126
+ }
127
+ function widget($args, $instance){
128
+ extract($args, EXTR_SKIP);
129
+
130
+ echo $before_widget;
131
+ $wpltf_wdgt_title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
132
+ $wpltf_wdgt_name = $instance['name'];
133
+ $wpltf_wdgt_consumerSecret = trim($instance['consumerSecret']);
134
+ $wpltf_wdgt_accessTokenSecret = trim($instance['accessTokenSecret']);
135
+ $widget_replies_excl = isset( $instance['replies_excl'] ) ? $instance['replies_excl'] : false;
136
+ $wpltf_wdgt_accessToken = trim($instance['accessToken']);
137
+ $wpltf_wdgt_tweets_cnt = $instance['tweets_cnt'];
138
+ $wpltf_wdgt_store_time = $instance['store_time'];
139
+ $wpltf_wdgt_consumerKey = trim($instance['consumerKey']);
140
+ //$wpltf_wdgt_dataShowCount = isset( $instance['dataShowCount'] ) ? $instance['dataShowCount'] : false;
141
+ $wpltf_wdgt_disp_scr_name = isset( $instance['disp_scr_name'] ) ? $instance['disp_scr_name'] : false;
142
+ $wpltf_wdgt_timeRef = isset( $instance['timeRef'] ) ? $instance['timeRef'] : false;
143
+ $wpltf_wdgt_timeAgo = isset( $instance['timeAgo'] ) ? $instance['timeAgo'] : false;
144
+ $wpltf_wdgt_twitterIntents = isset( $instance['twitterIntents'] ) ? $instance['twitterIntents'] : false;
145
+ $wpltf_wdgt_twitterIntentsText = isset( $instance['twitterIntentsText'] ) ? $instance['twitterIntentsText'] : false;
146
+ $wpltf_wdgt_intentColor = $instance['intentColor'];
147
+ $wpltf_wdgt_showAvatar = isset( $instance['showAvatar'] ) ? $instance['showAvatar'] : false;
148
+ $wpltf_wdgt_border_rad = isset( $instance['border_rad'] ) ? $instance['border_rad'] : false;
149
+ $wpltf_wdgt_tewwt_border = isset( $instance['tweet_border'] ) ? $instance['tweet_border'] : 'false';
150
+ $wpltf_wdgt_tweet_theme = isset( $instance['tweet_theme'] ) ? $instance['tweet_theme'] : 'light';
151
+ if (!empty($wpltf_wdgt_title))
152
+ echo $before_title . $wpltf_wdgt_title . $after_title;
153
+ if($wpltf_wdgt_consumerKey=='' || $wpltf_wdgt_consumerSecret ==''|| $wpltf_wdgt_accessTokenSecret=='' || $wpltf_wdgt_accessToken=='' )
154
+ {
155
+ echo '<div class="isa_error">Bad Authentication data.<br/>Please enter valid API Keys.</div>';
156
+ }
157
+ else
158
+ {
159
+ $class='light';
160
+ if(isset($wpltf_wdgt_tweet_theme) && $wpltf_wdgt_tweet_theme=='dark')
161
+ $class='dark';
162
+ if(isset($wpltf_wdgt_tewwt_border) && $wpltf_wdgt_tewwt_border=='true')
163
+ {
164
+ echo '<style>
165
+ .fetched_tweets.light > li{border-color: rgb(238, 238, 238) rgb(221, 221, 221) rgb(187, 187, 187);
166
+ border-width: 1px;
167
+ border-style: solid;}
168
+ .fetched_tweets.dark > li{
169
+ border-color: #444;
170
+ border-width: 1px;
171
+ border-style: solid;}</style>';
172
+ }
173
+ ?> <ul class="fetched_tweets <?php echo $class;?>">
174
+ <?php
175
+
176
+ $tweets_count = $wpltf_wdgt_tweets_cnt;
177
+ $name = $wpltf_wdgt_name;
178
+ $timeto_store = $wpltf_wdgt_store_time;
179
+ $consumerSecret = trim($wpltf_wdgt_consumerSecret);
180
+ $accessToken = trim($wpltf_wdgt_accessToken);
181
+ $accessTokenSecret = trim($wpltf_wdgt_accessTokenSecret);
182
+ $replies_excl = $widget_replies_excl;
183
+ $consumerKey = trim($wpltf_wdgt_consumerKey);
184
+ //$dataShowCount = ($wpltf_wdgt_dataShowCount != "true") ? "false" : "true";
185
+ $disp_screen_name = ($wpltf_wdgt_disp_scr_name != "true") ? "false" : "true";
186
+ $intents_text = $wpltf_wdgt_twitterIntentsText;
187
+ $color_intents = $wpltf_wdgt_intentColor;
188
+ $cache_transient = $wpltf_wdgt_timeRef;
189
+ $alter_ago_time = $wpltf_wdgt_timeAgo;
190
+ $twitterIntents = $wpltf_wdgt_twitterIntents;
191
+ $showAvatar = $wpltf_wdgt_showAvatar;
192
+ $border_rad_avatar = $wpltf_wdgt_border_rad;
193
+ $transName = 'list-tweets-'.$name;
194
+ $backupName = $transName . '-backup';
195
+ if(false === ($tweets = get_transient($transName) ) ) :
196
+ require_once 'twitteroauth/twitteroauth.php';
197
+
198
+ $api_call = new TwitterOAuth(
199
+ $consumerKey,
200
+ $consumerSecret,
201
+ $accessToken,
202
+ $accessTokenSecret
203
+ );
204
+ $totalToFetch = ($replies_excl) ? max(50, $tweets_count * 3) : $tweets_count;
205
+
206
+ $fetchedTweets = $api_call->get(
207
+ 'statuses/user_timeline',
208
+ array(
209
+ 'screen_name' => $name,
210
+ 'count' => $totalToFetch,
211
+ 'replies_excl' => $replies_excl
212
+ )
213
+ );
214
+
215
+ if($api_call->http_code != 200) :
216
+ $tweets = get_option($backupName);
217
+
218
+ else :
219
+ $limitToDisplay = min($tweets_count, count($fetchedTweets));
220
+
221
+ for($i = 0; $i < $limitToDisplay; $i++) :
222
+ $tweet = $fetchedTweets[$i];
223
+ $name = $tweet->user->name;
224
+ $screen_name = $tweet->user->screen_name;
225
+ $permalink = 'http://twitter.com/'. $name .'/status/'. $tweet->id_str;
226
+ $tweet_id = $tweet->id_str;
227
+ $image = $tweet->user->profile_image_url;
228
+ $text = $this->sanitize_links($tweet);
229
+ $time = $tweet->created_at;
230
+ $time = date_parse($time);
231
+ $uTime = mktime($time['hour'], $time['minute'], $time['second'], $time['month'], $time['day'], $time['year']);
232
+ $tweets[] = array(
233
+ 'text' => $text,
234
+ 'scr_name'=>$screen_name,
235
+ 'favourite_count'=>$tweet->favorite_count,
236
+ 'retweet_count'=>$tweet->retweet_count,
237
+ 'name' => $name,
238
+ 'permalink' => $permalink,
239
+ 'image' => $image,
240
+ 'time' => $uTime,
241
+ 'tweet_id' => $tweet_id
242
+ );
243
+ endfor;
244
+ set_transient($transName, $tweets, 60 * $timeto_store);
245
+ update_option($backupName, $tweets);
246
+ endif;
247
+ endif;
248
+ if(!function_exists('twitter_time_diff'))
249
+ {
250
+ function twitter_time_diff( $from, $to = '' ) {
251
+ $diff = human_time_diff($from,$to);
252
+ $replace = array(
253
+ ' hour' => 'h',
254
+ ' hours' => 'h',
255
+ ' day' => 'd',
256
+ ' days' => 'd',
257
+ ' minute' => 'm',
258
+ ' minutes' => 'm',
259
+ ' second' => 's',
260
+ ' seconds' => 's',
261
+ );
262
+ return strtr($diff,$replace);
263
+ }
264
+ }
265
+ if($tweets) : ?>
266
+ <?php foreach($tweets as $t) : ?>
267
+ <li class="tweets_avatar">
268
+ <?php
269
+ echo '<div class="tweet_wrap"><div class="wdtf-user-card ltr">';
270
+ if ($showAvatar){
271
+
272
+ echo '<img ';
273
+ echo 'width="45px" height="45px"';
274
+ echo 'src="'.$t['image'].'" alt="Tweet Avatar" class="';
275
+ echo ($border_rad_avatar) ? 'circular':'';
276
+ echo '"/>';
277
+ }
278
+ if(!isset($screen_name)){$screen_name = $name;}
279
+
280
+ if($disp_screen_name!='false')
281
+ {
282
+ echo '<div class="wdtf-screen-name">';
283
+ echo "<span class=\"screen_name\">{$t['name']}</span><br>";
284
+ echo "<a href=\"https://twitter.com/{$screen_name}\" target=\"_blank\" dir=\"ltr\">@{$screen_name}</a></div>";
285
+
286
+ }
287
+ echo '<div class="clear"></div></div>';
288
+ ?>
289
+ <div class="tweet_data">
290
+ <?php echo $t['text']; ?>
291
+ </div>
292
+ <br/>
293
+ <div class="clear"></div>
294
+ <div class="times">
295
+ <em>
296
+
297
+ <a href="http://www.twitter.com/<?php echo $screen_name; ?>" target="_blank" title="Follow <?php echo $name; ?> on Twitter [Opens new window]">
298
+ <?php
299
+ if($cache_transient == "true"){
300
+ $timeDisplay = twitter_time_diff($t['time'], current_time('timestamp'));
301
+ }else{
302
+ $timeDisplay = human_time_diff($t['time'], current_time('timestamp'));
303
+ }
304
+ if($alter_ago_time == "true"){
305
+ $displayAgo = " ago";
306
+ }
307
+ printf(__('%1$s%2$s'), $timeDisplay, $displayAgo);
308
+
309
+ ?>
310
+ </a>
311
+ </em>
312
+ </div>
313
+ <?php if($twitterIntents == "true"){
314
+ ?>
315
+ <div class="tweets-intent-data">
316
+ <?php if($t['favourite_count']!=0 || $t['retweet_count']!=0){?>
317
+ <span class="stats-narrow customisable-border"><span class="stats" data-scribe="component:stats">
318
+ <?php if($t['retweet_count']!=0)
319
+ {?>
320
+ <a href="https://twitter.com/<?php echo $screen_name; ?>/statuses/<?php echo $t['tweet_id']; ?>" title="View Tweet on Twitter" data-scribe="element:favorite_count" target="_blank">
321
+ <span class="stats-favorites">
322
+ <strong><?php echo $t['retweet_count'];?></strong> retweet<?php if($t['retweet_count']>1)echo's';?>
323
+ </span>
324
+ </a>
325
+ <?php } ?>
326
+ <?php if($t['favourite_count']!=0)
327
+ {?>
328
+ <a href="https://twitter.com/<?php echo $screen_name; ?>/statuses/<?php echo $t['tweet_id']; ?>" title="View Tweet on Twitter" data-scribe="element:favorite_count" target="_blank">
329
+ <span class="stats-favorites">
330
+ <strong><?php echo $t['favourite_count'];?></strong> Favorite<?php if($t['favourite_count']>1)echo's';?>
331
+ </span>
332
+ </a>
333
+ <?php }?>
334
+
335
+ </span>
336
+ </span>
337
+ <div class="clear"></div>
338
+ <div class="seperator_wpltf"></div>
339
+ <?php }?>
340
+ <ul class="tweet-actions " role="menu" >
341
+ <li><a href="http://twitter.com/intent/tweet?in_reply_to=<?php echo $t['tweet_id']; ?>" data-lang="en" class="in-reply-to" title="Reply" target="_blank"><span aria-hidden="true" data-icon="&#xf079;" <?php echo ($color_intents) ? 'style="color:'.$color_intents.';"' :''; ?>></span></a></li>
342
+ <li><a href="http://twitter.com/intent/retweet?tweet_id=<?php echo $t['tweet_id']; ?>" data-lang="en" class="retweet" title="Retweet" target="_blank"><span aria-hidden="true" data-icon="&#xf112;" <?php echo ($color_intents) ? 'style="color:'.$color_intents.';"' :''; ?>></span></a></li>
343
+ <li><a href="http://twitter.com/intent/favorite?tweet_id=<?php echo $t['tweet_id']; ?>" data-lang="en" class="favorite" title="Favorite" target="_blank"><span aria-hidden="true" data-icon="&#xf005;" <?php echo ($color_intents) ? 'style="color:'.$color_intents.';"' :''; ?>></span></a></li>
344
+ </ul>
345
+ </div>
346
+ <?php } ?>
347
+ <div class="clear"></div>
348
+ </div><div class="clear"></div>
349
+ </li>
350
+ <?php endforeach; ?>
351
+
352
+ <?php else : ?>
353
+ <li>Waiting for twitter.com...Try reloading the page again </li>
354
+ <?php endif; ?>
355
+ </ul>
356
+ <?php
357
+ }
358
+ echo $after_widget;
359
+ }
360
+
361
+ }
362
+
363
+ ?>
controller/twitteroauth/twitteroauth.php CHANGED
@@ -1,162 +1,162 @@
1
- <?php
2
- require_once('OAuth.php');
3
-
4
- class TwitterOAuth {
5
-
6
- public $http_code;
7
- public $url;
8
- public $host = "https://api.twitter.com/1.1/";
9
- public $timeout = 30;
10
- public $connecttimeout = 30;
11
- public $ssl_verifypeer = FALSE;
12
- public $format = 'json';
13
- public $decode_json = TRUE;
14
- public $http_info;
15
- public $useragent = 'TwitterOAuth v0.2.0-beta2';
16
- function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; }
17
- function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; }
18
- function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; }
19
- function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
20
-
21
- function lastStatusCode() { return $this->http_status; }
22
- function lastAPICall() { return $this->last_awptt_widget_call; }
23
-
24
- function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
25
- $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
26
- $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
27
- if (!empty($oauth_token) && !empty($oauth_token_secret)) {
28
- $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
29
- } else {
30
- $this->token = NULL;
31
- }
32
- }
33
-
34
-
35
-
36
- function getRequestToken($oauth_callback) {
37
- $parameters = array();
38
- $parameters['oauth_callback'] = $oauth_callback;
39
- $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
40
- $token = OAuthUtil::parse_parameters($request);
41
- $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
42
- return $token;
43
- }
44
-
45
- function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
46
- if (is_array($token)) {
47
- $token = $token['oauth_token'];
48
- }
49
- if (empty($sign_in_with_twitter)) {
50
- return $this->authorizeURL() . "?oauth_token={$token}";
51
- } else {
52
- return $this->authenticateURL() . "?oauth_token={$token}";
53
- }
54
- }
55
-
56
-
57
- function getAccessToken($oauth_verifier) {
58
- $parameters = array();
59
- $parameters['oauth_verifier'] = $oauth_verifier;
60
- $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
61
- $token = OAuthUtil::parse_parameters($request);
62
- $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
63
- return $token;
64
- }
65
-
66
-
67
- function getXAuthToken($username, $password) {
68
- $parameters = array();
69
- $parameters['x_auth_username'] = $username;
70
- $parameters['x_auth_password'] = $password;
71
- $parameters['x_auth_mode'] = 'client_auth';
72
- $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
73
- $token = OAuthUtil::parse_parameters($request);
74
- $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
75
- return $token;
76
- }
77
-
78
- function get($url, $parameters = array()) {
79
- $response = $this->oAuthRequest($url, 'GET', $parameters);
80
- if ($this->format === 'json' && $this->decode_json) {
81
- return json_decode($response);
82
- }
83
- return $response;
84
- }
85
-
86
- function post($url, $parameters = array()) {
87
- $response = $this->oAuthRequest($url, 'POST', $parameters);
88
- if ($this->format === 'json' && $this->decode_json) {
89
- return json_decode($response);
90
- }
91
- return $response;
92
- }
93
-
94
- function delete($url, $parameters = array()) {
95
- $response = $this->oAuthRequest($url, 'DELETE', $parameters);
96
- if ($this->format === 'json' && $this->decode_json) {
97
- return json_decode($response);
98
- }
99
- return $response;
100
- }
101
-
102
-
103
- function oAuthRequest($url, $method, $parameters) {
104
- if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
105
- $url = "{$this->host}{$url}.{$this->format}";
106
- }
107
- $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
108
- $request->sign_request($this->sha1_method, $this->consumer, $this->token);
109
- switch ($method) {
110
- case 'GET':
111
- return $this->http($request->to_url(), 'GET');
112
- default:
113
- return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
114
- }
115
- }
116
-
117
- function http($url, $method, $postfields = NULL) {
118
- $this->http_info = array();
119
- $ci = curl_init();
120
-
121
- curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
122
- curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
123
- curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
124
- curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
125
- curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
126
- curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
127
- curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
128
- curl_setopt($ci, CURLOPT_HEADER, FALSE);
129
-
130
- switch ($method) {
131
- case 'POST':
132
- curl_setopt($ci, CURLOPT_POST, TRUE);
133
- if (!empty($postfields)) {
134
- curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
135
- }
136
- break;
137
- case 'DELETE':
138
- curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
139
- if (!empty($postfields)) {
140
- $url = "{$url}?{$postfields}";
141
- }
142
- }
143
-
144
- curl_setopt($ci, CURLOPT_URL, $url);
145
- $response = curl_exec($ci);
146
- $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
147
- $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
148
- $this->url = $url;
149
- curl_close ($ci);
150
- return $response;
151
- }
152
-
153
- function getHeader($ch, $header) {
154
- $i = strpos($header, ':');
155
- if (!empty($i)) {
156
- $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
157
- $value = trim(substr($header, $i + 2));
158
- $this->http_header[$key] = $value;
159
- }
160
- return strlen($header);
161
- }
162
- }
1
+ <?php
2
+ require_once('OAuth.php');
3
+
4
+ class TwitterOAuth {
5
+
6
+ public $http_code;
7
+ public $url;
8
+ public $host = "https://api.twitter.com/1.1/";
9
+ public $timeout = 30;
10
+ public $connecttimeout = 30;
11
+ public $ssl_verifypeer = FALSE;
12
+ public $format = 'json';
13
+ public $decode_json = TRUE;
14
+ public $http_info;
15
+ public $useragent = 'TwitterOAuth v0.2.0-beta2';
16
+ function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; }
17
+ function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; }
18
+ function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; }
19
+ function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
20
+
21
+ function lastStatusCode() { return $this->http_status; }
22
+ function lastAPICall() { return $this->last_awptt_widget_call; }
23
+
24
+ function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
25
+ $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
26
+ $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
27
+ if (!empty($oauth_token) && !empty($oauth_token_secret)) {
28
+ $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
29
+ } else {
30
+ $this->token = NULL;
31
+ }
32
+ }
33
+
34
+
35
+
36
+ function getRequestToken($oauth_callback) {
37
+ $parameters = array();
38
+ $parameters['oauth_callback'] = $oauth_callback;
39
+ $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
40
+ $token = OAuthUtil::parse_parameters($request);
41
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
42
+ return $token;
43
+ }
44
+
45
+ function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
46
+ if (is_array($token)) {
47
+ $token = $token['oauth_token'];
48
+ }
49
+ if (empty($sign_in_with_twitter)) {
50
+ return $this->authorizeURL() . "?oauth_token={$token}";
51
+ } else {
52
+ return $this->authenticateURL() . "?oauth_token={$token}";
53
+ }
54
+ }
55
+
56
+
57
+ function getAccessToken($oauth_verifier) {
58
+ $parameters = array();
59
+ $parameters['oauth_verifier'] = $oauth_verifier;
60
+ $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
61
+ $token = OAuthUtil::parse_parameters($request);
62
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
63
+ return $token;
64
+ }
65
+
66
+
67
+ function getXAuthToken($username, $password) {
68
+ $parameters = array();
69
+ $parameters['x_auth_username'] = $username;
70
+ $parameters['x_auth_password'] = $password;
71
+ $parameters['x_auth_mode'] = 'client_auth';
72
+ $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
73
+ $token = OAuthUtil::parse_parameters($request);
74
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
75
+ return $token;
76
+ }
77
+
78
+ function get($url, $parameters = array()) {
79
+ $response = $this->oAuthRequest($url, 'GET', $parameters);
80
+ if ($this->format === 'json' && $this->decode_json) {
81
+ return json_decode($response);
82
+ }
83
+ return $response;
84
+ }
85
+
86
+ function post($url, $parameters = array()) {
87
+ $response = $this->oAuthRequest($url, 'POST', $parameters);
88
+ if ($this->format === 'json' && $this->decode_json) {
89
+ return json_decode($response);
90
+ }
91
+ return $response;
92
+ }
93
+
94
+ function delete($url, $parameters = array()) {
95
+ $response = $this->oAuthRequest($url, 'DELETE', $parameters);
96
+ if ($this->format === 'json' && $this->decode_json) {
97
+ return json_decode($response);
98
+ }
99
+ return $response;
100
+ }
101
+
102
+
103
+ function oAuthRequest($url, $method, $parameters) {
104
+ if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
105
+ $url = "{$this->host}{$url}.{$this->format}";
106
+ }
107
+ $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
108
+ $request->sign_request($this->sha1_method, $this->consumer, $this->token);
109
+ switch ($method) {
110
+ case 'GET':
111
+ return $this->http($request->to_url(), 'GET');
112
+ default:
113
+ return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
114
+ }
115
+ }
116
+
117
+ function http($url, $method, $postfields = NULL) {
118
+ $this->http_info = array();
119
+ $ci = curl_init();
120
+
121
+ curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
122
+ curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
123
+ curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
124
+ curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
125
+ curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
126
+ curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
127
+ curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
128
+ curl_setopt($ci, CURLOPT_HEADER, FALSE);
129
+
130
+ switch ($method) {
131
+ case 'POST':
132
+ curl_setopt($ci, CURLOPT_POST, TRUE);
133
+ if (!empty($postfields)) {
134
+ curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
135
+ }
136
+ break;
137
+ case 'DELETE':
138
+ curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
139
+ if (!empty($postfields)) {
140
+ $url = "{$url}?{$postfields}";
141
+ }
142
+ }
143
+
144
+ curl_setopt($ci, CURLOPT_URL, $url);
145
+ $response = curl_exec($ci);
146
+ $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
147
+ $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
148
+ $this->url = $url;
149
+ curl_close ($ci);
150
+ return $response;
151
+ }
152
+
153
+ function getHeader($ch, $header) {
154
+ $i = strpos($header, ':');
155
+ if (!empty($i)) {
156
+ $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
157
+ $value = trim(substr($header, $i + 2));
158
+ $this->http_header[$key] = $value;
159
+ }
160
+ return strlen($header);
161
+ }
162
+ }
wp-latest-twitter-tweets.php CHANGED
@@ -1,34 +1,43 @@
1
- <?php
2
- /*
3
- Plugin Name: WP Twitter Feeds
4
- Plugin URI: http://www.vivacityinfotech.net/
5
- Description: Displays latest tweets from your Twitter account using Twitter oAuth API 1.1.
6
- Author: vivacityinfotech
7
- Version: 1.3
8
  Author URI: http://www.vivacityinfotech.net/
9
 
10
- Copyright 2014 Vivacity InfoTech Pvt. Ltd. (email : support@vivacityinfotech.com)
11
-
12
- This program is free software; you can redistribute it and/or modify
13
- it under the terms of the GNU General Public License, version 2, as
14
- published by the Free Software Foundation.
15
-
16
- This program is distributed in the hope that it will be useful,
17
- but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- GNU General Public License for more details.
20
-
21
- You should have received a copy of the GNU General Public License
22
- along with this program; if not, write to the Free Software
23
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
-
25
- */
26
- include('twitter_usr_validation.php');
27
- require_once('controller/twitter_widget.class.php');
28
- add_action( 'widgets_init', 'wpltf_reg_widget');
29
- function wpltf_reg_widget()
30
- {
31
-
32
- register_widget("wptt_TwitterTweets");
33
- }
34
- ?>
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP Twitter Feeds
4
+ Plugin URI: http://www.vivacityinfotech.net/
5
+ Description: Displays latest tweets from your Twitter account using Twitter oAuth API 1.1.
6
+ Author: Vivacity Infotech Pvt. Ltd.
7
+ Version: 1.4
8
  Author URI: http://www.vivacityinfotech.net/
9
 
10
+ Copyright 2014 Vivacity InfoTech Pvt. Ltd. (email : support@vivacityinfotech.com)
11
+
12
+ This program is free software; you can redistribute it and/or modify
13
+ it under the terms of the GNU General Public License, version 2, as
14
+ published by the Free Software Foundation.
15
+
16
+ This program is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program; if not, write to the Free Software
23
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
+
25
+ */
26
+ include('twitter_usr_validation.php');
27
+ require_once('controller/twitter_widget.class.php');
28
+ add_action( 'widgets_init', 'wpltf_reg_widget');
29
+ function wpltf_reg_widget()
30
+ {
31
+
32
+ register_widget("wptt_TwitterTweets");
33
+ }
34
+
35
+ add_filter('plugin_row_meta', 'add_meta_links',10, 2);
36
+ function add_meta_links($links, $file) {
37
+ if ( strpos( $file, 'wp-latest-twitter-tweets.php' ) !== false ) {
38
+ $links[] = '<a href="http://wordpress.org/support/plugin/wp-twitter-feeds">Support</a>';
39
+ $links[] = '<a href="http://bit.ly/1icl56K">Donate</a>';
40
+ }
41
+ return $links;
42
+ }
43
+ ?>