* @license PHP License * @package WB * @subpackage content */ /** * Load required class */ WBClass::load( 'WBContent' , 'WBCache' , 'WBStream' ); /** * Content component: Rss * * RSS Feed reader * * @version 0.2.6 * @package WB * @subpackage content */ class WBContent_Rss extends WBContent { /** * my parameter list * @var array */ protected $config = array( 'tmpl' => 'list', 'url' => '', 'limit' => 100, 'ttl' => 300 ); /** * channel data * @var array */ protected $channel = array(); /** * run * * run component * * @todo remove wget hack! * @return array parameter list */ public function run() { $cacheId = serialize($this->config); $this->channel = WBCache::get($cacheId); if (is_array($this->channel)) { return $this->config; } try{ $stream = WBStream::open( $this->config['url'], 'r' ); } catch(WBException_File $e) { return $this->config; } // initialize channel info $this->channel = array( 'info' => array(), 'items' => array() ); WBClass::load('XML_RSS'); $rss = new XML_RSS($stream); $rss->parse(); $items = array(); foreach( $rss->getItems() as $item ) { // only fetch a few if (count($items) >= $this->config['limit']) { break; } if (isset($item['dc:creator'])) { $item['author'] = $item['dc:creator']; } if (isset($item['dc:date'])) { $item['pubdate'] = $item['dc:date']; } $item['timestamp'] = 0; if (isset( $item['pubdate'])) { $item['timestamp'] = strtotime($item['pubdate']); } $items[] = $item; } $this->channel['info'] = $rss->getChannelInfo(); $this->channel['items'] = $items; $expire = array( 'ttl' => $this->config['ttl'], ); WBCache::set($cacheId, $this->channel, $expire); return $this->config; } /** * receive output * * fetch output of this content component * * @return string */ public function getString() { if (empty($this->channel)) { $this->loadTemplates('broken'); $this->tmpl->addGLobalVars($this->config, 'config_'); return $this->tmpl->getParsedTemplate('snippet'); } $this->loadTemplates($this->config['tmpl']); $this->tmpl->addGlobalVars($this->channel['info'], 'channel_'); $this->tmpl->addRows('item', $this->channel['items']); return $this->tmpl->getParsedTemplate('snippet'); } } ?>