Version Description
- [Enhanced] Widget Admin Javascript - Enhanced user experience while completing settings and options
- [Updated] Optimised widget admin javascript and cleaned
- [Added] Div for follow button alignment control - Props Brian Henry
- [Added] Permalink screen name, prevent issues with spaces - thx to Brian
- [Added] Link widget title to Twitter account.Widget admin option added for control - thx to Brian
- [Added] Span to mimic line break and emphasis using CSS, cleaner - thx again Brian
Download this release
Release Info
Developer | Planet Interactive |
Plugin | Simple Twitter Tweets |
Version | 4.1 |
Comparing to | |
See all releases |
Code changes from version 4.0 to 4.1
- README.txt +10 -2
- css/stt.css +5 -0
- css/stt.min.css +1 -1
- js/sttAdmin.js +28 -13
- js/sttAdmin.min.js +6 -6
- simple-twitter-tweets.php +14 -4
- trunk/README.txt +212 -0
- trunk/css/fonts/stt-intents.dev.svg +25 -0
- trunk/css/fonts/stt-intents.eot +0 -0
- trunk/css/fonts/stt-intents.svg +25 -0
- trunk/css/fonts/stt-intents.ttf +0 -0
- trunk/css/fonts/stt-intents.woff +0 -0
- trunk/css/stt.css +63 -0
- trunk/css/stt.min.css +5 -0
- trunk/js/sttAdmin.js +74 -0
- trunk/js/sttAdmin.min.js +6 -0
- trunk/libs/console.php +82 -0
- trunk/simple-twitter-tweets.php +621 -0
- trunk/twitteroauth/OAuth.php +874 -0
- trunk/twitteroauth/twitteroauth.php +241 -0
README.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: Planet Interactive
|
|
3 |
Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A9437VN7R36VN
|
4 |
Tags: Twitter, Stream, Tweets, Twitter OAuth, social
|
5 |
Requires at least: 3.0
|
6 |
-
Tested up to: 4.3
|
7 |
-
Stable tag: 4.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -129,6 +129,14 @@ We've tested it and as far as we know it works great! Phew, but if you have an i
|
|
129 |
9. Style how you like, "Your Tweets your way"
|
130 |
|
131 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
= 4.0 =
|
133 |
* [Added] Multiple Widget ready - you can now use multiple versions in widget ready areas as requested
|
134 |
* [Added] Internationalisation (i18n) - Ready for impending WP [theme and plugin] Language packs. All interface text marked up ready for translations
|
3 |
Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A9437VN7R36VN
|
4 |
Tags: Twitter, Stream, Tweets, Twitter OAuth, social
|
5 |
Requires at least: 3.0
|
6 |
+
Tested up to: 4.3.1
|
7 |
+
Stable tag: 4.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
129 |
9. Style how you like, "Your Tweets your way"
|
130 |
|
131 |
== Changelog ==
|
132 |
+
= 4.1 =
|
133 |
+
* [Enhanced] Widget Admin Javascript - Enhanced user experience while completing settings and options
|
134 |
+
* [Updated] Optimised widget admin javascript and cleaned
|
135 |
+
* [Added] Div for follow button alignment control - Props Brian Henry
|
136 |
+
* [Added] Permalink screen name, prevent issues with spaces - thx to Brian
|
137 |
+
* [Added] Link widget title to Twitter account.Widget admin option added for control - thx to Brian
|
138 |
+
* [Added] Span to mimic line break and emphasis using CSS, cleaner - thx again Brian
|
139 |
+
|
140 |
= 4.0 =
|
141 |
* [Added] Multiple Widget ready - you can now use multiple versions in widget ready areas as requested
|
142 |
* [Added] Internationalisation (i18n) - Ready for impending WP [theme and plugin] Language packs. All interface text marked up ready for translations
|
css/stt.css
CHANGED
@@ -55,4 +55,9 @@
|
|
55 |
padding: 0;
|
56 |
position: absolute;
|
57 |
width: 1px;
|
|
|
|
|
|
|
|
|
|
|
58 |
}
|
55 |
padding: 0;
|
56 |
position: absolute;
|
57 |
width: 1px;
|
58 |
+
}
|
59 |
+
/* replacing <br/><em> with CSS class */
|
60 |
+
.stt-em {
|
61 |
+
font-style: italic;
|
62 |
+
display: block;
|
63 |
}
|
css/stt.min.css
CHANGED
@@ -2,4 +2,4 @@
|
|
2 |
.tweets li>a{-ms-word-break:break-all;word-break:break-all;word-break:break-word;-webkit-hyphens:auto;-moz-hyphens:auto;hyphens:auto}.avatar{margin-left:53px}
|
3 |
.avatar img{float:left;margin-left:-53px}.a-corn{-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.intent-meta{margin-top:5px}.intent-meta a{margin-right:5px}
|
4 |
[data-icon]:before{font-family:'stt-intents';content:attr(data-icon);speak:none;font-weight:normal;font-variant:normal;font-size:14px;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}
|
5 |
-
.pi-visuallyhidden{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}
|
2 |
.tweets li>a{-ms-word-break:break-all;word-break:break-all;word-break:break-word;-webkit-hyphens:auto;-moz-hyphens:auto;hyphens:auto}.avatar{margin-left:53px}
|
3 |
.avatar img{float:left;margin-left:-53px}.a-corn{-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.intent-meta{margin-top:5px}.intent-meta a{margin-right:5px}
|
4 |
[data-icon]:before{font-family:'stt-intents';content:attr(data-icon);speak:none;font-weight:normal;font-variant:normal;font-size:14px;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}
|
5 |
+
.pi-visuallyhidden{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.stt-em{font-style:italic;display:block}
|
js/sttAdmin.js
CHANGED
@@ -13,9 +13,9 @@ jQuery(document).ready(function($) {
|
|
13 |
// or in the data-default-color attribute on the input
|
14 |
defaultColor: false,
|
15 |
// a callback to fire whenever the color changes to a valid color
|
16 |
-
|
17 |
// a callback to fire when the input is emptied or an invalid color
|
18 |
-
|
19 |
// hide the color picker controls on load
|
20 |
hide: true,
|
21 |
// show a group of common colors beneath the square
|
@@ -29,31 +29,46 @@ jQuery(document).ready(function($) {
|
|
29 |
}
|
30 |
}
|
31 |
updateColorPicker();
|
32 |
-
// Widget Button reveals
|
33 |
-
$('.secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div').hide();
|
34 |
|
|
|
|
|
|
|
35 |
$(document).on('click', '.secrets h4, .avatar h4, .twitterFollow h4, .modTime h4, .twitterIntents h4', function() {
|
36 |
// var tFollow = $(this).next('div');
|
|
|
37 |
$(this).next('div').slideToggle('fast', function() {
|
38 |
if(!$(this).is(':hidden')) {
|
39 |
$(this).siblings('h4').children('span').html('▲');
|
40 |
}else{
|
|
|
41 |
$(this).siblings('h4').children('span').html('▼');
|
42 |
}
|
43 |
});
|
44 |
});
|
45 |
|
46 |
-
// Widget Saved
|
47 |
-
$(document).ajaxSuccess(function(e, xhr, settings) {
|
48 |
-
// reset toggles - clean view
|
49 |
-
$('.secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div').slideUp();
|
50 |
-
$('.secrets h4 > span, .avatar h4 > span, .twitterFollow h4 > span, .modTime h4 > span, .twitterIntents h4 > span').html('▼');
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
}); // END AJAX success
|
58 |
|
|
|
59 |
}); // END READY
|
13 |
// or in the data-default-color attribute on the input
|
14 |
defaultColor: false,
|
15 |
// a callback to fire whenever the color changes to a valid color
|
16 |
+
// change: function(event, ui){},
|
17 |
// a callback to fire when the input is emptied or an invalid color
|
18 |
+
// clear: function() {},
|
19 |
// hide the color picker controls on load
|
20 |
hide: true,
|
21 |
// show a group of common colors beneath the square
|
29 |
}
|
30 |
}
|
31 |
updateColorPicker();
|
|
|
|
|
32 |
|
33 |
+
// Widget Button reveals - close onLoad
|
34 |
+
// $('.secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div').hide();
|
35 |
+
// Reveal/Hide onClick and change arrow direction
|
36 |
$(document).on('click', '.secrets h4, .avatar h4, .twitterFollow h4, .modTime h4, .twitterIntents h4', function() {
|
37 |
// var tFollow = $(this).next('div');
|
38 |
+
$(this).next('div').addClass('open');
|
39 |
$(this).next('div').slideToggle('fast', function() {
|
40 |
if(!$(this).is(':hidden')) {
|
41 |
$(this).siblings('h4').children('span').html('▲');
|
42 |
}else{
|
43 |
+
$(this).removeClass('open');
|
44 |
$(this).siblings('h4').children('span').html('▼');
|
45 |
}
|
46 |
});
|
47 |
});
|
48 |
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
function savedIt(e, xhr, settings){
|
51 |
+
// settings.data.search('action=save-widget') != -1
|
52 |
+
|
53 |
+
if( $('.secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div').hasClass('open') ){
|
54 |
+
// Do nothing
|
55 |
+
}else{
|
56 |
+
// reset toggles - clean view
|
57 |
+
// $('.secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div').slideUp();
|
58 |
+
$('.secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div').hide();
|
59 |
+
$('.secrets h4 > span, .avatar h4 > span, .twitterFollow h4 > span, .modTime h4 > span, .twitterIntents h4 > span').html('▼');
|
60 |
}
|
61 |
+
|
62 |
+
|
63 |
+
// re-initiate the colour picker
|
64 |
+
$('.intentColor .wp-picker-container').remove();
|
65 |
+
updateColorPicker();
|
66 |
+
}
|
67 |
+
|
68 |
+
// // Widget - Auto Ajax Saved
|
69 |
+
$(document).ajaxSuccess(function(e, xhr, settings) {
|
70 |
+
savedIt(e, xhr, settings);
|
71 |
}); // END AJAX success
|
72 |
|
73 |
+
|
74 |
}); // END READY
|
js/sttAdmin.min.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
jQuery(document).ready(function(a){function b(){if(typeof jQuery.wp==="object"&&typeof jQuery.wp.wpColorPicker==="function"){var
|
2 |
-
jQuery(".intentColor").wpColorPicker(
|
3 |
-
a(
|
4 |
-
|
5 |
-
a(".secrets h4 > span, .avatar h4 > span, .twitterFollow h4 > span, .modTime h4 > span, .twitterIntents h4 > span").html("▼");
|
6 |
-
b();}});});
|
1 |
+
jQuery(document).ready(function(a){function b(){if(typeof jQuery.wp==="object"&&typeof jQuery.wp.wpColorPicker==="function"){var d={defaultColor:false,hide:true,palettes:true};
|
2 |
+
jQuery(".intentColor").wpColorPicker(d);}else{jQuery("#colorpicker").farbtastic("intentColor");}}b();a(document).on("click",".secrets h4, .avatar h4, .twitterFollow h4, .modTime h4, .twitterIntents h4",function(){a(this).next("div").addClass("open");
|
3 |
+
a(this).next("div").slideToggle("fast",function(){if(!a(this).is(":hidden")){a(this).siblings("h4").children("span").html("▲");}else{a(this).removeClass("open");
|
4 |
+
a(this).siblings("h4").children("span").html("▼");}});});function c(f,g,d){if(a(".secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div").hasClass("open")){}else{a(".secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div").hide();
|
5 |
+
a(".secrets h4 > span, .avatar h4 > span, .twitterFollow h4 > span, .modTime h4 > span, .twitterIntents h4 > span").html("▼");}a(".intentColor .wp-picker-container").remove();
|
6 |
+
b();}a(document).ajaxSuccess(function(f,g,d){c(f,g,d);});});
|
simple-twitter-tweets.php
CHANGED
@@ -184,6 +184,12 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
184 |
<p>
|
185 |
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label>
|
186 |
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
<p>
|
188 |
<label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Twitter Name (without @ symbol):', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" type="text" value="<?php echo esc_attr($name); ?>" /></label>
|
189 |
</p>
|
@@ -302,6 +308,7 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
302 |
|
303 |
//Strip tags from title and name to remove HTML
|
304 |
$instance['title'] = strip_tags( $new_instance['title'] );
|
|
|
305 |
$instance['name'] = strip_tags( $new_instance['name'] );
|
306 |
$instance['numTweets'] = $new_instance['numTweets'];
|
307 |
$instance['cacheTime'] = $new_instance['cacheTime'];
|
@@ -335,6 +342,9 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
335 |
|
336 |
//Our variables from the widget settings.
|
337 |
$PI_title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
|
|
|
|
|
|
|
338 |
$PI_name = $instance['name'];
|
339 |
$PI_numTweets = $instance['numTweets'];
|
340 |
$PI_cacheTime = $instance['cacheTime'];
|
@@ -460,7 +470,7 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
460 |
// COMMUNITY REQUEST !!!!!! (2)
|
461 |
$screen_name = $tweet->user->screen_name;
|
462 |
|
463 |
-
$permalink = 'http://twitter.com/'. $
|
464 |
$tweet_id = $tweet->id_str;
|
465 |
|
466 |
/* Alternative image sizes method: http://dev.twitter.com/doc/get/users/profile_image/:screen_name */
|
@@ -539,7 +549,7 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
539 |
}
|
540 |
?>
|
541 |
<?php echo $t['text']; ?>
|
542 |
-
<
|
543 |
<?php if(!isset($screen_name)){ $screen_name = $name; }?>
|
544 |
<a href="http://www.twitter.com/<?php echo $screen_name; ?>" target="_blank" title="<?php
|
545 |
printf(
|
@@ -568,7 +578,7 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
568 |
|
569 |
?>
|
570 |
</a>
|
571 |
-
</
|
572 |
|
573 |
<?php // INTENTS REF: DISPLAY OR NOT
|
574 |
if($twitterIntents == "true"){
|
@@ -598,7 +608,7 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
598 |
// ADD Twitter follow button - to increase engagement
|
599 |
// Make it an options choice though
|
600 |
if($twitterFollow){ ?>
|
601 |
-
<a href="https://twitter.com/<?php echo $PI_name; ?>" class="twitter-follow-button" data-show-count="<?php echo $dataShowCount; ?>" data-show-screen-name="<?php echo $dataShowScreenName; ?>" data-lang="<?php echo $dataLang; ?>"><?php _e('Follow','simple-twitter-tweets'); ?> @<?php echo $PI_name; ?></a>
|
602 |
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
|
603 |
<?php
|
604 |
}
|
184 |
<p>
|
185 |
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label>
|
186 |
</p>
|
187 |
+
<p>
|
188 |
+
<label for="<?php echo $this->get_field_id("titleLink"); ?>">
|
189 |
+
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("titleLink"); ?>" name="<?php echo $this->get_field_name("titleLink"); ?>"<?php checked( (bool) $instance["titleLink"], true ); ?> />
|
190 |
+
<?php _e( 'Make widget title link' ); ?>
|
191 |
+
</label>
|
192 |
+
</p>
|
193 |
<p>
|
194 |
<label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Twitter Name (without @ symbol):', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" type="text" value="<?php echo esc_attr($name); ?>" /></label>
|
195 |
</p>
|
308 |
|
309 |
//Strip tags from title and name to remove HTML
|
310 |
$instance['title'] = strip_tags( $new_instance['title'] );
|
311 |
+
$instance['titleLink'] = $new_instance['titleLink'];
|
312 |
$instance['name'] = strip_tags( $new_instance['name'] );
|
313 |
$instance['numTweets'] = $new_instance['numTweets'];
|
314 |
$instance['cacheTime'] = $new_instance['cacheTime'];
|
342 |
|
343 |
//Our variables from the widget settings.
|
344 |
$PI_title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
|
345 |
+
if( isset($instance['titleLink']) && $instance['titleLink'] == true){
|
346 |
+
$PI_title = '<a target="_blank" href="https://twitter.com/'.$instance['name'].'">'.$PI_title.'</a>';
|
347 |
+
}
|
348 |
$PI_name = $instance['name'];
|
349 |
$PI_numTweets = $instance['numTweets'];
|
350 |
$PI_cacheTime = $instance['cacheTime'];
|
470 |
// COMMUNITY REQUEST !!!!!! (2)
|
471 |
$screen_name = $tweet->user->screen_name;
|
472 |
|
473 |
+
$permalink = 'http://twitter.com/'. $screen_name .'/status/'. $tweet->id_str;
|
474 |
$tweet_id = $tweet->id_str;
|
475 |
|
476 |
/* Alternative image sizes method: http://dev.twitter.com/doc/get/users/profile_image/:screen_name */
|
549 |
}
|
550 |
?>
|
551 |
<?php echo $t['text']; ?>
|
552 |
+
<span class="stt-em">
|
553 |
<?php if(!isset($screen_name)){ $screen_name = $name; }?>
|
554 |
<a href="http://www.twitter.com/<?php echo $screen_name; ?>" target="_blank" title="<?php
|
555 |
printf(
|
578 |
|
579 |
?>
|
580 |
</a>
|
581 |
+
</span>
|
582 |
|
583 |
<?php // INTENTS REF: DISPLAY OR NOT
|
584 |
if($twitterIntents == "true"){
|
608 |
// ADD Twitter follow button - to increase engagement
|
609 |
// Make it an options choice though
|
610 |
if($twitterFollow){ ?>
|
611 |
+
<div class="twitter-follow-container"><a href="https://twitter.com/<?php echo $PI_name; ?>" class="twitter-follow-button" data-show-count="<?php echo $dataShowCount; ?>" data-show-screen-name="<?php echo $dataShowScreenName; ?>" data-lang="<?php echo $dataLang; ?>"><?php _e('Follow','simple-twitter-tweets'); ?> @<?php echo $PI_name; ?></a></div>
|
612 |
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
|
613 |
<?php
|
614 |
}
|
trunk/README.txt
ADDED
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Plugin Name ===
|
2 |
+
Contributors: Planet Interactive
|
3 |
+
Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A9437VN7R36VN
|
4 |
+
Tags: Twitter, Stream, Tweets, Twitter OAuth, social
|
5 |
+
Requires at least: 3.0
|
6 |
+
Tested up to: 4.3.1
|
7 |
+
Stable tag: 4.1
|
8 |
+
License: GPLv2 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
|
11 |
+
Simple Twitter Tweets - Display your Tweets on your Wordpress site using the new Twitter OAuth API v1.1. (even when you can't connect) Because they're backed up!
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
A Simple Twitter Tweets display widget, using Twitter OAth and API v1.1 and backup up so it always displays your Tweets.
|
16 |
+
|
17 |
+
**Why?**
|
18 |
+
|
19 |
+
Our clients, especially on shared hosting were having issues with the Twitter API not displaying their tweets, too many connections from the same source (host). We solved that issue, then lo and behold Twitter changed their API so displaying your own Tweets required OAuth authentication and finally we buckled and decided to roll our own so it would be simple for them, for us and for you.
|
20 |
+
|
21 |
+
Twitter changed their API again. Removing version 1.0 of the API altogether and by forcing version 1.1 of the API and use of the OAuth authentication requirement. We wrote this plugin so everyone could have it at a click of a button.
|
22 |
+
|
23 |
+
There are a few Twitter plugins out their, but we couldn't find one simple enough, or that worked (to be honest) and so the Simple Twitter Tweets plugin was born.
|
24 |
+
|
25 |
+
Twitter users who want to display their Tweets on their website (or within an application) have to create a Twitter Application to get access to the required "Keys" and "Tokens" Twitter provides for Authentication. The instructions for this are provided below so you can be up and running with Tweets on your site in less time than it takes to make a cup of Tea.
|
26 |
+
|
27 |
+
= Features =
|
28 |
+
|
29 |
+
* Simple setup
|
30 |
+
* Twitter API v1.1 compliant (OAuth Ready)
|
31 |
+
* No passwords required or used
|
32 |
+
* Works even when Twitters down, over capacity or not connecting
|
33 |
+
* Tweets stored in the database with each call, so if your call to the Twitter API fails for whatever reason there won't be a blank space or Oops message on your site, you'll just see the last set of Tweets the system stored - sweet huh.
|
34 |
+
* Tweeted when? - In Human Time using minutes, hours and days (i.e. 5 hours ago) or using Twitter time display (i.e. 5h)
|
35 |
+
* Twitter intents - increase social interaction with users ability to Reply, Retweet and Favourite your tweets right from you page
|
36 |
+
* Twitter intents using bespoke (only three characters) icon font (tiny) and colour the icons right in the widget
|
37 |
+
* Did we say it was simple and works...
|
38 |
+
|
39 |
+
== Installation ==
|
40 |
+
|
41 |
+
Installation is as simple as 1,2,3 or maybe 4 because of Twitter :)
|
42 |
+
|
43 |
+
1. Upload 'simple-twitter-tweets' to the '/wp-content/plugins/' directory
|
44 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
45 |
+
3. Add the Widget to your page (e.g. Sidebar) and update the required details
|
46 |
+
4. Click Save
|
47 |
+
5. Note: You will need to create a Twitter Application - See below. Oh, it's really easy.
|
48 |
+
|
49 |
+
= Creating a Twitter Application =
|
50 |
+
|
51 |
+
The Twitter Widget will never ask for your password, as it gets all your required data from the Open Authentication keys and secrets you will get by creating your application at Twitter. It also means that if you change your password, you won’t need to update any of the details of your Widget.
|
52 |
+
|
53 |
+
To find these details, go to https://apps.twitter.com/ and sign in.
|
54 |
+
|
55 |
+
Center of the screen click "Create a New Application."
|
56 |
+
|
57 |
+
Enter a unique name (anything you want), a description (again this is just for you), and your site's URL. You can leave the Callback URL empty as it is not used for this implementation.
|
58 |
+
|
59 |
+
Yay, success - OK! You will be taken to a new screen, there's one more step then you can copy all the details into correct fields of the Widget and be on your way.
|
60 |
+
|
61 |
+
OK, click the "Create my Access Token" button. This is a shortcut to authenticate your own account with your application (so you never need use your password).
|
62 |
+
|
63 |
+
Good. Now click the Details Tab as all the information you need is presented hereso you can just copy the required information into the exact corresponding inputs fields of the Widget.
|
64 |
+
|
65 |
+
Full details and screenshots of this process can seen on the [Simple Twitter Tweets page](http://www.planet-interactive.co.uk/simple-twitter-tweets "Simple Twitter Tweets page by Planet Interactive")
|
66 |
+
|
67 |
+
= The Widget Options =
|
68 |
+
|
69 |
+
Fill in your details, copy and past the Twitter Application details (as described below).
|
70 |
+
|
71 |
+
* You can select the Title of the Widget as you like.
|
72 |
+
* Enter your Twitter username (without the @) just the name.
|
73 |
+
* How many Tweets to display
|
74 |
+
* The time in minutes between updates (per the API requirement) this should be 5 but if the API changes you can alter it here.
|
75 |
+
* Consumer Key: Under the *OAuth settings* heading
|
76 |
+
* Consumer Secret: Under the *OAuth settings* heading
|
77 |
+
* Access Token: Under the *Your access token* heading
|
78 |
+
* Access Token Secret: Under the *Your access token* heading
|
79 |
+
* Choose if you want the @replies included or not
|
80 |
+
* Avatar: Your image or logo as displayed on Twitter – show on/off
|
81 |
+
* Avatar: Round the corners to your image (5px on modern browsers)
|
82 |
+
* Avatar: Set the size - defaults to the Twitter default of 48px
|
83 |
+
* Time Display: Default is WP human time (i.e. 5 hours ago)
|
84 |
+
* Time Display: New option – if set, Twitter time (i.e. 5h)
|
85 |
+
* Time Display: Choose to display the 'ago' or not
|
86 |
+
* Twitter Intents: Show Twitter intents for 'Reply', 'Retweet' and 'Favourite'
|
87 |
+
* Twitter Intents: Option to hide the Text and just use icons
|
88 |
+
* Twitter Intents: Colourise the icons to your display
|
89 |
+
* Twitter Follow: Choose to Show the Twitter Follow button
|
90 |
+
* Twitter Follow: Choose to show your Twitter name
|
91 |
+
* Twitter Follow: Choose to show your follower count
|
92 |
+
* Twitter Follow: Enforce your language (defaults to en [English])
|
93 |
+
* Click Save
|
94 |
+
|
95 |
+
Enjoy!
|
96 |
+
|
97 |
+
== Frequently Asked Questions ==
|
98 |
+
|
99 |
+
= Can I change the look and feel of the Tweets =
|
100 |
+
|
101 |
+
Of course you can. It's really simple too.
|
102 |
+
|
103 |
+
The Tweets are in a widget as with all widgets, and are a simple unordered list.
|
104 |
+
|
105 |
+
* To make styling easier the <ul> has a class of Tweets - <ul class="tweets">
|
106 |
+
* Each Tweet is a list item <li>
|
107 |
+
* Each Time reference is an emphasised link <em><a>
|
108 |
+
* Inside the <li> we now have (if you choose to diplay it) the avatar image
|
109 |
+
* Inside the <li> we also have (if you choose to diplay them) the Twitter intents. These are are in a DIV with a class of 'intent-meta' – in case you want to control its placement or spacing further. Each Intent is a link containing a 'span' for icon (using icon fonts for speed and styling flexibility) and another span for the text
|
110 |
+
* Done.
|
111 |
+
|
112 |
+
= Where can I get help =
|
113 |
+
|
114 |
+
If you're really stuck use the Wordpress Support Forum or check out the [support portal](http://planetinteractive.freshdesk.com/support/login "Support by Planet Interactive")
|
115 |
+
|
116 |
+
= More FAQs =
|
117 |
+
We've tested it and as far as we know it works great! Phew, but if you have an issue or you want to propose some functionality then submit you ideas at the [support portal](http://planetinteractive.freshdesk.com/support/login "Support by Planet Interactive") and we'll update these FAQs and get onto it when we can.
|
118 |
+
|
119 |
+
== Screenshots ==
|
120 |
+
|
121 |
+
1. Go to https://apps.twitter.com and Sign In
|
122 |
+
2. Create a new Application
|
123 |
+
3. Fill a name for your App, a description (this is for you) and your website address (URL)
|
124 |
+
4. Click "Create my access token"
|
125 |
+
5. If you've already installed in the "Simple Twitter Tweets" plugin go to Appearance->Widgets (otherwise install it first then go here)
|
126 |
+
6. Drag the "Simple Twitter Tweets" widget your widget area of choice
|
127 |
+
7. Fill in the widget options and correlating Twitter Application OAuth requirements, just copy and paste
|
128 |
+
8. New options for "Twitter Follow Button" and what elements to display
|
129 |
+
9. Style how you like, "Your Tweets your way"
|
130 |
+
|
131 |
+
== Changelog ==
|
132 |
+
= 4.1 =
|
133 |
+
* [Enhanced] Widget Admin Javascript - Enhanced user experience while completing settings and options
|
134 |
+
* [Updated] Optimised widget admin javascript and cleaned
|
135 |
+
* [Added] Div for follow button alignment control - Props Brian Henry
|
136 |
+
* [Added] Permalink screen name, prevent issues with spaces - thx to Brian
|
137 |
+
* [Added] Link widget title to Twitter account.Widget admin option added for control - thx to Brian
|
138 |
+
* [Added] Span to mimic line break and emphasis using CSS, cleaner - thx again Brian
|
139 |
+
|
140 |
+
= 4.0 =
|
141 |
+
* [Added] Multiple Widget ready - you can now use multiple versions in widget ready areas as requested
|
142 |
+
* [Added] Internationalisation (i18n) - Ready for impending WP [theme and plugin] Language packs. All interface text marked up ready for translations
|
143 |
+
* [Fixed] Redeclared Function Error Fixed
|
144 |
+
|
145 |
+
= 3.3 =
|
146 |
+
* [Fixed] PHP deprecated functions (notice) added PHP 5 construction references
|
147 |
+
|
148 |
+
= 3.2 =
|
149 |
+
* [Added] SSL reference for avatar (profile pic) images for secure pages
|
150 |
+
* [Added] Check for data retrieval, handles foreach warning (bullet proof old bug)
|
151 |
+
* [Added] Defined 'ago' so when not used handles warning
|
152 |
+
* [Added] Clean inputs no whitespace issue
|
153 |
+
* [Updated] URL for Twitter apps creation updated (as it was moved)
|
154 |
+
|
155 |
+
= 3.1 =
|
156 |
+
* [Fixed] Serialization error fixed - changed base_64 fix for 4-byte emoji strip
|
157 |
+
|
158 |
+
= 3.0 =
|
159 |
+
* [Fixed] Class conflict error - check for use before including
|
160 |
+
* [Fixed] Emoji error (presented as for each error) 4-byte emoji issue
|
161 |
+
* [Fixed] Word break (letter break on certain browsers) - moved so break on links only to ensure long URLs don't break display
|
162 |
+
|
163 |
+
= 2.1 =
|
164 |
+
* [Updated] Intents was on by default before selected (but not saved) - now off on initialisation and user selection to turn on required
|
165 |
+
* [Fixed] Show Avatar was maintaining indent of tweets when turned off after having been set. Now checks for Avatar on flag not just size change.
|
166 |
+
|
167 |
+
= 2.0 =
|
168 |
+
* [Added] Twitter Avatar, display, controls, presentation, styling and more
|
169 |
+
* [Added] Time display formating and options
|
170 |
+
* [Added] Twitter Intents, plus display styling and options
|
171 |
+
* [Updated] Time reference i18n (localisation) compliance
|
172 |
+
* [Updated] Widget UI, cleaner and more compartmentalized
|
173 |
+
* [Fixed] Twitter API Copy/Paste (copy and past can introduce whitespace error - fixed)
|
174 |
+
* [Fixed] Widget UI Javascript fix
|
175 |
+
|
176 |
+
= 1.3.3 =
|
177 |
+
* [Fixed] URLs no longer truncated in retweets!
|
178 |
+
* [Added] cURL error notification: this is a required PHP extension for connection to the Twitter API
|
179 |
+
|
180 |
+
= 1.3.2 =
|
181 |
+
* Fixed Exclude Replies variable notice and tweet calculation
|
182 |
+
|
183 |
+
= 1.3.1 =
|
184 |
+
* Added @ symbol for Twitter name links in Tweets
|
185 |
+
|
186 |
+
= 1.3 =
|
187 |
+
* Added
|
188 |
+
* Hash Tag linking and ReTweet @names linking
|
189 |
+
* Name reference added to hover state attribute for date link Screen Names - better than username reference
|
190 |
+
|
191 |
+
* Updated
|
192 |
+
* Updated depricated functions to ensure future compatibility
|
193 |
+
* Rewrote link creation for URLs in tweets
|
194 |
+
|
195 |
+
* Fixed
|
196 |
+
* Fixed screen name reference for Twitter date links
|
197 |
+
|
198 |
+
= 1.2 =
|
199 |
+
* Added Twitter name reference enabling database backup for multiple account use
|
200 |
+
* Added Twitter Follow Button and configuration options
|
201 |
+
* Updated screenshots and instructions for new functionality and option settings
|
202 |
+
|
203 |
+
= 1.1 =
|
204 |
+
* Readme, descriptions and screenshot updates
|
205 |
+
|
206 |
+
= 1.0 =
|
207 |
+
* Initial release
|
208 |
+
|
209 |
+
== Upgrade Notice ==
|
210 |
+
|
211 |
+
= 1.3.3 =
|
212 |
+
Fixed retweets truncated links and more.
|
trunk/css/fonts/stt-intents.dev.svg
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" standalone="no"?>
|
2 |
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
|
3 |
+
<svg xmlns="http://www.w3.org/2000/svg">
|
4 |
+
<metadata>
|
5 |
+
This is a custom SVG font generated by IcoMoon.
|
6 |
+
<iconset grid="14"></iconset>
|
7 |
+
</metadata>
|
8 |
+
<defs>
|
9 |
+
<font id="stt-intents" horiz-adv-x="448" >
|
10 |
+
<font-face units-per-em="448" ascent="384" descent="-64" />
|
11 |
+
<missing-glyph horiz-adv-x="448" />
|
12 |
+
<glyph class="hidden" unicode="" d="M0,384L 448 -64L0 -64 z" horiz-adv-x="0" />
|
13 |
+
<glyph unicode="" d="M 448,104q0-41.5 -31.75-112.75q-0.75-1.75 -2.625-6t-3.375-7.5t-3.25-5.5q-3-4.25 -7-4.25q-3.75,0 -5.875,2.5t-2.125,6.25q0,2.25 0.625,6.625t 0.625,5.875q 1.25,17 1.25,30.75q0,25.25 -4.375,45.25t-12.125,34.625t-20,25.25t-26.375,17.375t-33.25,10.625t-38.5,5.375t-43.875,1.5l-56,0 l0-64 q0-6.5 -4.75-11.25t-11.25-4.75t-11.25,4.75 l-128,128q-4.75,4.75 -4.75,11.25t 4.75,11.25l 128,128q 4.75,4.75 11.25,4.75t 11.25-4.75t 4.75-11.25l0-64 l 56,0 q 178.25,0 218.75-100.75q 13.25-33.5 13.25-83.25z" data-tags="reply, arrow, left" />
|
14 |
+
<glyph unicode="" d="M 320,8q0-3.25 -2.375-5.625t-5.625-2.375l-240,0 q-2,0 -3.375,0.5t-2.25,1.75t-1.375,2t-0.75,2.875t-0.25,2.875l0,3.25 l0,2.75 l0,40 l0,104 l-48,0 q-6.5,0 -11.25,4.75t-4.75,11.25q0,6 3.75,10.25l 80,96q 4.75,5.5 12.25,5.5t 12.25-5.5l 80-96q 3.75-4.25 3.75-10.25q0-6.5 -4.75-11.25t-11.25-4.75l-48,0 l0-96 l 144,0 q 4,0 6.25-2.75l 40-48q 1.75-2.75 1.75-5.25 zM 480,112q0-6 -3.75-10.25l-80-96q-5-5.75 -12.25-5.75t-12.25,5.75l-80,96q-3.75,4.25 -3.75,10.25q0,6.5 4.75,11.25t 11.25,4.75l 48,0 l0,96 l-144,0 q-4,0 -6.25,3l-40,48q-1.75,2.25 -1.75,5q0,3.25 2.375,5.625t 5.625,2.375l 240,0 q 2,0 3.375-0.5t 2.25-1.75t 1.375-2t 0.75-2.875t 0.25-2.875l0-3.25 l0-2.75 l0-40 l0-104 l 48,0 q 6.5,0 11.25-4.75t 4.75-11.25z " horiz-adv-x="480" data-tags="retweet, loop, arrows" />
|
15 |
+
<glyph unicode="" d="M 416,222.25q0-5.5 -6.5-12l-90.75-88.5l 21.5-125q 0.25-1.75 0.25-5q0-5.25 -2.625-8.875t-7.625-3.625q-4.75,0 -10,3l-112.25,59l-112.25-59q-5.5-3 -10-3q-5.25,0 -7.875,3.625t-2.625,8.875q0,1.5 0.5,5l 21.5,125l-91,88.5q-6.25,6.75 -6.25,12q0,9.25 14,11.5l 125.5,18.25l 56.25,113.75q 4.75,10.25 12.25,10.25t 12.25-10.25l 56.25-113.75 l 125.5-18.25q 14-2.25 14-11.5z" horiz-adv-x="416" data-tags="star, favorite, rate" />
|
16 |
+
<glyph unicode="" d="M 448,298.942c-16.483-7.31-34.197-12.251-52.789-14.473c 18.975,11.375, 33.55,29.387, 40.413,50.851
|
17 |
+
c-17.761-10.534-37.431-18.183-58.367-22.304c-16.765,17.863-40.653,29.024-67.089,29.024c-50.76,0-91.913-41.15-91.913-91.909
|
18 |
+
c0-7.204, 0.813-14.219, 2.38-20.947c-76.388,3.834-144.113,40.425-189.445,96.034c-7.912-13.575-12.445-29.363-12.445-46.208
|
19 |
+
c0-31.889, 16.226-60.022, 40.889-76.504c-15.067,0.478-29.239,4.612-41.63,11.497c-0.009-0.383-0.009-0.768-0.009-1.156
|
20 |
+
c0-44.532, 31.683-81.68, 73.728-90.125c-7.711-2.1-15.832-3.225-24.215-3.225c-5.923,0-11.68,0.578-17.293,1.65
|
21 |
+
c 11.697-36.514, 45.64-63.090, 85.86-63.829c-31.456-24.653-71.088-39.346-114.151-39.346c-7.419,0-14.735,0.435-21.926,1.286
|
22 |
+
c 40.675-26.079, 88.988-41.297, 140.893-41.297c 169.060,0, 261.51,140.054, 261.51,261.513c0,3.985-0.090,7.948-0.267,11.891
|
23 |
+
C 420.096,264.324, 435.678,280.511, 448,298.942z" data-tags="twitter, tweet, social" />
|
24 |
+
<glyph unicode=" " horiz-adv-x="224" />
|
25 |
+
</font></defs></svg>
|
trunk/css/fonts/stt-intents.eot
ADDED
Binary file
|
trunk/css/fonts/stt-intents.svg
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" standalone="no"?>
|
2 |
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
|
3 |
+
<svg xmlns="http://www.w3.org/2000/svg">
|
4 |
+
<metadata>
|
5 |
+
This is a custom SVG font generated by IcoMoon.
|
6 |
+
<iconset grid="14"></iconset>
|
7 |
+
</metadata>
|
8 |
+
<defs>
|
9 |
+
<font id="stt-intents" horiz-adv-x="448" >
|
10 |
+
<font-face units-per-em="448" ascent="384" descent="-64" />
|
11 |
+
<missing-glyph horiz-adv-x="448" />
|
12 |
+
<glyph class="hidden" unicode="" d="M0,384L 448 -64L0 -64 z" horiz-adv-x="0" />
|
13 |
+
<glyph unicode="" d="M 448,104q0-41.5 -31.75-112.75q-0.75-1.75 -2.625-6t-3.375-7.5t-3.25-5.5q-3-4.25 -7-4.25q-3.75,0 -5.875,2.5t-2.125,6.25q0,2.25 0.625,6.625t 0.625,5.875q 1.25,17 1.25,30.75q0,25.25 -4.375,45.25t-12.125,34.625t-20,25.25t-26.375,17.375t-33.25,10.625t-38.5,5.375t-43.875,1.5l-56,0 l0-64 q0-6.5 -4.75-11.25t-11.25-4.75t-11.25,4.75 l-128,128q-4.75,4.75 -4.75,11.25t 4.75,11.25l 128,128q 4.75,4.75 11.25,4.75t 11.25-4.75t 4.75-11.25l0-64 l 56,0 q 178.25,0 218.75-100.75q 13.25-33.5 13.25-83.25z" />
|
14 |
+
<glyph unicode="" d="M 320,8q0-3.25 -2.375-5.625t-5.625-2.375l-240,0 q-2,0 -3.375,0.5t-2.25,1.75t-1.375,2t-0.75,2.875t-0.25,2.875l0,3.25 l0,2.75 l0,40 l0,104 l-48,0 q-6.5,0 -11.25,4.75t-4.75,11.25q0,6 3.75,10.25l 80,96q 4.75,5.5 12.25,5.5t 12.25-5.5l 80-96q 3.75-4.25 3.75-10.25q0-6.5 -4.75-11.25t-11.25-4.75l-48,0 l0-96 l 144,0 q 4,0 6.25-2.75l 40-48q 1.75-2.75 1.75-5.25 zM 480,112q0-6 -3.75-10.25l-80-96q-5-5.75 -12.25-5.75t-12.25,5.75l-80,96q-3.75,4.25 -3.75,10.25q0,6.5 4.75,11.25t 11.25,4.75l 48,0 l0,96 l-144,0 q-4,0 -6.25,3l-40,48q-1.75,2.25 -1.75,5q0,3.25 2.375,5.625t 5.625,2.375l 240,0 q 2,0 3.375-0.5t 2.25-1.75t 1.375-2t 0.75-2.875t 0.25-2.875l0-3.25 l0-2.75 l0-40 l0-104 l 48,0 q 6.5,0 11.25-4.75t 4.75-11.25z " horiz-adv-x="480" />
|
15 |
+
<glyph unicode="" d="M 416,222.25q0-5.5 -6.5-12l-90.75-88.5l 21.5-125q 0.25-1.75 0.25-5q0-5.25 -2.625-8.875t-7.625-3.625q-4.75,0 -10,3l-112.25,59l-112.25-59q-5.5-3 -10-3q-5.25,0 -7.875,3.625t-2.625,8.875q0,1.5 0.5,5l 21.5,125l-91,88.5q-6.25,6.75 -6.25,12q0,9.25 14,11.5l 125.5,18.25l 56.25,113.75q 4.75,10.25 12.25,10.25t 12.25-10.25l 56.25-113.75 l 125.5-18.25q 14-2.25 14-11.5z" horiz-adv-x="416" />
|
16 |
+
<glyph unicode="" d="M 448,298.942c-16.483-7.31-34.197-12.251-52.789-14.473c 18.975,11.375, 33.55,29.387, 40.413,50.851
|
17 |
+
c-17.761-10.534-37.431-18.183-58.367-22.304c-16.765,17.863-40.653,29.024-67.089,29.024c-50.76,0-91.913-41.15-91.913-91.909
|
18 |
+
c0-7.204, 0.813-14.219, 2.38-20.947c-76.388,3.834-144.113,40.425-189.445,96.034c-7.912-13.575-12.445-29.363-12.445-46.208
|
19 |
+
c0-31.889, 16.226-60.022, 40.889-76.504c-15.067,0.478-29.239,4.612-41.63,11.497c-0.009-0.383-0.009-0.768-0.009-1.156
|
20 |
+
c0-44.532, 31.683-81.68, 73.728-90.125c-7.711-2.1-15.832-3.225-24.215-3.225c-5.923,0-11.68,0.578-17.293,1.65
|
21 |
+
c 11.697-36.514, 45.64-63.090, 85.86-63.829c-31.456-24.653-71.088-39.346-114.151-39.346c-7.419,0-14.735,0.435-21.926,1.286
|
22 |
+
c 40.675-26.079, 88.988-41.297, 140.893-41.297c 169.060,0, 261.51,140.054, 261.51,261.513c0,3.985-0.090,7.948-0.267,11.891
|
23 |
+
C 420.096,264.324, 435.678,280.511, 448,298.942z" />
|
24 |
+
<glyph unicode=" " horiz-adv-x="224" />
|
25 |
+
</font></defs></svg>
|
trunk/css/fonts/stt-intents.ttf
ADDED
Binary file
|
trunk/css/fonts/stt-intents.woff
ADDED
Binary file
|
trunk/css/stt.css
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Font face for icons */
|
2 |
+
@font-face {
|
3 |
+
font-family: 'stt-intents';
|
4 |
+
src:url('fonts/stt-intents.eot');
|
5 |
+
}
|
6 |
+
@font-face {
|
7 |
+
font-family: 'stt-intents';
|
8 |
+
src: url(data:application/font-woff;charset=utf-8;base64,d09G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cEu8coJ9cC0FXJL9XuUCgvKlahbqwAYvbSE4rlbIUYB9ieb9TGHO7s2vQru4oww1Np8zDYHfXWhC0vqNlDf1X6vabrff1H99IKFyUMtOUOv7HtqWO4GgVF4Q2pbjqs5BB3bKiaM3NE3SDIpGq6O3jpqDfsZef/KNofti1DWMarU67US5rudnp1cLvwljndd7NWxnfV2yeGQ3XjV16MXIacuHAIbT9x8niBYhPwFSAFEqeJxjYGRgYADiMywHV8fz23xl4GY8ABRhOFc7XQxG/////wDjA8YGIJeDgQkkCgByZg3DAHicY2BkYGBs+H+AQYPxwf///xwYHzAARVAABwC4bQdxeJxjPMAAAVMhFCOQz/gAiBdA2ABAiwRbAAAAAAAAAAAADgBOALAA5gEuAAB4nGNgZGBg4GDwYWBiAAEQycgAEnMA8xkACqsAnAAAAHicjY6xDcIwEEV/QgChIEqgdEFB48gOVBE1NVU2iFAaR0o8ByWrMAYDMAYDwHc4IYQosOW753/f5wMwxRkRwoqQYikcY4yt8ABrnIQTeq7CQ/JdeIQ0WtAZJRMq8/5V4BgzrIQHOGAnnNBzER6Sb8Ij8gMdPLdGDcdc9bEDOu917XzlPC9ftbe+R9NrIbc40qGQI4NhLnh+937VLLfmMYw5o8WGDRvn9017rFSeGVWojyl4s1Zbo3Nj6fxn7JJ6S7XuxwxfhtFQVm1XN07ZzPzV5wlIcketAHicY2BiwA84gJiRgYmRiZGZkYWRlZGNvTQv083AwABCm1uCaUNDI6i4KYh2BcoDAOnwCww=) format('woff'),
|
9 |
+
url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAANAIAAAwBQRkZUTWaEnV4AAAfsAAAAHEdERUYANQAGAAAHzAAAACBPUy8yLuLcHAAAAVgAAABWY21hcKHZA/EAAAHQAAABamdhc3D//wADAAAHxAAAAAhnbHlmkC1hRwAAA1AAAAJcaGVhZP35bikAAADcAAAANmhoZWEDif/pAAABFAAAACRobXR4CVUAAAAAAbAAAAAgbG9jYQHsATQAAAM8AAAAEm1heHAATABPAAABOAA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0AC0AaQBuAHQAZQBuAHQAcwAAc3R0LWludGVudHMAAFYAZQByAHMAaQBvAG4AIAAxAC4AMAAAVmVyc2lvbiAxLjAAAHMAdAB0AC0AaQBuAHQAZQBuAHQAcwAAc3R0LWludGVudHMAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAEAAgECAQMBBAEFAQYHdW5pRjAwMAd1bmlGMDc5B3VuaUYxMTIHdW5pRjAwNQd1bmlFMDAwAAAAAAAB//8AAgABAAAADgAAABgAAAAAAAIAAQADAAcAAQAEAAAAAgAAAAAAAQAAAADJiW8xAAAAAM59lxYAAAAAzn2XFg==) format('truetype');
|
10 |
+
font-weight: normal;
|
11 |
+
font-style: normal;
|
12 |
+
}
|
13 |
+
/* push in list item and pull out image if avatar display */
|
14 |
+
.tweets li > a{
|
15 |
+
-ms-word-break: break-all;
|
16 |
+
word-break: break-all;
|
17 |
+
/* Non standard for webkit */
|
18 |
+
word-break: break-word;
|
19 |
+
|
20 |
+
-webkit-hyphens: auto;
|
21 |
+
-moz-hyphens: auto;
|
22 |
+
hyphens: auto;
|
23 |
+
}
|
24 |
+
.avatar{margin-left:53px;}
|
25 |
+
.avatar img{float:left; margin-left:-53px;}
|
26 |
+
.a-corn{
|
27 |
+
-webkit-border-radius: 5px;
|
28 |
+
-moz-border-radius:5px;
|
29 |
+
border-radius: 5px;
|
30 |
+
}
|
31 |
+
.a-rnd{}
|
32 |
+
/* intents */
|
33 |
+
.intent-meta {margin-top: 5px;}
|
34 |
+
.intent-meta a{margin-right: 5px;}
|
35 |
+
/* data attributes for inserting your icons */
|
36 |
+
[data-icon]:before {
|
37 |
+
font-family: 'stt-intents';
|
38 |
+
content: attr(data-icon);
|
39 |
+
speak: none;
|
40 |
+
font-weight: normal;
|
41 |
+
font-variant: normal;
|
42 |
+
font-size:14px;
|
43 |
+
text-transform: none;
|
44 |
+
line-height: 1;
|
45 |
+
-webkit-font-smoothing: antialiased;
|
46 |
+
-moz-osx-font-smoothing: grayscale;
|
47 |
+
}
|
48 |
+
/* icon only hide the text */
|
49 |
+
.pi-visuallyhidden {
|
50 |
+
border: 0;
|
51 |
+
clip: rect(0 0 0 0);
|
52 |
+
height: 1px;
|
53 |
+
margin: -1px;
|
54 |
+
overflow: hidden;
|
55 |
+
padding: 0;
|
56 |
+
position: absolute;
|
57 |
+
width: 1px;
|
58 |
+
}
|
59 |
+
/* replacing <br/><em> with CSS class */
|
60 |
+
.stt-em {
|
61 |
+
font-style: italic;
|
62 |
+
display: block;
|
63 |
+
}
|
trunk/css/stt.min.css
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@font-face{font-family:'stt-intents';src:url('fonts/stt-intents.eot')}@font-face{font-family:'stt-intents';src:url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAAWQAA0AAAAACAgAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABoAAAAcZoSdXkdERUYAAAFMAAAAHwAAACAANQAGT1MvMgAAAWwAAABHAAAAVi7i3BxjbWFwAAABtAAAAFUAAAFqodkD8Wdhc3AAAAIMAAAACAAAAAj//wADZ2x5ZgAAAhQAAAHQAAACXJAtYUdoZWFkAAAD5AAAADMAAAA2/fluKWhoZWEAAAQYAAAAIAAAACQDif/paG10eAAABDgAAAAYAAAAIAlVAABsb2NhAAAEUAAAABIAAAASAewBNG1heHAAAARkAAAAHQAAACAATABPbmFtZQAABIQAAADXAAABuXl6fnVwb3N0AAAFXAAAADQAAABaJCWFRHicY2BgYGQAgpOd+YYg+lztdDEYDQBAyQXkAAB4nGNgZGBg4ANiCQYQYGJgZGBmYAeSLGAeAwAEsQA8AHicY2BkPMA4gYGVgYNRmdGSgYHBDkpfZxBjKGZgYGJgZWaAAwEEkyEgzTWFweEBw0chxob/Bxg0GBsYHBoYGBhBcgCOlwsBAHicY2BgYGaAYBkGRgYQSAHyGMF8FgYPIM3HwMHAxMDGwPCA4QPDB9YPlR+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NrIbc40qGQI4NhLnh+937VLLfmMYw5o8WGDRvn9017rFSeGVWojyl4s1Zbo3Nj6fxn7JJ6S7XuxwxfhtFQVm1XN07ZzPzV5wlIcketAHicY2BiwA84gJiRgYmRiZGZkYWRlZGNvTQv083AwABCm1uCaUNDI6i4KYh2BcoDAOnwCww=) format('woff'),url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAANAIAAAwBQRkZUTWaEnV4AAAfsAAAAHEdERUYANQAGAAAHzAAAACBPUy8yLuLcHAAAAVgAAABWY21hcKHZA/EAAAHQAAABamdhc3D//wADAAAHxAAAAAhnbHlmkC1hRwAAA1AAAAJcaGVhZP35bikAAADcAAAANmhoZWEDif/pAAABFAAAACRobXR4CVUAAAAAAbAAAAAgbG9jYQHsATQAAAM8AAAAEm1heHAATABPAAABOAAAACBuYW1leXp+dQAABawAAAG5cG9zdCQlhUQAAAdoAAAAWgABAAAAAQAAzATBq18PPPUACwHAAAAAAM59lxYAAAAAzn2XFv///8AB4AGAAAAACAACAAAAAAAAAAEAAAGA/8AAKAHg///+QAHgAAEAAAAAAAAAAAAAAAAAAAAIAAEAAAAIAEwAAgAAAAAAAgAAAAEAAQAAAEAAAAAAAAAAAQHAAZAABQAIASMBOQAAAD4BIwE5AAAA1wAWAHMAAAIABQMAAAAAAAAAAAAAEAAAAAAAAAAAAAAAUGZFZABA4ADxEgGA/8AAKAGAAECAAAABAAAAAAAAAcAAAAAAAAAAlQAAAAAAAAHAAAAB4AAAAaAAAAHAAAAAAAADAAAAAwAAABwAAQAAAAAAZAADAAEAAAAcAAQASAAAAA4ACAACAAYAAOAA8ADwBfB58RL//wAAAADgAPAA8AXwefES//8AACAHEAMQAQ+LDvMAAQAAAAAAAAAAAAAAAAAAAAABBgAAAQAAAAAAAAABAgAAAAIAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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ACWAAEAAAAAAAEACwAYAAEAAAAAAAIABwA0AAEAAAAAAAMAKACOAAEAAAAAAAQACwDPAAEAAAAAAAUACwDzAAEAAAAAAAYACwEXAAMAAQQJAAEAFgAAAAMAAQQJAAIADgAkAAMAAQQJAAMAUAA8AAMAAQQJAAQAFgC3AAMAAQQJAAUAFgDbAAMAAQQJAAYAFgD/AHMAdAB0AC0AaQBuAHQAZQBuAHQAcwAAc3R0LWludGVudHMAAGkAbgB0AGUAbgB0AHMAAGludGVudHMAAEYAbwBuAHQARgBvAHIAZwBlACAAMgAuADAAIAA6ACAAcwB0AHQALQBpAG4AdABlAG4AdABzACAAOgAgADEAMQAtADEAMAAtADIAMAAxADMAAEZvbnRGb3JnZSAyLjAgOiBzdHQtaW50ZW50cyA6IDExLTEwLTIwMTMAAHMAdAB0AC0AaQBuAHQAZQBuAHQAcwAAc3R0LWludGVudHMAAFYAZQByAHMAaQBvAG4AIAAxAC4AMAAAVmVyc2lvbiAxLjAAAHMAdAB0AC0AaQBuAHQAZQBuAHQAcwAAc3R0LWludGVudHMAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAEAAgECAQMBBAEFAQYHdW5pRjAwMAd1bmlGMDc5B3VuaUYxMTIHdW5pRjAwNQd1bmlFMDAwAAAAAAAB//8AAgABAAAADgAAABgAAAAAAAIAAQADAAcAAQAEAAAAAgAAAAAAAQAAAADJiW8xAAAAAM59lxYAAAAAzn2XFg==) format('truetype');font-weight:normal;font-style:normal}
|
2 |
+
.tweets li>a{-ms-word-break:break-all;word-break:break-all;word-break:break-word;-webkit-hyphens:auto;-moz-hyphens:auto;hyphens:auto}.avatar{margin-left:53px}
|
3 |
+
.avatar img{float:left;margin-left:-53px}.a-corn{-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.intent-meta{margin-top:5px}.intent-meta a{margin-right:5px}
|
4 |
+
[data-icon]:before{font-family:'stt-intents';content:attr(data-icon);speak:none;font-weight:normal;font-variant:normal;font-size:14px;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}
|
5 |
+
.pi-visuallyhidden{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.stt-em{font-style:italic;display:block}
|
trunk/js/sttAdmin.js
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*global jQuery:false */
|
2 |
+
jQuery(document).ready(function($) {
|
3 |
+
|
4 |
+
'use strict';
|
5 |
+
|
6 |
+
// USe function so we can recall on save
|
7 |
+
function updateColorPicker(){
|
8 |
+
// Checks if the color picker widget exists in jQuery UI
|
9 |
+
// If it exists then initialize the WordPress color picker on our text input field
|
10 |
+
if( typeof jQuery.wp === 'object' && typeof jQuery.wp.wpColorPicker === 'function' ){
|
11 |
+
var sttOptions = {
|
12 |
+
// you can declare a default color here,
|
13 |
+
// or in the data-default-color attribute on the input
|
14 |
+
defaultColor: false,
|
15 |
+
// a callback to fire whenever the color changes to a valid color
|
16 |
+
// change: function(event, ui){},
|
17 |
+
// a callback to fire when the input is emptied or an invalid color
|
18 |
+
// clear: function() {},
|
19 |
+
// hide the color picker controls on load
|
20 |
+
hide: true,
|
21 |
+
// show a group of common colors beneath the square
|
22 |
+
// or, supply an array of colors to customize further
|
23 |
+
palettes: true
|
24 |
+
};
|
25 |
+
jQuery( '.intentColor' ).wpColorPicker(sttOptions);
|
26 |
+
} else {
|
27 |
+
// We use farbtastic if the WordPress color picker widget doesn't exist
|
28 |
+
jQuery( '#colorpicker' ).farbtastic( 'intentColor' );
|
29 |
+
}
|
30 |
+
}
|
31 |
+
updateColorPicker();
|
32 |
+
|
33 |
+
// Widget Button reveals - close onLoad
|
34 |
+
// $('.secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div').hide();
|
35 |
+
// Reveal/Hide onClick and change arrow direction
|
36 |
+
$(document).on('click', '.secrets h4, .avatar h4, .twitterFollow h4, .modTime h4, .twitterIntents h4', function() {
|
37 |
+
// var tFollow = $(this).next('div');
|
38 |
+
$(this).next('div').addClass('open');
|
39 |
+
$(this).next('div').slideToggle('fast', function() {
|
40 |
+
if(!$(this).is(':hidden')) {
|
41 |
+
$(this).siblings('h4').children('span').html('▲');
|
42 |
+
}else{
|
43 |
+
$(this).removeClass('open');
|
44 |
+
$(this).siblings('h4').children('span').html('▼');
|
45 |
+
}
|
46 |
+
});
|
47 |
+
});
|
48 |
+
|
49 |
+
|
50 |
+
function savedIt(e, xhr, settings){
|
51 |
+
// settings.data.search('action=save-widget') != -1
|
52 |
+
|
53 |
+
if( $('.secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div').hasClass('open') ){
|
54 |
+
// Do nothing
|
55 |
+
}else{
|
56 |
+
// reset toggles - clean view
|
57 |
+
// $('.secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div').slideUp();
|
58 |
+
$('.secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div').hide();
|
59 |
+
$('.secrets h4 > span, .avatar h4 > span, .twitterFollow h4 > span, .modTime h4 > span, .twitterIntents h4 > span').html('▼');
|
60 |
+
}
|
61 |
+
|
62 |
+
|
63 |
+
// re-initiate the colour picker
|
64 |
+
$('.intentColor .wp-picker-container').remove();
|
65 |
+
updateColorPicker();
|
66 |
+
}
|
67 |
+
|
68 |
+
// // Widget - Auto Ajax Saved
|
69 |
+
$(document).ajaxSuccess(function(e, xhr, settings) {
|
70 |
+
savedIt(e, xhr, settings);
|
71 |
+
}); // END AJAX success
|
72 |
+
|
73 |
+
|
74 |
+
}); // END READY
|
trunk/js/sttAdmin.min.js
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery(document).ready(function(a){function b(){if(typeof jQuery.wp==="object"&&typeof jQuery.wp.wpColorPicker==="function"){var d={defaultColor:false,hide:true,palettes:true};
|
2 |
+
jQuery(".intentColor").wpColorPicker(d);}else{jQuery("#colorpicker").farbtastic("intentColor");}}b();a(document).on("click",".secrets h4, .avatar h4, .twitterFollow h4, .modTime h4, .twitterIntents h4",function(){a(this).next("div").addClass("open");
|
3 |
+
a(this).next("div").slideToggle("fast",function(){if(!a(this).is(":hidden")){a(this).siblings("h4").children("span").html("▲");}else{a(this).removeClass("open");
|
4 |
+
a(this).siblings("h4").children("span").html("▼");}});});function c(f,g,d){if(a(".secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div").hasClass("open")){}else{a(".secrets > div, .avatar > div, .twitterFollow > div, .modTime > div, .twitterIntents > div").hide();
|
5 |
+
a(".secrets h4 > span, .avatar h4 > span, .twitterFollow h4 > span, .modTime h4 > span, .twitterIntents h4 > span").html("▼");}a(".intentColor .wp-picker-container").remove();
|
6 |
+
b();}a(document).ajaxSuccess(function(f,g,d){c(f,g,d);});});
|
trunk/libs/console.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Logs messages/variables/data to browser console from within php
|
4 |
+
*
|
5 |
+
* @param $name: message to be shown for optional data/vars
|
6 |
+
* @param $data: variable (scalar/mixed) arrays/objects, etc to be logged
|
7 |
+
* @param $jsEval: whether to apply JS eval() to arrays/objects
|
8 |
+
*
|
9 |
+
* @return none
|
10 |
+
* @author Sarfraz
|
11 |
+
*/
|
12 |
+
function logConsole($name, $data = NULL, $jsEval = FALSE){
|
13 |
+
|
14 |
+
if (! $name) return false;
|
15 |
+
|
16 |
+
$isevaled = false;
|
17 |
+
$type = ($data || gettype($data)) ? 'Type: ' . gettype($data) : '';
|
18 |
+
|
19 |
+
if ($jsEval && (is_array($data) || is_object($data)))
|
20 |
+
{
|
21 |
+
$data = 'eval(' . preg_replace('#[\s\r\n\t\0\x0B]+#', '', json_encode($data)) . ')';
|
22 |
+
$isevaled = true;
|
23 |
+
}
|
24 |
+
else
|
25 |
+
{
|
26 |
+
$data = json_encode($data);
|
27 |
+
}
|
28 |
+
|
29 |
+
# sanitalize
|
30 |
+
$data = $data ? $data : '';
|
31 |
+
$search_array = array("#'#", '#""#', "#''#", "#\n#", "#\r\n#");
|
32 |
+
$replace_array = array('"', '', '', '\\n', '\\n');
|
33 |
+
$data = preg_replace($search_array, $replace_array, $data);
|
34 |
+
$data = ltrim(rtrim($data, '"'), '"');
|
35 |
+
$data = $isevaled ? $data : ($data[0] === "'") ? $data : "'" . $data . "'";
|
36 |
+
|
37 |
+
$js = <<<JSCODE
|
38 |
+
\n<script>
|
39 |
+
// fallback - to deal with IE (or browsers that don't have console)
|
40 |
+
if (! window.console) console = {};
|
41 |
+
console.log = console.log || function(name, data){};
|
42 |
+
// end of fallback
|
43 |
+
|
44 |
+
console.log('$name');
|
45 |
+
console.log('------------------------------------------');
|
46 |
+
console.log('$type');
|
47 |
+
console.log($data);
|
48 |
+
console.log('\\n');
|
49 |
+
</script>
|
50 |
+
JSCODE;
|
51 |
+
|
52 |
+
echo $js;
|
53 |
+
} # end logConsole
|
54 |
+
|
55 |
+
/*
|
56 |
+
* EXAMPLE USES
|
57 |
+
* $name = 'sarfraz';
|
58 |
+
|
59 |
+
* $fruits = array("banana", "apple", "strawberry", "pineaple");
|
60 |
+
|
61 |
+
* $user = new stdClass;
|
62 |
+
* $user->name = "Sarfraz";
|
63 |
+
* $user->desig = "Sr. Software Engineer";
|
64 |
+
* $user->lang = "PHP";
|
65 |
+
|
66 |
+
* logConsole('$name var', $name, true);
|
67 |
+
* logConsole('An array of fruits', $fruits, true);
|
68 |
+
* logConsole('$user object', $user, true);
|
69 |
+
|
70 |
+
*/
|
71 |
+
|
72 |
+
|
73 |
+
/*
|
74 |
+
WORPRESS EXTEND
|
75 |
+
Change Search And Replace for:
|
76 |
+
$search_array = array("/=\'(\w*)\'/", "#'#", '#""#', "#''#", "#\n#", "#\r\n#", "/:,/", "/(\d{1,}),(\d{1,})/");
|
77 |
+
$replace_array = array('=\"$1\"','"', '', '', '\\n', '\\n', ":\"\",", '$1-$2');
|
78 |
+
|
79 |
+
post associated:
|
80 |
+
http://sarfraznawaz.wordpress.com/2012/01/05/outputting-php-to-browser-console/
|
81 |
+
*/
|
82 |
+
?>
|
trunk/simple-twitter-tweets.php
ADDED
@@ -0,0 +1,621 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Simple Twitter Tweets
|
4 |
+
Plugin URI: http://www.planet-interactive.co.uk/simple-twitter-tweets
|
5 |
+
Description: Display last x number tweets from Twitter API stream, store locally in database to present past tweets when failure to access Twitters restrictive API occurs
|
6 |
+
Author: Ashley Sheinwald
|
7 |
+
Version: 4.1
|
8 |
+
Author URI: http://www.planet-interactive.co.uk/
|
9 |
+
Text Domain: simple-twitter-tweets
|
10 |
+
*/
|
11 |
+
|
12 |
+
/* Copyright 2014-2015 Ashley Sheinwald (email : ashley@planet-interactive.co.uk)
|
13 |
+
|
14 |
+
This program is free software; you can redistribute it and/or modify
|
15 |
+
it under the terms of the GNU General Public License, version 2, as
|
16 |
+
published by the Free Software Foundation.
|
17 |
+
|
18 |
+
This program is distributed in the hope that it will be useful,
|
19 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
GNU General Public License for more details.
|
22 |
+
|
23 |
+
You should have received a copy of the GNU General Public License
|
24 |
+
along with this program; if not, write to the Free Software
|
25 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
26 |
+
*/
|
27 |
+
|
28 |
+
// USED FOR DEBUG
|
29 |
+
// include 'console.php';
|
30 |
+
|
31 |
+
// if(!class_exists('helpers')) {
|
32 |
+
// require 'libs/helpers.php';
|
33 |
+
// }
|
34 |
+
|
35 |
+
class PI_SimpleTwitterTweets extends WP_Widget{
|
36 |
+
|
37 |
+
function __construct() {
|
38 |
+
$widget_ops = array('classname' => 'PI_SimpleTwitterTweets', 'description' => 'Displays the most recent tweets from your Twitter Stream' );
|
39 |
+
//$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'Not-required-this-time' );
|
40 |
+
parent::__construct('PI_SimpleTwitterTweets', 'Simple Twitter Tweets', $widget_ops);
|
41 |
+
|
42 |
+
// Load (enqueue) some JS in Admin ONLY on widgets page
|
43 |
+
add_action('admin_enqueue_scripts', array(&$this, 'PI_load_admin_scripts'));
|
44 |
+
|
45 |
+
// Front End ONLY
|
46 |
+
if(!is_admin()){
|
47 |
+
// Register style sheet.
|
48 |
+
add_action( 'wp_enqueue_scripts', array( &$this, 'register_stt_styles' ) );
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
// FRONT END - Register and enqueue style sheet.
|
53 |
+
function register_stt_styles() {
|
54 |
+
if(!is_admin()){
|
55 |
+
wp_register_style( 'PI_stt_front', plugins_url( 'simple-twitter-tweets/css/stt.min.css' ) );
|
56 |
+
wp_enqueue_style( 'PI_stt_front' );
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
// ADMIN - Lets load some JS to aid widget display in Appearance->Widgets
|
61 |
+
function PI_load_admin_scripts($hook) {
|
62 |
+
if( $hook != 'widgets.php' )
|
63 |
+
return;
|
64 |
+
|
65 |
+
// Get global $wp_version - what version of WordPress is installed.
|
66 |
+
global $wp_version;
|
67 |
+
|
68 |
+
// If the WordPress >= 3.5, then load the new WordPress color picker.
|
69 |
+
if ( 3.5 <= $wp_version ){
|
70 |
+
//Both the necessary css and javascript have been registered already by WordPress, so all we have to do is load them with their handle.
|
71 |
+
wp_enqueue_style( 'wp-color-picker' );
|
72 |
+
wp_enqueue_script( 'wp-color-picker' );
|
73 |
+
}
|
74 |
+
// If the WP < 3.5 load the older farbtasic color picker.
|
75 |
+
else {
|
76 |
+
// As above load both style sna scripts
|
77 |
+
wp_enqueue_style( 'farbtastic' );
|
78 |
+
wp_enqueue_script( 'farbtastic' );
|
79 |
+
}
|
80 |
+
// Now load STT JS
|
81 |
+
wp_enqueue_script('PI_stt_js', plugins_url( '/simple-twitter-tweets/js/sttAdmin.min.js' , dirname(__FILE__) ), array('jquery'));
|
82 |
+
}
|
83 |
+
|
84 |
+
function process_links($tweet) {
|
85 |
+
|
86 |
+
// Is the Tweet a ReTweet - then grab the full text of the original Tweet
|
87 |
+
if(isset($tweet->retweeted_status)) {
|
88 |
+
// Split it so indices count correctly for @mentions etc.
|
89 |
+
$rt_section = current(explode(":", $tweet->text));
|
90 |
+
$text = $rt_section.": ";
|
91 |
+
// Get Text
|
92 |
+
$text .= $tweet->retweeted_status->text;
|
93 |
+
} else {
|
94 |
+
// Not a retweet - get Tweet
|
95 |
+
$text = $tweet->text;
|
96 |
+
}
|
97 |
+
|
98 |
+
// NEW Link Creation from clickable items in the text
|
99 |
+
$text = preg_replace('/((http)+(s)?:\/\/[^<>\s]+)/i', '<a href="$0" target="_blank" rel="nofollow">$0</a>', $text );
|
100 |
+
// Clickable Twitter names
|
101 |
+
$text = preg_replace('/[@]+([A-Za-z0-9-_]+)/', '<a href="http://twitter.com/$1" target="_blank" rel="nofollow">@$1</a>', $text );
|
102 |
+
// Clickable Twitter hash tags
|
103 |
+
$text = preg_replace('/[#]+([A-Za-z0-9-_]+)/', '<a href="http://twitter.com/search?q=%23$1" target="_blank" rel="nofollow">$0</a>', $text );
|
104 |
+
// END TWEET CONTENT REGEX
|
105 |
+
return $text;
|
106 |
+
|
107 |
+
}
|
108 |
+
// END PROCESS LINKS - Using Entities
|
109 |
+
|
110 |
+
|
111 |
+
// Clean four-byte Emoji icons out of tweet text.
|
112 |
+
// MySQL utf8 columns cannot store four byte Unicode sequences
|
113 |
+
function twitter_api_strip_emoji( $text ){
|
114 |
+
// four byte utf8: 11110www 10xxxxxx 10yyyyyy 10zzzzzz
|
115 |
+
return preg_replace('/[\xF0-\xF7][\x80-\xBF]{3}/', '', $text );
|
116 |
+
}
|
117 |
+
|
118 |
+
function form($instance){
|
119 |
+
|
120 |
+
//Set up some default widget settings.
|
121 |
+
$defaults = array(
|
122 |
+
'title' => __('Recent Tweets', 'simple-twitter-tweets')
|
123 |
+
, 'name' => __('iPlanetUK', 'simple-twitter-tweets')
|
124 |
+
, 'numTweets' => __(4, 'simple-twitter-tweets') // How many to display
|
125 |
+
, 'cacheTime' => __(5, 'simple-twitter-tweets') // Time in minutes between updates
|
126 |
+
, 'consumerKey' => __('xxxxxxxxxxxx', 'simple-twitter-tweets') // Consumer key
|
127 |
+
, 'consumerSecret' => __('xxxxxxxxxxxx', 'simple-twitter-tweets') // Consumer secret
|
128 |
+
, 'accessToken' => __('xxxxxxxxxxxx', 'simple-twitter-tweets') // Access token
|
129 |
+
, 'accessTokenSecret' => __('xxxxxxxxxxxx', 'simple-twitter-tweets') // Access token secret
|
130 |
+
, 'exclude_replies' => true
|
131 |
+
, 'twitterFollow' => false
|
132 |
+
, 'dataShowCount' => false
|
133 |
+
, 'dataShowScreenName' => false
|
134 |
+
, 'dataLang' => __('en', 'simple-twitter-tweets') // Language reference
|
135 |
+
// STARTING NEW FOR 2.0
|
136 |
+
// Time
|
137 |
+
, 'timeRef' => false // false = use old full hour ref, true if selected will use hour ref as h (twitter style)
|
138 |
+
, 'timeAgo' => true // true = show ago, false will turn it off
|
139 |
+
// Intents
|
140 |
+
, 'twitterIntents' => false // true = Default: show Twitter Intents
|
141 |
+
, 'twitterIntentsText' => false // false = Default: Show text - activate to turn off text display and use icons only
|
142 |
+
, 'intentColor' => "#999999" // Default colour, light grey
|
143 |
+
// Avatar
|
144 |
+
, 'showAvatar' => false // Show the avatar ?
|
145 |
+
, 'roundCorners' => false // Do we want rounded corners
|
146 |
+
, 'avatarSize' => "" // what size should it be - defaults to 48px
|
147 |
+
);
|
148 |
+
$instance = wp_parse_args( (array) $instance, $defaults );
|
149 |
+
$title = $instance['title'];
|
150 |
+
$name = $instance['name'];
|
151 |
+
$numTweets = $instance['numTweets'];
|
152 |
+
$cacheTime = $instance['cacheTime'];
|
153 |
+
$consumerKey = trim($instance['consumerKey']);
|
154 |
+
$consumerSecret = trim($instance['consumerSecret']);
|
155 |
+
$accessToken = trim($instance['accessToken']);
|
156 |
+
$accessTokenSecret = trim($instance['accessTokenSecret']);
|
157 |
+
$exclude_replies = $instance['exclude_replies'];
|
158 |
+
$twitterFollow = $instance['twitterFollow'];
|
159 |
+
$dataShowCount = $instance['dataShowCount'];
|
160 |
+
$dataShowScreenName = $instance['dataShowScreenName'];
|
161 |
+
$dataLang = $instance['dataLang'];
|
162 |
+
// STARTING NEW FOR 2.0
|
163 |
+
$timeRef = $instance['timeRef'];
|
164 |
+
$timeAgo = $instance['timeAgo'];
|
165 |
+
$twitterIntents = $instance['twitterIntents'];
|
166 |
+
$twitterIntentsText = $instance['twitterIntentsText'];
|
167 |
+
$intentColor = $instance['intentColor'];
|
168 |
+
$showAvatar = $instance['showAvatar'];
|
169 |
+
$roundCorners = $instance['roundCorners'];
|
170 |
+
$avatarSize = $instance['avatarSize'];
|
171 |
+
?>
|
172 |
+
|
173 |
+
<?php
|
174 |
+
// Show error if cURL not installed - extension required for Twitter API calls
|
175 |
+
if (!in_array('curl', get_loaded_extensions())) {
|
176 |
+
echo '<p style="background-color:pink;padding:10px;border:1px solid red;"><strong>';
|
177 |
+
_e('You do not have cURL installed! This is a required PHP extension to use the Twitter API:', 'simple-twitter-tweets');
|
178 |
+
echo ' <a href="http://curl.haxx.se/docs/install.html" taget="_blank">';
|
179 |
+
_e('cURL install', 'simple-twitter-tweets');
|
180 |
+
echo '</a></strong></p>';
|
181 |
+
}
|
182 |
+
?>
|
183 |
+
|
184 |
+
<p>
|
185 |
+
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label>
|
186 |
+
</p>
|
187 |
+
<p>
|
188 |
+
<label for="<?php echo $this->get_field_id("titleLink"); ?>">
|
189 |
+
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("titleLink"); ?>" name="<?php echo $this->get_field_name("titleLink"); ?>"<?php checked( (bool) $instance["titleLink"], true ); ?> />
|
190 |
+
<?php _e( 'Make widget title link' ); ?>
|
191 |
+
</label>
|
192 |
+
</p>
|
193 |
+
<p>
|
194 |
+
<label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Twitter Name (without @ symbol):', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" type="text" value="<?php echo esc_attr($name); ?>" /></label>
|
195 |
+
</p>
|
196 |
+
<p>
|
197 |
+
<label for="<?php echo $this->get_field_id('numTweets'); ?>"><?php _e('Number of Tweets:', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('numTweets'); ?>" name="<?php echo $this->get_field_name('numTweets'); ?>" type="text" value="<?php echo esc_attr($numTweets); ?>" /></label>
|
198 |
+
</p>
|
199 |
+
<p>
|
200 |
+
<label for="<?php echo $this->get_field_id('cacheTime'); ?>"><?php _e('Time in Minutes between updates:', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('cacheTime'); ?>" name="<?php echo $this->get_field_name('cacheTime'); ?>" type="text" value="<?php echo esc_attr($cacheTime); ?>" /></label>
|
201 |
+
</p>
|
202 |
+
|
203 |
+
<?php // NEW FOR 2.0 ?>
|
204 |
+
<?php // Time display options ?>
|
205 |
+
<div class="secrets" style="background:#d6eef9; margin-bottom:10px;">
|
206 |
+
<h4 class="button-secondary" style="width:100%; text-align:center;"><?php _e('Twitter API settings', 'simple-twitter-tweets') ?> <span style="font-size:75%;">▼</span></h4>
|
207 |
+
<div style="padding:10px;">
|
208 |
+
<p>
|
209 |
+
<label for="<?php echo $this->get_field_id('consumerKey'); ?>"><?php _e('Consumer Key:', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('consumerKey'); ?>" name="<?php echo $this->get_field_name('consumerKey'); ?>" type="text" value="<?php echo esc_attr($consumerKey); ?>" /></label>
|
210 |
+
</p>
|
211 |
+
<p>
|
212 |
+
<label for="<?php echo $this->get_field_id('consumerSecret'); ?>"><?php _e('Consumer Secret:', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('consumerSecret'); ?>" name="<?php echo $this->get_field_name('consumerSecret'); ?>" type="text" value="<?php echo esc_attr($consumerSecret); ?>" /></label>
|
213 |
+
</p>
|
214 |
+
<p>
|
215 |
+
<label for="<?php echo $this->get_field_id('accessToken'); ?>"><?php _e('Access Token:', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('accessToken'); ?>" name="<?php echo $this->get_field_name('accessToken'); ?>" type="text" value="<?php echo esc_attr($accessToken); ?>" /></label>
|
216 |
+
</p>
|
217 |
+
<p>
|
218 |
+
<label for="<?php echo $this->get_field_id('accessTokenSecret'); ?>"><?php _e('Access Token Secret:', 'simple-twitter-tweets') ?> <input class="widefat" id="<?php echo $this->get_field_id('accessTokenSecret'); ?>" name="<?php echo $this->get_field_name('accessTokenSecret'); ?>" type="text" value="<?php echo esc_attr($accessTokenSecret); ?>" /></label>
|
219 |
+
</p>
|
220 |
+
<p>
|
221 |
+
<input class="checkbox" type="checkbox" <?php checked( isset( $instance['exclude_replies']), true ); ?> id="<?php echo $this->get_field_id( 'exclude_replies' ); ?>" name="<?php echo $this->get_field_name( 'exclude_replies' ); ?>" />
|
222 |
+
<label for="<?php echo $this->get_field_id( 'exclude_replies' ); ?>"><?php _e('Exclude_@replies', 'simple-twitter-tweets'); ?></label>
|
223 |
+
</p>
|
224 |
+
</div>
|
225 |
+
</div>
|
226 |
+
|
227 |
+
<?php // NEW FOR 2.0 ?>
|
228 |
+
<?php // Avatar display options ?>
|
229 |
+
<div class="avatar" style="background:#d6eef9; margin-bottom:10px;">
|
230 |
+
<h4 class="button-secondary" style="width:100%; text-align:center;"><?php _e('Twitter Avatar settings', 'simple-twitter-tweets'); ?> <span style="font-size:75%;">▼</span></h4>
|
231 |
+
<div style="padding:10px;">
|
232 |
+
<p><?php _e('Display your Twitter Avatar: image', 'simple-twitter-tweets'); ?></p>
|
233 |
+
<p>
|
234 |
+
<input class="checkbox" type="checkbox" value="true" <?php checked( ( isset( $instance['showAvatar']) && ($instance['showAvatar'] == "true") ), true ); ?> id="<?php echo $this->get_field_id( 'showAvatar' ); ?>" name="<?php echo $this->get_field_name( 'showAvatar' ); ?>" />
|
235 |
+
<label for="<?php echo $this->get_field_id( 'showAvatar' ); ?>"><?php _e('Show your avatar image', 'simple-twitter-tweets'); ?></label>
|
236 |
+
</p>
|
237 |
+
<p>
|
238 |
+
<input class="checkbox" type="checkbox" value="true" <?php checked( ( isset( $instance['roundCorners']) && ($instance['showAvatar'] == "true") ), true ); ?> id="<?php echo $this->get_field_id( 'roundCorners' ); ?>" name="<?php echo $this->get_field_name( 'roundCorners' ); ?>" />
|
239 |
+
<label for="<?php echo $this->get_field_id( 'roundCorners' ); ?>"><?php _e('Round avatar corners (5px)', 'simple-twitter-tweets'); ?></label>
|
240 |
+
</p>
|
241 |
+
<p>
|
242 |
+
<label for="<?php echo $this->get_field_id('avatarSize'); ?>"><?php _e('Size of Avatar (default: 48):', 'simple-twitter-tweets'); ?> <input class="widefat" id="<?php echo $this->get_field_id('avatarSize'); ?>" name="<?php echo $this->get_field_name('avatarSize'); ?>" type="text" value="<?php echo esc_attr($avatarSize); ?>" /><br><em><?php _e('input number only', 'simple-twitter-tweets'); ?></em></label>
|
243 |
+
</p>
|
244 |
+
</div>
|
245 |
+
</div>
|
246 |
+
|
247 |
+
<?php // NEW FOR 2.0 ?>
|
248 |
+
<?php // Time display options ?>
|
249 |
+
<div class="modTime" style="background:#d6eef9; margin-bottom:10px;">
|
250 |
+
<h4 class="button-secondary" style="width:100%; text-align:center;"><?php _e('Time Display Options', 'simple-twitter-tweets'); ?> <span style="font-size:75%;">▼</span></h4>
|
251 |
+
<div style="padding:10px;">
|
252 |
+
<p>
|
253 |
+
<input class="checkbox" type="checkbox" value="true" <?php checked( (isset( $instance['timeRef']) && ($instance['timeRef'] == "true") ), true ); ?> id="<?php echo $this->get_field_id( 'timeRef' ); ?>" name="<?php echo $this->get_field_name( 'timeRef' ); ?>" />
|
254 |
+
<label for="<?php echo $this->get_field_id( 'timeRef' ); ?>"><?php _e('Change to short time reference <br><em>h for Hour(s), d for Day(s) ... <strong>Twitter style</strong></em>', 'simple-twitter-tweets'); ?></label>
|
255 |
+
</p>
|
256 |
+
<p>
|
257 |
+
<input class="checkbox" type="checkbox" value="true" <?php checked( (isset( $instance['timeAgo']) && ($instance['timeAgo'] == "true") ), true ); ?> id="<?php echo $this->get_field_id( 'timeAgo' ); ?>" name="<?php echo $this->get_field_name( 'timeAgo' ); ?>" value="true" />
|
258 |
+
<label for="<?php echo $this->get_field_id( 'timeAgo' ); ?>"><?php _e('Show "ago" after the time', 'simple-twitter-tweets'); ?></label>
|
259 |
+
</p>
|
260 |
+
</div>
|
261 |
+
</div>
|
262 |
+
|
263 |
+
<?php // NEW FOR 2.0 ?>
|
264 |
+
<?php // Twitter Intents and Display Options ?>
|
265 |
+
<div class="twitterIntents" style="background:#d6eef9; margin-bottom:10px;">
|
266 |
+
<h4 class="button-secondary" style="width:100%; text-align:center;"><?php _e('Twitter Intents', 'simple-twitter-tweets'); ?> <span style="font-size:75%;">▼</span></h4>
|
267 |
+
<div style="padding:10px;">
|
268 |
+
<p>
|
269 |
+
<input class="checkbox" type="checkbox" value="true" <?php checked( (isset( $instance['twitterIntents']) && ($instance['twitterIntents'] == "true") ), true ); ?> id="<?php echo $this->get_field_id( 'twitterIntents' ); ?>" name="<?php echo $this->get_field_name( 'twitterIntents' ); ?>" />
|
270 |
+
<label for="<?php echo $this->get_field_id( 'twitterIntents' ); ?>"><?php _e('Show Twitter Intents', 'simple-twitter-tweets'); ?></label>
|
271 |
+
</p>
|
272 |
+
<p>
|
273 |
+
<input class="checkbox" type="checkbox" value="true" <?php checked( (isset( $instance['twitterIntentsText']) && ($instance['twitterIntentsText'] == "true") ), true ); ?> id="<?php echo $this->get_field_id( 'twitterIntentsText' ); ?>" name="<?php echo $this->get_field_name( 'twitterIntentsText' ); ?>" />
|
274 |
+
<label for="<?php echo $this->get_field_id( 'twitterIntentsText' ); ?>"><?php _e('Hide Twitter Intents Text <br><em>e.g. just use icons</em>', 'simple-twitter-tweets'); ?></label>
|
275 |
+
</p>
|
276 |
+
<p>
|
277 |
+
<label for="<?php echo $this->get_field_id('intentColor'); ?>"><?php _e('Intent icons colour:', 'simple-twitter-tweets'); ?> <input class="intentColor" id="<?php echo $this->get_field_id('intentColor'); ?>" name="<?php echo $this->get_field_name('intentColor'); ?>" type="text" value="<?php echo esc_attr($intentColor); ?>" /></label>
|
278 |
+
<div id="colorpicker"></div>
|
279 |
+
</p>
|
280 |
+
</div>
|
281 |
+
</div>
|
282 |
+
|
283 |
+
<div class="twitterFollow" style="background:#d6eef9;">
|
284 |
+
<h4 class="button-secondary" style="width:100%; text-align:center;"><?php _e('Twitter Follow Button', 'simple-twitter-tweets'); ?> <span style="font-size:75%;">▼</span></h4>
|
285 |
+
<div style="padding:10px;">
|
286 |
+
<p>
|
287 |
+
<input class="checkbox" type="checkbox" <?php checked( (isset( $instance['twitterFollow']) && ($instance['twitterFollow'] == "on") ), true ); ?> id="<?php echo $this->get_field_id( 'twitterFollow' ); ?>" name="<?php echo $this->get_field_name( 'twitterFollow' ); ?>" />
|
288 |
+
<label for="<?php echo $this->get_field_id( 'twitterFollow' ); ?>"><?php _e('Show Twitter Follow Button', 'simple-twitter-tweets'); ?></label>
|
289 |
+
</p>
|
290 |
+
<p>
|
291 |
+
<input class="checkbox" type="checkbox" <?php checked( (isset( $instance['dataShowScreenName']) && ($instance['dataShowScreenName'] == "true") ), true ); ?> id="<?php echo $this->get_field_id( 'dataShowScreenName' ); ?>" name="<?php echo $this->get_field_name( 'dataShowScreenName' ); ?>" value="true" />
|
292 |
+
<label for="<?php echo $this->get_field_id( 'dataShowScreenName' ); ?>"><?php _e('Show Twitter Screen Name', 'simple-twitter-tweets'); ?></label>
|
293 |
+
</p>
|
294 |
+
<p>
|
295 |
+
<input class="checkbox" type="checkbox" <?php checked( (isset( $instance['dataShowCount']) && ($instance['dataShowCount'] == "true") ), true ); ?> id="<?php echo $this->get_field_id( 'dataShowCount' ); ?>" name="<?php echo $this->get_field_name( 'dataShowCount' ); ?>" value="true" />
|
296 |
+
<label for="<?php echo $this->get_field_id( 'dataShowCount' ); ?>"><?php _e('Show Twitter Followers Count', 'simple-twitter-tweets'); ?></label>
|
297 |
+
</p>
|
298 |
+
<p>
|
299 |
+
<label for="<?php echo $this->get_field_id('dataLang'); ?>"><?php _e('Language:', 'simple-twitter-tweets'); ?> <input class="widefat" id="<?php echo $this->get_field_id('dataLang'); ?>" name="<?php echo $this->get_field_name('dataLang'); ?>" type="text" value="<?php echo esc_attr($dataLang); ?>" /></label>
|
300 |
+
</p>
|
301 |
+
</div>
|
302 |
+
</div>
|
303 |
+
<?php
|
304 |
+
}
|
305 |
+
|
306 |
+
function update($new_instance, $old_instance){
|
307 |
+
$instance = $old_instance;
|
308 |
+
|
309 |
+
//Strip tags from title and name to remove HTML
|
310 |
+
$instance['title'] = strip_tags( $new_instance['title'] );
|
311 |
+
$instance['titleLink'] = $new_instance['titleLink'];
|
312 |
+
$instance['name'] = strip_tags( $new_instance['name'] );
|
313 |
+
$instance['numTweets'] = $new_instance['numTweets'];
|
314 |
+
$instance['cacheTime'] = $new_instance['cacheTime'];
|
315 |
+
$instance['consumerKey'] = trim($new_instance['consumerKey']);
|
316 |
+
$instance['consumerSecret'] = trim($new_instance['consumerSecret']);
|
317 |
+
$instance['accessToken'] = trim($new_instance['accessToken']);
|
318 |
+
$instance['accessTokenSecret'] = trim($new_instance['accessTokenSecret']);
|
319 |
+
$instance['exclude_replies'] = $new_instance['exclude_replies'];
|
320 |
+
$instance['twitterFollow'] = $new_instance['twitterFollow'];
|
321 |
+
$instance['dataShowCount'] = $new_instance['dataShowCount'];
|
322 |
+
$instance['dataShowScreenName'] = $new_instance['dataShowScreenName'];
|
323 |
+
$instance['dataLang'] = $new_instance['dataLang'];
|
324 |
+
// STARTING NEW FOR 2.0
|
325 |
+
$instance['timeRef'] = $new_instance['timeRef'];
|
326 |
+
$instance['timeAgo'] = $new_instance['timeAgo'];
|
327 |
+
$instance['twitterIntents'] = $new_instance['twitterIntents'];
|
328 |
+
$instance['twitterIntentsText'] = $new_instance['twitterIntentsText'];
|
329 |
+
$instance['intentColor'] = strip_tags( $new_instance['intentColor'] );
|
330 |
+
$instance['showAvatar'] = $new_instance['showAvatar'];
|
331 |
+
$instance['roundCorners'] = $new_instance['roundCorners'];
|
332 |
+
$instance['avatarSize'] = strip_tags( $new_instance['avatarSize'] );
|
333 |
+
|
334 |
+
return $instance;
|
335 |
+
}
|
336 |
+
|
337 |
+
function widget($args, $instance){
|
338 |
+
|
339 |
+
extract($args, EXTR_SKIP);
|
340 |
+
|
341 |
+
echo $before_widget;
|
342 |
+
|
343 |
+
//Our variables from the widget settings.
|
344 |
+
$PI_title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
|
345 |
+
if( isset($instance['titleLink']) && $instance['titleLink'] == true){
|
346 |
+
$PI_title = '<a target="_blank" href="https://twitter.com/'.$instance['name'].'">'.$PI_title.'</a>';
|
347 |
+
}
|
348 |
+
$PI_name = $instance['name'];
|
349 |
+
$PI_numTweets = $instance['numTweets'];
|
350 |
+
$PI_cacheTime = $instance['cacheTime'];
|
351 |
+
|
352 |
+
//Setup Twitter API OAuth tokens
|
353 |
+
$PI_consumerKey = trim($instance['consumerKey']);
|
354 |
+
$PI_consumerSecret = trim($instance['consumerSecret']);
|
355 |
+
$PI_accessToken = trim($instance['accessToken']);
|
356 |
+
$PI_accessTokenSecret = trim($instance['accessTokenSecret']);
|
357 |
+
|
358 |
+
$PI_exclude_replies = isset( $instance['exclude_replies'] ) ? $instance['exclude_replies'] : false;
|
359 |
+
$PI_twitterFollow = isset( $instance['twitterFollow'] ) ? $instance['twitterFollow'] : false;
|
360 |
+
|
361 |
+
$PI_dataShowCount = isset( $instance['dataShowCount'] ) ? $instance['dataShowCount'] : false;
|
362 |
+
$PI_dataShowScreenName = isset( $instance['dataShowScreenName'] ) ? $instance['dataShowScreenName'] : false;
|
363 |
+
$PI_dataLang = $instance['dataLang'];
|
364 |
+
|
365 |
+
// 2.0 updates
|
366 |
+
$PI_timeRef = isset( $instance['timeRef'] ) ? $instance['timeRef'] : false;
|
367 |
+
$PI_timeAgo = isset( $instance['timeAgo'] ) ? $instance['timeAgo'] : false;
|
368 |
+
$PI_twitterIntents = isset( $instance['twitterIntents'] ) ? $instance['twitterIntents'] : false;
|
369 |
+
$PI_twitterIntentsText = isset( $instance['twitterIntentsText'] ) ? $instance['twitterIntentsText'] : false;
|
370 |
+
$PI_intentColor = $instance['intentColor'];
|
371 |
+
|
372 |
+
// Avatar
|
373 |
+
$PI_showAvatar = isset( $instance['showAvatar'] ) ? $instance['showAvatar'] : false;
|
374 |
+
$PI_roundCorners = isset( $instance['roundCorners'] ) ? $instance['roundCorners'] : false;
|
375 |
+
$PI_avatarSize = $instance['avatarSize'];
|
376 |
+
|
377 |
+
if (!empty($PI_title))
|
378 |
+
echo $before_title . $PI_title . $after_title;
|
379 |
+
|
380 |
+
// START WIDGET CODE HERE
|
381 |
+
?>
|
382 |
+
|
383 |
+
<ul class="tweets">
|
384 |
+
<?php
|
385 |
+
/*
|
386 |
+
* Uses:
|
387 |
+
* Twitter API call:
|
388 |
+
* http://dev.twitter.com/doc/get/statuses/user_timeline
|
389 |
+
* WP transient API ref.
|
390 |
+
* http://www.problogdesign.com/wordpress/use-the-transients-api-to-list-the-latest-commenter/
|
391 |
+
* Plugin Development and Script enhancement
|
392 |
+
* http://www.planet-interactive.co.uk
|
393 |
+
*/
|
394 |
+
|
395 |
+
// Configuration.
|
396 |
+
$numTweets = $PI_numTweets; // Num tweets to show
|
397 |
+
$name = $PI_name; // Twitter UserName
|
398 |
+
$cacheTime = $PI_cacheTime; // Time in minutes between updates.
|
399 |
+
|
400 |
+
// Get from https://dev.twitter.com/
|
401 |
+
// Login - Create New Application, fill in details and use required data below
|
402 |
+
$consumerKey = trim($PI_consumerKey); // OAuth Key
|
403 |
+
$consumerSecret = trim($PI_consumerSecret); // OAuth Secret
|
404 |
+
$accessToken = trim($PI_accessToken); // OAuth Access Token
|
405 |
+
$accessTokenSecret = trim($PI_accessTokenSecret); // OAuth Token Secret
|
406 |
+
|
407 |
+
$exclude_replies = $PI_exclude_replies; // Leave out @replies?
|
408 |
+
$twitterFollow = $PI_twitterFollow; // Whether to show Twitter Follow button
|
409 |
+
|
410 |
+
$dataShowCount = ($PI_dataShowCount != "true") ? "false" : "true"; // Whether to show Twitter Follower Count
|
411 |
+
$dataShowScreenName = ($PI_dataShowScreenName != "true") ? "false" : "true"; // Whether to show Twitter Screen Name
|
412 |
+
$dataLang = $PI_dataLang; // Tell Twitter what Language is being used
|
413 |
+
|
414 |
+
$timeRef = $PI_timeRef; // Time ref: hours or short h
|
415 |
+
$timeAgo = $PI_timeAgo; // Human Time: ago ref or not
|
416 |
+
$twitterIntents = $PI_twitterIntents; // Intent on/off
|
417 |
+
$twitterIntentsText = $PI_twitterIntentsText; // Intents Text on/off
|
418 |
+
$intentColor = $PI_intentColor; // Intent icons colour
|
419 |
+
|
420 |
+
$showAvatar = $PI_showAvatar;
|
421 |
+
$roundCorners = $PI_roundCorners;
|
422 |
+
$avatarSize = $PI_avatarSize;
|
423 |
+
|
424 |
+
// COMMUNITY REQUEST! (1)
|
425 |
+
$transName = 'list-tweets-'.$name; // Name of value in database. [added $name for multiple account use]
|
426 |
+
$backupName = $transName . '-backup'; // Name of backup value in database.
|
427 |
+
|
428 |
+
// if(false === ($tweets = unserialize( base64_decode(get_transient( $transName ) ) ) ) ) :
|
429 |
+
if(false === ($tweets = get_transient( $transName ) ) ) :
|
430 |
+
|
431 |
+
// Get the tweets from Twitter.
|
432 |
+
if ( ! class_exists('TwitterOAuth') )
|
433 |
+
include 'twitteroauth/twitteroauth.php';
|
434 |
+
|
435 |
+
$connection = new TwitterOAuth(
|
436 |
+
$consumerKey, // Consumer key
|
437 |
+
$consumerSecret, // Consumer secret
|
438 |
+
$accessToken, // Access token
|
439 |
+
$accessTokenSecret // Access token secret
|
440 |
+
);
|
441 |
+
|
442 |
+
// If excluding replies, we need to fetch more than requested as the
|
443 |
+
// total is fetched first, and then replies removed.
|
444 |
+
$totalToFetch = ($exclude_replies) ? max(50, $numTweets * 3) : $numTweets;
|
445 |
+
|
446 |
+
$fetchedTweets = $connection->get(
|
447 |
+
'statuses/user_timeline',
|
448 |
+
array(
|
449 |
+
'screen_name' => $name,
|
450 |
+
'count' => $totalToFetch,
|
451 |
+
'exclude_replies' => $exclude_replies
|
452 |
+
)
|
453 |
+
);
|
454 |
+
|
455 |
+
// Did the fetch fail?
|
456 |
+
if($connection->http_code != 200) :
|
457 |
+
$tweets = get_option($backupName); // False if there has never been data saved.
|
458 |
+
else :
|
459 |
+
// Fetch succeeded.
|
460 |
+
// Now update the array to store just what we need.
|
461 |
+
// (Done here instead of PHP doing this for every page load)
|
462 |
+
$limitToDisplay = min($numTweets, count($fetchedTweets));
|
463 |
+
|
464 |
+
for($i = 0; $i < $limitToDisplay; $i++) :
|
465 |
+
$tweet = $fetchedTweets[$i];
|
466 |
+
|
467 |
+
// Core info.
|
468 |
+
$name = $tweet->user->name;
|
469 |
+
|
470 |
+
// COMMUNITY REQUEST !!!!!! (2)
|
471 |
+
$screen_name = $tweet->user->screen_name;
|
472 |
+
|
473 |
+
$permalink = 'http://twitter.com/'. $screen_name .'/status/'. $tweet->id_str;
|
474 |
+
$tweet_id = $tweet->id_str;
|
475 |
+
|
476 |
+
/* Alternative image sizes method: http://dev.twitter.com/doc/get/users/profile_image/:screen_name */
|
477 |
+
// Check for SSL via protocol https then display relevant image - thanks SO - this should do
|
478 |
+
if (isset($_SERVER['HTTPS']) &&
|
479 |
+
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
|
480 |
+
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
|
481 |
+
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
|
482 |
+
// $protocol = 'https://';
|
483 |
+
$image = $tweet->user->profile_image_url_https;
|
484 |
+
}
|
485 |
+
else {
|
486 |
+
// $protocol = 'http://';
|
487 |
+
$image = $tweet->user->profile_image_url;
|
488 |
+
}
|
489 |
+
// $image = $tweet->user->profile_image_url;
|
490 |
+
|
491 |
+
// Process Tweets - Use Twitter entities for correct URL, hash and mentions
|
492 |
+
$text = $this->process_links($tweet);
|
493 |
+
|
494 |
+
// lets strip 4-byte emojis
|
495 |
+
$text = $this->twitter_api_strip_emoji( $text );
|
496 |
+
|
497 |
+
// Need to get time in Unix format.
|
498 |
+
$time = $tweet->created_at;
|
499 |
+
$time = date_parse($time);
|
500 |
+
$uTime = mktime($time['hour'], $time['minute'], $time['second'], $time['month'], $time['day'], $time['year']);
|
501 |
+
|
502 |
+
// Now make the new array.
|
503 |
+
$tweets[] = array(
|
504 |
+
'text' => $text,
|
505 |
+
'name' => $name,
|
506 |
+
'permalink' => $permalink,
|
507 |
+
'image' => $image,
|
508 |
+
'time' => $uTime,
|
509 |
+
'tweet_id' => $tweet_id
|
510 |
+
);
|
511 |
+
endfor;
|
512 |
+
|
513 |
+
set_transient($transName, $tweets, 60 * $cacheTime);
|
514 |
+
update_option($backupName, $tweets );
|
515 |
+
endif;
|
516 |
+
endif;
|
517 |
+
|
518 |
+
if(!function_exists('twitter_time_diff'))
|
519 |
+
{
|
520 |
+
function twitter_time_diff( $from, $to = '' ) {
|
521 |
+
$diff = human_time_diff($from,$to);
|
522 |
+
$replace = array(
|
523 |
+
' hour' => 'h',
|
524 |
+
' hours' => 'h',
|
525 |
+
' day' => 'd',
|
526 |
+
' days' => 'd',
|
527 |
+
' minute' => 'm',
|
528 |
+
' minutes' => 'm',
|
529 |
+
' second' => 's',
|
530 |
+
' seconds' => 's',
|
531 |
+
);
|
532 |
+
return strtr($diff,$replace);
|
533 |
+
}
|
534 |
+
}
|
535 |
+
// Now display the tweets, if we can.
|
536 |
+
if($tweets) : ?>
|
537 |
+
<?php foreach( (array) $tweets as $t) : // casting array to array just in case it's empty - then prevents PHP warning ?>
|
538 |
+
<li<?php echo ($showAvatar) ? ' class="avatar"':""; ?><?php echo ($showAvatar && $avatarSize) ? ' style="margin-left:'.($avatarSize+5).'px"':""; ?>>
|
539 |
+
<?php
|
540 |
+
if ($showAvatar){
|
541 |
+
echo '<img ';
|
542 |
+
echo ($avatarSize) ? ' style="margin-left:-'.($avatarSize+5).'px"':"";
|
543 |
+
echo ($avatarSize) ? 'width="'.$avatarSize.'px" height="'.$avatarSize.'px"' : 'width="48px" height="48px"';
|
544 |
+
echo 'src="'.$t['image'].'" alt="';
|
545 |
+
_e('Tweet Avatar', 'simple-twitter-tweets');
|
546 |
+
echo '" class="';
|
547 |
+
echo ($roundCorners) ? 'a-corn':'';
|
548 |
+
echo '"/>';
|
549 |
+
}
|
550 |
+
?>
|
551 |
+
<?php echo $t['text']; ?>
|
552 |
+
<span class="stt-em">
|
553 |
+
<?php if(!isset($screen_name)){ $screen_name = $name; }?>
|
554 |
+
<a href="http://www.twitter.com/<?php echo $screen_name; ?>" target="_blank" title="<?php
|
555 |
+
printf(
|
556 |
+
/* translators: %s: Twitter user name to follow */
|
557 |
+
__( 'Follow %s on Twitter [Opens a new window]', 'simple-twitter-tweets' ),
|
558 |
+
$name
|
559 |
+
); ?>">
|
560 |
+
<?php
|
561 |
+
|
562 |
+
// Original - long time ref: hours...
|
563 |
+
if($timeRef == "true"){
|
564 |
+
// New - short Twitter style time ref: h...
|
565 |
+
$timeDisplay = twitter_time_diff($t['time'], current_time('timestamp'));
|
566 |
+
}else{
|
567 |
+
$timeDisplay = human_time_diff($t['time'], current_time('timestamp'));
|
568 |
+
}
|
569 |
+
// Ago - to show?
|
570 |
+
if($timeAgo == "true"){
|
571 |
+
$displayAgo = _x(' ago', 'leading space is required to keep gap from date', 'simple-twitter-tweets');
|
572 |
+
}else{
|
573 |
+
// Added to counter 'no ago var' setting undefined variable warning
|
574 |
+
$displayAgo = "";
|
575 |
+
}
|
576 |
+
// Use to make il8n compliant
|
577 |
+
printf(__('%1$s%2$s'), $timeDisplay, $displayAgo);
|
578 |
+
|
579 |
+
?>
|
580 |
+
</a>
|
581 |
+
</span>
|
582 |
+
|
583 |
+
<?php // INTENTS REF: DISPLAY OR NOT
|
584 |
+
if($twitterIntents == "true"){
|
585 |
+
?>
|
586 |
+
<div class="intent-meta">
|
587 |
+
<a href="http://twitter.com/intent/tweet?in_reply_to=<?php echo $t['tweet_id']; ?>" data-lang="en" class="in-reply-to" title="<?php _e('Reply','simple-twitter-tweets'); ?>" target="_blank">
|
588 |
+
<span aria-hidden="true" data-icon="" <?php echo ($intentColor) ? 'style="color:'.$intentColor.';"' :''; ?>></span>
|
589 |
+
<span <?php echo ($twitterIntentsText) ? 'class="pi-visuallyhidden"':''; ?>><?php _e('Reply','simple-twitter-tweets'); ?></span></a>
|
590 |
+
<a href="http://twitter.com/intent/retweet?tweet_id=<?php echo $t['tweet_id']; ?>" data-lang="en" class="retweet" title="<?php _e('Retweet','simple-twitter-tweets'); ?>" target="_blank">
|
591 |
+
<span aria-hidden="true" data-icon="" <?php echo ($intentColor) ? 'style="color:'.$intentColor.';"' :''; ?>></span>
|
592 |
+
<span <?php echo ($twitterIntentsText) ? 'class="pi-visuallyhidden"':''; ?>><?php _e('Retweet','simple-twitter-tweets'); ?></span></a>
|
593 |
+
<a href="http://twitter.com/intent/favorite?tweet_id=<?php echo $t['tweet_id']; ?>" data-lang="en" class="favorite" title="<?php _e('Favourite','simple-twitter-tweets'); ?>" target="_blank">
|
594 |
+
<span aria-hidden="true" data-icon="" <?php echo ($intentColor) ? 'style="color:'.$intentColor.';"' :''; ?>></span>
|
595 |
+
<span <?php echo ($twitterIntentsText) ? 'class="pi-visuallyhidden"':''; ?>><?php _e('Favourite','simple-twitter-tweets'); ?></span></a>
|
596 |
+
</div>
|
597 |
+
<?php } ?>
|
598 |
+
|
599 |
+
</li>
|
600 |
+
<?php endforeach; ?>
|
601 |
+
|
602 |
+
<?php else : ?>
|
603 |
+
<li><?php _e('Waiting for Twitter... Once Twitter is ready they will display my Tweets again.','simple-twitter-tweets'); ?></li>
|
604 |
+
<?php endif; ?>
|
605 |
+
</ul>
|
606 |
+
|
607 |
+
<?php
|
608 |
+
// ADD Twitter follow button - to increase engagement
|
609 |
+
// Make it an options choice though
|
610 |
+
if($twitterFollow){ ?>
|
611 |
+
<div class="twitter-follow-container"><a href="https://twitter.com/<?php echo $PI_name; ?>" class="twitter-follow-button" data-show-count="<?php echo $dataShowCount; ?>" data-show-screen-name="<?php echo $dataShowScreenName; ?>" data-lang="<?php echo $dataLang; ?>"><?php _e('Follow','simple-twitter-tweets'); ?> @<?php echo $PI_name; ?></a></div>
|
612 |
+
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
|
613 |
+
<?php
|
614 |
+
}
|
615 |
+
// END OF WIDGET CODE HERE
|
616 |
+
echo $after_widget;
|
617 |
+
}
|
618 |
+
|
619 |
+
}
|
620 |
+
add_action( 'widgets_init', create_function('', 'return register_widget("PI_SimpleTwitterTweets");') );
|
621 |
+
?>
|
trunk/twitteroauth/OAuth.php
ADDED
@@ -0,0 +1,874 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// vim: foldmethod=marker
|
3 |
+
|
4 |
+
/* Generic exception class
|
5 |
+
*/
|
6 |
+
if (!class_exists('OAuthException')) {
|
7 |
+
class OAuthException extends Exception {
|
8 |
+
// pass
|
9 |
+
}
|
10 |
+
}
|
11 |
+
|
12 |
+
class OAuthConsumer {
|
13 |
+
public $key;
|
14 |
+
public $secret;
|
15 |
+
|
16 |
+
function __construct($key, $secret, $callback_url=NULL) {
|
17 |
+
$this->key = $key;
|
18 |
+
$this->secret = $secret;
|
19 |
+
$this->callback_url = $callback_url;
|
20 |
+
}
|
21 |
+
|
22 |
+
function __toString() {
|
23 |
+
return "OAuthConsumer[key=$this->key,secret=$this->secret]";
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
class OAuthToken {
|
28 |
+
// access tokens and request tokens
|
29 |
+
public $key;
|
30 |
+
public $secret;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* key = the token
|
34 |
+
* secret = the token secret
|
35 |
+
*/
|
36 |
+
function __construct($key, $secret) {
|
37 |
+
$this->key = $key;
|
38 |
+
$this->secret = $secret;
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* generates the basic string serialization of a token that a server
|
43 |
+
* would respond to request_token and access_token calls with
|
44 |
+
*/
|
45 |
+
function to_string() {
|
46 |
+
return "oauth_token=" .
|
47 |
+
OAuthUtil::urlencode_rfc3986($this->key) .
|
48 |
+
"&oauth_token_secret=" .
|
49 |
+
OAuthUtil::urlencode_rfc3986($this->secret);
|
50 |
+
}
|
51 |
+
|
52 |
+
function __toString() {
|
53 |
+
return $this->to_string();
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* A class for implementing a Signature Method
|
59 |
+
* See section 9 ("Signing Requests") in the spec
|
60 |
+
*/
|
61 |
+
abstract class OAuthSignatureMethod {
|
62 |
+
/**
|
63 |
+
* Needs to return the name of the Signature Method (ie HMAC-SHA1)
|
64 |
+
* @return string
|
65 |
+
*/
|
66 |
+
abstract public function get_name();
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Build up the signature
|
70 |
+
* NOTE: The output of this function MUST NOT be urlencoded.
|
71 |
+
* the encoding is handled in OAuthRequest when the final
|
72 |
+
* request is serialized
|
73 |
+
* @param OAuthRequest $request
|
74 |
+
* @param OAuthConsumer $consumer
|
75 |
+
* @param OAuthToken $token
|
76 |
+
* @return string
|
77 |
+
*/
|
78 |
+
abstract public function build_signature($request, $consumer, $token);
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Verifies that a given signature is correct
|
82 |
+
* @param OAuthRequest $request
|
83 |
+
* @param OAuthConsumer $consumer
|
84 |
+
* @param OAuthToken $token
|
85 |
+
* @param string $signature
|
86 |
+
* @return bool
|
87 |
+
*/
|
88 |
+
public function check_signature($request, $consumer, $token, $signature) {
|
89 |
+
$built = $this->build_signature($request, $consumer, $token);
|
90 |
+
return $built == $signature;
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
|
96 |
+
* where the Signature Base String is the text and the key is the concatenated values (each first
|
97 |
+
* encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
|
98 |
+
* character (ASCII code 38) even if empty.
|
99 |
+
* - Chapter 9.2 ("HMAC-SHA1")
|
100 |
+
*/
|
101 |
+
class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod {
|
102 |
+
function get_name() {
|
103 |
+
return "HMAC-SHA1";
|
104 |
+
}
|
105 |
+
|
106 |
+
public function build_signature($request, $consumer, $token) {
|
107 |
+
$base_string = $request->get_signature_base_string();
|
108 |
+
$request->base_string = $base_string;
|
109 |
+
|
110 |
+
$key_parts = array(
|
111 |
+
$consumer->secret,
|
112 |
+
($token) ? $token->secret : ""
|
113 |
+
);
|
114 |
+
|
115 |
+
$key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
|
116 |
+
$key = implode('&', $key_parts);
|
117 |
+
|
118 |
+
return base64_encode(hash_hmac('sha1', $base_string, $key, true));
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* The PLAINTEXT method does not provide any security protection and SHOULD only be used
|
124 |
+
* over a secure channel such as HTTPS. It does not use the Signature Base String.
|
125 |
+
* - Chapter 9.4 ("PLAINTEXT")
|
126 |
+
*/
|
127 |
+
class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod {
|
128 |
+
public function get_name() {
|
129 |
+
return "PLAINTEXT";
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* oauth_signature is set to the concatenated encoded values of the Consumer Secret and
|
134 |
+
* Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
|
135 |
+
* empty. The result MUST be encoded again.
|
136 |
+
* - Chapter 9.4.1 ("Generating Signatures")
|
137 |
+
*
|
138 |
+
* Please note that the second encoding MUST NOT happen in the SignatureMethod, as
|
139 |
+
* OAuthRequest handles this!
|
140 |
+
*/
|
141 |
+
public function build_signature($request, $consumer, $token) {
|
142 |
+
$key_parts = array(
|
143 |
+
$consumer->secret,
|
144 |
+
($token) ? $token->secret : ""
|
145 |
+
);
|
146 |
+
|
147 |
+
$key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
|
148 |
+
$key = implode('&', $key_parts);
|
149 |
+
$request->base_string = $key;
|
150 |
+
|
151 |
+
return $key;
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in
|
157 |
+
* [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for
|
158 |
+
* EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a
|
159 |
+
* verified way to the Service Provider, in a manner which is beyond the scope of this
|
160 |
+
* specification.
|
161 |
+
* - Chapter 9.3 ("RSA-SHA1")
|
162 |
+
*/
|
163 |
+
abstract class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod {
|
164 |
+
public function get_name() {
|
165 |
+
return "RSA-SHA1";
|
166 |
+
}
|
167 |
+
|
168 |
+
// Up to the SP to implement this lookup of keys. Possible ideas are:
|
169 |
+
// (1) do a lookup in a table of trusted certs keyed off of consumer
|
170 |
+
// (2) fetch via http using a url provided by the requester
|
171 |
+
// (3) some sort of specific discovery code based on request
|
172 |
+
//
|
173 |
+
// Either way should return a string representation of the certificate
|
174 |
+
protected abstract function fetch_public_cert(&$request);
|
175 |
+
|
176 |
+
// Up to the SP to implement this lookup of keys. Possible ideas are:
|
177 |
+
// (1) do a lookup in a table of trusted certs keyed off of consumer
|
178 |
+
//
|
179 |
+
// Either way should return a string representation of the certificate
|
180 |
+
protected abstract function fetch_private_cert(&$request);
|
181 |
+
|
182 |
+
public function build_signature($request, $consumer, $token) {
|
183 |
+
$base_string = $request->get_signature_base_string();
|
184 |
+
$request->base_string = $base_string;
|
185 |
+
|
186 |
+
// Fetch the private key cert based on the request
|
187 |
+
$cert = $this->fetch_private_cert($request);
|
188 |
+
|
189 |
+
// Pull the private key ID from the certificate
|
190 |
+
$privatekeyid = openssl_get_privatekey($cert);
|
191 |
+
|
192 |
+
// Sign using the key
|
193 |
+
$ok = openssl_sign($base_string, $signature, $privatekeyid);
|
194 |
+
|
195 |
+
// Release the key resource
|
196 |
+
openssl_free_key($privatekeyid);
|
197 |
+
|
198 |
+
return base64_encode($signature);
|
199 |
+
}
|
200 |
+
|
201 |
+
public function check_signature($request, $consumer, $token, $signature) {
|
202 |
+
$decoded_sig = base64_decode($signature);
|
203 |
+
|
204 |
+
$base_string = $request->get_signature_base_string();
|
205 |
+
|
206 |
+
// Fetch the public key cert based on the request
|
207 |
+
$cert = $this->fetch_public_cert($request);
|
208 |
+
|
209 |
+
// Pull the public key ID from the certificate
|
210 |
+
$publickeyid = openssl_get_publickey($cert);
|
211 |
+
|
212 |
+
// Check the computed signature against the one passed in the query
|
213 |
+
$ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
|
214 |
+
|
215 |
+
// Release the key resource
|
216 |
+
openssl_free_key($publickeyid);
|
217 |
+
|
218 |
+
return $ok == 1;
|
219 |
+
}
|
220 |
+
}
|
221 |
+
|
222 |
+
class OAuthRequest {
|
223 |
+
private $parameters;
|
224 |
+
private $http_method;
|
225 |
+
private $http_url;
|
226 |
+
// for debug purposes
|
227 |
+
public $base_string;
|
228 |
+
public static $version = '1.0';
|
229 |
+
public static $POST_INPUT = 'php://input';
|
230 |
+
|
231 |
+
function __construct($http_method, $http_url, $parameters=NULL) {
|
232 |
+
@$parameters or $parameters = array();
|
233 |
+
$parameters = array_merge( OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
|
234 |
+
$this->parameters = $parameters;
|
235 |
+
$this->http_method = $http_method;
|
236 |
+
$this->http_url = $http_url;
|
237 |
+
}
|
238 |
+
|
239 |
+
|
240 |
+
/**
|
241 |
+
* attempt to build up a request from what was passed to the server
|
242 |
+
*/
|
243 |
+
public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) {
|
244 |
+
$scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
|
245 |
+
? 'http'
|
246 |
+
: 'https';
|
247 |
+
@$http_url or $http_url = $scheme .
|
248 |
+
'://' . $_SERVER['HTTP_HOST'] .
|
249 |
+
':' .
|
250 |
+
$_SERVER['SERVER_PORT'] .
|
251 |
+
$_SERVER['REQUEST_URI'];
|
252 |
+
@$http_method or $http_method = $_SERVER['REQUEST_METHOD'];
|
253 |
+
|
254 |
+
// We weren't handed any parameters, so let's find the ones relevant to
|
255 |
+
// this request.
|
256 |
+
// If you run XML-RPC or similar you should use this to provide your own
|
257 |
+
// parsed parameter-list
|
258 |
+
if (!$parameters) {
|
259 |
+
// Find request headers
|
260 |
+
$request_headers = OAuthUtil::get_headers();
|
261 |
+
|
262 |
+
// Parse the query-string to find GET parameters
|
263 |
+
$parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);
|
264 |
+
|
265 |
+
// It's a POST request of the proper content-type, so parse POST
|
266 |
+
// parameters and add those overriding any duplicates from GET
|
267 |
+
if ($http_method == "POST"
|
268 |
+
&& @strstr($request_headers["Content-Type"],
|
269 |
+
"application/x-www-form-urlencoded")
|
270 |
+
) {
|
271 |
+
$post_data = OAuthUtil::parse_parameters(
|
272 |
+
file_get_contents(self::$POST_INPUT)
|
273 |
+
);
|
274 |
+
$parameters = array_merge($parameters, $post_data);
|
275 |
+
}
|
276 |
+
|
277 |
+
// We have a Authorization-header with OAuth data. Parse the header
|
278 |
+
// and add those overriding any duplicates from GET or POST
|
279 |
+
if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") {
|
280 |
+
$header_parameters = OAuthUtil::split_header(
|
281 |
+
$request_headers['Authorization']
|
282 |
+
);
|
283 |
+
$parameters = array_merge($parameters, $header_parameters);
|
284 |
+
}
|
285 |
+
|
286 |
+
}
|
287 |
+
|
288 |
+
return new OAuthRequest($http_method, $http_url, $parameters);
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* pretty much a helper function to set up the request
|
293 |
+
*/
|
294 |
+
public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) {
|
295 |
+
@$parameters or $parameters = array();
|
296 |
+
$defaults = array("oauth_version" => OAuthRequest::$version,
|
297 |
+
"oauth_nonce" => OAuthRequest::generate_nonce(),
|
298 |
+
"oauth_timestamp" => OAuthRequest::generate_timestamp(),
|
299 |
+
"oauth_consumer_key" => $consumer->key);
|
300 |
+
if ($token)
|
301 |
+
$defaults['oauth_token'] = $token->key;
|
302 |
+
|
303 |
+
$parameters = array_merge($defaults, $parameters);
|
304 |
+
|
305 |
+
return new OAuthRequest($http_method, $http_url, $parameters);
|
306 |
+
}
|
307 |
+
|
308 |
+
public function set_parameter($name, $value, $allow_duplicates = true) {
|
309 |
+
if ($allow_duplicates && isset($this->parameters[$name])) {
|
310 |
+
// We have already added parameter(s) with this name, so add to the list
|
311 |
+
if (is_scalar($this->parameters[$name])) {
|
312 |
+
// This is the first duplicate, so transform scalar (string)
|
313 |
+
// into an array so we can add the duplicates
|
314 |
+
$this->parameters[$name] = array($this->parameters[$name]);
|
315 |
+
}
|
316 |
+
|
317 |
+
$this->parameters[$name][] = $value;
|
318 |
+
} else {
|
319 |
+
$this->parameters[$name] = $value;
|
320 |
+
}
|
321 |
+
}
|
322 |
+
|
323 |
+
public function get_parameter($name) {
|
324 |
+
return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
|
325 |
+
}
|
326 |
+
|
327 |
+
public function get_parameters() {
|
328 |
+
return $this->parameters;
|
329 |
+
}
|
330 |
+
|
331 |
+
public function unset_parameter($name) {
|
332 |
+
unset($this->parameters[$name]);
|
333 |
+
}
|
334 |
+
|
335 |
+
/**
|
336 |
+
* The request parameters, sorted and concatenated into a normalized string.
|
337 |
+
* @return string
|
338 |
+
*/
|
339 |
+
public function get_signable_parameters() {
|
340 |
+
// Grab all parameters
|
341 |
+
$params = $this->parameters;
|
342 |
+
|
343 |
+
// Remove oauth_signature if present
|
344 |
+
// Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
|
345 |
+
if (isset($params['oauth_signature'])) {
|
346 |
+
unset($params['oauth_signature']);
|
347 |
+
}
|
348 |
+
|
349 |
+
return OAuthUtil::build_http_query($params);
|
350 |
+
}
|
351 |
+
|
352 |
+
/**
|
353 |
+
* Returns the base string of this request
|
354 |
+
*
|
355 |
+
* The base string defined as the method, the url
|
356 |
+
* and the parameters (normalized), each urlencoded
|
357 |
+
* and the concated with &.
|
358 |
+
*/
|
359 |
+
public function get_signature_base_string() {
|
360 |
+
$parts = array(
|
361 |
+
$this->get_normalized_http_method(),
|
362 |
+
$this->get_normalized_http_url(),
|
363 |
+
$this->get_signable_parameters()
|
364 |
+
);
|
365 |
+
|
366 |
+
$parts = OAuthUtil::urlencode_rfc3986($parts);
|
367 |
+
|
368 |
+
return implode('&', $parts);
|
369 |
+
}
|
370 |
+
|
371 |
+
/**
|
372 |
+
* just uppercases the http method
|
373 |
+
*/
|
374 |
+
public function get_normalized_http_method() {
|
375 |
+
return strtoupper($this->http_method);
|
376 |
+
}
|
377 |
+
|
378 |
+
/**
|
379 |
+
* parses the url and rebuilds it to be
|
380 |
+
* scheme://host/path
|
381 |
+
*/
|
382 |
+
public function get_normalized_http_url() {
|
383 |
+
$parts = parse_url($this->http_url);
|
384 |
+
|
385 |
+
$port = @$parts['port'];
|
386 |
+
$scheme = $parts['scheme'];
|
387 |
+
$host = $parts['host'];
|
388 |
+
$path = @$parts['path'];
|
389 |
+
|
390 |
+
$port or $port = ($scheme == 'https') ? '443' : '80';
|
391 |
+
|
392 |
+
if (($scheme == 'https' && $port != '443')
|
393 |
+
|| ($scheme == 'http' && $port != '80')) {
|
394 |
+
$host = "$host:$port";
|
395 |
+
}
|
396 |
+
return "$scheme://$host$path";
|
397 |
+
}
|
398 |
+
|
399 |
+
/**
|
400 |
+
* builds a url usable for a GET request
|
401 |
+
*/
|
402 |
+
public function to_url() {
|
403 |
+
$post_data = $this->to_postdata();
|
404 |
+
$out = $this->get_normalized_http_url();
|
405 |
+
if ($post_data) {
|
406 |
+
$out .= '?'.$post_data;
|
407 |
+
}
|
408 |
+
return $out;
|
409 |
+
}
|
410 |
+
|
411 |
+
/**
|
412 |
+
* builds the data one would send in a POST request
|
413 |
+
*/
|
414 |
+
public function to_postdata() {
|
415 |
+
return OAuthUtil::build_http_query($this->parameters);
|
416 |
+
}
|
417 |
+
|
418 |
+
/**
|
419 |
+
* builds the Authorization: header
|
420 |
+
*/
|
421 |
+
public function to_header($realm=null) {
|
422 |
+
$first = true;
|
423 |
+
if($realm) {
|
424 |
+
$out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"';
|
425 |
+
$first = false;
|
426 |
+
} else
|
427 |
+
$out = 'Authorization: OAuth';
|
428 |
+
|
429 |
+
$total = array();
|
430 |
+
foreach ($this->parameters as $k => $v) {
|
431 |
+
if (substr($k, 0, 5) != "oauth") continue;
|
432 |
+
if (is_array($v)) {
|
433 |
+
throw new OAuthException('Arrays not supported in headers');
|
434 |
+
}
|
435 |
+
$out .= ($first) ? ' ' : ',';
|
436 |
+
$out .= OAuthUtil::urlencode_rfc3986($k) .
|
437 |
+
'="' .
|
438 |
+
OAuthUtil::urlencode_rfc3986($v) .
|
439 |
+
'"';
|
440 |
+
$first = false;
|
441 |
+
}
|
442 |
+
return $out;
|
443 |
+
}
|
444 |
+
|
445 |
+
public function __toString() {
|
446 |
+
return $this->to_url();
|
447 |
+
}
|
448 |
+
|
449 |
+
|
450 |
+
public function sign_request($signature_method, $consumer, $token) {
|
451 |
+
$this->set_parameter(
|
452 |
+
"oauth_signature_method",
|
453 |
+
$signature_method->get_name(),
|
454 |
+
false
|
455 |
+
);
|
456 |
+
$signature = $this->build_signature($signature_method, $consumer, $token);
|
457 |
+
$this->set_parameter("oauth_signature", $signature, false);
|
458 |
+
}
|
459 |
+
|
460 |
+
public function build_signature($signature_method, $consumer, $token) {
|
461 |
+
$signature = $signature_method->build_signature($this, $consumer, $token);
|
462 |
+
return $signature;
|
463 |
+
}
|
464 |
+
|
465 |
+
/**
|
466 |
+
* util function: current timestamp
|
467 |
+
*/
|
468 |
+
private static function generate_timestamp() {
|
469 |
+
return time();
|
470 |
+
}
|
471 |
+
|
472 |
+
/**
|
473 |
+
* util function: current nonce
|
474 |
+
*/
|
475 |
+
private static function generate_nonce() {
|
476 |
+
$mt = microtime();
|
477 |
+
$rand = mt_rand();
|
478 |
+
|
479 |
+
return md5($mt . $rand); // md5s look nicer than numbers
|
480 |
+
}
|
481 |
+
}
|
482 |
+
|
483 |
+
class OAuthServer {
|
484 |
+
protected $timestamp_threshold = 300; // in seconds, five minutes
|
485 |
+
protected $version = '1.0'; // hi blaine
|
486 |
+
protected $signature_methods = array();
|
487 |
+
|
488 |
+
protected $data_store;
|
489 |
+
|
490 |
+
function __construct($data_store) {
|
491 |
+
$this->data_store = $data_store;
|
492 |
+
}
|
493 |
+
|
494 |
+
public function add_signature_method($signature_method) {
|
495 |
+
$this->signature_methods[$signature_method->get_name()] =
|
496 |
+
$signature_method;
|
497 |
+
}
|
498 |
+
|
499 |
+
// high level functions
|
500 |
+
|
501 |
+
/**
|
502 |
+
* process a request_token request
|
503 |
+
* returns the request token on success
|
504 |
+
*/
|
505 |
+
public function fetch_request_token(&$request) {
|
506 |
+
$this->get_version($request);
|
507 |
+
|
508 |
+
$consumer = $this->get_consumer($request);
|
509 |
+
|
510 |
+
// no token required for the initial token request
|
511 |
+
$token = NULL;
|
512 |
+
|
513 |
+
$this->check_signature($request, $consumer, $token);
|
514 |
+
|
515 |
+
// Rev A change
|
516 |
+
$callback = $request->get_parameter('oauth_callback');
|
517 |
+
$new_token = $this->data_store->new_request_token($consumer, $callback);
|
518 |
+
|
519 |
+
return $new_token;
|
520 |
+
}
|
521 |
+
|
522 |
+
/**
|
523 |
+
* process an access_token request
|
524 |
+
* returns the access token on success
|
525 |
+
*/
|
526 |
+
public function fetch_access_token(&$request) {
|
527 |
+
$this->get_version($request);
|
528 |
+
|
529 |
+
$consumer = $this->get_consumer($request);
|
530 |
+
|
531 |
+
// requires authorized request token
|
532 |
+
$token = $this->get_token($request, $consumer, "request");
|
533 |
+
|
534 |
+
$this->check_signature($request, $consumer, $token);
|
535 |
+
|
536 |
+
// Rev A change
|
537 |
+
$verifier = $request->get_parameter('oauth_verifier');
|
538 |
+
$new_token = $this->data_store->new_access_token($token, $consumer, $verifier);
|
539 |
+
|
540 |
+
return $new_token;
|
541 |
+
}
|
542 |
+
|
543 |
+
/**
|
544 |
+
* verify an api call, checks all the parameters
|
545 |
+
*/
|
546 |
+
public function verify_request(&$request) {
|
547 |
+
$this->get_version($request);
|
548 |
+
$consumer = $this->get_consumer($request);
|
549 |
+
$token = $this->get_token($request, $consumer, "access");
|
550 |
+
$this->check_signature($request, $consumer, $token);
|
551 |
+
return array($consumer, $token);
|
552 |
+
}
|
553 |
+
|
554 |
+
// Internals from here
|
555 |
+
/**
|
556 |
+
* version 1
|
557 |
+
*/
|
558 |
+
private function get_version(&$request) {
|
559 |
+
$version = $request->get_parameter("oauth_version");
|
560 |
+
if (!$version) {
|
561 |
+
// Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
|
562 |
+
// Chapter 7.0 ("Accessing Protected Ressources")
|
563 |
+
$version = '1.0';
|
564 |
+
}
|
565 |
+
if ($version !== $this->version) {
|
566 |
+
throw new OAuthException("OAuth version '$version' not supported");
|
567 |
+
}
|
568 |
+
return $version;
|
569 |
+
}
|
570 |
+
|
571 |
+
/**
|
572 |
+
* figure out the signature with some defaults
|
573 |
+
*/
|
574 |
+
private function get_signature_method(&$request) {
|
575 |
+
$signature_method =
|
576 |
+
@$request->get_parameter("oauth_signature_method");
|
577 |
+
|
578 |
+
if (!$signature_method) {
|
579 |
+
// According to chapter 7 ("Accessing Protected Ressources") the signature-method
|
580 |
+
// parameter is required, and we can't just fallback to PLAINTEXT
|
581 |
+
throw new OAuthException('No signature method parameter. This parameter is required');
|
582 |
+
}
|
583 |
+
|
584 |
+
if (!in_array($signature_method,
|
585 |
+
array_keys($this->signature_methods))) {
|
586 |
+
throw new OAuthException(
|
587 |
+
"Signature method '$signature_method' not supported " .
|
588 |
+
"try one of the following: " .
|
589 |
+
implode(", ", array_keys($this->signature_methods))
|
590 |
+
);
|
591 |
+
}
|
592 |
+
return $this->signature_methods[$signature_method];
|
593 |
+
}
|
594 |
+
|
595 |
+
/**
|
596 |
+
* try to find the consumer for the provided request's consumer key
|
597 |
+
*/
|
598 |
+
private function get_consumer(&$request) {
|
599 |
+
$consumer_key = @$request->get_parameter("oauth_consumer_key");
|
600 |
+
if (!$consumer_key) {
|
601 |
+
throw new OAuthException("Invalid consumer key");
|
602 |
+
}
|
603 |
+
|
604 |
+
$consumer = $this->data_store->lookup_consumer($consumer_key);
|
605 |
+
if (!$consumer) {
|
606 |
+
throw new OAuthException("Invalid consumer");
|
607 |
+
}
|
608 |
+
|
609 |
+
return $consumer;
|
610 |
+
}
|
611 |
+
|
612 |
+
/**
|
613 |
+
* try to find the token for the provided request's token key
|
614 |
+
*/
|
615 |
+
private function get_token(&$request, $consumer, $token_type="access") {
|
616 |
+
$token_field = @$request->get_parameter('oauth_token');
|
617 |
+
$token = $this->data_store->lookup_token(
|
618 |
+
$consumer, $token_type, $token_field
|
619 |
+
);
|
620 |
+
if (!$token) {
|
621 |
+
throw new OAuthException("Invalid $token_type token: $token_field");
|
622 |
+
}
|
623 |
+
return $token;
|
624 |
+
}
|
625 |
+
|
626 |
+
/**
|
627 |
+
* all-in-one function to check the signature on a request
|
628 |
+
* should guess the signature method appropriately
|
629 |
+
*/
|
630 |
+
private function check_signature(&$request, $consumer, $token) {
|
631 |
+
// this should probably be in a different method
|
632 |
+
$timestamp = @$request->get_parameter('oauth_timestamp');
|
633 |
+
$nonce = @$request->get_parameter('oauth_nonce');
|
634 |
+
|
635 |
+
$this->check_timestamp($timestamp);
|
636 |
+
$this->check_nonce($consumer, $token, $nonce, $timestamp);
|
637 |
+
|
638 |
+
$signature_method = $this->get_signature_method($request);
|
639 |
+
|
640 |
+
$signature = $request->get_parameter('oauth_signature');
|
641 |
+
$valid_sig = $signature_method->check_signature(
|
642 |
+
$request,
|
643 |
+
$consumer,
|
644 |
+
$token,
|
645 |
+
$signature
|
646 |
+
);
|
647 |
+
|
648 |
+
if (!$valid_sig) {
|
649 |
+
throw new OAuthException("Invalid signature");
|
650 |
+
}
|
651 |
+
}
|
652 |
+
|
653 |
+
/**
|
654 |
+
* check that the timestamp is new enough
|
655 |
+
*/
|
656 |
+
private function check_timestamp($timestamp) {
|
657 |
+
if( ! $timestamp )
|
658 |
+
throw new OAuthException(
|
659 |
+
'Missing timestamp parameter. The parameter is required'
|
660 |
+
);
|
661 |
+
|
662 |
+
// verify that timestamp is recentish
|
663 |
+
$now = time();
|
664 |
+
if (abs($now - $timestamp) > $this->timestamp_threshold) {
|
665 |
+
throw new OAuthException(
|
666 |
+
"Expired timestamp, yours $timestamp, ours $now"
|
667 |
+
);
|
668 |
+
}
|
669 |
+
}
|
670 |
+
|
671 |
+
/**
|
672 |
+
* check that the nonce is not repeated
|
673 |
+
*/
|
674 |
+
private function check_nonce($consumer, $token, $nonce, $timestamp) {
|
675 |
+
if( ! $nonce )
|
676 |
+
throw new OAuthException(
|
677 |
+
'Missing nonce parameter. The parameter is required'
|
678 |
+
);
|
679 |
+
|
680 |
+
// verify that the nonce is uniqueish
|
681 |
+
$found = $this->data_store->lookup_nonce(
|
682 |
+
$consumer,
|
683 |
+
$token,
|
684 |
+
$nonce,
|
685 |
+
$timestamp
|
686 |
+
);
|
687 |
+
if ($found) {
|
688 |
+
throw new OAuthException("Nonce already used: $nonce");
|
689 |
+
}
|
690 |
+
}
|
691 |
+
|
692 |
+
}
|
693 |
+
|
694 |
+
class OAuthDataStore {
|
695 |
+
function lookup_consumer($consumer_key) {
|
696 |
+
// implement me
|
697 |
+
}
|
698 |
+
|
699 |
+
function lookup_token($consumer, $token_type, $token) {
|
700 |
+
// implement me
|
701 |
+
}
|
702 |
+
|
703 |
+
function lookup_nonce($consumer, $token, $nonce, $timestamp) {
|
704 |
+
// implement me
|
705 |
+
}
|
706 |
+
|
707 |
+
function new_request_token($consumer, $callback = null) {
|
708 |
+
// return a new token attached to this consumer
|
709 |
+
}
|
710 |
+
|
711 |
+
function new_access_token($token, $consumer, $verifier = null) {
|
712 |
+
// return a new access token attached to this consumer
|
713 |
+
// for the user associated with this token if the request token
|
714 |
+
// is authorized
|
715 |
+
// should also invalidate the request token
|
716 |
+
}
|
717 |
+
|
718 |
+
}
|
719 |
+
|
720 |
+
class OAuthUtil {
|
721 |
+
public static function urlencode_rfc3986($input) {
|
722 |
+
if (is_array($input)) {
|
723 |
+
return array_map(array('OAuthUtil', 'urlencode_rfc3986'), $input);
|
724 |
+
} else if (is_scalar($input)) {
|
725 |
+
return str_replace(
|
726 |
+
'+',
|
727 |
+
' ',
|
728 |
+
str_replace('%7E', '~', rawurlencode($input))
|
729 |
+
);
|
730 |
+
} else {
|
731 |
+
return '';
|
732 |
+
}
|
733 |
+
}
|
734 |
+
|
735 |
+
|
736 |
+
// This decode function isn't taking into consideration the above
|
737 |
+
// modifications to the encoding process. However, this method doesn't
|
738 |
+
// seem to be used anywhere so leaving it as is.
|
739 |
+
public static function urldecode_rfc3986($string) {
|
740 |
+
return urldecode($string);
|
741 |
+
}
|
742 |
+
|
743 |
+
// Utility function for turning the Authorization: header into
|
744 |
+
// parameters, has to do some unescaping
|
745 |
+
// Can filter out any non-oauth parameters if needed (default behaviour)
|
746 |
+
public static function split_header($header, $only_allow_oauth_parameters = true) {
|
747 |
+
$pattern = '/(([-_a-z]*)=("([^"]*)"|([^,]*)),?)/';
|
748 |
+
$offset = 0;
|
749 |
+
$params = array();
|
750 |
+
while (preg_match($pattern, $header, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) {
|
751 |
+
$match = $matches[0];
|
752 |
+
$header_name = $matches[2][0];
|
753 |
+
$header_content = (isset($matches[5])) ? $matches[5][0] : $matches[4][0];
|
754 |
+
if (preg_match('/^oauth_/', $header_name) || !$only_allow_oauth_parameters) {
|
755 |
+
$params[$header_name] = OAuthUtil::urldecode_rfc3986($header_content);
|
756 |
+
}
|
757 |
+
$offset = $match[1] + strlen($match[0]);
|
758 |
+
}
|
759 |
+
|
760 |
+
if (isset($params['realm'])) {
|
761 |
+
unset($params['realm']);
|
762 |
+
}
|
763 |
+
|
764 |
+
return $params;
|
765 |
+
}
|
766 |
+
|
767 |
+
// helper to try to sort out headers for people who aren't running apache
|
768 |
+
public static function get_headers() {
|
769 |
+
if (function_exists('apache_request_headers')) {
|
770 |
+
// we need this to get the actual Authorization: header
|
771 |
+
// because apache tends to tell us it doesn't exist
|
772 |
+
$headers = apache_request_headers();
|
773 |
+
|
774 |
+
// sanitize the output of apache_request_headers because
|
775 |
+
// we always want the keys to be Cased-Like-This and arh()
|
776 |
+
// returns the headers in the same case as they are in the
|
777 |
+
// request
|
778 |
+
$out = array();
|
779 |
+
foreach( $headers AS $key => $value ) {
|
780 |
+
$key = str_replace(
|
781 |
+
" ",
|
782 |
+
"-",
|
783 |
+
ucwords(strtolower(str_replace("-", " ", $key)))
|
784 |
+
);
|
785 |
+
$out[$key] = $value;
|
786 |
+
}
|
787 |
+
} else {
|
788 |
+
// otherwise we don't have apache and are just going to have to hope
|
789 |
+
// that $_SERVER actually contains what we need
|
790 |
+
$out = array();
|
791 |
+
if( isset($_SERVER['CONTENT_TYPE']) )
|
792 |
+
$out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
|
793 |
+
if( isset($_ENV['CONTENT_TYPE']) )
|
794 |
+
$out['Content-Type'] = $_ENV['CONTENT_TYPE'];
|
795 |
+
|
796 |
+
foreach ($_SERVER as $key => $value) {
|
797 |
+
if (substr($key, 0, 5) == "HTTP_") {
|
798 |
+
// this is chaos, basically it is just there to capitalize the first
|
799 |
+
// letter of every word that is not an initial HTTP and strip HTTP
|
800 |
+
// code from przemek
|
801 |
+
$key = str_replace(
|
802 |
+
" ",
|
803 |
+
"-",
|
804 |
+
ucwords(strtolower(str_replace("_", " ", substr($key, 5))))
|
805 |
+
);
|
806 |
+
$out[$key] = $value;
|
807 |
+
}
|
808 |
+
}
|
809 |
+
}
|
810 |
+
return $out;
|
811 |
+
}
|
812 |
+
|
813 |
+
// This function takes a input like a=b&a=c&d=e and returns the parsed
|
814 |
+
// parameters like this
|
815 |
+
// array('a' => array('b','c'), 'd' => 'e')
|
816 |
+
public static function parse_parameters( $input ) {
|
817 |
+
if (!isset($input) || !$input) return array();
|
818 |
+
|
819 |
+
$pairs = explode('&', $input);
|
820 |
+
|
821 |
+
$parsed_parameters = array();
|
822 |
+
foreach ($pairs as $pair) {
|
823 |
+
$split = explode('=', $pair, 2);
|
824 |
+
$parameter = OAuthUtil::urldecode_rfc3986($split[0]);
|
825 |
+
$value = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : '';
|
826 |
+
|
827 |
+
if (isset($parsed_parameters[$parameter])) {
|
828 |
+
// We have already recieved parameter(s) with this name, so add to the list
|
829 |
+
// of parameters with this name
|
830 |
+
|
831 |
+
if (is_scalar($parsed_parameters[$parameter])) {
|
832 |
+
// This is the first duplicate, so transform scalar (string) into an array
|
833 |
+
// so we can add the duplicates
|
834 |
+
$parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
|
835 |
+
}
|
836 |
+
|
837 |
+
$parsed_parameters[$parameter][] = $value;
|
838 |
+
} else {
|
839 |
+
$parsed_parameters[$parameter] = $value;
|
840 |
+
}
|
841 |
+
}
|
842 |
+
return $parsed_parameters;
|
843 |
+
}
|
844 |
+
|
845 |
+
public static function build_http_query($params) {
|
846 |
+
if (!$params) return '';
|
847 |
+
|
848 |
+
// Urlencode both keys and values
|
849 |
+
$keys = OAuthUtil::urlencode_rfc3986(array_keys($params));
|
850 |
+
$values = OAuthUtil::urlencode_rfc3986(array_values($params));
|
851 |
+
$params = array_combine($keys, $values);
|
852 |
+
|
853 |
+
// Parameters are sorted by name, using lexicographical byte value ordering.
|
854 |
+
// Ref: Spec: 9.1.1 (1)
|
855 |
+
uksort($params, 'strcmp');
|
856 |
+
|
857 |
+
$pairs = array();
|
858 |
+
foreach ($params as $parameter => $value) {
|
859 |
+
if (is_array($value)) {
|
860 |
+
// If two or more parameters share the same name, they are sorted by their value
|
861 |
+
// Ref: Spec: 9.1.1 (1)
|
862 |
+
natsort($value);
|
863 |
+
foreach ($value as $duplicate_value) {
|
864 |
+
$pairs[] = $parameter . '=' . $duplicate_value;
|
865 |
+
}
|
866 |
+
} else {
|
867 |
+
$pairs[] = $parameter . '=' . $value;
|
868 |
+
}
|
869 |
+
}
|
870 |
+
// For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
|
871 |
+
// Each name-value pair is separated by an '&' character (ASCII code 38)
|
872 |
+
return implode('&', $pairs);
|
873 |
+
}
|
874 |
+
}
|
trunk/twitteroauth/twitteroauth.php
ADDED
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Abraham Williams (abraham@abrah.am) http://abrah.am
|
5 |
+
*
|
6 |
+
* The first PHP Library to support OAuth for Twitter's REST API.
|
7 |
+
*/
|
8 |
+
|
9 |
+
/* Load OAuth lib. You can find it at http://oauth.net */
|
10 |
+
require_once('OAuth.php');
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Twitter OAuth class
|
14 |
+
*/
|
15 |
+
class TwitterOAuth {
|
16 |
+
/* Contains the last HTTP status code returned. */
|
17 |
+
public $http_code;
|
18 |
+
/* Contains the last API call. */
|
19 |
+
public $url;
|
20 |
+
/* Set up the API root URL. */
|
21 |
+
public $host = "https://api.twitter.com/1.1/";
|
22 |
+
/* Set timeout default. */
|
23 |
+
public $timeout = 30;
|
24 |
+
/* Set connect timeout. */
|
25 |
+
public $connecttimeout = 30;
|
26 |
+
/* Verify SSL Cert. */
|
27 |
+
public $ssl_verifypeer = FALSE;
|
28 |
+
/* Respons format. */
|
29 |
+
public $format = 'json';
|
30 |
+
/* Decode returned json data. */
|
31 |
+
public $decode_json = TRUE;
|
32 |
+
/* Contains the last HTTP headers returned. */
|
33 |
+
public $http_info;
|
34 |
+
/* Set the useragnet. */
|
35 |
+
public $useragent = 'TwitterOAuth v0.2.0-beta2';
|
36 |
+
/* Immediately retry the API call if the response was not successful. */
|
37 |
+
//public $retry = TRUE;
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Set API URLS
|
44 |
+
*/
|
45 |
+
function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; }
|
46 |
+
function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; }
|
47 |
+
function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; }
|
48 |
+
function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Debug helpers
|
52 |
+
*/
|
53 |
+
function lastStatusCode() { return $this->http_status; }
|
54 |
+
function lastAPICall() { return $this->last_api_call; }
|
55 |
+
|
56 |
+
/**
|
57 |
+
* construct TwitterOAuth object
|
58 |
+
*/
|
59 |
+
function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
|
60 |
+
$this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
|
61 |
+
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
|
62 |
+
if (!empty($oauth_token) && !empty($oauth_token_secret)) {
|
63 |
+
$this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
|
64 |
+
} else {
|
65 |
+
$this->token = NULL;
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Get a request_token from Twitter
|
72 |
+
*
|
73 |
+
* @returns a key/value array containing oauth_token and oauth_token_secret
|
74 |
+
*/
|
75 |
+
function getRequestToken($oauth_callback) {
|
76 |
+
$parameters = array();
|
77 |
+
$parameters['oauth_callback'] = $oauth_callback;
|
78 |
+
$request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
|
79 |
+
$token = OAuthUtil::parse_parameters($request);
|
80 |
+
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
|
81 |
+
return $token;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Get the authorize URL
|
86 |
+
*
|
87 |
+
* @returns a string
|
88 |
+
*/
|
89 |
+
function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
|
90 |
+
if (is_array($token)) {
|
91 |
+
$token = $token['oauth_token'];
|
92 |
+
}
|
93 |
+
if (empty($sign_in_with_twitter)) {
|
94 |
+
return $this->authorizeURL() . "?oauth_token={$token}";
|
95 |
+
} else {
|
96 |
+
return $this->authenticateURL() . "?oauth_token={$token}";
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Exchange request token and secret for an access token and
|
102 |
+
* secret, to sign API calls.
|
103 |
+
*
|
104 |
+
* @returns array("oauth_token" => "the-access-token",
|
105 |
+
* "oauth_token_secret" => "the-access-secret",
|
106 |
+
* "user_id" => "9436992",
|
107 |
+
* "screen_name" => "abraham")
|
108 |
+
*/
|
109 |
+
function getAccessToken($oauth_verifier) {
|
110 |
+
$parameters = array();
|
111 |
+
$parameters['oauth_verifier'] = $oauth_verifier;
|
112 |
+
$request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
|
113 |
+
$token = OAuthUtil::parse_parameters($request);
|
114 |
+
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
|
115 |
+
return $token;
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* One time exchange of username and password for access token and secret.
|
120 |
+
*
|
121 |
+
* @returns array("oauth_token" => "the-access-token",
|
122 |
+
* "oauth_token_secret" => "the-access-secret",
|
123 |
+
* "user_id" => "9436992",
|
124 |
+
* "screen_name" => "abraham",
|
125 |
+
* "x_auth_expires" => "0")
|
126 |
+
*/
|
127 |
+
function getXAuthToken($username, $password) {
|
128 |
+
$parameters = array();
|
129 |
+
$parameters['x_auth_username'] = $username;
|
130 |
+
$parameters['x_auth_password'] = $password;
|
131 |
+
$parameters['x_auth_mode'] = 'client_auth';
|
132 |
+
$request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
|
133 |
+
$token = OAuthUtil::parse_parameters($request);
|
134 |
+
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
|
135 |
+
return $token;
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* GET wrapper for oAuthRequest.
|
140 |
+
*/
|
141 |
+
function get($url, $parameters = array()) {
|
142 |
+
$response = $this->oAuthRequest($url, 'GET', $parameters);
|
143 |
+
if ($this->format === 'json' && $this->decode_json) {
|
144 |
+
return json_decode($response);
|
145 |
+
}
|
146 |
+
return $response;
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* POST wrapper for oAuthRequest.
|
151 |
+
*/
|
152 |
+
function post($url, $parameters = array()) {
|
153 |
+
$response = $this->oAuthRequest($url, 'POST', $parameters);
|
154 |
+
if ($this->format === 'json' && $this->decode_json) {
|
155 |
+
return json_decode($response);
|
156 |
+
}
|
157 |
+
return $response;
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* DELETE wrapper for oAuthReqeust.
|
162 |
+
*/
|
163 |
+
function delete($url, $parameters = array()) {
|
164 |
+
$response = $this->oAuthRequest($url, 'DELETE', $parameters);
|
165 |
+
if ($this->format === 'json' && $this->decode_json) {
|
166 |
+
return json_decode($response);
|
167 |
+
}
|
168 |
+
return $response;
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Format and sign an OAuth / API request
|
173 |
+
*/
|
174 |
+
function oAuthRequest($url, $method, $parameters) {
|
175 |
+
if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
|
176 |
+
$url = "{$this->host}{$url}.{$this->format}";
|
177 |
+
}
|
178 |
+
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
|
179 |
+
$request->sign_request($this->sha1_method, $this->consumer, $this->token);
|
180 |
+
switch ($method) {
|
181 |
+
case 'GET':
|
182 |
+
return $this->http($request->to_url(), 'GET');
|
183 |
+
default:
|
184 |
+
return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
|
185 |
+
}
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* Make an HTTP request
|
190 |
+
*
|
191 |
+
* @return API results
|
192 |
+
*/
|
193 |
+
function http($url, $method, $postfields = NULL) {
|
194 |
+
$this->http_info = array();
|
195 |
+
$ci = curl_init();
|
196 |
+
/* Curl settings */
|
197 |
+
curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
|
198 |
+
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
|
199 |
+
curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
|
200 |
+
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
|
201 |
+
curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
|
202 |
+
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
|
203 |
+
curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
|
204 |
+
curl_setopt($ci, CURLOPT_HEADER, FALSE);
|
205 |
+
|
206 |
+
switch ($method) {
|
207 |
+
case 'POST':
|
208 |
+
curl_setopt($ci, CURLOPT_POST, TRUE);
|
209 |
+
if (!empty($postfields)) {
|
210 |
+
curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
|
211 |
+
}
|
212 |
+
break;
|
213 |
+
case 'DELETE':
|
214 |
+
curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
215 |
+
if (!empty($postfields)) {
|
216 |
+
$url = "{$url}?{$postfields}";
|
217 |
+
}
|
218 |
+
}
|
219 |
+
|
220 |
+
curl_setopt($ci, CURLOPT_URL, $url);
|
221 |
+
$response = curl_exec($ci);
|
222 |
+
$this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
|
223 |
+
$this->http_info = array_merge($this->http_info, curl_getinfo($ci));
|
224 |
+
$this->url = $url;
|
225 |
+
curl_close ($ci);
|
226 |
+
return $response;
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Get the header info to store.
|
231 |
+
*/
|
232 |
+
function getHeader($ch, $header) {
|
233 |
+
$i = strpos($header, ':');
|
234 |
+
if (!empty($i)) {
|
235 |
+
$key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
|
236 |
+
$value = trim(substr($header, $i + 2));
|
237 |
+
$this->http_header[$key] = $value;
|
238 |
+
}
|
239 |
+
return strlen($header);
|
240 |
+
}
|
241 |
+
}
|