* @license PHP License * @package WB * @subpackage content */ /** * Load required class */ WBClass::load( 'WBContent' , 'WBCache' , 'WBStream' ); /** * Content component: RssFeeder * * Deliver blog roll as RSS feed * * @version 0.1.0 * @package WB * @subpackage content */ class WBContent_RssFeeder extends WBContent { /** * my parameter list * @var array */ protected $config = array( 'listurl' => 'http://[[SERVER]][[SERVICE_HTML]]blog', 'articleurl' => 'http://[[SERVER]][[SERVICE_HTML]]blog/%s/%s', 'category' => '', 'limit' => 20, 'ttl' => 3600, 'title' => 'Blog RSS Feed', 'brief' => 'Automatically created RSS feed for this weblog.' ); /** * use this XML snippet if everything else fails */ const XML_FRAME = ' 60 http://example.com/ Error: %d Failed to build RSS feed! %s '; /** * channel data * @var array */ protected $channel = array(); /** * 2nd constructor * * */ protected function init() { $this->table = WBClass::create('WBDatasource_Table'); $this->blogConfig = WBClass::create('WBConfig'); $this->blogConfig->load('blog/config'); $this->scanner = wBClass::Create('WBMarkup_Scanner'); $this->handler = wBClass::Create('WBMarkup_Handler_Xml2Html'); $this->scanner->setHandler($this->handler); } /** * run * * run component * * @todo remove wget hack! * @return array parameter list */ public function run() { $this->channel = array( 'ttl' => $this->config['ttl'], 'link' => $this->config['listurl'], 'title' => $this->config['title'], 'description' => $this->config['brief'] ); $clause = array(); $clause[] = array( 'field' => 'published', 'value' => 1 ); $clause[] = array( 'field' => 'created', 'relation' => 'le', 'value' => gmdate('Y-m-d H:i:s') ); if (!empty($this->config['category'])) { if (!is_array($this->config['category'])) { $this->config['category'] = array($this->config['category']); } $clause[] = array( 'field' => $this->table->getIdentifier('blogcategory'), 'relation' => 'in', 'value' => $this->config['category'] ); } $options = array(); $options['limit'] = $this->config['limit']; $options['order'] = array( array( 'field' => 'created', 'asc' => 0 ) ); $list = $this->table->get('blog', null, null, $clause, $options ); $uid = $this->table->getIdentifier('user'); foreach ($list as $l) { // publish date $time = strtotime($l['created']); // author $user = $this->table->get('user', $l[$uid]); $user = $user[0]; // body $this->scanner->scan($l['body']); $body = $this->handler->getParsedContent(); // item $item = array( 'title' => $l['title'], 'description' => $body, 'author' => sprintf('%s %s', $user['forename'], $user['surname']), 'guid' => sprintf('[[SERVER]][[DOCROOT]]/blog/%s', $l['id']), 'link' => sprintf($this->config['articleurl'], date('Y-m-d', $time), urlencode($l['title'])), 'pubDate' => date('d M Y h:i:s', $time) . ' GMT', //'dc:creator' => sprintf('%s %s', $user['forename'], $user['surname']), //'dc:date' => date('Y-m-dTh:i:s', $time), ); $this->channel[] = $item; } return $this->config; } /** * receive output * * fetch output of this content component * * @return string */ public function getString() { $res = WBClass::create('WBResponse'); /** @var $res WBResponse */ $content = $this->serialize(); $res->add($content); $res->addHeader('Content-Type', 'text/xml; charset=utf-8;'); $res->send($this->req); exit(0); } /** * serialize to XML * * Serialize response array to XML string * * @param int $status HTTP status code * @param artray $response * @return string */ protected function serialize() { $channel = array('channel' => $this->channel); WBClass::load('XML_Serializer'); $opts = array( XML_SERIALIZER_OPTION_ROOT_NAME => 'rss', XML_SERIALIZER_OPTION_ROOT_ATTRIBS => array( 'version' => '2.0' ), XML_SERIALIZER_OPTION_LINEBREAKS => "\n", XML_SERIALIZER_OPTION_INDENT => '', XML_SERIALIZER_OPTION_DEFAULT_TAG => 'item', XML_SERIALIZER_OPTION_XML_DECL_ENABLED => true, XML_SERIALIZER_OPTION_XML_ENCODING => 'utf-8', XML_SERIALIZER_OPTION_INDENT => ' ' /* XML_SERIALIZER_OPTION_DOCTYPE_ENABLED => true, XML_SERIALIZER_OPTION_DOCTYPE => array( 'uri' => 'http://xml.wombat.exit0.net/rest', 'id' => 'Wombat REST 1.0' ) */ ); $ser = new XML_Serializer($opts); $result = $ser->serialize($channel); if (PEAR::isError($result)) { return sprintf(self::XML_FRAME, 6, 'Failed to build xml response'); } return $ser->getSerializedData(); } } ?>