diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/controls_compat.php | 2 | ||||
| -rw-r--r-- | include/errorhandler.php | 12 | ||||
| -rw-r--r-- | include/functions.php | 82 | ||||
| -rw-r--r-- | include/sessions.php | 20 |
4 files changed, 17 insertions, 99 deletions
diff --git a/include/controls_compat.php b/include/controls_compat.php index d62265471..a4e9ad73f 100644 --- a/include/controls_compat.php +++ b/include/controls_compat.php @@ -128,7 +128,7 @@ function print_feed_multi_select($id, $default_ids = [], } } - if (get_pref('ENABLE_FEED_CATS')) { + if (get_pref(Prefs::ENABLE_FEED_CATS)) { if (!$root_id) $root_id = null; diff --git a/include/errorhandler.php b/include/errorhandler.php index 68e2285c1..1908bd39c 100644 --- a/include/errorhandler.php +++ b/include/errorhandler.php @@ -40,13 +40,13 @@ function format_backtrace($trace) { } function ttrss_error_handler($errno, $errstr, $file, $line) { - if (version_compare(PHP_VERSION, '8.0.0', '<')) { + /*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; + if (error_reporting() == 0 || !$errno) return false;*/ $file = substr(str_replace(dirname(__DIR__), "", $file), 1); @@ -54,12 +54,10 @@ function ttrss_error_handler($errno, $errstr, $file, $line) { $errstr = truncate_middle($errstr, 16384, " (...) "); if (class_exists("Logger")) - return Logger::get()->log_error($errno, $errstr, $file, $line, $context); + return Logger::log_error((int)$errno, $errstr, $file, (int)$line, $context); } function ttrss_fatal_handler() { - global $last_query; - $error = error_get_last(); if ($error !== NULL) { @@ -74,10 +72,8 @@ function ttrss_fatal_handler() { $file = substr(str_replace(dirname(__DIR__), "", $file), 1); - if ($last_query) $errstr .= " [Last query: $last_query]"; - if (class_exists("Logger")) - return Logger::get()->log_error($errno, $errstr, $file, $line, $context); + return Logger::log_error((int)$errno, $errstr, $file, (int)$line, $context); } return false; diff --git a/include/functions.php b/include/functions.php index d916301fb..e0580a076 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,5 +1,5 @@ <?php - define('SCHEMA_VERSION', 140); + define('SCHEMA_VERSION', 141); define('LABEL_BASE_INDEX', -1024); define('PLUGIN_FEED_BASE_INDEX', -128); @@ -42,12 +42,12 @@ define('SUBSTRING_FOR_DATE', 'SUBSTRING'); } - function get_pref($pref_name, $user_id = false, $die_on_error = false) { - return Db_Prefs::get()->read($pref_name, $user_id, $die_on_error); + function get_pref(string $pref_name, int $owner_uid = null) { + return Prefs::get($pref_name, $owner_uid ? $owner_uid : $_SESSION["uid"], $_SESSION["profile"] ?? null); } - function set_pref($pref_name, $value, $user_id = false, $strip_tags = true) { - return Db_Prefs::get()->write($pref_name, $value, $user_id, $strip_tags); + function set_pref(string $pref_name, $value, int $owner_uid = null, bool $strip_tags = true) { + return Prefs::set($pref_name, $value, $owner_uid ? $owner_uid : $_SESSION["uid"], $_SESSION["profile"] ?? null, $strip_tags); } function get_translations() { @@ -140,7 +140,7 @@ } if (!empty($_SESSION["uid"]) && get_schema_version() >= 120) { - $pref_locale = get_pref("USER_LANGUAGE", $_SESSION["uid"]); + $pref_locale = get_pref(Prefs::USER_LANGUAGE, $_SESSION["uid"]); if (!empty($pref_locale) && $pref_locale != 'auto') { $selected_locale = $pref_locale; @@ -166,8 +166,6 @@ define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . get_version() . ' (http://tt-rss.org/)'); ini_set('user_agent', SELF_USER_AGENT); - $schema_version = false; - /* compat shims */ function _debug($msg) { @@ -305,22 +303,8 @@ return $s ? 1 : 0; } - // Session caching removed due to causing wrong redirects to upgrade - // script when get_schema_version() is called on an obsolete session - // created on a previous schema version. - function get_schema_version($nocache = false) { - global $schema_version; - - $pdo = Db::pdo(); - - if (!$schema_version && !$nocache) { - $row = $pdo->query("SELECT schema_version FROM ttrss_version")->fetch(); - $version = $row["schema_version"]; - $schema_version = $version; - return $version; - } else { - return $schema_version; - } + function get_schema_version() { + return Config::get_schema_version(); } function file_is_locked($filename) { @@ -459,54 +443,6 @@ return in_array($interface, class_implements($class)); } - function T_js_decl($s1, $s2) { - if ($s1 && $s2) { - $s1 = preg_replace("/\n/", "", $s1); - $s2 = preg_replace("/\n/", "", $s2); - - $s1 = preg_replace("/\"/", "\\\"", $s1); - $s2 = preg_replace("/\"/", "\\\"", $s2); - - return "T_messages[\"$s1\"] = \"$s2\";\n"; - } - } - - function init_js_translations() { - - print 'var T_messages = new Object(); - - function __(msg) { - if (T_messages[msg]) { - return T_messages[msg]; - } else { - return msg; - } - } - - function ngettext(msg1, msg2, n) { - return __((parseInt(n) > 1) ? msg2 : msg1); - }'; - - global $text_domains; - - foreach (array_keys($text_domains) as $domain) { - $l10n = _get_reader($domain); - - for ($i = 0; $i < $l10n->total; $i++) { - $orig = $l10n->get_original_string($i); - if(strpos($orig, "\000") !== false) { // Plural forms - $key = explode(chr(0), $orig); - print T_js_decl($key[0], _ngettext($key[0], $key[1], 1)); // Singular - print T_js_decl($key[1], _ngettext($key[0], $key[1], 2)); // Plural - } else { - $translation = _dgettext($domain,$orig); - print T_js_decl($orig, $translation); - } - } - - } - } - function get_theme_path($theme) { $check = "themes/$theme"; if (file_exists($check)) return $check; @@ -578,7 +514,7 @@ $git_commit = $commit; $git_timestamp = $timestamp; - $ttrss_version['version'] = strftime("%y.%m", $timestamp) . "-$commit"; + $ttrss_version['version'] = strftime("%y.%m", (int)$timestamp) . "-$commit"; $ttrss_version['commit'] = $commit; $ttrss_version['timestamp'] = $timestamp; } diff --git a/include/sessions.php b/include/sessions.php index d4f21d8cd..891a6b3fa 100644 --- a/include/sessions.php +++ b/include/sessions.php @@ -19,25 +19,10 @@ ini_set("session.gc_maxlifetime", $session_expire); ini_set("session.cookie_lifetime", "0"); - function session_get_schema_version() { - global $schema_version; - - if (!$schema_version) { - $row = \Db::pdo()->query("SELECT schema_version FROM ttrss_version")->fetch(); - - $version = $row["schema_version"]; - - $schema_version = $version; - return $version; - } else { - return $schema_version; - } - } - function validate_session() { if (\Config::get(\Config::SINGLE_USER_MODE)) return true; - if (isset($_SESSION["ref_schema_version"]) && $_SESSION["ref_schema_version"] != session_get_schema_version()) { + if (isset($_SESSION["ref_schema_version"]) && $_SESSION["ref_schema_version"] != \Config::get_schema_version()) { $_SESSION["login_error_msg"] = __("Session failed to validate (schema version changed)"); return false; @@ -152,6 +137,7 @@ if (!defined('NO_SESSION_AUTOSTART')) { if (isset($_COOKIE[session_name()])) { - @session_start(); + if (session_status() != PHP_SESSION_ACTIVE) + session_start(); } } |