]>
git.wh0rd.org - tt-rss.git/blob - db-prefs.php
2 require_once "config.php";
5 if (! DISABLE_SESSIONS
) {
6 if (!$_SESSION["prefs_cache"])
7 $_SESSION["prefs_cache"] = array();
10 function get_pref($link, $pref_name, $user_id = false) {
12 $pref_name = db_escape_string($pref_name);
15 $user_id = $_SESSION["uid"];
17 $user_id = sprintf("%d", $user_id);
21 if ($_SESSION["prefs_cache"] && $_SESSION["prefs_cache"][$pref_name]) {
22 $tuple = $_SESSION["prefs_cache"][$pref_name];
23 return convert_pref_type($tuple["value"], $tuple["type"]);
26 $result = db_query($link, "SELECT
27 value,ttrss_prefs_types.type_name as type_name
29 ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types
31 ttrss_user_prefs.pref_name = '$pref_name' AND
32 ttrss_prefs_types.id = type_id AND
33 owner_uid = '$user_id' AND
34 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name");
36 if (db_num_rows($result) > 0) {
37 $value = db_fetch_result($result, 0, "value");
38 $type_name = db_fetch_result($result, 0, "type_name");
40 if ($user_id = $_SESSION["uid"]) {
41 $_SESSION["prefs_cache"][$pref_name]["type"] = $type_name;
42 $_SESSION["prefs_cache"][$pref_name]["value"] = $value;
44 return convert_pref_type($value, $type_name);
47 die("Fatal error, unknown preferences key: $pref_name");
51 function convert_pref_type($value, $type_name) {
52 if ($type_name == "bool") {
53 return $value == "true";
54 } else if ($type_name == "integer") {
55 return sprintf("%d", $value);
61 // doesn't peform any type checking, be vigilant
63 function set_pref($link, $key, $value) {
64 $key = db_escape_string($key);
65 $value = db_escape_string($value);
67 db_query($link, "UPDATE ttrss_user_prefs SET
68 value = '$value' WHERE pref_name = '$key'
69 AND owner_uid = " . $_SESSION["uid"]);
71 $_SESSION["prefs_cache"] = array();