/** * @return array */ public function populateItemTemplate(&$item) { $comments_count = $item->children('http://purl.org/rss/1.0/modules/slash/')->comments; $content = $item->children('http://purl.org/rss/1.0/modules/content/')->encoded; $tags = ''; // pull tags out and make links of them foreach ($item->category as $t) { $tags .= '<li class="tag"><a href="' . $t->attributes() . htmlspecialchars($t) . '">' . htmlspecialchars($t) . '</a></li>'; } if ($tags != '') { $tags = '<ul class="tags">' . $tags . '<li>Tagged:</li></ul>'; } return array('link' => htmlspecialchars($item->link), 'title' => trim($item->title), 'date' => Pubwich::time_since($item->pubDate), 'comments_link' => $item->comments, 'comments_count' => $comments_count, 'description' => $item->description, 'content' => $content, 'author' => $item->author, 'tags' => $tags); }
/** * Return a date in a relative format * Based on: http://snippets.dzone.com/posts/show/5565 * * @param $original Date timestamp * @return string */ public static function time_since($original) { $original = strtotime($original); $chunks = array(array(60 * 60 * 24 * 365, Pubwich::_('year')), array(60 * 60 * 24 * 30, Pubwich::_('month')), array(60 * 60 * 24 * 7, Pubwich::_('week')), array(60 * 60 * 24, Pubwich::_('day')), array(60 * 60, Pubwich::_('hour')), array(60, Pubwich::_('minute'))); $today = time(); $since = $today - $original; if ($since < 0) { return sprintf(Pubwich::_('just moments ago'), $since); } if ($since < 60) { return sprintf(Pubwich::_('%d seconds ago'), $since); } if ($since > 7 * 24 * 60 * 60) { $print = strftime(Pubwich::_('%e %B at %H:%M'), $original); return $print; } for ($i = 0, $j = count($chunks); $i < $j; $i++) { $seconds = $chunks[$i][0]; $name = $chunks[$i][1]; if (($count = floor($since / $seconds)) != 0) { break; } } $suffixe = "s"; $print = $count == 1 ? '1 ' . $name : $count . ' ' . $name . $suffixe; return sprintf(Pubwich::_('%s ago'), $print); }
/** * @return array */ public function populateItemTemplate(&$item) { $link = $item->link->attributes()->href; return array('link' => htmlspecialchars($link), 'title' => trim($item->title), 'date' => $item->published ? Pubwich::time_since($item->published) : Pubwich::time_since($item->updated), 'content' => $item->content); }
<?php defined('PUBWICH') or die('No direct access allowed.'); /** * @classname Pinboard * @description Fetch Pinboard bookmarks * @version 1.0 (20110115) * @author Rémi Prévost (exomel.com) * @methods None */ Pubwich::requireServiceFile('RSS'); class Pinboard extends RSS { public function __construct($config) { $config['link'] = 'http://pinboard.in/u:' . $config['username'] . '/'; $config['url'] = sprintf('http://feeds.pinboard.in/rss/secret:%s/u:%s/', $config['secret'], $config['username']); parent::__construct($config); $this->setItemTemplate('<li><a href="{{{link}}}">{{{title}}}</a></li>' . "\n"); } // This is RSS 1.0 (RDF), not RSS 2.0… public function getData() { $data = parent::getParentData(); return $data->item; } }
$twitter = array( // TODO ); //*/ /* $vimeo_likes = array( 'Vimeo', 'vimeo_likes', array( 'username' => 'VIMEO_USERNAME_HERE', 'list' => 'likes', 'total' => 3, 'title' => 'Vimeo', 'description' => 'what I liked' ) ); //*/ /* $youtube_uploads = array( 'Youtube', 'youtube_uploads', array( 'list' => 'uploads', 'username' => 'YOUTUBE_USERNAME_HERE', 'total' => 3, 'title' => 'Youtube', 'description' => 'my recent videos' ) ); //*/ /* -- 7) Add service configurations -------------------------------- */ /* Use the configuration variables from step 6 to group the Social Web services (if you use the vars from the examples, do not forget to uncomment). The default theme can have up to 3 groups (columns). */ Pubwich::setServices(array(array(), array(), array())); // Don't forget to fill informations in /humans.txt
?> </head> <body> <div id="wrap"> <h1><a href="/" rel="me"><?php echo PUBWICH_TITLE; ?> </a></h1> <hr> <div class="clearfix"> <?php echo Pubwich::getLoop(); ?> </div> <div id="footer"> <div class="footer-inner"> <hr> <?php echo sprintf(Pubwich::_('All data is © copyright %s. Proudly powered by %s.'), date('Y'), '<a class="pubwich" href="http://pubwich.org/">Pubwich</a>'); ?> </div> </div> </div> <?php echo Pubwich::getFooter(); ?> </body> </html>
/** * @return array */ public function populateItemTemplate(&$item) { $link = $item->link->attributes()->href; $date = $item->published ? $item->published : $item->updated; return array('link' => htmlspecialchars($link), 'title' => trim($item->title), 'date' => Pubwich::time_since($date), 'absolute_date' => date($this->dateFormat, strtotime($date)), 'content' => $item->content); }
/** * @return array */ public function populateItemTemplate(&$item) { return array('link' => htmlspecialchars($item->url), 'title' => $item->title, 'date' => Pubwich::time_since($item->uploaded_date), 'caption' => $item->caption, 'duration' => $item->duration, 'width' => $item->width, 'height' => $item->height, 'image_small' => $item->thumbnail_small, 'image_medium' => $item->thumbnail_medium, 'image_large' => $item->thumbnail_large); }
public function processDataItem($item) { return array('text' => $item->text, 'status' => $this->filterContent($item->text), 'date' => Pubwich::time_since($item->created_at), 'timestamp' => strtotime($item->created_at)); }
/** * @param SimpleXMLElement $album * @return string */ public function getImage($album) { $id = $this->buildAlbumId($album); $image = $this->albumdata[$id]->album->image[1]; return $image == '' ? Pubwich::getThemeUrl() . '/img/cover.png' : $image; }
/** * Return a date in a relative format * Based on: http://snippets.dzone.com/posts/show/5565 * * @param $original Date timestamp * @return string */ public static function time_since($original) { $original = strtotime($original); $today = time(); $since = $today - $original; if ($since < 0) { return sprintf(Pubwich::_('just moments ago'), $since); } if ($since >= 7 * 24 * 60 * 60) { return strftime(Pubwich::_('%e %B at %H:%M'), $original); } $timechunks = array(array(60, 60, '1 second ago', '%d seconds ago'), array(60 * 60, 60, '1 minute ago', '%d minutes ago'), array(24 * 60 * 60, 24, '1 hour ago', '%d hours ago'), array(7 * 24 * 60 * 60, 7, '1 day ago', '%d days ago')); for ($i = 0, $j = count($timechunks); $i < $j; $i++) { $seconds = $timechunks[$i][0]; $string_single = $timechunks[$i][2]; $string_plural = $timechunks[$i][3]; if ($since < $seconds) { $count = floor($since / ($seconds / $timechunks[$i][1])); return sprintf(Pubwich::_($string_single, $string_plural, $count), $count); } } }
/** * @return array * @since 20120909 */ public function processDataItem($item) { return array('description' => $item->description, 'owner' => $item->user->login, 'link' => $item->html_url, 'public' => $item->public, 'date' => Pubwich::time_since($item->updated_at), 'timestamp' => strtotime($item->updated_at)); }
/** * @constructor */ public function __construct($msg) { die('<strong>' . Pubwich::_('Error!') . '</strong> ' . $msg); }
/** * @return array */ public function populateItemTemplate(&$item) { $public = $item->fork == 'true'; return array('description' => $item->description, 'repo' => $item->repo, 'permalink' => sprintf('http://gist.github.com/%s', $item->repo), 'date' => Pubwich::time_since($item->{'created-at'}), 'owner' => $item->owner, 'files' => (array) $item->files->file); }
public function populateItemTemplate(&$item) { return array('date' => Pubwich::time_since($item->last_checkin_at), 'image' => $item->spot->image_url, 'name' => $item->spot->name, 'url' => $this->base . $item->spot->url, 'visits' => $item->checkins_count); }
public function populateItemTemplate(&$item) { return parent::populateItemTemplate($items) + array('title' => $item->Title, 'description' => $item->Description, 'link' => $item->URL, 'image' => $item->ThumbnailURL, 'thumbnail' => $item->ThumbnailSmallURL, 'embed' => $item->Embed, 'date' => Pubwich::time_since($item->Created), 'language' => $item->Language); }
<?php defined('PUBWICH') or die('No direct access allowed.'); /** * @classname GitHub * @description Fetch GitHub user public activity feed * @version 1.0 (20100107) * @author Rémi Prévost (exomel.com) * @methods None */ Pubwich::requireServiceFile('Atom'); class Github extends Atom { /** * @constructor */ public function __construct($config) { $config['url'] = sprintf('http://github.com/%s.atom', $config['username']); $config['link'] = 'http://github.com/' . $config['username'] . '/'; parent::__construct($config); $this->setItemTemplate('<li class="clearfix"><a href="{%link%}">{%title%}</a></li>' . "\n"); } /** * @return array */ public function populateItemTemplate(&$item) { return parent::populateItemTemplate($item) + array(); } }
<?php define('PUBWICH_CRON', true); define('PUBWICH', 1); require dirname(__FILE__) . '/../lib/Pubwich.php'; Pubwich::init(); Pubwich::rebuildCache();
public function populateItemTemplate(&$item) { return array('text' => $this->filterContent($item->text), 'date' => Pubwich::time_since($item->created_at), 'location' => $item->user->location, 'source' => $item->source); }
/** * @return array * @since 20110531 */ public function processDataItem($item) { // meta $link = $item->get_permalink(); $author = ($author = $item->get_author()) ? trim($author->get_name()) : 'null'; $category = ($category = $item->get_category()) ? trim($category->get_label()) : 'null'; $date = $item->get_date('c'); if (isset($this->dateFormat)) { $absolute_date = date($this->dateFormat, strtotime($date)); } else { $absolute_date = null; } $timestamp = 0; $timestamp = strtotime($date); // content $summary = strip_tags(trim($item->get_description()), '<br>'); $content = trim($item->get_content()); $title = strip_tags(trim($item->get_title())); if (!$title) { $title = $summary ? $summary : $content; } $title = strip_tags(str_replace(array('<br>', '<br/>'), ' ', $title)); // media $media = $item->get_enclosure(); if ($media) { $media_url = $media->get_link(); $media_thumbnail_url = $media->get_thumbnail(); $media_extension = $media->get_extension(); $media_type = explode('/', $media->get_real_type()); $media_type[] = array(null); $media_type = ($media_type = trim($media_type[0])) ? $media_type : $media->get_medium(); $media_caption = trim(strip_tags($media->get_description())); if (!$media_caption) { $media_caption = $media->get_caption(); $media_caption = $media_caption ? trim(strip_tags($media->get_text())) : ''; } } else { $media_url = null; $media_thumbnail_url = null; $media_extension = null; $media_type = null; $media_caption = null; } // comments TODO // compile array to return return array('link' => $link, 'author' => $author, 'category' => $category, 'date' => Pubwich::time_since($date), 'absolute_date' => $absolute_date, 'timestamp' => $timestamp, 'title' => $title, 'summary' => $summary, 'content' => $content, 'media_url' => $media_url, 'media_thumbnail_url' => $media_thumbnail_url, 'media_type' => $media_type, 'media_caption' => $media_caption); }
<?php // $Id$ define('PUBWICH', 1); require dirname(__FILE__) . '/lib/Pubwich.php'; Pubwich::init(); Pubwich::renderTemplate();
/** * @param SimpleXMLElement $album * [@param bool $rebuildCache] * @return void */ public function fetchPhotoGeoData($photo, $rebuildCache = false) { $Cache_Lite = new Cache_Lite(parent::getCacheOptions()); $id = $photo["id"]; if (!$rebuildCache && ($data = $Cache_Lite->get($id))) { $this->photogeodata["{$id}"] = simplexml_load_string($data); } else { $Cache_Lite->get($id); PubwichLog::log(2, Pubwich::_('Rebuilding geo cache for a Flickr Photo')); $url = sprintf('http://api.flickr.com/services/rest/?method=flickr.photos.geo.getLocation&api_key=%s&photo_id=%s', $this->apikey, $id); $fdata = FileFetcher::get($url); $cacheWrite = $Cache_Lite->save($fdata); if (PEAR::isError($cacheWrite)) { //var_dump( $cacheWrite ); } $pdata = simplexml_load_string($fdata); $this->photogeodata["{$id}"] = $pdata; } }
/** * @return array */ public function populateItemTemplate(&$item) { // yep, this is actually book_edtion. Readernaut's creator Nathan Borror has been notified about this typo :) return array('id' => $item->reader_book_id, 'link' => $item->book_edtion->permalink, 'title' => $item->book_edtion->title, 'subtitle' => $item->book_edtion->subtitle, 'author' => $item->book_edtion->authors->author, 'image' => $item->book_edtion->covers->cover_small, 'image_medium' => $item->book_edtion->covers->cover_medium, 'image_large' => $item->book_edtion->covers->cover_large, 'size' => $this->size, 'created' => Pubwich::time_since($item->book_edtion->created), 'modified' => Pubwich::time_since($item->book_edtion->modified), 'isbn' => $item->book_edtion->isbn, 'body' => $item->body); }
* array( * * // column 1 * array( * array('Flickr', 'photos', array( * 'method' => 'FlickrUser', * 'title' => 'Flickr', * 'description' => 'My pictures', * 'key' => '', * ... * ) * ), * * // column 2 * array( * ... * ), * * // column 3 * array( * ... * ) * ) * ); * */ Pubwich::setServices(array(array(array('Text', 'intro', array('title' => 'Introduction', 'text' => 'This is a short introduction text. To hide the "Introduction" title, all you have to is not specify a "title" item for the <strong>Text</strong> box.')), array('Flickr', 'photos', array('method' => 'FlickrUser', 'key' => 'FLICKR_KEY_HERE', 'userid' => 'FLICKER_USERID_HERE', 'username' => 'FLICKR_USERNAME_HERE', 'total' => 12, 'title' => 'Flick<em>r</em>', 'description' => 'latest photos', 'row' => 4)), array('Vimeo', 'videos', array('username' => 'VIMEO_USERNAME_HERE', 'total' => 4, 'title' => 'Vimeo', 'description' => 'latest videos')), array('Youtube', 'youtube', array('method' => 'YoutubeVideos', 'username' => 'YOUTUBE_USERNAME_HERE', 'total' => 4, 'size' => 120, 'title' => 'Youtube', 'description' => 'latest videos'))), array(array('Twitter', 'etats', array('method' => 'TwitterUser', 'username' => 'TWITTER_USERNAME_HERE', 'oauth' => array('app_consumer_key' => '', 'app_consumer_secret' => '', 'user_access_token' => '', 'user_access_token_secret' => ''), 'total' => 10, 'title' => 'Twitter', 'description' => 'latest statuses')), array('Delicious', 'liens', array('username' => 'DELICIOUS_USERNAME_HERE', 'total' => 5, 'title' => 'del.icio.us', 'description' => 'latest bookmarks')), array('Facebook', 'status', array('id' => 'FACEBOOK_USERID_HERE', 'key' => 'FACEBOOK_KEY_HERE', 'username' => 'FACEBOOK_USERNAME_HERE', 'total' => 5, 'title' => 'Facebook', 'description' => 'latest statuses')), array('RSS', 'ixmedia', array('url' => 'http://feeds2.feedburner.com/ixmediablogue', 'link' => 'http://blogue.ixmedia.com/', 'total' => 5, 'title' => 'Blogue iXmédia', 'description' => 'latest atom blog entries'))), array(array('Atom', 'effair', array('url' => 'http://remiprevost.com/atom/', 'link' => 'http://remiprevost.com/', 'total' => 5, 'title' => 'Effair', 'description' => 'latest rss blog entries')), array('Readernaut', 'livres', array('method' => 'ReadernautBooks', 'username' => 'READERNAUT_USERNAME_HERE', 'total' => 9, 'size' => 50, 'title' => 'Readernaut', 'description' => 'latest books')), array('Lastfm', 'albums', array('method' => 'LastFMWeeklyAlbums', 'key' => 'LASTFM_KEY_HERE', 'username' => 'LASTFM_USERNAME_HERE', 'total' => 5, 'size' => 64, 'title' => 'Last.fm', 'description' => 'weekly top albums'))))); // Caching system define('CACHE_LOCATION', dirname(__FILE__) . '/../cache/'); define('CACHE_LIMIT', 20 * 60); // Don't forget to fill informations in /humans.txt
public function renderBox() { $items = ''; $classData = $this->getData(); $htmlClass = strtolower(get_class($this)) . ' ' . (get_parent_class($this) != 'Service' ? strtolower(get_parent_class($this)) : ''); if (!$classData) { $items = '<li class="nodata">' . sprintf(Pubwich::_('An error occured with the %s API. The data is therefore unavailable.'), get_class($this)) . '</li>'; $htmlClass .= ' nodata'; } else { foreach ($classData as $item) { $compteur++; if ($this->total && $compteur > $this->total) { break; } $populate = $this->populateItemTemplate($item); if (function_exists(get_class($this) . '_populateItemTemplate')) { $populate = call_user_func(get_class($this) . '_populateItemTemplate', $item) + $populate; } $this->getItemTemplate()->populate($populate); $items .= ' ' . $this->getItemTemplate()->output(); } } $data = array('class' => $htmlClass, 'items' => $items); // Let the service override it $data = $this->populateBoxTemplate($data) + $data; // Let the theme override it if (function_exists('populateBoxTemplate')) { $data = call_user_func('populateBoxTemplate', $this, $data) + $data; } $this->getBoxTemplate()->populate($data); return $this->getBoxTemplate()->output(); }
/** * @return array */ public function populateItemTemplate(&$item) { $comments_count = $item->children('http://purl.org/rss/1.0/modules/slash/')->comments; $content = $item->children('http://purl.org/rss/1.0/modules/content/')->encoded; return array('link' => htmlspecialchars($item->link), 'title' => trim($item->title), 'date' => Pubwich::time_since($item->pubDate), 'comments_link' => $item->comments, 'comments_count' => $comments_count, 'description' => $item->description, 'content' => $content, 'author' => $item->author); }
<?php defined('PUBWICH') or die('No direct access allowed.'); /** * Delicious Service * * Fetch Delicious bookmarks. * * @version 1.1 (20090929) * @author Rémi Prévost (exomel.com) * @author Michael Haschke, http://michael.haschke.biz/ * @methods None */ Pubwich::requireServiceFile('Feed'); class Delicious extends Feed { public function __construct($config) { $config['link'] = 'http://delicious.com/' . $config['username'] . '/'; $config['url'] = sprintf('http://feeds.delicious.com/v2/rss/%s?count=%s', $config['username'], $config['total']); parent::__construct($config); $this->setItemTemplate('<li> <a href="{{{link}}}">{{{title}}}</a> ({{{date}}}) {{#category}} <em><a href="{{{service_link}}}{{{category}}}">{{{category}}}</a></em> {{/category}} </li>' . "\n"); } /** * @return array
public function populateItemTemplate($item) { return array('url' => $item->url, 'title' => $item->title, 'state' => $item->state, 'time_added' => Pubwich::time_since(strftime('%T', $item->time_added)), 'time_updated' => Pubwich::time_since(strftime('%T', $item->time_updated))); }