- Timestamp:
- Jun 7, 2006 8:41:19 PM (18 years ago)
- Location:
- trunk/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Cache.inc.php
r152 r153 131 131 } 132 132 133 $key = md5($key);133 $keyhash = md5($key); 134 134 $var = serialize($var); 135 135 $var_len = strlen($var); … … 146 146 147 147 // Remove any value already stored under this key. 148 unset($_SESSION[$this->_ns][$key ]);148 unset($_SESSION[$this->_ns][$keyhash]); 149 149 150 150 // Continue to prune the cache if its size is greater than stack_size_limit, but keep at least min_items. … … 154 154 155 155 // Save this value under the specified key. 156 $_SESSION[$this->_ns][$key ] =& $var;156 $_SESSION[$this->_ns][$keyhash] =& $var; 157 157 158 158 if ($var_len >= 1024000) { … … 174 174 function get($key) 175 175 { 176 $app =& App::getInstance(); 177 176 178 if (true !== $this->getParam('enabled')) { 177 return false; 178 } 179 180 $key = md5($key); 181 if (isset($_SESSION[$this->_ns][$key])) { 179 $app->logMsg(sprintf('Cache not enabled, not getting data.', null), LOG_DEBUG, __FILE__, __LINE__); 180 return false; 181 } 182 183 $keyhash = md5($key); 184 if (isset($_SESSION[$this->_ns][$keyhash])) { 185 $app->logMsg(sprintf('Retreiving %s from cache.', $key), LOG_DEBUG, __FILE__, __LINE__); 182 186 // Move the accessed cached datum to the top of the stack. Maybe somebody knows a better way to do this? 183 $tmp =& $_SESSION[$this->_ns][$key ];184 unset($_SESSION[$this->_ns][$key ]);185 $_SESSION[$this->_ns][$key ] =& $tmp;187 $tmp =& $_SESSION[$this->_ns][$keyhash]; 188 unset($_SESSION[$this->_ns][$keyhash]); 189 $_SESSION[$this->_ns][$keyhash] =& $tmp; 186 190 // Return the unserialized datum. 187 return unserialize($_SESSION[$this->_ns][$key ]);191 return unserialize($_SESSION[$this->_ns][$keyhash]); 188 192 } else { 189 193 return false; … … 203 207 } 204 208 205 $key = md5($key);206 return array_key_exists($key , $_SESSION[$this->_ns]);209 $keyhash = md5($key); 210 return array_key_exists($keyhash, $_SESSION[$this->_ns]); 207 211 } 208 212 … … 215 219 function delete($key) 216 220 { 217 $key = md5($key);218 unset($_SESSION[$this->_ns][$key ]);221 $keyhash = md5($key); 222 unset($_SESSION[$this->_ns][$keyhash]); 219 223 } 220 224 -
trunk/lib/PageNumbers.inc.php
r152 r153 65 65 // in special cases like using a /my/page/# scheme. 66 66 $this->url_base = $_SERVER['PHP_SELF'] . '?page_number='; 67 68 $this->prefs = new Prefs(); 69 $this->prefs->setParam(array('persistent' => false)); 67 70 } 68 71 … … 72 75 function setPerPage($per_page, $default=25, $save_value=true) 73 76 { 74 $prefs =& Prefs::getInstance($_SERVER['PHP_SELF']);75 $prefs->setParam(array('persistent' => false));76 77 77 // (1) By provided argument, if valid. 78 78 // (2) By saved preference, if available. … … 82 82 $this->_per_page = $per_page; 83 83 if ($save_value) { 84 $ prefs->set('items_per_page', $this->_per_page);85 } 86 } else if ($save_value && $ prefs->exists('items_per_page')) {87 $this->_per_page = (int)$ prefs->get('items_per_page');84 $this->prefs->set('items_per_page', $this->_per_page); 85 } 86 } else if ($save_value && $this->prefs->exists('items_per_page')) { 87 $this->_per_page = (int)$this->prefs->get('items_per_page'); 88 88 } else if (is_numeric($default) && $default > 0) { 89 89 $this->_per_page = $default; … … 97 97 function setPageNumber($page_number, $save_value=true) 98 98 { 99 $prefs =& Prefs::getInstance($_SERVER['PHP_SELF']);100 $prefs->setParam(array('persistent' => false));101 102 99 // (1) By provided argument, if valid. 103 100 // (2) By saved preference, if available. … … 111 108 } 112 109 if ($save_value) { 113 $ prefs->set('page_number', $this->current_page);114 } 115 } else if ($save_value && $ prefs->exists('page_number')) {116 $this->current_page = (int)$ prefs->get('page_number');110 $this->prefs->set('page_number', $this->current_page); 111 } 112 } else if ($save_value && $this->prefs->exists('page_number')) { 113 $this->current_page = (int)$this->prefs->get('page_number'); 117 114 } 118 115 $this->set_page_number_initialized = true; -
trunk/lib/Prefs.inc.php
r152 r153 14 14 // Load preferences for the user's session. 15 15 require_once 'codebase/lib/Prefs.inc.php'; 16 $prefs = & Prefs::getInstance('my-namespace');16 $prefs = new Prefs('my-namespace'); 17 17 $prefs->setParam(array( 18 18 'persistent' => $auth->isLoggedIn(), … … 74 74 $this->setParam(array('create_table' => $app->getParam('db_create_tables'))); 75 75 } 76 }77 78 /**79 * This method enforces the singleton pattern for this class.80 *81 * @return object Reference to the global Prefs object.82 * @access public83 * @static84 */85 function &getInstance($namespace='')86 {87 static $instances = array();88 89 if (!array_key_exists($namespace, $instances)) {90 $instances[$namespace] = new Prefs($namespace);91 }92 93 return $instances[$namespace];94 76 } 95 77 -
trunk/lib/SortOrder.inc.php
r152 r153 39 39 $this->default_sort = $default_sort; 40 40 $this->default_order = $default_order; 41 42 $this->prefs = new Prefs(); 43 $this->prefs->setParam(array('persistent' => false)); 41 44 } 42 45 … … 69 72 function setDefault($default_sort = '', $default_order = '') 70 73 { 71 $prefs =& Prefs::getInstance($_SERVER['PHP_SELF']);72 $prefs->setParam(array('persistent' => false));73 74 74 // Which column to sort by? 75 75 // (1) By GET or POST specification, if available. … … 79 79 if (!empty($new_sort_by)) { 80 80 $this->sort_by = $new_sort_by; 81 $ prefs->set('sort_by', $this->sort_by);82 } else if ($ prefs->exists('sort_by')) {83 $this->sort_by = $ prefs->get('sort_by');81 $this->prefs->set('sort_by', $this->sort_by); 82 } else if ($this->prefs->exists('sort_by')) { 83 $this->sort_by = $this->prefs->get('sort_by'); 84 84 } else { 85 85 $this->sort_by = $default_sort; … … 93 93 if (!empty($new_order)) { 94 94 $this->order = $new_order; 95 $ prefs->set('sort_order', $this->order);96 } else if ($ prefs->exists('sort_order')) {97 $this->order = $ prefs->get('sort_order');95 $this->prefs->set('sort_order', $this->order); 96 } else if ($this->prefs->exists('sort_order')) { 97 $this->order = $this->prefs->get('sort_order'); 98 98 } else { 99 99 $this->order = $default_order; … … 112 112 function set($sort = null, $order = null) 113 113 { 114 $prefs =& Prefs::getInstance($_SERVER['PHP_SELF']);115 $prefs->setParam(array('persistent' => false));116 117 114 // Set new sort value. 118 115 if (isset($sort)) { 119 116 $this->sort_by = $sort; 120 $ prefs->set('sort_by', $this->sort_by);117 $this->prefs->set('sort_by', $this->sort_by); 121 118 } 122 119 … … 124 121 if (isset($order)) { 125 122 $this->order = $order; 126 $ prefs->set('sort_order', $this->order);123 $this->prefs->set('sort_order', $this->order); 127 124 } 128 125 }
Note: See TracChangeset
for help on using the changeset viewer.