Changeset 481 for trunk/lib/Prefs.inc.php
- Timestamp:
- May 4, 2014 12:46:59 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Prefs.inc.php
r480 r481 29 29 * @author Quinn Comendant <quinn@strangecode.com> 30 30 * @version 3.0 31 * @todo This class could really benefit from being refactored using the factory pattern, with backend storage mechanisms. 31 32 * 32 33 * Example of use (database storagetype): … … 59 60 private $_params = array( 60 61 61 // Legacy parameter, superceeded by the 'storagetype' setting. 62 // Store preferences in one of the available storage mechanisms: session, cookie, database 63 // This default should remain set to 'session' for legacy support. 64 'storagetype' => 'session', 65 66 // This parameter is only used for legacy support, superceeded by the 'storagetype' setting. 62 67 // Enable database storage. If this is false, all prefs will live only as long as the session. 63 68 'persistent' => null, 64 69 65 // Store preferences in one of the available storage mechanisms: session, cookie, database66 'storagetype' => 'session',67 68 70 // ---------------------------------------------------------- 69 71 // Cookie-type settings. … … 87 89 'load_timeout' => 3600, 88 90 89 // Name of database table to store p ersistent prefs.91 // Name of database table to store prefs. 90 92 'db_table' => 'pref_tbl', 91 93 … … 111 113 // Optional initial params. 112 114 $this->setParam($params); 115 116 // Initialized the prefs array. 117 if ('cookie' != $app->getParam('storagetype') && !isset($_SESSION['_prefs'][$this->_ns]['saved'])) { 118 $this->clear(); 119 } 113 120 114 121 // Run Prefs->save() upon script completion if we're using the database storagetype. … … 174 181 175 182 // Convert the legacy param 'persistent' to 'storagetype=database'. 183 // Old sites would set 'persistent' to true (use database) or false (use sessions). 184 // If it is true, we set storagetype=database here. 185 // If false, we rely on the default, sessions (which is assigned in the params). 176 186 if (isset($params['persistent']) && $params['persistent'] && !isset($params['storagetype'])) { 177 187 $params['storagetype'] = 'database'; … … 206 216 * Sets the default values for preferences. If a preference is not explicitly 207 217 * set, the value set here will be used. Can be called multiple times to merge additional 208 * defaults together. This is mostly only useful for the database stor etype, when you have218 * defaults together. This is mostly only useful for the database storagetype, when you have 209 219 * values you want to use as default, and those are not stored to the database (so the defaults 210 220 * can be changed later and apply to all users who haven't make s specific setting). 211 * For the cookie stor etype, using setDefaults just sets cookies but only if a cookie with221 * For the cookie storagetype, using setDefaults just sets cookies but only if a cookie with 212 222 * the same name is not already set. 213 223 * … … 267 277 case 'session': 268 278 case 'database': 269 // Initialized the prefs array.270 if (!isset($_SESSION['_prefs'][$this->_ns]['saved'])) {271 $this->clear();272 }273 279 // Set a saved preference if... 274 280 // - there isn't a default.
Note: See TracChangeset
for help on using the changeset viewer.