From c625b6aba83fa3ad13d57ae46f8821dd3e747496 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 7 Jul 2016 22:37:16 +0200 Subject: [PATCH] If a page contains a feed url then follow it. --- include/Probe.php | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/include/Probe.php b/include/Probe.php index 23a89428b2..4dcbc78411 100644 --- a/include/Probe.php +++ b/include/Probe.php @@ -706,12 +706,51 @@ class Probe { return $data; } - private function feed($url) { + private function get_feed_link($url) { + $doc = new DOMDocument(); + + if (!@$doc->loadHTMLFile($url)) + return false; + + $xpath = new DomXPath($doc); + + //$feeds = $xpath->query("/html/head/link[@type='application/rss+xml']"); + $feeds = $xpath->query("/html/head/link[@type='application/rss+xml' and @rel='alternate']"); + if (!is_object($feeds)) + return false; + + if ($feeds->length == 0) + return false; + + $feed_url = ""; + + foreach ($feeds AS $feed) { + $attr = array(); + foreach ($feed->attributes as $attribute) + $attr[$attribute->name] = trim($attribute->value); + + if ($feed_url == "") + $feed_url = $attr["href"]; + } + + return $feed_url; + } + + private function feed($url, $probe = true) { $feed = fetch_url($url); $feed_data = feed_import($feed, $dummy1, $dummy2, $dummy3, true); - if (!$feed_data) - return false; + if (!$feed_data) { + if (!$probe) + return false; + + $feed_url = self::get_feed_link($url); + + if (!$feed_url) + return false; + + return self::feed($feed_url, false); + } if ($feed_data["header"]["author-name"] != "") $data["name"] = $feed_data["header"]["author-name"]; -- 2.39.5