composer update
This commit is contained in:
parent
9ac51e0523
commit
623395064f
279 changed files with 4458 additions and 16328 deletions
|
@ -9,6 +9,7 @@ use PicoFeed\Client\Url;
|
|||
/**
|
||||
* Atom parser.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Atom extends Parser
|
||||
|
@ -154,30 +155,33 @@ class Atom extends Parser
|
|||
}
|
||||
|
||||
/**
|
||||
* Find the item date.
|
||||
* Find the item published date.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
public function findItemDate(SimpleXMLElement $entry, Item $item, Feed $feed)
|
||||
public function findItemPublishedDate(SimpleXMLElement $entry, Item $item, Feed $feed)
|
||||
{
|
||||
$published = XmlParser::getXPathResult($entry, 'atom:published', $this->namespaces)
|
||||
?: XmlParser::getXPathResult($entry, 'published');
|
||||
$date = XmlParser::getXPathResult($entry, 'atom:published', $this->namespaces)
|
||||
?: XmlParser::getXPathResult($entry, 'published');
|
||||
|
||||
$updated = XmlParser::getXPathResult($entry, 'atom:updated', $this->namespaces)
|
||||
?: XmlParser::getXPathResult($entry, 'updated');
|
||||
$item->setPublishedDate(!empty($date) ? $this->getDateParser()->getDateTime((string) current($date)) : null);
|
||||
}
|
||||
|
||||
$published = !empty($published) ? $this->getDateParser()->getDateTime((string) current($published)) : null;
|
||||
$updated = !empty($updated) ? $this->getDateParser()->getDateTime((string) current($updated)) : null;
|
||||
/**
|
||||
* Find the item updated date.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
public function findItemUpdatedDate(SimpleXMLElement $entry, Item $item, Feed $feed)
|
||||
{
|
||||
$date = XmlParser::getXPathResult($entry, 'atom:updated', $this->namespaces)
|
||||
?: XmlParser::getXPathResult($entry, 'updated');
|
||||
|
||||
if ($published === null && $updated === null) {
|
||||
$item->setDate($feed->getDate()); // We use the feed date if there is no date for the item
|
||||
} elseif ($published !== null && $updated !== null) {
|
||||
$item->setDate(max($published, $updated)); // We use the most recent date between published and updated
|
||||
} else {
|
||||
$item->setDate($updated ?: $published);
|
||||
}
|
||||
$item->setUpdatedDate(!empty($date) ? $this->getDateParser()->getDateTime((string) current($date)) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,7 @@ use PicoFeed\Base;
|
|||
/**
|
||||
* Date Parser.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class DateParser extends Base
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace PicoFeed\Parser;
|
|||
/**
|
||||
* Feed.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Feed
|
||||
|
@ -12,7 +13,7 @@ class Feed
|
|||
/**
|
||||
* Feed items.
|
||||
*
|
||||
* @var array
|
||||
* @var Item[]
|
||||
*/
|
||||
public $items = array();
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace PicoFeed\Parser;
|
|||
/**
|
||||
* Feed Item.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Item
|
||||
|
@ -60,6 +61,20 @@ class Item
|
|||
*/
|
||||
public $date = null;
|
||||
|
||||
/**
|
||||
* Item published date.
|
||||
*
|
||||
* @var \DateTime
|
||||
*/
|
||||
public $publishedDate = null;
|
||||
|
||||
/**
|
||||
* Item updated date.
|
||||
*
|
||||
* @var \DateTime
|
||||
*/
|
||||
public $updatedDate = null;
|
||||
|
||||
/**
|
||||
* Item content.
|
||||
*
|
||||
|
@ -151,7 +166,12 @@ class Item
|
|||
$output .= 'Item::'.$property.' = '.$this->$property.PHP_EOL;
|
||||
}
|
||||
|
||||
$publishedDate = $this->publishedDate != null ? $this->publishedDate->format(DATE_RFC822) : null;
|
||||
$updatedDate = $this->updatedDate != null ? $this->updatedDate->format(DATE_RFC822) : null;
|
||||
|
||||
$output .= 'Item::date = '.$this->date->format(DATE_RFC822).PHP_EOL;
|
||||
$output .= 'Item::publishedDate = '.$publishedDate.PHP_EOL;
|
||||
$output .= 'Item::updatedDate = '.$updatedDate.PHP_EOL;
|
||||
$output .= 'Item::isRTL() = '.($this->isRTL() ? 'true' : 'false').PHP_EOL;
|
||||
$output .= 'Item::content = '.strlen($this->content).' bytes'.PHP_EOL;
|
||||
|
||||
|
@ -212,6 +232,26 @@ class Item
|
|||
return $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get published date.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getPublishedDate()
|
||||
{
|
||||
return $this->publishedDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get updated date.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getUpdatedDate()
|
||||
{
|
||||
return $this->updatedDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content.
|
||||
*
|
||||
|
@ -333,6 +373,30 @@ class Item
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set item published date.
|
||||
*
|
||||
* @param \DateTime $publishedDate
|
||||
* @return Item
|
||||
*/
|
||||
public function setPublishedDate($publishedDate)
|
||||
{
|
||||
$this->publishedDate = $publishedDate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set item updated date.
|
||||
*
|
||||
* @param \DateTime $updatedDate
|
||||
* @return Item
|
||||
*/
|
||||
public function setUpdatedDate($updatedDate)
|
||||
{
|
||||
$this->updatedDate = $updatedDate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set enclosure url.
|
||||
*
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace PicoFeed\Parser;
|
|||
/**
|
||||
* MalformedXmlException Exception.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class MalformedXmlException extends ParserException
|
||||
|
|
|
@ -15,9 +15,10 @@ use PicoFeed\Logging\Logger;
|
|||
/**
|
||||
* Base parser class.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
abstract class Parser
|
||||
abstract class Parser implements ParserInterface
|
||||
{
|
||||
/**
|
||||
* Config object.
|
||||
|
@ -211,6 +212,32 @@ abstract class Parser
|
|||
$item->url = Url::resolve($item->getUrl(), $feed->getSiteUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the item date.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
public function findItemDate(SimpleXMLElement $entry, Item $item, Feed $feed)
|
||||
{
|
||||
$this->findItemPublishedDate($entry, $item, $feed);
|
||||
$this->findItemUpdatedDate($entry, $item, $feed);
|
||||
|
||||
if ($item->getPublishedDate() === null) {
|
||||
// Use the updated date if available, otherwise use the feed date
|
||||
$item->setPublishedDate($item->getUpdatedDate() ?: $feed->getDate());
|
||||
}
|
||||
|
||||
if ($item->getUpdatedDate() === null) {
|
||||
// Use the published date as fallback
|
||||
$item->setUpdatedDate($item->getPublishedDate());
|
||||
}
|
||||
|
||||
// Use the most recent of published and updated dates
|
||||
$item->setDate(max($item->getPublishedDate(), $item->getUpdatedDate()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Item Post Processor instance
|
||||
*
|
||||
|
@ -371,153 +398,5 @@ abstract class Parser
|
|||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the feed url.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findFeedUrl(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the site url.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findSiteUrl(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed title.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findFeedTitle(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed description.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findFeedDescription(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed language.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findFeedLanguage(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed id.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findFeedId(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed date.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findFeedDate(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed logo url.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findFeedLogo(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed icon.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findFeedIcon(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Get the path to the items XML tree.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
abstract public function getItemsTree(SimpleXMLElement $xml);
|
||||
|
||||
/**
|
||||
* Find the item author.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param \PicoFeed\Parser\Item $item Item object
|
||||
*/
|
||||
abstract public function findItemAuthor(SimpleXMLElement $xml, SimpleXMLElement $entry, Item $item);
|
||||
|
||||
/**
|
||||
* Find the item URL.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param \PicoFeed\Parser\Item $item Item object
|
||||
*/
|
||||
abstract public function findItemUrl(SimpleXMLElement $entry, Item $item);
|
||||
|
||||
/**
|
||||
* Find the item title.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param \PicoFeed\Parser\Item $item Item object
|
||||
*/
|
||||
abstract public function findItemTitle(SimpleXMLElement $entry, Item $item);
|
||||
|
||||
/**
|
||||
* Genereate the item id.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param \PicoFeed\Parser\Item $item Item object
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findItemId(SimpleXMLElement $entry, Item $item, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the item date.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findItemDate(SimpleXMLElement $entry, Item $item, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the item content.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param \PicoFeed\Parser\Item $item Item object
|
||||
*/
|
||||
abstract public function findItemContent(SimpleXMLElement $entry, Item $item);
|
||||
|
||||
/**
|
||||
* Find the item enclosure.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param \PicoFeed\Parser\Item $item Item object
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findItemEnclosure(SimpleXMLElement $entry, Item $item, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the item language.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param \PicoFeed\Parser\Item $item Item object
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
abstract public function findItemLanguage(SimpleXMLElement $entry, Item $item, Feed $feed);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use PicoFeed\PicoFeedException;
|
|||
/**
|
||||
* ParserException Exception.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
abstract class ParserException extends PicoFeedException
|
||||
|
|
173
vendor/fguillot/picofeed/lib/PicoFeed/Parser/ParserInterface.php
vendored
Normal file
173
vendor/fguillot/picofeed/lib/PicoFeed/Parser/ParserInterface.php
vendored
Normal file
|
@ -0,0 +1,173 @@
|
|||
<?php
|
||||
|
||||
namespace PicoFeed\Parser;
|
||||
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Interface ParserInterface
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
interface ParserInterface
|
||||
{
|
||||
/**
|
||||
* Find the feed url.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findFeedUrl(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the site url.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findSiteUrl(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed title.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findFeedTitle(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed description.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findFeedDescription(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed language.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findFeedLanguage(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed id.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findFeedId(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed date.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findFeedDate(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed logo url.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findFeedLogo(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the feed icon.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findFeedIcon(SimpleXMLElement $xml, Feed $feed);
|
||||
|
||||
/**
|
||||
* Get the path to the items XML tree.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed xml
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function getItemsTree(SimpleXMLElement $xml);
|
||||
|
||||
/**
|
||||
* Find the item author.
|
||||
*
|
||||
* @param SimpleXMLElement $xml Feed
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
*/
|
||||
public function findItemAuthor(SimpleXMLElement $xml, SimpleXMLElement $entry, Item $item);
|
||||
|
||||
/**
|
||||
* Find the item URL.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
*/
|
||||
public function findItemUrl(SimpleXMLElement $entry, Item $item);
|
||||
|
||||
/**
|
||||
* Find the item title.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
*/
|
||||
public function findItemTitle(SimpleXMLElement $entry, Item $item);
|
||||
|
||||
/**
|
||||
* Genereate the item id.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findItemId(SimpleXMLElement $entry, Item $item, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the item published date.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findItemPublishedDate(SimpleXMLElement $entry, Item $item, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the item updated date.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findItemUpdatedDate(SimpleXMLElement $entry, Item $item, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the item content.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
*/
|
||||
public function findItemContent(SimpleXMLElement $entry, Item $item);
|
||||
|
||||
/**
|
||||
* Find the item enclosure.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findItemEnclosure(SimpleXMLElement $entry, Item $item, Feed $feed);
|
||||
|
||||
/**
|
||||
* Find the item language.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param Feed $feed Feed object
|
||||
*/
|
||||
public function findItemLanguage(SimpleXMLElement $entry, Item $item, Feed $feed);
|
||||
}
|
|
@ -8,6 +8,7 @@ use PicoFeed\Filter\Filter;
|
|||
/**
|
||||
* RSS 1.0 parser.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Rss10 extends Parser
|
||||
|
@ -157,17 +158,32 @@ class Rss10 extends Parser
|
|||
}
|
||||
|
||||
/**
|
||||
* Find the item date.
|
||||
* Find the item published date.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
public function findItemDate(SimpleXMLElement $entry, Item $item, Feed $feed)
|
||||
public function findItemPublishedDate(SimpleXMLElement $entry, Item $item, Feed $feed)
|
||||
{
|
||||
$date = XmlParser::getXPathResult($entry, 'dc:date', $this->namespaces);
|
||||
|
||||
$item->setDate(empty($date) ? $feed->getDate() : $this->getDateParser()->getDateTime(XmlParser::getValue($date)));
|
||||
$item->setPublishedDate(!empty($date) ? $this->getDateParser()->getDateTime(XmlParser::getValue($date)) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the item updated date.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
public function findItemUpdatedDate(SimpleXMLElement $entry, Item $item, Feed $feed)
|
||||
{
|
||||
if ($item->publishedDate === null) {
|
||||
$this->findItemPublishedDate($entry, $item, $feed);
|
||||
}
|
||||
$item->setUpdatedDate($item->getPublishedDate()); // No updated date in RSS 1.0 specifications
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,7 @@ use PicoFeed\Client\Url;
|
|||
/**
|
||||
* RSS 2.0 Parser.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Rss20 extends Parser
|
||||
|
@ -152,17 +153,32 @@ class Rss20 extends Parser
|
|||
}
|
||||
|
||||
/**
|
||||
* Find the item date.
|
||||
* Find the item published date.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
public function findItemDate(SimpleXMLElement $entry, Item $item, Feed $feed)
|
||||
public function findItemPublishedDate(SimpleXMLElement $entry, Item $item, Feed $feed)
|
||||
{
|
||||
$date = XmlParser::getXPathResult($entry, 'pubDate');
|
||||
|
||||
$item->setDate(empty($date) ? $feed->getDate() : $this->getDateParser()->getDateTime(XmlParser::getValue($date)));
|
||||
$item->setPublishedDate(!empty($date) ? $this->getDateParser()->getDateTime(XmlParser::getValue($date)) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the item updated date.
|
||||
*
|
||||
* @param SimpleXMLElement $entry Feed item
|
||||
* @param Item $item Item object
|
||||
* @param \PicoFeed\Parser\Feed $feed Feed object
|
||||
*/
|
||||
public function findItemUpdatedDate(SimpleXMLElement $entry, Item $item, Feed $feed)
|
||||
{
|
||||
if ($item->publishedDate === null) {
|
||||
$this->findItemPublishedDate($entry, $item, $feed);
|
||||
}
|
||||
$item->setUpdatedDate($item->getPublishedDate()); // No updated date in RSS 2.0 specifications
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace PicoFeed\Parser;
|
|||
/**
|
||||
* RSS 0.91 Parser.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Rss91 extends Rss20
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace PicoFeed\Parser;
|
|||
/**
|
||||
* RSS 0.92 Parser.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Rss92 extends Rss20
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace PicoFeed\Parser;
|
|||
/**
|
||||
* XmlEntityException Exception.
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Bernhard Posselt
|
||||
*/
|
||||
class XmlEntityException extends MalformedXmlException
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace PicoFeed\Parser;
|
||||
|
||||
use DomDocument;
|
||||
use SimpleXmlElement;
|
||||
|
||||
use DOMDocument;
|
||||
use SimpleXMLElement;
|
||||
use ZendXml\Exception\RuntimeException;
|
||||
use ZendXml\Security;
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@ use ZendXml\Security;
|
|||
*
|
||||
* Checks for XML eXternal Entity (XXE) and XML Entity Expansion (XEE) attacks on XML documents
|
||||
*
|
||||
* @package PicoFeed\Parser
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class XmlParser
|
||||
|
@ -33,7 +34,7 @@ class XmlParser
|
|||
*
|
||||
* @static
|
||||
* @param string $input XML content
|
||||
* @return \DOMDocument
|
||||
* @return DOMDocument
|
||||
*/
|
||||
public static function getDomDocument($input)
|
||||
{
|
||||
|
@ -52,18 +53,20 @@ class XmlParser
|
|||
}
|
||||
|
||||
/**
|
||||
* Small wrapper around ZendXml to turn their exceptions into picoFeed
|
||||
* exceptions
|
||||
* Small wrapper around ZendXml to turn their exceptions into PicoFeed exceptions
|
||||
*
|
||||
* @param $input the xml to load
|
||||
* @param $dom pass in a dom document or use null/omit if simpleXml should
|
||||
* be used
|
||||
* @static
|
||||
* @access private
|
||||
* @param string $input
|
||||
* @param DOMDocument $dom
|
||||
* @throws XmlEntityException
|
||||
* @return SimpleXMLElement|DomDocument|boolean
|
||||
*/
|
||||
private static function scan($input, $dom = null)
|
||||
{
|
||||
try {
|
||||
return Security::scan($input, $dom);
|
||||
} catch(\ZendXml\Exception\RuntimeException $e) {
|
||||
} catch(RuntimeException $e) {
|
||||
throw new XmlEntityException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -72,8 +75,9 @@ class XmlParser
|
|||
* Load HTML document by using a DomDocument instance or return false on failure.
|
||||
*
|
||||
* @static
|
||||
* @param string $input XML content
|
||||
* @return \DOMDocument
|
||||
* @access public
|
||||
* @param string $input XML content
|
||||
* @return DOMDocument
|
||||
*/
|
||||
public static function getHtmlDocument($input)
|
||||
{
|
||||
|
@ -98,9 +102,8 @@ class XmlParser
|
|||
* Convert a HTML document to XML.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @param string $html HTML document
|
||||
*
|
||||
* @access public
|
||||
* @param string $html HTML document
|
||||
* @return string
|
||||
*/
|
||||
public static function htmlToXml($html)
|
||||
|
@ -113,6 +116,7 @@ class XmlParser
|
|||
* Get XML parser errors.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public static function getErrors()
|
||||
|
@ -135,7 +139,8 @@ class XmlParser
|
|||
* Get the encoding from a xml tag.
|
||||
*
|
||||
* @static
|
||||
* @param string $data Input data
|
||||
* @access public
|
||||
* @param string $data Input data
|
||||
* @return string
|
||||
*/
|
||||
public static function getEncodingFromXmlTag($data)
|
||||
|
@ -162,7 +167,8 @@ class XmlParser
|
|||
* Get the charset from a meta tag.
|
||||
*
|
||||
* @static
|
||||
* @param string $data Input data
|
||||
* @access public
|
||||
* @param string $data Input data
|
||||
* @return string
|
||||
*/
|
||||
public static function getEncodingFromMetaTag($data)
|
||||
|
@ -179,6 +185,8 @@ class XmlParser
|
|||
/**
|
||||
* Rewrite XPath query to use namespace-uri and local-name derived from prefix.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $query XPath query
|
||||
* @param array $ns Prefix to namespace URI mapping
|
||||
* @return string
|
||||
|
@ -199,10 +207,12 @@ class XmlParser
|
|||
/**
|
||||
* Get the result elements of a XPath query.
|
||||
*
|
||||
* @param \SimpleXMLElement $xml XML element
|
||||
* @param string $query XPath query
|
||||
* @param array $ns Prefix to namespace URI mapping
|
||||
* @return \SimpleXMLElement[]
|
||||
* @static
|
||||
* @access public
|
||||
* @param SimpleXMLElement $xml XML element
|
||||
* @param string $query XPath query
|
||||
* @param array $ns Prefix to namespace URI mapping
|
||||
* @return SimpleXMLElement[]
|
||||
*/
|
||||
public static function getXPathResult(SimpleXMLElement $xml, $query, array $ns = array())
|
||||
{
|
||||
|
|
Reference in a new issue