From a8cc43a0ff1cf6297577fae8536408287518baf4 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 15:31:03 +0300 Subject: move logout_user() to UserHelper --- classes/userhelper.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'classes/userhelper.php') diff --git a/classes/userhelper.php b/classes/userhelper.php index c9c4dd102..8eb97f5d0 100644 --- a/classes/userhelper.php +++ b/classes/userhelper.php @@ -105,7 +105,7 @@ class UserHelper { } if (empty($_SESSION["uid"])) { - Pref_Users::logout_user(); + UserHelper::logout(); Handler_Public::render_login_form(); exit; @@ -157,4 +157,16 @@ class UserHelper { return false; } + + static function logout() { + if (session_status() === PHP_SESSION_ACTIVE) + session_destroy(); + + if (isset($_COOKIE[session_name()])) { + setcookie(session_name(), '', time()-42000, '/'); + + } + session_commit(); + } + } -- cgit v1.2.3-54-g00ecf From 8e79f1717d5270558ffd30c20cc75840b0ecc955 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Feb 2021 16:07:22 +0300 Subject: prefs: unify naming --- classes/handler/public.php | 2 +- classes/pref/filters.php | 32 ++++++++++++++++---------------- classes/pref/prefs.php | 20 ++++++++++---------- classes/pref/system.php | 4 ++-- classes/pref/users.php | 8 ++++---- classes/rpc.php | 2 +- classes/userhelper.php | 4 ++-- 7 files changed, 36 insertions(+), 36 deletions(-) (limited to 'classes/userhelper.php') diff --git a/classes/handler/public.php b/classes/handler/public.php index b11c8ba04..ea2a0c5ef 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -950,7 +950,7 @@ class Handler_Public extends Handler { WHERE id = ?"); $sth->execute([$id]); - Pref_Users::resetUserPassword($id, true); + Pref_Users::_reset_password($id, true); print "

"."Completed."."

"; diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 62bcb8f59..95f0fcfc0 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -162,7 +162,7 @@ class Pref_Filters extends Handler_Protected { print json_encode($rv); } - private function getfilterrules_list($filter_id) { + private function _get_rules_list($filter_id) { $sth = $this->pdo->prepare("SELECT reg_exp, inverse, match_on, @@ -250,7 +250,7 @@ class Pref_Filters extends Handler_Protected { while ($line = $sth->fetch()) { - $name = $this->getFilterName($line["id"]); + $name = $this->_get_name($line["id"]); $match_ok = false; if ($filter_search) { @@ -292,7 +292,7 @@ class Pref_Filters extends Handler_Protected { $filter['checkbox'] = false; $filter['last_triggered'] = $line["last_triggered"] ? TimeHelper::make_local_datetime($line["last_triggered"], false) : null; $filter['enabled'] = sql_bool_to_bool($line["enabled"]); - $filter['rules'] = $this->getfilterrules_list($line['id']); + $filter['rules'] = $this->_get_rules_list($line['id']); if (!$filter_search || $match_ok) { array_push($folder['items'], $filter); @@ -391,7 +391,7 @@ class Pref_Filters extends Handler_Protected { $data = htmlspecialchars((string)json_encode($line)); print "
  • - ".$this->getRuleName($line)."". + ".$this->_get_rule_name($line)."". format_hidden("rule[]", $data)."
  • "; } } @@ -433,7 +433,7 @@ class Pref_Filters extends Handler_Protected { $data = htmlspecialchars((string)json_encode($line)); print "
  • - ".$this->getActionName($line)."". + ".$this->_get_action_name($line)."". format_hidden("action[]", $data)."
  • "; } } @@ -482,7 +482,7 @@ class Pref_Filters extends Handler_Protected { } } - private function getRuleName($rule) { + private function _get_rule_name($rule) { if (!$rule) $rule = json_decode(clean($_REQUEST["rule"]), true); $feeds = $rule["feed_id"]; @@ -523,10 +523,10 @@ class Pref_Filters extends Handler_Protected { } function printRuleName() { - print $this->getRuleName(json_decode(clean($_REQUEST["rule"]), true)); + print $this->_get_rule_name(json_decode(clean($_REQUEST["rule"]), true)); } - private function getActionName($action) { + private function _get_action_name($action) { $sth = $this->pdo->prepare("SELECT description FROM ttrss_filter_actions WHERE id = ?"); $sth->execute([(int)$action["action_id"]]); @@ -561,7 +561,7 @@ class Pref_Filters extends Handler_Protected { } function printActionName() { - print $this->getActionName(json_decode(clean($_REQUEST["action"]), true)); + print $this->_get_action_name(json_decode(clean($_REQUEST["action"]), true)); } function editSave() { @@ -581,7 +581,7 @@ class Pref_Filters extends Handler_Protected { $sth->execute([$enabled, $match_any_rule, $inverse, $title, $filter_id, $_SESSION['uid']]); - $this->saveRulesAndActions($filter_id); + $this->_save_rules_and_actions($filter_id); $this->pdo->commit(); } @@ -596,7 +596,7 @@ class Pref_Filters extends Handler_Protected { $sth->execute(array_merge($ids, [$_SESSION['uid']])); } - private function saveRulesAndActions($filter_id) + private function _save_rules_and_actions($filter_id) { $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2_rules WHERE filter_id = ?"); @@ -696,7 +696,7 @@ class Pref_Filters extends Handler_Protected { if ($row = $sth->fetch()) { $filter_id = $row['id']; - $this->saveRulesAndActions($filter_id); + $this->_save_rules_and_actions($filter_id); } $this->pdo->commit(); @@ -941,7 +941,7 @@ class Pref_Filters extends Handler_Protected { print ""; } - private function getFilterName($id) { + private function _get_name($id) { $sth = $this->pdo->prepare( "SELECT title,match_any_rule,f.inverse AS inverse,COUNT(DISTINCT r.id) AS num_rules,COUNT(DISTINCT a.id) AS num_actions @@ -970,7 +970,7 @@ class Pref_Filters extends Handler_Protected { $actions = ""; if ($line = $sth->fetch()) { - $actions = $this->getActionName($line); + $actions = $this->_get_action_name($line); $num_actions -= 1; } @@ -1012,12 +1012,12 @@ class Pref_Filters extends Handler_Protected { $this->pdo->commit(); - $this->optimizeFilter($base_id); + $this->_optimize($base_id); } } - private function optimizeFilter($id) { + private function _optimize($id) { $this->pdo->beginTransaction(); diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 6e4deb223..81b7767eb 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -268,7 +268,7 @@ class Pref_Prefs extends Handler_Protected { AND owner_uid = :uid"); $sth->execute([":profile" => $_SESSION['profile'], ":uid" => $_SESSION['uid']]); - $this->initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]); + $this->_init_user_prefs($_SESSION["uid"], $_SESSION["profile"]); echo __("Your preferences are now set to default values."); } @@ -588,9 +588,9 @@ class Pref_Prefs extends Handler_Protected { if ($profile) { print_notice(__("Some preferences are only available in default profile.")); - $this->initialize_user_prefs($_SESSION["uid"], $profile); + $this->_init_user_prefs($_SESSION["uid"], $profile); } else { - $this->initialize_user_prefs($_SESSION["uid"]); + $this->_init_user_prefs($_SESSION["uid"]); } $prefs_available = []; @@ -621,7 +621,7 @@ class Pref_Prefs extends Handler_Protected { } $pref_name = $line["pref_name"]; - $short_desc = $this->getShortDesc($pref_name); + $short_desc = $this->_get_short_desc($pref_name); if (!$short_desc) continue; @@ -629,7 +629,7 @@ class Pref_Prefs extends Handler_Protected { $prefs_available[$pref_name] = [ 'type_name' => $line["type_name"], 'value' => $line['value'], - 'help_text' => $this->getHelpText($pref_name), + 'help_text' => $this->_get_help_text($pref_name), 'short_desc' => $short_desc ]; } @@ -1318,14 +1318,14 @@ class Pref_Prefs extends Handler_Protected { } - private function getShortDesc($pref_name) { + private function _get_short_desc($pref_name) { if (isset($this->pref_help[$pref_name][0])) { return $this->pref_help[$pref_name][0]; } return ""; } - private function getHelpText($pref_name) { + private function _get_help_text($pref_name) { if (isset($this->pref_help[$pref_name][1])) { return $this->pref_help[$pref_name][1]; } @@ -1380,7 +1380,7 @@ class Pref_Prefs extends Handler_Protected { encryptAppPassword($new_password); + $new_password_hash = $this->_encrypt_app_password($new_password); print_warning(T_sprintf("Generated password %s for %s. Please remember it for future reference.", $new_password, $title)); @@ -1413,7 +1413,7 @@ class Pref_Prefs extends Handler_Protected { $this->appPasswordList(); } - static function initialize_user_prefs($uid, $profile = false) { + static function _init_user_prefs($uid, $profile = false) { if (get_schema_version() < 63) $profile_qpart = ""; diff --git a/classes/pref/system.php b/classes/pref/system.php index 2a97ec6f0..f0a5f7b7f 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -23,7 +23,7 @@ class Pref_System extends Handler_Administrative { print preg_replace( '%^.*(.*).*$%ms','$1', (string)$info); } - private function log_viewer(int $page, int $severity) { + private function _log_viewer(int $page, int $severity) { $errno_values = []; switch ($severity) { @@ -154,7 +154,7 @@ class Pref_System extends Handler_Administrative {
    '> log_viewer($page, $severity); + $this->_log_viewer($page, $severity); } else { print_notice("Please set LOG_DESTINATION to 'sql' in config.php to enable database logging."); } diff --git a/classes/pref/users.php b/classes/pref/users.php index bc125d0ce..d2dd06fd8 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -166,7 +166,7 @@ class Pref_Users extends Handler_Administrative { } } - static function resetUserPassword($uid, $format_output = false) { + static function _reset_password($uid, $format_output = false) { $pdo = Db::pdo(); @@ -199,7 +199,7 @@ class Pref_Users extends Handler_Administrative { function resetPass() { $uid = clean($_REQUEST["id"]); - self::resetUserPassword($uid); + self::_reset_password($uid); } function index() { @@ -220,7 +220,7 @@ class Pref_Users extends Handler_Administrative { $sort = "login"; } - $sort = $this->validate_field($sort, + $sort = $this->_validate_field($sort, ["login", "access_level", "created", "num_feeds", "created", "last_login"], "login"); if ($sort != "login") $sort = "$sort DESC"; @@ -314,7 +314,7 @@ class Pref_Users extends Handler_Administrative { Date: Mon, 15 Feb 2021 16:59:54 +0300 Subject: move reset_password to UserHelper --- classes/handler/public.php | 2 +- classes/pref/users.php | 34 +--------------------------------- classes/userhelper.php | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 34 deletions(-) (limited to 'classes/userhelper.php') diff --git a/classes/handler/public.php b/classes/handler/public.php index ca963d111..da1e53853 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -950,7 +950,7 @@ class Handler_Public extends Handler { WHERE id = ?"); $sth->execute([$id]); - Pref_Users::_reset_password($id, true); + UserHelper::reset_password($id, true); print "

    "."Completed."."

    "; diff --git a/classes/pref/users.php b/classes/pref/users.php index d2dd06fd8..ab1694564 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -166,40 +166,8 @@ class Pref_Users extends Handler_Administrative { } } - static function _reset_password($uid, $format_output = false) { - - $pdo = Db::pdo(); - - $sth = $pdo->prepare("SELECT login FROM ttrss_users WHERE id = ?"); - $sth->execute([$uid]); - - if ($row = $sth->fetch()) { - - $login = $row["login"]; - - $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); - $tmp_user_pwd = make_password(); - - $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true); - - $sth = $pdo->prepare("UPDATE ttrss_users - SET pwd_hash = ?, salt = ?, otp_enabled = false - WHERE id = ?"); - $sth->execute([$pwd_hash, $new_salt, $uid]); - - $message = T_sprintf("Changed password of user %s to %s", "$login", "$tmp_user_pwd"); - - if ($format_output) - print_notice($message); - else - print $message; - - } - } - function resetPass() { - $uid = clean($_REQUEST["id"]); - self::_reset_password($uid); + UserHelper::reset_password(clean($_REQUEST["id"])); } function index() { diff --git a/classes/userhelper.php b/classes/userhelper.php index 744f77a23..8e9b9a01b 100644 --- a/classes/userhelper.php +++ b/classes/userhelper.php @@ -169,4 +169,34 @@ class UserHelper { session_commit(); } + static function reset_password($uid, $format_output = false) { + + $pdo = Db::pdo(); + + $sth = $pdo->prepare("SELECT login FROM ttrss_users WHERE id = ?"); + $sth->execute([$uid]); + + if ($row = $sth->fetch()) { + + $login = $row["login"]; + + $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250); + $tmp_user_pwd = make_password(); + + $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true); + + $sth = $pdo->prepare("UPDATE ttrss_users + SET pwd_hash = ?, salt = ?, otp_enabled = false + WHERE id = ?"); + $sth->execute([$pwd_hash, $new_salt, $uid]); + + $message = T_sprintf("Changed password of user %s to %s", "$login", "$tmp_user_pwd"); + + if ($format_output) + print_notice($message); + else + print $message; + + } + } } -- cgit v1.2.3-54-g00ecf From 9d7ba773ec97bfb44601348c07e818f1a1d2c841 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 17:13:16 +0300 Subject: move session-related functions to their own namespace --- api/index.php | 2 +- backend.php | 2 +- classes/userhelper.php | 2 +- include/sessions.php | 27 +++++++++++++++------------ 4 files changed, 18 insertions(+), 15 deletions(-) (limited to 'classes/userhelper.php') diff --git a/api/index.php b/api/index.php index 664e92abe..eb79422f9 100644 --- a/api/index.php +++ b/api/index.php @@ -50,7 +50,7 @@ if (!init_plugins()) return; if (!empty($_SESSION["uid"])) { - if (!validate_session()) { + if (!\Sessions\validate_session()) { header("Content-Type: text/json"); print json_encode(array("seq" => -1, diff --git a/backend.php b/backend.php index 89b06b7eb..9ecc22914 100644 --- a/backend.php +++ b/backend.php @@ -45,7 +45,7 @@ } if (!empty($_SESSION["uid"])) { - if (!validate_session()) { + if (!\Sessions\validate_session()) { header("Content-Type: text/json"); print error_json(6); return; diff --git a/classes/userhelper.php b/classes/userhelper.php index 8e9b9a01b..42d50a0f4 100644 --- a/classes/userhelper.php +++ b/classes/userhelper.php @@ -94,7 +94,7 @@ class UserHelper { startup_gettext(); self::load_user_plugins($_SESSION["uid"]); } else { - if (!validate_session()) $_SESSION["uid"] = false; + if (!\Sessions\validate_session()) $_SESSION["uid"] = false; if (empty($_SESSION["uid"])) { diff --git a/include/sessions.php b/include/sessions.php index 4de894c95..16de53ab2 100644 --- a/include/sessions.php +++ b/include/sessions.php @@ -1,4 +1,6 @@ query("SELECT schema_version FROM ttrss_version")->fetch(); + $row = \Db::pdo()->query("SELECT schema_version FROM ttrss_version")->fetch(); $version = $row["schema_version"]; @@ -42,7 +44,7 @@ __("Session failed to validate (schema version changed)"); return false; } - $pdo = Db::pdo(); + $pdo = \Db::pdo(); if (!empty($_SESSION["uid"])) { @@ -85,7 +87,7 @@ function ttrss_read ($id){ global $session_expire; - $sth = Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?"); + $sth = \Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?"); $sth->execute([$id]); if ($row = $sth->fetch()) { @@ -94,7 +96,7 @@ } else { $expire = time() + $session_expire; - $sth = Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) + $sth = \Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) VALUES (?, '', ?)"); $sth->execute([$id, $expire]); @@ -110,14 +112,14 @@ $data = base64_encode($data); $expire = time() + $session_expire; - $sth = Db::pdo()->prepare("SELECT id FROM ttrss_sessions WHERE id=?"); + $sth = \Db::pdo()->prepare("SELECT id FROM ttrss_sessions WHERE id=?"); $sth->execute([$id]); if ($row = $sth->fetch()) { - $sth = Db::pdo()->prepare("UPDATE ttrss_sessions SET data=?, expire=? WHERE id=?"); + $sth = \Db::pdo()->prepare("UPDATE ttrss_sessions SET data=?, expire=? WHERE id=?"); $sth->execute([$data, $expire, $id]); } else { - $sth = Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) + $sth = \Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire) VALUES (?, ?, ?)"); $sth->execute([$id, $data, $expire]); } @@ -130,22 +132,23 @@ } function ttrss_destroy($id) { - $sth = Db::pdo()->prepare("DELETE FROM ttrss_sessions WHERE id = ?"); + $sth = \Db::pdo()->prepare("DELETE FROM ttrss_sessions WHERE id = ?"); $sth->execute([$id]); return true; } function ttrss_gc ($expire) { - Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time()); + \Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time()); return true; } if (!SINGLE_USER_MODE /* && DB_TYPE == "pgsql" */) { - session_set_save_handler("ttrss_open", - "ttrss_close", "ttrss_read", "ttrss_write", - "ttrss_destroy", "ttrss_gc"); + session_set_save_handler('\Sessions\ttrss_open', + '\Sessions\ttrss_close', '\Sessions\ttrss_read', + '\Sessions\ttrss_write', '\Sessions\ttrss_destroy', + '\Sessions\ttrss_gc'); register_shutdown_function('session_write_close'); } -- cgit v1.2.3-54-g00ecf From fc0ebf089189ca42875d31b1bec4aa1c27852506 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 20:21:36 +0300 Subject: move bookmarklet-related methods out of public.php into the plugin --- classes/handler/public.php | 321 +--------------------------------------- classes/pluginhost.php | 4 +- classes/userhelper.php | 2 +- include/controls.php | 4 + plugins/bookmarklets/init.php | 331 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 335 insertions(+), 327 deletions(-) (limited to 'classes/userhelper.php') diff --git a/classes/handler/public.php b/classes/handler/public.php index de3165e2f..62543859c 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -98,7 +98,7 @@ class Handler_Public extends Handler { $tpl->setVariable('ARTICLE_ID', htmlspecialchars($orig_guid ? $line['link'] : - $this->make_article_tag_uri($line['id'], $line['date_entered'])), true); + $this->_make_article_tag_uri($line['id'], $line['date_entered'])), true); $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true); $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true); $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true); @@ -346,165 +346,6 @@ class Handler_Public extends Handler { PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK); } - function sharepopup() { - if (SINGLE_USER_MODE) { - UserHelper::login_sequence(); - } - - header('Content-Type: text/html; charset=utf-8'); - ?> - - - - <?= __("Share with Tiny Tiny RSS") ?> - - - - - - - - -
    - - "; - print "window.close();"; - print ""; - - } else { - $title = htmlspecialchars(clean($_REQUEST["title"])); - $url = htmlspecialchars(clean($_REQUEST["url"])); - - ?> -
    - - - - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    -
    - -
    - -
    - - - -
    - -
    - - - - -
    - - - -
    - - " /> -
    - -
    - - - "/> -
    - -
    - -
    - - - -
    - -
    - "; - } - function login() { if (!SINGLE_USER_MODE) { @@ -565,160 +406,6 @@ class Handler_Public extends Handler { } } - function subscribe() { - if (SINGLE_USER_MODE) { - UserHelper::login_sequence(); - } - - if (!empty($_SESSION["uid"])) { - - $feed_url = clean($_REQUEST["feed_url"] ?? ""); - $csrf_token = clean($_POST["csrf_token"] ?? ""); - - header('Content-Type: text/html; charset=utf-8'); - ?> - - - - Tiny Tiny RSS - - - - - - - - -
    -

    -
    - -
    - - -
    - - -
    - - - - -
    - %s.", $feed_url)); - break; - case 1: - print_notice(T_sprintf("Subscribed to %s.", $feed_url)); - break; - case 2: - print_error(T_sprintf("Could not subscribe to %s.", $feed_url)); - break; - case 3: - print_error(T_sprintf("No feeds found in %s.", $feed_url)); - break; - case 4: - $feed_urls = $rc["feeds"]; - break; - case 5: - print_error(T_sprintf("Could not subscribe to %s.
    Can't download the Feed URL.", $feed_url)); - break; - } - - if ($feed_urls) { - - print "
    "; - print ""; - print \Controls\hidden_tag("csrf_token", $_SESSION["csrf_token"]); - - print "
    "; - print ""; - print ""; - print "
    "; - - print ""; - print "".__("Return to Tiny Tiny RSS").""; - - print "
    "; - } - - $tp_uri = get_self_url_prefix() . "/prefs.php"; - - if ($rc['code'] <= 2){ - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE - feed_url = ? AND owner_uid = ?"); - $sth->execute([$feed_url, $_SESSION['uid']]); - $row = $sth->fetch(); - - $feed_id = $row["id"]; - } else { - $feed_id = 0; - } - - if ($feed_id) { - print "
    - - - - - ".__("Return to Tiny Tiny RSS")." -
    "; - } - } - - print "
    "; - - } else { - $this->render_login_form(); - } - } - function index() { header("Content-Type: text/plain"); print error_json(13); @@ -928,7 +615,7 @@ class Handler_Public extends Handler { if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); - $this->render_login_form(); + $this->_render_login_form(); exit; } @@ -1066,7 +753,7 @@ class Handler_Public extends Handler { } } - private function make_article_tag_uri($id, $timestamp) { + private function _make_article_tag_uri($id, $timestamp) { $timestamp = date("Y-m-d", strtotime($timestamp)); @@ -1108,7 +795,7 @@ class Handler_Public extends Handler { } } - static function render_login_form() { + static function _render_login_form() { header('Cache-Control: public'); require_once "login_form.php"; diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 065fa99c4..d50c5a706 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -599,7 +599,7 @@ class PluginHost { } // handled by classes/pluginhandler.php, requires valid session - function get_method_url(Plugin $sender, string $method, $params) { + function get_method_url(Plugin $sender, string $method, $params = []) { return get_self_url_prefix() . "/backend.php?" . http_build_query( array_merge( @@ -623,7 +623,7 @@ class PluginHost { } */ // WARNING: endpoint in public.php, exposed to unauthenticated users - function get_public_method_url(Plugin $sender, string $method, $params) { + function get_public_method_url(Plugin $sender, string $method, $params = []) { if ($sender->is_public_method($method)) { return get_self_url_prefix() . "/public.php?" . http_build_query( diff --git a/classes/userhelper.php b/classes/userhelper.php index 42d50a0f4..7fe1e5557 100644 --- a/classes/userhelper.php +++ b/classes/userhelper.php @@ -107,7 +107,7 @@ class UserHelper { if (empty($_SESSION["uid"])) { UserHelper::logout(); - Handler_Public::render_login_form(); + Handler_Public::_render_login_form(); exit; } diff --git a/include/controls.php b/include/controls.php index a60b1e0b0..ae5fba739 100755 --- a/include/controls.php +++ b/include/controls.php @@ -16,6 +16,10 @@ return hidden_tag("op", strtolower(get_class($plugin) . \PluginHost::PUBLIC_METHOD_DELIMITER . $method)); } */ + function public_method_tags(\Plugin $plugin, string $method) { + return hidden_tag("op", strtolower(get_class($plugin) . \PluginHost::PUBLIC_METHOD_DELIMITER . $method)); + } + function pluginhandler_tags(\Plugin $plugin, string $method) { return hidden_tag("op", "pluginhandler") . hidden_tag("plugin", strtolower(get_class($plugin))) . diff --git a/plugins/bookmarklets/init.php b/plugins/bookmarklets/init.php index a9dc3e69d..4c3bbf4cc 100644 --- a/plugins/bookmarklets/init.php +++ b/plugins/bookmarklets/init.php @@ -16,21 +16,338 @@ class Bookmarklets extends Plugin { $host->add_hook($host::HOOK_PREFS_TAB, $this); } - private function subscribe_to_feed_url() { - $url_path = get_self_url_prefix() . - "/public.php?op=subscribe&feed_url=%s"; - return $url_path; + function is_public_method($method) { + return in_array($method, ["subscribe", "sharepopup"]); } + function subscribe() { + if (SINGLE_USER_MODE) { + UserHelper::login_sequence(); + } + + if (!empty($_SESSION["uid"])) { + + $feed_url = clean($_REQUEST["feed_url"] ?? ""); + $csrf_token = clean($_POST["csrf_token"] ?? ""); + + header('Content-Type: text/html; charset=utf-8'); + ?> + + + + <?= __("Subscribe to feed...") ?> + + + + + + + + + + + +
    +

    +
    + +
    + + + +
    + + +
    + + + + +
    + %s.", $feed_url)); + break; + case 1: + print_notice(T_sprintf("Subscribed to %s.", $feed_url)); + break; + case 2: + print_error(T_sprintf("Could not subscribe to %s.", $feed_url)); + break; + case 3: + print_error(T_sprintf("No feeds found in %s.", $feed_url)); + break; + case 4: + $feed_urls = $rc["feeds"]; + break; + case 5: + print_error(T_sprintf("Could not subscribe to %s.
    Can't download the Feed URL.", $feed_url)); + break; + } + + if ($feed_urls) { + + print "
    "; + print \Controls\public_method_tags($this, "subscribe"); + print \Controls\hidden_tag("csrf_token", $_SESSION["csrf_token"]); + + print "
    "; + print ""; + print ""; + print "
    "; + + print ""; + print "".__("Return to Tiny Tiny RSS").""; + + print "
    "; + } + + $tp_uri = get_self_url_prefix() . "/prefs.php"; + + if ($rc['code'] <= 2){ + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE + feed_url = ? AND owner_uid = ?"); + $sth->execute([$feed_url, $_SESSION['uid']]); + $row = $sth->fetch(); + + $feed_id = $row["id"]; + } else { + $feed_id = 0; + } + + if ($feed_id) { + print "
    + + + + + ".__("Return to Tiny Tiny RSS")." +
    "; + } + } + + print "
    "; + } else { + Handler_Public::_render_login_form(); + } + } + + function sharepopup() { + if (SINGLE_USER_MODE) { + UserHelper::login_sequence(); + } + + header('Content-Type: text/html; charset=utf-8'); + ?> + + + + <?= __("Share with Tiny Tiny RSS") ?> + + + + + + + + + + + +
    + + "; + print "window.close();"; + print ""; + + } else { + $title = htmlspecialchars(clean($_REQUEST["title"])); + $url = htmlspecialchars(clean($_REQUEST["url"])); + + ?> +
    + + + + + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + + +
    + +
    + +
    + + "window.close()"]) ?> + +
    + +
    + + +
    + + + +
    + + " /> +
    + +
    + + + "/> +
    + +
    + +
    + + + +
    + +
    + +
    + + "; + subscribe_to_feed_url()); + $bm_subscribe_url = $this->host->get_public_method_url($this, "subscribe"); + $bm_share_url = $this->host->get_public_method_url($this, "sharepopup"); + $confirm_str = str_replace("'", "\'", __('Subscribe to %s in Tiny Tiny RSS?')); - $bm_subscribe_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+encodeURIComponent(window.location.href)}"); - $bm_share_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='".get_self_url_prefix()."/public.php?op=sharepopup',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=250')){l.href=g;}}a();})()"); + $bm_subscribe_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url&feed_url='+encodeURIComponent(window.location.href)}"); + $bm_share_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='$bm_share_url',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=250')){l.href=g;}}a();})()"); + + //$bm_subscribe_url = str_replace('%s', '', $this->subscribe_to_feed_url()); + //$confirm_str = str_replace("'", "\'", __('Subscribe to %s in Tiny Tiny RSS?')); + //$bm_subscribe_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+encodeURIComponent(window.location.href)}"); + + //$bm_share_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='".get_self_url_prefix()."/public.php?op=sharepopup',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=250')){l.href=g;}}a();})()"); ?>
    Date: Mon, 22 Feb 2021 21:47:48 +0300 Subject: wip: initial for config object --- backend.php | 2 +- classes/api.php | 9 ++++--- classes/article.php | 6 ++--- classes/db.php | 12 ++++----- classes/digest.php | 12 ++++----- classes/diskcache.php | 6 ++--- classes/feeditem/common.php | 2 +- classes/feeds.php | 36 +++++++++++++-------------- classes/handler/public.php | 18 +++++++------- classes/opml.php | 2 +- classes/pref/feeds.php | 18 +++++++------- classes/pref/prefs.php | 16 ++++++------ classes/rpc.php | 12 ++++----- classes/rssutils.php | 40 +++++++++++++++--------------- classes/userhelper.php | 6 ++--- include/autoload.php | 2 -- include/functions.php | 24 +++++++++--------- include/login_form.php | 6 ++--- include/sanity_check.php | 54 ++++++++++++++--------------------------- include/sanity_config.php | 3 --- include/sessions.php | 7 +++--- index.php | 2 ++ phpstan.neon | 2 +- plugins/af_psql_trgm/init.php | 4 +-- plugins/af_redditimgur/init.php | 2 +- plugins/auth_internal/init.php | 2 +- plugins/bookmarklets/init.php | 4 +-- update.php | 28 ++++++++++----------- update_daemon2.php | 10 ++++---- utils/regen_config_checks.sh | 17 ------------- 30 files changed, 165 insertions(+), 199 deletions(-) delete mode 100644 include/sanity_config.php delete mode 100755 utils/regen_config_checks.sh (limited to 'classes/userhelper.php') diff --git a/backend.php b/backend.php index b6b3e0030..2237c06b3 100644 --- a/backend.php +++ b/backend.php @@ -40,7 +40,7 @@ header("Content-Type: text/json; charset=utf-8"); - if (SINGLE_USER_MODE) { + if (Config::get(Config::SINGLE_USER_MODE)) { UserHelper::authenticate( "admin", null); } diff --git a/classes/api.php b/classes/api.php index 5677cb908..6f3ee77db 100755 --- a/classes/api.php +++ b/classes/api.php @@ -57,7 +57,7 @@ class API extends Handler { $password = clean($_REQUEST["password"]); $password_base64 = base64_decode(clean($_REQUEST["password"])); - if (SINGLE_USER_MODE) $login = "admin"; + if (Config::get(Config::SINGLE_USER_MODE)) $login = "admin"; if ($uid = UserHelper::find_user_by_login($login)) { if (get_pref("ENABLE_API_ACCESS", $uid)) { @@ -361,9 +361,10 @@ class API extends Handler { } function getConfig() { - $config = array( - "icons_dir" => ICONS_DIR, - "icons_url" => ICONS_URL); + $config = [ + "icons_dir" => Config::get(Config::ICONS_DIR), + "icons_url" => Config::get(Config::ICONS_URL) + ]; $config["daemon_is_running"] = file_is_locked("update_daemon.lock"); diff --git a/classes/article.php b/classes/article.php index acd83694c..a2a38118b 100755 --- a/classes/article.php +++ b/classes/article.php @@ -85,7 +85,7 @@ class Article extends Handler_Protected { content = ?, content_hash = ? WHERE id = ?"); $sth->execute([$content, $content_hash, $ref_id]); - if (DB_TYPE == "pgsql"){ + if (Config::get(Config::DB_TYPE) == "pgsql") { $sth = $pdo->prepare("UPDATE ttrss_entries SET tsvector_combined = to_tsvector( :ts_content) WHERE id = :id"); @@ -130,7 +130,7 @@ class Article extends Handler_Protected { if ($row = $sth->fetch()) { $ref_id = $row["id"]; - if (DB_TYPE == "pgsql"){ + if (Config::get(Config::DB_TYPE) == "pgsql"){ $sth = $pdo->prepare("UPDATE ttrss_entries SET tsvector_combined = to_tsvector( :ts_content) WHERE id = :id"); @@ -475,7 +475,7 @@ class Article extends Handler_Protected { // purge orphaned posts in main content table - if (DB_TYPE == "mysql") + if (Config::get(Config::DB_TYPE) == "mysql") $limit_qpart = "LIMIT 5000"; else $limit_qpart = ""; diff --git a/classes/db.php b/classes/db.php index 490cecd57..1ccaa3533 100755 --- a/classes/db.php +++ b/classes/db.php @@ -21,9 +21,9 @@ class Db $db_host = defined('DB_HOST') && DB_HOST ? ';host=' . DB_HOST : ''; try { - $pdo = new PDO(DB_TYPE . ':dbname=' . DB_NAME . $db_host . $db_port, - DB_USER, - DB_PASS); + $pdo = new PDO(Config::get(Config::DB_TYPE) . ':dbname=' . Config::get(Config::DB_NAME) . $db_host . $db_port, + Config::get(Config::DB_USER), + Config::get(Config::DB_PASS)); } catch (Exception $e) { print "
    Exception while creating PDO object:" . $e->getMessage() . "
    "; exit(101); @@ -31,14 +31,14 @@ class Db $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $pdo->query("set client_encoding = 'UTF-8'"); $pdo->query("set datestyle = 'ISO, european'"); $pdo->query("set TIME ZONE 0"); $pdo->query("set cpu_tuple_cost = 0.5"); - } else if (DB_TYPE == "mysql") { + } else if (Config::get(Config::DB_TYPE) == "mysql") { $pdo->query("SET time_zone = '+0:0'"); if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { @@ -68,7 +68,7 @@ class Db } public static function sql_random_function() { - if (DB_TYPE == "mysql") { + if (Config::get(Config::DB_TYPE) == "mysql") { return "RAND()"; } else { return "RANDOM()"; diff --git a/classes/digest.php b/classes/digest.php index e0c23d705..9ac3f6a17 100644 --- a/classes/digest.php +++ b/classes/digest.php @@ -8,9 +8,9 @@ class Digest Debug::log("Sending digests, batch of max $user_limit users, headline limit = $limit"); - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $interval_qpart = "last_digest_sent < NOW() - INTERVAL '1 days'"; - } else /* if (DB_TYPE == "mysql") */ { + } else /* if (Config::get(Config::DB_TYPE) == "mysql") */ { $interval_qpart = "last_digest_sent < DATE_SUB(NOW(), INTERVAL 1 DAY)"; } @@ -91,19 +91,19 @@ class Digest $tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); $tpl->setVariable('CUR_TIME', date('G:i', $local_ts)); - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); + $tpl->setVariable('TTRSS_HOST', Config::get(Config.Config::get(Config::SELF_URL_PATH))); $tpl_t->setVariable('CUR_DATE', date('Y/m/d', $local_ts)); $tpl_t->setVariable('CUR_TIME', date('G:i', $local_ts)); - $tpl_t->setVariable('TTRSS_HOST', SELF_URL_PATH); + $tpl_t->setVariable('TTRSS_HOST', Config::get(Config.Config::get(Config::SELF_URL_PATH))); $affected_ids = array(); $days = (int) $days; - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'"; - } else /* if (DB_TYPE == "mysql") */ { + } else /* if (Config::get(Config::DB_TYPE) == "mysql") */ { $interval_qpart = "ttrss_entries.date_updated > DATE_SUB(NOW(), INTERVAL $days DAY)"; } diff --git a/classes/diskcache.php b/classes/diskcache.php index 94f645f32..063a3847c 100644 --- a/classes/diskcache.php +++ b/classes/diskcache.php @@ -191,7 +191,7 @@ class DiskCache { ]; public function __construct($dir) { - $this->dir = CACHE_DIR . "/" . basename(clean($dir)); + $this->dir = Config::get(Config::CACHE_DIR) . "/" . basename(clean($dir)); } public function get_dir() { @@ -339,7 +339,7 @@ class DiskCache { } static function expire() { - $dirs = array_filter(glob(CACHE_DIR . "/*"), "is_dir"); + $dirs = array_filter(glob(Config::get(Config::CACHE_DIR) . "/*"), "is_dir"); foreach ($dirs as $cache_dir) { $num_deleted = 0; @@ -396,7 +396,7 @@ class DiskCache { $tmppluginhost = new PluginHost(); - $tmppluginhost->load(PLUGINS, PluginHost::KIND_SYSTEM); + $tmppluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_SYSTEM); //$tmppluginhost->load_data(); if ($tmppluginhost->run_hooks_until(PluginHost::HOOK_SEND_LOCAL_FILE, true, $filename)) diff --git a/classes/feeditem/common.php b/classes/feeditem/common.php index f387e0779..8f2b9188b 100755 --- a/classes/feeditem/common.php +++ b/classes/feeditem/common.php @@ -179,7 +179,7 @@ abstract class FeedItem_Common extends FeedItem { $cat = preg_replace('/[,\'\"]/', "", $cat); - if (DB_TYPE == "mysql") { + if (Config::get(Config::DB_TYPE) == "mysql") { $cat = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $cat); } diff --git a/classes/feeds.php b/classes/feeds.php index b59504c03..274cb22d0 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -186,7 +186,7 @@ class Feeds extends Handler_Protected { $id = $line["id"]; // frontend doesn't expect pdo returning booleans as strings on mysql - if (DB_TYPE == "mysql") { + if (Config::get(Config::DB_TYPE) == "mysql") { foreach (["unread", "marked", "published"] as $k) { $line[$k] = $line[$k] === "1"; } @@ -576,7 +576,7 @@ class Feeds extends Handler_Protected { function search() { print json_encode([ - "show_language" => DB_TYPE == "pgsql", + "show_language" => Config::get(Config::DB_TYPE) == "pgsql", "show_syntax_help" => count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0, "all_languages" => Pref_Feeds::get_ts_languages(), "default_language" => get_pref('DEFAULT_SEARCH_LANGUAGE') @@ -716,21 +716,21 @@ class Feeds extends Handler_Protected { switch ($mode) { case "1day": - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $date_qpart = "date_entered < NOW() - INTERVAL '1 day' "; } else { $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) "; } break; case "1week": - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $date_qpart = "date_entered < NOW() - INTERVAL '1 week' "; } else { $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; } break; case "2week": - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $date_qpart = "date_entered < NOW() - INTERVAL '2 week' "; } else { $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) "; @@ -807,7 +807,7 @@ class Feeds extends Handler_Protected { $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE"); - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $match_part = "date_entered > NOW() - INTERVAL '$intl hour' "; } else { $match_part = "date_entered > DATE_SUB(NOW(), @@ -900,7 +900,7 @@ class Feeds extends Handler_Protected { $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid); - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; } else { $match_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; @@ -1332,7 +1332,7 @@ class Feeds extends Handler_Protected { list($search_query_part, $search_words) = self::_search_to_sql($search, $search_language, $owner_uid); } - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $test_sth = $pdo->prepare("select $search_query_part FROM ttrss_entries, ttrss_user_entries WHERE id = ref_id limit 1"); @@ -1469,7 +1469,7 @@ class Feeds extends Handler_Protected { } else if ($feed == -6) { // recently read $query_strategy_part = "unread = false AND last_read IS NOT NULL"; - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $query_strategy_part .= " AND last_read > NOW() - INTERVAL '1 DAY' "; } else { $query_strategy_part .= " AND last_read > DATE_SUB(NOW(), INTERVAL 1 DAY) "; @@ -1486,7 +1486,7 @@ class Feeds extends Handler_Protected { $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid); - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; } else { $query_strategy_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; @@ -1605,7 +1605,7 @@ class Feeds extends Handler_Protected { if ($feed == -3) $first_id_query_strategy_part = "true"; - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND"; $yyiw_qpart = "to_char(date_entered, 'IYYY-IW') AS yyiw"; @@ -1705,7 +1705,7 @@ class Feeds extends Handler_Protected { } else { // browsing by tag - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $distinct_columns = str_replace("desc", "", strtolower($order_by)); $distinct_qpart = "DISTINCT ON (id, $distinct_columns)"; } else { @@ -1948,10 +1948,10 @@ class Feeds extends Handler_Protected { if ($row = $sth->fetch()) { $owner_uid = $row["owner_uid"]; - if (FORCE_ARTICLE_PURGE != 0) { - Debug::log("purge_feed: FORCE_ARTICLE_PURGE is set, overriding interval to " . FORCE_ARTICLE_PURGE, Debug::$LOG_VERBOSE); + if (Config::get(Config::FORCE_ARTICLE_PURGE) != 0) { + Debug::log("purge_feed: FORCE_ARTICLE_PURGE is set, overriding interval to " . Config::get(Config::FORCE_ARTICLE_PURGE), Debug::$LOG_VERBOSE); $purge_unread = true; - $purge_interval = FORCE_ARTICLE_PURGE; + $purge_interval = Config::get(Config::FORCE_ARTICLE_PURGE); } else { $purge_unread = get_pref("PURGE_UNREAD_ARTICLES", $owner_uid, false); } @@ -1970,7 +1970,7 @@ class Feeds extends Handler_Protected { else $query_limit = ""; - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $sth = $pdo->prepare("DELETE FROM ttrss_user_entries USING ttrss_entries WHERE ttrss_entries.id = ref_id AND @@ -2153,7 +2153,7 @@ class Feeds extends Handler_Protected { array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')"); } else { - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $k = mb_strtolower($k); array_push($search_query_leftover, $not ? "!$k" : $k); } else { @@ -2168,7 +2168,7 @@ class Feeds extends Handler_Protected { if (count($search_query_leftover) > 0) { - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { // if there's no joiners consider this a "simple" search and // concatenate everything with &, otherwise don't try to mess with tsquery syntax diff --git a/classes/handler/public.php b/classes/handler/public.php index 3910cf7c1..79dff37b5 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -43,7 +43,7 @@ class Handler_Public extends Handler { $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); $tmppluginhost = new PluginHost(); - $tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL); + $tmppluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL); $tmppluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $owner_uid); //$tmppluginhost->load_data(); @@ -309,7 +309,7 @@ class Handler_Public extends Handler { $format = clean($_REQUEST['format'] ?? "atom"); $orig_guid = clean($_REQUEST["orig_guid"] ?? false); - if (SINGLE_USER_MODE) { + if (Config::get(Config::SINGLE_USER_MODE)) { UserHelper::authenticate("admin", null); } @@ -347,7 +347,7 @@ class Handler_Public extends Handler { } function login() { - if (!SINGLE_USER_MODE) { + if (!Config::get(Config::SINGLE_USER_MODE)) { $login = clean($_POST["login"]); $password = clean($_POST["password"]); @@ -355,7 +355,7 @@ class Handler_Public extends Handler { $safe_mode = checkbox_to_sql_bool(clean($_POST["safe_mode"] ?? false)); if ($remember_me) { - @session_set_cookie_params(SESSION_COOKIE_LIFETIME); + @session_set_cookie_params(Config::get(Config::SESSION_COOKIE_LIFETIME)); } else { @session_set_cookie_params(0); } @@ -398,7 +398,7 @@ class Handler_Public extends Handler { $return = clean($_REQUEST['return']); - if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) { + if ($_REQUEST['return'] && mb_strpos($return, Config::get(Config::SELF_URL_PATH)) === 0) { header("Location: " . clean($_REQUEST['return'])); } else { header("Location: " . get_self_url_prefix()); @@ -559,7 +559,7 @@ class Handler_Public extends Handler { $tpl->setVariable('LOGIN', $login); $tpl->setVariable('RESETPASS_LINK', $resetpass_link); - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); + $tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH)); $tpl->addBlock('message'); @@ -613,7 +613,7 @@ class Handler_Public extends Handler { function dbupdate() { startup_gettext(); - if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { + if (!Config::get(Config::SINGLE_USER_MODE) && $_SESSION["access_level"] < 10) { $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); $this->_render_login_form(); exit; @@ -660,7 +660,7 @@ class Handler_Public extends Handler { is_update_required()) { @@ -709,7 +709,7 @@ class Handler_Public extends Handler { print "

    ".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).", $updater->get_schema_version(), SCHEMA_VERSION)."

    "; - if (DB_TYPE == "mysql") { + if (Config::get(Config::DB_TYPE) == "mysql") { print_error("READ THIS: Due to MySQL limitations, your database is not completely protected while updating. ". "Errors may put it in an inconsistent state requiring manual rollback. BACKUP YOUR DATABASE BEFORE CONTINUING."); } else { diff --git a/classes/opml.php b/classes/opml.php index 04d287125..cbc1269e3 100644 --- a/classes/opml.php +++ b/classes/opml.php @@ -594,7 +594,7 @@ class OPML extends Handler_Protected { } if (is_uploaded_file($_FILES['opml_file']['tmp_name'])) { - $tmp_file = (string)tempnam(CACHE_DIR . '/upload', 'opml'); + $tmp_file = (string)tempnam(Config::get(Config::CACHE_DIR) . '/upload', 'opml'); $result = move_uploaded_file($_FILES['opml_file']['tmp_name'], $tmp_file); diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index e583a5f51..229effeb3 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -9,7 +9,7 @@ class Pref_Feeds extends Handler_Protected { public static function get_ts_languages() { $rv = []; - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $dbh = Db::pdo(); $res = $dbh->query("SELECT cfgname FROM pg_ts_config"); @@ -453,7 +453,7 @@ class Pref_Feeds extends Handler_Protected { header("Content-type: text/html"); if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) { - $tmp_file = tempnam(CACHE_DIR . '/upload', 'icon'); + $tmp_file = tempnam(Config::get(Config::CACHE_DIR) . '/upload', 'icon'); if (!$tmp_file) return; @@ -529,7 +529,7 @@ class Pref_Feeds extends Handler_Protected { $local_update_intervals = $update_intervals; $local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]); - if (FORCE_ARTICLE_PURGE == 0) { + if (Config::get(Config::FORCE_ARTICLE_PURGE) == 0) { $local_purge_intervals = $purge_intervals; $default_purge_interval = get_pref("PURGE_OLD_DAYS"); @@ -539,7 +539,7 @@ class Pref_Feeds extends Handler_Protected { $local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled")); } else { - $purge_interval = FORCE_ARTICLE_PURGE; + $purge_interval = Config::get(Config::FORCE_ARTICLE_PURGE); $local_purge_intervals = [ T_nsprintf('%d day', '%d days', $purge_interval, $purge_interval) ]; } @@ -550,13 +550,13 @@ class Pref_Feeds extends Handler_Protected { "select" => \Controls\select_feeds_cats("cat_id", $row["cat_id"]), ], "plugin_data" => $plugin_data, - "force_purge" => (int)FORCE_ARTICLE_PURGE, + "force_purge" => (int)Config::get(Config::FORCE_ARTICLE_PURGE), "intervals" => [ "update" => $local_update_intervals, "purge" => $local_purge_intervals, ], "lang" => [ - "enabled" => DB_TYPE == "pgsql", + "enabled" => Config::get(Config::DB_TYPE) == "pgsql", "default" => get_pref('DEFAULT_SEARCH_LANGUAGE'), "all" => $this::get_ts_languages(), ] @@ -614,7 +614,7 @@ class Pref_Feeds extends Handler_Protected { - +
    1]) ?> @@ -632,7 +632,7 @@ class Pref_Feeds extends Handler_Protected { _batch_toggle_checkbox("update_interval") ?>
    - +
    1]) ?> @@ -1147,7 +1147,7 @@ class Pref_Feeds extends Handler_Protected { function inactiveFeeds() { - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $interval_qpart = "NOW() - INTERVAL '3 months'"; } else { $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index adb249dac..1ca5b28be 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -236,7 +236,7 @@ class Pref_Prefs extends Handler_Protected { $tpl->setVariable('LOGIN', $row["login"]); $tpl->setVariable('NEWMAIL', $email); - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); + $tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH)); $tpl->addBlock('message'); @@ -625,7 +625,7 @@ class Pref_Prefs extends Handler_Protected { continue; } - if ($pref_name == "DEFAULT_SEARCH_LANGUAGE" && DB_TYPE != "pgsql") { + if ($pref_name == "DEFAULT_SEARCH_LANGUAGE" && Config::get(Config::DB_TYPE) != "pgsql") { continue; } @@ -705,7 +705,7 @@ class Pref_Prefs extends Handler_Protected { array_push($listed_boolean_prefs, $pref_name); - if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { + if ($pref_name == "PURGE_UNREAD_ARTICLES" && Config::get(Config::FORCE_ARTICLE_PURGE) != 0) { $is_disabled = true; $is_checked = true; } else { @@ -719,9 +719,9 @@ class Pref_Prefs extends Handler_Protected { } else if (in_array($pref_name, ['FRESH_ARTICLE_MAX_AGE', 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT'])) { - if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { + if ($pref_name == "PURGE_OLD_DAYS" && Config::get(Config::FORCE_ARTICLE_PURGE) != 0) { $attributes = ["disabled" => true, "required" => true]; - $value = FORCE_ARTICLE_PURGE; + $value = Config::get(Config::FORCE_ARTICLE_PURGE); } else { $attributes = ["required" => true]; } @@ -829,7 +829,7 @@ class Pref_Prefs extends Handler_Protected { private function index_plugins_system() { print_notice("System plugins are enabled in config.php for all users."); - $system_enabled = array_map("trim", explode(",", (string)PLUGINS)); + $system_enabled = array_map("trim", explode(",", (string)Config::get(Config::PLUGINS))); $tmppluginhost = new PluginHost(); $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); @@ -862,7 +862,7 @@ class Pref_Prefs extends Handler_Protected { } private function index_plugins_user() { - $system_enabled = array_map("trim", explode(",", (string)PLUGINS)); + $system_enabled = array_map("trim", explode(",", (string)Config::get(Config::PLUGINS))); $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS"))); $tmppluginhost = new PluginHost(); @@ -1135,7 +1135,7 @@ class Pref_Prefs extends Handler_Protected { $tpl->readTemplateFromFile("otp_disabled_template.txt"); $tpl->setVariable('LOGIN', $row["login"]); - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); + $tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH)); $tpl->addBlock('message'); diff --git a/classes/rpc.php b/classes/rpc.php index 95fd0f5ae..bf24132b0 100755 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -174,7 +174,7 @@ class RPC extends Handler_Protected { static function updaterandomfeed_real() { // Test if the feed need a update (update interval exceded). - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $update_limit_qpart = "AND (( ttrss_feeds.update_interval = 0 AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL) @@ -199,7 +199,7 @@ class RPC extends Handler_Protected { } // Test if feed is currently being updated by another process. - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')"; } else { $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))"; @@ -361,7 +361,7 @@ class RPC extends Handler_Protected { $params["safe_mode"] = !empty($_SESSION["safe_mode"]); $params["check_for_updates"] = CHECK_FOR_UPDATES; $params["icons_url"] = ICONS_URL; - $params["cookie_lifetime"] = SESSION_COOKIE_LIFETIME; + $params["cookie_lifetime"] = Config::get(Config::SESSION_COOKIE_LIFETIME); $params["default_view_mode"] = get_pref("_DEFAULT_VIEW_MODE"); $params["default_view_limit"] = (int) get_pref("_DEFAULT_VIEW_LIMIT"); $params["default_view_order_by"] = get_pref("_DEFAULT_VIEW_ORDER_BY"); @@ -433,7 +433,7 @@ class RPC extends Handler_Protected { $data["labels"] = Labels::get_all($_SESSION["uid"]); if (LOG_DESTINATION == 'sql' && $_SESSION['access_level'] >= 10) { - if (DB_TYPE == 'pgsql') { + if (Config::get(Config::DB_TYPE) == 'pgsql') { $log_interval = "created_at > NOW() - interval '1 hour'"; } else { $log_interval = "created_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)"; @@ -452,13 +452,13 @@ class RPC extends Handler_Protected { } } - if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) { + if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon.lock")) { $data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock"); if (time() - ($_SESSION["daemon_stamp_check"] ?? 0) > 30) { - $stamp = (int) @file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp"); + $stamp = (int) @file_get_contents(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon.stamp"); if ($stamp) { $stamp_delta = time() - $stamp; diff --git a/classes/rssutils.php b/classes/rssutils.php index 30d08328f..c951003f0 100755 --- a/classes/rssutils.php +++ b/classes/rssutils.php @@ -61,8 +61,8 @@ class RSSUtils { $pdo = Db::pdo(); - if (!SINGLE_USER_MODE && DAEMON_UPDATE_LOGIN_LIMIT > 0) { - if (DB_TYPE == "pgsql") { + if (!Config::get(Config::SINGLE_USER_MODE) && DAEMON_UPDATE_LOGIN_LIMIT > 0) { + if (Config::get(Config::DB_TYPE) == "pgsql") { $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".DAEMON_UPDATE_LOGIN_LIMIT." days'"; } else { $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".DAEMON_UPDATE_LOGIN_LIMIT." DAY)"; @@ -71,7 +71,7 @@ class RSSUtils { $login_thresh_qpart = ""; } - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $update_limit_qpart = "AND (( ttrss_feeds.update_interval = 0 AND ttrss_user_prefs.value != '-1' @@ -96,7 +96,7 @@ class RSSUtils { } // Test if feed is currently being updated by another process. - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $updstart_thresh_qpart = "AND (last_update_started IS NULL OR last_update_started < NOW() - INTERVAL '10 minutes')"; } else { $updstart_thresh_qpart = "AND (last_update_started IS NULL OR last_update_started < DATE_SUB(NOW(), INTERVAL 10 MINUTE))"; @@ -106,7 +106,7 @@ class RSSUtils { // Update the least recently updated feeds first $query_order = "ORDER BY last_updated"; - if (DB_TYPE == "pgsql") $query_order .= " NULLS FIRST"; + if (Config::get(Config::DB_TYPE) == "pgsql") $query_order .= " NULLS FIRST"; $query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated FROM @@ -182,7 +182,7 @@ class RSSUtils { if (self::function_enabled('passthru')) { $exit_code = 0; - passthru(PHP_EXECUTABLE . " update.php --update-feed " . $tline["id"] . " --pidlock feed-" . $tline["id"] . " $quiet $log $log_level", $exit_code); + passthru(Config::get(Config::PHP_EXECUTABLE) . " update.php --update-feed " . $tline["id"] . " --pidlock feed-" . $tline["id"] . " $quiet $log $log_level", $exit_code); Debug::log(sprintf("<= %.4f (sec) exit code: %d", microtime(true) - $fstarted, $exit_code)); @@ -275,7 +275,7 @@ class RSSUtils { $pluginhost = new PluginHost(); $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); - $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); + $pluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL); $pluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $owner_uid); //$pluginhost->load_data(); @@ -395,12 +395,12 @@ class RSSUtils { $date_feed_processed = date('Y-m-d H:i'); - $cache_filename = CACHE_DIR . "/feeds/" . sha1($fetch_url) . ".xml"; + $cache_filename = Config::get(Config::CACHE_DIR) . "/feeds/" . sha1($fetch_url) . ".xml"; $pluginhost = new PluginHost(); $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); - $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); + $pluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL); $pluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $owner_uid); //$pluginhost->load_data(); @@ -488,7 +488,7 @@ class RSSUtils { } // cache vanilla feed data for re-use - if ($feed_data && !$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/feeds")) { + if ($feed_data && !$auth_pass && !$auth_login && is_writable(Config::get(Config::CACHE_DIR) . "/feeds")) { $new_rss_hash = sha1($feed_data); if ($new_rss_hash != $rss_hash) { @@ -561,7 +561,7 @@ class RSSUtils { Debug::log("language: $feed_language", Debug::$LOG_VERBOSE); Debug::log("processing feed data...", Debug::$LOG_VERBOSE); - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'"; } else { $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)"; @@ -755,7 +755,7 @@ class RSSUtils { $e->type, $e->length, $e->title, $e->width, $e->height); // Yet another episode of "mysql utf8_general_ci is gimped" - if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") { + if (Config::get(Config::DB_TYPE) == "mysql" && MYSQL_CHARSET != "UTF8MB4") { for ($i = 0; $i < count($e_item); $i++) { if (is_string($e_item[$i])) { $e_item[$i] = self::strip_utf8mb4($e_item[$i]); @@ -833,7 +833,7 @@ class RSSUtils { Debug::log("plugin data: $entry_plugin_data", Debug::$LOG_VERBOSE); // Workaround: 4-byte unicode requires utf8mb4 in MySQL. See https://tt-rss.org/forum/viewtopic.php?f=1&t=3377&p=20077#p20077 - if (DB_TYPE == "mysql" && MYSQL_CHARSET != "UTF8MB4") { + if (Config::get(Config::DB_TYPE) == "mysql" && MYSQL_CHARSET != "UTF8MB4") { foreach ($article as $k => $v) { // i guess we'll have to take the risk of 4byte unicode labels & tags here if (is_string($article[$k])) { @@ -1079,7 +1079,7 @@ class RSSUtils { Debug::log("resulting RID: $entry_ref_id, IID: $entry_int_id", Debug::$LOG_VERBOSE); - if (DB_TYPE == "pgsql") + if (Config::get(Config::DB_TYPE) == "pgsql") $tsvector_qpart = "tsvector_combined = to_tsvector(:ts_lang, :ts_content),"; else $tsvector_qpart = ""; @@ -1107,7 +1107,7 @@ class RSSUtils { ":lang" => $entry_language, ":id" => $ref_id]; - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $params[":ts_lang"] = $feed_language; $params[":ts_content"] = mb_substr(strip_tags($entry_title . " " . $entry_content), 0, 900000); } @@ -1375,7 +1375,7 @@ class RSSUtils { $pdo = Db::pdo(); - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $pdo->query("DELETE FROM ttrss_error_log WHERE created_at < NOW() - INTERVAL '7 days'"); } else { @@ -1396,8 +1396,8 @@ class RSSUtils { $num_deleted = 0; - if (is_writable(LOCK_DIRECTORY)) { - $files = glob(LOCK_DIRECTORY . "/*.lock"); + if (is_writable(Config::get(Config::LOCK_DIRECTORY))) { + $files = glob(Config::get(Config::LOCK_DIRECTORY) . "/*.lock"); if ($files) { foreach ($files as $file) { @@ -1589,9 +1589,9 @@ class RSSUtils { $days = DAEMON_UNSUCCESSFUL_DAYS_LIMIT; - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $interval_query = "last_successful_update < NOW() - INTERVAL '$days days' AND last_updated > NOW() - INTERVAL '1 days'"; - } else /* if (DB_TYPE == "mysql") */ { + } else /* if (Config::get(Config::DB_TYPE) == "mysql") */ { $interval_query = "last_successful_update < DATE_SUB(NOW(), INTERVAL $days DAY) AND last_updated > DATE_SUB(NOW(), INTERVAL 1 DAY)"; } diff --git a/classes/userhelper.php b/classes/userhelper.php index 7fe1e5557..82a2fe05f 100644 --- a/classes/userhelper.php +++ b/classes/userhelper.php @@ -2,7 +2,7 @@ class UserHelper { static function authenticate(string $login = null, string $password = null, bool $check_only = false, string $service = null) { - if (!SINGLE_USER_MODE) { + if (!Config::get(Config::SINGLE_USER_MODE)) { $user_id = false; $auth_module = false; @@ -88,7 +88,7 @@ class UserHelper { static function login_sequence() { $pdo = Db::pdo(); - if (SINGLE_USER_MODE) { + if (Config::get(Config::SINGLE_USER_MODE)) { @session_start(); self::authenticate("admin", null); startup_gettext(); @@ -98,7 +98,7 @@ class UserHelper { if (empty($_SESSION["uid"])) { - if (AUTH_AUTO_LOGIN && self::authenticate(null, null)) { + if (Config::get(Config::AUTH_AUTO_LOGIN) && self::authenticate(null, null)) { $_SESSION["ref_schema_version"] = get_schema_version(true); } else { self::authenticate(null, null, true); diff --git a/include/autoload.php b/include/autoload.php index c02923dba..19e00b9ea 100644 --- a/include/autoload.php +++ b/include/autoload.php @@ -1,6 +1,4 @@ load(PLUGINS, PluginHost::KIND_ALL); + PluginHost::getInstance()->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL); return true; } diff --git a/include/login_form.php b/include/login_form.php index 211302a87..537c7f994 100755 --- a/include/login_form.php +++ b/include/login_form.php @@ -79,7 +79,7 @@ }, bwLimitChange: function(elem) { Cookie.set("ttrss_bwlimit", elem.checked, - ); + ); } }; @@ -122,7 +122,7 @@ onblur="UtilityApp.fetchProfiles()" value=""/>
    - +
    @@ -161,7 +161,7 @@
    - 0) { ?> + 0) { ?>
    diff --git a/include/sanity_check.php b/include/sanity_check.php index 2786f012f..5efd23d98 100755 --- a/include/sanity_check.php +++ b/include/sanity_check.php @@ -21,7 +21,7 @@ $sth = $pdo->prepare("SELECT engine, table_name FROM information_schema.tables WHERE table_schema = ? AND table_name LIKE 'ttrss_%' AND engine != 'InnoDB'"); - $sth->execute([DB_NAME]); + $sth->execute([Config::get(Config::DB_NAME)]); $bad_tables = []; @@ -44,8 +44,8 @@ array_push($errors, "Please copy config.php-dist to config.php"); } - if (strpos(PLUGINS, "auth_") === false) { - array_push($errors, "Please enable at least one authentication module via PLUGINS constant in config.php"); + if (strpos(Config::get(Config::PLUGINS), "auth_") === false) { + array_push($errors, "Please enable at least one authentication module via Config::get(Config::PLUGINS) constant in config.php"); } if (function_exists('posix_getuid') && posix_getuid() == 0) { @@ -60,43 +60,25 @@ array_push($errors, "PHP UConverter class is missing, it's provided by the Internationalization (intl) module."); } - if (CONFIG_VERSION != EXPECTED_CONFIG_VERSION) { - array_push($errors, "Configuration file (config.php) has incorrect version. Update it with new options from config.php-dist and set CONFIG_VERSION to the correct value."); + if (!is_writable(Config::get(Config::CACHE_DIR) . "/images")) { + array_push($errors, "Image cache is not writable (chmod -R 777 ".Config::get(Config::CACHE_DIR)."/images)"); } - if (!is_writable(CACHE_DIR . "/images")) { - array_push($errors, "Image cache is not writable (chmod -R 777 ".CACHE_DIR."/images)"); + if (!is_writable(Config::get(Config::CACHE_DIR) . "/upload")) { + array_push($errors, "Upload cache is not writable (chmod -R 777 ".Config::get(Config::CACHE_DIR)."/upload)"); } - if (!is_writable(CACHE_DIR . "/upload")) { - array_push($errors, "Upload cache is not writable (chmod -R 777 ".CACHE_DIR."/upload)"); + if (!is_writable(Config::get(Config::CACHE_DIR) . "/export")) { + array_push($errors, "Data export cache is not writable (chmod -R 777 ".Config::get(Config::CACHE_DIR)."/export)"); } - if (!is_writable(CACHE_DIR . "/export")) { - array_push($errors, "Data export cache is not writable (chmod -R 777 ".CACHE_DIR."/export)"); - } - - require_once "sanity_config.php"; - - if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) { - array_push($errors, - "Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh"); - } - - foreach (get_required_defines() as $d) { - if (!defined($d)) { - array_push($errors, - "Required configuration file parameter $d is not defined in config.php. You might need to copy it from config.php-dist."); - } - } - - if (SINGLE_USER_MODE && class_exists("PDO")) { + if (Config::get(Config::SINGLE_USER_MODE) && class_exists("PDO")) { $pdo = Db::pdo(); $res = $pdo->query("SELECT id FROM ttrss_users WHERE id = 1"); if (!$res->fetch()) { - array_push($errors, "SINGLE_USER_MODE is enabled in config.php but default admin account is not found."); + array_push($errors, "Config::get(Config::SINGLE_USER_MODE) is enabled in config.php but default admin account is not found."); } } @@ -107,17 +89,17 @@ $ref_self_url_path = preg_replace("/\w+\.php$/", "", $ref_self_url_path); } - if (SELF_URL_PATH == "http://example.org/tt-rss/") { + if (Config::get(Config::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"); + "Please set Config::get(Config::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)) { + Config::get(Config::SELF_URL_PATH) != $ref_self_url_path && Config::get(Config::SELF_URL_PATH) != mb_substr($ref_self_url_path, 0, mb_strlen($ref_self_url_path)-1)) { array_push($errors, - "Please set SELF_URL_PATH to the correct value detected for your server: $ref_self_url_path (you're using: " . SELF_URL_PATH . ")"); + "Please set Config::get(Config::SELF_URL_PATH) to the correct value detected for your server: $ref_self_url_path (you're using: " . Config::get(Config::SELF_URL_PATH) . ")"); } } @@ -125,8 +107,8 @@ array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".ICONS_DIR.").\n"); } - if (!is_writable(LOCK_DIRECTORY)) { - array_push($errors, "LOCK_DIRECTORY defined in config.php is not writable (chmod -R 777 ".LOCK_DIRECTORY.").\n"); + if (!is_writable(Config::get(Config::LOCK_DIRECTORY))) { + array_push($errors, "Config::get(Config::LOCK_DIRECTORY) defined in config.php is not writable (chmod -R 777 ".Config::get(Config::LOCK_DIRECTORY).").\n"); } if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) { @@ -161,7 +143,7 @@ array_push($errors, "PHP support for DOMDocument is required, but was not found."); } - if (DB_TYPE == "mysql") { + if (Config::get(Config::DB_TYPE) == "mysql") { $bad_tables = check_mysql_tables(); if (count($bad_tables) > 0) { diff --git a/include/sanity_config.php b/include/sanity_config.php deleted file mode 100644 index b304adf54..000000000 --- a/include/sanity_config.php +++ /dev/null @@ -1,3 +0,0 @@ -Fatal Error: You forgot to copy config.php-dist to config.php and edit it.\n"; @@ -16,6 +17,7 @@ get_include_path()); require_once "autoload.php"; + require_once "sessions.php"; require_once "functions.php"; require_once "sanity_check.php"; diff --git a/phpstan.neon b/phpstan.neon index b2cd978d8..ba425e3d9 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ parameters: level: 5 ignoreErrors: - - '#Constant.*not found#' +# - '#Constant.*not found#' - '#Comparison operation ">" between int<1, max> and 0 is always true.#' - '#Access to an undefined property DOMNode::\$tagName.#' - '#Call to an undefined method DOMNode::(get|remove|set)Attribute\(\).#' diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 3b7ed6b14..5611d8998 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -134,7 +134,7 @@ class Af_Psql_Trgm extends Plugin { title="extension "> pdo->query("select 'similarity'::regproc"); @@ -258,7 +258,7 @@ class Af_Psql_Trgm extends Plugin { function hook_article_filter($article) { - if (DB_TYPE != "pgsql") return $article; + if (Config::get(Config::DB_TYPE) != "pgsql") return $article; $res = $this->pdo->query("select 'similarity'::regproc"); if (!$res || !$res->fetch()) return $article; diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 713eaea5c..9cd046ba4 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -530,7 +530,7 @@ class Af_RedditImgur extends Plugin { $entry_guid = $article["guid_hashed"]; $owner_uid = $article["owner_uid"]; - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $interval_qpart = "date_entered < NOW() - INTERVAL '1 day'"; } else { $interval_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY)"; diff --git a/plugins/auth_internal/init.php b/plugins/auth_internal/init.php index 6a68534ea..13a7bc969 100644 --- a/plugins/auth_internal/init.php +++ b/plugins/auth_internal/init.php @@ -244,7 +244,7 @@ class Auth_Internal extends Auth_Base { $tpl->readTemplateFromFile("password_change_template.txt"); $tpl->setVariable('LOGIN', $row["login"]); - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); + $tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH)); $tpl->addBlock('message'); diff --git a/plugins/bookmarklets/init.php b/plugins/bookmarklets/init.php index caa8b39df..967918823 100644 --- a/plugins/bookmarklets/init.php +++ b/plugins/bookmarklets/init.php @@ -21,7 +21,7 @@ class Bookmarklets extends Plugin { } function subscribe() { - if (SINGLE_USER_MODE) { + if (Config::get(Config::SINGLE_USER_MODE)) { UserHelper::login_sequence(); } @@ -172,7 +172,7 @@ class Bookmarklets extends Plugin { } function sharepopup() { - if (SINGLE_USER_MODE) { + if (Config::get(Config::SINGLE_USER_MODE)) { UserHelper::login_sequence(); } diff --git a/update.php b/update.php index ab6272c83..4aff4a774 100755 --- a/update.php +++ b/update.php @@ -14,7 +14,7 @@ require_once "db-prefs.php"; function make_stampfile($filename) { - $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); + $fp = fopen(Config::get(Config::LOCK_DIRECTORY) . "/$filename", "w"); if (flock($fp, LOCK_EX | LOCK_NB)) { fwrite($fp, time() . "\n"); @@ -30,9 +30,9 @@ $days = (int) $days; - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $interval_query = "date_updated < NOW() - INTERVAL '$days days'"; - } else /*if (DB_TYPE == "mysql") */ { + } else /*if (Config::get(Config::DB_TYPE) == "mysql") */ { $interval_query = "date_updated < DATE_SUB(NOW(), INTERVAL $days DAY)"; } @@ -224,7 +224,7 @@ $log = isset($options['log']) ? '--log '.$options['log'] : ''; $log_level = isset($options['log-level']) ? '--log-level '.$options['log-level'] : ''; - passthru(PHP_EXECUTABLE . " " . $argv[0] ." --daemon-loop $quiet $log $log_level"); + passthru(Config::get(Config::PHP_EXECUTABLE) . " " . $argv[0] ." --daemon-loop $quiet $log $log_level"); // let's enforce a minimum spawn interval as to not forkbomb the host $spawn_interval = max(60, DAEMON_SLEEP_INTERVAL); @@ -277,7 +277,7 @@ Debug::log("clearing existing indexes..."); - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $sth = $pdo->query( "SELECT relname FROM pg_catalog.pg_class WHERE relname LIKE 'ttrss_%' AND relname NOT LIKE '%_pkey' @@ -288,7 +288,7 @@ } while ($line = $sth->fetch()) { - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $statement = "DROP INDEX " . $line["relname"]; Debug::log($statement); } else { @@ -299,9 +299,9 @@ $pdo->query($statement); } - Debug::log("reading indexes from schema for: " . DB_TYPE); + Debug::log("reading indexes from schema for: " . Config::get(Config::DB_TYPE)); - $fp = fopen("schema/ttrss_schema_" . DB_TYPE . ".sql", "r"); + $fp = fopen("schema/ttrss_schema_" . Config::get(Config::DB_TYPE) . ".sql", "r"); if ($fp) { while ($line = fgets($fp)) { $matches = array(); @@ -375,14 +375,14 @@ } if (isset($options["update-schema"])) { - Debug::log("Checking for updates (" . DB_TYPE . ")..."); + Debug::log("Checking for updates (" . Config::get(Config::DB_TYPE) . ")..."); - $updater = new DbUpdater(Db::pdo(), DB_TYPE, SCHEMA_VERSION); + $updater = new DbUpdater(Db::pdo(), Config::get(Config::DB_TYPE), SCHEMA_VERSION); if ($updater->is_update_required()) { Debug::log("Schema update required, version " . $updater->get_schema_version() . " to " . SCHEMA_VERSION); - if (DB_TYPE == "mysql") + if (Config::get(Config::DB_TYPE) == "mysql") Debug::Log("READ THIS: Due to MySQL limitations, your database is not completely protected while updating.\n". "Errors may put it in an inconsistent state requiring manual rollback.\nBACKUP YOUR DATABASE BEFORE CONTINUING."); else @@ -460,7 +460,7 @@ if (isset($options["list-plugins"])) { $tmppluginhost = new PluginHost(); $tmppluginhost->load_all($tmppluginhost::KIND_ALL); - $enabled = array_map("trim", explode(",", PLUGINS)); + $enabled = array_map("trim", explode(",", Config::get(Config::PLUGINS))); echo "List of all available plugins:\n"; @@ -515,8 +515,8 @@ PluginHost::getInstance()->run_commands($options); - if (file_exists(LOCK_DIRECTORY . "/$lock_filename")) + if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/$lock_filename")) if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') fclose($lock_handle); - unlink(LOCK_DIRECTORY . "/$lock_filename"); + unlink(Config::get(Config::LOCK_DIRECTORY) . "/$lock_filename"); ?> diff --git a/update_daemon2.php b/update_daemon2.php index 5d4d3759c..b67fba37d 100755 --- a/update_daemon2.php +++ b/update_daemon2.php @@ -98,9 +98,9 @@ function shutdown($caller_pid) { if ($caller_pid == posix_getpid()) { - if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) { + if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon.lock")) { Debug::log("Removing lockfile (master)..."); - unlink(LOCK_DIRECTORY . "/update_daemon.lock"); + unlink(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon.lock"); } } } @@ -108,9 +108,9 @@ function task_shutdown() { $pid = posix_getpid(); - if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) { + if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon-$pid.lock")) { Debug::log("Removing task lockfile for PID $pid..."); - unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock"); + unlink(Config::get(Config::LOCK_DIRECTORY) . "/update_daemon-$pid.lock"); } } @@ -249,7 +249,7 @@ $my_pid = posix_getpid(); - passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid"); + passthru(Config::get(Config::PHP_EXECUTABLE) . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid"); sleep(1); diff --git a/utils/regen_config_checks.sh b/utils/regen_config_checks.sh deleted file mode 100755 index b20ce0480..000000000 --- a/utils/regen_config_checks.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -DESTINATION="include/sanity_config.php" - -echo " $DESTINATION - -echo -n "define('GENERATED_CONFIG_CHECK', " >> $DESTINATION -grep CONFIG_VERSION config.php-dist | awk -F ' |\)' '{ print $2 }' | xargs echo -n >> $DESTINATION -echo ");" >> $DESTINATION - -echo -n "function get_required_defines() { return [ " >> $DESTINATION - -grep define\( config.php-dist | awk -F\' '{ print "*" $2 "*," }' | grep -v DB_PORT | xargs echo -n | sed -e s/,$// -e s/*/\'/g >> $DESTINATION - -echo "]; }" >> $DESTINATION - - -- cgit v1.2.3-54-g00ecf