diff options
Diffstat (limited to 'vendor/fguillot/picofeed/lib/PicoFeed/Parser')
5 files changed, 204 insertions, 122 deletions
diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Atom.php b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Atom.php index 1217bc4b0..5bb930b22 100644 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Atom.php +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Atom.php @@ -30,19 +30,31 @@ class Atom extends Parser * Find the feed url * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedUrl(SimpleXMLElement $xml, Feed $feed) { - $feed->url = $this->getLink($xml); + $feed->feed_url = $this->getUrl($xml, 'self'); + } + + /** + * Find the site url + * + * @access public + * @param SimpleXMLElement $xml Feed xml + * @param \PicoFeed\Parser\Feed $feed Feed object + */ + public function findSiteUrl(SimpleXMLElement $xml, Feed $feed) + { + $feed->site_url = $this->getUrl($xml, 'alternate', true); } /** * Find the feed description * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedDescription(SimpleXMLElement $xml, Feed $feed) @@ -54,7 +66,7 @@ class Atom extends Parser * Find the feed logo url * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedLogo(SimpleXMLElement $xml, Feed $feed) @@ -66,19 +78,19 @@ class Atom extends Parser * Find the feed title * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedTitle(SimpleXMLElement $xml, Feed $feed) { - $feed->title = Filter::stripWhiteSpace((string) $xml->title) ?: $feed->url; + $feed->title = Filter::stripWhiteSpace((string) $xml->title) ?: $feed->getSiteUrl(); } /** * Find the feed language * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedLanguage(SimpleXMLElement $xml, Feed $feed) @@ -90,7 +102,7 @@ class Atom extends Parser * Find the feed id * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedId(SimpleXMLElement $xml, Feed $feed) @@ -102,7 +114,7 @@ class Atom extends Parser * Find the feed date * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedDate(SimpleXMLElement $xml, Feed $feed) @@ -115,7 +127,7 @@ class Atom extends Parser * * @access public * @param SimpleXMLElement $entry Feed item - * @param Item $item Item object + * @param Item $item Item object */ public function findItemDate(SimpleXMLElement $entry, Item $item) { @@ -145,8 +157,8 @@ class Atom extends Parser * Find the item author * * @access public - * @param SimpleXMLElement $xml Feed - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $xml Feed + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object */ public function findItemAuthor(SimpleXMLElement $xml, SimpleXMLElement $entry, Item $item) @@ -180,7 +192,7 @@ class Atom extends Parser */ public function findItemUrl(SimpleXMLElement $entry, Item $item) { - $item->url = $this->getLink($entry); + $item->url = $this->getUrl($entry, 'alternate'); } /** @@ -215,13 +227,11 @@ class Atom extends Parser */ public function findItemEnclosure(SimpleXMLElement $entry, Item $item, Feed $feed) { - foreach ($entry->link as $link) { - if ((string) $link['rel'] === 'enclosure') { + $enclosure = $this->findLink($entry, 'enclosure'); - $item->enclosure_url = Url::resolve((string) $link['href'], $feed->url); - $item->enclosure_type = (string) $link['type']; - break; - } + if ($enclosure) { + $item->enclosure_url = Url::resolve((string) $enclosure['href'], $feed->getSiteUrl()); + $item->enclosure_type = (string) $enclosure['type']; } } @@ -241,29 +251,54 @@ class Atom extends Parser /** * Get the URL from a link tag * - * @access public - * @param SimpleXMLElement $xml XML tag + * @access private + * @param SimpleXMLElement $xml XML tag + * @param string $rel Link relationship: alternate, enclosure, related, self, via * @return string */ - public function getLink(SimpleXMLElement $xml) + private function getUrl(SimpleXMLElement $xml, $rel, $fallback = false) + { + $link = $this->findLink($xml, $rel); + + if ($link) { + return (string) $link['href']; + } + + if ($fallback) { + $link = $this->findLink($xml, ''); + return $link ? (string) $link['href'] : ''; + } + + return ''; + } + + /** + * Get a link tag that match a relationship + * + * @access private + * @param SimpleXMLElement $xml XML tag + * @param string $rel Link relationship: alternate, enclosure, related, self, via + * @return SimpleXMLElement|null + */ + private function findLink(SimpleXMLElement $xml, $rel) { foreach ($xml->link as $link) { - if ((string) $link['type'] === 'text/html' || (string) $link['type'] === 'application/xhtml+xml') { - return (string) $link['href']; + if (empty($rel) || $rel === (string) $link['rel']) { + return $link; } } - return (string) $xml->link['href']; + return null; } /** * Get the entry content * - * @access public + * @access private * @param SimpleXMLElement $entry XML Entry * @return string */ - public function getContent(SimpleXMLElement $entry) + private function getContent(SimpleXMLElement $entry) { if (isset($entry->content) && ! empty($entry->content)) { diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Feed.php b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Feed.php index 77a6f0c97..b8edbd6f8 100644 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Feed.php +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Feed.php @@ -48,7 +48,15 @@ class Feed * @access public * @var string */ - public $url = ''; + public $feed_url = ''; + + /** + * Site url + * + * @access public + * @var string + */ + public $site_url = ''; /** * Feed date @@ -84,7 +92,7 @@ class Feed { $output = ''; - foreach (array('id', 'title', 'url', 'date', 'language', 'description', 'logo') as $property) { + foreach (array('id', 'title', 'feed_url', 'site_url', 'date', 'language', 'description', 'logo') as $property) { $output .= 'Feed::'.$property.' = '.$this->$property.PHP_EOL; } @@ -132,14 +140,25 @@ class Feed } /** - * Get url + * Get feed url + * + * @access public + * $return string + */ + public function getFeedUrl() + { + return $this->feed_url; + } + + /** + * Get site url * * @access public * $return string */ - public function getUrl() + public function getSiteUrl() { - return $this->url; + return $this->site_url; } /** diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Item.php b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Item.php index 1731f5a29..6b2864ba7 100644 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Item.php +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Item.php @@ -11,6 +11,23 @@ namespace PicoFeed\Parser; class Item { /** + * List of known RTL languages + * + * @access public + * @var public + */ + public $rtl = array( + 'ar', // Arabic (ar-**) + 'fa', // Farsi (fa-**) + 'ur', // Urdu (ur-**) + 'ps', // Pashtu (ps-**) + 'syr', // Syriac (syr-**) + 'dv', // Divehi (dv-**) + 'he', // Hebrew (he-**) + 'yi', // Yiddish (yi-**) + ); + + /** * Item id * * @access public @@ -96,6 +113,7 @@ class Item $output .= 'Item::'.$property.' = '.$this->$property.PHP_EOL; } + $output .= 'Item::isRTL() = '.($this->isRTL() ? 'true' : 'false').PHP_EOL; $output .= 'Item::content = '.strlen($this->content).' bytes'.PHP_EOL; return $output; @@ -199,4 +217,23 @@ class Item { return $this->author; } + + /** + * Return true if the item is "Right to Left" + * + * @access public + * @return bool + */ + public function isRTL() + { + $language = strtolower($this->language); + + foreach ($this->rtl as $prefix) { + if (strpos($language, $prefix) === 0) { + return true; + } + } + + return false; + } } diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php index 80e09e016..de73504e4 100644 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Parser.php @@ -141,6 +141,9 @@ abstract class Parser $this->findFeedUrl($xml, $feed); $this->checkFeedUrl($feed); + $this->findSiteUrl($xml, $feed); + $this->checkSiteUrl($feed); + $this->findFeedTitle($xml, $feed); $this->findFeedDescription($xml, $feed); $this->findFeedLanguage($xml, $feed); @@ -185,10 +188,27 @@ abstract class Parser */ public function checkFeedUrl(Feed $feed) { - $url = new Url($feed->getUrl()); + if ($feed->getFeedUrl() === '') { + $feed->feed_url = $this->fallback_url; + } + else { + $feed->feed_url = Url::resolve($feed->getFeedUrl(), $this->fallback_url); + } + } - if ($url->isRelativeUrl()) { - $feed->url = $this->fallback_url; + /** + * Check if the site url is correct + * + * @access public + * @param Feed $feed Feed object + */ + public function checkSiteUrl(Feed $feed) + { + if ($feed->getSiteUrl() === '') { + $feed->site_url = Url::base($feed->getFeedUrl()); + } + else { + $feed->site_url = Url::resolve($feed->getSiteUrl(), $this->fallback_url); } } @@ -201,11 +221,7 @@ abstract class Parser */ public function checkItemUrl(Feed $feed, Item $item) { - $url = new Url($item->getUrl()); - - if ($url->isRelativeUrl()) { - $item->url = Url::resolve($item->getUrl(), $feed->getUrl()); - } + $item->url = Url::resolve($item->getUrl(), $feed->getSiteUrl()); } /** @@ -238,7 +254,7 @@ abstract class Parser public function filterItemContent(Feed $feed, Item $item) { if ($this->isFilteringEnabled()) { - $filter = Filter::html($item->getContent(), $feed->getUrl()); + $filter = Filter::html($item->getContent(), $feed->getSiteUrl()); $filter->setConfig($this->config); $item->content = $filter->execute(); } @@ -283,6 +299,7 @@ abstract class Parser 'D, d M Y H:i:s' => 25, 'D, d M Y h:i:s' => 25, 'D M d Y H:i:s' => 24, + 'j M Y H:i:s' => 20, 'Y-m-d H:i:s' => 19, 'Y-m-d\TH:i:s' => 19, 'd/m/Y H:i:s' => 19, @@ -340,38 +357,6 @@ abstract class Parser } /** - * Return true if the given language is "Right to Left" - * - * @static - * @access public - * @param string $language Language: fr-FR, en-US - * @return bool - */ - public static function isLanguageRTL($language) - { - $language = strtolower($language); - - $rtl_languages = array( - 'ar', // Arabic (ar-**) - 'fa', // Farsi (fa-**) - 'ur', // Urdu (ur-**) - 'ps', // Pashtu (ps-**) - 'syr', // Syriac (syr-**) - 'dv', // Divehi (dv-**) - 'he', // Hebrew (he-**) - 'yi', // Yiddish (yi-**) - ); - - foreach ($rtl_languages as $prefix) { - if (strpos($language, $prefix) === 0) { - return true; - } - } - - return false; - } - - /** * Set Hash algorithm used for id generation * * @access public @@ -464,16 +449,25 @@ abstract class Parser * Find the feed url * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public abstract function findFeedUrl(SimpleXMLElement $xml, Feed $feed); /** + * Find the site url + * + * @access public + * @param SimpleXMLElement $xml Feed xml + * @param \PicoFeed\Parser\Feed $feed Feed object + */ + public abstract function findSiteUrl(SimpleXMLElement $xml, Feed $feed); + + /** * Find the feed title * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public abstract function findFeedTitle(SimpleXMLElement $xml, Feed $feed); @@ -482,7 +476,7 @@ abstract class Parser * Find the feed description * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public abstract function findFeedDescription(SimpleXMLElement $xml, Feed $feed); @@ -491,7 +485,7 @@ abstract class Parser * Find the feed language * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public abstract function findFeedLanguage(SimpleXMLElement $xml, Feed $feed); @@ -500,7 +494,7 @@ abstract class Parser * Find the feed id * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public abstract function findFeedId(SimpleXMLElement $xml, Feed $feed); @@ -509,7 +503,7 @@ abstract class Parser * Find the feed date * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public abstract function findFeedDate(SimpleXMLElement $xml, Feed $feed); @@ -518,7 +512,7 @@ abstract class Parser * Find the feed logo url * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public abstract function findFeedLogo(SimpleXMLElement $xml, Feed $feed); @@ -536,8 +530,8 @@ abstract class Parser * Find the item author * * @access public - * @param SimpleXMLElement $xml Feed - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $xml Feed + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object */ public abstract function findItemAuthor(SimpleXMLElement $xml, SimpleXMLElement $entry, Item $item); @@ -546,7 +540,7 @@ abstract class Parser * Find the item URL * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object */ public abstract function findItemUrl(SimpleXMLElement $entry, Item $item); @@ -555,7 +549,7 @@ abstract class Parser * Find the item title * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object */ public abstract function findItemTitle(SimpleXMLElement $entry, Item $item); @@ -564,7 +558,7 @@ abstract class Parser * Genereate the item id * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object * @param \PicoFeed\Parser\Feed $feed Feed object */ @@ -574,7 +568,7 @@ abstract class Parser * Find the item date * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object */ public abstract function findItemDate(SimpleXMLElement $entry, Item $item); @@ -583,7 +577,7 @@ abstract class Parser * Find the item content * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object */ public abstract function findItemContent(SimpleXMLElement $entry, Item $item); @@ -592,7 +586,7 @@ abstract class Parser * Find the item enclosure * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object * @param \PicoFeed\Parser\Feed $feed Feed object */ @@ -602,7 +596,7 @@ abstract class Parser * Find the item language * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object * @param \PicoFeed\Parser\Feed $feed Feed object */ diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Rss20.php b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Rss20.php index 80e65fab8..c0417f9ac 100644 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Rss20.php +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Parser/Rss20.php @@ -30,34 +30,31 @@ class Rss20 extends Parser * Find the feed url * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedUrl(SimpleXMLElement $xml, Feed $feed) { - if ($xml->channel->link && $xml->channel->link->count() > 1) { - - foreach ($xml->channel->link as $xml_link) { - - $link = (string) $xml_link; - - if ($link !== '') { - $feed->url = $link; - break; - } - } - } - else { + $feed->feed_url = ''; + } - $feed->url = (string) $xml->channel->link; - } + /** + * Find the site url + * + * @access public + * @param SimpleXMLElement $xml Feed xml + * @param \PicoFeed\Parser\Feed $feed Feed object + */ + public function findSiteUrl(SimpleXMLElement $xml, Feed $feed) + { + $feed->site_url = (string) $xml->channel->link; } /** * Find the feed description * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedDescription(SimpleXMLElement $xml, Feed $feed) @@ -69,7 +66,7 @@ class Rss20 extends Parser * Find the feed logo url * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedLogo(SimpleXMLElement $xml, Feed $feed) @@ -83,19 +80,19 @@ class Rss20 extends Parser * Find the feed title * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedTitle(SimpleXMLElement $xml, Feed $feed) { - $feed->title = Filter::stripWhiteSpace((string) $xml->channel->title) ?: $feed->url; + $feed->title = Filter::stripWhiteSpace((string) $xml->channel->title) ?: $feed->getSiteUrl(); } /** * Find the feed language * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedLanguage(SimpleXMLElement $xml, Feed $feed) @@ -107,19 +104,19 @@ class Rss20 extends Parser * Find the feed id * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedId(SimpleXMLElement $xml, Feed $feed) { - $feed->id = $feed->url; + $feed->id = $feed->getFeedUrl() ?: $feed->getSiteUrl(); } /** * Find the feed date * * @access public - * @param SimpleXMLElement $xml Feed xml + * @param SimpleXMLElement $xml Feed xml * @param \PicoFeed\Parser\Feed $feed Feed object */ public function findFeedDate(SimpleXMLElement $xml, Feed $feed) @@ -132,7 +129,7 @@ class Rss20 extends Parser * Find the item date * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object */ public function findItemDate(SimpleXMLElement $entry, Item $item) @@ -154,7 +151,7 @@ class Rss20 extends Parser * Find the item title * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object */ public function findItemTitle(SimpleXMLElement $entry, Item $item) @@ -170,8 +167,8 @@ class Rss20 extends Parser * Find the item author * * @access public - * @param SimpleXMLElement $xml Feed - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $xml Feed + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object */ public function findItemAuthor(SimpleXMLElement $xml, SimpleXMLElement $entry, Item $item) @@ -192,7 +189,7 @@ class Rss20 extends Parser * Find the item content * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object */ public function findItemContent(SimpleXMLElement $entry, Item $item) @@ -210,7 +207,7 @@ class Rss20 extends Parser * Find the item URL * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object */ public function findItemUrl(SimpleXMLElement $entry, Item $item) @@ -234,7 +231,7 @@ class Rss20 extends Parser * Genereate the item id * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object * @param \PicoFeed\Parser\Feed $feed Feed object */ @@ -256,7 +253,7 @@ class Rss20 extends Parser * Find the item enclosure * * @access public - * @param SimpleXMLElement $entry Feed item + * @param SimpleXMLElement $entry Feed item * @param \PicoFeed\Parser\Item $item Item object * @param \PicoFeed\Parser\Feed $feed Feed object */ @@ -271,7 +268,7 @@ class Rss20 extends Parser } $item->enclosure_type = isset($entry->enclosure['type']) ? (string) $entry->enclosure['type'] : ''; - $item->enclosure_url = Url::resolve($item->enclosure_url, $feed->url); + $item->enclosure_url = Url::resolve($item->enclosure_url, $feed->getSiteUrl()); } } |