From 74d8d361eec01cc85ff98d6c6f6b8301af9514f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Mon, 17 Feb 2014 22:04:49 -0500 Subject: [PATCH] Improve enclosure support --- README.markdown | 1 + locales/fr_FR/translations.php | 1 + models/item.php | 8 +++++++- models/schema.php | 2 ++ templates/feeds.php | 18 ++++++++++++------ templates/item.php | 6 +++--- templates/show_item.php | 17 +++++++++++++++++ vendor/PicoFeed/Filter.php | 4 ++-- vendor/PicoFeed/Parsers/Atom.php | 18 +++++++++++++----- vendor/PicoFeed/Parsers/Rss20.php | 19 ++++++++++++++++--- 10 files changed, 74 insertions(+), 20 deletions(-) diff --git a/README.markdown b/README.markdown index 80e788a..e996da2 100644 --- a/README.markdown +++ b/README.markdown @@ -63,6 +63,7 @@ People who sent a pull-request, report a bug, make a new theme or share a super - MonsieurPaulLeBoulanger: https://github.com/MonsieurPaulLeBoulanger - Necku: https://github.com/Necku - Nicolas Dewaele: http://adminrezo.fr/ +- Pcwalden: https://github.com/pcwalden - Silvus: https://github.com/Silvus - Skasi7: https://github.com/skasi7 - Thiriot Christophe: https://github.com/doubleface diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index 1ed1efc..c1d7047 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -1,6 +1,7 @@ 'pièce jointe', 'When there is nothing to read, redirect me to this page' => 'Quand il n\'y a rien à lire, redirigez moi vers cette page', 'Subscription page' => 'Page des abonnements', 'History page' => 'Historique de lecture', diff --git a/models/item.php b/models/item.php index ac7e695..b645fd7 100644 --- a/models/item.php +++ b/models/item.php @@ -19,6 +19,7 @@ function get_everything() 'items.updated', 'items.url', 'items.enclosure', + 'items.enclosure_type', 'items.bookmark', 'items.feed_id', 'items.status', @@ -43,6 +44,7 @@ function get_everything_since($timestamp) 'items.updated', 'items.url', 'items.enclosure', + 'items.enclosure_type', 'items.bookmark', 'items.feed_id', 'items.status', @@ -78,6 +80,7 @@ function get_all($status, $offset = null, $limit = null, $order_column = 'update 'items.updated', 'items.url', 'items.enclosure', + 'items.enclosure_type', 'items.bookmark', 'items.feed_id', 'items.status', @@ -123,6 +126,7 @@ function get_bookmarks($offset = null, $limit = null) 'items.updated', 'items.url', 'items.enclosure', + 'items.enclosure_type', 'items.bookmark', 'items.status', 'items.content', @@ -160,6 +164,7 @@ function get_all_by_feed($feed_id, $offset = null, $limit = null, $order_column 'items.updated', 'items.url', 'items.enclosure', + 'items.enclosure_type', 'items.feed_id', 'items.status', 'items.content', @@ -426,7 +431,8 @@ function update_all($feed_id, array $items, $grabber = false) 'content' => $nocontent ? '' : $item->content, 'status' => 'unread', 'feed_id' => $feed_id, - 'enclosure' => isset($item->enclosure) ? $item->enclosure : NULL + 'enclosure' => isset($item->enclosure) ? $item->enclosure : null, + 'enclosure_type' => isset($item->enclosure_type) ? $item->enclosure_type : null, )); } else { diff --git a/models/schema.php b/models/schema.php index 5ef0ee8..08a904b 100644 --- a/models/schema.php +++ b/models/schema.php @@ -6,8 +6,10 @@ namespace Schema; function version_21($pdo) { $pdo->exec('ALTER TABLE items ADD COLUMN enclosure TEXT'); + $pdo->exec('ALTER TABLE items ADD COLUMN enclosure_type TEXT'); } + function version_20($pdo) { $pdo->exec('ALTER TABLE config ADD COLUMN redirect_nothing_to_read TEXT DEFAULT "feeds"'); diff --git a/templates/feeds.php b/templates/feeds.php index c393eec..ece49b5 100644 --- a/templates/feeds.php +++ b/templates/feeds.php @@ -63,14 +63,20 @@ + +
  • - - - - - - +
  • +
  • + +
  • + +
  • + +
  • + +
  • diff --git a/templates/item.php b/templates/item.php index 9b68e13..aaf8316 100644 --- a/templates/item.php +++ b/templates/item.php @@ -35,9 +35,9 @@
  • - -
  • - multimedia 🔉 + +
  • +
  • $item, 'menu' => $menu, 'offset' => $offset, 'source' => '')) ?> diff --git a/templates/show_item.php b/templates/show_item.php index f7552fb..729580c 100644 --- a/templates/show_item.php +++ b/templates/show_item.php @@ -64,6 +64,11 @@
  • + +
  • + +
  • +
  • + + + + + + + + diff --git a/vendor/PicoFeed/Filter.php b/vendor/PicoFeed/Filter.php index ae80f34..d6da5ac 100644 --- a/vendor/PicoFeed/Filter.php +++ b/vendor/PicoFeed/Filter.php @@ -315,7 +315,7 @@ class Filter } - public function getAbsoluteUrl($path, $url) + public static function getAbsoluteUrl($path, $url) { $components = parse_url($url); @@ -358,7 +358,7 @@ class Filter } - public function isRelativePath($value) + public static function isRelativePath($value) { if (strpos($value, 'data:') === 0) return false; return strpos($value, '://') === false && strpos($value, '//') !== 0; diff --git a/vendor/PicoFeed/Parsers/Atom.php b/vendor/PicoFeed/Parsers/Atom.php index 30dd2f3..b483cac 100644 --- a/vendor/PicoFeed/Parsers/Atom.php +++ b/vendor/PicoFeed/Parsers/Atom.php @@ -44,6 +44,19 @@ class Atom extends \PicoFeed\Parser if (empty($item->title)) $item->title = $item->url; + // Try to find an enclosure + foreach ($entry->link as $link) { + if ((string) $link['rel'] === 'enclosure') { + $item->enclosure = (string) $link['href']; + $item->enclosure_type = (string) $link['type']; + + if (\PicoFeed\Filter::isRelativePath($item->enclosure)) { + $item->enclosure = \PicoFeed\Filter::getAbsoluteUrl($item->enclosure, $this->url); + } + break; + } + } + $this->items[] = $item; } @@ -58,16 +71,13 @@ class Atom extends \PicoFeed\Parser if (isset($entry->content) && ! empty($entry->content)) { if (count($entry->content->children())) { - return (string) $entry->content->asXML(); } else { - return (string) $entry->content; } } else if (isset($entry->summary) && ! empty($entry->summary)) { - return (string) $entry->summary; } @@ -78,9 +88,7 @@ class Atom extends \PicoFeed\Parser public function getUrl($xml) { foreach ($xml->link as $link) { - if ((string) $link['type'] === 'text/html' || (string) $link['type'] === 'application/xhtml+xml') { - return (string) $link['href']; } } diff --git a/vendor/PicoFeed/Parsers/Rss20.php b/vendor/PicoFeed/Parsers/Rss20.php index a44c9d6..c871c59 100644 --- a/vendor/PicoFeed/Parsers/Rss20.php +++ b/vendor/PicoFeed/Parsers/Rss20.php @@ -58,16 +58,21 @@ class Rss20 extends \PicoFeed\Parser $item->author= ''; $item->updated = ''; $item->content = ''; + $item->enclosure = ''; + $item->enclosure_type = ''; foreach ($namespaces as $name => $url) { $namespace = $entry->children($namespaces[$name]); - if (! $item->url && ! empty($namespace->origLink)) $item->url = (string) $namespace->origLink; if (! $item->author && ! empty($namespace->creator)) $item->author = (string) $namespace->creator; if (! $item->updated && ! empty($namespace->date)) $item->updated = $this->parseDate((string) $namespace->date); if (! $item->updated && ! empty($namespace->updated)) $item->updated = $this->parseDate((string) $namespace->updated); if (! $item->content && ! empty($namespace->encoded)) $item->content = (string) $namespace->encoded; + + // Get FeedBurner original links + if (! $item->url && ! empty($namespace->origLink)) $item->url = (string) $namespace->origLink; + if (! $item->enclosure && ! empty($namespace->origEnclosureLink)) $item->enclosure = (string) $namespace->origEnclosureLink; } if (empty($item->url)) { @@ -112,8 +117,16 @@ class Rss20 extends \PicoFeed\Parser // if optional enclosure tag with multimedia provided, capture here if (isset($entry->enclosure)) { - $item->enclosure = (string) $entry->enclosure['url']; - // \PicoFeed\Logging::log(\get_called_class().': recorded enclosure ('.(string) $item->enclosure.')'); + + if (! $item->enclosure) { + $item->enclosure = isset($entry->enclosure['url']) ? (string) $entry->enclosure['url'] : ''; + } + + $item->enclosure_type = isset($entry->enclosure['type']) ? (string) $entry->enclosure['type'] : ''; + + if (\PicoFeed\Filter::isRelativePath($item->enclosure)) { + $item->enclosure = \PicoFeed\Filter::getAbsoluteUrl($item->enclosure, $this->url); + } } $item->content = $this->filterHtml($item->content, $item->url);