adding zend project folders into old campcaster.
This commit is contained in:
parent
56abfaf28e
commit
7ef0c18b26
4045 changed files with 1054952 additions and 0 deletions
33
library/Zend/Feed/Reader/Collection.php
Normal file
33
library/Zend/Feed/Reader/Collection.php
Normal file
|
@ -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
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
51
library/Zend/Feed/Reader/Collection/Author.php
Normal file
51
library/Zend/Feed/Reader/Collection/Author.php
Normal file
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
57
library/Zend/Feed/Reader/Collection/Category.php
Normal file
57
library/Zend/Feed/Reader/Collection/Category.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?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 20954 2010-02-06 17:56:27Z padraic $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
if (isset($element['label']) && !empty($element['label'])) {
|
||||
$categories[] = $element['label'];
|
||||
} else {
|
||||
$categories[] = $element['term'];
|
||||
}
|
||||
}
|
||||
return array_unique($categories);
|
||||
}
|
||||
|
||||
}
|
41
library/Zend/Feed/Reader/Collection/CollectionAbstract.php
Normal file
41
library/Zend/Feed/Reader/Collection/CollectionAbstract.php
Normal file
|
@ -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();
|
||||
|
||||
}
|
400
library/Zend/Feed/Reader/Entry/Atom.php
Normal file
400
library/Zend/Feed/Reader/Entry/Atom.php
Normal file
|
@ -0,0 +1,400 @@
|
|||
<?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 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_EntryInterface
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/EntryInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_EntryAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/EntryAbstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_Atom_Entry
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/Atom/Entry.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_Entry_Atom extends Zend_Feed_Reader_EntryAbstract implements Zend_Feed_Reader_EntryInterface
|
||||
{
|
||||
/**
|
||||
* XPath query
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_xpathQuery = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DOMElement $entry
|
||||
* @param int $entryKey
|
||||
* @param string $type
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(DOMElement $entry, $entryKey, $type = null)
|
||||
{
|
||||
parent::__construct($entry, $entryKey, $type);
|
||||
|
||||
// Everyone by now should know XPath indices start from 1 not 0
|
||||
$this->_xpathQuery = '//atom:entry[' . ($this->_entryKey + 1) . ']';
|
||||
|
||||
$atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Entry');
|
||||
$this->_extensions['Atom_Entry'] = new $atomClass($entry, $entryKey, $type);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified 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'];
|
||||
}
|
||||
|
||||
$people = $this->getExtension('Atom')->getAuthors();
|
||||
|
||||
$this->_data['authors'] = $people;
|
||||
|
||||
return $this->_data['authors'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
if (array_key_exists('content', $this->_data)) {
|
||||
return $this->_data['content'];
|
||||
}
|
||||
|
||||
$content = $this->getExtension('Atom')->getContent();
|
||||
|
||||
$this->_data['content'] = $content;
|
||||
|
||||
return $this->_data['content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry creation date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateCreated()
|
||||
{
|
||||
if (array_key_exists('datecreated', $this->_data)) {
|
||||
return $this->_data['datecreated'];
|
||||
}
|
||||
|
||||
$dateCreated = $this->getExtension('Atom')->getDateCreated();
|
||||
|
||||
$this->_data['datecreated'] = $dateCreated;
|
||||
|
||||
return $this->_data['datecreated'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry modification date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateModified()
|
||||
{
|
||||
if (array_key_exists('datemodified', $this->_data)) {
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
$dateModified = $this->getExtension('Atom')->getDateModified();
|
||||
|
||||
$this->_data['datemodified'] = $dateModified;
|
||||
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
if (array_key_exists('description', $this->_data)) {
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
$description = $this->getExtension('Atom')->getDescription();
|
||||
|
||||
$this->_data['description'] = $description;
|
||||
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry enclosure
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEnclosure()
|
||||
{
|
||||
if (array_key_exists('enclosure', $this->_data)) {
|
||||
return $this->_data['enclosure'];
|
||||
}
|
||||
|
||||
$enclosure = $this->getExtension('Atom')->getEnclosure();
|
||||
|
||||
$this->_data['enclosure'] = $enclosure;
|
||||
|
||||
return $this->_data['enclosure'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
if (array_key_exists('id', $this->_data)) {
|
||||
return $this->_data['id'];
|
||||
}
|
||||
|
||||
$id = $this->getExtension('Atom')->getId();
|
||||
|
||||
$this->_data['id'] = $id;
|
||||
|
||||
return $this->_data['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific link
|
||||
*
|
||||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
public function getLink($index = 0)
|
||||
{
|
||||
if (!array_key_exists('links', $this->_data)) {
|
||||
$this->getLinks();
|
||||
}
|
||||
|
||||
if (isset($this->_data['links'][$index])) {
|
||||
return $this->_data['links'][$index];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all links
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLinks()
|
||||
{
|
||||
if (array_key_exists('links', $this->_data)) {
|
||||
return $this->_data['links'];
|
||||
}
|
||||
|
||||
$links = $this->getExtension('Atom')->getLinks();
|
||||
|
||||
$this->_data['links'] = $links;
|
||||
|
||||
return $this->_data['links'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a permalink to the entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPermalink()
|
||||
{
|
||||
return $this->getLink(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
if (array_key_exists('title', $this->_data)) {
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
$title = $this->getExtension('Atom')->getTitle();
|
||||
|
||||
$this->_data['title'] = $title;
|
||||
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of comments/replies for current entry
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getCommentCount()
|
||||
{
|
||||
if (array_key_exists('commentcount', $this->_data)) {
|
||||
return $this->_data['commentcount'];
|
||||
}
|
||||
|
||||
$commentcount = $this->getExtension('Thread')->getCommentCount();
|
||||
|
||||
if (!$commentcount) {
|
||||
$commentcount = $this->getExtension('Atom')->getCommentCount();
|
||||
}
|
||||
|
||||
$this->_data['commentcount'] = $commentcount;
|
||||
|
||||
return $this->_data['commentcount'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URI pointing to the HTML page where comments can be made on this entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentLink()
|
||||
{
|
||||
if (array_key_exists('commentlink', $this->_data)) {
|
||||
return $this->_data['commentlink'];
|
||||
}
|
||||
|
||||
$commentlink = $this->getExtension('Atom')->getCommentLink();
|
||||
|
||||
$this->_data['commentlink'] = $commentlink;
|
||||
|
||||
return $this->_data['commentlink'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URI pointing to a feed of all comments for this entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentFeedLink()
|
||||
{
|
||||
if (array_key_exists('commentfeedlink', $this->_data)) {
|
||||
return $this->_data['commentfeedlink'];
|
||||
}
|
||||
|
||||
$commentfeedlink = $this->getExtension('Atom')->getCommentFeedLink();
|
||||
|
||||
$this->_data['commentfeedlink'] = $commentfeedlink;
|
||||
|
||||
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)
|
||||
*
|
||||
* @param DOMXPath $xpath
|
||||
*/
|
||||
public function setXpath(DOMXPath $xpath)
|
||||
{
|
||||
parent::setXpath($xpath);
|
||||
foreach ($this->_extensions as $extension) {
|
||||
$extension->setXpath($this->_xpath);
|
||||
}
|
||||
}
|
||||
}
|
665
library/Zend/Feed/Reader/Entry/Rss.php
Normal file
665
library/Zend/Feed/Reader/Entry/Rss.php
Normal file
|
@ -0,0 +1,665 @@
|
|||
<?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: Rss.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_EntryInterface
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/EntryInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_EntryAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/EntryAbstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_DublinCore_Entry
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/DublinCore/Entry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_Content_Entry
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/Content/Entry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_Atom_Entry
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/Atom/Entry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_WellformedWeb_Entry
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/WellFormedWeb/Entry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_Slash_Entry
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/Slash/Entry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_Thread_Entry
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/Thread/Entry.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Date
|
||||
*/
|
||||
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-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
|
||||
{
|
||||
|
||||
/**
|
||||
* XPath query for RDF
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_xpathQueryRdf = '';
|
||||
|
||||
/**
|
||||
* XPath query for RSS
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_xpathQueryRss = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Zend_Feed_Entry_Abstract $entry
|
||||
* @param string $entryKey
|
||||
* @param string $type
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(DOMElement $entry, $entryKey, $type = null)
|
||||
{
|
||||
parent::__construct($entry, $entryKey, $type);
|
||||
$this->_xpathQueryRss = '//item[' . ($this->_entryKey+1) . ']';
|
||||
$this->_xpathQueryRdf = '//rss:item[' . ($this->_entryKey+1) . ']';
|
||||
|
||||
$pluginLoader = Zend_Feed_Reader::getPluginLoader();
|
||||
|
||||
$dublinCoreClass = $pluginLoader->getClassName('DublinCore_Entry');
|
||||
$this->_extensions['DublinCore_Entry'] = new $dublinCoreClass($entry, $entryKey, $type);
|
||||
|
||||
$contentClass = $pluginLoader->getClassName('Content_Entry');
|
||||
$this->_extensions['Content_Entry'] = new $contentClass($entry, $entryKey, $type);
|
||||
|
||||
$atomClass = $pluginLoader->getClassName('Atom_Entry');
|
||||
$this->_extensions['Atom_Entry'] = new $atomClass($entry, $entryKey, $type);
|
||||
|
||||
$wfwClass = $pluginLoader->getClassName('WellFormedWeb_Entry');
|
||||
$this->_extensions['WellFormedWeb_Entry'] = new $wfwClass($entry, $entryKey, $type);
|
||||
|
||||
$slashClass = $pluginLoader->getClassName('Slash_Entry');
|
||||
$this->_extensions['Slash_Entry'] = new $slashClass($entry, $entryKey, $type);
|
||||
|
||||
$threadClass = $pluginLoader->getClassName('Thread_Entry');
|
||||
$this->_extensions['Thread_Entry'] = new $threadClass($entry, $entryKey, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an author entry
|
||||
*
|
||||
* @param DOMElement $element
|
||||
* @return string
|
||||
*/
|
||||
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();
|
||||
$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) {
|
||||
$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 (count($authors) == 0) {
|
||||
$authors = $this->getExtension('Atom')->getAuthors();
|
||||
} else {
|
||||
$authors = new Zend_Feed_Reader_Collection_Author(
|
||||
Zend_Feed_Reader::arrayUnique($authors)
|
||||
);
|
||||
}
|
||||
|
||||
if (count($authors) == 0) {
|
||||
$authors = null;
|
||||
}
|
||||
|
||||
$this->_data['authors'] = $authors;
|
||||
|
||||
return $this->_data['authors'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
if (array_key_exists('content', $this->_data)) {
|
||||
return $this->_data['content'];
|
||||
}
|
||||
|
||||
$content = $this->getExtension('Content')->getContent();
|
||||
|
||||
if (!$content) {
|
||||
$content = $this->getDescription();
|
||||
}
|
||||
|
||||
if (empty($content)) {
|
||||
$content = $this->getExtension('Atom')->getContent();
|
||||
}
|
||||
|
||||
$this->_data['content'] = $content;
|
||||
|
||||
return $this->_data['content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry's date of creation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateCreated()
|
||||
{
|
||||
return $this->getDateModified();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry's date of modification
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateModified()
|
||||
{
|
||||
if (array_key_exists('datemodified', $this->_data)) {
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
$dateModified = null;
|
||||
$date = null;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10
|
||||
&& $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090
|
||||
) {
|
||||
$dateModified = $this->_xpath->evaluate('string('.$this->_xpathQueryRss.'/pubDate)');
|
||||
if ($dateModified) {
|
||||
$dateStandards = array(Zend_Date::RSS, Zend_Date::RFC_822,
|
||||
Zend_Date::RFC_2822, Zend_Date::DATES);
|
||||
$date = new Zend_Date;
|
||||
foreach ($dateStandards as $standard) {
|
||||
try {
|
||||
$date->set($dateModified, $standard);
|
||||
break;
|
||||
} catch (Zend_Date_Exception $e) {
|
||||
if ($standard == Zend_Date::DATES) {
|
||||
require_once 'Zend/Feed/Exception.php';
|
||||
throw new Zend_Feed_Exception(
|
||||
'Could not load date due to unrecognised'
|
||||
.' format (should follow RFC 822 or 2822):'
|
||||
. $e->getMessage(),
|
||||
0, $e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$date) {
|
||||
$date = $this->getExtension('DublinCore')->getDate();
|
||||
}
|
||||
|
||||
if (!$date) {
|
||||
$date = $this->getExtension('Atom')->getDateModified();
|
||||
}
|
||||
|
||||
if (!$date) {
|
||||
$date = null;
|
||||
}
|
||||
|
||||
$this->_data['datemodified'] = $date;
|
||||
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
if (array_key_exists('description', $this->_data)) {
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
$description = null;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10
|
||||
&& $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090
|
||||
) {
|
||||
$description = $this->_xpath->evaluate('string('.$this->_xpathQueryRss.'/description)');
|
||||
} else {
|
||||
$description = $this->_xpath->evaluate('string('.$this->_xpathQueryRdf.'/rss:description)');
|
||||
}
|
||||
|
||||
if (!$description) {
|
||||
$description = $this->getExtension('DublinCore')->getDescription();
|
||||
}
|
||||
|
||||
if (empty($description)) {
|
||||
$description = $this->getExtension('Atom')->getDescription();
|
||||
}
|
||||
|
||||
if (!$description) {
|
||||
$description = null;
|
||||
} else {
|
||||
$description = html_entity_decode($description, ENT_QUOTES, $this->getEncoding());
|
||||
}
|
||||
|
||||
$this->_data['description'] = $description;
|
||||
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry enclosure
|
||||
* @return string
|
||||
*/
|
||||
public function getEnclosure()
|
||||
{
|
||||
if (array_key_exists('enclosure', $this->_data)) {
|
||||
return $this->_data['enclosure'];
|
||||
}
|
||||
|
||||
$enclosure = null;
|
||||
|
||||
if ($this->getType() == Zend_Feed_Reader::TYPE_RSS_20) {
|
||||
$nodeList = $this->_xpath->query($this->_xpathQueryRss . '/enclosure');
|
||||
|
||||
if ($nodeList->length > 0) {
|
||||
$enclosure = new stdClass();
|
||||
$enclosure->url = $nodeList->item(0)->getAttribute('url');
|
||||
$enclosure->length = $nodeList->item(0)->getAttribute('length');
|
||||
$enclosure->type = $nodeList->item(0)->getAttribute('type');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$enclosure) {
|
||||
$enclosure = $this->getExtension('Atom')->getEnclosure();
|
||||
}
|
||||
|
||||
$this->_data['enclosure'] = $enclosure;
|
||||
|
||||
return $this->_data['enclosure'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
if (array_key_exists('id', $this->_data)) {
|
||||
return $this->_data['id'];
|
||||
}
|
||||
|
||||
$id = null;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10
|
||||
&& $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090
|
||||
) {
|
||||
$id = $this->_xpath->evaluate('string('.$this->_xpathQueryRss.'/guid)');
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
$id = $this->getExtension('DublinCore')->getId();
|
||||
}
|
||||
|
||||
if (empty($id)) {
|
||||
$id = $this->getExtension('Atom')->getId();
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
if ($this->getPermalink()) {
|
||||
$id = $this->getPermalink();
|
||||
} elseif ($this->getTitle()) {
|
||||
$id = $this->getTitle();
|
||||
} else {
|
||||
$id = null;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_data['id'] = $id;
|
||||
|
||||
return $this->_data['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific link
|
||||
*
|
||||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
public function getLink($index = 0)
|
||||
{
|
||||
if (!array_key_exists('links', $this->_data)) {
|
||||
$this->getLinks();
|
||||
}
|
||||
|
||||
if (isset($this->_data['links'][$index])) {
|
||||
return $this->_data['links'][$index];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all links
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLinks()
|
||||
{
|
||||
if (array_key_exists('links', $this->_data)) {
|
||||
return $this->_data['links'];
|
||||
}
|
||||
|
||||
$links = array();
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 &&
|
||||
$this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$list = $this->_xpath->query($this->_xpathQueryRss.'//link');
|
||||
} else {
|
||||
$list = $this->_xpath->query($this->_xpathQueryRdf.'//rss:link');
|
||||
}
|
||||
|
||||
if (!$list->length) {
|
||||
$links = $this->getExtension('Atom')->getLinks();
|
||||
} else {
|
||||
foreach ($list as $link) {
|
||||
$links[] = $link->nodeValue;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_data['links'] = $links;
|
||||
|
||||
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
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPermalink()
|
||||
{
|
||||
return $this->getLink(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
if (array_key_exists('title', $this->_data)) {
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
$title = null;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10
|
||||
&& $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090
|
||||
) {
|
||||
$title = $this->_xpath->evaluate('string('.$this->_xpathQueryRss.'/title)');
|
||||
} else {
|
||||
$title = $this->_xpath->evaluate('string('.$this->_xpathQueryRdf.'/rss:title)');
|
||||
}
|
||||
|
||||
if (!$title) {
|
||||
$title = $this->getExtension('DublinCore')->getTitle();
|
||||
}
|
||||
|
||||
if (!$title) {
|
||||
$title = $this->getExtension('Atom')->getTitle();
|
||||
}
|
||||
|
||||
if (!$title) {
|
||||
$title = null;
|
||||
}
|
||||
|
||||
$this->_data['title'] = $title;
|
||||
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of comments/replies for current entry
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCommentCount()
|
||||
{
|
||||
if (array_key_exists('commentcount', $this->_data)) {
|
||||
return $this->_data['commentcount'];
|
||||
}
|
||||
|
||||
$commentcount = $this->getExtension('Slash')->getCommentCount();
|
||||
|
||||
if (!$commentcount) {
|
||||
$commentcount = $this->getExtension('Thread')->getCommentCount();
|
||||
}
|
||||
|
||||
if (!$commentcount) {
|
||||
$commentcount = $this->getExtension('Atom')->getCommentCount();
|
||||
}
|
||||
|
||||
if (!$commentcount) {
|
||||
$commentcount = null;
|
||||
}
|
||||
|
||||
$this->_data['commentcount'] = $commentcount;
|
||||
|
||||
return $this->_data['commentcount'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URI pointing to the HTML page where comments can be made on this entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentLink()
|
||||
{
|
||||
if (array_key_exists('commentlink', $this->_data)) {
|
||||
return $this->_data['commentlink'];
|
||||
}
|
||||
|
||||
$commentlink = null;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10
|
||||
&& $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090
|
||||
) {
|
||||
$commentlink = $this->_xpath->evaluate('string('.$this->_xpathQueryRss.'/comments)');
|
||||
}
|
||||
|
||||
if (!$commentlink) {
|
||||
$commentlink = $this->getExtension('Atom')->getCommentLink();
|
||||
}
|
||||
|
||||
if (!$commentlink) {
|
||||
$commentlink = null;
|
||||
}
|
||||
|
||||
$this->_data['commentlink'] = $commentlink;
|
||||
|
||||
return $this->_data['commentlink'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URI pointing to a feed of all comments for this entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentFeedLink()
|
||||
{
|
||||
if (array_key_exists('commentfeedlink', $this->_data)) {
|
||||
return $this->_data['commentfeedlink'];
|
||||
}
|
||||
|
||||
$commentfeedlink = $this->getExtension('WellFormedWeb')->getCommentFeedLink();
|
||||
|
||||
if (!$commentfeedlink) {
|
||||
$commentfeedlink = $this->getExtension('Atom')->getCommentFeedLink('rss');
|
||||
}
|
||||
|
||||
if (!$commentfeedlink) {
|
||||
$commentfeedlink = $this->getExtension('Atom')->getCommentFeedLink('rdf');
|
||||
}
|
||||
|
||||
if (!$commentfeedlink) {
|
||||
$commentfeedlink = null;
|
||||
}
|
||||
|
||||
$this->_data['commentfeedlink'] = $commentfeedlink;
|
||||
|
||||
return $this->_data['commentfeedlink'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the XPath query (incl. on all Extensions)
|
||||
*
|
||||
* @param DOMXPath $xpath
|
||||
*/
|
||||
public function setXpath(DOMXPath $xpath)
|
||||
{
|
||||
parent::setXpath($xpath);
|
||||
foreach ($this->_extensions as $extension) {
|
||||
$extension->setXpath($this->_xpath);
|
||||
}
|
||||
}
|
||||
}
|
238
library/Zend/Feed/Reader/EntryAbstract.php
Normal file
238
library/Zend/Feed/Reader/EntryAbstract.php
Normal file
|
@ -0,0 +1,238 @@
|
|||
<?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: EntryAbstract.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_EntryAbstract
|
||||
{
|
||||
/**
|
||||
* Feed entry data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_data = array();
|
||||
|
||||
/**
|
||||
* DOM document object
|
||||
*
|
||||
* @var DOMDocument
|
||||
*/
|
||||
protected $_domDocument = null;
|
||||
|
||||
/**
|
||||
* Entry instance
|
||||
*
|
||||
* @var Zend_Feed_Entry_Interface
|
||||
*/
|
||||
protected $_entry = null;
|
||||
|
||||
/**
|
||||
* Pointer to the current entry
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_entryKey = 0;
|
||||
|
||||
/**
|
||||
* XPath object
|
||||
*
|
||||
* @var DOMXPath
|
||||
*/
|
||||
protected $_xpath = null;
|
||||
|
||||
/**
|
||||
* Registered extensions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_extensions = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DOMElement $entry
|
||||
* @param int $entryKey
|
||||
* @param string $type
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(DOMElement $entry, $entryKey, $type = null)
|
||||
{
|
||||
$this->_entry = $entry;
|
||||
$this->_entryKey = $entryKey;
|
||||
$this->_domDocument = $entry->ownerDocument;
|
||||
if ($type !== null) {
|
||||
$this->_data['type'] = $type;
|
||||
} else {
|
||||
$this->_data['type'] = Zend_Feed_Reader::detectType($feed);
|
||||
}
|
||||
$this->_loadExtensions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DOM
|
||||
*
|
||||
* @return DOMDocument
|
||||
*/
|
||||
public function getDomDocument()
|
||||
{
|
||||
return $this->_domDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry element
|
||||
*
|
||||
* @return DOMElement
|
||||
*/
|
||||
public function getElement()
|
||||
{
|
||||
return $this->_entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Entry's encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
$assumed = $this->getDomDocument()->encoding;
|
||||
if (empty($assumed)) {
|
||||
$assumed = 'UTF-8';
|
||||
}
|
||||
return $assumed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entry as xml
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function saveXml()
|
||||
{
|
||||
$dom = new DOMDocument('1.0', $this->getEncoding());
|
||||
$entry = $dom->importNode($this->getElement(), true);
|
||||
$dom->appendChild($entry);
|
||||
return $dom->saveXml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_data['type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the XPath query object
|
||||
*
|
||||
* @return DOMXPath
|
||||
*/
|
||||
public function getXpath()
|
||||
{
|
||||
if (!$this->_xpath) {
|
||||
$this->setXpath(new DOMXPath($this->getDomDocument()));
|
||||
}
|
||||
return $this->_xpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the XPath query
|
||||
*
|
||||
* @param DOMXPath $xpath
|
||||
* @return Zend_Feed_Reader_Entry_EntryAbstract
|
||||
*/
|
||||
public function setXpath(DOMXPath $xpath)
|
||||
{
|
||||
$this->_xpath = $xpath;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get registered extensions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensions()
|
||||
{
|
||||
return $this->_extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an Extension object with the matching name (postfixed with _Entry)
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Feed_Reader_Extension_EntryAbstract
|
||||
*/
|
||||
public function getExtension($name)
|
||||
{
|
||||
if (array_key_exists($name . '_Entry', $this->_extensions)) {
|
||||
return $this->_extensions[$name . '_Entry'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method overloading: call given method on first extension implementing it
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
* @throws Zend_Feed_Exception if no extensions implements the method
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
foreach ($this->_extensions as $extension) {
|
||||
if (method_exists($extension, $method)) {
|
||||
return call_user_func_array(array($extension, $method), $args);
|
||||
}
|
||||
}
|
||||
require_once 'Zend/Feed/Exception.php';
|
||||
throw new Zend_Feed_Exception('Method: ' . $method
|
||||
. 'does not exist and could not be located on a registered Extension');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load extensions from Zend_Feed_Reader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _loadExtensions()
|
||||
{
|
||||
$all = Zend_Feed_Reader::getExtensions();
|
||||
$feed = $all['entry'];
|
||||
foreach ($feed as $extension) {
|
||||
if (in_array($extension, $all['core'])) {
|
||||
continue;
|
||||
}
|
||||
$className = Zend_Feed_Reader::getPluginLoader()->getClassName($extension);
|
||||
$this->_extensions[$extension] = new $className(
|
||||
$this->getElement(), $this->_entryKey, $this->_data['type']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
143
library/Zend/Feed/Reader/EntryInterface.php
Normal file
143
library/Zend/Feed/Reader/EntryInterface.php
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?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: EntryInterface.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
|
||||
*/
|
||||
interface Zend_Feed_Reader_EntryInterface
|
||||
{
|
||||
/**
|
||||
* Get the specified author
|
||||
*
|
||||
* @param int $index
|
||||
* @return string|null
|
||||
*/
|
||||
public function getAuthor($index = 0);
|
||||
|
||||
/**
|
||||
* Get an array with feed authors
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAuthors();
|
||||
|
||||
/**
|
||||
* Get the entry content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent();
|
||||
|
||||
/**
|
||||
* Get the entry creation date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateCreated();
|
||||
|
||||
/**
|
||||
* Get the entry modification date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateModified();
|
||||
|
||||
/**
|
||||
* Get the entry description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription();
|
||||
|
||||
/**
|
||||
* Get the entry enclosure
|
||||
*
|
||||
* @return stdClass
|
||||
*/
|
||||
public function getEnclosure();
|
||||
|
||||
/**
|
||||
* Get the entry ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
* Get a specific link
|
||||
*
|
||||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
public function getLink($index = 0);
|
||||
|
||||
/**
|
||||
* Get all links
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLinks();
|
||||
|
||||
/**
|
||||
* Get a permalink to the entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPermalink();
|
||||
|
||||
/**
|
||||
* Get the entry title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle();
|
||||
|
||||
/**
|
||||
* Get the number of comments/replies for current entry
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getCommentCount();
|
||||
|
||||
/**
|
||||
* Returns a URI pointing to the HTML page where comments can be made on this entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentLink();
|
||||
|
||||
/**
|
||||
* Returns a URI pointing to a feed of all comments for this entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentFeedLink();
|
||||
|
||||
/**
|
||||
* Get all categories
|
||||
*
|
||||
* @return Zend_Feed_Reader_Collection_Category
|
||||
*/
|
||||
public function getCategories();
|
||||
}
|
665
library/Zend/Feed/Reader/Extension/Atom/Entry.php
Normal file
665
library/Zend/Feed/Reader/Extension/Atom/Entry.php
Normal file
|
@ -0,0 +1,665 @@
|
|||
<?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: Entry.php 20507 2010-01-21 22:21:07Z padraic $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_EntryAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Date
|
||||
*/
|
||||
require_once 'Zend/Date.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Uri
|
||||
*/
|
||||
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-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
|
||||
extends Zend_Feed_Reader_Extension_EntryAbstract
|
||||
{
|
||||
/**
|
||||
* Get the specified 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($this->getXpathPrefix() . '//atom:author');
|
||||
|
||||
if (!$list->length) {
|
||||
/**
|
||||
* TODO: Limit query to feed level els only!
|
||||
*/
|
||||
$list = $this->getXpath()->query('//atom:author');
|
||||
}
|
||||
|
||||
if ($list->length) {
|
||||
foreach ($list as $author) {
|
||||
$author = $this->_getAuthor($author);
|
||||
if (!empty($author)) {
|
||||
$authors[] = $author;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
if (array_key_exists('content', $this->_data)) {
|
||||
return $this->_data['content'];
|
||||
}
|
||||
|
||||
$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'] = 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
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateCreated()
|
||||
{
|
||||
if (array_key_exists('datecreated', $this->_data)) {
|
||||
return $this->_data['datecreated'];
|
||||
}
|
||||
|
||||
$date = null;
|
||||
|
||||
if ($this->_getAtomType() === Zend_Feed_Reader::TYPE_ATOM_03) {
|
||||
$dateCreated = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:created)');
|
||||
} else {
|
||||
$dateCreated = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:published)');
|
||||
}
|
||||
|
||||
if ($dateCreated) {
|
||||
$date = new Zend_Date;
|
||||
$date->set($dateCreated, Zend_Date::ISO_8601);
|
||||
}
|
||||
|
||||
$this->_data['datecreated'] = $date;
|
||||
|
||||
return $this->_data['datecreated'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry modification date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDateModified()
|
||||
{
|
||||
if (array_key_exists('datemodified', $this->_data)) {
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
$date = null;
|
||||
|
||||
if ($this->_getAtomType() === Zend_Feed_Reader::TYPE_ATOM_03) {
|
||||
$dateModified = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:modified)');
|
||||
} else {
|
||||
$dateModified = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:updated)');
|
||||
}
|
||||
|
||||
if ($dateModified) {
|
||||
$date = new Zend_Date;
|
||||
$date->set($dateModified, Zend_Date::ISO_8601);
|
||||
}
|
||||
|
||||
$this->_data['datemodified'] = $date;
|
||||
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
if (array_key_exists('description', $this->_data)) {
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
$description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:summary)');
|
||||
|
||||
if (!$description) {
|
||||
$description = null;
|
||||
} else {
|
||||
$description = html_entity_decode($description, ENT_QUOTES, $this->getEncoding());
|
||||
}
|
||||
|
||||
$this->_data['description'] = $description;
|
||||
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry enclosure
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEnclosure()
|
||||
{
|
||||
if (array_key_exists('enclosure', $this->_data)) {
|
||||
return $this->_data['enclosure'];
|
||||
}
|
||||
|
||||
$enclosure = null;
|
||||
|
||||
$nodeList = $this->getXpath()->query($this->getXpathPrefix() . '/atom:link[@rel="enclosure"]');
|
||||
|
||||
if ($nodeList->length > 0) {
|
||||
$enclosure = new stdClass();
|
||||
$enclosure->url = $nodeList->item(0)->getAttribute('href');
|
||||
$enclosure->length = $nodeList->item(0)->getAttribute('length');
|
||||
$enclosure->type = $nodeList->item(0)->getAttribute('type');
|
||||
}
|
||||
|
||||
$this->_data['enclosure'] = $enclosure;
|
||||
|
||||
return $this->_data['enclosure'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
if (array_key_exists('id', $this->_data)) {
|
||||
return $this->_data['id'];
|
||||
}
|
||||
|
||||
$id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:id)');
|
||||
|
||||
if (!$id) {
|
||||
if ($this->getPermalink()) {
|
||||
$id = $this->getPermalink();
|
||||
} elseif ($this->getTitle()) {
|
||||
$id = $this->getTitle();
|
||||
} else {
|
||||
$id = null;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_data['id'] = $id;
|
||||
|
||||
return $this->_data['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base URI of the feed (if set).
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
{
|
||||
if (array_key_exists('baseUrl', $this->_data)) {
|
||||
return $this->_data['baseUrl'];
|
||||
}
|
||||
|
||||
$baseUrl = $this->getXpath()->evaluate('string('
|
||||
. $this->getXpathPrefix() . '/@xml:base[1]'
|
||||
. ')');
|
||||
|
||||
if (!$baseUrl) {
|
||||
$baseUrl = $this->getXpath()->evaluate('string(//@xml:base[1])');
|
||||
}
|
||||
|
||||
if (!$baseUrl) {
|
||||
$baseUrl = null;
|
||||
}
|
||||
|
||||
$this->_data['baseUrl'] = $baseUrl;
|
||||
|
||||
return $this->_data['baseUrl'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific link
|
||||
*
|
||||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
public function getLink($index = 0)
|
||||
{
|
||||
if (!array_key_exists('links', $this->_data)) {
|
||||
$this->getLinks();
|
||||
}
|
||||
|
||||
if (isset($this->_data['links'][$index])) {
|
||||
return $this->_data['links'][$index];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all links
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLinks()
|
||||
{
|
||||
if (array_key_exists('links', $this->_data)) {
|
||||
return $this->_data['links'];
|
||||
}
|
||||
|
||||
$links = array();
|
||||
|
||||
$list = $this->getXpath()->query(
|
||||
$this->getXpathPrefix() . '//atom:link[@rel="alternate"]/@href' . '|' .
|
||||
$this->getXpathPrefix() . '//atom:link[not(@rel)]/@href'
|
||||
);
|
||||
|
||||
if ($list->length) {
|
||||
foreach ($list as $link) {
|
||||
$links[] = $this->_absolutiseUri($link->value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_data['links'] = $links;
|
||||
|
||||
return $this->_data['links'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a permalink to the entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPermalink()
|
||||
{
|
||||
return $this->getLink(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
if (array_key_exists('title', $this->_data)) {
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
$title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:title)');
|
||||
|
||||
if (!$title) {
|
||||
$title = null;
|
||||
} else {
|
||||
$title = html_entity_decode($title, ENT_QUOTES, $this->getEncoding());
|
||||
}
|
||||
|
||||
$this->_data['title'] = $title;
|
||||
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of comments/replies for current entry
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getCommentCount()
|
||||
{
|
||||
if (array_key_exists('commentcount', $this->_data)) {
|
||||
return $this->_data['commentcount'];
|
||||
}
|
||||
|
||||
$count = null;
|
||||
|
||||
$this->getXpath()->registerNamespace('thread10', 'http://purl.org/syndication/thread/1.0');
|
||||
$list = $this->getXpath()->query(
|
||||
$this->getXpathPrefix() . '//atom:link[@rel="replies"]/@thread10:count'
|
||||
);
|
||||
|
||||
if ($list->length) {
|
||||
$count = $list->item(0)->value;
|
||||
}
|
||||
|
||||
$this->_data['commentcount'] = $count;
|
||||
|
||||
return $this->_data['commentcount'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URI pointing to the HTML page where comments can be made on this entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentLink()
|
||||
{
|
||||
if (array_key_exists('commentlink', $this->_data)) {
|
||||
return $this->_data['commentlink'];
|
||||
}
|
||||
|
||||
$link = null;
|
||||
|
||||
$list = $this->getXpath()->query(
|
||||
$this->getXpathPrefix() . '//atom:link[@rel="replies" and @type="text/html"]/@href'
|
||||
);
|
||||
|
||||
if ($list->length) {
|
||||
$link = $list->item(0)->value;
|
||||
$link = $this->_absolutiseUri($link);
|
||||
}
|
||||
|
||||
$this->_data['commentlink'] = $link;
|
||||
|
||||
return $this->_data['commentlink'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URI pointing to a feed of all comments for this entry
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentFeedLink($type = 'atom')
|
||||
{
|
||||
if (array_key_exists('commentfeedlink', $this->_data)) {
|
||||
return $this->_data['commentfeedlink'];
|
||||
}
|
||||
|
||||
$link = null;
|
||||
|
||||
$list = $this->getXpath()->query(
|
||||
$this->getXpathPrefix() . '//atom:link[@rel="replies" and @type="application/'.$type.'+xml"]/@href'
|
||||
);
|
||||
|
||||
if ($list->length) {
|
||||
$link = $list->item(0)->value;
|
||||
$link = $this->_absolutiseUri($link);
|
||||
}
|
||||
|
||||
$this->_data['commentfeedlink'] = $link;
|
||||
|
||||
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
|
||||
* xml:base value as a prefix to turn into an absolute URI.
|
||||
*/
|
||||
protected function _absolutiseUri($link)
|
||||
{
|
||||
if (!Zend_Uri::check($link)) {
|
||||
if (!is_null($this->getBaseUrl())) {
|
||||
$link = $this->getBaseUrl() . $link;
|
||||
if (!Zend_Uri::check($link)) {
|
||||
$link = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an author entry
|
||||
*
|
||||
* @param DOMElement $element
|
||||
* @return string
|
||||
*/
|
||||
protected function _getAuthor(DOMElement $element)
|
||||
{
|
||||
$author = array();
|
||||
|
||||
$emailNode = $element->getElementsByTagName('email');
|
||||
$nameNode = $element->getElementsByTagName('name');
|
||||
$uriNode = $element->getElementsByTagName('uri');
|
||||
|
||||
if ($emailNode->length && strlen($emailNode->item(0)->nodeValue) > 0) {
|
||||
$author['email'] = $emailNode->item(0)->nodeValue;
|
||||
}
|
||||
|
||||
if ($nameNode->length && strlen($nameNode->item(0)->nodeValue) > 0) {
|
||||
$author['name'] = $nameNode->item(0)->nodeValue;
|
||||
}
|
||||
|
||||
if ($uriNode->length && strlen($uriNode->item(0)->nodeValue) > 0) {
|
||||
$author['uri'] = $uriNode->item(0)->nodeValue;
|
||||
}
|
||||
|
||||
if (empty($author)) {
|
||||
return null;
|
||||
}
|
||||
return $author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the default namespaces for the current feed format
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
switch ($this->_getAtomType()) {
|
||||
case Zend_Feed_Reader::TYPE_ATOM_03:
|
||||
$this->getXpath()->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_03);
|
||||
break;
|
||||
default:
|
||||
$this->getXpath()->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect the presence of any Atom namespaces in use
|
||||
*/
|
||||
protected function _getAtomType()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
544
library/Zend/Feed/Reader/Extension/Atom/Feed.php
Normal file
544
library/Zend/Feed/Reader/Extension/Atom/Feed.php
Normal file
|
@ -0,0 +1,544 @@
|
|||
<?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: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_FeedAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Date
|
||||
*/
|
||||
require_once 'Zend/Date.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Uri
|
||||
*/
|
||||
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-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
|
||||
extends Zend_Feed_Reader_Extension_FeedAbstract
|
||||
{
|
||||
/**
|
||||
* 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'];
|
||||
}
|
||||
|
||||
$list = $this->_xpath->query('//atom:author');
|
||||
|
||||
$authors = array();
|
||||
|
||||
if ($list->length) {
|
||||
foreach ($list as $author) {
|
||||
$author = $this->_getAuthor($author);
|
||||
if (!empty($author)) {
|
||||
$authors[] = $author;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the copyright entry
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCopyright()
|
||||
{
|
||||
if (array_key_exists('copyright', $this->_data)) {
|
||||
return $this->_data['copyright'];
|
||||
}
|
||||
|
||||
$copyright = null;
|
||||
|
||||
if ($this->getType() === Zend_Feed_Reader::TYPE_ATOM_03) {
|
||||
$copyright = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:copyright)');
|
||||
} else {
|
||||
$copyright = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:rights)');
|
||||
}
|
||||
|
||||
if (!$copyright) {
|
||||
$copyright = null;
|
||||
}
|
||||
|
||||
$this->_data['copyright'] = $copyright;
|
||||
|
||||
return $this->_data['copyright'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed creation date
|
||||
*
|
||||
* @return Zend_Date|null
|
||||
*/
|
||||
public function getDateCreated()
|
||||
{
|
||||
if (array_key_exists('datecreated', $this->_data)) {
|
||||
return $this->_data['datecreated'];
|
||||
}
|
||||
|
||||
$date = null;
|
||||
|
||||
if ($this->getType() === Zend_Feed_Reader::TYPE_ATOM_03) {
|
||||
$dateCreated = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:created)');
|
||||
} else {
|
||||
$dateCreated = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:published)');
|
||||
}
|
||||
|
||||
if ($dateCreated) {
|
||||
$date = new Zend_Date;
|
||||
$date->set($dateCreated, Zend_Date::ISO_8601);
|
||||
}
|
||||
|
||||
$this->_data['datecreated'] = $date;
|
||||
|
||||
return $this->_data['datecreated'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed modification date
|
||||
*
|
||||
* @return Zend_Date|null
|
||||
*/
|
||||
public function getDateModified()
|
||||
{
|
||||
if (array_key_exists('datemodified', $this->_data)) {
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
$date = null;
|
||||
|
||||
if ($this->getType() === Zend_Feed_Reader::TYPE_ATOM_03) {
|
||||
$dateModified = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:modified)');
|
||||
} else {
|
||||
$dateModified = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:updated)');
|
||||
}
|
||||
|
||||
if ($dateModified) {
|
||||
$date = new Zend_Date;
|
||||
$date->set($dateModified, Zend_Date::ISO_8601);
|
||||
}
|
||||
|
||||
$this->_data['datemodified'] = $date;
|
||||
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed description
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
if (array_key_exists('description', $this->_data)) {
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
$description = null;
|
||||
|
||||
if ($this->getType() === Zend_Feed_Reader::TYPE_ATOM_03) {
|
||||
$description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:tagline)'); // TODO: Is this the same as subtitle?
|
||||
} else {
|
||||
$description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:subtitle)');
|
||||
}
|
||||
|
||||
if (!$description) {
|
||||
$description = null;
|
||||
}
|
||||
|
||||
$this->_data['description'] = $description;
|
||||
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed generator entry
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getGenerator()
|
||||
{
|
||||
if (array_key_exists('generator', $this->_data)) {
|
||||
return $this->_data['generator'];
|
||||
}
|
||||
// TODO: Add uri support
|
||||
$generator = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:generator)');
|
||||
|
||||
if (!$generator) {
|
||||
$generator = null;
|
||||
} else {
|
||||
$generator = html_entity_decode($generator, ENT_QUOTES, $this->getEncoding());
|
||||
}
|
||||
|
||||
$this->_data['generator'] = $generator;
|
||||
|
||||
return $this->_data['generator'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed ID
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
if (array_key_exists('id', $this->_data)) {
|
||||
return $this->_data['id'];
|
||||
}
|
||||
|
||||
$id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:id)');
|
||||
|
||||
if (!$id) {
|
||||
if ($this->getLink()) {
|
||||
$id = $this->getLink();
|
||||
} elseif ($this->getTitle()) {
|
||||
$id = $this->getTitle();
|
||||
} else {
|
||||
$id = null;
|
||||
}
|
||||
}
|
||||
|
||||
$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 = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:lang)');
|
||||
|
||||
if (!$language) {
|
||||
$language = $this->_xpath->evaluate('string(//@xml:lang[1])');
|
||||
}
|
||||
|
||||
if (!$language) {
|
||||
$language = null;
|
||||
}
|
||||
|
||||
$this->_data['language'] = $language;
|
||||
|
||||
return $this->_data['language'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base URI of the feed (if set).
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
{
|
||||
if (array_key_exists('baseUrl', $this->_data)) {
|
||||
return $this->_data['baseUrl'];
|
||||
}
|
||||
|
||||
$baseUrl = $this->_xpath->evaluate('string(//@xml:base[1])');
|
||||
|
||||
if (!$baseUrl) {
|
||||
$baseUrl = null;
|
||||
}
|
||||
$this->_data['baseUrl'] = $baseUrl;
|
||||
|
||||
return $this->_data['baseUrl'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a link to the source website
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLink()
|
||||
{
|
||||
if (array_key_exists('link', $this->_data)) {
|
||||
return $this->_data['link'];
|
||||
}
|
||||
|
||||
$link = null;
|
||||
|
||||
$list = $this->_xpath->query(
|
||||
$this->getXpathPrefix() . '/atom:link[@rel="alternate"]/@href' . '|' .
|
||||
$this->getXpathPrefix() . '/atom:link[not(@rel)]/@href'
|
||||
);
|
||||
|
||||
if ($list->length) {
|
||||
$link = $list->item(0)->nodeValue;
|
||||
$link = $this->_absolutiseUri($link);
|
||||
}
|
||||
|
||||
$this->_data['link'] = $link;
|
||||
|
||||
return $this->_data['link'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a link to the feed's XML Url
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFeedLink()
|
||||
{
|
||||
if (array_key_exists('feedlink', $this->_data)) {
|
||||
return $this->_data['feedlink'];
|
||||
}
|
||||
|
||||
$link = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:link[@rel="self"]/@href)');
|
||||
|
||||
$link = $this->_absolutiseUri($link);
|
||||
|
||||
$this->_data['feedlink'] = $link;
|
||||
|
||||
return $this->_data['feedlink'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
if (array_key_exists('title', $this->_data)) {
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
$title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:title)');
|
||||
|
||||
if (!$title) {
|
||||
$title = null;
|
||||
}
|
||||
|
||||
$this->_data['title'] = $title;
|
||||
|
||||
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
|
||||
*
|
||||
* @param DOMElement $element
|
||||
* @return string
|
||||
*/
|
||||
protected function _getAuthor(DOMElement $element)
|
||||
{
|
||||
$author = array();
|
||||
|
||||
$emailNode = $element->getElementsByTagName('email');
|
||||
$nameNode = $element->getElementsByTagName('name');
|
||||
$uriNode = $element->getElementsByTagName('uri');
|
||||
|
||||
if ($emailNode->length && strlen($emailNode->item(0)->nodeValue) > 0) {
|
||||
$author['email'] = $emailNode->item(0)->nodeValue;
|
||||
}
|
||||
|
||||
if ($nameNode->length && strlen($nameNode->item(0)->nodeValue) > 0) {
|
||||
$author['name'] = $nameNode->item(0)->nodeValue;
|
||||
}
|
||||
|
||||
if ($uriNode->length && strlen($uriNode->item(0)->nodeValue) > 0) {
|
||||
$author['uri'] = $uriNode->item(0)->nodeValue;
|
||||
}
|
||||
|
||||
if (empty($author)) {
|
||||
return null;
|
||||
}
|
||||
return $author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to absolutise the URI, i.e. if a relative URI apply the
|
||||
* xml:base value as a prefix to turn into an absolute URI.
|
||||
*/
|
||||
protected function _absolutiseUri($link)
|
||||
{
|
||||
if (!Zend_Uri::check($link)) {
|
||||
if (!is_null($this->getBaseUrl())) {
|
||||
$link = $this->getBaseUrl() . $link;
|
||||
if (!Zend_Uri::check($link)) {
|
||||
$link = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the default namespaces for the current feed format
|
||||
*/
|
||||
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) {
|
||||
case Zend_Feed_Reader::TYPE_ATOM_03:
|
||||
$this->_xpath->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_03);
|
||||
break;
|
||||
default:
|
||||
$this->_xpath->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect the presence of any Atom namespaces in use
|
||||
*/
|
||||
protected function _getAtomType()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
64
library/Zend/Feed/Reader/Extension/Content/Entry.php
Normal file
64
library/Zend/Feed/Reader/Extension/Content/Entry.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?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: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Entry_EntryAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/EntryAbstract.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_Extension_Content_Entry
|
||||
extends Zend_Feed_Reader_Extension_EntryAbstract
|
||||
{
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10
|
||||
&& $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090
|
||||
) {
|
||||
$content = $this->_xpath->evaluate('string('.$this->getXpathPrefix().'/content:encoded)');
|
||||
} else {
|
||||
$content = $this->_xpath->evaluate('string('.$this->getXpathPrefix().'/content:encoded)');
|
||||
}
|
||||
if ($content) {
|
||||
$content = html_entity_decode($content, ENT_QUOTES, $this->getEncoding());
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register RSS Content Module namespace
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
$this->_xpath->registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/');
|
||||
}
|
||||
}
|
97
library/Zend/Feed/Reader/Extension/CreativeCommons/Entry.php
Normal file
97
library/Zend/Feed/Reader/Extension/CreativeCommons/Entry.php
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?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: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_EntryAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_CreativeCommons_Feed
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/CreativeCommons/Feed.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_Extension_CreativeCommons_Entry extends Zend_Feed_Reader_Extension_EntryAbstract
|
||||
{
|
||||
/**
|
||||
* Get the entry license
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLicense($index = 0)
|
||||
{
|
||||
$licenses = $this->getLicenses();
|
||||
|
||||
if (isset($licenses[$index])) {
|
||||
return $licenses[$index];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry licenses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLicenses()
|
||||
{
|
||||
$name = 'licenses';
|
||||
if (array_key_exists($name, $this->_data)) {
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
$licenses = array();
|
||||
$list = $this->_xpath->evaluate($this->getXpathPrefix() . '//cc:license');
|
||||
|
||||
if ($list->length) {
|
||||
foreach ($list as $license) {
|
||||
$licenses[] = $license->nodeValue;
|
||||
}
|
||||
|
||||
$licenses = array_unique($licenses);
|
||||
} else {
|
||||
$cc = new Zend_Feed_Reader_Extension_CreativeCommons_Feed(
|
||||
$this->_domDocument, $this->_data['type'], $this->_xpath
|
||||
);
|
||||
$licenses = $cc->getLicenses();
|
||||
}
|
||||
|
||||
$this->_data[$name] = $licenses;
|
||||
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Creative Commons namespaces
|
||||
*
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
$this->_xpath->registerNamespace('cc', 'http://backend.userland.com/creativeCommonsRssModule');
|
||||
}
|
||||
}
|
89
library/Zend/Feed/Reader/Extension/CreativeCommons/Feed.php
Normal file
89
library/Zend/Feed/Reader/Extension/CreativeCommons/Feed.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?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: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_FeedAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/FeedAbstract.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_Extension_CreativeCommons_Feed
|
||||
extends Zend_Feed_Reader_Extension_FeedAbstract
|
||||
{
|
||||
/**
|
||||
* Get the entry license
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLicense($index = 0)
|
||||
{
|
||||
$licenses = $this->getLicenses();
|
||||
|
||||
if (isset($licenses[$index])) {
|
||||
return $licenses[$index];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry licenses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLicenses()
|
||||
{
|
||||
$name = 'licenses';
|
||||
if (array_key_exists($name, $this->_data)) {
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
$licenses = array();
|
||||
$list = $this->_xpath->evaluate('channel/cc:license');
|
||||
|
||||
if ($list->length) {
|
||||
foreach ($list as $license) {
|
||||
$licenses[] = $license->nodeValue;
|
||||
}
|
||||
|
||||
$licenses = array_unique($licenses);
|
||||
}
|
||||
|
||||
$this->_data[$name] = $licenses;
|
||||
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Creative Commons namespaces
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
$this->_xpath->registerNamespace('cc', 'http://backend.userland.com/creativeCommonsRssModule');
|
||||
}
|
||||
}
|
266
library/Zend/Feed/Reader/Extension/DublinCore/Entry.php
Normal file
266
library/Zend/Feed/Reader/Extension/DublinCore/Entry.php
Normal file
|
@ -0,0 +1,266 @@
|
|||
<?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: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_EntryAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Date
|
||||
*/
|
||||
require_once 'Zend/Date.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_Extension_DublinCore_Entry
|
||||
extends Zend_Feed_Reader_Extension_EntryAbstract
|
||||
{
|
||||
/**
|
||||
* Get an author entry
|
||||
*
|
||||
* @param DOMElement $element
|
||||
* @return string
|
||||
*/
|
||||
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->_xpath->evaluate($this->getXpathPrefix() . '//dc11:creator');
|
||||
|
||||
if (!$list->length) {
|
||||
$list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:creator');
|
||||
}
|
||||
if (!$list->length) {
|
||||
$list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:publisher');
|
||||
|
||||
if (!$list->length) {
|
||||
$list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:publisher');
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->getDescription();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
if (array_key_exists('description', $this->_data)) {
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
$description = null;
|
||||
$description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)');
|
||||
|
||||
if (!$description) {
|
||||
$description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)');
|
||||
}
|
||||
|
||||
if (!$description) {
|
||||
$description = null;
|
||||
}
|
||||
|
||||
$this->_data['description'] = $description;
|
||||
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
if (array_key_exists('id', $this->_data)) {
|
||||
return $this->_data['id'];
|
||||
}
|
||||
|
||||
$id = null;
|
||||
$id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)');
|
||||
|
||||
if (!$id) {
|
||||
$id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:identifier)');
|
||||
}
|
||||
|
||||
$this->_data['id'] = $id;
|
||||
|
||||
return $this->_data['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
if (array_key_exists('title', $this->_data)) {
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
$title = null;
|
||||
$title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)');
|
||||
|
||||
if (!$title) {
|
||||
$title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)');
|
||||
}
|
||||
|
||||
if (!$title) {
|
||||
$title = null;
|
||||
}
|
||||
|
||||
$this->_data['title'] = $title;
|
||||
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return Zend_Date|null
|
||||
*/
|
||||
public function getDate()
|
||||
{
|
||||
if (array_key_exists('date', $this->_data)) {
|
||||
return $this->_data['date'];
|
||||
}
|
||||
|
||||
$d = null;
|
||||
$date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)');
|
||||
|
||||
if (!$date) {
|
||||
$date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)');
|
||||
}
|
||||
|
||||
if ($date) {
|
||||
$d = new Zend_Date;
|
||||
$d->set($date, Zend_Date::ISO_8601);
|
||||
}
|
||||
|
||||
$this->_data['date'] = $d;
|
||||
|
||||
return $this->_data['date'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register DC namespaces
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
$this->_xpath->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/');
|
||||
$this->_xpath->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/');
|
||||
}
|
||||
}
|
309
library/Zend/Feed/Reader/Extension/DublinCore/Feed.php
Normal file
309
library/Zend/Feed/Reader/Extension/DublinCore/Feed.php
Normal file
|
@ -0,0 +1,309 @@
|
|||
<?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: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_FeedAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Date
|
||||
*/
|
||||
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-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
|
||||
extends Zend_Feed_Reader_Extension_FeedAbstract
|
||||
{
|
||||
/**
|
||||
* 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->_xpath->query('//dc11:creator');
|
||||
|
||||
if (!$list->length) {
|
||||
$list = $this->_xpath->query('//dc10:creator');
|
||||
}
|
||||
if (!$list->length) {
|
||||
$list = $this->_xpath->query('//dc11:publisher');
|
||||
|
||||
if (!$list->length) {
|
||||
$list = $this->_xpath->query('//dc10:publisher');
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:rights)');
|
||||
|
||||
if (!$copyright) {
|
||||
$copyright = $this->_xpath->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->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)');
|
||||
|
||||
if (!$description) {
|
||||
$description = $this->_xpath->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->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)');
|
||||
|
||||
if (!$id) {
|
||||
$id = $this->_xpath->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->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:language)');
|
||||
|
||||
if (!$language) {
|
||||
$language = $this->_xpath->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->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)');
|
||||
|
||||
if (!$title) {
|
||||
$title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)');
|
||||
}
|
||||
|
||||
if (!$title) {
|
||||
$title = null;
|
||||
}
|
||||
|
||||
$this->_data['title'] = $title;
|
||||
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return Zend_Date|null
|
||||
*/
|
||||
public function getDate()
|
||||
{
|
||||
if (array_key_exists('date', $this->_data)) {
|
||||
return $this->_data['date'];
|
||||
}
|
||||
|
||||
$d = null;
|
||||
$date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)');
|
||||
|
||||
if (!$date) {
|
||||
$date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)');
|
||||
}
|
||||
|
||||
if ($date) {
|
||||
$d = new Zend_Date;
|
||||
$d->set($date, Zend_Date::ISO_8601);
|
||||
}
|
||||
|
||||
$this->_data['date'] = $d;
|
||||
|
||||
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
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
$this->_xpath->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/');
|
||||
$this->_xpath->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/');
|
||||
}
|
||||
}
|
200
library/Zend/Feed/Reader/Extension/EntryAbstract.php
Normal file
200
library/Zend/Feed/Reader/Extension/EntryAbstract.php
Normal file
|
@ -0,0 +1,200 @@
|
|||
<?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: EntryAbstract.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_Extension_EntryAbstract
|
||||
{
|
||||
/**
|
||||
* Feed entry data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_data = array();
|
||||
|
||||
/**
|
||||
* DOM document object
|
||||
*
|
||||
* @var DOMDocument
|
||||
*/
|
||||
protected $_domDocument = null;
|
||||
|
||||
/**
|
||||
* Entry instance
|
||||
*
|
||||
* @var Zend_Feed_Entry_Abstract
|
||||
*/
|
||||
protected $_entry = null;
|
||||
|
||||
/**
|
||||
* Pointer to the current entry
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_entryKey = 0;
|
||||
|
||||
/**
|
||||
* XPath object
|
||||
*
|
||||
* @var DOMXPath
|
||||
*/
|
||||
protected $_xpath = null;
|
||||
|
||||
/**
|
||||
* XPath query
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_xpathPrefix = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Zend_Feed_Entry_Abstract $entry
|
||||
* @param int $entryKey
|
||||
* @param string $type
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(DOMElement $entry, $entryKey, $type = null)
|
||||
{
|
||||
$this->_entry = $entry;
|
||||
$this->_entryKey = $entryKey;
|
||||
$this->_domDocument = $entry->ownerDocument;
|
||||
|
||||
if (!is_null($type)) {
|
||||
$this->_data['type'] = $type;
|
||||
} else {
|
||||
$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
|
||||
|| $this->getType() == Zend_Feed_Reader::TYPE_RSS_090
|
||||
) {
|
||||
$this->setXpathPrefix('//rss:item[' . ($this->_entryKey+1) . ']');
|
||||
} elseif ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10
|
||||
|| $this->getType() == Zend_Feed_Reader::TYPE_ATOM_03
|
||||
) {
|
||||
$this->setXpathPrefix('//atom:entry[' . ($this->_entryKey+1) . ']');
|
||||
} else {
|
||||
$this->setXpathPrefix('//item[' . ($this->_entryKey+1) . ']');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DOM
|
||||
*
|
||||
* @return DOMDocument
|
||||
*/
|
||||
public function getDomDocument()
|
||||
{
|
||||
return $this->_domDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Entry's encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
$assumed = $this->getDomDocument()->encoding;
|
||||
return $assumed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_data['type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 XPath query object
|
||||
*
|
||||
* @return DOMXPath
|
||||
*/
|
||||
public function getXpath()
|
||||
{
|
||||
if (!$this->_xpath) {
|
||||
$this->setXpath(new DOMXPath($this->getDomDocument()));
|
||||
}
|
||||
return $this->_xpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the entry to an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the XPath prefix
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getXpathPrefix()
|
||||
{
|
||||
return $this->_xpathPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the XPath prefix
|
||||
*
|
||||
* @param string $prefix
|
||||
* @return Zend_Feed_Reader_Extension_EntryAbstract
|
||||
*/
|
||||
public function setXpathPrefix($prefix)
|
||||
{
|
||||
$this->_xpathPrefix = $prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register XML namespaces
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected abstract function _registerNamespaces();
|
||||
}
|
189
library/Zend/Feed/Reader/Extension/FeedAbstract.php
Normal file
189
library/Zend/Feed/Reader/Extension/FeedAbstract.php
Normal file
|
@ -0,0 +1,189 @@
|
|||
<?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: FeedAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader
|
||||
*/
|
||||
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';
|
||||
|
||||
/**
|
||||
* @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_Extension_FeedAbstract
|
||||
{
|
||||
/**
|
||||
* Parsed feed data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_data = array();
|
||||
|
||||
/**
|
||||
* Parsed feed data in the shape of a DOMDocument
|
||||
*
|
||||
* @var DOMDocument
|
||||
*/
|
||||
protected $_domDocument = null;
|
||||
|
||||
/**
|
||||
* The base XPath query used to retrieve feed data
|
||||
*
|
||||
* @var DOMXPath
|
||||
*/
|
||||
protected $_xpath = null;
|
||||
|
||||
/**
|
||||
* The XPath prefix
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_xpathPrefix = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Zend_Feed_Abstract $feed The source Zend_Feed object
|
||||
* @param string $type Feed type
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(DomDocument $dom, $type = null, DOMXPath $xpath = null)
|
||||
{
|
||||
$this->_domDocument = $dom;
|
||||
|
||||
if ($type !== null) {
|
||||
$this->_data['type'] = $type;
|
||||
} else {
|
||||
$this->_data['type'] = Zend_Feed_Reader::detectType($dom);
|
||||
}
|
||||
|
||||
if ($xpath !== null) {
|
||||
$this->_xpath = $xpath;
|
||||
} else {
|
||||
$this->_xpath = new DOMXPath($this->_domDocument);
|
||||
}
|
||||
|
||||
$this->_registerNamespaces();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DOM
|
||||
*
|
||||
* @return DOMDocument
|
||||
*/
|
||||
public function getDomDocument()
|
||||
{
|
||||
return $this->_domDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Feed's encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
$assumed = $this->getDomDocument()->encoding;
|
||||
return $assumed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_data['type'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the feed as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray() // untested
|
||||
{
|
||||
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
|
||||
*/
|
||||
public function getXpathPrefix()
|
||||
{
|
||||
return $this->_xpathPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the XPath prefix
|
||||
*
|
||||
* @return Zend_Feed_Reader_Feed_Atom
|
||||
*/
|
||||
public function setXpathPrefix($prefix)
|
||||
{
|
||||
$this->_xpathPrefix = $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the default namespaces for the current feed format
|
||||
*/
|
||||
abstract protected function _registerNamespaces();
|
||||
}
|
202
library/Zend/Feed/Reader/Extension/Podcast/Entry.php
Normal file
202
library/Zend/Feed/Reader/Extension/Podcast/Entry.php
Normal file
|
@ -0,0 +1,202 @@
|
|||
<?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: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_EntryAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/EntryAbstract.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_Extension_Podcast_Entry extends Zend_Feed_Reader_Extension_EntryAbstract
|
||||
{
|
||||
/**
|
||||
* Get the entry author
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCastAuthor()
|
||||
{
|
||||
if (isset($this->_data['author'])) {
|
||||
return $this->_data['author'];
|
||||
}
|
||||
|
||||
$author = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:author)');
|
||||
|
||||
if (!$author) {
|
||||
$author = null;
|
||||
}
|
||||
|
||||
$this->_data['author'] = $author;
|
||||
|
||||
return $this->_data['author'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry block
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBlock()
|
||||
{
|
||||
if (isset($this->_data['block'])) {
|
||||
return $this->_data['block'];
|
||||
}
|
||||
|
||||
$block = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:block)');
|
||||
|
||||
if (!$block) {
|
||||
$block = null;
|
||||
}
|
||||
|
||||
$this->_data['block'] = $block;
|
||||
|
||||
return $this->_data['block'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry duration
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDuration()
|
||||
{
|
||||
if (isset($this->_data['duration'])) {
|
||||
return $this->_data['duration'];
|
||||
}
|
||||
|
||||
$duration = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:duration)');
|
||||
|
||||
if (!$duration) {
|
||||
$duration = null;
|
||||
}
|
||||
|
||||
$this->_data['duration'] = $duration;
|
||||
|
||||
return $this->_data['duration'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry explicit
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExplicit()
|
||||
{
|
||||
if (isset($this->_data['explicit'])) {
|
||||
return $this->_data['explicit'];
|
||||
}
|
||||
|
||||
$explicit = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:explicit)');
|
||||
|
||||
if (!$explicit) {
|
||||
$explicit = null;
|
||||
}
|
||||
|
||||
$this->_data['explicit'] = $explicit;
|
||||
|
||||
return $this->_data['explicit'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry keywords
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKeywords()
|
||||
{
|
||||
if (isset($this->_data['keywords'])) {
|
||||
return $this->_data['keywords'];
|
||||
}
|
||||
|
||||
$keywords = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:keywords)');
|
||||
|
||||
if (!$keywords) {
|
||||
$keywords = null;
|
||||
}
|
||||
|
||||
$this->_data['keywords'] = $keywords;
|
||||
|
||||
return $this->_data['keywords'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry subtitle
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubtitle()
|
||||
{
|
||||
if (isset($this->_data['subtitle'])) {
|
||||
return $this->_data['subtitle'];
|
||||
}
|
||||
|
||||
$subtitle = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:subtitle)');
|
||||
|
||||
if (!$subtitle) {
|
||||
$subtitle = null;
|
||||
}
|
||||
|
||||
$this->_data['subtitle'] = $subtitle;
|
||||
|
||||
return $this->_data['subtitle'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry summary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
if (isset($this->_data['summary'])) {
|
||||
return $this->_data['summary'];
|
||||
}
|
||||
|
||||
$summary = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:summary)');
|
||||
|
||||
if (!$summary) {
|
||||
$summary = null;
|
||||
}
|
||||
|
||||
$this->_data['summary'] = $summary;
|
||||
|
||||
return $this->_data['summary'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register iTunes namespace
|
||||
*
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
$this->_xpath->registerNamespace('itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
|
||||
}
|
||||
}
|
293
library/Zend/Feed/Reader/Extension/Podcast/Feed.php
Normal file
293
library/Zend/Feed/Reader/Extension/Podcast/Feed.php
Normal file
|
@ -0,0 +1,293 @@
|
|||
<?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: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_FeedAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/FeedAbstract.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_Extension_Podcast_Feed extends Zend_Feed_Reader_Extension_FeedAbstract
|
||||
{
|
||||
/**
|
||||
* Get the entry author
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCastAuthor()
|
||||
{
|
||||
if (isset($this->_data['author'])) {
|
||||
return $this->_data['author'];
|
||||
}
|
||||
|
||||
$author = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:author)');
|
||||
|
||||
if (!$author) {
|
||||
$author = null;
|
||||
}
|
||||
|
||||
$this->_data['author'] = $author;
|
||||
|
||||
return $this->_data['author'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry block
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBlock()
|
||||
{
|
||||
if (isset($this->_data['block'])) {
|
||||
return $this->_data['block'];
|
||||
}
|
||||
|
||||
$block = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:block)');
|
||||
|
||||
if (!$block) {
|
||||
$block = null;
|
||||
}
|
||||
|
||||
$this->_data['block'] = $block;
|
||||
|
||||
return $this->_data['block'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry category
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCategories()
|
||||
{
|
||||
if (isset($this->_data['categories'])) {
|
||||
return $this->_data['categories'];
|
||||
}
|
||||
|
||||
$categoryList = $this->_xpath->query($this->getXpathPrefix() . '/itunes:category');
|
||||
|
||||
$categories = array();
|
||||
|
||||
if ($categoryList->length > 0) {
|
||||
foreach ($categoryList as $node) {
|
||||
$children = null;
|
||||
|
||||
if ($node->childNodes->length > 0) {
|
||||
$children = array();
|
||||
|
||||
foreach ($node->childNodes as $childNode) {
|
||||
if (!($childNode instanceof DOMText)) {
|
||||
$children[$childNode->getAttribute('text')] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$categories[$node->getAttribute('text')] = $children;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$categories) {
|
||||
$categories = null;
|
||||
}
|
||||
|
||||
$this->_data['categories'] = $categories;
|
||||
|
||||
return $this->_data['categories'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry explicit
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExplicit()
|
||||
{
|
||||
if (isset($this->_data['explicit'])) {
|
||||
return $this->_data['explicit'];
|
||||
}
|
||||
|
||||
$explicit = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:explicit)');
|
||||
|
||||
if (!$explicit) {
|
||||
$explicit = null;
|
||||
}
|
||||
|
||||
$this->_data['explicit'] = $explicit;
|
||||
|
||||
return $this->_data['explicit'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry image
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getImage()
|
||||
{
|
||||
if (isset($this->_data['image'])) {
|
||||
return $this->_data['image'];
|
||||
}
|
||||
|
||||
$image = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:image/@href)');
|
||||
|
||||
if (!$image) {
|
||||
$image = null;
|
||||
}
|
||||
|
||||
$this->_data['image'] = $image;
|
||||
|
||||
return $this->_data['image'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry keywords
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKeywords()
|
||||
{
|
||||
if (isset($this->_data['keywords'])) {
|
||||
return $this->_data['keywords'];
|
||||
}
|
||||
|
||||
$keywords = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:keywords)');
|
||||
|
||||
if (!$keywords) {
|
||||
$keywords = null;
|
||||
}
|
||||
|
||||
$this->_data['keywords'] = $keywords;
|
||||
|
||||
return $this->_data['keywords'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry's new feed url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNewFeedUrl()
|
||||
{
|
||||
if (isset($this->_data['new-feed-url'])) {
|
||||
return $this->_data['new-feed-url'];
|
||||
}
|
||||
|
||||
$newFeedUrl = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:new-feed-url)');
|
||||
|
||||
if (!$newFeedUrl) {
|
||||
$newFeedUrl = null;
|
||||
}
|
||||
|
||||
$this->_data['new-feed-url'] = $newFeedUrl;
|
||||
|
||||
return $this->_data['new-feed-url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry owner
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOwner()
|
||||
{
|
||||
if (isset($this->_data['owner'])) {
|
||||
return $this->_data['owner'];
|
||||
}
|
||||
|
||||
$owner = null;
|
||||
|
||||
$email = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:owner/itunes:email)');
|
||||
$name = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:owner/itunes:name)');
|
||||
|
||||
if (!empty($email)) {
|
||||
$owner = $email . (empty($name) ? '' : ' (' . $name . ')');
|
||||
} else if (!empty($name)) {
|
||||
$owner = $name;
|
||||
}
|
||||
|
||||
if (!$owner) {
|
||||
$owner = null;
|
||||
}
|
||||
|
||||
$this->_data['owner'] = $owner;
|
||||
|
||||
return $this->_data['owner'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry subtitle
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubtitle()
|
||||
{
|
||||
if (isset($this->_data['subtitle'])) {
|
||||
return $this->_data['subtitle'];
|
||||
}
|
||||
|
||||
$subtitle = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:subtitle)');
|
||||
|
||||
if (!$subtitle) {
|
||||
$subtitle = null;
|
||||
}
|
||||
|
||||
$this->_data['subtitle'] = $subtitle;
|
||||
|
||||
return $this->_data['subtitle'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry summary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
if (isset($this->_data['summary'])) {
|
||||
return $this->_data['summary'];
|
||||
}
|
||||
|
||||
$summary = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:summary)');
|
||||
|
||||
if (!$summary) {
|
||||
$summary = null;
|
||||
}
|
||||
|
||||
$this->_data['summary'] = $summary;
|
||||
|
||||
return $this->_data['summary'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register iTunes namespace
|
||||
*
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
$this->_xpath->registerNamespace('itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
|
||||
}
|
||||
}
|
144
library/Zend/Feed/Reader/Extension/Slash/Entry.php
Normal file
144
library/Zend/Feed/Reader/Extension/Slash/Entry.php
Normal file
|
@ -0,0 +1,144 @@
|
|||
<?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: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_EntryAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/EntryAbstract.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_Extension_Slash_Entry
|
||||
extends Zend_Feed_Reader_Extension_EntryAbstract
|
||||
{
|
||||
/**
|
||||
* Get the entry section
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSection()
|
||||
{
|
||||
return $this->_getData('section');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry department
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDepartment()
|
||||
{
|
||||
return $this->_getData('department');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry hit_parade
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHitParade()
|
||||
{
|
||||
$name = 'hit_parade';
|
||||
|
||||
if (isset($this->_data[$name])) {
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
$stringParade = $this->_getData($name);
|
||||
$hitParade = array();
|
||||
|
||||
if (!empty($stringParade)) {
|
||||
$stringParade = explode(',', $stringParade);
|
||||
|
||||
foreach ($stringParade as $hit)
|
||||
$hitParade[] = $hit + 0; //cast to integer
|
||||
}
|
||||
|
||||
$this->_data[$name] = $hitParade;
|
||||
return $hitParade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry comments
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCommentCount()
|
||||
{
|
||||
$name = 'comments';
|
||||
|
||||
if (isset($this->_data[$name])) {
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
$comments = $this->_getData($name, 'string');
|
||||
|
||||
if (!$comments) {
|
||||
$this->_data[$name] = null;
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
return $comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry data specified by name
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected function _getData($name, $type = 'string')
|
||||
{
|
||||
if (array_key_exists($name, $this->_data)) {
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
$data = $this->_xpath->evaluate($type . '(' . $this->getXpathPrefix() . '/slash10:' . $name . ')');
|
||||
|
||||
if (!$data) {
|
||||
$data = null;
|
||||
}
|
||||
|
||||
$this->_data[$name] = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Slash namespaces
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
$this->_xpath->registerNamespace('slash10', 'http://purl.org/rss/1.0/modules/slash/');
|
||||
}
|
||||
}
|
168
library/Zend/Feed/Reader/Extension/Syndication/Feed.php
Normal file
168
library/Zend/Feed/Reader/Extension/Syndication/Feed.php
Normal file
|
@ -0,0 +1,168 @@
|
|||
<?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: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_FeedAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php';
|
||||
|
||||
require_once 'Zend/Date.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_Extension_Syndication_Feed
|
||||
extends Zend_Feed_Reader_Extension_FeedAbstract
|
||||
{
|
||||
/**
|
||||
* Get update period
|
||||
* @return string
|
||||
*/
|
||||
public function getUpdatePeriod()
|
||||
{
|
||||
$name = 'updatePeriod';
|
||||
$period = $this->_getData($name);
|
||||
|
||||
if ($period === null) {
|
||||
$this->_data[$name] = 'daily';
|
||||
return 'daily'; //Default specified by spec
|
||||
}
|
||||
|
||||
switch ($period)
|
||||
{
|
||||
case 'hourly':
|
||||
case 'daily':
|
||||
case 'weekly':
|
||||
case 'yearly':
|
||||
return $period;
|
||||
default:
|
||||
throw new Zend_Feed_Exception("Feed specified invalid update period: '$period'."
|
||||
. " Must be one of hourly, daily, weekly or yearly"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get update frequency
|
||||
* @return int
|
||||
*/
|
||||
public function getUpdateFrequency()
|
||||
{
|
||||
$name = 'updateFrequency';
|
||||
$freq = $this->_getData($name, 'number');
|
||||
|
||||
if (!$freq || $freq < 1) {
|
||||
$this->_data[$name] = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return $freq;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get update frequency as ticks
|
||||
* @return int
|
||||
*/
|
||||
public function getUpdateFrequencyAsTicks()
|
||||
{
|
||||
$name = 'updateFrequency';
|
||||
$freq = $this->_getData($name, 'number');
|
||||
|
||||
if (!$freq || $freq < 1) {
|
||||
$this->_data[$name] = 1;
|
||||
$freq = 1;
|
||||
}
|
||||
|
||||
$period = $this->getUpdatePeriod();
|
||||
$ticks = 1;
|
||||
|
||||
switch ($period)
|
||||
{
|
||||
//intentional fall through
|
||||
case 'yearly':
|
||||
$ticks *= 52; //TODO: fix generalisation, how?
|
||||
case 'weekly':
|
||||
$ticks *= 7;
|
||||
case 'daily':
|
||||
$ticks *= 24;
|
||||
case 'hourly':
|
||||
$ticks *= 3600;
|
||||
break;
|
||||
default: //Never arrive here, exception thrown in getPeriod()
|
||||
break;
|
||||
}
|
||||
|
||||
return $ticks / $freq;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get update base
|
||||
*
|
||||
* @return Zend_Date|null
|
||||
*/
|
||||
public function getUpdateBase()
|
||||
{
|
||||
$updateBase = $this->_getData('updateBase');
|
||||
$date = null;
|
||||
if ($updateBase) {
|
||||
$date = new Zend_Date;
|
||||
$date->set($updateBase, Zend_Date::W3C);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry data specified by name
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @return mixed|null
|
||||
*/
|
||||
private function _getData($name, $type = 'string')
|
||||
{
|
||||
if (array_key_exists($name, $this->_data)) {
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
$data = $this->_xpath->evaluate($type . '(' . $this->getXpathPrefix() . '/syn10:' . $name . ')');
|
||||
|
||||
if (!$data) {
|
||||
$data = null;
|
||||
}
|
||||
|
||||
$this->_data[$name] = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Syndication namespaces
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
$this->_xpath->registerNamespace('syn10', 'http://purl.org/rss/1.0/modules/syndication/');
|
||||
}
|
||||
}
|
91
library/Zend/Feed/Reader/Extension/Thread/Entry.php
Normal file
91
library/Zend/Feed/Reader/Extension/Thread/Entry.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?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: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_EntryAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/EntryAbstract.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_Extension_Thread_Entry
|
||||
extends Zend_Feed_Reader_Extension_EntryAbstract
|
||||
{
|
||||
/**
|
||||
* Get the "in-reply-to" value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInReplyTo()
|
||||
{
|
||||
// TODO: to be implemented
|
||||
}
|
||||
|
||||
// TODO: Implement "replies" and "updated" constructs from standard
|
||||
|
||||
/**
|
||||
* Get the total number of threaded responses (i.e comments)
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getCommentCount()
|
||||
{
|
||||
return $this->_getData('total');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry data specified by name
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected function _getData($name)
|
||||
{
|
||||
if (array_key_exists($name, $this->_data)) {
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
$data = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/thread10:' . $name . ')');
|
||||
|
||||
if (!$data) {
|
||||
$data = null;
|
||||
}
|
||||
|
||||
$this->_data[$name] = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Atom Thread Extension 1.0 namespace
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
$this->_xpath->registerNamespace('thread10', 'http://purl.org/syndication/thread/1.0');
|
||||
}
|
||||
}
|
73
library/Zend/Feed/Reader/Extension/WellFormedWeb/Entry.php
Normal file
73
library/Zend/Feed/Reader/Extension/WellFormedWeb/Entry.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?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: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_EntryAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/EntryAbstract.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_Extension_WellFormedWeb_Entry
|
||||
extends Zend_Feed_Reader_Extension_EntryAbstract
|
||||
{
|
||||
/**
|
||||
* Get the entry comment Uri
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCommentFeedLink()
|
||||
{
|
||||
$name = 'commentRss';
|
||||
if (array_key_exists($name, $this->_data)) {
|
||||
return $this->_data[$name];
|
||||
}
|
||||
|
||||
$data = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/wfw:' . $name . ')');
|
||||
|
||||
if (!$data) {
|
||||
$data = null;
|
||||
}
|
||||
|
||||
$this->_data[$name] = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Slash namespaces
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
$this->_xpath->registerNamespace('wfw', 'http://wellformedweb.org/CommentAPI/');
|
||||
}
|
||||
}
|
389
library/Zend/Feed/Reader/Feed/Atom.php
Normal file
389
library/Zend/Feed/Reader/Feed/Atom.php
Normal file
|
@ -0,0 +1,389 @@
|
|||
<?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 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_FeedAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/FeedAbstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_Atom_Feed
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/Atom/Feed.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 extends Zend_Feed_Reader_FeedAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DOMDocument $dom
|
||||
* @param string $type
|
||||
*/
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = $this->getExtension('Atom')->getAuthors();
|
||||
|
||||
$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 = $this->getExtension('Atom')->getCopyright();
|
||||
|
||||
if (!$copyright) {
|
||||
$copyright = null;
|
||||
}
|
||||
|
||||
$this->_data['copyright'] = $copyright;
|
||||
|
||||
return $this->_data['copyright'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed creation date
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDateCreated()
|
||||
{
|
||||
if (array_key_exists('datecreated', $this->_data)) {
|
||||
return $this->_data['datecreated'];
|
||||
}
|
||||
|
||||
$dateCreated = $this->getExtension('Atom')->getDateCreated();
|
||||
|
||||
if (!$dateCreated) {
|
||||
$dateCreated = null;
|
||||
}
|
||||
|
||||
$this->_data['datecreated'] = $dateCreated;
|
||||
|
||||
return $this->_data['datecreated'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed modification date
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDateModified()
|
||||
{
|
||||
if (array_key_exists('datemodified', $this->_data)) {
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
$dateModified = $this->getExtension('Atom')->getDateModified();
|
||||
|
||||
if (!$dateModified) {
|
||||
$dateModified = null;
|
||||
}
|
||||
|
||||
$this->_data['datemodified'] = $dateModified;
|
||||
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed description
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
if (array_key_exists('description', $this->_data)) {
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
$description = $this->getExtension('Atom')->getDescription();
|
||||
|
||||
if (!$description) {
|
||||
$description = null;
|
||||
}
|
||||
|
||||
$this->_data['description'] = $description;
|
||||
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed generator entry
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getGenerator()
|
||||
{
|
||||
if (array_key_exists('generator', $this->_data)) {
|
||||
return $this->_data['generator'];
|
||||
}
|
||||
|
||||
$generator = $this->getExtension('Atom')->getGenerator();
|
||||
|
||||
$this->_data['generator'] = $generator;
|
||||
|
||||
return $this->_data['generator'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed ID
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
if (array_key_exists('id', $this->_data)) {
|
||||
return $this->_data['id'];
|
||||
}
|
||||
|
||||
$id = $this->getExtension('Atom')->getId();
|
||||
|
||||
$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 = $this->getExtension('Atom')->getLanguage();
|
||||
|
||||
if (!$language) {
|
||||
$language = $this->_xpath->evaluate('string(//@xml:lang[1])');
|
||||
}
|
||||
|
||||
if (!$language) {
|
||||
$language = null;
|
||||
}
|
||||
|
||||
$this->_data['language'] = $language;
|
||||
|
||||
return $this->_data['language'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a link to the source website
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
{
|
||||
if (array_key_exists('baseUrl', $this->_data)) {
|
||||
return $this->_data['baseUrl'];
|
||||
}
|
||||
|
||||
$baseUrl = $this->getExtension('Atom')->getBaseUrl();
|
||||
|
||||
$this->_data['baseUrl'] = $baseUrl;
|
||||
|
||||
return $this->_data['baseUrl'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a link to the source website
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLink()
|
||||
{
|
||||
if (array_key_exists('link', $this->_data)) {
|
||||
return $this->_data['link'];
|
||||
}
|
||||
|
||||
$link = $this->getExtension('Atom')->getLink();
|
||||
|
||||
$this->_data['link'] = $link;
|
||||
|
||||
return $this->_data['link'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a link to the feed's XML Url
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFeedLink()
|
||||
{
|
||||
if (array_key_exists('feedlink', $this->_data)) {
|
||||
return $this->_data['feedlink'];
|
||||
}
|
||||
|
||||
$link = $this->getExtension('Atom')->getFeedLink();
|
||||
|
||||
$this->_data['feedlink'] = $link;
|
||||
|
||||
return $this->_data['feedlink'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed title
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
if (array_key_exists('title', $this->_data)) {
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
$title = $this->getExtension('Atom')->getTitle();
|
||||
|
||||
$this->_data['title'] = $title;
|
||||
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
if ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10 ||
|
||||
$this->getType() == Zend_Feed_Reader::TYPE_ATOM_03) {
|
||||
$entries = array();
|
||||
$entries = $this->_xpath->evaluate('//atom:entry');
|
||||
|
||||
foreach($entries as $index=>$entry) {
|
||||
$this->_entries[$index] = $entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the default namespaces for the current feed format
|
||||
*
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
switch ($this->_data['type']) {
|
||||
case Zend_Feed_Reader::TYPE_ATOM_03:
|
||||
$this->_xpath->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_03);
|
||||
break;
|
||||
case Zend_Feed_Reader::TYPE_ATOM_10:
|
||||
default:
|
||||
$this->_xpath->registerNamespace('atom', Zend_Feed_Reader::NAMESPACE_ATOM_10);
|
||||
}
|
||||
}
|
||||
}
|
102
library/Zend/Feed/Reader/Feed/Atom/Source.php
Normal file
102
library/Zend/Feed/Reader/Feed/Atom/Source.php
Normal file
|
@ -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() {}
|
||||
|
||||
}
|
623
library/Zend/Feed/Reader/Feed/Rss.php
Normal file
623
library/Zend/Feed/Reader/Feed/Rss.php
Normal file
|
@ -0,0 +1,623 @@
|
|||
<?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: Rss.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_FeedAbstract
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/FeedAbstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_feed_Reader_Extension_Atom_Feed
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/Atom/Feed.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader_Extension_DublinCore_Feed
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/Extension/DublinCore/Feed.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Date
|
||||
*/
|
||||
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-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
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DOMDocument $dom
|
||||
* @param string $type
|
||||
*/
|
||||
public function __construct(DomDocument $dom, $type = null)
|
||||
{
|
||||
parent::__construct($dom, $type);
|
||||
|
||||
$dublinCoreClass = Zend_Feed_Reader::getPluginLoader()->getClassName('DublinCore_Feed');
|
||||
$this->_extensions['DublinCore_Feed'] = new $dublinCoreClass($dom, $this->_data['type'], $this->_xpath);
|
||||
$atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Feed');
|
||||
$this->_extensions['Atom_Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath);
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$xpathPrefix = '/rss/channel';
|
||||
} else {
|
||||
$xpathPrefix = '/rdf:RDF/rss:channel';
|
||||
}
|
||||
foreach ($this->_extensions as $extension) {
|
||||
$extension->setXpathPrefix($xpathPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
$authors_dc = $this->getExtension('DublinCore')->getAuthors();
|
||||
if (!empty($authors_dc)) {
|
||||
foreach ($authors_dc as $author) {
|
||||
$authors[] = array(
|
||||
'name' => $author['name']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (count($authors) == 0) {
|
||||
$authors = $this->getExtension('Atom')->getAuthors();
|
||||
} else {
|
||||
$authors = new Zend_Feed_Reader_Collection_Author(
|
||||
Zend_Feed_Reader::arrayUnique($authors)
|
||||
);
|
||||
}
|
||||
|
||||
if (count($authors) == 0) {
|
||||
$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;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 &&
|
||||
$this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$copyright = $this->_xpath->evaluate('string(/rss/channel/copyright)');
|
||||
}
|
||||
|
||||
if (!$copyright && !is_null($this->getExtension('DublinCore'))) {
|
||||
$copyright = $this->getExtension('DublinCore')->getCopyright();
|
||||
}
|
||||
|
||||
if (empty($copyright)) {
|
||||
$copyright = $this->getExtension('Atom')->getCopyright();
|
||||
}
|
||||
|
||||
if (!$copyright) {
|
||||
$copyright = null;
|
||||
}
|
||||
|
||||
$this->_data['copyright'] = $copyright;
|
||||
|
||||
return $this->_data['copyright'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed creation date
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDateCreated()
|
||||
{
|
||||
return $this->getDateModified();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed modification date
|
||||
*
|
||||
* @return Zend_Date
|
||||
*/
|
||||
public function getDateModified()
|
||||
{
|
||||
if (array_key_exists('datemodified', $this->_data)) {
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
$dateModified = null;
|
||||
$date = null;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 &&
|
||||
$this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$dateModified = $this->_xpath->evaluate('string(/rss/channel/pubDate)');
|
||||
if (!$dateModified) {
|
||||
$dateModified = $this->_xpath->evaluate('string(/rss/channel/lastBuildDate)');
|
||||
}
|
||||
if ($dateModified) {
|
||||
$dateStandards = array(Zend_Date::RSS, Zend_Date::RFC_822,
|
||||
Zend_Date::RFC_2822, Zend_Date::DATES);
|
||||
$date = new Zend_Date;
|
||||
foreach ($dateStandards as $standard) {
|
||||
try {
|
||||
$date->set($dateModified, $standard);
|
||||
break;
|
||||
} catch (Zend_Date_Exception $e) {
|
||||
if ($standard == Zend_Date::DATES) {
|
||||
require_once 'Zend/Feed/Exception.php';
|
||||
throw new Zend_Feed_Exception(
|
||||
'Could not load date due to unrecognised'
|
||||
.' format (should follow RFC 822 or 2822):'
|
||||
. $e->getMessage(),
|
||||
0, $e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$date) {
|
||||
$date = $this->getExtension('DublinCore')->getDate();
|
||||
}
|
||||
|
||||
if (!$date) {
|
||||
$date = $this->getExtension('Atom')->getDateModified();
|
||||
}
|
||||
|
||||
if (!$date) {
|
||||
$date = null;
|
||||
}
|
||||
|
||||
$this->_data['datemodified'] = $date;
|
||||
|
||||
return $this->_data['datemodified'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed description
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
if (array_key_exists('description', $this->_data)) {
|
||||
return $this->_data['description'];
|
||||
}
|
||||
|
||||
$description = null;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 &&
|
||||
$this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$description = $this->_xpath->evaluate('string(/rss/channel/description)');
|
||||
} else {
|
||||
$description = $this->_xpath->evaluate('string(/rdf:RDF/rss:channel/rss:description)');
|
||||
}
|
||||
|
||||
if (!$description && !is_null($this->getExtension('DublinCore'))) {
|
||||
$description = $this->getExtension('DublinCore')->getDescription();
|
||||
}
|
||||
|
||||
if (empty($description)) {
|
||||
$description = $this->getExtension('Atom')->getDescription();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 &&
|
||||
$this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$id = $this->_xpath->evaluate('string(/rss/channel/guid)');
|
||||
}
|
||||
|
||||
if (!$id && !is_null($this->getExtension('DublinCore'))) {
|
||||
$id = $this->getExtension('DublinCore')->getId();
|
||||
}
|
||||
|
||||
if (empty($id)) {
|
||||
$id = $this->getExtension('Atom')->getId();
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
if ($this->getLink()) {
|
||||
$id = $this->getLink();
|
||||
} elseif ($this->getTitle()) {
|
||||
$id = $this->getTitle();
|
||||
} else {
|
||||
$id = null;
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 &&
|
||||
$this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$language = $this->_xpath->evaluate('string(/rss/channel/language)');
|
||||
}
|
||||
|
||||
if (!$language && !is_null($this->getExtension('DublinCore'))) {
|
||||
$language = $this->getExtension('DublinCore')->getLanguage();
|
||||
}
|
||||
|
||||
if (empty($language)) {
|
||||
$language = $this->getExtension('Atom')->getLanguage();
|
||||
}
|
||||
|
||||
if (!$language) {
|
||||
$language = $this->_xpath->evaluate('string(//@xml:lang[1])');
|
||||
}
|
||||
|
||||
if (!$language) {
|
||||
$language = null;
|
||||
}
|
||||
|
||||
$this->_data['language'] = $language;
|
||||
|
||||
return $this->_data['language'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a link to the feed
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLink()
|
||||
{
|
||||
if (array_key_exists('link', $this->_data)) {
|
||||
return $this->_data['link'];
|
||||
}
|
||||
|
||||
$link = null;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 &&
|
||||
$this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$link = $this->_xpath->evaluate('string(/rss/channel/link)');
|
||||
} else {
|
||||
$link = $this->_xpath->evaluate('string(/rdf:RDF/rss:channel/rss:link)');
|
||||
}
|
||||
|
||||
if (empty($link)) {
|
||||
$link = $this->getExtension('Atom')->getLink();
|
||||
}
|
||||
|
||||
if (!$link) {
|
||||
$link = null;
|
||||
}
|
||||
|
||||
$this->_data['link'] = $link;
|
||||
|
||||
return $this->_data['link'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a link to the feed XML
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFeedLink()
|
||||
{
|
||||
if (array_key_exists('feedlink', $this->_data)) {
|
||||
return $this->_data['feedlink'];
|
||||
}
|
||||
|
||||
$link = null;
|
||||
|
||||
$link = $this->getExtension('Atom')->getFeedLink();
|
||||
|
||||
if (!$link) {
|
||||
$link = null;
|
||||
}
|
||||
|
||||
$this->_data['feedlink'] = $link;
|
||||
|
||||
return $this->_data['feedlink'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed generator entry
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getGenerator()
|
||||
{
|
||||
if (array_key_exists('generator', $this->_data)) {
|
||||
return $this->_data['generator'];
|
||||
}
|
||||
|
||||
$generator = null;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 &&
|
||||
$this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$generator = $this->_xpath->evaluate('string(/rss/channel/generator)');
|
||||
}
|
||||
|
||||
if (!$generator) {
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 &&
|
||||
$this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$generator = $this->_xpath->evaluate('string(/rss/channel/atom:generator)');
|
||||
} else {
|
||||
$generator = $this->_xpath->evaluate('string(/rdf:RDF/rss:channel/atom:generator)');
|
||||
}
|
||||
if ($generator) {
|
||||
$generator = html_entity_decode($generator, ENT_QUOTES, $this->getEncoding());
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($generator)) {
|
||||
$generator = $this->getExtension('Atom')->getGenerator();
|
||||
}
|
||||
|
||||
if (!$generator) {
|
||||
$generator = null;
|
||||
}
|
||||
|
||||
$this->_data['generator'] = $generator;
|
||||
|
||||
return $this->_data['generator'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed title
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
if (array_key_exists('title', $this->_data)) {
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
$title = null;
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 &&
|
||||
$this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$title = $this->_xpath->evaluate('string(/rss/channel/title)');
|
||||
} else {
|
||||
$title = $this->_xpath->evaluate('string(/rdf:RDF/rss:channel/rss:title)');
|
||||
}
|
||||
|
||||
if (!$title && !is_null($this->getExtension('DublinCore'))) {
|
||||
$title = $this->getExtension('DublinCore')->getTitle();
|
||||
}
|
||||
|
||||
if (!$title) {
|
||||
$title = $this->getExtension('Atom')->getTitle();
|
||||
}
|
||||
|
||||
if (!$title) {
|
||||
$title = null;
|
||||
}
|
||||
|
||||
$this->_data['title'] = $title;
|
||||
|
||||
return $this->_data['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
protected function _indexEntries()
|
||||
{
|
||||
$entries = array();
|
||||
|
||||
if ($this->getType() !== Zend_Feed_Reader::TYPE_RSS_10 && $this->getType() !== Zend_Feed_Reader::TYPE_RSS_090) {
|
||||
$entries = $this->_xpath->evaluate('//item');
|
||||
} else {
|
||||
$entries = $this->_xpath->evaluate('//rss:item');
|
||||
}
|
||||
|
||||
foreach($entries as $index=>$entry) {
|
||||
$this->_entries[$index] = $entry;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the default namespaces for the current feed format
|
||||
*
|
||||
*/
|
||||
protected function _registerNamespaces()
|
||||
{
|
||||
switch ($this->_data['type']) {
|
||||
case Zend_Feed_Reader::TYPE_RSS_10:
|
||||
$this->_xpath->registerNamespace('rdf', Zend_Feed_Reader::NAMESPACE_RDF);
|
||||
$this->_xpath->registerNamespace('rss', Zend_Feed_Reader::NAMESPACE_RSS_10);
|
||||
break;
|
||||
|
||||
case Zend_Feed_Reader::TYPE_RSS_090:
|
||||
$this->_xpath->registerNamespace('rdf', Zend_Feed_Reader::NAMESPACE_RDF);
|
||||
$this->_xpath->registerNamespace('rss', Zend_Feed_Reader::NAMESPACE_RSS_090);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
291
library/Zend/Feed/Reader/FeedAbstract.php
Normal file
291
library/Zend/Feed/Reader/FeedAbstract.php
Normal file
|
@ -0,0 +1,291 @@
|
|||
<?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: FeedAbstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_feed_Reader_FeedInterface
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader/FeedInterface.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
|
||||
*/
|
||||
abstract class Zend_Feed_Reader_FeedAbstract implements Zend_Feed_Reader_FeedInterface
|
||||
{
|
||||
/**
|
||||
* Parsed feed data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_data = array();
|
||||
|
||||
/**
|
||||
* Parsed feed data in the shape of a DOMDocument
|
||||
*
|
||||
* @var DOMDocument
|
||||
*/
|
||||
protected $_domDocument = null;
|
||||
|
||||
/**
|
||||
* An array of parsed feed entries
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_entries = array();
|
||||
|
||||
/**
|
||||
* A pointer for the iterator to keep track of the entries array
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_entriesKey = 0;
|
||||
|
||||
/**
|
||||
* The base XPath query used to retrieve feed data
|
||||
*
|
||||
* @var DOMXPath
|
||||
*/
|
||||
protected $_xpath = null;
|
||||
|
||||
/**
|
||||
* Array of loaded extensions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_extensions = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DomDocument The DOM object for the feed's XML
|
||||
* @param string $type Feed type
|
||||
*/
|
||||
public function __construct(DomDocument $domDocument, $type = null)
|
||||
{
|
||||
$this->_domDocument = $domDocument;
|
||||
$this->_xpath = new DOMXPath($this->_domDocument);
|
||||
|
||||
if ($type !== null) {
|
||||
$this->_data['type'] = $type;
|
||||
} else {
|
||||
$this->_data['type'] = Zend_Feed_Reader::detectType($this->_domDocument);
|
||||
}
|
||||
$this->_registerNamespaces();
|
||||
$this->_indexEntries();
|
||||
$this->_loadExtensions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of feed entries.
|
||||
* Required by the Iterator interface.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->_entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current entry
|
||||
*
|
||||
* @return Zend_Feed_Reader_EntryInterface
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
if (substr($this->getType(), 0, 3) == 'rss') {
|
||||
$reader = new Zend_Feed_Reader_Entry_Rss($this->_entries[$this->key()], $this->key(), $this->getType());
|
||||
} else {
|
||||
$reader = new Zend_Feed_Reader_Entry_Atom($this->_entries[$this->key()], $this->key(), $this->getType());
|
||||
}
|
||||
|
||||
$reader->setXpath($this->_xpath);
|
||||
|
||||
return $reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DOM
|
||||
*
|
||||
* @return DOMDocument
|
||||
*/
|
||||
public function getDomDocument()
|
||||
{
|
||||
return $this->_domDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Feed's encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
$assumed = $this->getDomDocument()->encoding;
|
||||
if (empty($assumed)) {
|
||||
$assumed = 'UTF-8';
|
||||
}
|
||||
return $assumed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get feed as xml
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function saveXml()
|
||||
{
|
||||
return $this->getDomDocument()->saveXml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DOMElement representing the items/feed element
|
||||
*
|
||||
* @return DOMElement
|
||||
*/
|
||||
public function getElement()
|
||||
{
|
||||
return $this->getDomDocument()->documentElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DOMXPath object for this feed
|
||||
*
|
||||
* @return DOMXPath
|
||||
*/
|
||||
public function getXpath()
|
||||
{
|
||||
return $this->_xpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the feed type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->_data['type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current feed key
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return $this->_entriesKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the feed pointer forward
|
||||
*
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
++$this->_entriesKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the pointer in the feed object
|
||||
*
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
$this->_entriesKey = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the iterator is still valid
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return 0 <= $this->_entriesKey && $this->_entriesKey < $this->count();
|
||||
}
|
||||
|
||||
public function getExtensions()
|
||||
{
|
||||
return $this->_extensions;
|
||||
}
|
||||
|
||||
public function __call($method, $args)
|
||||
{
|
||||
foreach ($this->_extensions as $extension) {
|
||||
if (method_exists($extension, $method)) {
|
||||
return call_user_func_array(array($extension, $method), $args);
|
||||
}
|
||||
}
|
||||
require_once 'Zend/Feed/Exception.php';
|
||||
throw new Zend_Feed_Exception('Method: ' . $method
|
||||
. 'does not exist and could not be located on a registered Extension');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an Extension object with the matching name (postfixed with _Feed)
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Feed_Reader_Extension_FeedAbstract
|
||||
*/
|
||||
public function getExtension($name)
|
||||
{
|
||||
if (array_key_exists($name . '_Feed', $this->_extensions)) {
|
||||
return $this->_extensions[$name . '_Feed'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function _loadExtensions()
|
||||
{
|
||||
$all = Zend_Feed_Reader::getExtensions();
|
||||
$feed = $all['feed'];
|
||||
foreach ($feed as $extension) {
|
||||
if (in_array($extension, $all['core'])) {
|
||||
continue;
|
||||
}
|
||||
$className = Zend_Feed_Reader::getPluginLoader()->getClassName($extension);
|
||||
$this->_extensions[$extension] = new $className(
|
||||
$this->getDomDocument(), $this->_data['type'], $this->_xpath
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all entries to the internal entries array
|
||||
*
|
||||
*/
|
||||
abstract protected function _indexEntries();
|
||||
|
||||
/**
|
||||
* Register the default namespaces for the current feed format
|
||||
*
|
||||
*/
|
||||
abstract protected function _registerNamespaces();
|
||||
}
|
122
library/Zend/Feed/Reader/FeedInterface.php
Normal file
122
library/Zend/Feed/Reader/FeedInterface.php
Normal file
|
@ -0,0 +1,122 @@
|
|||
<?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: FeedInterface.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
|
||||
*/
|
||||
interface Zend_Feed_Reader_FeedInterface extends Iterator, Countable
|
||||
{
|
||||
/**
|
||||
* Get a single author
|
||||
*
|
||||
* @param int $index
|
||||
* @return string|null
|
||||
*/
|
||||
public function getAuthor($index = 0);
|
||||
|
||||
/**
|
||||
* Get an array with feed authors
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAuthors();
|
||||
|
||||
/**
|
||||
* Get the copyright entry
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCopyright();
|
||||
|
||||
/**
|
||||
* Get the feed creation date
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDateCreated();
|
||||
|
||||
/**
|
||||
* Get the feed modification date
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDateModified();
|
||||
|
||||
/**
|
||||
* Get the feed description
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDescription();
|
||||
|
||||
/**
|
||||
* Get the feed generator entry
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getGenerator();
|
||||
|
||||
/**
|
||||
* Get the feed ID
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
* Get the feed language
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLanguage();
|
||||
|
||||
/**
|
||||
* Get a link to the HTML source
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLink();
|
||||
|
||||
/**
|
||||
* Get a link to the XML feed
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFeedLink();
|
||||
|
||||
/**
|
||||
* Get the feed title
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTitle();
|
||||
|
||||
/**
|
||||
* Get all categories
|
||||
*
|
||||
* @return Zend_Feed_Reader_Collection_Category
|
||||
*/
|
||||
public function getCategories();
|
||||
|
||||
}
|
148
library/Zend/Feed/Reader/FeedSet.php
Normal file
148
library/Zend/Feed/Reader/FeedSet.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?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: FeedSet.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Feed_Reader
|
||||
*/
|
||||
require_once 'Zend/Feed/Reader.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Uri
|
||||
*/
|
||||
require_once 'Zend/Uri.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_FeedSet extends ArrayObject
|
||||
{
|
||||
|
||||
public $rss = null;
|
||||
|
||||
public $rdf = null;
|
||||
|
||||
public $atom = null;
|
||||
|
||||
/**
|
||||
* Import a DOMNodeList from any document containing a set of links
|
||||
* for alternate versions of a document, which will normally refer to
|
||||
* RSS/RDF/Atom feeds for the current document.
|
||||
*
|
||||
* All such links are stored internally, however the first instance of
|
||||
* each RSS, RDF or Atom type has its URI stored as a public property
|
||||
* as a shortcut where the use case is simply to get a quick feed ref.
|
||||
*
|
||||
* Note that feeds are not loaded at this point, but will be lazy
|
||||
* loaded automatically when each links 'feed' array key is accessed.
|
||||
*
|
||||
* @param DOMNodeList $links
|
||||
* @param string $uri
|
||||
* @return void
|
||||
*/
|
||||
public function addLinks(DOMNodeList $links, $uri)
|
||||
{
|
||||
foreach ($links as $link) {
|
||||
if (strtolower($link->getAttribute('rel')) !== 'alternate'
|
||||
|| !$link->getAttribute('type') || !$link->getAttribute('href')) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($this->rss) && $link->getAttribute('type') == 'application/rss+xml') {
|
||||
$this->rss = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri);
|
||||
} elseif(!isset($this->atom) && $link->getAttribute('type') == 'application/atom+xml') {
|
||||
$this->atom = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri);
|
||||
} elseif(!isset($this->rdf) && $link->getAttribute('type') == 'application/rdf+xml') {
|
||||
$this->rdf = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri);
|
||||
}
|
||||
$this[] = new self(array(
|
||||
'rel' => 'alternate',
|
||||
'type' => $link->getAttribute('type'),
|
||||
'href' => $this->_absolutiseUri(trim($link->getAttribute('href')), $uri),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to turn a relative URI into an absolute URI
|
||||
*/
|
||||
protected function _absolutiseUri($link, $uri = null)
|
||||
{
|
||||
if (!Zend_Uri::check($link)) {
|
||||
if (!is_null($uri)) {
|
||||
$uri = Zend_Uri::factory($uri);
|
||||
|
||||
if ($link[0] !== '/') {
|
||||
$link = $uri->getPath() . '/' . $link;
|
||||
}
|
||||
|
||||
$link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->_canonicalizePath($link);
|
||||
if (!Zend_Uri::check($link)) {
|
||||
$link = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Canonicalize relative path
|
||||
*/
|
||||
protected function _canonicalizePath($path)
|
||||
{
|
||||
$parts = array_filter(explode('/', $path));
|
||||
$absolutes = array();
|
||||
foreach ($parts as $part) {
|
||||
if ('.' == $part) {
|
||||
continue;
|
||||
}
|
||||
if ('..' == $part) {
|
||||
array_pop($absolutes);
|
||||
} else {
|
||||
$absolutes[] = $part;
|
||||
}
|
||||
}
|
||||
return implode('/', $absolutes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports lazy loading of feeds using Zend_Feed_Reader::import() but
|
||||
* delegates any other operations to the parent class.
|
||||
*
|
||||
* @param string $offset
|
||||
* @return mixed
|
||||
* @uses Zend_Feed_Reader
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
if ($offset == 'feed' && !$this->offsetExists('feed')) {
|
||||
if (!$this->offsetExists('href')) {
|
||||
return null;
|
||||
}
|
||||
$feed = Zend_Feed_Reader::import($this->offsetGet('href'));
|
||||
$this->offsetSet('feed', $feed);
|
||||
return $feed;
|
||||
}
|
||||
return parent::offsetGet($offset);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue