Skip to content
Snippets Groups Projects
Commit a58796a0 authored by root's avatar root Committed by lechuck
Browse files

Adding plugin selective-tweets

parent b4e54486
No related branches found
No related tags found
No related merge requests found
=== 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;
}
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment