Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,229 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader;
use DOMDocument;
use DOMElement;
use DOMXPath;
/**
* @deprecated This (abstract) class is deprecated. Use Zend\Feed\Reader\Entry\AbstractEntry instead.
*/
abstract class AbstractEntry
{
/**
* Feed entry data
*
* @var array
*/
protected $data = [];
/**
* DOM document object
*
* @var DOMDocument
*/
protected $domDocument = null;
/**
* Entry instance
*
* @var DOMElement
*/
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 = [];
/**
* Constructor
*
* @param DOMElement $entry
* @param int $entryKey
* @param null|string $type
*/
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'] = Reader::detectType($entry);
}
$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\AbstractEntry
*/
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\AbstractEntry
*/
public function getExtension($name)
{
if (array_key_exists($name . '\Entry', $this->extensions)) {
return $this->extensions[$name . '\Entry'];
}
return;
}
/**
* Method overloading: call given method on first extension implementing it
*
* @param string $method
* @param array $args
* @return mixed
* @throws Exception\BadMethodCallException 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([$extension, $method], $args);
}
}
throw new Exception\BadMethodCallException('Method: ' . $method
. 'does not exist and could not be located on a registered Extension');
}
/**
* Load extensions from Zend\Feed\Reader\Reader
*
* @return void
*/
// @codingStandardsIgnoreStart
protected function _loadExtensions()
{
// @codingStandardsIgnoreEnd
$all = Reader::getExtensions();
$feed = $all['entry'];
foreach ($feed as $extension) {
if (in_array($extension, $all['core'])) {
continue;
}
$className = Reader::getPluginLoader()->getClassName($extension);
$this->extensions[$extension] = new $className(
$this->getElement(), $this->entryKey, $this->data['type']
);
}
}
}

View File

@@ -0,0 +1,303 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader;
use DOMDocument;
use DOMElement;
use DOMXPath;
/**
* @deprecated This (abstract) class is deprecated. Use \Zend\Feed\Reader\Feed\AbstractFeed instead.
*/
abstract class AbstractFeed implements Feed\FeedInterface
{
/**
* Parsed feed data
*
* @var array
*/
protected $data = [];
/**
* Parsed feed data in the shape of a DOMDocument
*
* @var DOMDocument
*/
protected $domDocument = null;
/**
* An array of parsed feed entries
*
* @var array
*/
protected $entries = [];
/**
* 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 = [];
/**
* Original Source URI (set if imported from a URI)
*
* @var string
*/
protected $originalSourceUri = null;
/**
* Constructor
*
* @param DomDocument $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'] = Reader::detectType($this->domDocument);
}
$this->registerNamespaces();
$this->indexEntries();
$this->loadExtensions();
}
/**
* Set an original source URI for the feed being parsed. This value
* is returned from getFeedLink() method if the feed does not carry
* a self-referencing URI.
*
* @param string $uri
*/
public function setOriginalSourceUri($uri)
{
$this->originalSourceUri = $uri;
}
/**
* Get an original source URI for the feed being parsed. Returns null if
* unset or the feed was not imported from a URI.
*
* @return string|null
*/
public function getOriginalSourceUri()
{
return $this->originalSourceUri;
}
/**
* 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\Entry\AbstractEntry
*/
public function current()
{
if (0 === strpos($this->getType(), 'rss')) {
$reader = new Entry\RSS($this->entries[$this->key()], $this->key(), $this->getType());
} else {
$reader = new 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 int
*/
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 bool
*/
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([$extension, $method], $args);
}
}
throw new Exception\BadMethodCallException('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\AbstractFeed
*/
public function getExtension($name)
{
if (array_key_exists($name . '\Feed', $this->extensions)) {
return $this->extensions[$name . '\Feed'];
}
return;
}
protected function loadExtensions()
{
$all = Reader::getExtensions();
$manager = Reader::getExtensionManager();
$feed = $all['feed'];
foreach ($feed as $extension) {
if (in_array($extension, $all['core'])) {
continue;
}
$plugin = $manager->get($extension);
$plugin->setDomDocument($this->getDomDocument());
$plugin->setType($this->data['type']);
$plugin->setXpath($this->xpath);
$this->extensions[$extension] = $plugin;
}
}
/**
* 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();
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2019 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader;
use ArrayObject;
/**
* @deprecated This class is deprecated. Use the concrete collection classes
* \Zend\Feed\Reader\Collection\Author and \Zend\Feed\Reader\Collection\Category
* or the generic class \Zend\Feed\Reader\Collection\Collection instead.
*/
class Collection extends ArrayObject
{
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Collection;
use ArrayObject;
abstract class AbstractCollection 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
*/
abstract public function getValues();
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Collection;
class Author extends AbstractCollection
{
/**
* Return a simple array of the most relevant slice of
* the author values, i.e. all author names.
*
* @return array
*/
public function getValues()
{
$authors = [];
foreach ($this->getIterator() as $element) {
$authors[] = $element['name'];
}
return array_unique($authors);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Collection;
class Category extends AbstractCollection
{
/**
* 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 = [];
foreach ($this->getIterator() as $element) {
if (isset($element['label']) && ! empty($element['label'])) {
$categories[] = $element['label'];
} else {
$categories[] = $element['term'];
}
}
return array_unique($categories);
}
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Collection;
use ArrayObject;
class Collection extends ArrayObject
{
}

View File

@@ -0,0 +1,233 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Entry;
use DOMDocument;
use DOMElement;
use DOMXPath;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Exception;
abstract class AbstractEntry
{
/**
* Feed entry data
*
* @var array
*/
protected $data = [];
/**
* DOM document object
*
* @var DOMDocument
*/
protected $domDocument = null;
/**
* Entry instance
*
* @var DOMElement
*/
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 = [];
/**
* Constructor
*
* @param DOMElement $entry
* @param int $entryKey
* @param string $type
*/
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;
} elseif ($this->domDocument !== null) {
$this->data['type'] = Reader\Reader::detectType($this->domDocument);
} else {
$this->data['type'] = Reader\Reader::TYPE_ANY;
}
$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());
$deep = version_compare(PHP_VERSION, '7', 'ge') ? 1 : true;
$entry = $dom->importNode($this->getElement(), $deep);
$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 AbstractEntry
*/
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 Reader\Extension\AbstractEntry
*/
public function getExtension($name)
{
if (array_key_exists($name . '\\Entry', $this->extensions)) {
return $this->extensions[$name . '\\Entry'];
}
return;
}
/**
* Method overloading: call given method on first extension implementing it
*
* @param string $method
* @param array $args
* @return mixed
* @throws Exception\RuntimeException 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([$extension, $method], $args);
}
}
throw new Exception\RuntimeException(sprintf(
'Method: %s does not exist and could not be located on a registered Extension',
$method
));
}
/**
* Load extensions from Zend\Feed\Reader\Reader
*
* @return void
*/
protected function loadExtensions()
{
$all = Reader\Reader::getExtensions();
$manager = Reader\Reader::getExtensionManager();
$feed = $all['entry'];
foreach ($feed as $extension) {
if (in_array($extension, $all['core'])) {
continue;
}
$plugin = $manager->get($extension);
$plugin->setEntryElement($this->getElement());
$plugin->setEntryKey($this->entryKey);
$plugin->setType($this->data['type']);
$this->extensions[$extension] = $plugin;
}
}
}

View File

@@ -0,0 +1,367 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Entry;
use DOMElement;
use DOMXPath;
use Zend\Feed\Reader;
class Atom extends AbstractEntry implements EntryInterface
{
/**
* XPath query
*
* @var string
*/
protected $xpathQuery = '';
/**
* Constructor
*
* @param DOMElement $entry
* @param int $entryKey
* @param string $type
*/
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) . ']';
$manager = Reader\Reader::getExtensionManager();
$extensions = ['Atom\Entry', 'Thread\Entry', 'DublinCore\Entry'];
foreach ($extensions as $name) {
$extension = $manager->get($name);
$extension->setEntryElement($entry);
$extension->setEntryKey($entryKey);
$extension->setType($type);
$this->extensions[$name] = $extension;
}
}
/**
* @inheritdoc
*/
public function getAuthor($index = 0)
{
$authors = $this->getAuthors();
if (isset($authors[$index])) {
return $authors[$index];
}
return;
}
/**
* 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 \DateTime
*/
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 \DateTime
*/
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;
}
/**
* 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 int
*/
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 Reader\Reader_Collection_Category object
*
* @return 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 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
* @return void
*/
public function setXpath(DOMXPath $xpath)
{
parent::setXpath($xpath);
foreach ($this->extensions as $extension) {
$extension->setXpath($this->xpath);
}
}
}

View File

@@ -0,0 +1,129 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Entry;
use Zend\Feed\Reader\Collection\Category;
interface EntryInterface
{
/**
* Get the specified author
*
* @param int $index
* @return array<string, 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 \DateTime
*/
public function getDateCreated();
/**
* Get the entry modification date
*
* @return \DateTime
*/
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 int
*/
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 Category
*/
public function getCategories();
}

View File

