'alexmoss',
"mode" => 'feed',
"other" => '',
"num" => '5',
"img" => 'yes',
"imgclass" => '',
"auth" => 'no',
"encoding" => '',
"term" => 'twitter',
"hashtag" => 'WordPress',
"followlink" => 'yes',
"searchlink" => 'yes',
"anchor" => '',
"userlinks" => 'yes',
"hashlinks" => 'yes',
"timeline" => 'yes',
"smalltime" => 'yes',
"smalltimeclass" => '',
"conditional" => 'yes',
"tprefix" => '(about',
"tsecs" => 'seconds',
"tmin" => 'minutes',
"tmins" => 'minutes',
"thour" => 'hour',
"thours" => 'hours',
"tday" => 'day',
"tdays" => 'days',
"tsuffix" => 'ago)',
"phptime" => 'j F Y \a\t h:ia',
"linktotweet" => 'yes',
"divid" => '',
"ulclass" => '',
"liclass" => '',
"linklove" => 'yes',
), $atts));
//MODES
if ($mode == "fav") { $twitter_rss = "http://twitter.com/favorites/".$username.".atom?rpp=".$num; }
if ($mode == "feed") {
if ($other == "yes") {
$twitter_rss = "http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=".$username."&count=".$num;
$img="no";
} else {
$twitter_rss = "http://search.twitter.com/search.rss?q=from%3A".$username."&rpp=".$num;
}
}
if ($mode == "mentions") { $twitter_rss = "http://search.twitter.com/search.rss?q=%40".$username."&rpp=".$num; }
if ($mode == "retweets") { $twitter_rss = "http://search.twitter.com/search.rss?q=RT%20%40".$username."&rpp=".$num; }
if ($mode == "public") { $twitter_rss = "http://search.twitter.com/search.rss?q=".$username."&rpp=".$num; }
if ($mode == "hashtag") { $twitter_rss = "http://search.twitter.com/search.rss?q=%23".$hashtag."&rpp=".$num; }
if ($mode == "search") { $twitter_rss = "http://search.twitter.com/search.rss?q=".$term."&rpp=".$num; }
//SETUP FEED
include_once(ABSPATH . WPINC . '/feed.php');
$rss = fetch_feed($twitter_rss);
if ( is_wp_error( $rss ) ) {
$wholetweet = 'The connection to twitter has returned an error. Please try again later.
';
} else {
$maxitems = $rss->get_item_quantity($num);
$rss_items = $rss->get_items(0, $maxitems);
ob_start();
$now = time();
$page = get_bloginfo('url');
//START OUTPUT
if ($divid != "") {
$divstart = "
\n";
$divend = "
";
}
if ($ulclass != "") {
$ulstart = "";
} else {
$ulstart = "";
}
//POPULATE TWEET
foreach ( $rss_items as $item ) {
if ($mode == "fav") {
$tweet = $item->get_description();
} else {
$tweet = $item->get_title();
}
if ($encoding == "fix") {$tweet = htmlentities($tweet);}
if ($page != "") {if (!strpos($tweet, $page) === false) {continue;}}
$when = ($now - strtotime($item->get_date()));
$posted = "";
if ($timeline != "no") {
$when = ($now - strtotime($item->get_date()));
$posted = "";
if ($conditional == "yes") {
if ($when < 60) {
$posted = $tprefix." ".$when." ".$tsecs." ".$tsuffix;
}
if (($posted == "") & ($when < 3600)) {
$posted = $tprefix." ".(floor($when / 60))." ".$tmins." ".$tsuffix;
}
if (($posted == "") & ($when < 7200)) {
$posted = $tprefix." 1 ".$thour." ".$tsuffix;
}
if (($posted == "") & ($when < 86400)) {
$posted = $tprefix." ".(floor($when / 3600))." ".$thours." ".$tsuffix;
}
if (($posted == "") & ($when < 172800)) {
$posted = $tprefix." 1 ".$tday." ".$tsuffix;
}
if ($posted == "") {
$posted = $tprefix." ".(floor($when / 86400))." ".$tdays." ".$tsuffix;
}
} else {
$date = date($phptime, strtotime($item->get_date()));
$posted = $date;
}
$entry = $entry."\n
".$pubtext.$posted;
}
if ($anchor == "") {
$tweet = preg_replace("/(http:\/\/)(.*?)\/([\w\.\/\&\=\?\-\,\:\;\#\_\~\%\+]*)/", "\\0", $tweet);
} else {
$tweet = preg_replace("/(http:\/\/)(.*?)\/([\w\.\/\&\=\?\-\,\:\;\#\_\~\%\+]*)/", "".$anchor."", $tweet);
}
if ($mode != "fav") {
//SETUP SPECIAL ATTRIBUTES
$author_tag = $item->get_item_tags('','author');
$author = $author_tag[0]['data'];
$author = substr($author, 0, stripos($author, "@") );
if ($other != "yes"){$tweet = "@".$author.": ".$tweet;}
if ($img == "yes"){
$avatar_tag = $item->get_item_tags('http://base.google.com/ns/1.0','image_link');
$avatar = $avatar_tag[0]['data'];
if ($imgclass == "") {
$preimgclass = "style=\"";
$imgclass = "float: left;";
} else {
$preimgclass = "class=\"";
}
$avatar = "
";
if ( $userlinks == "yes" ) {
$avatar = "";
}
}
} else {
$tweet = "@".$tweet;
}
if ($auth == "no") {
if ($other != "yes"){
$tweet = preg_replace("(@([a-zA-Z0-9\_]+))", "", $tweet, 1);
$tweet =substr($tweet, 2);
} else {
$tweet = preg_replace("(([a-zA-Z0-9\_]+):)", "", $tweet, 1);
}
} else {
if ($other == "yes"){$tweet = preg_replace("(([a-zA-Z0-9\_]+))", "\\1", $tweet, 1);}
}
if ( $userlinks == "yes" ) {
$tweet = preg_replace("(@([a-zA-Z0-9\_]+))", "\\0", $tweet);
}
if ( $hashlinks == "yes" ) {
$tweet = preg_replace("(#([a-zA-Z0-9\_]+))", "\\0", $tweet);
}
if ($timeline == "yes") {
if ($linktotweet == "yes") {
if ($smalltime == "yes") {
if ($smalltimeclass == "") {
$presmalltimeclass = "style=\"";
$smalltimeclass = "font-size: 85%;";
} else {
$presmalltimeclass = "class=\"";
}
$posted = "
".$posted."";
$smalltimeclass='';
}
$tweet = $tweet."\nget_permalink()."\" rel=\"external nofollow\">".$posted."";
} else {
$tweet = $tweet."
(".$posted.")";
}
}
if ($liclass != ""){
$entry = "\n- ".$avatar.$tweet."
";
} else {
$entry = "\n- ".$avatar.$tweet."
";
}
$wholetweet = $wholetweet."".$entry;
$imgclass='';
}
}
ob_end_flush();
if ($followlink == "yes"){
if ($mode == "feed" || $mode == "mentions" || $mode == "retweets" || $mode == "public") {
$linktofeed = ("follow ".$username." on twitter
\n");
}
if ($mode == "fav") {
$linktofeed = ("view all favourites for ".$username."
\n");
}
if ($mode == "search") {
$linktofeed = ("view search results for \"".$term."\" on twitter
\n");
}
if ($mode == "hashtag") {
$linktofeed = ("view search results for \"#".$hashtag."\" on twitter
\n");
}
}
if ($linklove != "no"){ $pleer = "\nPowered by Twitter Feed
\n"; }
$whole = "\n\n".$divstart.$ulstart.$wholetweet."\n
\n".$linktofeed.$pleer.$divend."\n";
return $whole;
}
add_filter( 'wp_feed_cache_transient_lifetime', create_function( '$a', 'return 3;' ) );
add_filter('widget_text', 'do_shortcode');
add_shortcode('twitter-feed', 'Twitterfeedreader');
remove_filter('wp_feed_cache_transient_lifetime', create_function( '$a', 'return 3;' ));
?>