You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
3.9 KiB
PHTML
156 lines
3.9 KiB
PHTML
19 years ago
|
<?php
|
||
19 years ago
|
require_once "config.php";
|
||
|
require_once "db.php";
|
||
|
|
||
15 years ago
|
if (!defined('DISABLE_SESSIONS')) {
|
||
19 years ago
|
if (!$_SESSION["prefs_cache"])
|
||
|
$_SESSION["prefs_cache"] = array();
|
||
|
}
|
||
19 years ago
|
|
||
18 years ago
|
function get_pref($link, $pref_name, $user_id = false, $die_on_error = false) {
|
||
19 years ago
|
|
||
|
$pref_name = db_escape_string($pref_name);
|
||
17 years ago
|
$prefs_cache = true;
|
||
14 years ago
|
$profile = false;
|
||
19 years ago
|
|
||
19 years ago
|
if (!$user_id) {
|
||
|
$user_id = $_SESSION["uid"];
|
||
14 years ago
|
@$profile = $_SESSION["profile"];
|
||
19 years ago
|
} else {
|
||
|
$user_id = sprintf("%d", $user_id);
|
||
13 years ago
|
//$prefs_cache = false;
|
||
19 years ago
|
}
|
||
19 years ago
|
|
||
13 years ago
|
if ($prefs_cache && !defined('DISABLE_SESSIONS')) {
|
||
13 years ago
|
if ($_SESSION["prefs_cache"] && @$_SESSION["prefs_cache"][$pref_name]) {
|
||
|
$tuple = $_SESSION["prefs_cache"][$pref_name];
|
||
|
return convert_pref_type($tuple["value"], $tuple["type"]);
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
if ($profile) {
|
||
15 years ago
|
$profile_qpart = "profile = '$profile' AND";
|
||
15 years ago
|
} else {
|
||
15 years ago
|
$profile_qpart = "profile IS NULL AND";
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
if (get_schema_version($link) < 63) $profile_qpart = "";
|
||
15 years ago
|
|
||
13 years ago
|
$result = db_query($link, "SELECT
|
||
|
value,ttrss_prefs_types.type_name as type_name
|
||
|
FROM
|
||
19 years ago
|
ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types
|
||
13 years ago
|
WHERE
|
||
15 years ago
|
$profile_qpart
|
||
13 years ago
|
ttrss_user_prefs.pref_name = '$pref_name' AND
|
||
19 years ago
|
ttrss_prefs_types.id = type_id AND
|
||
19 years ago
|
owner_uid = '$user_id' AND
|
||
19 years ago
|
ttrss_user_prefs.pref_name = ttrss_prefs.pref_name");
|
||
19 years ago
|
|
||
|
if (db_num_rows($result) > 0) {
|
||
|
$value = db_fetch_result($result, 0, "value");
|
||
19 years ago
|
$type_name = db_fetch_result($result, 0, "type_name");
|
||
|
|
||
13 years ago
|
if (!defined('DISABLE_SESSIONS')) {
|
||
|
if ($user_id == $_SESSION["uid"]) {
|
||
19 years ago
|
$_SESSION["prefs_cache"][$pref_name]["type"] = $type_name;
|
||
|
$_SESSION["prefs_cache"][$pref_name]["value"] = $value;
|
||
|
}
|
||
19 years ago
|
}
|
||
19 years ago
|
|
||
19 years ago
|
return convert_pref_type($value, $type_name);
|
||
13 years ago
|
|
||
|
} else {
|
||
19 years ago
|
if ($die_on_error) {
|
||
|
die("Fatal error, unknown preferences key: $pref_name");
|
||
|
} else {
|
||
|
return null;
|
||
|
}
|
||
19 years ago
|
}
|
||
|
}
|
||
|
|
||
19 years ago
|
function convert_pref_type($value, $type_name) {
|
||
13 years ago
|
if ($type_name == "bool") {
|
||
|
return $value == "true";
|
||
|
} else if ($type_name == "integer") {
|
||
|
return sprintf("%d", $value);
|
||
19 years ago
|
} else {
|
||
|
return $value;
|
||
|
}
|
||
|
}
|
||
19 years ago
|
|
||
13 years ago
|
function set_pref($link, $pref_name, $value, $user_id = false) {
|
||
|
$pref_name = db_escape_string($pref_name);
|
||
19 years ago
|
$value = db_escape_string($value);
|
||
|
|
||
15 years ago
|
if (!$user_id) {
|
||
|
$user_id = $_SESSION["uid"];
|
||
14 years ago
|
@$profile = $_SESSION["profile"];
|
||
15 years ago
|
} else {
|
||
|
$user_id = sprintf("%d", $user_id);
|
||
|
$prefs_cache = false;
|
||
|
}
|
||
|
|
||
|
if ($profile) {
|
||
15 years ago
|
$profile_qpart = "AND profile = '$profile'";
|
||
15 years ago
|
} else {
|
||
15 years ago
|
$profile_qpart = "AND profile IS NULL";
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
if (get_schema_version($link) < 63) $profile_qpart = "";
|
||
|
|
||
13 years ago
|
$type_name = "";
|
||
|
$current_value = "";
|
||
15 years ago
|
|
||
13 years ago
|
if (!defined('DISABLE_SESSIONS')) {
|
||
|
if ($_SESSION["prefs_cache"] && @$_SESSION["prefs_cache"][$pref_name]) {
|
||
|
$type_name = $_SESSION["prefs_cache"][$pref_name]["type"];
|
||
|
$current_value = $_SESSION["prefs_cache"][$pref_name]["value"];
|
||
|
}
|
||
|
}
|
||
15 years ago
|
|
||
13 years ago
|
if (!$type_name) {
|
||
|
$result = db_query($link, "SELECT type_name
|
||
|
FROM ttrss_prefs,ttrss_prefs_types
|
||
|
WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
|
||
|
|
||
|
if (db_num_rows($result) > 0)
|
||
|
$type_name = db_fetch_result($result, 0, "type_name");
|
||
|
} else if ($current_value == $value) {
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
|
||
13 years ago
|
if ($type_name) {
|
||
15 years ago
|
if ($type_name == "bool") {
|
||
|
if ($value == "1" || $value == "true") {
|
||
|
$value = "true";
|
||
|
} else {
|
||
|
$value = "false";
|
||
|
}
|
||
|
} else if ($type_name == "integer") {
|
||
|
$value = sprintf("%d", $value);
|
||
|
}
|
||
|
|
||
13 years ago
|
if ($pref_name == 'DEFAULT_ARTICLE_LIMIT' && $value == 0) {
|
||
15 years ago
|
$value = 30;
|
||
|
}
|
||
|
|
||
13 years ago
|
if ($pref_name == 'USER_TIMEZONE' && $value == '') {
|
||
14 years ago
|
$value = 'UTC';
|
||
|
}
|
||
|
|
||
13 years ago
|
db_query($link, "UPDATE ttrss_user_prefs SET
|
||
13 years ago
|
value = '$value' WHERE pref_name = '$pref_name'
|
||
15 years ago
|
$profile_qpart
|
||
15 years ago
|
AND owner_uid = " . $_SESSION["uid"]);
|
||
19 years ago
|
|
||
13 years ago
|
if (!defined('DISABLE_SESSIONS')) {
|
||
|
if ($user_id == $_SESSION["uid"]) {
|
||
13 years ago
|
$_SESSION["prefs_cache"][$pref_name]["type"] = $type_name;
|
||
|
$_SESSION["prefs_cache"][$pref_name]["value"] = $value;
|
||
|
}
|
||
|
}
|
||
15 years ago
|
}
|
||
19 years ago
|
}
|
||
19 years ago
|
?>
|