Skip to content

Instantly share code, notes, and snippets.

@msenateatplos
Created September 21, 2012 22:46
Show Gist options
  • Save msenateatplos/3764348 to your computer and use it in GitHub Desktop.
Save msenateatplos/3764348 to your computer and use it in GitHub Desktop.
Patch to improve multi-twitter-widget for wordpress
http://wordpress.org/extend/plugins/multi-twitter-widget/
I needed to display the twitter stream for several accounts, as well as display an account with the results of a search query. This plugin seemed to do the trick, but there were a couple of bugs, so I tweaked it a bit, the code is below. My patch includes:
<ul>
<li>Improvement to the `$tweet preg_replace` to add proper links for account tweets</li>
<li>A "multi-twitter" css class to `<ul>` for customized styling</li>
<li>Renamed indeces and loop used in "// Split array and output results" to avoid confusion / naming conflict. Also improved formatting by making screenname and search result tweets consistent in display.
<li>Fixed display of human_time for search results</li>
</ul>
Index: multi-twitter-widget/widget.php
===================================================================
--- multi-twitter-widget/widget.php (revision 3527)
+++ multi-twitter-widget/widget.php (working copy)
@@ -140,7 +140,7 @@
$tweet = preg_replace('/(^|\s)#(\w+)/', '\1#<a href="http://search.twitter.com/search?q=%23\2">\2</a>', $tweet);
if( $options['links'] )
- $tweet = preg_replace('#(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)#is', '\\1\\2', $tweet);
+ $tweet = preg_replace('#(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)#is', '\1<a href="\2">\2</a>', $tweet);
return $tweet;
}
@@ -197,7 +197,7 @@
$widget['term_limit'] = 5;
}
- $output .= '<ul>';
+ $output .= '<ul class="multi-twitter">';
// Parse the accounts and CRUD cache
foreach ( $accounts as $account )
@@ -326,20 +326,27 @@
}
// Sort our $feeds array
- usort($feeds, "feed_sort");
+ //usort($feeds, "feed_sort");
// Split array and output results
- $i = 1;
+ $sn_index = 0;
+ $term_index = 0;
foreach ( $feeds as $feed )
{
- if ( $feed->screen_name != '' AND $i <= $widget['user_limit'] )
+ if ( $feed->screen_name != '' AND $sn_index <= $widget['user_limit'] )
{
$output .=
'<li class="clearfix">'.
'<a href="http://twitter.com/'.$feed->screen_name.'">'.
- '<img class="twitter-avatar" src="'.$feed->profile_image_url.'" width="40" height="40" alt="'.$feed->screen_name.'" />'.
- $feed->screen_name.': </a>'.format_tweet($feed->status->text, $widget).'<br />';
+ '<img class="twitter-avatar" src="'
+ .$feed->profile_image_url
+ .'" width="40" height="40" alt="'
+ .$feed->screen_name.'" />'
+ .$feed->screen_name
+ .':</a> '
+ .format_tweet($feed->status->text, $widget)
+ .'<br />';
if ( $widget['date'] )
{
@@ -348,7 +355,8 @@
$output .= '</li>';
}
- else if ( preg_match('/search.twitter.com/i', $feed->id) AND $i <= $widget['term_limit'] )
+ $sn_index++;
+ if ( preg_match('/search.twitter.com/i', $feed->id) AND $term_index <= $widget['term_limit'] )
{
$count = count($feed->entry);
@@ -363,20 +371,20 @@
'src="'.$feed->entry[$i]->link[1]->attributes()->href.'" '.
'width="40" height="40" '.
'alt="'.$feed->entry[$i]->author->name.'" />'.
- '<strong>'.$feed->entry[$i]->author->name.':</strong>'.
- '</a>'.
+ $feed->entry[$i]->author->name.
+ '</a>: '.
format_tweet($feed->entry[$i]->content, $widget).
'<br />';
if ( $widget['date'] )
{
- $output .= '<em>'.human_time(strtotime($feed->status->created_at)).'</em>';
+ $output .= '<em>'.human_time(strtotime($feed->updated)).'</em>';
}
$output .= '</li>';
- }
+ }
}
- }
- $i++;
+ }
+ $term_index++;
}
$output .= '</ul>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment