Changeset 149 for trunk/lib/Prefs.inc.php
- Timestamp:
- Jun 5, 2006 2:34:47 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Prefs.inc.php
r147 r149 18 18 var $_params = array( 19 19 20 // The current user_id for which to load/save preferences. 21 'user_id' => null, 22 23 // How long before we force a reload of the prefs data? 3600 = once every hour. 24 'load_timeout' => 3600, 25 20 26 // Enable database storage. 21 27 'enable_db' => true, … … 26 32 // Automatically create table and verify columns. Better set to false after site launch. 27 33 'create_table' => true, 28 29 // The current user_id for which to load/save preferences.30 'user_id' => null,31 34 ); 32 35 … … 132 135 function setDefaults($defaults) 133 136 { 137 $app =& App::getInstance(); 134 138 if (isset($defaults) && is_array($defaults)) { 135 139 // Apply defaults to the session, setting only non-existing values. 140 $app->logMsg(sprintf('Pre-defaulting: %s', getDump($_SESSION[$this->_ns]['data'])), LOG_DEBUG, __FILE__, __LINE__); 136 141 $_SESSION[$this->_ns]['data'] = array_merge($defaults, $_SESSION[$this->_ns]['data']); 142 $app->logMsg(sprintf('Post-defaulting: %s', getDump($_SESSION[$this->_ns]['data'])), LOG_DEBUG, __FILE__, __LINE__); 137 143 } 138 144 } … … 146 152 function set($key, $val) 147 153 { 148 $_SESSION[$this->_ns]['data'][$key] = $val; 154 if ('' != $key && '' != $val) { 155 $_SESSION[$this->_ns]['data'][$key] = $val; 156 } 149 157 } 150 158 … … 185 193 186 194 /** 187 * Empty the $_SESSION cache. 195 * Empty the $_SESSION cache. This should be executed with the same consideration as $auth->clear() 188 196 */ 189 197 function clear() … … 238 246 // Data loaded only once per session. 239 247 $_SESSION[$this->_ns]['loaded'] = true; 248 $_SESSION[$this->_ns]['load_datetime'] = date('Y-m-d H:i:s'); 240 249 241 250 return true; … … 243 252 244 253 /* 245 * Returns true if the prefs had been loaded from the database into the $_SESSION. 254 * Returns true if the prefs had been loaded from the database into the $_SESSION recently. 255 * This function is simply a check so the database isn't access every page load. 246 256 * 247 257 * @access private … … 253 263 function _isLoaded() 254 264 { 255 return isset($_SESSION[$this->_ns]['loaded']) && true === $_SESSION[$this->_ns]['loaded']; 265 if (isset($_SESSION[$this->_ns]['load_datetime']) 266 && strtotime($_SESSION[$this->_ns]['load_datetime']) > time() - $this->getParam('load_timeout') 267 && isset($_SESSION[$this->_ns]['loaded']) 268 && true === $_SESSION[$this->_ns]['loaded']) { 269 return true; 270 } else { 271 return false; 272 } 256 273 } 257 274 … … 294 311 $insert_values = array(); 295 312 foreach ($_SESSION[$this->_ns]['data'] as $key => $val) { 296 $insert_values[] = sprintf("('%s', '%s', '%s', '%s')", DB::escapeString($this->getParam('user_id')), DB::escapeString($this->_ns), DB::escapeString($key), DB::escapeString($val)); 313 if ('' != trim($key) && '' != trim($val)) { 314 $insert_values[] = sprintf("('%s', '%s', '%s', '%s')", $db->escapeString($this->getParam('user_id')), $db->escapeString($this->_ns), $db->escapeString($key), $db->escapeString($val)); 315 } 297 316 } 298 317 $db->query("
Note: See TracChangeset
for help on using the changeset viewer.