]>
git.wh0rd.org - tt-rss.git/blob - db-prefs.php
2 require_once "config.php";
5 if (!defined('DISABLE_SESSIONS')) {
6 if (!$_SESSION["prefs_cache"])
7 $_SESSION["prefs_cache"] = array();
10 function get_pref($link, $pref_name, $user_id = false, $die_on_error = false) {
12 $pref_name = db_escape_string($pref_name);
16 $user_id = $_SESSION["uid"];
17 $profile = $_SESSION["profile"];
19 $user_id = sprintf("%d", $user_id);
24 $profile_qpart = "profile = '$profile' AND";
26 $profile_qpart = "profile IS NULL AND";
29 if (get_schema_version($link) < 63) $profile_qpart = "";
31 if ($prefs_cache && !defined('DISABLE_SESSIONS') && !SINGLE_USER_MODE
) {
32 if ($_SESSION["prefs_cache"] && $_SESSION["prefs_cache"][$pref_name]) {
33 $tuple = $_SESSION["prefs_cache"][$pref_name];
34 return convert_pref_type($tuple["value"], $tuple["type"]);
38 $result = db_query($link, "SELECT
39 value,ttrss_prefs_types.type_name as type_name
41 ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types
44 ttrss_user_prefs.pref_name = '$pref_name' AND
45 ttrss_prefs_types.id = type_id AND
46 owner_uid = '$user_id' AND
47 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name");
49 if (db_num_rows($result) > 0) {
50 $value = db_fetch_result($result, 0, "value");
51 $type_name = db_fetch_result($result, 0, "type_name");
53 if (!defined('DISABLE_SESSIONS') && !SINGLE_USER_MODE
) {
54 if ($user_id = $_SESSION["uid"]) {
55 $_SESSION["prefs_cache"][$pref_name]["type"] = $type_name;
56 $_SESSION["prefs_cache"][$pref_name]["value"] = $value;
60 return convert_pref_type($value, $type_name);
64 die("Fatal error, unknown preferences key: $pref_name");
71 function convert_pref_type($value, $type_name) {
72 if ($type_name == "bool") {
73 return $value == "true";
74 } else if ($type_name == "integer") {
75 return sprintf("%d", $value);
81 function set_pref($link, $key, $value, $user_id = false) {
82 $key = db_escape_string($key);
83 $value = db_escape_string($value);
86 $user_id = $_SESSION["uid"];
87 $profile = $_SESSION["profile"];
89 $user_id = sprintf("%d", $user_id);
94 $profile_qpart = "AND profile = '$profile'";
96 $profile_qpart = "AND profile IS NULL";
99 if (get_schema_version($link) < 63) $profile_qpart = "";
101 $result = db_query($link, "SELECT type_name
102 FROM ttrss_prefs,ttrss_prefs_types
103 WHERE pref_name = '$key' AND type_id = ttrss_prefs_types.id");
105 if (db_num_rows($result) > 0) {
107 $type_name = db_fetch_result($result, 0, "type_name");
109 if ($type_name == "bool") {
110 if ($value == "1" ||
$value == "true") {
115 } else if ($type_name == "integer") {
116 $value = sprintf("%d", $value);
119 if ($pref_name == 'DEFAULT_ARTICLE_LIMIT' && $value == 0) {
123 db_query($link, "UPDATE ttrss_user_prefs SET
124 value = '$value' WHERE pref_name = '$key'
126 AND owner_uid = " . $_SESSION["uid"]);
128 $_SESSION["prefs_cache"] = array();