function twitterBadge($userEmail, $userPassword, $count = 4) { $json = new Services_JSON(); // Create the twitter Cacher object to pull feed // Password is needed in case feed is protected // HTTP Basic Auth hasn't been deprecated...yet...so...lazy wins for now $tc = new TwitterCacher($userEmail, $userPassword); $tc->setUserAgent("Mozilla/5.0 (compatible; TwitterCacher/1.0; +http://www.kolich.com)"); //echo '<!-- ' . $tc->getUserTimeline(4) . ' -->'; //Create a timeline object of the feed (pull from live if old) $timeline = $json->decode($tc->getUserTimeline($count)); if (!$timeline) { return '<p>Error locating tweets.</p>'; } // Create unorderer list of tweets (see gagawa module) $ul = new Ol(); foreach ($timeline as $tweet) { $text = $tweet->text; //Format date as 5 min ago, 2 hours ago, etc. $date = distance_of_time_in_words(strtotime($tweet->created_at)) . ' ago'; // Tweet source, i.e. twhril, tweetie, tweetdeck, etc. // $source = $tweet->source; // Generate direct link to tweet $tweetid = $tweet->id; $screenname = $tweet->user->screen_name; $tweetlink = 'http://twitter.com/' . $screenname . '/status/' . $tweetid; // Turn links into links $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\\+.~#?&//=]+)', '<a href="\\1" target="_blank">\\1</a>', $text); // Turn twitter @username into links to the users Twitter page $text = preg_replace('/(^|\\s)@(\\w+)/', '\\1<a href="http://www.twitter.com/\\2">@\\2</a>', $text); // Turn #hashtags into searches $text = preg_replace('/(^|\\s)#(\\w+)/', '\\1<a href="http://search.twitter.com/search?q=%23\\2">#\\2</a>', $text); // Personal Formatting, see Gagawa for documentaiton. // <li>Tweet Text <span>(<a href="linktotweet">some time ago</a>)<span></li> $li = new Li(); $ul->appendChild($li); $li->appendChild(new Text($text . ' (')); $span = new Span(); $link = new A(); $link->setHref($tweetlink); $link->appendChild(new Text($date)); $span->appendChild($link); $li->appendChild($span); $li->appendChild(new Text(')')); } //end foreach( $timeline as $tweet ) // Returns the stack of li's enclosed by ul return $ul->write(); }
<div class="box" id="donateNow"> <a href="https://co.clickandpledge.com/default.aspx?wid=24445">Donate Now!</a> </div> <div class="box" id="twitterFeed"> <h2>Radio Arte Is</h2> <?php require_once "TwitterCacher.php"; require_once "TimeAgo.php"; $twEmail = "radioarte"; $twPass = "******"; $tc = new TwitterCacher($twEmail, $twPass); // I do this just to be a nice guy. So Twitter knows who we are. $tc->setUserAgent("Mozilla/5.0 (compatible; TwitterCacher/1.0;)"); // Read the timeline from the cache, or from Twitter. $timeline = json_decode($tc->getUserTimeline()); // Get the Tweet itself. $text = $timeline[0]->text; // Twitter uses GMT+0 but I convert it to my local time. $date = TimeAgo(strtotime($timeline[0]->created_at)); ?> <p><?php echo $text; ?> <a href="http://twitter.com/<?php echo $timeline[0]->user->screen_name; ?> /status/<?php echo $timeline[0]->id; ?>