From 8e75551f95ec2ade517afce2afe76150d5ffda24 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 11:29:38 +0300 Subject: pref prefs: split index into manageable chunks --- classes/pref/prefs.php | 837 +++++++++++++++++++++++++------------------------ 1 file changed, 435 insertions(+), 402 deletions(-) diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index cfe63ce85..a37ae99b5 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -4,6 +4,7 @@ class Pref_Prefs extends Handler_Protected { private $pref_help = []; private $pref_item_map = []; + private $pref_help_bottom = []; private $pref_blacklist = []; private $profile_blacklist = []; @@ -272,34 +273,7 @@ class Pref_Prefs extends Handler_Protected { echo __("Your preferences are now set to default values."); } - function index() { - - global $access_level_names; - - $_SESSION["prefs_op_result"] = ""; - - print "
"; - print "
person ".__('Personal data / Authentication')."\">"; - - print "
"; - print "
"; - - print "
"; - - print ""; + private function index_auth_personal() { $sth = $this->pdo->prepare("SELECT email,full_name,otp_enabled, access_level FROM ttrss_users @@ -311,179 +285,214 @@ class Pref_Prefs extends Handler_Protected { $full_name = htmlspecialchars($row["full_name"]); $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); - print "
"; - print ""; - print ""; - print "
"; - - print "
"; - print ""; - print ""; - print "
"; - - if (!SINGLE_USER_MODE && !empty($_SESSION["hide_hello"])) { + ?> + - $access_level = $row["access_level"]; - print "
"; - print ""; - print $access_level_names[$access_level]; - print "
"; - } - - print_hidden("op", "pref-prefs"); - print_hidden("method", "changeemail"); - - print "
"; + + - print ""; - - print "
"; + + +
+ + +
+ +
+ + +
+ + +
+ + +
+ + +
+ + + + get_plugin($_SESSION["auth_module"]); } else { $authenticator = false; } - print "
"; + $otp_enabled = $this->is_otp_enabled(); if ($authenticator && method_exists($authenticator, "change_password")) { + ?> - print ""; + - print "
"; + - print ""; + const warn = $('default_pass_warning'); + if (warn) Element.hide(warn); + } - if ($otp_enabled) { - print_notice(__("Changing your current password will disable OTP.")); - } + new Effect.Appear('pwd_change_infobox'); + } + }); + this.reset(); + } + - print "
"; - print ""; - print ""; - print "
"; + - print "
"; - print ""; - print ""; - print "
"; +
+ + +
- print "
"; - print ""; - print ""; - print "
"; +
+ + +
- print_hidden("op", "pref-prefs"); - print_hidden("method", "changepassword"); +
+ + +
- print "
"; +
- print ""; + +
- print ""; + %s) does not provide an ability to set passwords.", $_SESSION["auth_module"])); } + } - print "
"; # content pane + private function index_auth_app_passwords() { + print_notice("You can create separate passwords for API clients. Using one is required if you enable OTP."); + ?> - print "
"; +
+ appPasswordList() ?> +
- print_notice("You can create separate passwords for API clients. Using one is required if you enable OTP."); +
- print "
"; - $this->appPasswordList(); - print "
"; + + + - print "
"; + " . - __('Generate new password') . " "; + private function is_otp_enabled() { + $sth = $this->pdo->prepare("SELECT otp_enabled FROM ttrss_users + WHERE id = ?"); + $sth->execute([$_SESSION["uid"]]); - print ""; + if ($row = $sth->fetch()) { + return sql_bool_to_bool($row["otp_enabled"]); + } - print "
"; # content pane + return false; + } - print "
"; + private function index_auth_2fa() { + $otp_enabled = $this->is_otp_enabled(); if ($_SESSION["auth_module"] == "auth_internal") { - if ($otp_enabled) { - print_warning("One time passwords are currently enabled. Enter your current password below to disable."); + ?> + +
+ + + + - print ""; - - print ""; - - print "
"; - print ""; - print ""; - print "
"; +
+ + +
- print_hidden("op", "pref-prefs"); - print_hidden("method", "otpdisable"); +
- print "
"; + - print ""; +
- print ""; + " . __("Scan the following code by the Authenticator application or copy the key manually") . ""; - $csrf_token_hash = sha1($_SESSION["csrf_token"]); print "otp qr-code"; } else { @@ -500,105 +508,86 @@ class Pref_Prefs extends Handler_Protected { print "

" . __("Use the following OTP key with a compatible Authenticator application") . "

"; } - print "
"; - $otp_secret = $this->otpsecret(); + ?> + + + + + + +
+ + +
+ + - print "
"; - print ""; - print ""; - print "
"; - - print_hidden("op", "pref-prefs"); - print_hidden("method", "otpenable"); - - print ""; - - print "
"; - print ""; - print ""; - print "
"; +
+ + +
- print "
"; - print ""; - print ""; - print "
"; +
+ + +
- print "
"; - print ""; +
- print "
"; + + + auth_internal authentication module."); } + } - print "
"; # content pane - - print "
"; # tab container - - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefPrefsAuth"); - - print "
"; #pane - - print "
settings ".__('Preferences')."\">"; - - print "
"; - - print ""; - - print '
'; - - print '
'; + private function index_auth() { + ?> +
+
+ index_auth_personal() ?> +
+
+ index_auth_password() ?> +
+
+ index_auth_app_passwords() ?> +
+
+ index_auth_2fa() ?> +
+
+ initialize_user_prefs($_SESSION["uid"], $profile); } else { $this->initialize_user_prefs($_SESSION["uid"]); @@ -660,7 +649,9 @@ class Pref_Prefs extends Handler_Protected { continue; } - if (isset($prefs_available[$pref_name]) &&$item = $prefs_available[$pref_name]) { + if (isset($prefs_available[$pref_name])) { + + $item = $prefs_available[$pref_name]; print "
"; @@ -735,16 +726,16 @@ class Pref_Prefs extends Handler_Protected { array_push($listed_boolean_prefs, $pref_name); - $checked = ($value == "true") ? "checked=\"checked\"" : ""; + $is_checked = ($value == "true") ? "checked=\"checked\"" : ""; if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { - $disabled = "disabled=\"1\""; - $checked = "checked=\"checked\""; + $is_disabled = "disabled=\"1\""; + $is_checked = "checked=\"checked\""; } else { - $disabled = ""; + $is_disabled = ""; } - print ""; } else if (in_array($pref_name, ['FRESH_ARTICLE_MAX_AGE', @@ -753,19 +744,19 @@ class Pref_Prefs extends Handler_Protected { $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { - $disabled = "disabled='1'"; + $is_disabled = "disabled='1'"; $value = FORCE_ARTICLE_PURGE; } else { - $disabled = ""; + $is_disabled = ""; } if ($type_name == 'integer') print ""; else print ""; } else if ($pref_name == "SSL_CERT_SERIAL") { @@ -808,204 +799,246 @@ class Pref_Prefs extends Handler_Protected { } } } + print_hidden("boolean_prefs", htmlspecialchars(join(",", $listed_boolean_prefs))); + } - $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs)); - - print_hidden("boolean_prefs", "$listed_boolean_prefs"); - - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefPrefsPrefsInside"); - - print '
'; # inside pane - print '
'; - - print_hidden("op", "pref-prefs"); - print_hidden("method", "saveconfig"); + private function index_prefs() { + ?> + + + + + +
+
+ index_prefs_list() ?> + run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefPrefsPrefsInside") ?> +
+
+ +
+ +
+
+ +
+
+
+ + + + + + run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefPrefsPrefsOutside") ?> +
-
"; - - print " "; - - print ""; - - print " "; - - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefPrefsPrefsOutside"); - - print ""; - print '
'; # inner pane - print '
'; # border container - - print "
"; #pane - - print "
extension ".__('Plugins')."\">"; - - print "
"; - - print ""; - - print_hidden("op", "pref-prefs"); - print_hidden("method", "setplugins"); - - print '
'; - print '
'; - - if (ini_get("open_basedir") && function_exists("curl_init") && !defined("NO_CURL")) { - print_warning("Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly."); - } - - if ($_SESSION["safe_mode"]) { - print_error("You have logged in using safe mode, no user plugins will be actually enabled until you login again."); - } - - $feed_handler_whitelist = [ "Af_Comics" ]; - - $feed_handlers = array_merge( - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_FETCHED), - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED), - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED)); - - $feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) { - return in_array(get_class($plugin), $feed_handler_whitelist) === false; }); - - if (count($feed_handlers) > 0) { - print_error( - T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: %s" , - implode(", ", array_map(function($plugin) { return get_class($plugin); }, $feed_handlers)) - ) . " (".__("More info...").")" - ); - } + + ".__("System plugins").""; + private function index_plugins_system() { print_notice("System plugins are enabled in config.php for all users."); - $system_enabled = array_map("trim", explode(",", PLUGINS)); - $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS"))); + $system_enabled = array_map("trim", explode(",", (string)PLUGINS)); $tmppluginhost = new PluginHost(); $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); - //$tmppluginhost->load_data(true); foreach ($tmppluginhost->get_plugins() as $name => $plugin) { $about = $plugin->about(); if ($about[3] ?? false) { - if (in_array($name, $system_enabled)) { - $checked = "checked='1'"; - } else { - $checked = ""; - } - - print "
- - "; - - if ($about[4] ?? false) { - print ""; - } - - print "
". - htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). - "
"; - - print "
"; - + $is_checked = in_array($name, $system_enabled) ? "checked" : ""; + ?> +
+ + + + + + + +
+ +
+
+ ".__("User plugins").""; + private function index_plugins_user() { + $system_enabled = array_map("trim", explode(",", (string)PLUGINS)); + $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS"))); + + $tmppluginhost = new PluginHost(); + $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); foreach ($tmppluginhost->get_plugins() as $name => $plugin) { $about = $plugin->about(); if (empty($about[3]) || $about[3] == false) { - $checked = ""; - $disabled = ""; + $is_checked = ""; + $is_disabled = ""; if (in_array($name, $system_enabled)) { - $checked = "checked='1'"; - $disabled = "disabled='1'"; + $is_checked = "checked='1'"; + $is_disabled = "disabled='1'"; } else if (in_array($name, $user_enabled)) { - $checked = "checked='1'"; + $is_checked = "checked='1'"; } - print "
- - "; - - if (count($tmppluginhost->get_all($plugin)) > 0) { - if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) { - print " "; - } - } + ?> + +
+ + + + get_all($plugin)) > 0) { + if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) { ?> + + + + + + + +
+ +
+ +
+ - open_in_new ".__("More info...").""; + private function index_plugins() { + ?> +
+ - print "
". - htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). - "
"; + + - print "
"; - } - } +
+
+ "; #content-pane - print '
'; + $feed_handler_whitelist = [ "Af_Comics" ]; - print ""; + $feed_handlers = array_merge( + PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_FETCHED), + PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED), + PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED)); - print ""; - print "
"; #pane + $feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) { + return in_array(get_class($plugin), $feed_handler_whitelist) === false; }); - print "
"; #pane - print "
"; #border-container + if (count($feed_handlers) > 0) { + print_error( + T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: %s" , + implode(", ", array_map(function($plugin) { return get_class($plugin); }, $feed_handlers)) + ) . " (".__("More info...").")" + ); + } + ?> - print ""; +

+ + index_plugins_system() ?> - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefPrefs"); +

- print "
"; #container + index_plugins_user() ?> +
+
+ + +
+
+ + +
+
+ index_auth() ?> +
+
+ index_prefs() ?> +
+
+ index_plugins() ?> +
+ run_hooks(PluginHost::HOOK_PREFS_TAB, "prefPrefs") ?> +
+