diff options
Diffstat (limited to 'classes/pref/prefs.php')
-rw-r--r-- | classes/pref/prefs.php | 268 |
1 files changed, 88 insertions, 180 deletions
diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 0d0dcadbc..ba63d76b3 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -6,7 +6,6 @@ class Pref_Prefs extends Handler_Protected { private $pref_item_map = []; private $pref_help_bottom = []; private $pref_blacklist = []; - private $profile_blacklist = []; function csrf_ignore($method) { $csrf_ignored = array("index", "updateself", "otpqrcode"); @@ -19,106 +18,99 @@ class Pref_Prefs extends Handler_Protected { $this->pref_item_map = [ __('General') => [ - 'USER_LANGUAGE', - 'USER_TIMEZONE', + Prefs::USER_LANGUAGE, + Prefs::USER_TIMEZONE, 'BLOCK_SEPARATOR', - 'USER_CSS_THEME', + Prefs::USER_CSS_THEME, 'BLOCK_SEPARATOR', - 'ENABLE_API_ACCESS', + Prefs::ENABLE_API_ACCESS, ], __('Feeds') => [ - 'DEFAULT_UPDATE_INTERVAL', - 'FRESH_ARTICLE_MAX_AGE', - 'DEFAULT_SEARCH_LANGUAGE', + Prefs::DEFAULT_UPDATE_INTERVAL, + Prefs::FRESH_ARTICLE_MAX_AGE, + Prefs::DEFAULT_SEARCH_LANGUAGE, 'BLOCK_SEPARATOR', - 'ENABLE_FEED_CATS', + Prefs::ENABLE_FEED_CATS, 'BLOCK_SEPARATOR', - 'CONFIRM_FEED_CATCHUP', - 'ON_CATCHUP_SHOW_NEXT_FEED', + Prefs::CONFIRM_FEED_CATCHUP, + Prefs::ON_CATCHUP_SHOW_NEXT_FEED, 'BLOCK_SEPARATOR', - 'HIDE_READ_FEEDS', - 'HIDE_READ_SHOWS_SPECIAL', + Prefs::HIDE_READ_FEEDS, + Prefs::HIDE_READ_SHOWS_SPECIAL, ], __('Articles') => [ - 'PURGE_OLD_DAYS', - 'PURGE_UNREAD_ARTICLES', + Prefs::PURGE_OLD_DAYS, + Prefs::PURGE_UNREAD_ARTICLES, 'BLOCK_SEPARATOR', - 'COMBINED_DISPLAY_MODE', - 'CDM_EXPANDED', + Prefs::COMBINED_DISPLAY_MODE, + Prefs::CDM_EXPANDED, 'BLOCK_SEPARATOR', - 'CDM_AUTO_CATCHUP', - 'VFEED_GROUP_BY_FEED', + Prefs::CDM_AUTO_CATCHUP, + Prefs::VFEED_GROUP_BY_FEED, 'BLOCK_SEPARATOR', - 'SHOW_CONTENT_PREVIEW', - 'STRIP_IMAGES', + Prefs::SHOW_CONTENT_PREVIEW, + Prefs::STRIP_IMAGES, ], __('Digest') => [ - 'DIGEST_ENABLE', - 'DIGEST_CATCHUP', - 'DIGEST_PREFERRED_TIME', + Prefs::DIGEST_ENABLE, + Prefs::DIGEST_CATCHUP, + Prefs::DIGEST_PREFERRED_TIME, ], __('Advanced') => [ - 'BLACKLISTED_TAGS', + Prefs::BLACKLISTED_TAGS, 'BLOCK_SEPARATOR', - 'LONG_DATE_FORMAT', - 'SHORT_DATE_FORMAT', + Prefs::LONG_DATE_FORMAT, + Prefs::SHORT_DATE_FORMAT, 'BLOCK_SEPARATOR', - 'SSL_CERT_SERIAL', - ] + Prefs::SSL_CERT_SERIAL, + 'BLOCK_SEPARATOR', + Prefs::HEADLINES_NO_DISTINCT, + ], + __('Debugging') => [ + Prefs::DEBUG_HEADLINE_IDS, + ], ]; $this->pref_help_bottom = [ - "BLACKLISTED_TAGS" => __("Never apply these tags automatically (comma-separated list)."), + Prefs::BLACKLISTED_TAGS => __("Never apply these tags automatically (comma-separated list)."), ]; $this->pref_help = [ - "ALLOW_DUPLICATE_POSTS" => array(__("Allow duplicate articles"), ""), - "BLACKLISTED_TAGS" => array(__("Blacklisted tags"), ""), - "DEFAULT_SEARCH_LANGUAGE" => array(__("Default language"), __("Used for full-text search")), - "CDM_AUTO_CATCHUP" => array(__("Mark read on scroll"), __("Mark articles as read as you scroll past them")), - "CDM_EXPANDED" => array(__("Always expand articles")), - "COMBINED_DISPLAY_MODE" => array(__("Combined mode"), __("Show flat list of articles instead of separate panels")), - "CONFIRM_FEED_CATCHUP" => array(__("Confirm marking feeds as read")), - "DEFAULT_ARTICLE_LIMIT" => array(__("Amount of articles to display at once")), - "DEFAULT_UPDATE_INTERVAL" => array(__("Default update interval")), - "DIGEST_CATCHUP" => array(__("Mark sent articles as read")), - "DIGEST_ENABLE" => array(__("Enable digest"), __("Send daily digest of new (and unread) headlines to your e-mail address")), - "DIGEST_PREFERRED_TIME" => array(__("Try to send around this time"), __("Time in UTC")), - "ENABLE_API_ACCESS" => array(__("Enable API"), __("Allows accessing this account through the API")), - "ENABLE_FEED_CATS" => array(__("Enable categories")), - "FEEDS_SORT_BY_UNREAD" => array(__("Sort feeds by unread articles count"), ""), - "FRESH_ARTICLE_MAX_AGE" => array(__("Maximum age of fresh articles"), "<strong>" . __("hours") . "</strong>"), - "HIDE_READ_FEEDS" => array(__("Hide read feeds")), - "HIDE_READ_SHOWS_SPECIAL" => array(__("Always show special feeds"), __("While hiding read feeds")), - "LONG_DATE_FORMAT" => array(__("Long date format"), __("Syntax is identical to PHP <a href='http://php.net/manual/function.date.php'>date()</a> function.")), - "ON_CATCHUP_SHOW_NEXT_FEED" => array(__("Automatically show next feed"), __("After marking one as read")), - "PURGE_OLD_DAYS" => array(__("Purge articles older than"), __("<strong>days</strong> (0 disables)")), - "PURGE_UNREAD_ARTICLES" => array(__("Purge unread articles")), - "REVERSE_HEADLINES" => array(__("Reverse headline order (oldest first)")), - "SHORT_DATE_FORMAT" => array(__("Short date format")), - "SHOW_CONTENT_PREVIEW" => array(__("Show content preview in headlines")), - "SORT_HEADLINES_BY_FEED_DATE" => array(__("Sort headlines by feed date"), __("Use feed-specified date to sort headlines instead of local import date.")), - "SSL_CERT_SERIAL" => array(__("SSL client certificate")), - "STRIP_IMAGES" => array(__("Do not embed media")), - "STRIP_UNSAFE_TAGS" => array(__("Strip unsafe tags from articles"), __("Strip all but most common HTML tags when reading articles.")), - "USER_STYLESHEET" => array(__("Customize stylesheet")), - "USER_TIMEZONE" => array(__("Time zone")), - "VFEED_GROUP_BY_FEED" => array(__("Group by feed"), __("Group multiple-feed output by originating feed")), - "USER_LANGUAGE" => array(__("Language")), - "USER_CSS_THEME" => array(__("Theme")) + Prefs::BLACKLISTED_TAGS => array(__("Blacklisted tags"), ""), + Prefs::DEFAULT_SEARCH_LANGUAGE => array(__("Default language"), __("Used for full-text search")), + Prefs::CDM_AUTO_CATCHUP => array(__("Mark read on scroll"), __("Mark articles as read as you scroll past them")), + Prefs::CDM_EXPANDED => array(__("Always expand articles")), + Prefs::COMBINED_DISPLAY_MODE => array(__("Combined mode"), __("Show flat list of articles instead of separate panels")), + Prefs::CONFIRM_FEED_CATCHUP => array(__("Confirm marking feeds as read")), + Prefs::DEFAULT_UPDATE_INTERVAL => array(__("Default update interval")), + Prefs::DIGEST_CATCHUP => array(__("Mark sent articles as read")), + Prefs::DIGEST_ENABLE => array(__("Enable digest"), __("Send daily digest of new (and unread) headlines to your e-mail address")), + Prefs::DIGEST_PREFERRED_TIME => array(__("Try to send around this time"), __("Time in UTC")), + Prefs::ENABLE_API_ACCESS => array(__("Enable API"), __("Allows accessing this account through the API")), + Prefs::ENABLE_FEED_CATS => array(__("Enable categories")), + Prefs::FRESH_ARTICLE_MAX_AGE => array(__("Maximum age of fresh articles"), "<strong>" . __("hours") . "</strong>"), + Prefs::HIDE_READ_FEEDS => array(__("Hide read feeds")), + Prefs::HIDE_READ_SHOWS_SPECIAL => array(__("Always show special feeds"), __("While hiding read feeds")), + Prefs::LONG_DATE_FORMAT => array(__("Long date format"), __("Syntax is identical to PHP <a href='http://php.net/manual/function.date.php'>date()</a> function.")), + Prefs::ON_CATCHUP_SHOW_NEXT_FEED => array(__("Automatically show next feed"), __("After marking one as read")), + Prefs::PURGE_OLD_DAYS => array(__("Purge articles older than"), __("<strong>days</strong> (0 disables)")), + Prefs::PURGE_UNREAD_ARTICLES => array(__("Purge unread articles")), + Prefs::SHORT_DATE_FORMAT => array(__("Short date format")), + Prefs::SHOW_CONTENT_PREVIEW => array(__("Show content preview in headlines")), + Prefs::SSL_CERT_SERIAL => array(__("SSL client certificate")), + Prefs::STRIP_IMAGES => array(__("Do not embed media")), + Prefs::USER_TIMEZONE => array(__("Time zone")), + Prefs::VFEED_GROUP_BY_FEED => array(__("Group by feed"), __("Group multiple-feed output by originating feed")), + Prefs::USER_LANGUAGE => array(__("Language")), + Prefs::USER_CSS_THEME => array(__("Theme")), + Prefs::HEADLINES_NO_DISTINCT => array(__("Don't enforce DISTINCT headlines"), __("May produce duplicate entries")), + Prefs::DEBUG_HEADLINE_IDS => array(__("Show article and feed IDs"), __("In the headlines buffer")), ]; - $this->pref_blacklist = ["ALLOW_DUPLICATE_POSTS", "STRIP_UNSAFE_TAGS", "REVERSE_HEADLINES", - "SORT_HEADLINES_BY_FEED_DATE", "DEFAULT_ARTICLE_LIMIT", - "FEEDS_SORT_BY_UNREAD", "USER_STYLESHEET"]; - - /* "FEEDS_SORT_BY_UNREAD", "HIDE_READ_FEEDS", "REVERSE_HEADLINES" */ - - $this->profile_blacklist = ["ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", - "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", - "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE", - "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE", - "SSL_CERT_SERIAL", "DIGEST_PREFERRED_TIME"]; + // hidden in the main prefs UI (use to hide things that have description set above) + $this->pref_blacklist = [ + // + ]; } function changepassword() { @@ -181,31 +173,33 @@ class Pref_Prefs extends Handler_Protected { $value = $_POST[$pref_name]; switch ($pref_name) { - case 'DIGEST_PREFERRED_TIME': - if (get_pref('DIGEST_PREFERRED_TIME') != $value) { + case Prefs::DIGEST_PREFERRED_TIME: + if (get_pref(Prefs::DIGEST_PREFERRED_TIME) != $value) { $sth = $this->pdo->prepare("UPDATE ttrss_users SET - last_digest_sent = NULL WHERE id = ?"); + last_digest_sent = NULL WHERE id = ?"); $sth->execute([$_SESSION['uid']]); } break; - case 'USER_LANGUAGE': + case Prefs::USER_LANGUAGE: if (!$need_reload) $need_reload = $_SESSION["language"] != $value; break; - case 'USER_CSS_THEME': + case Prefs::USER_CSS_THEME: if (!$need_reload) $need_reload = get_pref($pref_name) != $value; break; - case 'BLACKLISTED_TAGS': + case Prefs::BLACKLISTED_TAGS: $cats = FeedItem_Common::normalize_categories(explode(",", $value)); asort($cats); $value = implode(", ", $cats); break; } - set_pref($pref_name, $value); + if (Prefs::is_valid($pref_name)) { + Prefs::set($pref_name, $value, $_SESSION["uid"], $_SESSION["profile"] ?? null); + } } if ($need_reload) { @@ -260,17 +254,9 @@ class Pref_Prefs extends Handler_Protected { } function resetconfig() { + Prefs::reset($_SESSION["uid"], $_SESSION["profile"]); - $_SESSION["prefs_op_result"] = "reset-to-defaults"; - - $sth = $this->pdo->prepare("DELETE FROM ttrss_user_prefs - WHERE (profile = :profile OR (:profile IS NULL AND profile IS NULL)) - AND owner_uid = :uid"); - $sth->execute([":profile" => $_SESSION['profile'], ":uid" => $_SESSION['uid']]); - - $this->_init_user_prefs($_SESSION["uid"], $_SESSION["profile"]); - - echo __("Your preferences are now set to default values."); + print "PREFS_NEED_RELOAD"; } private function index_auth_personal() { @@ -568,35 +554,18 @@ class Pref_Prefs extends Handler_Protected { if ($profile) { print_notice(__("Some preferences are only available in default profile.")); - $this->_init_user_prefs($_SESSION["uid"], $profile); - } else { - $this->_init_user_prefs($_SESSION["uid"]); } $prefs_available = []; - - $sth = $this->pdo->prepare("SELECT DISTINCT - ttrss_user_prefs.pref_name,value,type_name, - ttrss_prefs_sections.order_id, - def_value,section_id - FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs - WHERE type_id = ttrss_prefs_types.id AND - (profile = :profile OR (:profile IS NULL AND profile IS NULL)) AND - section_id = ttrss_prefs_sections.id AND - ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND - owner_uid = :uid - ORDER BY ttrss_prefs_sections.order_id,pref_name"); - $sth->execute([":uid" => $_SESSION['uid'], ":profile" => $profile]); - $listed_boolean_prefs = []; - while ($line = $sth->fetch()) { + foreach (Prefs::get_all($_SESSION["uid"], $profile) as $line) { if (in_array($line["pref_name"], $this->pref_blacklist)) { continue; } - if ($profile && in_array($line["pref_name"], $this->profile_blacklist)) { + if ($profile && in_array($line["pref_name"], Prefs::_PROFILE_BLACKLIST)) { continue; } @@ -607,7 +576,7 @@ class Pref_Prefs extends Handler_Protected { continue; $prefs_available[$pref_name] = [ - 'type_name' => $line["type_name"], + 'type_hint' => $line['type_hint'], 'value' => $line['value'], 'help_text' => $this->_get_help_text($pref_name), 'short_desc' => $short_desc @@ -640,7 +609,7 @@ class Pref_Prefs extends Handler_Protected { print "</label>"; $value = $item['value']; - $type_name = $item['type_name']; + $type_hint = $item['type_hint']; if ($pref_name == "USER_LANGUAGE") { print \Controls\select_hash($pref_name, $value, get_translations(), @@ -701,7 +670,7 @@ class Pref_Prefs extends Handler_Protected { print \Controls\select_tag($pref_name, $value, Pref_Feeds::get_ts_languages()); - } else if ($type_name == "bool") { + } else if ($type_hint == Config::T_BOOL) { array_push($listed_boolean_prefs, $pref_name); @@ -726,7 +695,7 @@ class Pref_Prefs extends Handler_Protected { $attributes = ["required" => true]; } - if ($type_name == 'integer') + if ($type_hint == Config::T_INT) print \Controls\number_spinner_tag($pref_name, $value, $attributes); else print \Controls\input_tag($pref_name, $value, "text", $attributes); @@ -757,7 +726,7 @@ class Pref_Prefs extends Handler_Protected { $item['help_text'] .= ". " . T_sprintf("Current server time: %s", date("H:i")); } else { - $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; + $regexp = ($type_hint == Config::T_INT) ? 'regexp="^\d*$"' : ''; print "<input dojoType=\"dijit.form.ValidationTextBox\" $regexp name=\"$pref_name\" value=\"$value\">"; } @@ -863,7 +832,7 @@ class Pref_Prefs extends Handler_Protected { private function index_plugins_user() { $system_enabled = array_map("trim", explode(",", (string)Config::get(Config::PLUGINS))); - $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS"))); + $user_enabled = array_map("trim", explode(",", get_pref(Prefs::_ENABLED_PLUGINS))); $tmppluginhost = new PluginHost(); $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); @@ -1164,7 +1133,7 @@ class Pref_Prefs extends Handler_Protected { else $plugins = ""; - set_pref("_ENABLED_PLUGINS", $plugins); + set_pref(Prefs::_ENABLED_PLUGINS, $plugins); } function clearplugindata() { @@ -1174,7 +1143,7 @@ class Pref_Prefs extends Handler_Protected { } function customizeCSS() { - $value = get_pref("USER_STYLESHEET"); + $value = get_pref(Prefs::USER_STYLESHEET); $value = str_replace("<br/>", "\n", $value); print json_encode(["value" => $value]); @@ -1219,14 +1188,6 @@ class Pref_Prefs extends Handler_Protected { $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE title = ? AND owner_uid = ?"); $sth->execute([$title, $_SESSION['uid']]); - - if ($row = $sth->fetch()) { - $profile_id = $row['id']; - - if ($profile_id) { - Pref_Prefs::_init_user_prefs($_SESSION["uid"], $profile_id); - } - } } $this->pdo->commit(); @@ -1367,57 +1328,4 @@ class Pref_Prefs extends Handler_Protected { $this->appPasswordList(); } - - static function _init_user_prefs($uid, $profile = false) { - - if (get_schema_version() < 63) $profile_qpart = ""; - - $pdo = Db::pdo(); - $in_nested_tr = false; - - try { - $pdo->beginTransaction(); - } catch (Exception $e) { - $in_nested_tr = true; - } - - $sth = $pdo->query("SELECT pref_name,def_value FROM ttrss_prefs"); - - if (!is_numeric($profile) || !$profile || get_schema_version() < 63) $profile = null; - - $u_sth = $pdo->prepare("SELECT pref_name - FROM ttrss_user_prefs WHERE owner_uid = :uid AND - (profile = :profile OR (:profile IS NULL AND profile IS NULL))"); - $u_sth->execute([':uid' => $uid, ':profile' => $profile]); - - $active_prefs = array(); - - while ($line = $u_sth->fetch()) { - array_push($active_prefs, $line["pref_name"]); - } - - while ($line = $sth->fetch()) { - if (array_search($line["pref_name"], $active_prefs) === false) { -// print "adding " . $line["pref_name"] . "<br>"; - - if (get_schema_version() < 63) { - $i_sth = $pdo->prepare("INSERT INTO ttrss_user_prefs - (owner_uid,pref_name,value) VALUES - (?, ?, ?)"); - $i_sth->execute([$uid, $line["pref_name"], $line["def_value"]]); - - } else { - $i_sth = $pdo->prepare("INSERT INTO ttrss_user_prefs - (owner_uid,pref_name,value, profile) VALUES - (?, ?, ?, ?)"); - $i_sth->execute([$uid, $line["pref_name"], $line["def_value"], $profile]); - } - - } - } - - if (!$in_nested_tr) $pdo->commit(); - - } - } |