]> git.wh0rd.org Git - tt-rss.git/commitdiff
fixes for db-prefs cache
authorAndrew Dolgov <fox@bah.spb.su>
Thu, 29 Dec 2005 14:21:34 +0000 (15:21 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Thu, 29 Dec 2005 14:21:34 +0000 (15:21 +0100)
db-prefs.php

index 5f61f15ae6f6796a2d53c53944aa6cbaa95218f4..293af7beaeb74ce0cf9c124aa3215ec7def51f65 100644 (file)
@@ -19,7 +19,8 @@
                }
        
                if ($_SESSION["prefs_cache"] && $_SESSION["prefs_cache"][$pref_name]) {
-                       return $_SESSION["prefs_cache"][$pref_name];
+                       $tuple = $_SESSION["prefs_cache"][$pref_name];
+                       return convert_pref_type($tuple["value"], $tuple["type"]);
                }
 
                $result = db_query($link, "SELECT 
                        $value = db_fetch_result($result, 0, "value");
                        $type_name = db_fetch_result($result, 0, "type_name");
 
-                       if ($type_name == "bool") {                     
-                               $retv = $value == "true";                               
-                       } else if ($type_name == "integer") {                   
-                               $retv = sprintf("%d", $value);                          
-                       } else {
-                               $retv = $value;
-                       }
-
                        if ($user_id = $_SESSION["uid"]) {
-                               $_SESSION["prefs_cache"][$pref_name] = $value;
+                               $_SESSION["prefs_cache"][$pref_name]["type"] = $type_name;
+                               $_SESSION["prefs_cache"][$pref_name]["value"] = $value;
                        }
-                       return $value;
+                       return convert_pref_type($value, $type_name);
                        
                } else {                
                        die("Fatal error, unknown preferences key: $pref_name");                        
                }
        }
 
+       function convert_pref_type($value, $type_name) {
+               if ($type_name == "bool") {                     
+                       return $value == "true";                                
+               } else if ($type_name == "integer") {                   
+                       return sprintf("%d", $value);                           
+               } else {
+                       return $value;
+               }
+       }
 ?>