Changeset 154 for trunk/lib/Prefs.inc.php
- Timestamp:
- Jun 8, 2006 5:36:10 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Prefs.inc.php
r153 r154 63 63 $app =& App::getInstance(); 64 64 65 $this->_ns = '_prefs_' .$namespace;65 $this->_ns = $namespace; 66 66 67 67 // Initialized the prefs array. 68 if (!isset($_SESSION[ $this->_ns])) {68 if (!isset($_SESSION['_prefs'][$this->_ns])) { 69 69 $this->clear(); 70 70 } … … 158 158 { 159 159 if (isset($defaults) && is_array($defaults)) { 160 $_SESSION[ $this->_ns]['defaults'] = array_merge($_SESSION[$this->_ns]['defaults'], $defaults);160 $_SESSION['_prefs'][$this->_ns]['defaults'] = array_merge($_SESSION['_prefs'][$this->_ns]['defaults'], $defaults); 161 161 } 162 162 } … … 180 180 } 181 181 182 if (!isset($_SESSION[ $this->_ns]['defaults'][$key]) || $_SESSION[$this->_ns]['defaults'][$key] != $val || isset($_SESSION[$this->_ns]['persistent'][$key])) {183 $_SESSION[ $this->_ns]['persistent'][$key] = $val;182 if (!isset($_SESSION['_prefs'][$this->_ns]['defaults'][$key]) || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val || isset($_SESSION['_prefs'][$this->_ns]['persistent'][$key])) { 183 $_SESSION['_prefs'][$this->_ns]['persistent'][$key] = $val; 184 184 } 185 185 } … … 196 196 { 197 197 $app =& App::getInstance(); 198 if (array_key_exists($key, $_SESSION[ $this->_ns]['persistent'])) {199 return $_SESSION[ $this->_ns]['persistent'][$key];200 } else if (array_key_exists($key, $_SESSION[ $this->_ns]['defaults'])) {201 return $_SESSION[ $this->_ns]['defaults'][$key];198 if (array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['persistent'])) { 199 return $_SESSION['_prefs'][$this->_ns]['persistent'][$key]; 200 } else if (array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])) { 201 return $_SESSION['_prefs'][$this->_ns]['defaults'][$key]; 202 202 } else { 203 $app->logMsg(sprintf('Key not found in prefs cache: %s', $key), LOG_ NOTICE, __FILE__, __LINE__);203 $app->logMsg(sprintf('Key not found in prefs cache: %s', $key), LOG_DEBUG, __FILE__, __LINE__); 204 204 return null; 205 205 } … … 214 214 function exists($key) 215 215 { 216 return array_key_exists($key, $_SESSION[ $this->_ns]['persistent']);216 return array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['persistent']); 217 217 } 218 218 … … 224 224 function delete($key) 225 225 { 226 unset($_SESSION[ $this->_ns]['persistent'][$key]);226 unset($_SESSION['_prefs'][$this->_ns]['persistent'][$key]); 227 227 } 228 228 … … 233 233 function clear() 234 234 { 235 $_SESSION[ $this->_ns] = array(235 $_SESSION['_prefs'][$this->_ns] = array( 236 236 'loaded' => false, 237 237 'load_datetime' => '1970-01-01', … … 286 286 "); 287 287 while (list($key, $val) = mysql_fetch_row($qid)) { 288 $_SESSION[ $this->_ns]['persistent'][$key] = $val;288 $_SESSION['_prefs'][$this->_ns]['persistent'][$key] = $val; 289 289 } 290 290 291 $app->logMsg(sprintf('Loaded %s prefs from database.', sizeof($_SESSION[ $this->_ns]['persistent'])), LOG_DEBUG, __FILE__, __LINE__);291 $app->logMsg(sprintf('Loaded %s prefs from database.', sizeof($_SESSION['_prefs'][$this->_ns]['persistent'])), LOG_DEBUG, __FILE__, __LINE__); 292 292 293 293 // Data loaded only once per session. 294 $_SESSION[ $this->_ns]['loaded'] = true;295 $_SESSION[ $this->_ns]['load_datetime'] = date('Y-m-d H:i:s');294 $_SESSION['_prefs'][$this->_ns]['loaded'] = true; 295 $_SESSION['_prefs'][$this->_ns]['load_datetime'] = date('Y-m-d H:i:s'); 296 296 297 297 return true; … … 310 310 function _isLoaded() 311 311 { 312 if (isset($_SESSION[ $this->_ns]['load_datetime'])313 && strtotime($_SESSION[ $this->_ns]['load_datetime']) > time() - $this->getParam('load_timeout')314 && isset($_SESSION[ $this->_ns]['loaded'])315 && true === $_SESSION[ $this->_ns]['loaded']) {312 if (isset($_SESSION['_prefs'][$this->_ns]['load_datetime']) 313 && strtotime($_SESSION['_prefs'][$this->_ns]['load_datetime']) > time() - $this->getParam('load_timeout') 314 && isset($_SESSION['_prefs'][$this->_ns]['loaded']) 315 && true === $_SESSION['_prefs'][$this->_ns]['loaded']) { 316 316 return true; 317 317 } else { … … 347 347 $this->initDB(); 348 348 349 if (isset($_SESSION[ $this->_ns]['persistent']) && is_array($_SESSION[$this->_ns]['persistent'])) {349 if (isset($_SESSION['_prefs'][$this->_ns]['persistent']) && is_array($_SESSION['_prefs'][$this->_ns]['persistent'])) { 350 350 // Delete old prefs from database. 351 351 $db->query(" … … 357 357 // Insert new prefs. 358 358 $insert_values = array(); 359 foreach ($_SESSION[ $this->_ns]['persistent'] as $key => $val) {359 foreach ($_SESSION['_prefs'][$this->_ns]['persistent'] as $key => $val) { 360 360 $insert_values[] = sprintf("('%s', '%s', '%s', '%s')", $db->escapeString($this->getParam('user_id')), $db->escapeString($this->_ns), $db->escapeString($key), $db->escapeString($val)); 361 361 }
Note: See TracChangeset
for help on using the changeset viewer.