@@ -0,0 +1,593 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Entry;
use DateTime;
use DOMElement;
use DOMXPath;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Exception;
class Rss extends AbstractEntry implements EntryInterface
{
/**
* XPath query for RDF
*
* @var string
*/
protected $xpathQueryRdf = '';
/**
* XPath query for RSS
*
* @var string
*/
protected $xpathQueryRss = '';
/**
* Constructor
*
* @param DOMElement $entry
* @param string $entryKey
* @param string $type
*/
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) . ']';
$manager = Reader\Reader::getExtensionManager();
$extensions = [
'DublinCore\Entry',
'Content\Entry',
'Atom\Entry',
'WellFormedWeb\Entry',
'Slash\Entry',
'Thread\Entry',
];
foreach ($extensions as $name) {
$extension = $manager->get($name);
$extension->setEntryElement($entry);
$extension->setEntryKey($entryKey);
$extension->setType($type);
$this->extensions[$name] = $extension;
}
}
/**
* @inheritdoc
*/
public function getAuthor($index = 0)
{
$authors = $this->getAuthors();
if (isset($authors[$index])) {
return $authors[$index];
}
return;
}
/**
* Get an array with feed authors
*
* @return array
*/
public function getAuthors()
{
if (array_key_exists('authors', $this->data)) {
return $this->data['authors'];
}
$authors = [];
$authorsDc = $this->getExtension('DublinCore')->getAuthors();
if (! empty($authorsDc)) {
foreach ($authorsDc as $author) {
$authors[] = [
'name' => $author['name']
];
}
}
if ($this->getType() !== Reader\Reader::TYPE_RSS_10
&& $this->getType() !== Reader\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);
$data = [];
// 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 Reader\Collection\Author(
Reader\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 \DateTime
*/
public function getDateCreated()
{
return $this->getDateModified();
}
/**
* Get the entry's date of modification
*
* @throws Exception\RuntimeException
* @return \DateTime
*/
public function getDateModified()
{
if (array_key_exists('datemodified', $this->data)) {
return $this->data['datemodified'];
}
$date = null;
if ($this->getType() !== Reader\Reader::TYPE_RSS_10
&& $this->getType() !== Reader\Reader::TYPE_RSS_090
) {
$dateModified = $this->xpath->evaluate('string(' . $this->xpathQueryRss . '/pubDate)');
if ($dateModified) {
$dateModifiedParsed = strtotime($dateModified);
if ($dateModifiedParsed) {
$date = new DateTime('@' . $dateModifiedParsed);
} else {
$dateStandards = [DateTime::RSS, DateTime::RFC822,
DateTime::RFC2822, null];
foreach ($dateStandards as $standard) {
try {
$date = date_create_from_format($standard, $dateModified);
break;
} catch (\Exception $e) {
if ($standard === null) {
throw new Exception\RuntimeException(
'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() !== Reader\Reader::TYPE_RSS_10
&& $this->getType() !== Reader\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;
}
$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() == Reader\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() !== Reader\Reader::TYPE_RSS_10
&& $this->getType() !== Reader\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;
}
/**
* Get all links
*
* @return array
*/
public function getLinks()
{
if (array_key_exists('links', $this->data)) {
return $this->data['links'];
}
$links = [];
if ($this->getType() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\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 Reader\Collection\Category
*/
public function getCategories()
{
if (array_key_exists('categories', $this->data)) {
return $this->data['categories'];
}
if ($this->getType() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\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 Reader\Collection\Category;
foreach ($list as $category) {
$categoryCollection[] = [
'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() !== Reader\Reader::TYPE_RSS_10
&& $this->getType() !== Reader\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() !== Reader\Reader::TYPE_RSS_10
&& $this->getType() !== Reader\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
* @return void
*/
public function setXpath(DOMXPath $xpath)
{
parent::setXpath($xpath);
foreach ($this->extensions as $extension) {
$extension->setXpath($this->xpath);
}
}
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Exception;
use Zend\Feed\Exception;
class BadMethodCallException extends Exception\BadMethodCallException implements ExceptionInterface
{
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Exception;
use Zend\Feed\Exception\ExceptionInterface as Exception;
interface ExceptionInterface extends Exception
{
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Exception;
use Zend\Feed\Exception;
class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface
{
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Exception;
use Zend\Feed\Exception;
class InvalidHttpClientException extends Exception\InvalidArgumentException implements ExceptionInterface
{
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Exception;
use Zend\Feed\Exception;
class RuntimeException extends Exception\RuntimeException implements ExceptionInterface
{
}

View File

@@ -0,0 +1,233 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension;
use DOMDocument;
use DOMElement;
use DOMXPath;
use Zend\Feed\Reader;
abstract class AbstractEntry
{
/**
* Feed entry data
*
* @var array
*/
protected $data = [];
/**
* DOM document object
*
* @var DOMDocument
*/
protected $domDocument = null;
/**
* Entry instance
*
* @var DOMElement
*/
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 = '';
/**
* Set the entry DOMElement
*
* Has side effect of setting the DOMDocument for the entry.
*
* @param DOMElement $entry
* @return AbstractEntry
*/
public function setEntryElement(DOMElement $entry)
{
$this->entry = $entry;
$this->domDocument = $entry->ownerDocument;
return $this;
}
/**
* Get the entry DOMElement
*
* @return DOMElement
*/
public function getEntryElement()
{
return $this->entry;
}
/**
* Set the entry key
*
* @param string $entryKey
* @return AbstractEntry
*/
public function setEntryKey($entryKey)
{
$this->entryKey = $entryKey;
return $this;
}
/**
* 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;
}
/**
* Set the entry type
*
* Has side effect of setting xpath prefix
*
* @param string $type
* @return AbstractEntry
*/
public function setType($type)
{
if (null === $type) {
$this->data['type'] = null;
return $this;
}
$this->data['type'] = $type;
if ($type === Reader\Reader::TYPE_RSS_10
|| $type === Reader\Reader::TYPE_RSS_090
) {
$this->setXpathPrefix('//rss:item[' . ((int)$this->entryKey + 1) . ']');
return $this;
}
if ($type === Reader\Reader::TYPE_ATOM_10
|| $type === Reader\Reader::TYPE_ATOM_03
) {
$this->setXpathPrefix('//atom:entry[' . ((int)$this->entryKey + 1) . ']');
return $this;
}
$this->setXpathPrefix('//item[' . ((int)$this->entryKey + 1) . ']');
return $this;
}
/**
* Get the entry type
*
* @return string
*/
public function getType()
{
$type = $this->data['type'];
if ($type === null) {
$type = Reader\Reader::detectType($this->getEntryElement(), true);
$this->setType($type);
}
return $type;
}
/**
* Set the XPath query
*
* @param DOMXPath $xpath
* @return AbstractEntry
*/
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 AbstractEntry
*/
public function setXpathPrefix($prefix)
{
$this->xpathPrefix = $prefix;
return $this;
}
/**
* Register XML namespaces
*
* @return void
*/
abstract protected function registerNamespaces();
}

View File

@@ -0,0 +1,175 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension;
use DOMDocument;
use DOMXPath;
use Zend\Feed\Reader;
abstract class AbstractFeed
{
/**
* Parsed feed data
*
* @var array
*/
protected $data = [];
/**
* 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 = '';
/**
* Set the DOM document
*
* @param DOMDocument $dom
* @return AbstractFeed
*/
public function setDomDocument(DOMDocument $dom)
{
$this->domDocument = $dom;
return $this;
}
/**
* 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;
}
/**
* Set the feed type
*
* @param string $type
* @return AbstractFeed
*/
public function setType($type)
{
$this->data['type'] = $type;
return $this;
}
/**
* Get the feed type
*
* If null, it will attempt to autodetect the type.
*
* @return string
*/
public function getType()
{
$type = $this->data['type'];
if (null === $type) {
$type = Reader\Reader::detectType($this->getDomDocument());
$this->setType($type);
}
return $type;
}
/**
* Return the feed as an array
*
* @return array
*/
public function toArray() // untested
{
return $this->data;
}
/**
* Set the XPath query
*
* @param DOMXPath $xpath
* @return AbstractFeed
*/
public function setXpath(DOMXPath $xpath = null)
{
if (null === $xpath) {
$this->xpath = null;
return $this;
}
$this->xpath = $xpath;
$this->registerNamespaces();
return $this;
}
/**
* Get the DOMXPath object
*
* @return string
*/
public function getXpath()
{
if (null === $this->xpath) {
$this->setXpath(new DOMXPath($this->getDomDocument()));
}
return $this->xpath;
}
/**
* Get the XPath prefix
*
* @return string
*/
public function getXpathPrefix()
{
return $this->xpathPrefix;
}
/**
* Set the XPath prefix
*
* @param string $prefix
* @return void
*/
public function setXpathPrefix($prefix)
{
$this->xpathPrefix = $prefix;
}
/**
* Register the default namespaces for the current feed format
*/
abstract protected function registerNamespaces();
}

View File

@@ -0,0 +1,634 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension\Atom;
use DateTime;
use DOMDocument;
use DOMElement;
use stdClass;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Collection;
use Zend\Feed\Reader\Extension;
use Zend\Feed\Uri;
class Entry extends Extension\AbstractEntry
{
/**
* 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;
}
/**
* Get an array with feed authors
*
* @return Collection\Author
*/
public function getAuthors()
{
if (array_key_exists('authors', $this->data)) {
return $this->data['authors'];
}
$authors = [];
$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->getAuthorFromElement($author);
if (! empty($author)) {
$authors[] = $author;
}
}
}
if (count($authors) == 0) {
$authors = new Collection\Author();
} else {
$authors = new Collection\Author(
Reader\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);
$d = new DOMDocument('1.0', $this->getEncoding());
$deep = version_compare(PHP_VERSION, '7', 'ge') ? 1 : true;
$xhtmls = $d->importNode($xhtml, $deep);
$d->appendChild($xhtmls);
$content = $this->collectXhtml(
$d->saveXML(),
$d->lookupPrefix('http://www.w3.org/1999/xhtml')
);
break;
}
}
if (! $content) {
$content = $this->getDescription();
}
$this->data['content'] = trim($content);
return $this->data['content'];
}
/**
* Parse out XHTML to remove the namespacing
*
* @param $xhtml
* @param $prefix
* @return mixed
*/
protected function collectXhtml($xhtml, $prefix)
{
if (! empty($prefix)) {
$prefix = $prefix . ':';
}
$matches = [
"/<\?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() === Reader\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 DateTime($dateCreated);
}
$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() === Reader\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 DateTime($dateModified);
}
$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;
}
$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;
}
/**
* Get all links
*
* @return array
*/
public function getLinks()
{
if (array_key_exists('links', $this->data)) {
return $this->data['links'];
}
$links = [];
$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;
}
$this->data['title'] = $title;
return $this->data['title'];
}
/**
* Get the number of comments/replies for current entry
*
* @return int
*/
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
*
* @param string $type
* @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 Collection\Category
*/
public function getCategories()
{
if (array_key_exists('categories', $this->data)) {
return $this->data['categories'];
}
if ($this->getAtomType() == Reader\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 retrofitted to use Atom 1.0 instead.
*/
$this->getXpath()->registerNamespace('atom10', Reader\Reader::NAMESPACE_ATOM_10);
$list = $this->getXpath()->query($this->getXpathPrefix() . '//atom10:category');
}
if ($list->length) {
$categoryCollection = new Collection\Category;
foreach ($list as $category) {
$categoryCollection[] = [
'term' => $category->getAttribute('term'),
'scheme' => $category->getAttribute('scheme'),
'label' => $category->getAttribute('label')
];
}
} else {
return new Collection\Category;
}
$this->data['categories'] = $categoryCollection;
return $this->data['categories'];
}
/**
* Get source feed metadata from the entry
*
* @return 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() == Reader\Reader::TYPE_ATOM_10) {
$list = $this->getXpath()->query($this->getXpathPrefix() . '/atom:source[1]');
if ($list->length) {
$element = $list->item(0);
$source = new 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.
*
* @param $link
* @return string
*/
protected function absolutiseUri($link)
{
if (! Uri::factory($link)->isAbsolute()) {
if ($this->getBaseUrl() !== null) {
$link = $this->getBaseUrl() . $link;
if (! Uri::factory($link)->isValid()) {
$link = null;
}
}
}
return $link;
}
/**
* Get an author entry
*
* @param DOMElement $element
* @return string
*/
protected function getAuthorFromElement(DOMElement $element)
{
$author = [];
$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;
}
return $author;
}
/**
* Register the default namespaces for the current feed format
*/
protected function registerNamespaces()
{
switch ($this->getAtomType()) {
case Reader\Reader::TYPE_ATOM_03:
$this->getXpath()->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_03);
break;
default:
$this->getXpath()->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_10);
break;
}
}
/**
* Detect the presence of any Atom namespaces in use
*
* @return string
*/
protected function getAtomType()
{
$dom = $this->getDomDocument();
$prefixAtom03 = $dom->lookupPrefix(Reader\Reader::NAMESPACE_ATOM_03);
$prefixAtom10 = $dom->lookupPrefix(Reader\Reader::NAMESPACE_ATOM_10);
if ($dom->isDefaultNamespace(Reader\Reader::NAMESPACE_ATOM_03)
|| ! empty($prefixAtom03)) {
return Reader\Reader::TYPE_ATOM_03;
}
if ($dom->isDefaultNamespace(Reader\Reader::NAMESPACE_ATOM_10)
|| ! empty($prefixAtom10)) {
return Reader\Reader::TYPE_ATOM_10;
}
}
}

View File

@@ -0,0 +1,539 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension\Atom;
use DateTime;
use DOMElement;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Collection;
use Zend\Feed\Reader\Extension;
use Zend\Feed\Uri;
class Feed extends Extension\AbstractFeed
{
/**
* Get a single author
*
* @param int $index
* @return string|null
*/
public function getAuthor($index = 0)
{
$authors = $this->getAuthors();
if (isset($authors[$index])) {
return $authors[$index];
}
return;
}
/**
* Get an array with feed authors
*
* @return Collection\Author
*/
public function getAuthors()
{
if (array_key_exists('authors', $this->data)) {
return $this->data['authors'];
}
$list = $this->xpath->query('//atom:author');
$authors = [];
if ($list->length) {
foreach ($list as $author) {
$author = $this->getAuthorFromElement($author);
if (! empty($author)) {
$authors[] = $author;
}
}
}
if (count($authors) == 0) {
$authors = new Collection\Author();
} else {
$authors = new Collection\Author(
Reader\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() === Reader\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 DateTime|null
*/
public function getDateCreated()
{
if (array_key_exists('datecreated', $this->data)) {
return $this->data['datecreated'];
}
$date = null;
if ($this->getType() === Reader\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 DateTime($dateCreated);
}
$this->data['datecreated'] = $date;
return $this->data['datecreated'];
}
/**
* Get the feed modification date
*
* @return DateTime|null
*/
public function getDateModified()
{
if (array_key_exists('datemodified', $this->data)) {
return $this->data['datemodified'];
}
$date = null;
if ($this->getType() === Reader\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 DateTime($dateModified);
}
$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() === Reader\Reader::TYPE_ATOM_03) {
$description = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:tagline)');
} 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;
}
$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 feed image
*
* @return array|null
*/
public function getImage()
{
if (array_key_exists('image', $this->data)) {
return $this->data['image'];
}
$imageUrl = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/atom:logo)');
if (! $imageUrl) {
$image = null;
} else {
$image = ['uri' => $imageUrl];
}
$this->data['image'] = $image;
return $this->data['image'];
}
/**
* 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 = [];
$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 Collection\Category
*/
public function getCategories()
{
if (array_key_exists('categories', $this->data)) {
return $this->data['categories'];
}
if ($this->getType() == Reader\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', Reader\Reader::NAMESPACE_ATOM_10);
$list = $this->xpath->query($this->getXpathPrefix() . '/atom10:category');
}
if ($list->length) {
$categoryCollection = new Collection\Category;
foreach ($list as $category) {
$categoryCollection[] = [
'term' => $category->getAttribute('term'),
'scheme' => $category->getAttribute('scheme'),
'label' => $category->getAttribute('label')
];
}
} else {
return new Collection\Category;
}
$this->data['categories'] = $categoryCollection;
return $this->data['categories'];
}
/**
* Get an author entry in RSS format
*
* @param DOMElement $element
* @return string
*/
protected function getAuthorFromElement(DOMElement $element)
{
$author = [];
$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;
}
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.
*
* @param string $link
* @return string|null
*/
protected function absolutiseUri($link)
{
if (! Uri::factory($link)->isAbsolute()) {
if ($this->getBaseUrl() !== null) {
$link = $this->getBaseUrl() . $link;
if (! Uri::factory($link)->isValid()) {
$link = null;
}
}
}
return $link;
}
/**
* Register the default namespaces for the current feed format
*/
protected function registerNamespaces()
{
if ($this->getType() == Reader\Reader::TYPE_ATOM_10
|| $this->getType() == Reader\Reader::TYPE_ATOM_03
) {
return; // pre-registered at Feed level
}
$atomDetected = $this->getAtomType();
switch ($atomDetected) {
case Reader\Reader::TYPE_ATOM_03:
$this->xpath->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_03);
break;
default:
$this->xpath->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_10);
break;
}
}
/**
* Detect the presence of any Atom namespaces in use
*/
protected function getAtomType()
{
$dom = $this->getDomDocument();
$prefixAtom03 = $dom->lookupPrefix(Reader\Reader::NAMESPACE_ATOM_03);
$prefixAtom10 = $dom->lookupPrefix(Reader\Reader::NAMESPACE_ATOM_10);
if ($dom->isDefaultNamespace(Reader\Reader::NAMESPACE_ATOM_10)
|| ! empty($prefixAtom10)
) {
return Reader\Reader::TYPE_ATOM_10;
}
if ($dom->isDefaultNamespace(Reader\Reader::NAMESPACE_ATOM_03)
|| ! empty($prefixAtom03)
) {
return Reader\Reader::TYPE_ATOM_03;
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension\Content;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Extension;
class Entry extends Extension\AbstractEntry
{
public function getContent()
{
if ($this->getType() !== Reader\Reader::TYPE_RSS_10
&& $this->getType() !== Reader\Reader::TYPE_RSS_090
) {
$content = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/content:encoded)');
} else {
$content = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/content:encoded)');
}
return $content;
}
/**
* Register RSS Content Module namespace
*/
protected function registerNamespaces()
{
$this->xpath->registerNamespace('content', 'http://purl.org/rss/1.0/modules/content/');
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension\CreativeCommons;
use Zend\Feed\Reader\Extension;
class Entry extends Extension\AbstractEntry
{
/**
* Get the entry license
*
* @param int $index
* @return string|null
*/
public function getLicense($index = 0)
{
$licenses = $this->getLicenses();
if (isset($licenses[$index])) {
return $licenses[$index];
}
return;
}
/**
* Get the entry licenses
*
* @return array
*/
public function getLicenses()
{
$name = 'licenses';
if (array_key_exists($name, $this->data)) {
return $this->data[$name];
}
$licenses = [];
$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 Feed();
$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');
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension\CreativeCommons;
use Zend\Feed\Reader\Extension;
class Feed extends Extension\AbstractFeed
{
/**
* Get the entry license
*
* @param int $index
* @return string|null
*/
public function getLicense($index = 0)
{
$licenses = $this->getLicenses();
if (isset($licenses[$index])) {
return $licenses[$index];
}
return;
}
/**
* Get the entry licenses
*
* @return array
*/
public function getLicenses()
{
$name = 'licenses';
if (array_key_exists($name, $this->data)) {
return $this->data[$name];
}
$licenses = [];
$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');
}
}

View File

@@ -0,0 +1,234 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension\DublinCore;
use DateTime;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Collection;
use Zend\Feed\Reader\Extension;
class Entry extends Extension\AbstractEntry
{
/**
* Get an author entry
*
* @param int $index
* @return string
*/
public function getAuthor($index = 0)
{
$authors = $this->getAuthors();
if (isset($authors[$index])) {
return $authors[$index];
}
return;
}
/**
* Get an array with feed authors
*
* @return array
*/
public function getAuthors()
{
if (array_key_exists('authors', $this->data)) {
return $this->data['authors'];
}
$authors = [];
$list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc11:creator');
if (! $list->length) {
$list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc10:creator');
}
if (! $list->length) {
$list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc11:publisher');
if (! $list->length) {
$list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc10:publisher');
}
}
if ($list->length) {
foreach ($list as $author) {
$authors[] = [
'name' => $author->nodeValue
];
}
$authors = new Collection\Author(
Reader\Reader::arrayUnique($authors)
);
} else {
$authors = null;
}
$this->data['authors'] = $authors;
return $this->data['authors'];
}
/**
* Get categories (subjects under DC)
*
* @return Collection\Category
*/
public function getCategories()
{
if (array_key_exists('categories', $this->data)) {
return $this->data['categories'];
}
$list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc11:subject');
if (! $list->length) {
$list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc10:subject');
}
if ($list->length) {
$categoryCollection = new Collection\Category;
foreach ($list as $category) {
$categoryCollection[] = [
'term' => $category->nodeValue,
'scheme' => null,
'label' => $category->nodeValue,
];
}
} else {
$categoryCollection = new 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 = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)');
if (! $description) {
$description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)');
}
if (! $description) {
$description = null;
}
$this->data['description'] = $description;
return $this->data['description'];
}
/**
* Get the 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() . '/dc11:identifier)');
if (! $id) {
$id = $this->getXpath()->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 = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)');
if (! $title) {
$title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)');
}
if (! $title) {
$title = null;
}
$this->data['title'] = $title;
return $this->data['title'];
}
/**
*
*
* @return DateTime|null
*/
public function getDate()
{
if (array_key_exists('date', $this->data)) {
return $this->data['date'];
}
$d = null;
$date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)');
if (! $date) {
$date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)');
}
if ($date) {
$d = new DateTime($date);
}
$this->data['date'] = $d;
return $this->data['date'];
}
/**
* Register DC namespaces
*
* @return void
*/
protected function registerNamespaces()
{
$this->getXpath()->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/');
$this->getXpath()->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/');
}
}

View File

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

View File

@@ -0,0 +1,90 @@
<?php
/**
* @see https://github.com/zendframework/zend-feed for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-feed/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Feed\Reader\Extension\GooglePlayPodcast;
use Zend\Feed\Reader\Extension;
class Entry extends Extension\AbstractEntry
{
/**
* Get the entry block
*
* @return string
*/
public function getPlayPodcastBlock()
{
if (isset($this->data['block'])) {
return $this->data['block'];
}
$block = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/googleplay:block)');
if (! $block) {
$block = null;
}
$this->data['block'] = $block;
return $this->data['block'];
}
/**
* Get the entry explicit
*
* @return string
*/
public function getPlayPodcastExplicit()
{
if (isset($this->data['explicit'])) {
return $this->data['explicit'];
}
$explicit = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/googleplay:explicit)');
if (! $explicit) {
$explicit = null;
}
$this->data['explicit'] = $explicit;
return $this->data['explicit'];
}
/**
* Get the episode summary/description
*
* Uses verbiage so it does not conflict with base entry.
*
* @return string
*/
public function getPlayPodcastDescription()
{
if (isset($this->data['description'])) {
return $this->data['description'];
}
$description = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/googleplay:description)');
if (! $description) {
$description = null;
}
$this->data['description'] = $description;
return $this->data['description'];
}
/**
* Register googleplay namespace
*
*/
protected function registerNamespaces()
{
$this->xpath->registerNamespace('googleplay', 'http://www.google.com/schemas/play-podcasts/1.0');
}
}

View File

@@ -0,0 +1,175 @@
<?php
/**
* @see https://github.com/zendframework/zend-feed for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-feed/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Feed\Reader\Extension\GooglePlayPodcast;
use DOMText;
use Zend\Feed\Reader\Extension;
class Feed extends Extension\AbstractFeed
{
/**
* Get the entry author
*
* @return string
*/
public function getPlayPodcastAuthor()
{
if (isset($this->data['author'])) {
return $this->data['author'];
}
$author = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/googleplay:author)');
if (! $author) {
$author = null;
}
$this->data['author'] = $author;
return $this->data['author'];
}
/**
* Get the entry block
*
* @return string
*/
public function getPlayPodcastBlock()
{
if (isset($this->data['block'])) {
return $this->data['block'];
}
$block = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/googleplay:block)');
if (! $block) {
$block = null;
}
$this->data['block'] = $block;
return $this->data['block'];
}
/**
* Get the entry category
*
* @return array|null
*/
public function getPlayPodcastCategories()
{
if (isset($this->data['categories'])) {
return $this->data['categories'];
}
$categoryList = $this->xpath->query($this->getXpathPrefix() . '/googleplay:category');
$categories = [];
if ($categoryList->length > 0) {
foreach ($categoryList as $node) {
$children = null;
if ($node->childNodes->length > 0) {
$children = [];
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 getPlayPodcastExplicit()
{
if (isset($this->data['explicit'])) {
return $this->data['explicit'];
}
$explicit = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/googleplay:explicit)');
if (! $explicit) {
$explicit = null;
}
$this->data['explicit'] = $explicit;
return $this->data['explicit'];
}
/**
* Get the feed/podcast image
*
* @return string
*/
public function getPlayPodcastImage()
{
if (isset($this->data['image'])) {
return $this->data['image'];
}
$image = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/googleplay:image/@href)');
if (! $image) {
$image = null;
}
$this->data['image'] = $image;
return $this->data['image'];
}
/**
* Get the entry description
*
* @return string
*/
public function getPlayPodcastDescription()
{
if (isset($this->data['description'])) {
return $this->data['description'];
}
$description = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/googleplay:description)');
if (! $description) {
$description = null;
}
$this->data['description'] = $description;
return $this->data['description'];
}
/**
* Register googleplay namespace
*
*/
protected function registerNamespaces()
{
$this->xpath->registerNamespace('googleplay', 'http://www.google.com/schemas/play-podcasts/1.0');
}
}

View File

@@ -0,0 +1,314 @@
<?php
/**
* @see https://github.com/zendframework/zend-feed for the canonical source repository
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-feed/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Feed\Reader\Extension\Podcast;
use Zend\Feed\Reader\Extension;
class Entry extends Extension\AbstractEntry
{
/**
* 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
*
* @deprecated since 2.10.0; itunes:keywords is no longer part of the
* iTunes podcast RSS specification.
* @return string
*/
public function getKeywords()
{
trigger_error(
'itunes:keywords has been deprecated in the iTunes podcast RSS specification,'
. ' and should not be relied on.',
\E_USER_DEPRECATED
);
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 title
*
* @return string
*/
public function getTitle()
{
if (isset($this->data['title'])) {
return $this->data['title'];
}
$title = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:title)');
if (! $title) {
$title = null;
}
$this->data['title'] = $title;
return $this->data['title'];
}
/**
* 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'];
}
/**
* Get the entry image
*
* @return string
*/
public function getItunesImage()
{
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 episode number
*
* @return null|int
*/
public function getEpisode()
{
if (isset($this->data['episode'])) {
return $this->data['episode'];
}
$episode = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:episode)');
if (! $episode) {
$episode = null;
}
$this->data['episode'] = null === $episode ? $episode : (int) $episode;
return $this->data['episode'];
}
/**
* Get the episode number
*
* @return string One of "full", "trailer", or "bonus"; defaults to "full".
*/
public function getEpisodeType()
{
if (isset($this->data['episodeType'])) {
return $this->data['episodeType'];
}
$type = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:episodeType)');
if (! $type) {
$type = 'full';
}
$this->data['episodeType'] = (string) $type;
return $this->data['episodeType'];
}
/**
* Is the episode closed captioned?
*
* Returns true only if itunes:isClosedCaptioned has the value 'Yes'.
*
* @return bool
*/
public function isClosedCaptioned()
{
if (isset($this->data['isClosedCaptioned'])) {
return $this->data['isClosedCaptioned'];
}
$status = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:isClosedCaptioned)');
$this->data['isClosedCaptioned'] = $status === 'Yes';
return $this->data['isClosedCaptioned'];
}
/**
* Get the season number
*
* @return null|int
*/
public function getSeason()
{
if (isset($this->data['season'])) {
return $this->data['season'];
}
$season = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:season)');
if (! $season) {
$season = null;
}
$this->data['season'] = null === $season ? $season : (int) $season;
return $this->data['season'];
}
/**
* Register iTunes namespace
*
*/
protected function registerNamespaces()
{
$this->xpath->registerNamespace('itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
}
}

