Skip to content

Instantly share code, notes, and snippets.

@brandondove
Created July 18, 2016 20:37
Show Gist options
  • Save brandondove/1c93d75ec18907b2429efdf25da9fc87 to your computer and use it in GitHub Desktop.
Save brandondove/1c93d75ec18907b2429efdf25da9fc87 to your computer and use it in GitHub Desktop.
Twitter Stream Patch for PHP 5.5 compatibility
diff --git a/wp-content/plugins/twitter-stream/twitter-stream.php b/wp-content/plugins/twitter-stream/twitter-stream.php
index 7e7df60..29f5bb0 100644
--- a/wp-content/plugins/twitter-stream/twitter-stream.php
+++ b/wp-content/plugins/twitter-stream/twitter-stream.php
@@ -301,9 +301,9 @@ function twitter_stream($args = FALSE) {
//Now let's do some highlighting & auto linking.
//Find all the @replies and place them in a span so CSS can be used to highlight them.
- $output = preg_replace('~(\@[a-z0-9_]+)~ise', "'<span class=\"at-reply\"><a href=\"http://twitter.com/'.substr('$1', 1).'\" title=\"View '.substr('$1', 1).'\'s profile\">$1</a></span>'", $output);
+ $output = preg_replace_callback( '~(\@[a-z0-9_]+)~is', 'twitter_stream_reply_wrap', $output );
//Find all the #tags and place them in a span so CSS can be used to highlight them.
- $output = preg_replace('~(\#[a-z0-9_]+)~ise', "'<span class=\"hash-tag\"><a href=\"http://twitter.com/search?q='.urlencode('$1').'\" title=\"Search for $1 on Twitter\">$1</a></span>'", $output);
+ $output = preg_replace_callback( '~(\#[a-z0-9_]+)~is', 'twitter_stream_hashtag_wrap', $output );
//Show follower count
if($r['show_followers']) {
@@ -317,6 +317,24 @@ function twitter_stream($args = FALSE) {
}
+function twitter_stream_reply_wrap( $match ) {
+ return sprintf(
+ '<span class="at-reply"><a href="http://twitter.com/%s" title="View %s\'s profile">%s</a></span>',
+ esc_attr( substr( $match[1], 1 ) ),
+ esc_attr( substr( $match[1], 1 ) ),
+ esc_html( $match[1] )
+ );
+}
+
+function twitter_stream_hashtag_wrap( $match ) {
+ return sprintf(
+ '<span class="hash-tag"><a href="http://twitter.com/search?q=%s" title="Search for %s on Twitter">%s</a></span>',
+ esc_attr( urlencode( $match[1] ) ),
+ esc_html( $match[1] ),
+ esc_html( $match[1] )
+ );
+}
+
function twitter_stream_cache($modtime, $cache_path, $cache_time) {
$thirtyago = time() - $cache_time; //the timestamp thirty minutes ago
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment