diff options
author | robocoder <anthon.pang@gmail.com> | 2010-01-29 12:02:30 +0300 |
---|---|---|
committer | robocoder <anthon.pang@gmail.com> | 2010-01-29 12:02:30 +0300 |
commit | 1378f79297baa84590738839ec11cef90ac21bc4 (patch) | |
tree | 61b8272e59891a9d5d175d8a883a978fd913daf0 /libs/Zend/Feed/Reader | |
parent | f156256d1f2537e6e448c7b8b5852d59a0e9099e (diff) |
update wrt Zend Framework 1.10.0; remove svn:eol-style property
git-svn-id: http://dev.piwik.org/svn/trunk@1813 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'libs/Zend/Feed/Reader')
29 files changed, 1066 insertions, 300 deletions
diff --git a/libs/Zend/Feed/Reader/Collection.php b/libs/Zend/Feed/Reader/Collection.php new file mode 100644 index 0000000000..fba2b52b52 --- /dev/null +++ b/libs/Zend/Feed/Reader/Collection.php @@ -0,0 +1,33 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Feed_Reader + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** + * @category Zend + * @package Zend_Feed_Reader + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Feed_Reader_Collection extends ArrayObject +{ + + + +} diff --git a/libs/Zend/Feed/Reader/Collection/Author.php b/libs/Zend/Feed/Reader/Collection/Author.php new file mode 100644 index 0000000000..98a8aea226 --- /dev/null +++ b/libs/Zend/Feed/Reader/Collection/Author.php @@ -0,0 +1,51 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Feed_Reader + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Author.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * @see Zend_Feed_Reader_Collection_CollectionAbstract + */ +require_once 'Zend/Feed/Reader/Collection/CollectionAbstract.php'; + +/** + * @category Zend + * @package Zend_Feed_Reader + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Feed_Reader_Collection_Author +extends Zend_Feed_Reader_Collection_CollectionAbstract +{ + + /** + * Return a simple array of the most relevant slice of + * the author values, i.e. all author names. + * + * @return array + */ + public function getValues() { + $authors = array(); + foreach ($this->getIterator() as $element) { + $authors[] = $element['name']; + } + return array_unique($authors); + } + +} diff --git a/libs/Zend/Feed/Reader/Collection/Category.php b/libs/Zend/Feed/Reader/Collection/Category.php new file mode 100644 index 0000000000..18b9f362e5 --- /dev/null +++ b/libs/Zend/Feed/Reader/Collection/Category.php @@ -0,0 +1,53 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Feed_Reader + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Category.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * @see Zend_Feed_Reader_Collection_CollectionAbstract + */ +require_once 'Zend/Feed/Reader/Collection/CollectionAbstract.php'; + +/** + * @category Zend + * @package Zend_Feed_Reader + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Feed_Reader_Collection_Category +extends Zend_Feed_Reader_Collection_CollectionAbstract +{ + + /** + * Return a simple array of the most relevant slice of + * the collection values. For example, feed categories contain + * the category name, domain/URI, and other data. This method would + * merely return the most useful data - i.e. the category names. + * + * @return array + */ + public function getValues() { + $categories = array(); + foreach ($this->getIterator() as $element) { + $categories[] = $element['label']; + } + return array_unique($categories); + } + +} diff --git a/libs/Zend/Feed/Reader/Collection/CollectionAbstract.php b/libs/Zend/Feed/Reader/Collection/CollectionAbstract.php new file mode 100644 index 0000000000..7b6dbd0317 --- /dev/null +++ b/libs/Zend/Feed/Reader/Collection/CollectionAbstract.php @@ -0,0 +1,41 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Feed_Reader + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: CollectionAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ + */ + +/** + * @category Zend + * @package Zend_Feed_Reader + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +abstract class Zend_Feed_Reader_Collection_CollectionAbstract extends ArrayObject +{ + + /** + * Return a simple array of the most relevant slice of + * the collection values. For example, feed categories contain + * the category name, domain/URI, and other data. This method would + * merely return the most useful data - i.e. the category names. + * + * @return array + */ + public abstract function getValues(); + +} diff --git a/libs/Zend/Feed/Reader/Entry/Atom.php b/libs/Zend/Feed/Reader/Entry/Atom.php index c4ab3fa629..308deba59e 100644 --- a/libs/Zend/Feed/Reader/Entry/Atom.php +++ b/libs/Zend/Feed/Reader/Entry/Atom.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Atom.php 19193 2009-11-23 16:11:15Z padraic $ + * @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -42,7 +42,7 @@ require_once 'Zend/Feed/Reader/Extension/Atom/Entry.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract implements Zend_Feed_Reader_EntryInterface @@ -74,6 +74,9 @@ class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract impleme $threadClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Thread_Entry'); $this->_extensions['Thread_Entry'] = new $threadClass($entry, $entryKey, $type); + + $threadClass = Zend_Feed_Reader::getPluginLoader()->getClassName('DublinCore_Entry'); + $this->_extensions['DublinCore_Entry'] = new $threadClass($entry, $entryKey, $type); } /** @@ -341,6 +344,46 @@ class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract impleme return $this->_data['commentfeedlink']; } + + /** + * Get category data as a Zend_Feed_Reader_Collection_Category object + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + $categoryCollection = $this->getExtension('Atom')->getCategories(); + + if (count($categoryCollection) == 0) { + $categoryCollection = $this->getExtension('DublinCore')->getCategories(); + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } + + /** + * Get source feed metadata from the entry + * + * @return Zend_Feed_Reader_Feed_Atom_Source|null + */ + public function getSource() + { + if (array_key_exists('source', $this->_data)) { + return $this->_data['source']; + } + + $source = $this->getExtension('Atom')->getSource(); + + $this->_data['source'] = $source; + + return $this->_data['source']; + } /** * Set the XPath query (incl. on all Extensions) diff --git a/libs/Zend/Feed/Reader/Entry/Rss.php b/libs/Zend/Feed/Reader/Entry/Rss.php index b91990a665..30f90d8de3 100644 --- a/libs/Zend/Feed/Reader/Entry/Rss.php +++ b/libs/Zend/Feed/Reader/Entry/Rss.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Rss.php 18367 2009-09-22 14:55:59Z padraic $ + * @version $Id: Rss.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -70,9 +70,14 @@ require_once 'Zend/Feed/Reader/Extension/Thread/Entry.php'; require_once 'Zend/Date.php'; /** + * @see Zend_Feed_Reader_Collection_Category + */ +require_once 'Zend/Feed/Reader/Collection/Category.php'; + +/** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implements Zend_Feed_Reader_EntryInterface @@ -154,45 +159,50 @@ class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implemen if (array_key_exists('authors', $this->_data)) { return $this->_data['authors']; } - + $authors = array(); - // @todo: create a list from all potential sources rather than from alternatives - if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && - $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { - $list = $this->_xpath->evaluate($this->_xpathQueryRss.'//author'); - } else { - $list = $this->_xpath->evaluate($this->_xpathQueryRdf.'//rss:author'); - } - if (!$list->length) { - if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { - $list = $this->_xpath->query('//author'); - } else { - $list = $this->_xpath->query('//rss:author'); + $authors_dc = $this->getExtension('DublinCore')->getAuthors(); + if (!empty($authors_dc)) { + foreach ($authors_dc as $author) { + $authors[] = array( + 'name' => $author['name'] + ); } } - + + if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 + && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { + $list = $this->_xpath->query($this->_xpathQueryRss . '//author'); + } else { + $list = $this->_xpath->query($this->_xpathQueryRdf . '//rss:author'); + } if ($list->length) { foreach ($list as $author) { - if ($this->getType() == Zend_Feed_Reader::TYPE_RSS_20 - && preg_match("/\(([^\)]+)\)/", $author->nodeValue, $matches, PREG_OFFSET_CAPTURE) - ) { - // source name from RSS 2.0 <author> - // format "joe@example.com (Joe Bloggs)" - $authors[] = $matches[1][0]; - } else { - $authors[] = $author->nodeValue; - } + $string = trim($author->nodeValue); + $email = null; + $name = null; + $data = array(); + // Pretty rough parsing - but it's a catchall + if (preg_match("/^.*@[^ ]*/", $string, $matches)) { + $data['email'] = trim($matches[0]); + if (preg_match("/\((.*)\)$/", $string, $matches)) { + $data['name'] = $matches[1]; + } + $authors[] = $data; + } } - - $authors = array_unique($authors); } - if (empty($authors)) { - $authors = $this->getExtension('DublinCore')->getAuthors(); + if (count($authors) == 0) { + $authors = $this->getExtension('Atom')->getAuthors(); + } else { + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); } - if (empty($authors)) { - $authors = $this->getExtension('Atom')->getAuthors(); + if (count($authors) == 0) { + $authors = null; } $this->_data['authors'] = $authors; @@ -268,7 +278,8 @@ class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implemen throw new Zend_Feed_Exception( 'Could not load date due to unrecognised' .' format (should follow RFC 822 or 2822):' - . $e->getMessage() + . $e->getMessage(), + 0, $e ); } } @@ -458,6 +469,46 @@ class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implemen return $this->_data['links']; } + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && + $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { + $list = $this->_xpath->query($this->_xpathQueryRss.'//category'); + } else { + $list = $this->_xpath->query($this->_xpathQueryRdf.'//rss:category'); + } + + if ($list->length) { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + foreach ($list as $category) { + $categoryCollection[] = array( + 'term' => $category->nodeValue, + 'scheme' => $category->getAttribute('domain'), + 'label' => $category->nodeValue, + ); + } + } else { + $categoryCollection = $this->getExtension('DublinCore')->getCategories(); + } + + if (count($categoryCollection) == 0) { + $categoryCollection = $this->getExtension('Atom')->getCategories(); + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } /** * Get a permalink to the entry diff --git a/libs/Zend/Feed/Reader/EntryAbstract.php b/libs/Zend/Feed/Reader/EntryAbstract.php index f437001476..193bb65c5d 100644 --- a/libs/Zend/Feed/Reader/EntryAbstract.php +++ b/libs/Zend/Feed/Reader/EntryAbstract.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: EntryAbstract.php 19042 2009-11-19 15:23:34Z padraic $ + * @version $Id: EntryAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ abstract class Zend_Feed_Reader_EntryAbstract @@ -154,6 +154,9 @@ abstract class Zend_Feed_Reader_EntryAbstract */ public function getXpath() { + if (!$this->_xpath) { + $this->setXpath(new DOMXPath($this->getDomDocument())); + } return $this->_xpath; } @@ -170,16 +173,6 @@ abstract class Zend_Feed_Reader_EntryAbstract } /** - * Serialize the entry to an array - * - * @return array - */ - public function toArray() - { - return $this->_data; - } - - /** * Get registered extensions * * @return array diff --git a/libs/Zend/Feed/Reader/EntryInterface.php b/libs/Zend/Feed/Reader/EntryInterface.php index dafbe293dd..392a533a30 100644 --- a/libs/Zend/Feed/Reader/EntryInterface.php +++ b/libs/Zend/Feed/Reader/EntryInterface.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: EntryInterface.php 16953 2009-07-22 11:57:25Z padraic $ + * @version $Id: EntryInterface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ interface Zend_Feed_Reader_EntryInterface @@ -133,4 +133,11 @@ interface Zend_Feed_Reader_EntryInterface * @return string */ public function getCommentFeedLink(); + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories(); } diff --git a/libs/Zend/Feed/Reader/Extension/Atom/Entry.php b/libs/Zend/Feed/Reader/Extension/Atom/Entry.php index 70774848d1..57c12e2d1c 100644 --- a/libs/Zend/Feed/Reader/Extension/Atom/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Atom/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20507 2010-01-21 22:21:07Z padraic $ */ /** @@ -40,9 +40,19 @@ require_once 'Zend/Date.php'; require_once 'Zend/Uri.php'; /** + * @see Zend_Feed_Reader_Collection_Category + */ +require_once 'Zend/Feed/Reader/Collection/Category.php'; + +/** + * @see Zend_Feed_Reader_Feed_Atom_Source + */ +require_once 'Zend/Feed/Reader/Feed/Atom/Source.php'; + +/** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_Atom_Entry @@ -76,33 +86,34 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['authors']; } - $authors = $this->_xpath->query( - $this->getXpathPrefix() . '//atom:author' . '|' - . $this->getXpathPrefix(). '//atom:contributor' - ); + $authors = array(); + $list = $this->getXpath()->query($this->getXpathPrefix() . '//atom:author'); - if (!$authors->length) { - $authors = $this->_xpath->query( - '//atom:author' . '|' . '//atom:contributor' - ); + if (!$list->length) { + /** + * TODO: Limit query to feed level els only! + */ + $list = $this->getXpath()->query('//atom:author'); } - $people = array(); - - if ($authors->length) { - foreach ($authors as $author) { + if ($list->length) { + foreach ($list as $author) { $author = $this->_getAuthor($author); - if (!empty($author)) { - $people[] = $author; + $authors[] = $author; } } } - $people = array_unique($people); - - $this->_data['authors'] = $people; + if (count($authors) == 0) { + $authors = null; + } else { + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); + } + $this->_data['authors'] = $authors; return $this->_data['authors']; } @@ -116,21 +127,65 @@ class Zend_Feed_Reader_Extension_Atom_Entry if (array_key_exists('content', $this->_data)) { return $this->_data['content']; } - - $content = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:content)'); - - if ($content) { - $content = html_entity_decode($content, ENT_QUOTES, $this->getEncoding()); + + $content = null; + + $el = $this->getXpath()->query($this->getXpathPrefix() . '/atom:content'); + if($el->length > 0) { + $el = $el->item(0); + $type = $el->getAttribute('type'); + switch ($type) { + case '': + case 'text': + case 'text/plain': + case 'html': + case 'text/html': + $content = $el->nodeValue; + break; + case 'xhtml': + $this->getXpath()->registerNamespace('xhtml', 'http://www.w3.org/1999/xhtml'); + $xhtml = $this->getXpath()->query( + $this->getXpathPrefix() . '/atom:content/xhtml:div' + )->item(0); + //$xhtml->setAttribute('xmlns', 'http://www.w3.org/1999/xhtml'); + $d = new DOMDocument('1.0', $this->getEncoding()); + $xhtmls = $d->importNode($xhtml, true); + $d->appendChild($xhtmls); + $content = $this->_collectXhtml( + $d->saveXML(), + $d->lookupPrefix('http://www.w3.org/1999/xhtml') + ); + break; + } } + + //var_dump($content); exit; if (!$content) { $content = $this->getDescription(); } - $this->_data['content'] = $content; + $this->_data['content'] = trim($content); return $this->_data['content']; } + + /** + * Parse out XHTML to remove the namespacing + */ + protected function _collectXhtml($xhtml, $prefix) + { + if (!empty($prefix)) $prefix = $prefix . ':'; + $matches = array( + "/<\?xml[^<]*>[^<]*<" . $prefix . "div[^<]*/", + "/<\/" . $prefix . "div>\s*$/" + ); + $xhtml = preg_replace($matches, '', $xhtml); + if (!empty($prefix)) { + $xhtml = preg_replace("/(<[\/]?)" . $prefix . "([a-zA-Z]+)/", '$1$2', $xhtml); + } + return $xhtml; + } /** * Get the entry creation date @@ -145,10 +200,10 @@ class Zend_Feed_Reader_Extension_Atom_Entry $date = null; - if ($this->getType() === Zend_Feed_Reader::TYPE_ATOM_03) { - $dateCreated = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:created)'); + if ($this->_getAtomType() === Zend_Feed_Reader::TYPE_ATOM_03) { + $dateCreated = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:created)'); } else { - $dateCreated = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:published)'); + $dateCreated = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:published)'); } if ($dateCreated) { @@ -174,10 +229,10 @@ class Zend_Feed_Reader_Extension_Atom_Entry $date = null; - if ($this->getType() === Zend_Feed_Reader::TYPE_ATOM_03) { - $dateModified = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:modified)'); + if ($this->_getAtomType() === Zend_Feed_Reader::TYPE_ATOM_03) { + $dateModified = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:modified)'); } else { - $dateModified = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:updated)'); + $dateModified = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:updated)'); } if ($dateModified) { @@ -201,7 +256,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['description']; } - $description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:summary)'); + $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:summary)'); if (!$description) { $description = null; @@ -227,7 +282,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry $enclosure = null; - $nodeList = $this->_xpath->query($this->getXpathPrefix() . '/atom:link[@rel="enclosure"]'); + $nodeList = $this->getXpath()->query($this->getXpathPrefix() . '/atom:link[@rel="enclosure"]'); if ($nodeList->length > 0) { $enclosure = new stdClass(); @@ -252,7 +307,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['id']; } - $id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:id)'); + $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:id)'); if (!$id) { if ($this->getPermalink()) { @@ -280,12 +335,12 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['baseUrl']; } - $baseUrl = $this->_xpath->evaluate('string(' + $baseUrl = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/@xml:base[1]' . ')'); if (!$baseUrl) { - $baseUrl = $this->_xpath->evaluate('string(//@xml:base[1])'); + $baseUrl = $this->getXpath()->evaluate('string(//@xml:base[1])'); } if (!$baseUrl) { @@ -329,7 +384,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry $links = array(); - $list = $this->_xpath->query( + $list = $this->getXpath()->query( $this->getXpathPrefix() . '//atom:link[@rel="alternate"]/@href' . '|' . $this->getXpathPrefix() . '//atom:link[not(@rel)]/@href' ); @@ -366,7 +421,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['title']; } - $title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:title)'); + $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:title)'); if (!$title) { $title = null; @@ -392,8 +447,8 @@ class Zend_Feed_Reader_Extension_Atom_Entry $count = null; - $this->_xpath->registerNamespace('thread10', 'http://purl.org/syndication/thread/1.0'); - $list = $this->_xpath->query( + $this->getXpath()->registerNamespace('thread10', 'http://purl.org/syndication/thread/1.0'); + $list = $this->getXpath()->query( $this->getXpathPrefix() . '//atom:link[@rel="replies"]/@thread10:count' ); @@ -419,7 +474,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry $link = null; - $list = $this->_xpath->query( + $list = $this->getXpath()->query( $this->getXpathPrefix() . '//atom:link[@rel="replies" and @type="text/html"]/@href' ); @@ -446,7 +501,7 @@ class Zend_Feed_Reader_Extension_Atom_Entry $link = null; - $list = $this->_xpath->query( + $list = $this->getXpath()->query( $this->getXpathPrefix() . '//atom:link[@rel="replies" and @type="application/'.$type.'+xml"]/@href' ); @@ -459,6 +514,72 @@ class Zend_Feed_Reader_Extension_Atom_Entry return $this->_data['commentfeedlink']; } + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + if ($this->_getAtomType() == Zend_Feed_Reader::TYPE_ATOM_10) { + $list = $this->getXpath()->query($this->getXpathPrefix() . '//atom:category'); + } else { + /** + * Since Atom 0.3 did not support categories, it would have used the + * Dublin Core extension. However there is a small possibility Atom 0.3 + * may have been retrofittied to use Atom 1.0 instead. + */ + $this->getXpath()->registerNamespace('atom10', Zend_Feed_Reader::NAMESPACE_ATOM_10); + $list = $this->getXpath()->query($this->getXpathPrefix() . '//atom10:category'); + } + + if ($list->length) { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + foreach ($list as $category) { + $categoryCollection[] = array( + 'term' => $category->getAttribute('term'), + 'scheme' => $category->getAttribute('scheme'), + 'label' => html_entity_decode($category->getAttribute('label')) + ); + } + } else { + return new Zend_Feed_Reader_Collection_Category; + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } + + /** + * Get source feed metadata from the entry + * + * @return Zend_Feed_Reader_Feed_Atom_Source|null + */ + public function getSource() + { + if (array_key_exists('source', $this->_data)) { + return $this->_data['source']; + } + + $source = null; + // TODO: Investigate why _getAtomType() fails here. Is it even needed? + if ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10) { + $list = $this->getXpath()->query($this->getXpathPrefix() . '/atom:source[1]'); + if ($list->length) { + $element = $list->item(0); + $source = new Zend_Feed_Reader_Feed_Atom_Source($element, $this->getXpathPrefix()); + } + } + + $this->_data['source'] = $source; + return $this->_data['source']; + } /** * Attempt to absolutise the URI, i.e. if a relative URI apply the @@ -485,35 +606,28 @@ class Zend_Feed_Reader_Extension_Atom_Entry */ protected function _getAuthor(DOMElement $element) { - $email = null; - $name = null; - $uri = null; + $author = array(); $emailNode = $element->getElementsByTagName('email'); $nameNode = $element->getElementsByTagName('name'); $uriNode = $element->getElementsByTagName('uri'); - - if ($emailNode->length) { - $email = $emailNode->item(0)->nodeValue; + + if ($emailNode->length && strlen($emailNode->item(0)->nodeValue) > 0) { + $author['email'] = $emailNode->item(0)->nodeValue; } - if ($nameNode->length) { - $name = $nameNode->item(0)->nodeValue; + if ($nameNode->length && strlen($nameNode->item(0)->nodeValue) > 0) { + $author['name'] = $nameNode->item(0)->nodeValue; } - if ($uriNode->length) { - $uri = $uriNode->item(0)->nodeValue; + if ($uriNode->length && strlen($uriNode->item(0)->nodeValue) > 0) { + $author['uri'] = $uriNode->item(0)->nodeValue; } - if (!empty($email)) { - return $email . (empty($name) ? '' : ' (' . $name . ')'); - } else if (!empty($name)) { - return $name; - } else if (!empty($uri)) { - return $uri; + if (empty($author)) { + return null; } - - return null; + return $author; } /** @@ -521,18 +635,12 @@ class Zend_Feed_Reader_Extension_Atom_Entry */ protected function _registerNamespaces() { - if ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10 - || $this->getType() == Zend_Feed_Reader::TYPE_ATOM_03 - ) { - return; // pre-registered at Feed level - } - $atomDetected = $this->_getAtomType(); - switch ($atomDetected) { + switch ($this->_getAtomType()) { case Zend_Feed_Reader::TYPE_ATOM_03: - $this->_xpath->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_03); + $this->getXpath()->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_03); break; default: - $this->_xpath->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_10); + $this->getXpath()->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_10); break; } } @@ -542,17 +650,16 @@ class Zend_Feed_Reader_Extension_Atom_Entry */ protected function _getAtomType() { - $nslist = $this->getDomDocument()->documentElement->attributes; - if (!$nslist->length) { - return null; - } - foreach ($nslist as $ns) { - if ($ns->value == Zend_Feed_Reader::NAMESPACE_ATOM_10) { - return Zend_Feed_Reader::TYPE_ATOM_10; - } - if ($ns->value == Zend_Feed_Reader::NAMESPACE_ATOM_03) { - return Zend_Feed_Reader::TYPE_ATOM_03; - } + $dom = $this->getDomDocument(); + $prefixAtom03 = $dom->lookupPrefix(Zend_Feed_Reader::NAMESPACE_ATOM_03); + $prefixAtom10 = $dom->lookupPrefix(Zend_Feed_Reader::NAMESPACE_ATOM_10); + if ($dom->isDefaultNamespace(Zend_Feed_Reader::NAMESPACE_ATOM_03) + || !empty($prefixAtom03)) { + return Zend_Feed_Reader::TYPE_ATOM_03; + } + if ($dom->isDefaultNamespace(Zend_Feed_Reader::NAMESPACE_ATOM_10) + || !empty($prefixAtom10)) { + return Zend_Feed_Reader::TYPE_ATOM_10; } } } diff --git a/libs/Zend/Feed/Reader/Extension/Atom/Feed.php b/libs/Zend/Feed/Reader/Extension/Atom/Feed.php index 42d619fd08..502e9a9c1e 100644 --- a/libs/Zend/Feed/Reader/Extension/Atom/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/Atom/Feed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -35,9 +35,14 @@ require_once 'Zend/Date.php'; require_once 'Zend/Uri.php'; /** + * @see Zend_Feed_Reader_Collection_Author + */ +require_once 'Zend/Feed/Reader/Collection/Author.php'; + +/** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_Atom_Feed @@ -71,38 +76,28 @@ class Zend_Feed_Reader_Extension_Atom_Feed return $this->_data['authors']; } - $authors = $this->_xpath->query('//atom:author'); - $contributors = $this->_xpath->query('//atom:contributor'); + $list = $this->_xpath->query('//atom:author'); - $people = array(); + $authors = array(); - if ($authors->length) { - foreach ($authors as $author) { + if ($list->length) { + foreach ($list as $author) { $author = $this->_getAuthor($author); - if (!empty($author)) { - $people[] = $author; - } - } - } - - if ($contributors->length) { - foreach ($contributors as $contributor) { - $contributor = $this->_getAuthor($contributor); - - if (!empty($contributor)) { - $people[] = $contributor; + $authors[] = $author; } } } - if (empty($people)) { - $people = null; + if (count($authors) == 0) { + $authors = null; } else { - $people = array_unique($people); + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); } - $this->_data['authors'] = $people; + $this->_data['authors'] = $authors; return $this->_data['authors']; } @@ -369,6 +364,34 @@ class Zend_Feed_Reader_Extension_Atom_Feed } /** + * Get an array of any supported Pusubhubbub endpoints + * + * @return array|null + */ + public function getHubs() + { + if (array_key_exists('hubs', $this->_data)) { + return $this->_data['hubs']; + } + $hubs = array(); + + $list = $this->_xpath->query($this->getXpathPrefix() + . '//atom:link[@rel="hub"]/@href'); + + if ($list->length) { + foreach ($list as $uri) { + $hubs[] = $this->_absolutiseUri($uri->nodeValue); + } + } else { + $hubs = null; + } + + $this->_data['hubs'] = $hubs; + + return $this->_data['hubs']; + } + + /** * Get the feed title * * @return string|null @@ -389,6 +412,47 @@ class Zend_Feed_Reader_Extension_Atom_Feed return $this->_data['title']; } + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + if ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10) { + $list = $this->_xpath->query($this->getXpathPrefix() . '/atom:category'); + } else { + /** + * Since Atom 0.3 did not support categories, it would have used the + * Dublin Core extension. However there is a small possibility Atom 0.3 + * may have been retrofittied to use Atom 1.0 instead. + */ + $this->_xpath->registerNamespace('atom10', Zend_Feed_Reader::NAMESPACE_ATOM_10); + $list = $this->_xpath->query($this->getXpathPrefix() . '/atom10:category'); + } + + if ($list->length) { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + foreach ($list as $category) { + $categoryCollection[] = array( + 'term' => $category->getAttribute('term'), + 'scheme' => $category->getAttribute('scheme'), + 'label' => html_entity_decode($category->getAttribute('label')) + ); + } + } else { + return new Zend_Feed_Reader_Collection_Category; + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } /** * Get an author entry in RSS format @@ -398,35 +462,28 @@ class Zend_Feed_Reader_Extension_Atom_Feed */ protected function _getAuthor(DOMElement $element) { - $email = null; - $name = null; - $uri = null; + $author = array(); $emailNode = $element->getElementsByTagName('email'); $nameNode = $element->getElementsByTagName('name'); $uriNode = $element->getElementsByTagName('uri'); - - if ($emailNode->length) { - $email = $emailNode->item(0)->nodeValue; + + if ($emailNode->length && strlen($emailNode->item(0)->nodeValue) > 0) { + $author['email'] = $emailNode->item(0)->nodeValue; } - if ($nameNode->length) { - $name = $nameNode->item(0)->nodeValue; + if ($nameNode->length && strlen($nameNode->item(0)->nodeValue) > 0) { + $author['name'] = $nameNode->item(0)->nodeValue; } - if ($uriNode->length) { - $uri = $uriNode->item(0)->nodeValue; + if ($uriNode->length && strlen($uriNode->item(0)->nodeValue) > 0) { + $author['uri'] = $uriNode->item(0)->nodeValue; } - if (!empty($email)) { - return $email . (empty($name) ? '' : ' (' . $name . ')'); - } else if (!empty($name)) { - return $name; - } else if (!empty($uri)) { - return $uri; + if (empty($author)) { + return null; } - - return null; + return $author; } /** @@ -472,17 +529,16 @@ class Zend_Feed_Reader_Extension_Atom_Feed */ protected function _getAtomType() { - $nslist = $this->getDomDocument()->documentElement->attributes; - if (!$nslist->length) { - return null; - } - foreach ($nslist as $ns) { - if ($ns->value == Zend_Feed_Reader::NAMESPACE_ATOM_10) { - return Zend_Feed_Reader::TYPE_ATOM_10; - } - if ($ns->value == Zend_Feed_Reader::NAMESPACE_ATOM_03) { - return Zend_Feed_Reader::TYPE_ATOM_03; - } + $dom = $this->getDomDocument(); + $prefixAtom03 = $dom->lookupPrefix(Zend_Feed_Reader::NAMESPACE_ATOM_03); + $prefixAtom10 = $dom->lookupPrefix(Zend_Feed_Reader::NAMESPACE_ATOM_10); + if ($dom->isDefaultNamespace(Zend_Feed_Reader::NAMESPACE_ATOM_10) + || !empty($prefixAtom10)) { + return Zend_Feed_Reader::TYPE_ATOM_10; + } + if ($dom->isDefaultNamespace(Zend_Feed_Reader::NAMESPACE_ATOM_03) + || !empty($prefixAtom03)) { + return Zend_Feed_Reader::TYPE_ATOM_03; } } } diff --git a/libs/Zend/Feed/Reader/Extension/Content/Entry.php b/libs/Zend/Feed/Reader/Extension/Content/Entry.php index fa147af3e5..c6375b2244 100644 --- a/libs/Zend/Feed/Reader/Extension/Content/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Content/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_Content_Entry diff --git a/libs/Zend/Feed/Reader/Extension/CreativeCommons/Entry.php b/libs/Zend/Feed/Reader/Extension/CreativeCommons/Entry.php index b9830089d3..9c8cd4da72 100644 --- a/libs/Zend/Feed/Reader/Extension/CreativeCommons/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/CreativeCommons/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/CreativeCommons/Feed.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_CreativeCommons_Entry extends Zend_Feed_Reader_Extension_EntryAbstract diff --git a/libs/Zend/Feed/Reader/Extension/CreativeCommons/Feed.php b/libs/Zend/Feed/Reader/Extension/CreativeCommons/Feed.php index 20dfe6e2d4..4b1c7a9fbe 100644 --- a/libs/Zend/Feed/Reader/Extension/CreativeCommons/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/CreativeCommons/Feed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_CreativeCommons_Feed diff --git a/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php b/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php index b33cac8464..c20394594b 100644 --- a/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/DublinCore/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -37,7 +37,7 @@ require_once 'Zend/Date.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_DublinCore_Entry @@ -87,22 +87,56 @@ class Zend_Feed_Reader_Extension_DublinCore_Entry if ($list->length) { foreach ($list as $author) { - if ($this->getType() == Zend_Feed_Reader::TYPE_RSS_20 - && preg_match("/\(([^\)]+)\)/", $author->nodeValue, $matches, PREG_OFFSET_CAPTURE) - ) { - $authors[] = $matches[1][0]; - } else { - $authors[] = $author->nodeValue; - } + $authors[] = array( + 'name' => $author->nodeValue + ); } - - $authors = array_unique($authors); + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); + } else { + $authors = null; } $this->_data['authors'] = $authors; return $this->_data['authors']; } + + /** + * Get categories (subjects under DC) + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:subject'); + + if (!$list->length) { + $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:subject'); + } + + if ($list->length) { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + foreach ($list as $category) { + $categoryCollection[] = array( + 'term' => $category->nodeValue, + 'scheme' => null, + 'label' => $category->nodeValue, + ); + } + } else { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + } + + $this->_data['categories'] = $categoryCollection; + return $this->_data['categories']; + } + /** * Get the entry content diff --git a/libs/Zend/Feed/Reader/Extension/DublinCore/Feed.php b/libs/Zend/Feed/Reader/Extension/DublinCore/Feed.php index 968e81c5b0..5b7816f54e 100644 --- a/libs/Zend/Feed/Reader/Extension/DublinCore/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/DublinCore/Feed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -30,9 +30,14 @@ require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php'; require_once 'Zend/Date.php'; /** + * @see Zend_Feed_Reader_Collection_Author + */ +require_once 'Zend/Feed/Reader/Collection/Author.php'; + +/** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_DublinCore_Feed @@ -79,13 +84,18 @@ class Zend_Feed_Reader_Extension_DublinCore_Feed $list = $this->_xpath->query('//dc10:publisher'); } } - - foreach ($list as $authorObj) { - $authors[] = $authorObj->nodeValue; - } - - if (!empty($authors)) { - $authors = array_unique($authors); + + if ($list->length) { + foreach ($list as $author) { + $authors[] = array( + 'name' => $author->nodeValue + ); + } + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); + } else { + $authors = null; } $this->_data['authors'] = $authors; @@ -251,6 +261,40 @@ class Zend_Feed_Reader_Extension_DublinCore_Feed return $this->_data['date']; } + + /** + * Get categories (subjects under DC) + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:subject'); + + if (!$list->length) { + $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:subject'); + } + + if ($list->length) { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + foreach ($list as $category) { + $categoryCollection[] = array( + 'term' => $category->nodeValue, + 'scheme' => null, + 'label' => $category->nodeValue, + ); + } + } else { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + } + + $this->_data['categories'] = $categoryCollection; + return $this->_data['categories']; + } /** * Register the default namespaces for the current feed format diff --git a/libs/Zend/Feed/Reader/Extension/EntryAbstract.php b/libs/Zend/Feed/Reader/Extension/EntryAbstract.php index 3c212a8553..299c1bfbaf 100644 --- a/libs/Zend/Feed/Reader/Extension/EntryAbstract.php +++ b/libs/Zend/Feed/Reader/Extension/EntryAbstract.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: EntryAbstract.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: EntryAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ abstract class Zend_Feed_Reader_Extension_EntryAbstract @@ -86,7 +86,7 @@ abstract class Zend_Feed_Reader_Extension_EntryAbstract if (!is_null($type)) { $this->_data['type'] = $type; } else { - $this->_data['type'] = Zend_Feed_Reader::detectType($feed); + $this->_data['type'] = Zend_Feed_Reader::detectType($entry->ownerDocument, true); } // set the XPath query prefix for the entry being queried if ($this->getType() == Zend_Feed_Reader::TYPE_RSS_10 @@ -153,6 +153,9 @@ abstract class Zend_Feed_Reader_Extension_EntryAbstract */ public function getXpath() { + if (!$this->_xpath) { + $this->setXpath(new DOMXPath($this->getDomDocument())); + } return $this->_xpath; } diff --git a/libs/Zend/Feed/Reader/Extension/FeedAbstract.php b/libs/Zend/Feed/Reader/Extension/FeedAbstract.php index 5f4c4fc2ba..73aa8c90ee 100644 --- a/libs/Zend/Feed/Reader/Extension/FeedAbstract.php +++ b/libs/Zend/Feed/Reader/Extension/FeedAbstract.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: FeedAbstract.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: FeedAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -38,7 +38,7 @@ require_once 'Zend/Feed/Reader/Entry/Rss.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ abstract class Zend_Feed_Reader_Extension_FeedAbstract @@ -139,7 +139,30 @@ abstract class Zend_Feed_Reader_Extension_FeedAbstract return $this->_data; } - /** + /** + * Set the XPath query + * + * @param DOMXPath $xpath + * @return Zend_Feed_Reader_Extension_EntryAbstract + */ + public function setXpath(DOMXPath $xpath) + { + $this->_xpath = $xpath; + $this->_registerNamespaces(); + return $this; + } + + /** + * Get the DOMXPath object + * + * @return string + */ + public function getXpath() + { + return $this->_xpath; + } + + /** * Get the XPath prefix * * @return string diff --git a/libs/Zend/Feed/Reader/Extension/Podcast/Entry.php b/libs/Zend/Feed/Reader/Extension/Podcast/Entry.php index 7af2285421..eeffed2b1f 100644 --- a/libs/Zend/Feed/Reader/Extension/Podcast/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Podcast/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 16792 2009-07-17 02:52:37Z norm2782 $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_Podcast_Entry extends Zend_Feed_Reader_Extension_EntryAbstract diff --git a/libs/Zend/Feed/Reader/Extension/Podcast/Feed.php b/libs/Zend/Feed/Reader/Extension/Podcast/Feed.php index b213d34590..01a5a191db 100644 --- a/libs/Zend/Feed/Reader/Extension/Podcast/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/Podcast/Feed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 16792 2009-07-17 02:52:37Z norm2782 $ + * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_Podcast_Feed extends Zend_Feed_Reader_Extension_FeedAbstract diff --git a/libs/Zend/Feed/Reader/Extension/Slash/Entry.php b/libs/Zend/Feed/Reader/Extension/Slash/Entry.php index 0e016e8ead..c5f259fb3c 100644 --- a/libs/Zend/Feed/Reader/Extension/Slash/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Slash/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_Slash_Entry diff --git a/libs/Zend/Feed/Reader/Extension/Syndication/Feed.php b/libs/Zend/Feed/Reader/Extension/Syndication/Feed.php index b708848f5b..9104486520 100644 --- a/libs/Zend/Feed/Reader/Extension/Syndication/Feed.php +++ b/libs/Zend/Feed/Reader/Extension/Syndication/Feed.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Feed.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -29,7 +29,7 @@ require_once 'Zend/Date.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_Syndication_Feed diff --git a/libs/Zend/Feed/Reader/Extension/Thread/Entry.php b/libs/Zend/Feed/Reader/Extension/Thread/Entry.php index aff20c2a9f..7b397de763 100644 --- a/libs/Zend/Feed/Reader/Extension/Thread/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/Thread/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -27,7 +27,7 @@ require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_Thread_Entry diff --git a/libs/Zend/Feed/Reader/Extension/WellFormedWeb/Entry.php b/libs/Zend/Feed/Reader/Extension/WellFormedWeb/Entry.php index 6ba15bc231..24832fee61 100644 --- a/libs/Zend/Feed/Reader/Extension/WellFormedWeb/Entry.php +++ b/libs/Zend/Feed/Reader/Extension/WellFormedWeb/Entry.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Entry.php 18951 2009-11-12 16:26:19Z alexander $ + * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Extension_WellFormedWeb_Entry diff --git a/libs/Zend/Feed/Reader/Feed/Atom.php b/libs/Zend/Feed/Reader/Feed/Atom.php index 19606d0295..fb1e53e218 100644 --- a/libs/Zend/Feed/Reader/Feed/Atom.php +++ b/libs/Zend/Feed/Reader/Feed/Atom.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Atom.php 19044 2009-11-19 16:44:24Z padraic $ + * @version $Id: Atom.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Feed/Reader/Extension/Atom/Feed.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract @@ -44,11 +44,13 @@ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract * @param DOMDocument $dom * @param string $type */ - public function __construct(DomDocument $dom, $type = null) + public function __construct(DOMDocument $dom, $type = null) { parent::__construct($dom, $type); $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Feed'); $this->_extensions['Atom_Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath); + $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('DublinCore_Feed'); + $this->_extensions['DublinCore_Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath); foreach ($this->_extensions as $extension) { $extension->setXpathPrefix('/atom:feed'); } @@ -82,9 +84,9 @@ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract return $this->_data['authors']; } - $people = $this->getExtension('Atom')->getAuthors(); + $authors = $this->getExtension('Atom')->getAuthors(); - $this->_data['authors'] = $people; + $this->_data['authors'] = $authors; return $this->_data['authors']; } @@ -312,8 +314,49 @@ class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract } /** + * Get an array of any supported Pusubhubbub endpoints + * + * @return array|null + */ + public function getHubs() + { + if (array_key_exists('hubs', $this->_data)) { + return $this->_data['hubs']; + } + + $hubs = $this->getExtension('Atom')->getHubs(); + + $this->_data['hubs'] = $hubs; + + return $this->_data['hubs']; + } + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + $categoryCollection = $this->getExtension('Atom')->getCategories(); + + if (count($categoryCollection) == 0) { + $categoryCollection = $this->getExtension('DublinCore')->getCategories(); + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } + + /** * Read all entries to the internal entries array * + * @return void */ protected function _indexEntries() { diff --git a/libs/Zend/Feed/Reader/Feed/Atom/Source.php b/libs/Zend/Feed/Reader/Feed/Atom/Source.php new file mode 100644 index 0000000000..8d5fe0c94b --- /dev/null +++ b/libs/Zend/Feed/Reader/Feed/Atom/Source.php @@ -0,0 +1,102 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Feed_Reader + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Atom.php 19165 2009-11-21 16:46:40Z padraic $ + */ + +/** + * @see Zend_Feed_Reader_Feed_Atom + */ +require_once 'Zend/Feed/Reader/Feed/Atom.php'; + +/** + * @category Zend + * @package Zend_Feed_Reader + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Feed_Reader_Feed_Atom_Source extends Zend_Feed_Reader_Feed_Atom +{ + + /** + * Constructor: Create a Source object which is largely just a normal + * Zend_Feed_Reader_FeedAbstract object only designed to retrieve feed level + * metadata from an Atom entry's source element. + * + * @param DOMElement $source + * @param string $xpathPrefix Passed from parent Entry object + * @param string $type Nearly always Atom 1.0 + */ + public function __construct(DOMElement $source, $xpathPrefix, $type = Zend_Feed_Reader::TYPE_ATOM_10) + { + $this->_domDocument = $source->ownerDocument; + $this->_xpath = new DOMXPath($this->_domDocument); + $this->_data['type'] = $type; + $this->_registerNamespaces(); + $this->_loadExtensions(); + + $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Feed'); + $this->_extensions['Atom_Feed'] = new $atomClass($this->_domDocument, $this->_data['type'], $this->_xpath); + $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('DublinCore_Feed'); + $this->_extensions['DublinCore_Feed'] = new $atomClass($this->_domDocument, $this->_data['type'], $this->_xpath); + foreach ($this->_extensions as $extension) { + $extension->setXpathPrefix(rtrim($xpathPrefix, '/') . '/atom:source'); + } + } + + /** + * Since this is not an Entry carrier but a vehicle for Feed metadata, any + * applicable Entry methods are stubbed out and do nothing. + */ + + /** + * @return void + */ + public function count() {} + + /** + * @return void + */ + public function current() {} + + /** + * @return void + */ + public function key() {} + + /** + * @return void + */ + public function next() {} + + /** + * @return void + */ + public function rewind() {} + + /** + * @return void + */ + public function valid() {} + + /** + * @return void + */ + protected function _indexEntries() {} + +} diff --git a/libs/Zend/Feed/Reader/Feed/Rss.php b/libs/Zend/Feed/Reader/Feed/Rss.php index 00b6276eb9..dcb6192608 100644 --- a/libs/Zend/Feed/Reader/Feed/Rss.php +++ b/libs/Zend/Feed/Reader/Feed/Rss.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Rss.php 19044 2009-11-19 16:44:24Z padraic $ + * @version $Id: Rss.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -40,9 +40,14 @@ require_once 'Zend/Feed/Reader/Extension/DublinCore/Feed.php'; require_once 'Zend/Date.php'; /** + * @see Zend_Feed_Reader_Collection_Author + */ +require_once 'Zend/Feed/Reader/Collection/Author.php'; + +/** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract @@ -100,33 +105,54 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract if (array_key_exists('authors', $this->_data)) { return $this->_data['authors']; } - + $authors = array(); - - if (empty($authors)) { - $authors = $this->getExtension('DublinCore')->getAuthors(); - } - - if (empty($authors)) { - if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { - $list = $this->_xpath->query('//author'); - } else { - $list = $this->_xpath->query('//rss:author'); + $authors_dc = $this->getExtension('DublinCore')->getAuthors(); + if (!empty($authors_dc)) { + foreach ($authors_dc as $author) { + $authors[] = array( + 'name' => $author['name'] + ); } + } - foreach ($list as $authorObj) { - $authors[] = $authorObj->nodeValue; + /** + * Technically RSS doesn't specific author element use at the feed level + * but it's supported on a "just in case" basis. + */ + if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 + && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { + $list = $this->_xpath->query('//author'); + } else { + $list = $this->_xpath->query('//rss:author'); + } + if ($list->length) { + foreach ($list as $author) { + $string = trim($author->nodeValue); + $email = null; + $name = null; + $data = array(); + // Pretty rough parsing - but it's a catchall + if (preg_match("/^.*@[^ ]*/", $string, $matches)) { + $data['email'] = trim($matches[0]); + if (preg_match("/\((.*)\)$/", $string, $matches)) { + $data['name'] = $matches[1]; + } + $authors[] = $data; + } } } - if (empty($authors)) { + if (count($authors) == 0) { $authors = $this->getExtension('Atom')->getAuthors(); + } else { + $authors = new Zend_Feed_Reader_Collection_Author( + Zend_Feed_Reader::arrayUnique($authors) + ); } - if (empty($authors)) { + if (count($authors) == 0) { $authors = null; - } else { - $authors = array_unique($authors); } $this->_data['authors'] = $authors; @@ -213,7 +239,8 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract throw new Zend_Feed_Exception( 'Could not load date due to unrecognised' .' format (should follow RFC 822 or 2822):' - . $e->getMessage() + . $e->getMessage(), + 0, $e ); } } @@ -493,6 +520,70 @@ class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract } /** + * Get an array of any supported Pusubhubbub endpoints + * + * @return array|null + */ + public function getHubs() + { + if (array_key_exists('hubs', $this->_data)) { + return $this->_data['hubs']; + } + + $hubs = $this->getExtension('Atom')->getHubs(); + + if (empty($hubs)) { + $hubs = null; + } else { + $hubs = array_unique($hubs); + } + + $this->_data['hubs'] = $hubs; + + return $this->_data['hubs']; + } + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories() + { + if (array_key_exists('categories', $this->_data)) { + return $this->_data['categories']; + } + + if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && + $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) { + $list = $this->_xpath->query('/rss/channel//category'); + } else { + $list = $this->_xpath->query('/rdf:RDF/rss:channel//rss:category'); + } + + if ($list->length) { + $categoryCollection = new Zend_Feed_Reader_Collection_Category; + foreach ($list as $category) { + $categoryCollection[] = array( + 'term' => $category->nodeValue, + 'scheme' => $category->getAttribute('domain'), + 'label' => $category->nodeValue, + ); + } + } else { + $categoryCollection = $this->getExtension('DublinCore')->getCategories(); + } + + if (count($categoryCollection) == 0) { + $categoryCollection = $this->getExtension('Atom')->getCategories(); + } + + $this->_data['categories'] = $categoryCollection; + + return $this->_data['categories']; + } + + /** * Read all entries to the internal entries array * */ diff --git a/libs/Zend/Feed/Reader/FeedAbstract.php b/libs/Zend/Feed/Reader/FeedAbstract.php index 30b67b059d..6ec899a726 100644 --- a/libs/Zend/Feed/Reader/FeedAbstract.php +++ b/libs/Zend/Feed/Reader/FeedAbstract.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: FeedAbstract.php 19044 2009-11-19 16:44:24Z padraic $ + * @version $Id: FeedAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -25,17 +25,6 @@ require_once 'Zend/Feed/Reader.php'; /** - * @see Zend_Feed_Reader_Entry_Atom - */ -require_once 'Zend/Feed/Reader/Entry/Atom.php'; - - -/** - * @see Zend_Feed_Reader_Entry_Rss - */ -require_once 'Zend/Feed/Reader/Entry/Rss.php'; - -/** * @see Zend_feed_Reader_FeedInterface */ require_once 'Zend/Feed/Reader/FeedInterface.php'; @@ -43,7 +32,7 @@ require_once 'Zend/Feed/Reader/FeedInterface.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ abstract class Zend_Feed_Reader_FeedAbstract implements Zend_Feed_Reader_FeedInterface @@ -83,6 +72,11 @@ abstract class Zend_Feed_Reader_FeedAbstract implements Zend_Feed_Reader_FeedInt */ protected $_xpath = null; + /** + * Array of loaded extensions + * + * @var array + */ protected $_extensions = array(); /** @@ -228,16 +222,6 @@ abstract class Zend_Feed_Reader_FeedAbstract implements Zend_Feed_Reader_FeedInt } /** - * Return the feed as an array - * - * @return array - */ - public function toArray() // untested - { - return $this->_data; - } - - /** * Check to see if the iterator is still valid * * @return boolean diff --git a/libs/Zend/Feed/Reader/FeedInterface.php b/libs/Zend/Feed/Reader/FeedInterface.php index 3278f3ea75..35060bafce 100644 --- a/libs/Zend/Feed/Reader/FeedInterface.php +++ b/libs/Zend/Feed/Reader/FeedInterface.php @@ -14,15 +14,15 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: FeedInterface.php 16953 2009-07-22 11:57:25Z padraic $ + * @version $Id: FeedInterface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ interface Zend_Feed_Reader_FeedInterface extends Iterator, Countable @@ -111,5 +111,12 @@ interface Zend_Feed_Reader_FeedInterface extends Iterator, Countable * @return string|null */ public function getTitle(); + + /** + * Get all categories + * + * @return Zend_Feed_Reader_Collection_Category + */ + public function getCategories(); } diff --git a/libs/Zend/Feed/Reader/FeedSet.php b/libs/Zend/Feed/Reader/FeedSet.php index e5f4050f1f..3d073c7326 100644 --- a/libs/Zend/Feed/Reader/FeedSet.php +++ b/libs/Zend/Feed/Reader/FeedSet.php @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: FeedSet.php 19105 2009-11-20 17:13:54Z padraic $ + * @version $Id: FeedSet.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @@ -32,7 +32,7 @@ require_once 'Zend/Uri.php'; /** * @category Zend * @package Zend_Feed_Reader - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Feed_Reader_FeedSet extends ArrayObject |