View File

@@ -0,0 +1,325 @@
<?php
/**
* @see https://github.com/zendframework/zend-feed for the canonical source repository
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-feed/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Feed\Reader\Extension\Podcast;
use DOMText;
use Zend\Feed\Reader\Extension;
class Feed extends Extension\AbstractFeed
{
/**
* 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 array|null
*/
public function getItunesCategories()
{
if (isset($this->data['categories'])) {
return $this->data['categories'];
}
$categoryList = $this->xpath->query($this->getXpathPrefix() . '/itunes:category');
$categories = [];
if ($categoryList->length > 0) {
foreach ($categoryList as $node) {
$children = null;
if ($node->childNodes->length > 0) {
$children = [];
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 feed/podcast image
*
* @return string
*/
public function getItunesImage()
{
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
*
* @deprecated since 2.10.0; itunes:keywords is no longer part of the
* iTunes podcast RSS specification.
* @return string
*/
public function getKeywords()
{
trigger_error(
'itunes:keywords has been deprecated in the iTunes podcast RSS specification,'
. ' and should not be relied on.',
\E_USER_DEPRECATED
);
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 . ')');
} elseif (! 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'];
}
/**
* Get the type of podcast
*
* @return string One of "episodic" or "serial". Defaults to "episodic"
* if no itunes:type tag is encountered.
*/
public function getPodcastType()
{
if (isset($this->data['podcastType'])) {
return $this->data['podcastType'];
}
$type = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:type)');
if (! $type) {
$type = 'episodic';
}
$this->data['podcastType'] = (string) $type;
return $this->data['podcastType'];
}
/**
* Is the podcast complete (no more episodes will post)?
*
* @return bool
*/
public function isComplete()
{
if (isset($this->data['complete'])) {
return $this->data['complete'];
}
$complete = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:complete)');
if (! $complete) {
$complete = false;
}
$this->data['complete'] = $complete === 'Yes';
return $this->data['complete'];
}
/**
* Register iTunes namespace
*
*/
protected function registerNamespaces()
{
$this->xpath->registerNamespace('itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension\Slash;
use Zend\Feed\Reader\Extension;
/**
*/
class Entry extends Extension\AbstractEntry
{
/**
* 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 = [];
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/');
}
}

View File

@@ -0,0 +1,150 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension\Syndication;
use DateTime;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Extension;
class Feed extends Extension\AbstractFeed
{
/**
* Get update period
*
* @return string
* @throws Reader\Exception\InvalidArgumentException
*/
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 Reader\Exception\InvalidArgumentException("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) {
case 'yearly':
$ticks *= 52; //TODO: fix generalisation, how?
// no break
case 'weekly':
$ticks *= 7;
// no break
case 'daily':
$ticks *= 24;
// no break
case 'hourly':
$ticks *= 3600;
break;
default: //Never arrive here, exception thrown in getPeriod()
break;
}
return $ticks / $freq;
}
/**
* Get update base
*
* @return DateTime|null
*/
public function getUpdateBase()
{
$updateBase = $this->getData('updateBase');
$date = null;
if ($updateBase) {
$date = DateTime::createFromFormat(DateTime::W3C, $updateBase);
}
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/');
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension\Thread;
use Zend\Feed\Reader\Extension;
/**
*/
class Entry extends Extension\AbstractEntry
{
/**
* 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
* @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');
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Extension\WellFormedWeb;
use Zend\Feed\Reader\Extension;
/**
*/
class Entry extends Extension\AbstractEntry
{
/**
* 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/');
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader;
/**
* Default implementation of ExtensionManagerInterface
*
* Decorator of ExtensionPluginManager.
*/
class ExtensionManager implements ExtensionManagerInterface
{
protected $pluginManager;
/**
* Constructor
*
* Seeds the extension manager with a plugin manager; if none provided,
* creates an instance.
*
* @param null|ExtensionPluginManager $pluginManager
*/
public function __construct(ExtensionPluginManager $pluginManager = null)
{
if (null === $pluginManager) {
$pluginManager = new ExtensionPluginManager();
}
$this->pluginManager = $pluginManager;
}
/**
* Method overloading
*
* Proxy to composed ExtensionPluginManager instance.
*
* @param string $method
* @param array $args
* @return mixed
* @throws Exception\BadMethodCallException
*/
public function __call($method, $args)
{
if (! method_exists($this->pluginManager, $method)) {
throw new Exception\BadMethodCallException(sprintf(
'Method by name of %s does not exist in %s',
$method,
__CLASS__
));
}
return call_user_func_array([$this->pluginManager, $method], $args);
}
/**
* Get the named extension
*
* @param string $name
* @return Extension\AbstractEntry|Extension\AbstractFeed
*/
public function get($name)
{
return $this->pluginManager->get($name);
}
/**
* Do we have the named extension?
*
* @param string $name
* @return bool
*/
public function has($name)
{
return $this->pluginManager->has($name);
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader;
interface ExtensionManagerInterface
{
/**
* Do we have the extension?
*
* @param string $extension
* @return bool
*/
public function has($extension);
/**
* Retrieve the extension
*
* @param string $extension
* @return mixed
*/
public function get($extension);
}

View File

@@ -0,0 +1,196 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Exception\InvalidServiceException;
use Zend\ServiceManager\Factory\InvokableFactory;
/**
* Plugin manager implementation for feed reader extensions based on the
* AbstractPluginManager.
*
* Validation checks that we have an Extension\AbstractEntry or
* Extension\AbstractFeed.
*/
class ExtensionPluginManager extends AbstractPluginManager implements ExtensionManagerInterface
{
/**
* Aliases for default set of extension classes
*
* @var array
*/
protected $aliases = [
'atomentry' => Extension\Atom\Entry::class,
'atomEntry' => Extension\Atom\Entry::class,
'AtomEntry' => Extension\Atom\Entry::class,
'Atom\Entry' => Extension\Atom\Entry::class,
'atomfeed' => Extension\Atom\Feed::class,
'atomFeed' => Extension\Atom\Feed::class,
'AtomFeed' => Extension\Atom\Feed::class,
'Atom\Feed' => Extension\Atom\Feed::class,
'contententry' => Extension\Content\Entry::class,
'contentEntry' => Extension\Content\Entry::class,
'ContentEntry' => Extension\Content\Entry::class,
'Content\Entry' => Extension\Content\Entry::class,
'creativecommonsentry' => Extension\CreativeCommons\Entry::class,
'creativeCommonsEntry' => Extension\CreativeCommons\Entry::class,
'CreativeCommonsEntry' => Extension\CreativeCommons\Entry::class,
'CreativeCommons\Entry' => Extension\CreativeCommons\Entry::class,
'creativecommonsfeed' => Extension\CreativeCommons\Feed::class,
'creativeCommonsFeed' => Extension\CreativeCommons\Feed::class,
'CreativeCommonsFeed' => Extension\CreativeCommons\Feed::class,
'CreativeCommons\Feed' => Extension\CreativeCommons\Feed::class,
'dublincoreentry' => Extension\DublinCore\Entry::class,
'dublinCoreEntry' => Extension\DublinCore\Entry::class,
'DublinCoreEntry' => Extension\DublinCore\Entry::class,
'DublinCore\Entry' => Extension\DublinCore\Entry::class,
'dublincorefeed' => Extension\DublinCore\Feed::class,
'dublinCoreFeed' => Extension\DublinCore\Feed::class,
'DublinCoreFeed' => Extension\DublinCore\Feed::class,
'DublinCore\Feed' => Extension\DublinCore\Feed::class,
'googleplaypodcastentry' => Extension\GooglePlayPodcast\Entry::class,
'googlePlayPodcastEntry' => Extension\GooglePlayPodcast\Entry::class,
'GooglePlayPodcastEntry' => Extension\GooglePlayPodcast\Entry::class,
'GooglePlayPodcast\Entry' => Extension\GooglePlayPodcast\Entry::class,
'googleplaypodcastfeed' => Extension\GooglePlayPodcast\Feed::class,
'googlePlayPodcastFeed' => Extension\GooglePlayPodcast\Feed::class,
'GooglePlayPodcastFeed' => Extension\GooglePlayPodcast\Feed::class,
'GooglePlayPodcast\Feed' => Extension\GooglePlayPodcast\Feed::class,
'podcastentry' => Extension\Podcast\Entry::class,
'podcastEntry' => Extension\Podcast\Entry::class,
'PodcastEntry' => Extension\Podcast\Entry::class,
'Podcast\Entry' => Extension\Podcast\Entry::class,
'podcastfeed' => Extension\Podcast\Feed::class,
'podcastFeed' => Extension\Podcast\Feed::class,
'PodcastFeed' => Extension\Podcast\Feed::class,
'Podcast\Feed' => Extension\Podcast\Feed::class,
'slashentry' => Extension\Slash\Entry::class,
'slashEntry' => Extension\Slash\Entry::class,
'SlashEntry' => Extension\Slash\Entry::class,
'Slash\Entry' => Extension\Slash\Entry::class,
'syndicationfeed' => Extension\Syndication\Feed::class,
'syndicationFeed' => Extension\Syndication\Feed::class,
'SyndicationFeed' => Extension\Syndication\Feed::class,
'Syndication\Feed' => Extension\Syndication\Feed::class,
'threadentry' => Extension\Thread\Entry::class,
'threadEntry' => Extension\Thread\Entry::class,
'ThreadEntry' => Extension\Thread\Entry::class,
'Thread\Entry' => Extension\Thread\Entry::class,
'wellformedwebentry' => Extension\WellFormedWeb\Entry::class,
'wellFormedWebEntry' => Extension\WellFormedWeb\Entry::class,
'WellFormedWebEntry' => Extension\WellFormedWeb\Entry::class,
'WellFormedWeb\Entry' => Extension\WellFormedWeb\Entry::class,
];
/**
* Factories for default set of extension classes
*
* @var array
*/
protected $factories = [
Extension\Atom\Entry::class => InvokableFactory::class,
Extension\Atom\Feed::class => InvokableFactory::class,
Extension\Content\Entry::class => InvokableFactory::class,
Extension\CreativeCommons\Entry::class => InvokableFactory::class,
Extension\CreativeCommons\Feed::class => InvokableFactory::class,
Extension\DublinCore\Entry::class => InvokableFactory::class,
Extension\DublinCore\Feed::class => InvokableFactory::class,
Extension\GooglePlayPodcast\Entry::class => InvokableFactory::class,
Extension\GooglePlayPodcast\Feed::class => InvokableFactory::class,
Extension\Podcast\Entry::class => InvokableFactory::class,
Extension\Podcast\Feed::class => InvokableFactory::class,
Extension\Slash\Entry::class => InvokableFactory::class,
Extension\Syndication\Feed::class => InvokableFactory::class,
Extension\Thread\Entry::class => InvokableFactory::class,
Extension\WellFormedWeb\Entry::class => InvokableFactory::class,
// Legacy (v2) due to alias resolution; canonical form of resolved
// alias is used to look up the factory, while the non-normalized
// resolved alias is used as the requested name passed to the factory.
'zendfeedreaderextensionatomentry' => InvokableFactory::class,
'zendfeedreaderextensionatomfeed' => InvokableFactory::class,
'zendfeedreaderextensioncontententry' => InvokableFactory::class,
'zendfeedreaderextensioncreativecommonsentry' => InvokableFactory::class,
'zendfeedreaderextensioncreativecommonsfeed' => InvokableFactory::class,
'zendfeedreaderextensiondublincoreentry' => InvokableFactory::class,
'zendfeedreaderextensiondublincorefeed' => InvokableFactory::class,
'zendfeedreaderextensiongoogleplaypodcastentry' => InvokableFactory::class,
'zendfeedreaderextensiongoogleplaypodcastfeed' => InvokableFactory::class,
'zendfeedreaderextensionpodcastentry' => InvokableFactory::class,
'zendfeedreaderextensionpodcastfeed' => InvokableFactory::class,
'zendfeedreaderextensionslashentry' => InvokableFactory::class,
'zendfeedreaderextensionsyndicationfeed' => InvokableFactory::class,
'zendfeedreaderextensionthreadentry' => InvokableFactory::class,
'zendfeedreaderextensionwellformedwebentry' => InvokableFactory::class,
];
/**
* Do not share instances (v2)
*
* @var bool
*/
protected $shareByDefault = false;
/**
* Do not share instances (v3)
*
* @var bool
*/
protected $sharedByDefault = false;
/**
* Validate the plugin
*
* Checks that the extension loaded is of a valid type.
*
* @param mixed $plugin
* @return void
* @throws Exception\InvalidArgumentException if invalid
*/
public function validate($plugin)
{
if ($plugin instanceof Extension\AbstractEntry
|| $plugin instanceof Extension\AbstractFeed
) {
// we're okay
return;
}
throw new InvalidServiceException(sprintf(
'Plugin of type %s is invalid; must implement %s\Extension\AbstractFeed '
. 'or %s\Extension\AbstractEntry',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__,
__NAMESPACE__
));
}
/**
* Validate the plugin (v2)
*
* @param mixed $plugin
* @return void
* @throws Exception\InvalidArgumentException if invalid
*/
public function validatePlugin($plugin)
{
try {
$this->validate($plugin);
} catch (InvalidServiceException $e) {
throw new Exception\InvalidArgumentException(sprintf(
'Plugin of type %s is invalid; must implement %s\Extension\AbstractFeed '
. 'or %s\Extension\AbstractEntry',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__,
__NAMESPACE__
));
}
}
}

View File

@@ -0,0 +1,309 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Feed;
use DOMDocument;
use DOMElement;
use DOMXPath;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Exception;
/**
*/
abstract class AbstractFeed implements FeedInterface
{
/**
* Parsed feed data
*
* @var array
*/
protected $data = [];
/**
* Parsed feed data in the shape of a DOMDocument
*
* @var DOMDocument
*/
protected $domDocument = null;
/**
* An array of parsed feed entries
*
* @var array
*/
protected $entries = [];
/**
* 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 = [];
/**
* Original Source URI (set if imported from a URI)
*
* @var string
*/
protected $originalSourceUri = null;
/**
* Constructor
*
* @param DOMDocument $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'] = Reader\Reader::detectType($this->domDocument);
}
$this->registerNamespaces();
$this->indexEntries();
$this->loadExtensions();
}
/**
* Set an original source URI for the feed being parsed. This value
* is returned from getFeedLink() method if the feed does not carry
* a self-referencing URI.
*
* @param string $uri
*/
public function setOriginalSourceUri($uri)
{
$this->originalSourceUri = $uri;
}
/**
* Get an original source URI for the feed being parsed. Returns null if
* unset or the feed was not imported from a URI.
*
* @return string|null
*/
public function getOriginalSourceUri()
{
return $this->originalSourceUri;
}
/**
* 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\Entry\EntryInterface
*/
public function current()
{
if (0 === strpos($this->getType(), 'rss')) {
$reader = new Reader\Entry\Rss($this->entries[$this->key()], $this->key(), $this->getType());
} else {
$reader = new 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 int
*/
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 bool
*/
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([$extension, $method], $args);
}
}
throw new Exception\BadMethodCallException('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\AbstractFeed|null
*/
public function getExtension($name)
{
if (array_key_exists($name . '\\Feed', $this->extensions)) {
return $this->extensions[$name . '\\Feed'];
}
return;
}
protected function loadExtensions()
{
$all = Reader\Reader::getExtensions();
$manager = Reader\Reader::getExtensionManager();
$feed = $all['feed'];
foreach ($feed as $extension) {
if (in_array($extension, $all['core'])) {
continue;
}
if (! $manager->has($extension)) {
throw new Exception\RuntimeException(
sprintf('Unable to load extension "%s"; cannot find class', $extension)
);
}
$plugin = $manager->get($extension);
$plugin->setDomDocument($this->getDomDocument());
$plugin->setType($this->data['type']);
$plugin->setXpath($this->xpath);
$this->extensions[$extension] = $plugin;
}
}
/**
* 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();
}

View File

@@ -0,0 +1,408 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Feed;
use DOMDocument;
use Zend\Feed\Reader;
/**
*/
class Atom extends AbstractFeed
{
/**
* Constructor
*
* @param DOMDocument $dom
* @param string $type
*/
public function __construct(DOMDocument $dom, $type = null)
{
parent::__construct($dom, $type);
$manager = Reader\Reader::getExtensionManager();
$atomFeed = $manager->get('Atom\Feed');
$atomFeed->setDomDocument($dom);
$atomFeed->setType($this->data['type']);
$atomFeed->setXpath($this->xpath);
$this->extensions['Atom\\Feed'] = $atomFeed;
$atomFeed = $manager->get('DublinCore\Feed');
$atomFeed->setDomDocument($dom);
$atomFeed->setType($this->data['type']);
$atomFeed->setXpath($this->xpath);
$this->extensions['DublinCore\\Feed'] = $atomFeed;
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;
}
/**
* 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 \DateTime|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 \DateTime|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 lastBuild date. This is not implemented in Atom.
*
* @return string|null
*/
public function getLastBuildDate()
{
return;
}
/**
* 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 feed image data
*
* @return array|null
*/
public function getImage()
{
if (array_key_exists('image', $this->data)) {
return $this->data['image'];
}
$link = $this->getExtension('Atom')->getImage();
$this->data['image'] = $link;
return $this->data['image'];
}
/**
* 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();
if ($link === null || empty($link)) {
$link = $this->getOriginalSourceUri();
}
$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 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() == Reader\Reader::TYPE_ATOM_10 ||
$this->getType() == Reader\Reader::TYPE_ATOM_03) {
$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 Reader\Reader::TYPE_ATOM_03:
$this->xpath->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_03);
break;
case Reader\Reader::TYPE_ATOM_10:
default:
$this->xpath->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_10);
}
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Feed\Atom;
use DOMElement;
use DOMXPath;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Feed;
/**
*/
class Source extends Feed\Atom
{
/**
* Constructor: Create a Source object which is largely just a normal
* Zend\Feed\Reader\AbstractFeed 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 = Reader\Reader::TYPE_ATOM_10)
{
$this->domDocument = $source->ownerDocument;
$this->xpath = new DOMXPath($this->domDocument);
$this->data['type'] = $type;
$this->registerNamespaces();
$this->loadExtensions();
$manager = Reader\Reader::getExtensionManager();
$extensions = ['Atom\Feed', 'DublinCore\Feed'];
foreach ($extensions as $name) {
$extension = $manager->get($name);
$extension->setDomDocument($this->domDocument);
$extension->setType($this->data['type']);
$extension->setXpath($this->xpath);
$this->extensions[$name] = $extension;
}
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()
{
}
}

View File

@@ -0,0 +1,110 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Feed;
use Countable;
use Iterator;
/**
*/
interface 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 \DateTime|null
*/
public function getDateCreated();
/**
* Get the feed modification date
*
* @return \DateTime|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();
}

View File

@@ -0,0 +1,696 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Feed;
use DateTime;
use DOMDocument;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Collection;
use Zend\Feed\Reader\Exception;
/**
*/
class Rss extends AbstractFeed
{
/**
* Constructor
*
* @param DOMDocument $dom
* @param string $type
*/
public function __construct(DOMDocument $dom, $type = null)
{
parent::__construct($dom, $type);
$manager = Reader\Reader::getExtensionManager();
$feed = $manager->get('DublinCore\Feed');
$feed->setDomDocument($dom);
$feed->setType($this->data['type']);
$feed->setXpath($this->xpath);
$this->extensions['DublinCore\Feed'] = $feed;
$feed = $manager->get('Atom\Feed');
$feed->setDomDocument($dom);
$feed->setType($this->data['type']);
$feed->setXpath($this->xpath);
$this->extensions['Atom\Feed'] = $feed;
if ($this->getType() !== Reader\Reader::TYPE_RSS_10
&& $this->getType() !== Reader\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;
}
/**
* Get an array with feed authors
*
* @return array
*/
public function getAuthors()
{
if (array_key_exists('authors', $this->data)) {
return $this->data['authors'];
}
$authors = [];
$authorsDc = $this->getExtension('DublinCore')->getAuthors();
if (! empty($authorsDc)) {
foreach ($authorsDc as $author) {
$authors[] = [
'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() !== Reader\Reader::TYPE_RSS_10
&& $this->getType() !== Reader\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);
$data = [];
// 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 Reader\Collection\Author(
Reader\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() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\Reader::TYPE_RSS_090) {
$copyright = $this->xpath->evaluate('string(/rss/channel/copyright)');
}
if (! $copyright && $this->getExtension('DublinCore') !== null) {
$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 DateTime|null
*/
public function getDateCreated()
{
return $this->getDateModified();
}
/**
* Get the feed modification date
*
* @return DateTime
* @throws Exception\RuntimeException
*/
public function getDateModified()
{
if (array_key_exists('datemodified', $this->data)) {
return $this->data['datemodified'];
}
$date = null;
if ($this->getType() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\Reader::TYPE_RSS_090) {
$dateModified = $this->xpath->evaluate('string(/rss/channel/pubDate)');
if (! $dateModified) {
$dateModified = $this->xpath->evaluate('string(/rss/channel/lastBuildDate)');
}
if ($dateModified) {
$dateModifiedParsed = strtotime($dateModified);
if ($dateModifiedParsed) {
$date = new DateTime('@' . $dateModifiedParsed);
} else {
$dateStandards = [DateTime::RSS, DateTime::RFC822,
DateTime::RFC2822, null];
foreach ($dateStandards as $standard) {
try {
$date = DateTime::createFromFormat($standard, $dateModified);
break;
} catch (\Exception $e) {
if ($standard === null) {
throw new Exception\RuntimeException(
'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 lastBuild date
*
* @throws Exception\RuntimeException
* @return DateTime
*/
public function getLastBuildDate()
{
if (array_key_exists('lastBuildDate', $this->data)) {
return $this->data['lastBuildDate'];
}
$date = null;
if ($this->getType() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\Reader::TYPE_RSS_090) {
$lastBuildDate = $this->xpath->evaluate('string(/rss/channel/lastBuildDate)');
if ($lastBuildDate) {
$lastBuildDateParsed = strtotime($lastBuildDate);
if ($lastBuildDateParsed) {
$date = new DateTime('@' . $lastBuildDateParsed);
} else {
$dateStandards = [DateTime::RSS, DateTime::RFC822,
DateTime::RFC2822, null];
foreach ($dateStandards as $standard) {
try {
$date = DateTime::createFromFormat($standard, $lastBuildDateParsed);
break;
} catch (\Exception $e) {
if ($standard === null) {
throw new Exception\RuntimeException(
'Could not load date due to unrecognised'
.' format (should follow RFC 822 or 2822):'
. $e->getMessage(),
0,
$e
);
}
}
}
}
}
}
if (! $date) {
$date = null;
}
$this->data['lastBuildDate'] = $date;
return $this->data['lastBuildDate'];
}
/**
* Get the feed description
*
* @return string|null
*/
public function getDescription()
{
if (array_key_exists('description', $this->data)) {
return $this->data['description'];
}
if ($this->getType() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\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 && $this->getExtension('DublinCore') !== null) {
$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() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\Reader::TYPE_RSS_090) {
$id = $this->xpath->evaluate('string(/rss/channel/guid)');
}
if (! $id && $this->getExtension('DublinCore') !== null) {
$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 image data
*
* @return array|null
*/
public function getImage()
{
if (array_key_exists('image', $this->data)) {
return $this->data['image'];
}
if ($this->getType() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\Reader::TYPE_RSS_090) {
$list = $this->xpath->query('/rss/channel/image');
$prefix = '/rss/channel/image[1]';
} else {
$list = $this->xpath->query('/rdf:RDF/rss:channel/rss:image');
$prefix = '/rdf:RDF/rss:channel/rss:image[1]';
}
if ($list->length > 0) {
$image = [];
$value = $this->xpath->evaluate('string(' . $prefix . '/url)');
if ($value) {
$image['uri'] = $value;
}
$value = $this->xpath->evaluate('string(' . $prefix . '/link)');
if ($value) {
$image['link'] = $value;
}
$value = $this->xpath->evaluate('string(' . $prefix . '/title)');
if ($value) {
$image['title'] = $value;
}
$value = $this->xpath->evaluate('string(' . $prefix . '/height)');
if ($value) {
$image['height'] = $value;
}
$value = $this->xpath->evaluate('string(' . $prefix . '/width)');
if ($value) {
$image['width'] = $value;
}
$value = $this->xpath->evaluate('string(' . $prefix . '/description)');
if ($value) {
$image['description'] = $value;
}
} else {
$image = null;
}
$this->data['image'] = $image;
return $this->data['image'];
}
/**
* 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() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\Reader::TYPE_RSS_090) {
$language = $this->xpath->evaluate('string(/rss/channel/language)');
}
if (! $language && $this->getExtension('DublinCore') !== null) {
$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'];
}
if ($this->getType() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\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 = $this->getExtension('Atom')->getFeedLink();
if ($link === null || empty($link)) {
$link = $this->getOriginalSourceUri();
}
$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() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\Reader::TYPE_RSS_090) {
$generator = $this->xpath->evaluate('string(/rss/channel/generator)');
}
if (! $generator) {
if ($this->getType() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\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 (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'];
}
if ($this->getType() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\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 && $this->getExtension('DublinCore') !== null) {
$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 Reader\Collection\Category
*/
public function getCategories()
{
if (array_key_exists('categories', $this->data)) {
return $this->data['categories'];
}
if ($this->getType() !== Reader\Reader::TYPE_RSS_10 &&
$this->getType() !== Reader\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 Collection\Category;
foreach ($list as $category) {
$categoryCollection[] = [
'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()
{
if ($this->getType() !== Reader\Reader::TYPE_RSS_10 && $this->getType() !== Reader\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 Reader\Reader::TYPE_RSS_10:
$this->xpath->registerNamespace('rdf', Reader\Reader::NAMESPACE_RDF);
$this->xpath->registerNamespace('rss', Reader\Reader::NAMESPACE_RSS_10);
break;
case Reader\Reader::TYPE_RSS_090:
$this->xpath->registerNamespace('rdf', Reader\Reader::NAMESPACE_RDF);
$this->xpath->registerNamespace('rss', Reader\Reader::NAMESPACE_RSS_090);
break;
}
}
}

View File

@@ -0,0 +1,174 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader;
use ArrayObject;
use DOMNodeList;
use Zend\Feed\Uri;
class 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 static([
'rel' => 'alternate',
'type' => $link->getAttribute('type'),
'href' => $this->absolutiseUri(trim($link->getAttribute('href')), $uri),
'title' => $link->getAttribute('title'),
]);
}
}
/**
* Attempt to turn a relative URI into an absolute URI
*
* @param string $link
* @param string $uri OPTIONAL
* @return string|null absolutised link or null if invalid
*/
protected function absolutiseUri($link, $uri = null)
{
$linkUri = Uri::factory($link);
if ($linkUri->isAbsolute()) {
// invalid absolute link can not be recovered
return $linkUri->isValid() ? $link : null;
}
$scheme = 'http';
if ($uri !== null) {
$uri = Uri::factory($uri);
$scheme = $uri->getScheme() ?: $scheme;
}
if ($linkUri->getHost()) {
$link = $this->resolveSchemeRelativeUri($link, $scheme);
} elseif ($uri !== null) {
$link = $this->resolveRelativeUri($link, $scheme, $uri->getHost(), $uri->getPath());
}
if (! Uri::factory($link)->isValid()) {
return null;
}
return $link;
}
/**
* Resolves scheme relative link to absolute
*
* @param string $link
* @param string $scheme
* @return string
*/
private function resolveSchemeRelativeUri($link, $scheme)
{
$link = ltrim($link, '/');
return sprintf('%s://%s', $scheme, $link);
}
/**
* Resolves relative link to absolute
*
* @param string $link
* @param string $scheme
* @param string $host
* @param string $uriPath
* @return string
*/
private function resolveRelativeUri($link, $scheme, $host, $uriPath)
{
if ($link[0] !== '/') {
$link = $uriPath . '/' . $link;
}
return sprintf(
'%s://%s/%s',
$scheme,
$host,
$this->canonicalizePath($link)
);
}
/**
* Canonicalize relative path
*
* @param string $path
* @return string
*/
protected function canonicalizePath($path)
{
$parts = array_filter(explode('/', $path));
$absolutes = [];
foreach ($parts as $part) {
if ('.' == $part) {
continue;
}
if ('..' == $part) {
array_pop($absolutes);
} else {
$absolutes[] = $part;
}
}
return implode('/', $absolutes);
}
/**
* Supports lazy loading of feeds using Reader::import() but
* delegates any other operations to the parent class.
*
* @param string $offset
* @return mixed
*/
public function offsetGet($offset)
{
if ($offset == 'feed' && ! $this->offsetExists('feed')) {
if (! $this->offsetExists('href')) {
return;
}
$feed = Reader::import($this->offsetGet('href'));
$this->offsetSet('feed', $feed);
return $feed;
}
return parent::offsetGet($offset);
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Http;
interface ClientInterface
{
/**
* Make a GET request to a given URI
*
* @param string $uri
* @return ResponseInterface
*/
public function get($uri);
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Http;
interface HeaderAwareClientInterface extends ClientInterface
{
/**
* Allow specifying headers to use when fetching a feed.
*
* Headers MUST be in the format:
*
* <code>
* [
* 'header-name' => [
* 'header',
* 'values'
* ]
* ]
* </code>
*
* @param string $uri
* @param array $headers
* @return HeaderAwareResponseInterface
*/
public function get($uri, array $headers = []);
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Http;
interface HeaderAwareResponseInterface extends ResponseInterface
{
/**
* Retrieve a header (as a single line) from the response.
*
* Header name lookups MUST be case insensitive.
*
* Since the only header values the feed reader consumes are singular
* in nature, this method is expected to return a string, and not
* an array of values.
*
* @param string $name Header name to retrieve.
* @param mixed $default Default value to use if header is not present.
* @return string
*/
public function getHeaderLine($name, $default = null);
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Http;
use Psr\Http\Message\ResponseInterface as Psr7ResponseInterface;
/**
* ResponseInterface wrapper for a PSR-7 response.
*/
class Psr7ResponseDecorator implements HeaderAwareResponseInterface
{
/**
* @var Psr7ResponseInterface
*/
private $decoratedResponse;
/**
* @param Psr7ResponseInterface $response
*/
public function __construct(Psr7ResponseInterface $response)
{
$this->decoratedResponse = $response;
}
/**
* Return the original PSR-7 response being decorated.
*
* @return Psr7ResponseInterface
*/
public function getDecoratedResponse()
{
return $this->decoratedResponse;
}
/**
* {@inheritDoc}
*/
public function getBody()
{
return (string) $this->decoratedResponse->getBody();
}
/**
* {@inheritDoc}
*/
public function getStatusCode()
{
return $this->decoratedResponse->getStatusCode();
}
/**
* {@inheritDoc}
*/
public function getHeaderLine($name, $default = null)
{
if (! $this->decoratedResponse->hasHeader($name)) {
return $default;
}
return $this->decoratedResponse->getHeaderLine($name);
}
}

View File

@@ -0,0 +1,175 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Http;
use Zend\Feed\Reader\Exception;
class Response implements HeaderAwareResponseInterface
{
/**
* @var string
*/
private $body;
/**
* @var array
*/
private $headers;
/**
* @var int
*/
private $statusCode;
/**
* @param int $statusCode
* @param string|object $body
* @param array $headers
* @throws Exception\InvalidArgumentException
*/
public function __construct($statusCode, $body = '', array $headers = [])
{
$this->validateStatusCode($statusCode);
$this->validateBody($body);
$this->validateHeaders($headers);
$this->statusCode = (int) $statusCode;
$this->body = (string) $body;
$this->headers = $this->normalizeHeaders($headers);
}
/**
* {@inheritDoc}
*/
public function getStatusCode()
{
return $this->statusCode;
}
/**
* {@inheritDoc}
*/
public function getBody()
{
return $this->body;
}
/**
* {@inheritDoc}
*/
public function getHeaderLine($name, $default = null)
{
$normalizedName = strtolower($name);
return isset($this->headers[$normalizedName])
? $this->headers[$normalizedName]
: $default;
}
/**
* Validate that we have a status code argument that will work for our context.
*
* @param int $statusCode
* @throws Exception\InvalidArgumentException for arguments not castable
* to integer HTTP status codes.
*/
private function validateStatusCode($statusCode)
{
if (! is_numeric($statusCode)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects a numeric status code; received %s',
__CLASS__,
(is_object($statusCode) ? get_class($statusCode) : gettype($statusCode))
));
}
if (100 > $statusCode || 599 < $statusCode) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an integer status code between 100 and 599 inclusive; received %s',
__CLASS__,
$statusCode
));
}
if (intval($statusCode) != $statusCode) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an integer status code; received %s',
__CLASS__,
$statusCode
));
}
}
/**
* Validate that we have a body argument that will work for our context.
*
* @param mixed $body
* @throws Exception\InvalidArgumentException for arguments not castable
* to strings.
*/
private function validateBody($body)
{
if (is_string($body)) {
return;
}
if (is_object($body) && method_exists($body, '__toString')) {
return;
}
throw new Exception\InvalidArgumentException(sprintf(
'%s expects a string body, or an object that can cast to string; received %s',
__CLASS__,
(is_object($body) ? get_class($body) : gettype($body))
));
}
/**
* Validate header values.
*
* @param array $headers
* @throws Exception\InvalidArgumentException
*/
private function validateHeaders(array $headers)
{
foreach ($headers as $name => $value) {
if (! is_string($name) || is_numeric($name) || empty($name)) {
throw new Exception\InvalidArgumentException(sprintf(
'Header names provided to %s must be non-empty, non-numeric strings; received %s',
__CLASS__,
$name
));
}
if (! is_string($value) && ! is_numeric($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'Individual header values provided to %s must be a string or numeric; received %s for header %s',
__CLASS__,
(is_object($value) ? get_class($value) : gettype($value)),
$name
));
}
}
}
/**
* Normalize header names to lowercase.
*
* @param array $headers
* @return array
*/
private function normalizeHeaders(array $headers)
{
$normalized = [];
foreach ($headers as $name => $value) {
$normalized[strtolower($name)] = $value;
}
return $normalized;
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Http;
interface ResponseInterface
{
/**
* Retrieve the response body
*
* @return string
*/
public function getBody();
/**
* Retrieve the HTTP response status code
*
* @return int
*/
public function getStatusCode();
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader\Http;
use Zend\Feed\Reader\Exception;
use Zend\Http\Client as ZendHttpClient;
use Zend\Http\Headers;
class ZendHttpClientDecorator implements HeaderAwareClientInterface
{
/**
* @var ZendHttpClient
*/
private $client;
/**
* @param ZendHttpClient $client
*/
public function __construct(ZendHttpClient $client)
{
$this->client = $client;
}
/**
* @return ZendHttpClient
*/
public function getDecoratedClient()
{
return $this->client;
}
/**
* {@inheritDoc}
*/
public function get($uri, array $headers = [])
{
$this->client->resetParameters();
$this->client->setMethod('GET');
$this->client->setHeaders(new Headers());
$this->client->setUri($uri);
if (! empty($headers)) {
$this->injectHeaders($headers);
}
$response = $this->client->send();
return new Response(
$response->getStatusCode(),
$response->getBody(),
$this->prepareResponseHeaders($response->getHeaders())
);
}
/**
* Inject header values into the client.
*
* @param array $headerValues
*/
private function injectHeaders(array $headerValues)
{
$headers = $this->client->getRequest()->getHeaders();
foreach ($headerValues as $name => $values) {
if (! is_string($name) || is_numeric($name) || empty($name)) {
throw new Exception\InvalidArgumentException(sprintf(
'Header names provided to %s::get must be non-empty, non-numeric strings; received %s',
__CLASS__,
$name
));
}
if (! is_array($values)) {
throw new Exception\InvalidArgumentException(sprintf(
'Header values provided to %s::get must be arrays of values; received %s',
__CLASS__,
(is_object($values) ? get_class($values) : gettype($values))
));
}
foreach ($values as $value) {
if (! is_string($value) && ! is_numeric($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'Individual header values provided to %s::get must be strings or numbers; '
. 'received %s for header %s',
__CLASS__,
(is_object($value) ? get_class($value) : gettype($value)),
$name
));
}
$headers->addHeaderLine($name, $value);
}
}
}
/**
* Normalize headers to use with HeaderAwareResponseInterface.
*
* Ensures multi-value headers are represented as a single string, via
* comma concatenation.
*
* @param Headers $headers
* @return array
*/
private function prepareResponseHeaders(Headers $headers)
{
$normalized = [];
foreach ($headers->toArray() as $name => $value) {
$normalized[$name] = is_array($value) ? implode(', ', $value) : $value;
}
return $normalized;
}
}

View File

@@ -0,0 +1,736 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader;
use DOMDocument;
use DOMXPath;
use Zend\Cache\Storage\StorageInterface as CacheStorage;
use Zend\Feed\Reader\Exception\InvalidHttpClientException;
use Zend\Http as ZendHttp;
use Zend\Stdlib\ErrorHandler;
/**
*/
class Reader implements ReaderImportInterface
{
/**
* Namespace constants
*/
const NAMESPACE_ATOM_03 = 'http://purl.org/atom/ns#';
const NAMESPACE_ATOM_10 = 'http://www.w3.org/2005/Atom';
const NAMESPACE_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
const NAMESPACE_RSS_090 = 'http://my.netscape.com/rdf/simple/0.9/';
const NAMESPACE_RSS_10 = 'http://purl.org/rss/1.0/';
/**
* Feed type constants
*/
const TYPE_ANY = 'any';
const TYPE_ATOM_03 = 'atom-03';
const TYPE_ATOM_10 = 'atom-10';
const TYPE_ATOM_10_ENTRY = 'atom-10-entry';
const TYPE_ATOM_ANY = 'atom';
const TYPE_RSS_090 = 'rss-090';
const TYPE_RSS_091 = 'rss-091';
const TYPE_RSS_091_NETSCAPE = 'rss-091n';
const TYPE_RSS_091_USERLAND = 'rss-091u';
const TYPE_RSS_092 = 'rss-092';
const TYPE_RSS_093 = 'rss-093';
const TYPE_RSS_094 = 'rss-094';
const TYPE_RSS_10 = 'rss-10';
const TYPE_RSS_20 = 'rss-20';
const TYPE_RSS_ANY = 'rss';
/**
* Cache instance
*
* @var CacheStorage
*/
protected static $cache = null;
/**
* HTTP client object to use for retrieving feeds
*
* @var Http\ClientInterface
*/
protected static $httpClient = null;
/**
* Override HTTP PUT and DELETE request methods?
*
* @var bool
*/
protected static $httpMethodOverride = false;
protected static $httpConditionalGet = false;
protected static $extensionManager = null;
protected static $extensions = [
'feed' => [
'DublinCore\Feed',
'Atom\Feed'
],
'entry' => [
'Content\Entry',
'DublinCore\Entry',
'Atom\Entry'
],
'core' => [
'DublinCore\Feed',
'Atom\Feed',
'Content\Entry',
'DublinCore\Entry',
'Atom\Entry'
]
];
/**
* Get the Feed cache
*
* @return CacheStorage
*/
public static function getCache()
{
return static::$cache;
}
/**
* Set the feed cache
*
* @param CacheStorage $cache
* @return void
*/
public static function setCache(CacheStorage $cache)
{
static::$cache = $cache;
}
/**
* Set the HTTP client instance
*
* Sets the HTTP client object to use for retrieving the feeds.
*
* @param ZendHttp\Client | Http\ClientInterface $httpClient
* @return void
*/
public static function setHttpClient($httpClient)
{
if ($httpClient instanceof ZendHttp\Client) {
$httpClient = new Http\ZendHttpClientDecorator($httpClient);
}
if (! $httpClient instanceof Http\ClientInterface) {
throw new InvalidHttpClientException();
}
static::$httpClient = $httpClient;
}
/**
* Gets the HTTP client object. If none is set, a new ZendHttp\Client will be used.
*
* @return Http\ClientInterface
*/
public static function getHttpClient()
{
if (! static::$httpClient) {
static::$httpClient = new Http\ZendHttpClientDecorator(new ZendHttp\Client());
}
return static::$httpClient;
}
/**
* Toggle using POST instead of PUT and DELETE HTTP methods
*
* Some feed implementations do not accept PUT and DELETE HTTP
* methods, or they can't be used because of proxies or other
* measures. This allows turning on using POST where PUT and
* DELETE would normally be used; in addition, an
* X-Method-Override header will be sent with a value of PUT or
* DELETE as appropriate.
*
* @param bool $override Whether to override PUT and DELETE.
* @return void
*/
public static function setHttpMethodOverride($override = true)
{
static::$httpMethodOverride = $override;
}
/**
* Get the HTTP override state
*
* @return bool
*/
public static function getHttpMethodOverride()
{
return static::$httpMethodOverride;
}
/**
* Set the flag indicating whether or not to use HTTP conditional GET
*
* @param bool $bool
* @return void
*/
public static function useHttpConditionalGet($bool = true)
{
static::$httpConditionalGet = $bool;
}
/**
* Import a feed by providing a URI
*
* @param string $uri The URI to the feed
* @param string $etag OPTIONAL Last received ETag for this resource
* @param string $lastModified OPTIONAL Last-Modified value for this resource
* @return Feed\FeedInterface
* @throws Exception\RuntimeException
*/
public static function import($uri, $etag = null, $lastModified = null)
{
$cache = self::getCache();
$client = self::getHttpClient();
$cacheId = 'Zend_Feed_Reader_' . md5($uri);
if (static::$httpConditionalGet && $cache) {
$headers = [];
$data = $cache->getItem($cacheId);
if ($data && $client instanceof Http\HeaderAwareClientInterface) {
// Only check for ETag and last modified values in the cache
// if we have a client capable of emitting headers in the first place.
if ($etag === null) {
$etag = $cache->getItem($cacheId . '_etag');
}
if ($lastModified === null) {
$lastModified = $cache->getItem($cacheId . '_lastmodified');
}
if ($etag) {
$headers['If-None-Match'] = [$etag];
}
if ($lastModified) {
$headers['If-Modified-Since'] = [$lastModified];
}
}
$response = $client->get($uri, $headers);
if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 304) {
throw new Exception\RuntimeException(
'Feed failed to load, got response code ' . $response->getStatusCode()
);
}
if ($response->getStatusCode() == 304) {
$responseXml = $data;
} else {
$responseXml = $response->getBody();
$cache->setItem($cacheId, $responseXml);
if ($response instanceof Http\HeaderAwareResponseInterface) {
if ($response->getHeaderLine('ETag', false)) {
$cache->setItem($cacheId . '_etag', $response->getHeaderLine('ETag'));
}
if ($response->getHeaderLine('Last-Modified', false)) {
$cache->setItem($cacheId . '_lastmodified', $response->getHeaderLine('Last-Modified'));
}
}
}
return static::importString($responseXml);
} elseif ($cache) {
$data = $cache->getItem($cacheId);
if ($data) {
return static::importString($data);
}
$response = $client->get($uri);
if ((int) $response->getStatusCode() !== 200) {
throw new Exception\RuntimeException(
'Feed failed to load, got response code ' . $response->getStatusCode()
);
}
$responseXml = $response->getBody();
$cache->setItem($cacheId, $responseXml);
return static::importString($responseXml);
} else {
$response = $client->get($uri);
if ((int) $response->getStatusCode() !== 200) {
throw new Exception\RuntimeException(
'Feed failed to load, got response code ' . $response->getStatusCode()
);
}
$reader = static::importString($response->getBody());
$reader->setOriginalSourceUri($uri);
return $reader;
}
}
/**
* Import a feed from a remote URI
*
* Performs similarly to import(), except it uses the HTTP client passed to
* the method, and does not take into account cached data.
*
* Primary purpose is to make it possible to use the Reader with alternate
* HTTP client implementations.
*
* @param string $uri
* @param Http\ClientInterface $client
* @return Feed\FeedInterface
* @throws Exception\RuntimeException if response is not an Http\ResponseInterface
*/
public static function importRemoteFeed($uri, Http\ClientInterface $client)
{
$response = $client->get($uri);
if (! $response instanceof Http\ResponseInterface) {
throw new Exception\RuntimeException(sprintf(
'Did not receive a %s\Http\ResponseInterface from the provided HTTP client; received "%s"',
__NAMESPACE__,
(is_object($response) ? get_class($response) : gettype($response))
));
}
if ((int) $response->getStatusCode() !== 200) {
throw new Exception\RuntimeException(
'Feed failed to load, got response code ' . $response->getStatusCode()
);
}
$reader = static::importString($response->getBody());
$reader->setOriginalSourceUri($uri);
return $reader;
}
/**
* Import a feed from a string
*
* @param string $string
* @return Feed\FeedInterface
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
*/
public static function importString($string)
{
$trimmed = trim($string);
if (! is_string($string) || empty($trimmed)) {
throw new Exception\InvalidArgumentException('Only non empty strings are allowed as input');
}
$libxmlErrflag = libxml_use_internal_errors(true);
$oldValue = libxml_disable_entity_loader(true);
$dom = new DOMDocument;
$status = $dom->loadXML(trim($string));
foreach ($dom->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new Exception\InvalidArgumentException(
'Invalid XML: Detected use of illegal DOCTYPE'
);
}
}
libxml_disable_entity_loader($oldValue);
libxml_use_internal_errors($libxmlErrflag);
if (! $status) {
// Build error message
$error = libxml_get_last_error();
if ($error && $error->message) {
$error->message = trim($error->message);
$errormsg = "DOMDocument cannot parse XML: {$error->message}";
} else {
$errormsg = "DOMDocument cannot parse XML: Please check the XML document's validity";
}
throw new Exception\RuntimeException($errormsg);
}
$type = static::detectType($dom);
static::registerCoreExtensions();
if (0 === strpos($type, 'rss')) {
$reader = new Feed\Rss($dom, $type);
} elseif (8 === strpos($type, 'entry')) {
$reader = new Entry\Atom($dom->documentElement, 0, self::TYPE_ATOM_10);
} elseif (0 === strpos($type, 'atom')) {
$reader = new Feed\Atom($dom, $type);
} else {
throw new Exception\RuntimeException('The URI used does not point to a '
. 'valid Atom, RSS or RDF feed that Zend\Feed\Reader can parse.');
}
return $reader;
}
/**
* Imports a feed from a file located at $filename.
*
* @param string $filename
* @throws Exception\RuntimeException
* @return Feed\FeedInterface
*/
public static function importFile($filename)
{
ErrorHandler::start();
$feed = file_get_contents($filename);
$err = ErrorHandler::stop();
if ($feed === false) {
throw new Exception\RuntimeException("File '{$filename}' could not be loaded", 0, $err);
}
return static::importString($feed);
}
/**
* Find feed links
*
* @param $uri
* @return FeedSet
* @throws Exception\RuntimeException
*/
public static function findFeedLinks($uri)
{
$client = static::getHttpClient();
$response = $client->get($uri);
if ($response->getStatusCode() !== 200) {
throw new Exception\RuntimeException(
"Failed to access $uri, got response code " . $response->getStatusCode()
);
}
$responseHtml = $response->getBody();
$libxmlErrflag = libxml_use_internal_errors(true);
$oldValue = libxml_disable_entity_loader(true);
$dom = new DOMDocument;
$status = $dom->loadHTML(trim($responseHtml));
libxml_disable_entity_loader($oldValue);
libxml_use_internal_errors($libxmlErrflag);
if (! $status) {
// Build error message
$error = libxml_get_last_error();
if ($error && $error->message) {
$error->message = trim($error->message);
$errormsg = "DOMDocument cannot parse HTML: {$error->message}";
} else {
$errormsg = "DOMDocument cannot parse HTML: Please check the XML document's validity";
}
throw new Exception\RuntimeException($errormsg);
}
$feedSet = new FeedSet;
$links = $dom->getElementsByTagName('link');
$feedSet->addLinks($links, $uri);
return $feedSet;
}
/**
* Detect the feed type of the provided feed
*
* @param Feed\AbstractFeed|DOMDocument|string $feed
* @param bool $specOnly
* @return string
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
*/
public static function detectType($feed, $specOnly = false)
{
if ($feed instanceof Feed\AbstractFeed) {
$dom = $feed->getDomDocument();
} elseif ($feed instanceof DOMDocument) {
$dom = $feed;
} elseif (is_string($feed) && ! empty($feed)) {
ErrorHandler::start(E_NOTICE | E_WARNING);
ini_set('track_errors', 1);
$oldValue = libxml_disable_entity_loader(true);
$dom = new DOMDocument;
$status = $dom->loadXML($feed);
foreach ($dom->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new Exception\InvalidArgumentException(
'Invalid XML: Detected use of illegal DOCTYPE'
);
}
}
libxml_disable_entity_loader($oldValue);
ini_restore('track_errors');
ErrorHandler::stop();
if (! $status) {
if (! isset($phpErrormsg)) {
if (function_exists('xdebug_is_enabled')) {
$phpErrormsg = '(error message not available, when XDebug is running)';
} else {
$phpErrormsg = '(error message not available)';
}
}
throw new Exception\RuntimeException("DOMDocument cannot parse XML: $phpErrormsg");
}
} else {
throw new Exception\InvalidArgumentException('Invalid object/scalar provided: must'
. ' be of type Zend\Feed\Reader\Feed, DomDocument or string');
}
$xpath = new DOMXPath($dom);
if ($xpath->query('/rss')->length) {
$type = self::TYPE_RSS_ANY;
$version = $xpath->evaluate('string(/rss/@version)');
if (strlen($version) > 0) {
switch ($version) {
case '2.0':
$type = self::TYPE_RSS_20;
break;
case '0.94':
$type = self::TYPE_RSS_094;
break;
case '0.93':
$type = self::TYPE_RSS_093;
break;
case '0.92':
$type = self::TYPE_RSS_092;
break;
case '0.91':
$type = self::TYPE_RSS_091;
break;
}
}
return $type;
}
$xpath->registerNamespace('rdf', self::NAMESPACE_RDF);
if ($xpath->query('/rdf:RDF')->length) {
$xpath->registerNamespace('rss', self::NAMESPACE_RSS_10);
if ($xpath->query('/rdf:RDF/rss:channel')->length
|| $xpath->query('/rdf:RDF/rss:image')->length
|| $xpath->query('/rdf:RDF/rss:item')->length
|| $xpath->query('/rdf:RDF/rss:textinput')->length
) {
return self::TYPE_RSS_10;
}
$xpath->registerNamespace('rss', self::NAMESPACE_RSS_090);
if ($xpath->query('/rdf:RDF/rss:channel')->length
|| $xpath->query('/rdf:RDF/rss:image')->length
|| $xpath->query('/rdf:RDF/rss:item')->length
|| $xpath->query('/rdf:RDF/rss:textinput')->length
) {
return self::TYPE_RSS_090;
}
}
$xpath->registerNamespace('atom', self::NAMESPACE_ATOM_10);
if ($xpath->query('//atom:feed')->length) {
return self::TYPE_ATOM_10;
}
if ($xpath->query('//atom:entry')->length) {
if ($specOnly == true) {
return self::TYPE_ATOM_10;
} else {
return self::TYPE_ATOM_10_ENTRY;
}
}
$xpath->registerNamespace('atom', self::NAMESPACE_ATOM_03);
if ($xpath->query('//atom:feed')->length) {
return self::TYPE_ATOM_03;
}
return self::TYPE_ANY;
}
/**
* Set plugin manager for use with Extensions
*
* @param ExtensionManagerInterface $extensionManager
*/
public static function setExtensionManager(ExtensionManagerInterface $extensionManager)
{
static::$extensionManager = $extensionManager;
}
/**
* Get plugin manager for use with Extensions
*
* @return ExtensionManagerInterface
*/
public static function getExtensionManager()
{
if (! isset(static::$extensionManager)) {
static::setExtensionManager(new StandaloneExtensionManager());
}
return static::$extensionManager;
}
/**
* Register an Extension by name
*
* @param string $name
* @return void
* @throws Exception\RuntimeException if unable to resolve Extension class
*/
public static function registerExtension($name)
{
if (! static::hasExtension($name)) {
throw new Exception\RuntimeException(sprintf(
'Could not load extension "%s" using Plugin Loader.'
. ' Check prefix paths are configured and extension exists.',
$name
));
}
// Return early if already registered.
if (static::isRegistered($name)) {
return;
}
$manager = static::getExtensionManager();
$feedName = $name . '\Feed';
if ($manager->has($feedName)) {
static::$extensions['feed'][] = $feedName;
}
$entryName = $name . '\Entry';
if ($manager->has($entryName)) {
static::$extensions['entry'][] = $entryName;
}
}
/**
* Is a given named Extension registered?
*
* @param string $extensionName
* @return bool
*/
public static function isRegistered($extensionName)
{
$feedName = $extensionName . '\Feed';
$entryName = $extensionName . '\Entry';
if (in_array($feedName, static::$extensions['feed'])
|| in_array($entryName, static::$extensions['entry'])
) {
return true;
}
return false;
}
/**
* Get a list of extensions
*
* @return array
*/
public static function getExtensions()
{
return static::$extensions;
}
/**
* Reset class state to defaults
*
* @return void
*/
public static function reset()
{
static::$cache = null;
static::$httpClient = null;
static::$httpMethodOverride = false;
static::$httpConditionalGet = false;
static::$extensionManager = null;
static::$extensions = [
'feed' => [
'DublinCore\Feed',
'Atom\Feed'
],
'entry' => [
'Content\Entry',
'DublinCore\Entry',
'Atom\Entry'
],
'core' => [
'DublinCore\Feed',
'Atom\Feed',
'Content\Entry',
'DublinCore\Entry',
'Atom\Entry'
]
];
}
/**
* Register core (default) extensions
*
* @return void
*/
protected static function registerCoreExtensions()
{
static::registerExtension('DublinCore');
static::registerExtension('Content');
static::registerExtension('Atom');
static::registerExtension('Slash');
static::registerExtension('WellFormedWeb');
static::registerExtension('Thread');
static::registerExtension('Podcast');
// Added in 2.10.0; check for it conditionally
static::hasExtension('GooglePlayPodcast')
? static::registerExtension('GooglePlayPodcast')
: trigger_error(
sprintf(
'Please update your %1$s\ExtensionManagerInterface implementation to add entries for'
. ' %1$s\Extension\GooglePlayPodcast\Entry and %1$s\Extension\GooglePlayPodcast\Feed.',
__NAMESPACE__
),
\E_USER_NOTICE
);
}
/**
* Utility method to apply array_unique operation to a multidimensional
* array.
*
* @param array
* @return array
*/
public static function arrayUnique(array $array)
{
foreach ($array as &$value) {
$value = serialize($value);
}
$array = array_unique($array);
foreach ($array as &$value) {
$value = unserialize($value);
}
return $array;
}
/**
* Does the extension manager have the named extension?
*
* This method exists to allow us to test if an extension is present in the
* extension manager. It may be used by registerExtension() to determine if
* the extension has items present in the manager, or by
* registerCoreExtension() to determine if the core extension has entries
* in the extension manager. In the latter case, this can be useful when
* adding new extensions in a minor release, as custom extension manager
* implementations may not yet have an entry for the extension, which would
* then otherwise cause registerExtension() to fail.
*
* @param string $name
* @return bool
*/
protected static function hasExtension($name)
{
$feedName = $name . '\Feed';
$entryName = $name . '\Entry';
$manager = static::getExtensionManager();
return $manager->has($feedName) || $manager->has($entryName);
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader;
interface ReaderImportInterface
{
/**
* Import a feed by providing a URI
*
* @param string $uri The URI to the feed
* @param string $etag OPTIONAL Last received ETag for this resource
* @param string $lastModified OPTIONAL Last-Modified value for this resource
* @return Feed\FeedInterface
* @throws Exception\RuntimeException
*/
public static function import($uri, $etag = null, $lastModified = null);
/**
* Import a feed from a remote URI
*
* Performs similarly to import(), except it uses the HTTP client passed to
* the method, and does not take into account cached data.
*
* Primary purpose is to make it possible to use the Reader with alternate
* HTTP client implementations.
*
* @param string $uri
* @param Http\ClientInterface $client
* @return self
* @throws Exception\RuntimeException if response is not an Http\ResponseInterface
*/
public static function importRemoteFeed($uri, Http\ClientInterface $client);
/**
* Import a feed from a string
*
* @param string $string
* @return Feed\FeedInterface
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
*/
public static function importString($string);
/**
* Imports a feed from a file located at $filename.
*
* @param string $filename
* @throws Exception\RuntimeException
* @return Feed\FeedInterface
*/
public static function importFile($filename);
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Feed\Reader;
use Zend\Feed\Reader\Exception\InvalidArgumentException;
class StandaloneExtensionManager implements ExtensionManagerInterface
{
private $extensions = [
'Atom\Entry' => Extension\Atom\Entry::class,
'Atom\Feed' => Extension\Atom\Feed::class,
'Content\Entry' => Extension\Content\Entry::class,
'CreativeCommons\Entry' => Extension\CreativeCommons\Entry::class,
'CreativeCommons\Feed' => Extension\CreativeCommons\Feed::class,
'DublinCore\Entry' => Extension\DublinCore\Entry::class,
'DublinCore\Feed' => Extension\DublinCore\Feed::class,
'GooglePlayPodcast\Entry' => Extension\GooglePlayPodcast\Entry::class,
'GooglePlayPodcast\Feed' => Extension\GooglePlayPodcast\Feed::class,
'Podcast\Entry' => Extension\Podcast\Entry::class,
'Podcast\Feed' => Extension\Podcast\Feed::class,
'Slash\Entry' => Extension\Slash\Entry::class,
'Syndication\Feed' => Extension\Syndication\Feed::class,
'Thread\Entry' => Extension\Thread\Entry::class,
'WellFormedWeb\Entry' => Extension\WellFormedWeb\Entry::class,
];
/**
* Do we have the extension?
*
* @param string $extension
* @return bool
*/
public function has($extension)
{
return array_key_exists($extension, $this->extensions);
}
/**
* Retrieve the extension
*
* @param string $extension
* @return Extension\AbstractEntry|Extension\AbstractFeed
*/
public function get($extension)
{
$class = $this->extensions[$extension];
return new $class();
}
/**
* Add an extension.
*
* @param string $name
* @param string $class
*/
public function add($name, $class)
{
if (is_string($class)
&& (
is_a($class, Extension\AbstractEntry::class, true)
|| is_a($class, Extension\AbstractFeed::class, true)
)
) {
$this->extensions[$name] = $class;
return;
}
throw new InvalidArgumentException(sprintf(
'Plugin of type %s is invalid; must implement %2$s\Extension\AbstractFeed '
. 'or %2$s\Extension\AbstractEntry',
$class,
__NAMESPACE__
));
}
/**
* Remove an extension.
*
* @param string $name
*/
public function remove($name)
{
unset($this->extensions[$name]);
}
}