From bec5ba93e23bfe08bc8a95cdc25667cd97b6d128 Mon Sep 17 00:00:00 2001 From: wn_ Date: Sun, 24 Sep 2017 19:37:49 -0500 Subject: [PATCH 1/2] Add 'HOOK_FEED_BASIC_INFO' to enable plugins to provide basic feed info. It's expected the plugin will return content parsable by FeedParser, which will act as an interface to the basic feed info. In the case of a plugin that also uses 'HOOK_FETCH_FEED', both might return the same content. The hook signature was made somewhat similar to 'HOOK_FETCH_FEED'. --- classes/pluginhost.php | 3 ++- classes/rssutils.php | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/classes/pluginhost.php b/classes/pluginhost.php index afe4da49e..571c30fb6 100644 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -54,6 +54,7 @@ class PluginHost { const HOOK_ENCLOSURE_ENTRY = 33; const HOOK_FORMAT_ARTICLE = 34; const HOOK_FORMAT_ARTICLE_CDM = 35; + const HOOK_FEED_BASIC_INFO = 36; const KIND_ALL = 1; const KIND_SYSTEM = 2; @@ -436,4 +437,4 @@ class PluginHost { function get_filter_actions() { return $this->plugin_actions; } -} \ No newline at end of file +} diff --git a/classes/rssutils.php b/classes/rssutils.php index 460709f05..a656de273 100644 --- a/classes/rssutils.php +++ b/classes/rssutils.php @@ -205,9 +205,11 @@ class RSSUtils { $feed = db_escape_string($feed); - $result = db_query("SELECT feed_url,auth_pass,auth_login,auth_pass_encrypted + $result = db_query("SELECT owner_uid,feed_url,auth_pass,auth_login,auth_pass_encrypted FROM ttrss_feeds WHERE id = '$feed'"); + $owner_uid = db_fetch_result($result, 0, "owner_uid"); + $auth_pass_encrypted = sql_bool_to_bool(db_fetch_result($result, 0, "auth_pass_encrypted")); @@ -221,17 +223,35 @@ class RSSUtils { $fetch_url = db_fetch_result($result, 0, "feed_url"); - $feed_data = fetch_file_contents($fetch_url, false, - $auth_login, $auth_pass, false, - FEED_FETCH_TIMEOUT, - 0); + $feed_data = ''; + + $pluginhost = new PluginHost(); + $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); - global $fetch_curl_used; + $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); + $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); + $pluginhost->load_data(); - if (!$fetch_curl_used) { - $tmp = @gzdecode($feed_data); + foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_BASIC_INFO) as $plugin) { + $feed_data = $plugin->hook_feed_basic_info($fetch_url, $owner_uid, $feed, $auth_login, $auth_pass); + if ($feed_data) { + break; + } + } - if ($tmp) $feed_data = $tmp; + if (!$feed_data) { + $feed_data = fetch_file_contents($fetch_url, false, + $auth_login, $auth_pass, false, + FEED_FETCH_TIMEOUT, + 0); + + global $fetch_curl_used; + + if (!$fetch_curl_used) { + $tmp = @gzdecode($feed_data); + + if ($tmp) $feed_data = $tmp; + } } $feed_data = trim($feed_data); @@ -1520,4 +1540,4 @@ class RSSUtils { -} \ No newline at end of file +} From 3476690cbfd1cb797e7b7da111f6656c3a1e9bf5 Mon Sep 17 00:00:00 2001 From: wn_ Date: Tue, 26 Sep 2017 20:37:05 -0500 Subject: [PATCH 2/2] Only require an array of basic info from 'HOOK_FEED_BASIC_INFO'. Removes the need for the plugin to provide feed content. Gives plugins a chance to provide 'title' and 'site_url' basic info. Falls back to attempting retrieval+parsing of the fetch URL if needed. --- classes/rssutils.php | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/classes/rssutils.php b/classes/rssutils.php index a656de273..d6dfc724e 100644 --- a/classes/rssutils.php +++ b/classes/rssutils.php @@ -223,8 +223,6 @@ class RSSUtils { $fetch_url = db_fetch_result($result, 0, "feed_url"); - $feed_data = ''; - $pluginhost = new PluginHost(); $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); @@ -232,14 +230,12 @@ class RSSUtils { $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); $pluginhost->load_data(); + $basic_info = array(); foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_BASIC_INFO) as $plugin) { - $feed_data = $plugin->hook_feed_basic_info($fetch_url, $owner_uid, $feed, $auth_login, $auth_pass); - if ($feed_data) { - break; - } - } + $basic_info = $plugin->hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed, $auth_login, $auth_pass); + } - if (!$feed_data) { + if (!$basic_info) { $feed_data = fetch_file_contents($fetch_url, false, $auth_login, $auth_pass, false, FEED_FETCH_TIMEOUT, @@ -252,31 +248,34 @@ class RSSUtils { if ($tmp) $feed_data = $tmp; } + + $feed_data = trim($feed_data); + + $rss = new FeedParser($feed_data); + $rss->init(); + + if (!$rss->error()) { + $basic_info = array( + 'title' => db_escape_string(mb_substr($rss->get_title(), 0, 199)), + 'site_url' => db_escape_string(mb_substr(rewrite_relative_url($fetch_url, $rss->get_link()), 0, 245)) + ); + } } - $feed_data = trim($feed_data); - - $rss = new FeedParser($feed_data); - $rss->init(); - - if (!$rss->error()) { - + if ($basic_info && is_array($basic_info)) { $result = db_query("SELECT title, site_url FROM ttrss_feeds WHERE id = '$feed'"); $registered_title = db_fetch_result($result, 0, "title"); $orig_site_url = db_fetch_result($result, 0, "site_url"); - $site_url = db_escape_string(mb_substr(rewrite_relative_url($fetch_url, $rss->get_link()), 0, 245)); - $feed_title = db_escape_string(mb_substr($rss->get_title(), 0, 199)); - - if ($feed_title && (!$registered_title || $registered_title == "[Unknown]")) { + if ($basic_info['title'] && (!$registered_title || $registered_title == "[Unknown]")) { db_query("UPDATE ttrss_feeds SET - title = '$feed_title' WHERE id = '$feed'"); + title = '${basic_info['title']}' WHERE id = '$feed'"); } - if ($site_url && $orig_site_url != $site_url) { + if ($basic_info['site_url'] && $orig_site_url != $basic_info['site_url']) { db_query("UPDATE ttrss_feeds SET - site_url = '$site_url' WHERE id = '$feed'"); + site_url = '${basic_info['site_url']}' WHERE id = '$feed'"); } } }