public function getData() { $Cache_Lite = new Cache_Lite(parent::getCacheOptions()); $url = sprintf('https://readitlaterlist.com/v2/get?username=%s&password=%s&apikey=%s&count=%s&format=json', $this->config['username'], $this->config['password'], $this->config['apikey'], $this->config['total']); $id = $url; if ($data = $Cache_Lite->get($id)) { $data = json_decode($data); } else { $Cache_Lite->get($id); PubwichLog::log(2, Pubwich::_('Rebuilding cache for a Readitlater')); PubwichLog::log(2, $this->url); $data = file_get_contents($url); $data = json_decode($data); foreach ($data->list as $item) { // Default value $item->title = parse_url($item->url, PHP_URL_HOST); // If check page title if (!empty($this->config['getTitle'])) { $file = @fopen($item->url, "r"); if ($file) { $text = fread($file, 1024 * 3); if (preg_match('/<title>(.*?)<\\/title>/is', $text, $found)) { $item->title = $found[1]; } } } } // Write cache $cacheWrite = $Cache_Lite->save(json_encode($data)); } return $data->list; }
?> </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 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); }
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(); }
/** * @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; } }
?> </head> <body> <div id="wrap"> <h1><?php echo PUBWICH_TITLE; ?> </h1> <hr> <div class="clearfix"> <?php echo Pubwich::getLoop(); ?> </div> <div id="footer"> <div class="footer-inner"> <hr> <?php echo sprintf(Pubwich::_('Fetched %s, proudly aggregated by %s.'), date('Y'), '<a class="pubwich" href="' . PUBWICH_WEB . '">' . PUBWICH_NAME . '</a>'); ?> </div> </div> </div> <?php echo Pubwich::getFooter(); ?> </body> </html>
/** * @param SimpleXMLElement $album * [@param bool $rebuildCache] * @return void */ public function fetchAlbum($album, $rebuildCache = false) { $Cache_Lite = new Cache_Lite(parent::getCacheOptions()); $id = $this->buildAlbumId($album); if (!$rebuildCache && ($data = $Cache_Lite->get($id))) { $this->albumdata[$id] = simplexml_load_string($data); } else { $Cache_Lite->get($id); PubwichLog::log(2, Pubwich::_('Rebuilding cache for a Last.fm album')); $url = sprintf("http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=%s&artist=%s&album=%s", $this->key, urlencode($album->artist), urlencode($album->name)); $data = FileFetcher::get($url); $cacheWrite = $Cache_Lite->save($data); if (PEAR::isError($cacheWrite)) { //var_dump( $cacheWrite ); } $this->albumdata[$id] = simplexml_load_string($data); } }
/** * 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); } } }
/** * @constructor */ public function __construct($msg) { die('<strong>' . Pubwich::_('Error!') . '</strong> ' . $msg); }
?> </head> <body> <div id="wrap"> <h1><?php echo PUBWICH_TITLE; ?> </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="' . PUBWICH_WEB . '">' . PUBWICH_NAME . '</a>'); ?> </div> </div> </div> <?php echo Pubwich::getFooter(); ?> </body> </html>