Commit 32ff4b5d authored by lucha's avatar lucha Committed by lechuck
Browse files

pulizie di primavera: rimossi plugin obsoleti e non usati

parent 0bb7bb9d
=== Selective status list ===
Contributors: publicvoid
Tags: twitter, tweets, status, filtered
Requires at least: 2.8
Tested up to: 2.8.4
Stable tag: 0.3
Widget shows list of tweets from specified user which are marked by a specified keyword.
== Description ==
The plugin provides a widget, which shows a list of tweets from the specified author, filtered by a specified hashtag. User name and hashtag are customizable. The plugin uses AJAX to fetch status notices, hence it does'nt work for users without javascript enabled at the moment, but keeps the page load small.
== Installation ==
1. Upload the 'selectiv-tweet-list.php' and 'selective-tweet-list.js' to your '/wp-content/plugins/' directory
1. Alternatively use your wordpress installations plugin install functions in the admin area
1. Activate the plugin through the 'Plugins' menu in WordPress
1. Drag the widget to the sidebar and fill in your desired settings (microblogging service, user name, filter hashtag, )
== Frequently Asked Questions ==
= Why are no tweets showing up? =
Make sure your user screen name is right. Check whether you have tweets containing your specified keyword in your timeline. Verify that the number of tweets fetched is set high enought to include some of those. You can check your settings by typing http://twitter.com/statuses/user_timeline.xml?screen_name=<your_screen_name>&count=<number_of_tweets_fetched> in your browsers address bar and see whether there are matching tweets.
= What about identi.ca, caching and status digests? =
Coming soon.
== Changelog ==
= 0.1 =
Initial release
= 0.2 =
- improved input validation and escaping
- use twitter search api
- allow querying status.net (identi.ca) api - usertime line batch fetching
= 0.3 =
bug fixes: widget layout, js path
/*
Part of Selective tweet list plugin for wordpress
Check out this plugin: http://wordpress.org/extend/plugins/selective-tweets/
*/
var selectiveTweetList = {
init : function(params) {
for (var p in params) {
this[p] = params[p];
}
this.pagesFetched = 0;
this.tweetsGrabbed = 0;
var searchQuery = "from:" + encodeURIComponent(this.twitterName) + "+" + encodeURIComponent(this.marker);
this.baseUrl = this.statusNet ?
"http://identi.ca/api/statuses/user_timeline.json?callback=selectiveTweetList.batchGrabTweets&count=" + Math.min(this.count*5, 200) + "&screen_name=" + encodeURIComponent(this.twitterName) :
"http://search.twitter.com/search.json?callback=selectiveTweetList.searchGrabTweets&q=" + searchQuery + "&rpp=" + this.count;
this.requestJSON();
},
requestJSON : function() {
this.pagesFetched++;
var script = document.createElement("script");
script.src = this.baseUrl + "&page=" + this.pagesFetched;
document.body.appendChild(script);
},
searchGrabTweets : function(response) {
if (response.error) {
this.makeListEntry("tweetlist", this.errorText);
} else {
for ( var tweet = 0; tweet<response.results.length; tweet++) {
this.makeListEntry("tweetlist", response.results[tweet].text.replace(this.marker, ""));
}
}
},
batchGrabTweets : function(data) {
if (data.error) {
this.makeListEntry("tweetlist", this.errorText);
} else {
this.grabTweets(data);
if(this.tweetsGrabbed<this.count && this.pagesFetched < 10) { this.requestJSON(); }
}
},
grabTweets : function(data) {
for ( var tweet = 0; tweet<data.length && this.tweetsGrabbed<this.count; tweet++) {
tweetstext = data[tweet].text;
var markerRegExp = new RegExp(this.marker);
if (tweetstext.search(markerRegExp) >= 0) {
this.tweetsGrabbed++;
this.makeListEntry("tweetlist", tweetstext.replace(markerRegExp, ""));
}
}
},
makeListEntry : function(listId, txt) {
var findUrl = /(http:\/\/\S*)/g;
var foundUrl;
var lastMatch = 0;
var entry = document.createElement("li");
var urlTxt = txt.replace(findUrl, '<a href="$1">$1</a>');
entry.innerHTML = urlTxt;
document.getElementById(this.listId).appendChild(entry);
}
}
<?php
/*
Plugin Name: Selective tweet list
Plugin URI: http://wordpress.org/extend/plugins/selective-tweets/
Description: Widget shows list of tweets from specified user which are marked by a specified keyword.
Version: 0.3
Author: publicvoid
Author URI: http://wordpress.org/extend/plugins/profile/publicvoid
*/
add_action('widgets_init', create_function('', 'return register_widget("Selective_Status_Widget");'));
class Selective_Status_Widget extends WP_Widget {
function Selective_Status_Widget() {
$widget_ops = array(
'description' => 'Shows statuses from specified user which are marked by a special keyword.'
);
$this->WP_Widget( 'selective-status', 'Selective Status', $widget_ops);
}
function form($instance) {
// show the options form
$defaults = array(
'twitter_name' => 'myname',
'selection_marker' => '#wp',
'tweets_count' => 7,
'list_title' => 'Selective tweet status',
'noscript_hint' => 'This list can only be shown with javascript switched on.',
'twitter_error' => 'Error in status api, list could not be fetched.',
'status_net' => false
);
$instance = wp_parse_args( (array) $instance, $defaults );
$texts = array(
"twitter_name"=> array(
"title"=>"user name",
"hint"=>"micro blogging user name to be used to fetch the statuses"),
"selection_marker"=> array(
"title"=>"selection marker",
"hint"=>"used to mark tweets that should be included into the list"),
"tweets_count" => array(
"title"=>"tweets count",
"hint"=>"number of tweets to be fetched from twitter (max. 100)"),
"list_title" => array(
"title"=>"list title",
"hint"=>"header of the selective tweets list"),
"noscript_hint" => array(
"title"=>"noscript hint",
"hint"=>"This hint will be shown for users with javascript switched off."),
"twitter_error"=> array(
"title"=>"twitter error message",
"hint"=>"This message will be shown, when twitter is not reachable and fetching data leeds to an error")
);
$field_name = $this->get_field_name("status_net");
$field_id = $this->get_field_id("status_net");
?>
<p>
<label title="which microblogging service you want to be queried">microblogging service:</label><br/>
<input id="<?php echo $field_id; ?>1" type="radio" name="<?php echo $field_name; ?>" value="twitter" <?php checked( $instance['status_net'], false ); ?>/> Twitter
<input id="<?php echo $field_id; ?>2" type="radio" name="<?php echo $field_name; ?>" value="status" <?php checked( $instance['status_net'], true ); ?> /> Identi.ca
</p>
<?php
foreach ($texts as $key => $texts) {
$field_id = $this->get_field_id($key);
$field_name = $this->get_field_name($key); ?>
<p>
<label for="<?php echo $field_id; ?>" title="<?php echo $texts['hint']; ?>" ><?php echo $texts['title']; ?>:</label>
<input id="<?php echo $field_id; ?>" name="<?php echo $field_name; ?>" value="<?php echo $instance[$key]; ?>" style="width:100%;" />
</p>
<?php
}
}
function update($new_instance, $old_instance) {
// update settings from options
$instance = $old_instance;
foreach (array('twitter_name','selection_marker','list_title','noscript_hint','twitter_error') as $field) {
$instance[$field] = strip_tags($new_instance[$field]);
}
$instance['status_net'] = ($new_instance['status_net']=="status");
$instance['tweets_count'] = min( intval($new_instance['tweets_count']), 100 );
// 100 is the max results per page (rpp) value for twitters search api and should definitly be enough (so we need to only fetch one page)
return $instance;
}
function widget($args, $instance) {
// actually displays the widget
extract($args);
$list_title = apply_filters('widget_title', $instance['list_title'] );
echo $before_widget;
echo $before_title . $list_title . $after_title; ?>
<ul id="tweetlist">
<noscript><li><?php echo $instance['noscript_hint']; ?></li></noscript>
</ul>
<!-- // TODO ? wp_enqueue_script, don't load multiple times +++ use a proper library for status api requests -->
<script src="wp-content/plugins/selective-tweets/selective-tweet-list.js"></script>
<script>selectiveTweetList.init({
"marker": "<?php echo esc_js($instance['selection_marker']); ?>",
"twitterName": "<?php echo esc_js($instance['twitter_name']); ?>",
"count": <?php echo $instance['tweets_count']; ?>,
"errorText" : "<?php echo esc_js($instance['twitter_error']); ?>",
"listId": "tweetlist",
"statusNet": <?php echo $instance['status_net'] ? 'true' : 'false'; ?>
});</script>
<?php echo $after_widget;
}
}
?>
<?php
// vim: foldmethod=marker
if (!class_exists('OAuthException')) {
/* Generic exception class
*/
class OAuthException extends Exception {
// pass
}
class OAuthConsumer {
public $key;
public $secret;
function __construct($key, $secret, $callback_url=NULL) {
$this->key = $key;
$this->secret = $secret;
$this->callback_url = $callback_url;
}
function __toString() {
return "OAuthConsumer[key=$this->key,secret=$this->secret]";
}
}
class OAuthToken {
// access tokens and request tokens
public $key;
public $secret;
/**
* key = the token
* secret = the token secret
*/
function __construct($key, $secret) {
$this->key = $key;
$this->secret = $secret;
}
/**
* generates the basic string serialization of a token that a server
* would respond to request_token and access_token calls with
*/
function to_string() {
return "oauth_token=" .
OAuthUtil::urlencode_rfc3986($this->key) .
"&oauth_token_secret=" .
OAuthUtil::urlencode_rfc3986($this->secret);
}
function __toString() {
return $this->to_string();
}
}
/**
* A class for implementing a Signature Method
* See section 9 ("Signing Requests") in the spec
*/
abstract class OAuthSignatureMethod {
/**
* Needs to return the name of the Signature Method (ie HMAC-SHA1)
* @return string
*/
abstract public function get_name();
/**
* Build up the signature
* NOTE: The output of this function MUST NOT be urlencoded.
* the encoding is handled in OAuthRequest when the final
* request is serialized
* @param OAuthRequest $request
* @param OAuthConsumer $consumer
* @param OAuthToken $token
* @return string
*/
abstract public function build_signature($request, $consumer, $token);
/**
* Verifies that a given signature is correct
* @param OAuthRequest $request
* @param OAuthConsumer $consumer
* @param OAuthToken $token
* @param string $signature
* @return bool
*/
public function check_signature($request, $consumer, $token, $signature) {
$built = $this->build_signature($request, $consumer, $token);
return $built == $signature;
}
}
/**
* The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
* where the Signature Base String is the text and the key is the concatenated values (each first
* encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
* character (ASCII code 38) even if empty.
* - Chapter 9.2 ("HMAC-SHA1")
*/
class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod {
function get_name() {
return "HMAC-SHA1";
}
public function build_signature($request, $consumer, $token) {
$base_string = $request->get_signature_base_string();
$request->base_string = $base_string;
$key_parts = array(
$consumer->secret,
($token) ? $token->secret : ""
);
$key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
$key = implode('&', $key_parts);
return base64_encode(hash_hmac('sha1', $base_string, $key, true));
}
}
/**
* The PLAINTEXT method does not provide any security protection and SHOULD only be used
* over a secure channel such as HTTPS. It does not use the Signature Base String.
* - Chapter 9.4 ("PLAINTEXT")
*/
class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod {
public function get_name() {
return "PLAINTEXT";
}
/**
* oauth_signature is set to the concatenated encoded values of the Consumer Secret and
* Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
* empty. The result MUST be encoded again.
* - Chapter 9.4.1 ("Generating Signatures")
*
* Please note that the second encoding MUST NOT happen in the SignatureMethod, as
* OAuthRequest handles this!
*/
public function build_signature($request, $consumer, $token) {
$key_parts = array(
$consumer->secret,
($token) ? $token->secret : ""
);
$key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
$key = implode('&', $key_parts);
$request->base_string = $key;
return $key;
}
}
/**
* The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in
* [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for
* EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a
* verified way to the Service Provider, in a manner which is beyond the scope of this
* specification.
* - Chapter 9.3 ("RSA-SHA1")
*/
abstract class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod {
public function get_name() {
return "RSA-SHA1";
}
// Up to the SP to implement this lookup of keys. Possible ideas are:
// (1) do a lookup in a table of trusted certs keyed off of consumer
// (2) fetch via http using a url provided by the requester
// (3) some sort of specific discovery code based on request
//
// Either way should return a string representation of the certificate
protected abstract function fetch_public_cert(&$request);
// Up to the SP to implement this lookup of keys. Possible ideas are:
// (1) do a lookup in a table of trusted certs keyed off of consumer
//
// Either way should return a string representation of the certificate
protected abstract function fetch_private_cert(&$request);
public function build_signature($request, $consumer, $token) {
$base_string = $request->get_signature_base_string();
$request->base_string = $base_string;
// Fetch the private key cert based on the request
$cert = $this->fetch_private_cert($request);
// Pull the private key ID from the certificate
$privatekeyid = openssl_get_privatekey($cert);
// Sign using the key
$ok = openssl_sign($base_string, $signature, $privatekeyid);
// Release the key resource
openssl_free_key($privatekeyid);
return base64_encode($signature);
}
public function check_signature($request, $consumer, $token, $signature) {
$decoded_sig = base64_decode($signature);
$base_string = $request->get_signature_base_string();
// Fetch the public key cert based on the request
$cert = $this->fetch_public_cert($request);
// Pull the public key ID from the certificate
$publickeyid = openssl_get_publickey($cert);
// Check the computed signature against the one passed in the query
$ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
// Release the key resource
openssl_free_key($publickeyid);
return $ok == 1;
}
}
class OAuthRequest {
private $parameters;
private $http_method;
private $http_url;
// for debug purposes
public $base_string;
public static $version = '1.0';
public static $POST_INPUT = 'php://input';
function __construct($http_method, $http_url, $parameters=NULL) {
@$parameters or $parameters = array();
$parameters = array_merge( OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
$this->parameters = $parameters;
$this->http_method = $http_method;
$this->http_url = $http_url;
}
/**
* attempt to build up a request from what was passed to the server
*/
public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) {
$scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
? 'http'
: 'https';
@$http_url or $http_url = $scheme .
'://' . $_SERVER['HTTP_HOST'] .
':' .
$_SERVER['SERVER_PORT'] .
$_SERVER['REQUEST_URI'];
@$http_method or $http_method = $_SERVER['REQUEST_METHOD'];
// We weren't handed any parameters, so let's find the ones relevant to
// this request.
// If you run XML-RPC or similar you should use this to provide your own
// parsed parameter-list
if (!$parameters) {
// Find request headers
$request_headers = OAuthUtil::get_headers();
// Parse the query-string to find GET parameters
$parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);
// It's a POST request of the proper content-type, so parse POST
// parameters and add those overriding any duplicates from GET
if ($http_method == "POST"
&& @strstr($request_headers["Content-Type"],
"application/x-www-form-urlencoded")
) {
$post_data = OAuthUtil::parse_parameters(
file_get_contents(self::$POST_INPUT)
);
$parameters = array_merge($parameters, $post_data);
}
// We have a Authorization-header with OAuth data. Parse the header
// and add those overriding any duplicates from GET or POST
if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") {
$header_parameters = OAuthUtil::split_header(
$request_headers['Authorization']
);
$parameters = array_merge($parameters, $header_parameters);
}
}
return new OAuthRequest($http_method, $http_url, $parameters);
}
/**
* pretty much a helper function to set up the request
*/
public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) {
@$parameters or $parameters = array();
$defaults = array("oauth_version" => OAuthRequest::$version,
"oauth_nonce" => OAuthRequest::generate_nonce(),
"oauth_timestamp" => OAuthRequest::generate_timestamp(),
"oauth_consumer_key" => $consumer->key);
if ($token)
$defaults['oauth_token'] = $token->key;
$parameters = array_merge($defaults, $parameters);
return new OAuthRequest($http_method, $http_url, $parameters);
}
public function set_parameter($name, $value, $allow_duplicates = true) {
if ($allow_duplicates && isset($this->parameters[$name])) {
// We have already added parameter(s) with this name, so add to the list
if (is_scalar($this->parameters[$name])) {
// This is the first duplicate, so transform scalar (string)
// into an array so we can add the duplicates
$this->parameters[$name] = array($this->parameters[$name]);
}
$this->parameters[$name][] = $value;
} else {
$this->parameters[$name] = $value;
}
}
public function get_parameter($name) {
return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
}
public function get_parameters() {
return $this->parameters;
}
public function unset_parameter($name) {
unset($this->parameters[$name]);
}
/**
* The request parameters, sorted and concatenated into a normalized string.
* @return string
*/
public function get_signable_parameters() {
// Grab all parameters
$params = $this->parameters;
// Remove oauth_signature if present
// Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
if (isset($params['oauth_signature'])) {
unset($params['oauth_signature']);
}
return OAuthUtil::build_http_query($params);
}
/**
* Returns the base string of this request
*