Posts Tagged: fyi

2007
26
dec

FYI: content:encoded olvasása


Küzdöttem a Zend Framework-kel, hogy beolvassa a ‘content:encoded’ tag-eket egy RSS feedből. Az alábbi kóddal sikerült:

public function indexAction()
{
	$ns = array
	(
	        'content' => 'http://purl.org/rss/1.0/modules/content/',
	        'wfw' => 'http://wellformedweb.org/CommentAPI/',
	        'dc' => 'http://purl.org/dc/elements/1.1/',
	);
 
	Zend_Loader::loadClass('Zend_Feed');
	try {
		$rssFeed = Zend_Feed::import('http://blog.linuxforge.hu/feed');
	} catch (Zend_Feed_Exception $e) {
		echo "Exception caught importing feed: {$e->getMessage()}\n";
		exit;
	}
 
	$channel = array(
		'title'			=> $rssFeed->title(),
		'link'			=> $rssFeed->link(),
		'description'	=> $rssFeed->description(),
		'items'			=> array(),
	);
 
	$i = 0;
	$xml = new SimpleXMLElement($rssFeed->saveXML());
 
	foreach ($rssFeed as $item) {
		$content = $xml->channel->item[$i++]->children($ns['content']);
		$channel['items'][] = array(
			'title'			=> $item->title(),
			'link'			=> $item->link(),
			'description'	=> $item->description(),
			'content'		=> trim($content->encoded),
		);			
	}
	$this->view->channel = $channel;
}