Reputation: 501
I just can't seem to be able to solve this. I want to get the media:thumbnail from an RSS file . using ZF2 ; Zend\Frame a follow the manual but i cant get images from the xml file , any idea plz :)
that the controller Code :
<?php
namespace RSS\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Feed\Reader as feed;
class IndexController extends AbstractActionController
{
public function indexAction(){
try{
$rss = feed\Reader::import('http://www.wdcdn.net/rss/presentation/library/client/skunkus/id/cc3d06c1cc3834464aef22836c55d13a');
}catch (feed\Exception\RuntimeException $e){
echo "error : " . $e->getMessage();
exit;
}
$channel = array(
'title' => $rss->getTitle(),
'description' => $rss->getDescription(),
'link' => $rss->getLink(),
'items' => array()
);
foreach($rss as $item){
$channel['items'][] = array(
'title' => $item->getTitle(),
'link' => $item->getLink(),
'description' => $item->getDescription(),
// 'image' => $item->getImage(),
);
}
return new ViewModel(array(
'channel' => $channel
));
}
}
Upvotes: 2
Views: 1170
Reputation: 21
Here is a way to do it without having to extend or modify the class:
foreach ($channel as $item) {
$xmlItem = $item->saveXml();
$xmlFeed = new \SimpleXMLElement($xmlItem);
$thumbAttr = $xmlFeed->children('http://search.yahoo.com/mrss/')->thumbnail->attributes();
$thumbUrl = (string)$thumbAttr['url'];
}
Upvotes: 2
Reputation: 501
Hi
for who get the same pb i solve it by adding a new function to Zend/Feed/Reader/Entry/rss.php called getMedia() , that the code for who has a better idea or a better code i'll be thankful if you help :
public function getMedia()
{
if (array_key_exists('media', $this->data)) {
return $this->data['media'];
}
$media = null;
if ($this->getType() == Reader\Reader::TYPE_RSS_20) {
$nodeList = $this->xpath->query($this->xpathQueryRss . '/media:thumbnail');
if ($nodeList->length > 0) {
$media = new \stdClass();
$media->url = $nodeList->item(0)->getAttribute('url');
}
}
$this->data['media'] = $media;
return $this->data['media'];
}
Upvotes: 4