tag It takes retweets into account and then updates links within the tweet text to convert urls, tags, and hashes into anchor tags it is based slightly on a script found here: http:stackoverflow.com/questions/11533214/php-how-to-use-the-twitter-apis-data-to-convert-urls-mentions-and-hastags-in#answer-11929224 --------------------------------------------------------------------------*/ function parse_message($tweet) { if(!empty($tweet['entities'])) { if(count($tweet['retweeted_status'])) { $new_tweet = $tweet['retweeted_status']['text']; $ent_array = $tweet['retweeted_status']['entities']; } else { $new_tweet = $tweet['text']; $ent_array = $tweet['entities']; } foreach($ent_array as $area => $items) { switch($area) { case 'hashtags': foreach($items as $item) { $find = 'text'; $prefix = '#'; $url = 'http://twitter.com/search/?src=hash&q=%23'; get_new_tweet($find, $prefix, $url, $item, $new_tweet); } break; case 'user_mentions': foreach($items as $item) { $find = 'screen_name'; $prefix = '@'; $url = 'https://twitter.com/'; get_new_tweet($find, $prefix, $url, $item, $new_tweet); } break; case 'media': case 'urls': foreach($items as $item) { $find = 'url'; $prefix = ''; $url = ''; get_new_tweet($find, $prefix, $url, $item, $new_tweet); } break; default: break; } } } return $new_tweet; } function get_new_tweet($find, $prefix, $url, $item, $new_tweet) { $string = $item[$find]; $href = $url . $string; $start = $item['indices'][0]; $stop = $item['indices'][1]; $replace = $prefix . $string; $with = '' . $prefix . $string .''; $new_tweet = str_replace($replace, $with, $new_tweet); } $local_tweets = ''; //check for cache from 15 minutes ago if(get_transient('jled_tweets_short')) { $local_tweets = get_transient('jled_tweets_short'); //if it isn't found, try to update tweets } else { $tweets = getTweets(3); //if Twitter returned results if(count($tweets)) { //loop through it and output tweets foreach ($tweets as $entry) { $text = parse_message($entry); $date = date('g:i A - j M y', strtotime($entry['created_at'])); $id = $entry['id']; $local_tweets .= '
' . '

' . $text . '

' . '

' . $date . '

' . '
'; } //reset our 15 min and 1 day caches set_transient('jled_tweets_long', $local_tweets, 60 * 60 * 24 * 1); set_transient('jled_tweets_short', $local_tweets, 60 * 15); //if Twitter didn't respond } else { //check for the 1 day cache if(get_transient('jled_tweets_long')) { $local_tweets = get_transient('jled_tweets_long'); //if we can't find that, respond with an error message } else { $local_tweets = '

No tweets at this time.

'; } } } ?>