<?php
class Buzz {
var $user_, $feed_;
private static $verbs_ = array(
'twitter' => 'Tweeted “%s”',
'google reader' => 'Shared “%s” on Google Reader.',
'youtube' => 'Added “%s” to favorites on YouTube.',
'flickr' => 'Added “%s” to favorites on Flickr.',
'blog' => '<strong>Posted a blog entry, “%s”</strong>.'
);
public function __construct($cache, $user) {
$this->cache_ = $cache;
$this->user_ = $user;
$url = sprintf('https://www.googleapis.com/buzz/v1/activities/%s/@public?alt=json',
urlencode($this->user_));
$buzzJson = $this->cache_->get($url);
$this->feed_ = json_decode($buzzJson);
}
public function getItems($howMany = 10) {
$items = array();
$count = 0;
foreach ($this->feed_->data->items as $id => $item) {
if (++$count > $howMany) break;
$title = str_replace('<br />', '—', $item->object->content);
$source = strtolower($item->source->title);
$verb = isset(Buzz::$verbs_[$source])
? Buzz::$verbs_[$source]
: 'Shared %s on ' . $source;
$items[] = sprintf($verb, $title);
}
return $items;
}
}
?>