DUVar 6.x-1.x-dev
Drupal User Variables
duvar.module
Go to the documentation of this file.
00001 <?php
00002 // $Id$
00020 function duvar_set($var, $val) {
00021   global $user;
00022   if ($user->uid == 0) {
00023     return FALSE;
00024   }
00025   $sql = "INSERT INTO `{duvariables}` (`uid`, `name`, `value`) VALUES (%d, '%s', '%s')";
00026   if (function_exists('dcache_del')) {
00027     dcache_del(duvar_ns('duvar'), DCACHE_DRUPAL);
00028   }
00029   return db_query($sql, $user->uid, $var, $val);
00030 }
00031 
00044 function duvar_get($var, $def) {
00045   static $cache = NULL;
00046   global $user;
00047   if ($user->uid == 0) {
00048     return $def;
00049   }
00050   if (!$cache && function_exists('dcache_get')) {
00051     $cache = dcache_get(duvar_ns('duvar'), DCACHE_DRUPAL);
00052   }
00053   if (isset($cache) && isset($cache[$var])) {
00054     return $cache[$var];
00055   }
00056   $sql = "SELECT `value` FROM `{duvariables}` WHERE `uid` = %d AND `name` = '%s'";
00057   $result = db_query($sql, $user->uid, $var);
00058   if ($result === FALSE) {
00059     $result = $def;
00060   }
00061   else {
00062     $result = db_fetch_object($result);
00063   }
00064   $cache[$var] = $result;
00065   if (function_exists('dcache_set')) {
00066     dcache_set(duvar_ns('duvar'), $cache, DCACHE_DRUPAL, TRUE);
00067   }
00068   return $cache[$var];
00069 }
00070 
00080 function duvar_del($var) {
00081   global $user;
00082   if ($user->uid == 0) {
00083     return FALSE;
00084   }
00085   $sql = "DELETE FROM `{duvariables}` WHERE `uid` = %d AND `name` = '%s'";
00086   if (function_exists('dcache_del')) {
00087     dcache_del(duvar_ns('duvar'), DCACHE_DRUPAL);
00088   }
00089   return db_query($sql, $user->uid, $var);
00090 }
00091 
00103 function duvar_ns($ns) {
00104   global $user;
00105   return "{$ns}:{$user->uid}:";
00106 }
All Files Functions