diff --git a/classes/API.php b/classes/API.php index 826d1f333..ad16f82fe 100644 --- a/classes/API.php +++ b/classes/API.php @@ -38,7 +38,7 @@ class API extends Handler { return false; } - if (!empty($_SESSION["uid"]) && $method != "logout" && !get_pref(Prefs::ENABLE_API_ACCESS)) { + if (!empty($_SESSION["uid"]) && $method != "logout" && !Prefs::get(Prefs::ENABLE_API_ACCESS, $_SESSION["uid"])) { $this->_wrap(self::STATUS_ERR, array("error" => self::E_API_DISABLED)); return false; } @@ -74,7 +74,7 @@ class API extends Handler { if (Config::get(Config::SINGLE_USER_MODE)) $login = "admin"; if ($uid = UserHelper::find_user_by_login($login)) { - if (get_pref(Prefs::ENABLE_API_ACCESS, $uid)) { + if (Prefs::get(Prefs::ENABLE_API_ACCESS, $uid)) { if (UserHelper::authenticate($login, $password, false, Auth_Base::AUTH_SERVICE_API)) { // needed for _get_config() @@ -421,7 +421,7 @@ class API extends Handler { function getPref(): bool { $pref_name = clean($_REQUEST["pref_name"]); - return $this->_wrap(self::STATUS_OK, array("value" => get_pref($pref_name))); + return $this->_wrap(self::STATUS_OK, array("value" => Prefs::get($pref_name, $_SESSION["uid"], $_SESSION["profile"] ?? null))); } function getLabels(): bool { diff --git a/classes/Article.php b/classes/Article.php index 550e42842..2bc647e48 100644 --- a/classes/Article.php +++ b/classes/Article.php @@ -337,7 +337,7 @@ class Article extends Handler_Protected { $rv['can_inline'] = isset($_SESSION["uid"]) && empty($_SESSION["bw_limit"]) && - !get_pref(Prefs::STRIP_IMAGES) && + !Prefs::get(Prefs::STRIP_IMAGES, $_SESSION["uid"], $_SESSION["profile"] ?? null) && ($always_display_enclosures || !preg_match("/fetch()) { - if (get_pref(Prefs::DIGEST_ENABLE, $line['id'])) { - $preferred_ts = strtotime(get_pref(Prefs::DIGEST_PREFERRED_TIME, $line['id']) ?? ''); + if (Prefs::get(Prefs::DIGEST_ENABLE, $line['id'])) { + $preferred_ts = strtotime(Prefs::get(Prefs::DIGEST_PREFERRED_TIME, $line['id']) ?? ''); // try to send digests within 2 hours of preferred time if ($preferred_ts && time() >= $preferred_ts && @@ -30,7 +30,7 @@ class Digest Debug::log("Sending digest for UID:" . $line['id'] . " - " . $line["email"]); - $do_catchup = get_pref(Prefs::DIGEST_CATCHUP, $line['id']); + $do_catchup = Prefs::get(Prefs::DIGEST_CATCHUP, $line['id']); global $tz_offset; @@ -156,7 +156,7 @@ class Digest $updated = TimeHelper::make_local_datetime($line['last_updated'], false, $user_id); - if (get_pref(Prefs::ENABLE_FEED_CATS, $user_id)) { + if (Prefs::get(Prefs::ENABLE_FEED_CATS, $user_id)) { $line['feed_title'] = $line['cat_title'] . " / " . $line['feed_title']; } diff --git a/classes/Feeds.php b/classes/Feeds.php index b4df690a7..91802e1ad 100644 --- a/classes/Feeds.php +++ b/classes/Feeds.php @@ -60,6 +60,8 @@ class Feeds extends Handler_Protected { int $offset, string $override_order, bool $include_children, ?int $check_first_id = null, ?bool $skip_first_id_check = false, ? string $order_by = ''): array { + $profile = $_SESSION['profile'] ?? null; + $disable_cache = false; $reply = []; @@ -144,7 +146,7 @@ class Feeds extends Handler_Protected { $qfh_ret = $this->_get_headlines($params); } - $vfeed_group_enabled = get_pref(Prefs::VFEED_GROUP_BY_FEED) && + $vfeed_group_enabled = Prefs::get(Prefs::VFEED_GROUP_BY_FEED, $_SESSION['uid'], $profile) && !(in_array($feed, self::NEVER_GROUP_FEEDS) && !$cat_view); $result = $qfh_ret[0]; // this could be either a PDO query result or a -1 if first id changed @@ -201,7 +203,7 @@ class Feeds extends Handler_Protected { ++$headlines_count; - if (!get_pref(Prefs::SHOW_CONTENT_PREVIEW)) { + if (!Prefs::get(Prefs::SHOW_CONTENT_PREVIEW, $_SESSION['uid'], $profile)) { $line["content_preview"] = ""; } else { $line["content_preview"] = "— " . truncate_string(strip_tags($line["content"]), 250); @@ -318,12 +320,12 @@ class Feeds extends Handler_Protected { $line["content"] = Sanitizer::sanitize($line["content"], $line['hide_images'], null, $line["site_url"], $highlight_words, $line["id"]); - if (!get_pref(Prefs::CDM_EXPANDED)) { + if (!Prefs::get(Prefs::CDM_EXPANDED, $_SESSION['uid'], $profile)) { $line["cdm_excerpt"] = " remove_circle"; - if (get_pref(Prefs::SHOW_CONTENT_PREVIEW)) { + if (Prefs::get(Prefs::SHOW_CONTENT_PREVIEW, $_SESSION['uid'], $profile)) { $line["cdm_excerpt"] .= "" . $line["content_preview"] . ""; } } @@ -460,6 +462,8 @@ class Feeds extends Handler_Protected { } function view(): void { + $profile = $_SESSION['profile'] ?? null; + $reply = array(); $feed = $_REQUEST["feed"]; @@ -502,8 +506,8 @@ class Feeds extends Handler_Protected { return; } - set_pref(Prefs::_DEFAULT_VIEW_MODE, $view_mode); - set_pref(Prefs::_DEFAULT_VIEW_ORDER_BY, $order_by); + Prefs::set(Prefs::_DEFAULT_VIEW_MODE, $view_mode, $_SESSION['uid'], $profile); + Prefs::set(Prefs::_DEFAULT_VIEW_ORDER_BY, $order_by, $_SESSION['uid'], $profile); /* bump login timestamp if needed */ if (time() - $_SESSION["last_login_update"] > 3600) { @@ -584,7 +588,7 @@ class Feeds extends Handler_Protected { "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(Prefs::DEFAULT_SEARCH_LANGUAGE) + "default_language" => Prefs::get(Prefs::DEFAULT_SEARCH_LANGUAGE, $_SESSION['uid'], $_SESSION['profile'] ?? null) ]); } @@ -738,8 +742,8 @@ class Feeds extends Handler_Protected { * @param array $search */ static function _catchup(string $feed_id_or_tag_name, bool $cat_view, ?int $owner_uid = null, string $mode = 'all', ?array $search = null): void { - if (!$owner_uid) $owner_uid = $_SESSION['uid']; + $profile = isset($_SESSION['uid']) && $owner_uid == $_SESSION['uid'] && isset($_SESSION['profile']) ? $_SESSION['profile'] : null; $pdo = Db::pdo(); @@ -858,7 +862,7 @@ class Feeds extends Handler_Protected { if ($feed_id == Feeds::FEED_FRESH) { - $intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE); + $intl = (int) Prefs::get(Prefs::FRESH_ARTICLE_MAX_AGE, $owner_uid, $profile); if (Config::get(Config::DB_TYPE) == "pgsql") { $match_part = "date_entered > NOW() - INTERVAL '$intl hour' "; @@ -923,6 +927,7 @@ class Feeds extends Handler_Protected { $pdo = Db::pdo(); if (!$owner_uid) $owner_uid = $_SESSION["uid"]; + $profile = isset($_SESSION['uid']) && $owner_uid == $_SESSION['uid'] && isset($_SESSION['profile']) ? $_SESSION['profile'] : null; if ($unread_only) { $unread_qpart = "unread = true"; @@ -961,7 +966,7 @@ class Feeds extends Handler_Protected { } else if ($n_feed == Feeds::FEED_FRESH) { $match_part = "unread = true AND score >= 0"; - $intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE, $owner_uid); + $intl = (int) Prefs::get(Prefs::FRESH_ARTICLE_MAX_AGE, $owner_uid, $profile); if (Config::get(Config::DB_TYPE) == "pgsql") { $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; @@ -1422,6 +1427,7 @@ class Feeds extends Handler_Protected { $override_order = $params["override_order"] ?? false; $offset = $params["offset"] ?? 0; $owner_uid = $params["owner_uid"] ?? $_SESSION["uid"]; + $profile = $owner_uid == $_SESSION["uid"] && isset($_SESSION["profile"]) ? $_SESSION["profile"] : null; $since_id = $params["since_id"] ?? 0; $include_children = $params["include_children"] ?? false; $ignore_vfeed_group = $params["ignore_vfeed_group"] ?? false; @@ -1608,7 +1614,7 @@ class Feeds extends Handler_Protected { } else if ($feed == Feeds::FEED_FRESH) { // fresh virtual feed $query_strategy_part = "unread = true AND score >= 0"; - $intl = (int) get_pref(Prefs::FRESH_ARTICLE_MAX_AGE, $owner_uid); + $intl = (int) Prefs::get(Prefs::FRESH_ARTICLE_MAX_AGE, $owner_uid, $profile); if (Config::get(Config::DB_TYPE) == "pgsql") { $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; @@ -1664,7 +1670,7 @@ class Feeds extends Handler_Protected { $ssth = $pdo->prepare("SELECT title,site_url,last_error,last_updated FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); $ssth->execute([$feed, $owner_uid]); - $row = $ssth->fetch(); + $row = $ssth->fetch(); $feed_title = $row["title"]; $feed_site_url = $row["site_url"]; @@ -1701,7 +1707,8 @@ class Feeds extends Handler_Protected { if (is_numeric($feed)) { // proper override_order applied above - if ($vfeed_query_part && !$ignore_vfeed_group && get_pref(Prefs::VFEED_GROUP_BY_FEED, $owner_uid)) { + if ($vfeed_query_part && !$ignore_vfeed_group + && Prefs::get(Prefs::VFEED_GROUP_BY_FEED, $owner_uid, $profile)) { if (!(in_array($feed, self::NEVER_GROUP_BY_DATE) && !$cat_view)) { $yyiw_desc = $order_by == "date_reverse" ? "" : "desc"; @@ -1745,7 +1752,8 @@ class Feeds extends Handler_Protected { } // except for Labels category - if (get_pref(Prefs::HEADLINES_NO_DISTINCT, $owner_uid) && !($feed == Feeds::CATEGORY_LABELS && $cat_view)) { + if (Prefs::get(Prefs::HEADLINES_NO_DISTINCT, $owner_uid, $profile) + && !($feed == Feeds::CATEGORY_LABELS && $cat_view)) { $distinct_qpart = ""; } @@ -1839,7 +1847,7 @@ class Feeds extends Handler_Protected { } else { // browsing by tag - if (get_pref(Prefs::HEADLINES_NO_DISTINCT, $owner_uid)) { + if (Prefs::get(Prefs::HEADLINES_NO_DISTINCT, $owner_uid, $profile)) { $distinct_qpart = ""; } else { if (Config::get(Config::DB_TYPE) == "pgsql") { @@ -2133,12 +2141,13 @@ class Feeds extends Handler_Protected { if ($row = $sth->fetch()) { $owner_uid = $row["owner_uid"]; + 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 = Config::get(Config::FORCE_ARTICLE_PURGE); } else { - $purge_unread = get_pref(Prefs::PURGE_UNREAD_ARTICLES, $owner_uid); + $purge_unread = Prefs::get(Prefs::PURGE_UNREAD_ARTICLES, $owner_uid); } $purge_interval = (int) $purge_interval; @@ -2195,7 +2204,7 @@ class Feeds extends Handler_Protected { if ($feed->purge_interval != 0) return $feed->purge_interval; else - return get_pref(Prefs::PURGE_OLD_DAYS, $feed->owner_uid); + return Prefs::get(Prefs::PURGE_OLD_DAYS, $feed->owner_uid); } else { return -1; } @@ -2203,6 +2212,7 @@ class Feeds extends Handler_Protected { /** * @return array{0: string, 1: array} [$search_query_part, $search_words] + * @todo $owner_uid and $_SESSION['uid'] are being used interchangeably-- maybe also pass in the profile so prefs can be correct */ private static function _search_to_sql(string $search, string $search_language, int $owner_uid): array { // Modify the search string so that 'keyword:"foo bar"' becomes '"keyword:foo bar"'. @@ -2218,7 +2228,8 @@ class Feeds extends Handler_Protected { $pdo = Db::pdo(); - $search_language = $pdo->quote(mb_strtolower($search_language ?: get_pref(Prefs::DEFAULT_SEARCH_LANGUAGE, $owner_uid))); + // TODO: profile should be used here or DEFAULT_SEARCH_LANGUAGE added to Prefs::_PROFILE_BLACKLIST + $search_language = $pdo->quote(mb_strtolower($search_language ?: Prefs::get(Prefs::DEFAULT_SEARCH_LANGUAGE, $owner_uid))); /** @var string $k a keyword pair (not yet split) or standalone value */ foreach ($keywords as $k) { @@ -2329,7 +2340,7 @@ class Feeds extends Handler_Protected { default: // @{date} handling if (strpos($k, "@") === 0) { - $user_tz_string = get_pref(Prefs::USER_TIMEZONE, $_SESSION['uid']); + $user_tz_string = Prefs::get(Prefs::USER_TIMEZONE, $_SESSION['uid']); $orig_ts = strtotime(substr($k, 1)); $k = date("Y-m-d", TimeHelper::convert_timestamp($orig_ts, $user_tz_string, 'UTC')); diff --git a/classes/Handler_Public.php b/classes/Handler_Public.php index 518dcad05..efa26646b 100644 --- a/classes/Handler_Public.php +++ b/classes/Handler_Public.php @@ -42,8 +42,9 @@ class Handler_Public extends Handler { ); if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { - - $user_plugins = get_pref(Prefs::_ENABLED_PLUGINS, $owner_uid); + // TODO: _ENABLED_PLUGINS is profile-specific, so use of the default profile's plugins here should + // be called out in the docs, and/or access key stuff (see 'rss()') should also consider the profile + $user_plugins = Prefs::get(Prefs::_ENABLED_PLUGINS, $owner_uid); $tmppluginhost = new PluginHost(); $tmppluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL); diff --git a/classes/OPML.php b/classes/OPML.php index 6b95a89db..fce614a17 100644 --- a/classes/OPML.php +++ b/classes/OPML.php @@ -363,6 +363,9 @@ class OPML extends Handler_Protected { } } + /** + * @todo support passing in $profile so 'update.php --opml-import' can import prefs to a user profile + */ private function opml_import_preference(DOMNode $node, int $owner_uid, int $nest): void { $attrs = $node->attributes; $pref_name = $attrs->getNamedItem('pref-name')->nodeValue; @@ -373,7 +376,7 @@ class OPML extends Handler_Protected { $this->opml_notice(T_sprintf("Setting preference key %s to %s", $pref_name, $pref_value), $nest); - set_pref($pref_name, $pref_value, $owner_uid); + Prefs::set($pref_name, $pref_value, $owner_uid, $_SESSION['profile'] ?? null); } } diff --git a/classes/Pref_Feeds.php b/classes/Pref_Feeds.php index 8101b9531..7256a5dce 100644 --- a/classes/Pref_Feeds.php +++ b/classes/Pref_Feeds.php @@ -112,6 +112,7 @@ class Pref_Feeds extends Handler_Protected { * @return array|string> */ function _makefeedtree(): array { + $profile = $_SESSION['profile'] ?? null; if (clean($_REQUEST['mode'] ?? 0) != 2) $search = $_SESSION["prefs_feed_search"] ?? ""; @@ -125,7 +126,7 @@ class Pref_Feeds extends Handler_Protected { $root['param'] = 0; $root['type'] = 'category'; - $enable_cats = get_pref(Prefs::ENABLE_FEED_CATS); + $enable_cats = Prefs::get(Prefs::ENABLE_FEED_CATS, $_SESSION['uid'], $profile); if (clean($_REQUEST['mode'] ?? 0) == 2) { @@ -175,7 +176,7 @@ class Pref_Feeds extends Handler_Protected { ttrss_labels2 WHERE owner_uid = ? ORDER by caption"); $sth->execute([$_SESSION['uid']]); - if (get_pref(Prefs::ENABLE_FEED_CATS)) { + if (Prefs::get(Prefs::ENABLE_FEED_CATS, $_SESSION['uid'], $profile)) { $cat = $this->feedlist_init_cat(Feeds::CATEGORY_LABELS); } else { $cat['items'] = []; @@ -522,6 +523,8 @@ class Pref_Feeds extends Handler_Protected { global $purge_intervals; global $update_intervals; + $profile = $_SESSION['profile'] ?? null; + $feed_id = (int)clean($_REQUEST["id"]); $row = ORM::for_table('ttrss_feeds') @@ -538,11 +541,11 @@ class Pref_Feeds extends Handler_Protected { $row["icon"] = Feeds::_get_icon($feed_id); $local_update_intervals = $update_intervals; - $local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref(Prefs::DEFAULT_UPDATE_INTERVAL)]); + $local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[Prefs::get(Prefs::DEFAULT_UPDATE_INTERVAL, $_SESSION['uid'])]); if (Config::get(Config::FORCE_ARTICLE_PURGE) == 0) { $local_purge_intervals = $purge_intervals; - $default_purge_interval = get_pref(Prefs::PURGE_OLD_DAYS); + $default_purge_interval = Prefs::get(Prefs::PURGE_OLD_DAYS, $_SESSION['uid']); if ($default_purge_interval > 0) $local_purge_intervals[0] .= " " . T_nsprintf('(%d day)', '(%d days)', $default_purge_interval, $default_purge_interval); @@ -559,7 +562,7 @@ class Pref_Feeds extends Handler_Protected { print json_encode([ "feed" => $row, "cats" => [ - "enabled" => get_pref(Prefs::ENABLE_FEED_CATS), + "enabled" => Prefs::get(Prefs::ENABLE_FEED_CATS, $_SESSION['uid'], $profile), "select" => \Controls\select_feeds_cats("cat_id", $row["cat_id"]), ], "plugin_data" => $plugin_data, @@ -573,7 +576,7 @@ class Pref_Feeds extends Handler_Protected { ], "lang" => [ "enabled" => Config::get(Config::DB_TYPE) == "pgsql", - "default" => get_pref(Prefs::DEFAULT_SEARCH_LANGUAGE), + "default" => Prefs::get(Prefs::DEFAULT_SEARCH_LANGUAGE, $_SESSION['uid'], $profile), "all" => $this::get_ts_languages(), ] ]); @@ -592,10 +595,10 @@ class Pref_Feeds extends Handler_Protected { $feed_ids = clean($_REQUEST["ids"]); $local_update_intervals = $update_intervals; - $local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref(Prefs::DEFAULT_UPDATE_INTERVAL)]); + $local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[Prefs::get(Prefs::DEFAULT_UPDATE_INTERVAL, $_SESSION['uid'])]); $local_purge_intervals = $purge_intervals; - $default_purge_interval = get_pref(Prefs::PURGE_OLD_DAYS); + $default_purge_interval = Prefs::get(Prefs::PURGE_OLD_DAYS, $_SESSION['uid']); if ($default_purge_interval > 0) $local_purge_intervals[0] .= " " . T_sprintf("(%d days)", $default_purge_interval); @@ -620,7 +623,7 @@ class Pref_Feeds extends Handler_Protected {
- +
'1']) ?> @@ -827,7 +830,7 @@ class Pref_Feeds extends Handler_Protected { break; case "cat_id": - if (get_pref(Prefs::ENABLE_FEED_CATS)) { + if (Prefs::get(Prefs::ENABLE_FEED_CATS, $_SESSION['uid'], $_SESSION['profile'] ?? null)) { $qpart = "cat_id = ?"; $qparams = $cat_id ? [$cat_id] : [null]; } @@ -937,7 +940,7 @@ class Pref_Feeds extends Handler_Protected {
- +
@@ -1196,7 +1199,7 @@ class Pref_Feeds extends Handler_Protected { function batchSubscribe(): void { print json_encode([ - "enable_cats" => (int)get_pref(Prefs::ENABLE_FEED_CATS), + "enable_cats" => (int)Prefs::get(Prefs::ENABLE_FEED_CATS, $_SESSION['uid'], $_SESSION['profile'] ?? null), "cat_select" => \Controls\select_feeds_cats("cat") ]); } diff --git a/classes/Pref_Filters.php b/classes/Pref_Filters.php index 87237342a..46cf6c30c 100644 --- a/classes/Pref_Filters.php +++ b/classes/Pref_Filters.php @@ -873,7 +873,7 @@ class Pref_Filters extends Handler_Protected { } } - if (get_pref(Prefs::ENABLE_FEED_CATS)) { + if (Prefs::get(Prefs::ENABLE_FEED_CATS, $_SESSION['uid'], $_SESSION['profile'] ?? null)) { if (!$root_id) $root_id = null; diff --git a/classes/Pref_Prefs.php b/classes/Pref_Prefs.php index 47d6886f9..5c4bd6872 100644 --- a/classes/Pref_Prefs.php +++ b/classes/Pref_Prefs.php @@ -185,6 +185,8 @@ class Pref_Prefs extends Handler_Protected { } function saveconfig(): void { + $profile = $_SESSION['profile'] ?? null; + $boolean_prefs = explode(",", clean($_POST["boolean_prefs"])); foreach ($boolean_prefs as $pref) { @@ -199,7 +201,7 @@ class Pref_Prefs extends Handler_Protected { switch ($pref_name) { case Prefs::DIGEST_PREFERRED_TIME: - if (get_pref(Prefs::DIGEST_PREFERRED_TIME) != $value) { + if (Prefs::get(Prefs::DIGEST_PREFERRED_TIME, $_SESSION['uid']) != $value) { $sth = $this->pdo->prepare("UPDATE ttrss_users SET last_digest_sent = NULL WHERE id = ?"); @@ -212,7 +214,7 @@ class Pref_Prefs extends Handler_Protected { break; case Prefs::USER_CSS_THEME: - if (!$need_reload) $need_reload = get_pref($pref_name) != $value; + if (!$need_reload) $need_reload = Prefs::get(Prefs::USER_CSS_THEME, $_SESSION['uid'], $profile) != $value; break; case Prefs::BLACKLISTED_TAGS: @@ -223,7 +225,7 @@ class Pref_Prefs extends Handler_Protected { } if (Prefs::is_valid($pref_name)) { - Prefs::set($pref_name, $value, $_SESSION["uid"], $_SESSION["profile"] ?? null); + Prefs::set($pref_name, $value, $_SESSION['uid'], $profile); } } @@ -802,7 +804,7 @@ class Pref_Prefs extends Handler_Protected { function getPluginsList(): void { $system_enabled = array_map("trim", explode(",", (string)Config::get(Config::PLUGINS))); - $user_enabled = array_map("trim", explode(",", get_pref(Prefs::_ENABLED_PLUGINS))); + $user_enabled = array_map('trim', explode(',', Prefs::get(Prefs::_ENABLED_PLUGINS, $_SESSION['uid'], $_SESSION['profile'] ?? null))); $tmppluginhost = new PluginHost(); $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); @@ -1031,7 +1033,7 @@ class Pref_Prefs extends Handler_Protected { function setplugins(): void { $plugins = array_filter($_REQUEST["plugins"] ?? [], 'clean'); - set_pref(Prefs::_ENABLED_PLUGINS, implode(",", $plugins)); + Prefs::set(Prefs::_ENABLED_PLUGINS, implode(',', $plugins), $_SESSION['uid'], $_SESSION['profile'] ?? null); } function _get_plugin_version(Plugin $plugin): string { @@ -1350,7 +1352,7 @@ class Pref_Prefs extends Handler_Protected { } function customizeCSS(): void { - $value = get_pref(Prefs::USER_STYLESHEET); + $value = Prefs::get(Prefs::USER_STYLESHEET, $_SESSION['uid'], $_SESSION['profile'] ?? null); $value = str_replace("
", "\n", $value); print json_encode(["value" => $value]); diff --git a/classes/RPC.php b/classes/RPC.php index ca8021877..4f7df652c 100644 --- a/classes/RPC.php +++ b/classes/RPC.php @@ -42,8 +42,9 @@ class RPC extends Handler_Protected { function togglepref(): void { $key = clean($_REQUEST["key"]); - set_pref($key, !get_pref($key)); - $value = get_pref($key); + $profile = $_SESSION['profile'] ?? null; + Prefs::set($key, !Prefs::get($key, $_SESSION['uid'], $profile), $_SESSION['uid'], $profile); + $value = Prefs::get($key, $_SESSION['uid'], $profile); print json_encode(array("param" =>$key, "value" => $value)); } @@ -53,7 +54,7 @@ class RPC extends Handler_Protected { $key = clean($_REQUEST['key']); $value = $_REQUEST['value']; - set_pref($key, $value, $_SESSION["uid"], $key != 'USER_STYLESHEET'); + Prefs::set($key, $value, $_SESSION['uid'], $_SESSION['profile'] ?? null, $key != 'USER_STYLESHEET'); print json_encode(array("param" =>$key, "value" => $value)); } @@ -124,7 +125,8 @@ class RPC extends Handler_Protected { else $label_ids = array_map("intval", clean($_REQUEST["label_ids"] ?? [])); - $counters = is_array($feed_ids) && !get_pref(Prefs::DISABLE_CONDITIONAL_COUNTERS) ? + $counters = is_array($feed_ids) + && !Prefs::get(Prefs::DISABLE_CONDITIONAL_COUNTERS, $_SESSION['uid'], $_SESSION['profile'] ?? null) ? Counters::get_conditional($feed_ids, $label_ids) : Counters::get_all(); $reply = [ @@ -241,7 +243,7 @@ class RPC extends Handler_Protected { function setWidescreen(): void { $wide = (int) clean($_REQUEST["wide"]); - set_pref(Prefs::WIDESCREEN_MODE, $wide); + Prefs::set(Prefs::WIDESCREEN_MODE, $wide, $_SESSION['uid'], $_SESSION['profile'] ?? null); print json_encode(["wide" => $wide]); } @@ -436,6 +438,7 @@ class RPC extends Handler_Protected { * @return array */ private function _make_init_params(): array { + $profile = $_SESSION['profile'] ?? null; $params = array(); foreach ([Prefs::ON_CATCHUP_SHOW_NEXT_FEED, Prefs::HIDE_READ_FEEDS, @@ -444,21 +447,21 @@ class RPC extends Handler_Protected { Prefs::FRESH_ARTICLE_MAX_AGE, Prefs::HIDE_READ_SHOWS_SPECIAL, Prefs::COMBINED_DISPLAY_MODE, Prefs::DEBUG_HEADLINE_IDS, Prefs::CDM_ENABLE_GRID] as $param) { - $params[strtolower($param)] = (int) get_pref($param); + $params[strtolower($param)] = (int) Prefs::get($param, $_SESSION['uid'], $profile); } $params["safe_mode"] = !empty($_SESSION["safe_mode"]); $params["check_for_updates"] = Config::get(Config::CHECK_FOR_UPDATES); $params["icons_url"] = Config::get_self_url() . '/public.php'; $params["cookie_lifetime"] = Config::get(Config::SESSION_COOKIE_LIFETIME); - $params["default_view_mode"] = get_pref(Prefs::_DEFAULT_VIEW_MODE); - $params["default_view_limit"] = (int) get_pref(Prefs::_DEFAULT_VIEW_LIMIT); - $params["default_view_order_by"] = get_pref(Prefs::_DEFAULT_VIEW_ORDER_BY); + $params["default_view_mode"] = Prefs::get(Prefs::_DEFAULT_VIEW_MODE, $_SESSION['uid'], $profile); + $params["default_view_limit"] = (int) Prefs::get(Prefs::_DEFAULT_VIEW_LIMIT, $_SESSION['uid'], $profile); + $params["default_view_order_by"] = Prefs::get(Prefs::_DEFAULT_VIEW_ORDER_BY, $_SESSION['uid'], $profile); $params["bw_limit"] = (int) ($_SESSION["bw_limit"] ?? false); $params["is_default_pw"] = UserHelper::is_default_password(); $params["label_base_index"] = LABEL_BASE_INDEX; - $theme = get_pref(Prefs::USER_CSS_THEME); + $theme = Prefs::get(Prefs::USER_CSS_THEME, $_SESSION['uid'], $profile); $params["theme"] = theme_exists($theme) ? $theme : ""; $params["plugins"] = implode(", ", PluginHost::getInstance()->get_plugin_names()); @@ -480,7 +483,7 @@ class RPC extends Handler_Protected { $params["max_feed_id"] = (int) $max_feed_id; $params["num_feeds"] = (int) $num_feeds; $params["hotkeys"] = $this->get_hotkeys_map(); - $params["widescreen"] = (int) get_pref(Prefs::WIDESCREEN_MODE); + $params["widescreen"] = (int) Prefs::get(Prefs::WIDESCREEN_MODE, $_SESSION['uid'], $profile); $params['simple_update'] = Config::get(Config::SIMPLE_UPDATE_MODE); $params["icon_indicator_white"] = $this->image_to_base64("images/indicator_white.gif"); $params["icon_oval"] = $this->image_to_base64("images/oval.svg"); @@ -521,7 +524,7 @@ class RPC extends Handler_Protected { $data["max_feed_id"] = (int) $max_feed_id; $data["num_feeds"] = (int) $num_feeds; - $data['cdm_expanded'] = get_pref(Prefs::CDM_EXPANDED); + $data['cdm_expanded'] = Prefs::get(Prefs::CDM_EXPANDED, $_SESSION['uid'], $_SESSION['profile'] ?? null); $data["labels"] = Labels::get_all($_SESSION["uid"]); if (Config::get(Config::LOG_DESTINATION) == 'sql' && $_SESSION['access_level'] >= UserHelper::ACCESS_LEVEL_ADMIN) { diff --git a/classes/RSSUtils.php b/classes/RSSUtils.php index cfd0b3b61..281e85bff 100644 --- a/classes/RSSUtils.php +++ b/classes/RSSUtils.php @@ -321,7 +321,7 @@ class RSSUtils { if ($feed) { $pluginhost = new PluginHost(); - $user_plugins = get_pref(Prefs::_ENABLED_PLUGINS, $feed->owner_uid); + $user_plugins = Prefs::get(Prefs::_ENABLED_PLUGINS, $feed->owner_uid); $pluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL); $pluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $feed->owner_uid); @@ -403,7 +403,7 @@ class RSSUtils { $feed_language = mb_strtolower($feed_obj->feed_language); - if (!$feed_language) $feed_language = mb_strtolower(get_pref(Prefs::DEFAULT_SEARCH_LANGUAGE, $feed_obj->owner_uid)); + if (!$feed_language) $feed_language = mb_strtolower(Prefs::get(Prefs::DEFAULT_SEARCH_LANGUAGE, $feed_obj->owner_uid)); if (!$feed_language) $feed_language = 'simple'; $user = ORM::for_table('ttrss_users')->find_one($feed_obj->owner_uid); @@ -436,7 +436,7 @@ class RSSUtils { $cache_filename = sha1($feed_obj->feed_url) . ".xml"; $pluginhost = new PluginHost(); - $user_plugins = get_pref(Prefs::_ENABLED_PLUGINS, $feed_obj->owner_uid); + $user_plugins = Prefs::get(Prefs::_ENABLED_PLUGINS, $feed_obj->owner_uid); $pluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL); $pluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $feed_obj->owner_uid); @@ -1274,7 +1274,7 @@ class RSSUtils { $entry_tags = FeedItem_Common::normalize_categories( array_diff($entry_tags, FeedItem_Common::normalize_categories(explode(",", - get_pref(Prefs::BLACKLISTED_TAGS, $feed_obj->owner_uid))))); + Prefs::get(Prefs::BLACKLISTED_TAGS, $feed_obj->owner_uid))))); Debug::log("resulting article tags: " . implode(", ", $entry_tags), Debug::LOG_VERBOSE); diff --git a/classes/Sanitizer.php b/classes/Sanitizer.php index 0bbb30586..efed9d418 100644 --- a/classes/Sanitizer.php +++ b/classes/Sanitizer.php @@ -68,6 +68,8 @@ class Sanitizer { if (!$owner && isset($_SESSION["uid"])) $owner = $_SESSION["uid"]; + $profile = isset($_SESSION['uid']) && $owner == $_SESSION['uid'] && isset($_SESSION['profile']) ? $_SESSION['profile'] : null; + $res = trim($str); if (!$res) return ''; $doc = new DOMDocument(); @@ -117,8 +119,7 @@ class Sanitizer { } if ($entry->hasAttribute('src') && - ($owner && get_pref(Prefs::STRIP_IMAGES, $owner)) || $force_remove_images || ($_SESSION["bw_limit"] ?? false)) { - + ($owner && Prefs::get(Prefs::STRIP_IMAGES, $owner, $profile)) || $force_remove_images || ($_SESSION['bw_limit'] ?? false)) { $p = $doc->createElement('p'); $a = $doc->createElement('a'); diff --git a/classes/TimeHelper.php b/classes/TimeHelper.php index f1c437831..a516f83a6 100644 --- a/classes/TimeHelper.php +++ b/classes/TimeHelper.php @@ -3,20 +3,21 @@ class TimeHelper { static function smart_date_time(int $timestamp, int $tz_offset = 0, ?int $owner_uid = null, bool $eta_min = false): string { if (!$owner_uid) $owner_uid = $_SESSION['uid']; + $profile = isset($_SESSION['uid']) && $owner_uid == $_SESSION['uid'] && isset($_SESSION['profile']) ? $_SESSION['profile'] : null; if ($eta_min && time() + $tz_offset - $timestamp < 3600) { return T_sprintf("%d min", date("i", time() + $tz_offset - $timestamp)); } else if (date("Y.m.d", $timestamp) == date("Y.m.d", time() + $tz_offset)) { - $format = get_pref(Prefs::SHORT_DATE_FORMAT, $owner_uid); + $format = Prefs::get(Prefs::SHORT_DATE_FORMAT, $owner_uid, $profile); if (strpos((strtolower($format)), "a") === false) return date("G:i", $timestamp); else return date("g:i a", $timestamp); } else if (date("Y", $timestamp) == date("Y", time() + $tz_offset)) { - $format = get_pref(Prefs::SHORT_DATE_FORMAT, $owner_uid); + $format = Prefs::get(Prefs::SHORT_DATE_FORMAT, $owner_uid, $profile); return date($format, $timestamp); } else { - $format = get_pref(Prefs::LONG_DATE_FORMAT, $owner_uid); + $format = Prefs::get(Prefs::LONG_DATE_FORMAT, $owner_uid, $profile); return date($format, $timestamp); } } @@ -25,6 +26,8 @@ class TimeHelper { bool $no_smart_dt = false, bool $eta_min = false): string { if (!$owner_uid) $owner_uid = $_SESSION['uid']; + $profile = isset($_SESSION['uid']) && $owner_uid == $_SESSION['uid'] && isset($_SESSION['profile']) ? $_SESSION['profile'] : null; + if (!$timestamp) $timestamp = '1970-01-01 0:00'; global $utc_tz; @@ -37,7 +40,7 @@ class TimeHelper { # We store date in UTC internally $dt = new DateTime($timestamp, $utc_tz); - $user_tz_string = get_pref(Prefs::USER_TIMEZONE, $owner_uid); + $user_tz_string = Prefs::get(Prefs::USER_TIMEZONE, $owner_uid); if ($user_tz_string != 'Automatic') { @@ -59,9 +62,9 @@ class TimeHelper { $tz_offset, $owner_uid, $eta_min); } else { if ($long) - $format = get_pref(Prefs::LONG_DATE_FORMAT, $owner_uid); + $format = Prefs::get(Prefs::LONG_DATE_FORMAT, $owner_uid, $profile); else - $format = get_pref(Prefs::SHORT_DATE_FORMAT, $owner_uid); + $format = Prefs::get(Prefs::SHORT_DATE_FORMAT, $owner_uid, $profile); return date($format, $user_timestamp); } diff --git a/classes/UserHelper.php b/classes/UserHelper.php index 27e022624..aa2d4ce19 100644 --- a/classes/UserHelper.php +++ b/classes/UserHelper.php @@ -127,7 +127,9 @@ class UserHelper { $_SESSION["csrf_token"] = bin2hex(get_random_bytes(16)); if (Config::get_schema_version() >= 120) { - $_SESSION["language"] = get_pref(Prefs::USER_LANGUAGE, $owner_uid); + // TODO: USER_LANGUAGE is currently profile-specific, so we should pass it in here, + // but $_SESSION['profile'] isn't currently available until after the login flow completes. + $_SESSION["language"] = Prefs::get(Prefs::USER_LANGUAGE, $owner_uid); } } @@ -136,7 +138,8 @@ class UserHelper { if (!$pluginhost) $pluginhost = PluginHost::getInstance(); if ($owner_uid && Config::get_schema_version() >= 100 && empty($_SESSION["safe_mode"])) { - $plugins = get_pref(Prefs::_ENABLED_PLUGINS, $owner_uid); + $profile = isset($_SESSION['uid']) && $owner_uid == $_SESSION['uid'] && isset($_SESSION['profile']) ? $_SESSION['profile'] : null; + $plugins = Prefs::get(Prefs::_ENABLED_PLUGINS, $owner_uid, $profile); $pluginhost->load((string)$plugins, PluginHost::KIND_USER, $owner_uid); @@ -192,7 +195,7 @@ class UserHelper { } static function print_user_stylesheet(): void { - $value = get_pref(Prefs::USER_STYLESHEET); + $value = Prefs::get(Prefs::USER_STYLESHEET, $_SESSION['uid'], $_SESSION['profile'] ?? null); if ($value) { print "