<?php
class FriendFeed {
var $user_, $feed_;
private static $verbs_ = array(
'googlereader' => 'Shared <a href="%s">“%s”</a> on Google Reader.',
'twitter' => '<a href="%s">Tweeted</a> “%s”.',
'amazon' => 'Added <a href="%s">“%s”</a> to my wishlist on Amazon.',
'youtube' => 'Added <a href="%s">“%s”</a> to favorites on YouTube.',
'flickr' => 'Added <a href="%s">“%s”</a> to favorites on Flickr.',
'delicious' => 'Bookmarked <a href="%s">“%s”</a> on Del.icio.us.',
'facebook' => 'Wrote a note on Facebook: <a href="%s">“%s”</a>.',
'blog' => '<strong>Posted a blog entry, <a href="%s">“%s”</a></strong>.'
);
public function __construct($cache, $user, $howMany = 100) {
$this->cache_ = $cache;
$this->user_ = $user;
$friendfeedJson = $this->cache_->get(
sprintf("http://friendfeed.com/api/feed/user/%s?format=json&start=0&num=%d",
urlencode($this->user_),
$howMany));
$this->feed_ = json_decode($friendfeedJson);
}
public function getEntries($howMany = 10) {
$entries = array();
$count = 0;
foreach ($this->feed_->entries as $id => $entry) {
if ("twitter" === $entry->service->id) continue;
if (++$count > $howMany) break;
$verb = isset(FriendFeed::$verbs_[$entry->service->id])
? FriendFeed::$verbs_[$entry->service->id]
: 'Shared <a href="%s">“%s”</a> on ' . $entry->service->name . '.';
$linkifiedTitle = preg_replace("/http:\/\/(.*?)\/[^ ]*/",
'<a href="\\0">\\0</a>', $entry->title);
$entries[] = sprintf($verb, $entry->link, $linkifiedTitle);
}
return $entries;
}
}
?>