Source of file Feed.php
Size: 7,128 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Feed/Reader/Extension/DublinCore/Feed.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Feed\Reader\Extension\DublinCore; use DateTime; use Zend\Feed\Reader; use Zend\Feed\Reader\Collection; use Zend\Feed\Reader\Extension; class Feed extends Extension\AbstractFeed { /** * Get a single author * * @param int $index * @return string|null */ public function getAuthor($index = 0) { $authors = $this->getAuthors(); if (isset($authors[$index])) { return $authors[$index]; } return null; } /** * Get an array with feed authors * * @return array */ public function getAuthors() { if (array_key_exists('authors', $this->data)) { return $this->data['authors']; } $authors = array(); $list = $this->getXpath()->query('//dc11:creator'); if (!$list->length) { $list = $this->getXpath()->query('//dc10:creator'); } if (!$list->length) { $list = $this->getXpath()->query('//dc11:publisher'); if (!$list->length) { $list = $this->getXpath()->query('//dc10:publisher'); } } if ($list->length) { foreach ($list as $author) { $authors[] = array( 'name' => $author->nodeValue ); } $authors = new Collection\Author( Reader\Reader::arrayUnique($authors) ); } else { $authors = null; } $this->data['authors'] = $authors; return $this->data['authors']; } /** * Get the copyright entry * * @return string|null */ public function getCopyright() { if (array_key_exists('copyright', $this->data)) { return $this->data['copyright']; } $copyright = null; $copyright = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:rights)'); if (!$copyright) { $copyright = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:rights)'); } if (!$copyright) { $copyright = null; } $this->data['copyright'] = $copyright; return $this->data['copyright']; } /** * Get the feed description * * @return string|null */ public function getDescription() { if (array_key_exists('description', $this->data)) { return $this->data['description']; } $description = null; $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)'); if (!$description) { $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)'); } if (!$description) { $description = null; } $this->data['description'] = $description; return $this->data['description']; } /** * Get the feed ID * * @return string|null */ public function getId() { if (array_key_exists('id', $this->data)) { return $this->data['id']; } $id = null; $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)'); if (!$id) { $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:identifier)'); } $this->data['id'] = $id; return $this->data['id']; } /** * Get the feed language * * @return string|null */ public function getLanguage() { if (array_key_exists('language', $this->data)) { return $this->data['language']; } $language = null; $language = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:language)'); if (!$language) { $language = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:language)'); } if (!$language) { $language = null; } $this->data['language'] = $language; return $this->data['language']; } /** * Get the feed title * * @return string|null */ public function getTitle() { if (array_key_exists('title', $this->data)) { return $this->data['title']; } $title = null; $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)'); if (!$title) { $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)'); } if (!$title) { $title = null; } $this->data['title'] = $title; return $this->data['title']; } /** * * * @return DateTime|null */ public function getDate() { if (array_key_exists('date', $this->data)) { return $this->data['date']; } $d = null; $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)'); if (!$date) { $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)'); } if ($date) { $d = new DateTime($date); } $this->data['date'] = $d; return $this->data['date']; } /** * Get categories (subjects under DC) * * @return Collection\Category */ public function getCategories() { if (array_key_exists('categories', $this->data)) { return $this->data['categories']; } $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc11:subject'); if (!$list->length) { $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc10:subject'); } if ($list->length) { $categoryCollection = new Collection\Category; foreach ($list as $category) { $categoryCollection[] = array( 'term' => $category->nodeValue, 'scheme' => null, 'label' => $category->nodeValue, ); } } else { $categoryCollection = new Collection\Category; } $this->data['categories'] = $categoryCollection; return $this->data['categories']; } /** * Register the default namespaces for the current feed format * * @return void */ protected function registerNamespaces() { $this->getXpath()->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/'); $this->getXpath()->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/'); } } |