X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=include%2Fdb-prefs.php;h=d786e53494b8332de784755b51b06c46e6773cd8;hb=6322ac79a020ab584d412d782d62b2ee77d7c6cf;hp=696aae5d16d9689896477912fb54909cd46d0eb8;hpb=0380cfa9eee1293b0c81802884aefbadaaab9671;p=tt-rss.git diff --git a/include/db-prefs.php b/include/db-prefs.php index 696aae5d..d786e534 100644 --- a/include/db-prefs.php +++ b/include/db-prefs.php @@ -7,9 +7,44 @@ $_SESSION["prefs_cache"] = array(); } - function get_pref($link, $pref_name, $user_id = false, $die_on_error = false) { + function cache_prefs() { + $profile = false; + + $user_id = $_SESSION["uid"]; + @$profile = $_SESSION["profile"]; - $pref_name = db_escape_string($pref_name); + if ($profile) { + $profile_qpart = "profile = '$profile' AND"; + } else { + $profile_qpart = "profile IS NULL AND"; + } + + if (get_schema_version() < 63) $profile_qpart = ""; + + $result = db_query( "SELECT + value,ttrss_prefs_types.type_name as type_name,ttrss_prefs.pref_name AS pref_name + FROM + ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types + WHERE + $profile_qpart + ttrss_prefs.pref_name NOT LIKE '_MOBILE%' AND + ttrss_prefs_types.id = type_id AND + owner_uid = '$user_id' AND + ttrss_user_prefs.pref_name = ttrss_prefs.pref_name"); + + while ($line = db_fetch_assoc($result)) { + if ($user_id == $_SESSION["uid"]) { + $pref_name = $line["pref_name"]; + + $_SESSION["prefs_cache"][$pref_name]["type"] = $line["type_name"]; + $_SESSION["prefs_cache"][$pref_name]["value"] = $line["value"]; + } + } + } + + function get_pref( $pref_name, $user_id = false, $die_on_error = false) { + + $pref_name = db_escape_string( $pref_name); $prefs_cache = true; $profile = false; @@ -34,9 +69,9 @@ $profile_qpart = "profile IS NULL AND"; } - if (get_schema_version($link) < 63) $profile_qpart = ""; + if (get_schema_version() < 63) $profile_qpart = ""; - $result = db_query($link, "SELECT + $result = db_query( "SELECT value,ttrss_prefs_types.type_name as type_name FROM ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types @@ -79,9 +114,9 @@ } } - function set_pref($link, $pref_name, $value, $user_id = false, $strip_tags = true) { - $pref_name = db_escape_string($pref_name); - $value = db_escape_string($value, $strip_tags); + function set_pref( $pref_name, $value, $user_id = false, $strip_tags = true) { + $pref_name = db_escape_string( $pref_name); + $value = db_escape_string( $value, $strip_tags); if (!$user_id) { $user_id = $_SESSION["uid"]; @@ -97,7 +132,7 @@ $profile_qpart = "AND profile IS NULL"; } - if (get_schema_version($link) < 63) $profile_qpart = ""; + if (get_schema_version() < 63) $profile_qpart = ""; $type_name = ""; $current_value = ""; @@ -110,7 +145,7 @@ } if (!$type_name) { - $result = db_query($link, "SELECT type_name + $result = db_query( "SELECT type_name FROM ttrss_prefs,ttrss_prefs_types WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id"); @@ -131,15 +166,11 @@ $value = sprintf("%d", $value); } - if ($pref_name == 'DEFAULT_ARTICLE_LIMIT' && $value == 0) { - $value = 30; - } - if ($pref_name == 'USER_TIMEZONE' && $value == '') { $value = 'UTC'; } - db_query($link, "UPDATE ttrss_user_prefs SET + db_query( "UPDATE ttrss_user_prefs SET value = '$value' WHERE pref_name = '$pref_name' $profile_qpart AND owner_uid = " . $_SESSION["uid"]);