From 358bcdd881741c43d45c41ac7f13071f02f1045c Mon Sep 17 00:00:00 2001 From: wn Date: Sat, 12 Dec 2020 09:39:49 -0600 Subject: [PATCH 01/11] Fix passing options to plugins in 'update.php'. --- update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.php b/update.php index 95f19d022..d60b1a6a5 100755 --- a/update.php +++ b/update.php @@ -239,7 +239,7 @@ RSSUtils::update_daemon_common(DAEMON_FEED_LIMIT, $options); RSSUtils::housekeeping_common(); - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op); + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $options); } if (isset($options["daemon"])) { From 6f31372b3788502007a17a1fe89095e8f7966cc0 Mon Sep 17 00:00:00 2001 From: wn Date: Sat, 12 Dec 2020 09:40:26 -0600 Subject: [PATCH 02/11] Address param order deprecation warning for 'af_redditimgur'. --- plugins/af_redditimgur/init.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index d3e91f383..7a395801d 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -506,7 +506,7 @@ class Af_RedditImgur extends Plugin { } } - private function get_header($url, $useragent = SELF_USER_AGENT, $header) { + private function get_header($url, $header, $useragent = SELF_USER_AGENT) { $ret = false; if (function_exists("curl_init") && !defined("NO_CURL")) { @@ -526,11 +526,11 @@ class Af_RedditImgur extends Plugin { } private function get_content_type($url, $useragent = SELF_USER_AGENT) { - return $this->get_header($url, $useragent, CURLINFO_CONTENT_TYPE); + return $this->get_header($url, CURLINFO_CONTENT_TYPE, $useragent); } private function get_location($url, $useragent = SELF_USER_AGENT) { - return $this->get_header($url, $useragent, CURLINFO_EFFECTIVE_URL); + return $this->get_header($url, CURLINFO_EFFECTIVE_URL, $useragent); } /** From 75536b4790a676bf9ffffc115d2ec5fbf9a090b4 Mon Sep 17 00:00:00 2001 From: wn Date: Sat, 12 Dec 2020 09:42:07 -0600 Subject: [PATCH 03/11] Switch to recommended 'default_charset' to fix 'gettext' error. 'mbstring.internal-encoding' was deprecated in 5.6. https://www.php.net/manual/en/mbstring.configuration.php#ini.mbstring.internal-encoding https://www.php.net/manual/en/ini.core.php#ini.default-charset --- lib/gettext/gettext.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gettext/gettext.inc.php b/lib/gettext/gettext.inc.php index ed5be6bbd..ef36924c7 100644 --- a/lib/gettext/gettext.inc.php +++ b/lib/gettext/gettext.inc.php @@ -167,7 +167,7 @@ function _check_locale_and_function($function=false) { function _get_codeset($domain=null) { global $text_domains, $default_domain, $LC_CATEGORIES; if (!isset($domain)) $domain = $default_domain; - return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); + return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('default_charset'); } /** From 08a6f6bde20055de5a08ea8afed5097783a5f164 Mon Sep 17 00:00:00 2001 From: wn Date: Sat, 12 Dec 2020 09:47:10 -0600 Subject: [PATCH 04/11] Only do sanity checks for self URL if we can create a valid URL. 'sanity_check.php' gets included in 'update.php' and 'update_daemon2.php', where a Host request header is likely not provided. --- include/sanity_check.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/sanity_check.php b/include/sanity_check.php index 86dc7a5f0..e6c0e5d4b 100755 --- a/include/sanity_check.php +++ b/include/sanity_check.php @@ -21,6 +21,8 @@ } function make_self_url_path() { + if (!isset($_SERVER["HTTP_HOST"])) return false; + $proto = is_server_https() ? 'https' : 'http'; $url_path = $proto . '://' . $_SERVER["HTTP_HOST"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); @@ -115,14 +117,18 @@ } $ref_self_url_path = make_self_url_path(); - $ref_self_url_path = preg_replace("/\w+\.php$/", "", $ref_self_url_path); - if (SELF_URL_PATH == "http://example.org/tt-rss/") { - array_push($errors, - "Please set SELF_URL_PATH to the correct value for your server (possible value: $ref_self_url_path)"); + if ($ref_self_url_path) { + $ref_self_url_path = preg_replace("/\w+\.php$/", "", $ref_self_url_path); } - if (isset($_SERVER["HTTP_HOST"]) && + if (SELF_URL_PATH == "http://example.org/tt-rss/") { + $hint = $ref_self_url_path ? "(possible value: $ref_self_url_path)" : ""; + array_push($errors, + "Please set SELF_URL_PATH to the correct value for your server $hint"); + } + + if ($ref_self_url_path && (!defined('_SKIP_SELF_URL_PATH_CHECKS') || !_SKIP_SELF_URL_PATH_CHECKS) && SELF_URL_PATH != $ref_self_url_path && SELF_URL_PATH != mb_substr($ref_self_url_path, 0, mb_strlen($ref_self_url_path)-1)) { array_push($errors, From 6bdf4a1a25f1fc2e84fdc65e3e6a74578536f137 Mon Sep 17 00:00:00 2001 From: wn Date: Sat, 12 Dec 2020 09:50:43 -0600 Subject: [PATCH 05/11] Switch to 'get_error_types()' to ensure availability in 'include/functions.php'. The global in 'sanity_check()' was null... possibly due to circular requires? --- errors.php | 42 ++++++++++++++++++++++-------------------- include/functions.php | 4 ++-- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/errors.php b/errors.php index deadb1e24..68164974b 100644 --- a/errors.php +++ b/errors.php @@ -4,48 +4,50 @@ require_once "functions.php"; - $ERRORS[0] = ""; + function get_error_types() { + $ERRORS[0] = ""; - $ERRORS[1] = __("This program requires XmlHttpRequest " . - "to function properly. Your browser doesn't seem to support it."); + $ERRORS[1] = __("This program requires XmlHttpRequest " . + "to function properly. Your browser doesn't seem to support it."); - $ERRORS[2] = __("This program requires cookies " . - "to function properly. Your browser doesn't seem to support them."); + $ERRORS[2] = __("This program requires cookies " . + "to function properly. Your browser doesn't seem to support them."); - $ERRORS[3] = __("Backend sanity check failed."); + $ERRORS[3] = __("Backend sanity check failed."); - $ERRORS[4] = __("Frontend sanity check failed."); + $ERRORS[4] = __("Frontend sanity check failed."); - $ERRORS[5] = __("Incorrect database schema version. <a href='db-updater.php'>Please update</a>."); + $ERRORS[5] = __("Incorrect database schema version. <a href='db-updater.php'>Please update</a>."); - $ERRORS[6] = __("Request not authorized."); + $ERRORS[6] = __("Request not authorized."); - $ERRORS[7] = __("No operation to perform."); + $ERRORS[7] = __("No operation to perform."); - $ERRORS[8] = __("Could not display feed: query failed. Please check label match syntax or local configuration."); + $ERRORS[8] = __("Could not display feed: query failed. Please check label match syntax or local configuration."); - $ERRORS[8] = __("Denied. Your access level is insufficient to access this page."); + $ERRORS[8] = __("Denied. Your access level is insufficient to access this page."); - $ERRORS[9] = __("Configuration check failed"); + $ERRORS[9] = __("Configuration check failed"); - $ERRORS[10] = __("Your version of MySQL is not currently supported. Please see official site for more information."); + $ERRORS[10] = __("Your version of MySQL is not currently supported. Please see official site for more information."); - $ERRORS[11] = "[This error is not returned by server]"; + $ERRORS[11] = "[This error is not returned by server]"; - $ERRORS[12] = __("SQL escaping test failed, check your database and PHP configuration"); + $ERRORS[12] = __("SQL escaping test failed, check your database and PHP configuration"); - $ERRORS[13] = __("Method not found"); + $ERRORS[13] = __("Method not found"); - $ERRORS[14] = __("Plugin not found"); + $ERRORS[14] = __("Plugin not found"); - $ERRORS[15] = __("Encoding data as JSON failed"); + $ERRORS[15] = __("Encoding data as JSON failed"); + } if ($_REQUEST['mode'] == 'js') { header("Content-Type: text/javascript; charset=UTF-8"); print "var ERRORS = [];\n"; - foreach ($ERRORS as $id => $error) { + foreach (get_error_types() as $id => $error) { $error = preg_replace("/\n/", "", $error); $error = preg_replace("/\"/", "\\\"", $error); diff --git a/include/functions.php b/include/functions.php index ceb7fbd9e..2f4ee8e35 100644 --- a/include/functions.php +++ b/include/functions.php @@ -327,7 +327,7 @@ function sanity_check() { require_once 'errors.php'; - global $ERRORS; + $ERRORS = get_error_types(); $error_code = 0; $schema_version = get_schema_version(true); @@ -540,7 +540,7 @@ */ function error_json($code) { require_once "errors.php"; - global $ERRORS; + $ERRORS = get_error_types(); @$message = $ERRORS[$code]; From 936b91a7e656169c7cc2f4652ee4ab9114d11dbc Mon Sep 17 00:00:00 2001 From: wn Date: Sat, 12 Dec 2020 09:53:08 -0600 Subject: [PATCH 06/11] Don't do deprecated 'libxml_disable_entity_loader(true)' under PHP 8. https://github.com/php/php-src/blob/2d467abc46ec4ee97484d4e35909bed322600037/UPGRADING#L886 --- include/functions.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/functions.php b/include/functions.php index 2f4ee8e35..a70b4ac44 100644 --- a/include/functions.php +++ b/include/functions.php @@ -18,7 +18,10 @@ $fetch_effective_url = false; $fetch_curl_used = false; - libxml_disable_entity_loader(true); + if (version_compare(PHP_VERSION, '8.0.0', '<')) { + libxml_disable_entity_loader(true); + } + libxml_use_internal_errors(true); // separate test because this is included before sanity checks From c68f2aabc929221b6c5af5ff51d28b990f6cd0f1 Mon Sep 17 00:00:00 2001 From: wn Date: Sat, 12 Dec 2020 09:56:10 -0600 Subject: [PATCH 07/11] Make 'ttrss_error_handler' compatible w/ 8. https://github.com/php/php-src/blob/2d467abc46ec4ee97484d4e35909bed322600037/UPGRADING#L43 https://github.com/php/php-src/blob/2d467abc46ec4ee97484d4e35909bed322600037/UPGRADING#L63 --- include/errorhandler.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/errorhandler.php b/include/errorhandler.php index 95c9edc69..188c8c5ce 100644 --- a/include/errorhandler.php +++ b/include/errorhandler.php @@ -31,7 +31,13 @@ function format_backtrace($trace) { return $rv; } -function ttrss_error_handler($errno, $errstr, $file, $line, $context) { +function ttrss_error_handler($errno, $errstr, $file, $line) { + if (version_compare(PHP_VERSION, '8.0.0', '<')) { + if (error_reporting() == 0 || !$errno) return false; + } else { + if (!(error_reporting() & $errno)) return false; + } + if (error_reporting() == 0 || !$errno) return false; $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); From 95d0cb4953b93ed7b40556ff5c79327b0cde5c32 Mon Sep 17 00:00:00 2001 From: wn Date: Sat, 12 Dec 2020 10:04:22 -0600 Subject: [PATCH 08/11] Handle potential absence of a URL path in UrlHelper. --- classes/urlhelper.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/classes/urlhelper.php b/classes/urlhelper.php index cc1074c55..fec36de51 100644 --- a/classes/urlhelper.php +++ b/classes/urlhelper.php @@ -1,8 +1,9 @@ Date: Sat, 12 Dec 2020 10:09:25 -0600 Subject: [PATCH 09/11] Fix some 'isset' checks in 'classes/pref/prefs.php'. --- classes/pref/prefs.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index d7b486cbb..4e57ea846 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -1271,14 +1271,14 @@ class Pref_Prefs extends Handler_Protected { } private function getShortDesc($pref_name) { - if (isset($this->pref_help[$pref_name])) { + if (isset($this->pref_help[$pref_name][0])) { return $this->pref_help[$pref_name][0]; } return ""; } private function getHelpText($pref_name) { - if (isset($this->pref_help[$pref_name])) { + if (isset($this->pref_help[$pref_name][1])) { return $this->pref_help[$pref_name][1]; } return ""; From a1f8d6941ba4b0499f6a1177a8f451aa436d2bb5 Mon Sep 17 00:00:00 2001 From: wn Date: Sat, 12 Dec 2020 10:14:40 -0600 Subject: [PATCH 10/11] Remove duplicate block in 'classes/pref/filters.php'. Also a minor tweak to getting the search filter. --- classes/pref/filters.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 00644c59f..70b7d0326 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -736,10 +736,8 @@ class Pref_Filters extends Handler_Protected { } function index() { - - $filter_search = clean($_REQUEST["search"]); - if (array_key_exists("search", $_REQUEST)) { + $filter_search = clean($_REQUEST["search"]); $_SESSION["prefs_filter_search"] = $filter_search; } else { $filter_search = $_SESSION["prefs_filter_search"]; @@ -749,12 +747,6 @@ class Pref_Filters extends Handler_Protected { print "
"; print "
"; - if (array_key_exists("search", $_REQUEST)) { - $_SESSION["prefs_filter_search"] = $filter_search; - } else { - $filter_search = $_SESSION["prefs_filter_search"]; - } - print "
From 62da307ef147b32eb214edecf1541f8ce896a700 Mon Sep 17 00:00:00 2001 From: wn Date: Sat, 12 Dec 2020 10:18:50 -0600 Subject: [PATCH 11/11] Use correct 'sprintf' function and other minor fixes in Pref_Feeds. --- classes/pref/feeds.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index ca2c7b514..b19d161fd 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -126,6 +126,7 @@ class Pref_Feeds extends Handler_Protected { $root['id'] = 'root'; $root['name'] = __('Feeds'); $root['items'] = array(); + $root['param'] = 0; $root['type'] = 'category'; $enable_cats = get_pref('ENABLE_FEED_CATS'); @@ -229,7 +230,7 @@ class Pref_Feeds extends Handler_Protected { $cat['items'] = $this->get_category_items($line['id']); $num_children = $this->calculate_children_count($cat); - $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); + $cat['param'] = sprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); if ($num_children > 0 || $show_empty_cats) array_push($root['items'], $cat); @@ -277,13 +278,13 @@ class Pref_Feeds extends Handler_Protected { array_push($cat['items'], $feed); } - $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); + $cat['param'] = sprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); if (count($cat['items']) > 0 || $show_empty_cats) array_push($root['items'], $cat); $num_children = $this->calculate_children_count($root); - $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); + $root['param'] = sprintf(_ngettext('(%d feed)', '(%d feeds)', (int) $num_children), $num_children); } else { $fsth = $this->pdo->prepare("SELECT id, title, last_error, @@ -312,7 +313,7 @@ class Pref_Feeds extends Handler_Protected { array_push($root['items'], $feed); } - $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($root['items'])), count($root['items'])); + $root['param'] = sprintf(_ngettext('(%d feed)', '(%d feeds)', count($root['items'])), count($root['items'])); } $fl = array(); @@ -1198,10 +1199,11 @@ class Pref_Feeds extends Handler_Protected { } if ($num_errors > 0) { - $error_button = ""; + } else { + $error_button = ""; } $inactive_button = "