@@ -44,237 +44,237 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | class HTTP_Session_Container |
| 46 | 46 | { |
| 47 | - /** |
|
| 48 | - * Additional options for the container object |
|
| 49 | - * |
|
| 50 | - * @var array |
|
| 51 | - * @access private |
|
| 52 | - */ |
|
| 53 | - public $options = array(); |
|
| 47 | + /** |
|
| 48 | + * Additional options for the container object |
|
| 49 | + * |
|
| 50 | + * @var array |
|
| 51 | + * @access private |
|
| 52 | + */ |
|
| 53 | + public $options = array(); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Constrtuctor method |
|
| 57 | - * |
|
| 58 | - * @param array $options Additional options for the container object |
|
| 59 | - * |
|
| 60 | - * @access public |
|
| 61 | - * @return object |
|
| 62 | - */ |
|
| 63 | - public function HTTP_Session_Container($options = null) |
|
| 64 | - { |
|
| 65 | - $this->_setDefaults(); |
|
| 66 | - if (is_array($options)) { |
|
| 67 | - $this->_parseOptions(); |
|
| 68 | - } |
|
| 69 | - } |
|
| 55 | + /** |
|
| 56 | + * Constrtuctor method |
|
| 57 | + * |
|
| 58 | + * @param array $options Additional options for the container object |
|
| 59 | + * |
|
| 60 | + * @access public |
|
| 61 | + * @return object |
|
| 62 | + */ |
|
| 63 | + public function HTTP_Session_Container($options = null) |
|
| 64 | + { |
|
| 65 | + $this->_setDefaults(); |
|
| 66 | + if (is_array($options)) { |
|
| 67 | + $this->_parseOptions(); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Set some default options |
|
| 73 | - * |
|
| 74 | - * @access private |
|
| 75 | - * @return void |
|
| 76 | - */ |
|
| 77 | - public function _setDefaults() |
|
| 78 | - { |
|
| 79 | - } |
|
| 71 | + /** |
|
| 72 | + * Set some default options |
|
| 73 | + * |
|
| 74 | + * @access private |
|
| 75 | + * @return void |
|
| 76 | + */ |
|
| 77 | + public function _setDefaults() |
|
| 78 | + { |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Parse options passed to the container class |
|
| 83 | - * |
|
| 84 | - * @param array $options Options |
|
| 85 | - * |
|
| 86 | - * @access private |
|
| 87 | - * @return void |
|
| 88 | - */ |
|
| 89 | - public function _parseOptions($options) |
|
| 90 | - { |
|
| 91 | - foreach ($options as $option => $value) { |
|
| 92 | - if (in_array($option, array_keys($this->options))) { |
|
| 93 | - $this->options[$option] = $value; |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 81 | + /** |
|
| 82 | + * Parse options passed to the container class |
|
| 83 | + * |
|
| 84 | + * @param array $options Options |
|
| 85 | + * |
|
| 86 | + * @access private |
|
| 87 | + * @return void |
|
| 88 | + */ |
|
| 89 | + public function _parseOptions($options) |
|
| 90 | + { |
|
| 91 | + foreach ($options as $option => $value) { |
|
| 92 | + if (in_array($option, array_keys($this->options))) { |
|
| 93 | + $this->options[$option] = $value; |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * This function is called by the session handler to initialize things |
|
| 100 | - * |
|
| 101 | - * @param string $save_path Save path |
|
| 102 | - * @param string $session_name Session name |
|
| 103 | - * |
|
| 104 | - * @access public |
|
| 105 | - * @return bool |
|
| 106 | - */ |
|
| 107 | - public function open($save_path, $session_name) |
|
| 108 | - { |
|
| 109 | - return true; |
|
| 110 | - } |
|
| 98 | + /** |
|
| 99 | + * This function is called by the session handler to initialize things |
|
| 100 | + * |
|
| 101 | + * @param string $save_path Save path |
|
| 102 | + * @param string $session_name Session name |
|
| 103 | + * |
|
| 104 | + * @access public |
|
| 105 | + * @return bool |
|
| 106 | + */ |
|
| 107 | + public function open($save_path, $session_name) |
|
| 108 | + { |
|
| 109 | + return true; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * This function is called when the page is finished |
|
| 114 | - * executing and the session handler needs to close things off |
|
| 115 | - * |
|
| 116 | - * Has to be overwritten by each container class |
|
| 117 | - * |
|
| 118 | - * @access public |
|
| 119 | - * @return bool |
|
| 120 | - */ |
|
| 121 | - public function close() |
|
| 122 | - { |
|
| 123 | - return true; |
|
| 124 | - } |
|
| 112 | + /** |
|
| 113 | + * This function is called when the page is finished |
|
| 114 | + * executing and the session handler needs to close things off |
|
| 115 | + * |
|
| 116 | + * Has to be overwritten by each container class |
|
| 117 | + * |
|
| 118 | + * @access public |
|
| 119 | + * @return bool |
|
| 120 | + */ |
|
| 121 | + public function close() |
|
| 122 | + { |
|
| 123 | + return true; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * This function is called by the session handler |
|
| 128 | - * to read the data associated with a given session ID. |
|
| 129 | - * This function must retrieve and return the session data |
|
| 130 | - * for the session identified by $id. |
|
| 131 | - * |
|
| 132 | - * Has to be overwritten by each container class |
|
| 133 | - * |
|
| 134 | - * @param string $id ID of the session |
|
| 135 | - * |
|
| 136 | - * @access public |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - public function read($id) |
|
| 140 | - { |
|
| 141 | - return ''; |
|
| 142 | - } |
|
| 126 | + /** |
|
| 127 | + * This function is called by the session handler |
|
| 128 | + * to read the data associated with a given session ID. |
|
| 129 | + * This function must retrieve and return the session data |
|
| 130 | + * for the session identified by $id. |
|
| 131 | + * |
|
| 132 | + * Has to be overwritten by each container class |
|
| 133 | + * |
|
| 134 | + * @param string $id ID of the session |
|
| 135 | + * |
|
| 136 | + * @access public |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + public function read($id) |
|
| 140 | + { |
|
| 141 | + return ''; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * This function is called when the session handler |
|
| 146 | - * has session data to save, which usually happens |
|
| 147 | - * at the end of your script |
|
| 148 | - * |
|
| 149 | - * Has to be overwritten by each container class |
|
| 150 | - * |
|
| 151 | - * @param string $id ID of the session |
|
| 152 | - * @param mixed $data The data associated with a given session ID |
|
| 153 | - * |
|
| 154 | - * @access public |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public function write($id, $data) |
|
| 158 | - { |
|
| 159 | - return true; |
|
| 160 | - } |
|
| 144 | + /** |
|
| 145 | + * This function is called when the session handler |
|
| 146 | + * has session data to save, which usually happens |
|
| 147 | + * at the end of your script |
|
| 148 | + * |
|
| 149 | + * Has to be overwritten by each container class |
|
| 150 | + * |
|
| 151 | + * @param string $id ID of the session |
|
| 152 | + * @param mixed $data The data associated with a given session ID |
|
| 153 | + * |
|
| 154 | + * @access public |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public function write($id, $data) |
|
| 158 | + { |
|
| 159 | + return true; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * This function is called when a session is destroyed. |
|
| 164 | - * It is responsible for deleting the session and cleaning things up. |
|
| 165 | - * |
|
| 166 | - * Has to be overwritten by each container class |
|
| 167 | - * |
|
| 168 | - * @param string $id ID of the session |
|
| 169 | - * |
|
| 170 | - * @access public |
|
| 171 | - * @return bool |
|
| 172 | - */ |
|
| 173 | - public function destroy($id) |
|
| 174 | - { |
|
| 175 | - return true; |
|
| 176 | - } |
|
| 162 | + /** |
|
| 163 | + * This function is called when a session is destroyed. |
|
| 164 | + * It is responsible for deleting the session and cleaning things up. |
|
| 165 | + * |
|
| 166 | + * Has to be overwritten by each container class |
|
| 167 | + * |
|
| 168 | + * @param string $id ID of the session |
|
| 169 | + * |
|
| 170 | + * @access public |
|
| 171 | + * @return bool |
|
| 172 | + */ |
|
| 173 | + public function destroy($id) |
|
| 174 | + { |
|
| 175 | + return true; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * This function copies session data of specified id to specified table |
|
| 180 | - * |
|
| 181 | - * Has to be overwritten by each container class |
|
| 182 | - * |
|
| 183 | - * @param string $targetTable Table to replicate data to |
|
| 184 | - * @param string $id ID of the session |
|
| 185 | - * |
|
| 186 | - * @access public |
|
| 187 | - * @return bool |
|
| 188 | - */ |
|
| 189 | - public function replicate($targetTable, $id = null) |
|
| 190 | - { |
|
| 191 | - return true; |
|
| 192 | - } |
|
| 178 | + /** |
|
| 179 | + * This function copies session data of specified id to specified table |
|
| 180 | + * |
|
| 181 | + * Has to be overwritten by each container class |
|
| 182 | + * |
|
| 183 | + * @param string $targetTable Table to replicate data to |
|
| 184 | + * @param string $id ID of the session |
|
| 185 | + * |
|
| 186 | + * @access public |
|
| 187 | + * @return bool |
|
| 188 | + */ |
|
| 189 | + public function replicate($targetTable, $id = null) |
|
| 190 | + { |
|
| 191 | + return true; |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * This function is responsible for garbage collection. |
|
| 196 | - * In the case of session handling, it is responsible |
|
| 197 | - * for deleting old, stale sessions that are hanging around. |
|
| 198 | - * The session handler will call this every now and then. |
|
| 199 | - * |
|
| 200 | - * Has to be overwritten by each container class |
|
| 201 | - * |
|
| 202 | - * @param integer $maxlifetime Maximum lifetime |
|
| 203 | - * |
|
| 204 | - * @access public |
|
| 205 | - * @return bool |
|
| 206 | - */ |
|
| 207 | - public function gc($maxlifetime) |
|
| 208 | - { |
|
| 209 | - return true; |
|
| 210 | - } |
|
| 194 | + /** |
|
| 195 | + * This function is responsible for garbage collection. |
|
| 196 | + * In the case of session handling, it is responsible |
|
| 197 | + * for deleting old, stale sessions that are hanging around. |
|
| 198 | + * The session handler will call this every now and then. |
|
| 199 | + * |
|
| 200 | + * Has to be overwritten by each container class |
|
| 201 | + * |
|
| 202 | + * @param integer $maxlifetime Maximum lifetime |
|
| 203 | + * |
|
| 204 | + * @access public |
|
| 205 | + * @return bool |
|
| 206 | + */ |
|
| 207 | + public function gc($maxlifetime) |
|
| 208 | + { |
|
| 209 | + return true; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * Set session save handler |
|
| 214 | - * |
|
| 215 | - * @access public |
|
| 216 | - * @return void |
|
| 217 | - */ |
|
| 218 | - public function set() |
|
| 219 | - { |
|
| 220 | - $GLOBALS['HTTP_Session_Container'] =& $this; |
|
| 221 | - session_module_name('user'); |
|
| 222 | - session_set_save_handler('HTTP_Session_Open', |
|
| 223 | - 'HTTP_Session_Close', |
|
| 224 | - 'HTTP_Session_Read', |
|
| 225 | - 'HTTP_Session_Write', |
|
| 226 | - 'HTTP_Session_Destroy', |
|
| 227 | - 'HTTP_Session_GC'); |
|
| 228 | - } |
|
| 212 | + /** |
|
| 213 | + * Set session save handler |
|
| 214 | + * |
|
| 215 | + * @access public |
|
| 216 | + * @return void |
|
| 217 | + */ |
|
| 218 | + public function set() |
|
| 219 | + { |
|
| 220 | + $GLOBALS['HTTP_Session_Container'] =& $this; |
|
| 221 | + session_module_name('user'); |
|
| 222 | + session_set_save_handler('HTTP_Session_Open', |
|
| 223 | + 'HTTP_Session_Close', |
|
| 224 | + 'HTTP_Session_Read', |
|
| 225 | + 'HTTP_Session_Write', |
|
| 226 | + 'HTTP_Session_Destroy', |
|
| 227 | + 'HTTP_Session_GC'); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - /** |
|
| 231 | - * Destructor for compatibility with PHP >= 5.0.5 |
|
| 232 | - * |
|
| 233 | - * @access private |
|
| 234 | - * @return void |
|
| 235 | - */ |
|
| 236 | - public function __destruct() |
|
| 237 | - { |
|
| 238 | - $GLOBALS['HTTP_Session_Container'] =& $this; |
|
| 239 | - session_write_close(); |
|
| 240 | - } |
|
| 230 | + /** |
|
| 231 | + * Destructor for compatibility with PHP >= 5.0.5 |
|
| 232 | + * |
|
| 233 | + * @access private |
|
| 234 | + * @return void |
|
| 235 | + */ |
|
| 236 | + public function __destruct() |
|
| 237 | + { |
|
| 238 | + $GLOBALS['HTTP_Session_Container'] =& $this; |
|
| 239 | + session_write_close(); |
|
| 240 | + } |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | // Delegate function calls to the object's methods |
| 244 | 244 | /** @ignore */ |
| 245 | 245 | function HTTP_Session_Open($save_path, $session_name) |
| 246 | 246 | { |
| 247 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->open($save_path, $session_name) |
|
| 248 | - : false; |
|
| 247 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->open($save_path, $session_name) |
|
| 248 | + : false; |
|
| 249 | 249 | } |
| 250 | 250 | /** @ignore */ |
| 251 | 251 | function HTTP_Session_Close() |
| 252 | 252 | { |
| 253 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->close() |
|
| 254 | - : false; |
|
| 253 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->close() |
|
| 254 | + : false; |
|
| 255 | 255 | } |
| 256 | 256 | /** @ignore */ |
| 257 | 257 | function HTTP_Session_Read($id) |
| 258 | 258 | { |
| 259 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->read($id) |
|
| 260 | - : false; |
|
| 259 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->read($id) |
|
| 260 | + : false; |
|
| 261 | 261 | } |
| 262 | 262 | /** @ignore */ |
| 263 | 263 | function HTTP_Session_Write($id, $data) |
| 264 | 264 | { |
| 265 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->write($id, $data) |
|
| 266 | - : false; |
|
| 265 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->write($id, $data) |
|
| 266 | + : false; |
|
| 267 | 267 | } |
| 268 | 268 | /** @ignore */ |
| 269 | 269 | function HTTP_Session_Destroy($id) |
| 270 | 270 | { |
| 271 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->destroy($id) |
|
| 272 | - : false; |
|
| 271 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->destroy($id) |
|
| 272 | + : false; |
|
| 273 | 273 | } |
| 274 | 274 | /** @ignore */ |
| 275 | 275 | function HTTP_Session_GC($maxlifetime) |
| 276 | 276 | { |
| 277 | - return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->gc($maxlifetime) |
|
| 278 | - : false; |
|
| 277 | + return (isset($GLOBALS['HTTP_Session_Container'])) ? $GLOBALS['HTTP_Session_Container']->gc($maxlifetime) |
|
| 278 | + : false; |
|
| 279 | 279 | } |
| 280 | 280 | ?> |
| 281 | 281 | \ No newline at end of file |
@@ -59,306 +59,306 @@ |
||
| 59 | 59 | */ |
| 60 | 60 | class HTTP_Session_Container_DB extends HTTP_Session_Container |
| 61 | 61 | { |
| 62 | - /** |
|
| 63 | - * DB connection object |
|
| 64 | - * |
|
| 65 | - * @var object DB |
|
| 66 | - * @access private |
|
| 67 | - */ |
|
| 68 | - public $db = null; |
|
| 62 | + /** |
|
| 63 | + * DB connection object |
|
| 64 | + * |
|
| 65 | + * @var object DB |
|
| 66 | + * @access private |
|
| 67 | + */ |
|
| 68 | + public $db = null; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Session data cache id |
|
| 72 | - * |
|
| 73 | - * @var mixed |
|
| 74 | - * @access private |
|
| 75 | - */ |
|
| 76 | - public $crc = false; |
|
| 70 | + /** |
|
| 71 | + * Session data cache id |
|
| 72 | + * |
|
| 73 | + * @var mixed |
|
| 74 | + * @access private |
|
| 75 | + */ |
|
| 76 | + public $crc = false; |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Constrtuctor method |
|
| 80 | - * |
|
| 81 | - * $options is an array with the options.<br> |
|
| 82 | - * The options are: |
|
| 83 | - * <ul> |
|
| 84 | - * <li>'dsn' - The DSN string</li> |
|
| 85 | - * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 86 | - * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 87 | - * the table on garbage collection, default is 'false'.</li> |
|
| 88 | - * </ul> |
|
| 89 | - * |
|
| 90 | - * @param array $options Options |
|
| 91 | - * |
|
| 92 | - * @access public |
|
| 93 | - * @return object |
|
| 94 | - */ |
|
| 95 | - public function HTTP_Session_Container_DB($options) |
|
| 96 | - { |
|
| 97 | - $this->_setDefaults(); |
|
| 98 | - if (is_array($options)) { |
|
| 99 | - $this->_parseOptions($options); |
|
| 100 | - } else { |
|
| 101 | - $this->options['dsn'] = $options; |
|
| 102 | - } |
|
| 103 | - } |
|
| 78 | + /** |
|
| 79 | + * Constrtuctor method |
|
| 80 | + * |
|
| 81 | + * $options is an array with the options.<br> |
|
| 82 | + * The options are: |
|
| 83 | + * <ul> |
|
| 84 | + * <li>'dsn' - The DSN string</li> |
|
| 85 | + * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 86 | + * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 87 | + * the table on garbage collection, default is 'false'.</li> |
|
| 88 | + * </ul> |
|
| 89 | + * |
|
| 90 | + * @param array $options Options |
|
| 91 | + * |
|
| 92 | + * @access public |
|
| 93 | + * @return object |
|
| 94 | + */ |
|
| 95 | + public function HTTP_Session_Container_DB($options) |
|
| 96 | + { |
|
| 97 | + $this->_setDefaults(); |
|
| 98 | + if (is_array($options)) { |
|
| 99 | + $this->_parseOptions($options); |
|
| 100 | + } else { |
|
| 101 | + $this->options['dsn'] = $options; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Connect to database by using the given DSN string |
|
| 107 | - * |
|
| 108 | - * @param string $dsn DSN string |
|
| 109 | - * |
|
| 110 | - * @access private |
|
| 111 | - * @return mixed Object on error, otherwise bool |
|
| 112 | - */ |
|
| 113 | - public function _connect($dsn) |
|
| 114 | - { |
|
| 115 | - if (is_string($dsn) || is_array($dsn)) { |
|
| 116 | - $this->db = DB::connect($dsn); |
|
| 117 | - } else if (is_object($dsn) && is_a($dsn, "db_common")) { |
|
| 118 | - $this->db = $dsn; |
|
| 119 | - } else if (is_object($dsn) && DB::isError($dsn)) { |
|
| 120 | - return new DB_Error($dsn->code, PEAR_ERROR_DIE); |
|
| 121 | - } else { |
|
| 122 | - return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 123 | - . " at line " . __LINE__, |
|
| 124 | - 41, |
|
| 125 | - PEAR_ERROR_RETURN, |
|
| 126 | - null, |
|
| 127 | - null |
|
| 128 | - ); |
|
| 105 | + /** |
|
| 106 | + * Connect to database by using the given DSN string |
|
| 107 | + * |
|
| 108 | + * @param string $dsn DSN string |
|
| 109 | + * |
|
| 110 | + * @access private |
|
| 111 | + * @return mixed Object on error, otherwise bool |
|
| 112 | + */ |
|
| 113 | + public function _connect($dsn) |
|
| 114 | + { |
|
| 115 | + if (is_string($dsn) || is_array($dsn)) { |
|
| 116 | + $this->db = DB::connect($dsn); |
|
| 117 | + } else if (is_object($dsn) && is_a($dsn, "db_common")) { |
|
| 118 | + $this->db = $dsn; |
|
| 119 | + } else if (is_object($dsn) && DB::isError($dsn)) { |
|
| 120 | + return new DB_Error($dsn->code, PEAR_ERROR_DIE); |
|
| 121 | + } else { |
|
| 122 | + return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 123 | + . " at line " . __LINE__, |
|
| 124 | + 41, |
|
| 125 | + PEAR_ERROR_RETURN, |
|
| 126 | + null, |
|
| 127 | + null |
|
| 128 | + ); |
|
| 129 | 129 | |
| 130 | - } |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - if (DB::isError($this->db)) { |
|
| 133 | - return new DB_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 134 | - } |
|
| 132 | + if (DB::isError($this->db)) { |
|
| 133 | + return new DB_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - return true; |
|
| 137 | - } |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Set some default options |
|
| 141 | - * |
|
| 142 | - * @access private |
|
| 143 | - * @return void |
|
| 144 | - */ |
|
| 145 | - public function _setDefaults() |
|
| 146 | - { |
|
| 147 | - $this->options['dsn'] = null; |
|
| 148 | - $this->options['table'] = 'sessiondata'; |
|
| 149 | - $this->options['autooptimize'] = false; |
|
| 150 | - } |
|
| 139 | + /** |
|
| 140 | + * Set some default options |
|
| 141 | + * |
|
| 142 | + * @access private |
|
| 143 | + * @return void |
|
| 144 | + */ |
|
| 145 | + public function _setDefaults() |
|
| 146 | + { |
|
| 147 | + $this->options['dsn'] = null; |
|
| 148 | + $this->options['table'] = 'sessiondata'; |
|
| 149 | + $this->options['autooptimize'] = false; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Establish connection to a database |
|
| 154 | - * |
|
| 155 | - * @param string $save_path Save path |
|
| 156 | - * @param string $session_name Session name |
|
| 157 | - * |
|
| 158 | - * @return bool |
|
| 159 | - */ |
|
| 160 | - public function open($save_path, $session_name) |
|
| 161 | - { |
|
| 162 | - if (DB::isError($this->_connect($this->options['dsn']))) { |
|
| 163 | - return false; |
|
| 164 | - } else { |
|
| 165 | - return true; |
|
| 166 | - } |
|
| 167 | - } |
|
| 152 | + /** |
|
| 153 | + * Establish connection to a database |
|
| 154 | + * |
|
| 155 | + * @param string $save_path Save path |
|
| 156 | + * @param string $session_name Session name |
|
| 157 | + * |
|
| 158 | + * @return bool |
|
| 159 | + */ |
|
| 160 | + public function open($save_path, $session_name) |
|
| 161 | + { |
|
| 162 | + if (DB::isError($this->_connect($this->options['dsn']))) { |
|
| 163 | + return false; |
|
| 164 | + } else { |
|
| 165 | + return true; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Free resources |
|
| 171 | - * |
|
| 172 | - * @return void |
|
| 173 | - */ |
|
| 174 | - public function close() |
|
| 175 | - { |
|
| 176 | - return true; |
|
| 177 | - } |
|
| 169 | + /** |
|
| 170 | + * Free resources |
|
| 171 | + * |
|
| 172 | + * @return void |
|
| 173 | + */ |
|
| 174 | + public function close() |
|
| 175 | + { |
|
| 176 | + return true; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * Read session data |
|
| 181 | - * |
|
| 182 | - * @param string $id Session id |
|
| 183 | - * |
|
| 184 | - * @return void |
|
| 185 | - */ |
|
| 186 | - public function read($id) |
|
| 187 | - { |
|
| 188 | - $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 189 | - $this->options['table'], |
|
| 190 | - $this->db->quoteSmart(md5($id)), |
|
| 191 | - time()); |
|
| 192 | - $result = $this->db->getOne($query); |
|
| 193 | - if (DB::isError($result)) { |
|
| 194 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 195 | - return false; |
|
| 196 | - } |
|
| 197 | - $this->crc = strlen($result) . crc32($result); |
|
| 198 | - return $result; |
|
| 199 | - } |
|
| 179 | + /** |
|
| 180 | + * Read session data |
|
| 181 | + * |
|
| 182 | + * @param string $id Session id |
|
| 183 | + * |
|
| 184 | + * @return void |
|
| 185 | + */ |
|
| 186 | + public function read($id) |
|
| 187 | + { |
|
| 188 | + $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 189 | + $this->options['table'], |
|
| 190 | + $this->db->quoteSmart(md5($id)), |
|
| 191 | + time()); |
|
| 192 | + $result = $this->db->getOne($query); |
|
| 193 | + if (DB::isError($result)) { |
|
| 194 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + $this->crc = strlen($result) . crc32($result); |
|
| 198 | + return $result; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Write session data |
|
| 203 | - * |
|
| 204 | - * @param string $id Session id |
|
| 205 | - * @param mixed $data Data |
|
| 206 | - * |
|
| 207 | - * @return bool |
|
| 208 | - */ |
|
| 209 | - public function write($id, $data) |
|
| 210 | - { |
|
| 211 | - if ((false !== $this->crc) && |
|
| 212 | - ($this->crc === strlen($data) . crc32($data))) { |
|
| 213 | - // $_SESSION hasn't been touched, no need to update the blob column |
|
| 214 | - $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 215 | - $this->options['table'], |
|
| 216 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 217 | - $this->db->quoteSmart(md5($id))); |
|
| 218 | - } else { |
|
| 219 | - // Check if table row already exists |
|
| 220 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 221 | - $this->options['table'], |
|
| 222 | - $this->db->quoteSmart(md5($id))); |
|
| 223 | - $result = $this->db->getOne($query); |
|
| 224 | - if (DB::isError($result)) { |
|
| 225 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - if (0 == intval($result)) { |
|
| 229 | - // Insert new row into table |
|
| 230 | - $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 231 | - $this->options['table'], |
|
| 232 | - $this->db->quoteSmart(md5($id)), |
|
| 233 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 234 | - $this->db->quoteSmart($data)); |
|
| 235 | - } else { |
|
| 236 | - // Update existing row |
|
| 237 | - $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 238 | - $this->options['table'], |
|
| 239 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 240 | - $this->db->quoteSmart($data), |
|
| 241 | - $this->db->quoteSmart(md5($id))); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - $result = $this->db->query($query); |
|
| 245 | - if (DB::isError($result)) { |
|
| 246 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 247 | - return false; |
|
| 248 | - } |
|
| 201 | + /** |
|
| 202 | + * Write session data |
|
| 203 | + * |
|
| 204 | + * @param string $id Session id |
|
| 205 | + * @param mixed $data Data |
|
| 206 | + * |
|
| 207 | + * @return bool |
|
| 208 | + */ |
|
| 209 | + public function write($id, $data) |
|
| 210 | + { |
|
| 211 | + if ((false !== $this->crc) && |
|
| 212 | + ($this->crc === strlen($data) . crc32($data))) { |
|
| 213 | + // $_SESSION hasn't been touched, no need to update the blob column |
|
| 214 | + $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 215 | + $this->options['table'], |
|
| 216 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 217 | + $this->db->quoteSmart(md5($id))); |
|
| 218 | + } else { |
|
| 219 | + // Check if table row already exists |
|
| 220 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 221 | + $this->options['table'], |
|
| 222 | + $this->db->quoteSmart(md5($id))); |
|
| 223 | + $result = $this->db->getOne($query); |
|
| 224 | + if (DB::isError($result)) { |
|
| 225 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + if (0 == intval($result)) { |
|
| 229 | + // Insert new row into table |
|
| 230 | + $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 231 | + $this->options['table'], |
|
| 232 | + $this->db->quoteSmart(md5($id)), |
|
| 233 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 234 | + $this->db->quoteSmart($data)); |
|
| 235 | + } else { |
|
| 236 | + // Update existing row |
|
| 237 | + $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 238 | + $this->options['table'], |
|
| 239 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 240 | + $this->db->quoteSmart($data), |
|
| 241 | + $this->db->quoteSmart(md5($id))); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + $result = $this->db->query($query); |
|
| 245 | + if (DB::isError($result)) { |
|
| 246 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - return true; |
|
| 251 | - } |
|
| 250 | + return true; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Destroy session data |
|
| 255 | - * |
|
| 256 | - * @param string $id Session id |
|
| 257 | - * |
|
| 258 | - * @return void |
|
| 259 | - */ |
|
| 260 | - public function destroy($id) |
|
| 261 | - { |
|
| 262 | - $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 263 | - $this->options['table'], |
|
| 264 | - $this->db->quoteSmart(md5($id))); |
|
| 265 | - $result = $this->db->query($query); |
|
| 266 | - if (DB::isError($result)) { |
|
| 267 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 268 | - return false; |
|
| 269 | - } |
|
| 253 | + /** |
|
| 254 | + * Destroy session data |
|
| 255 | + * |
|
| 256 | + * @param string $id Session id |
|
| 257 | + * |
|
| 258 | + * @return void |
|
| 259 | + */ |
|
| 260 | + public function destroy($id) |
|
| 261 | + { |
|
| 262 | + $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 263 | + $this->options['table'], |
|
| 264 | + $this->db->quoteSmart(md5($id))); |
|
| 265 | + $result = $this->db->query($query); |
|
| 266 | + if (DB::isError($result)) { |
|
| 267 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 268 | + return false; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - return true; |
|
| 272 | - } |
|
| 271 | + return true; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 276 | - * |
|
| 277 | - * @param string $targetTable Table to replicate to |
|
| 278 | - * @param string $id Id of record to replicate |
|
| 279 | - * |
|
| 280 | - * @access private |
|
| 281 | - * @return bool |
|
| 282 | - */ |
|
| 283 | - public function replicate($targetTable, $id = null) |
|
| 284 | - { |
|
| 285 | - if (is_null($id)) { |
|
| 286 | - $id = HTTP_Session::id(); |
|
| 287 | - } |
|
| 274 | + /** |
|
| 275 | + * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 276 | + * |
|
| 277 | + * @param string $targetTable Table to replicate to |
|
| 278 | + * @param string $id Id of record to replicate |
|
| 279 | + * |
|
| 280 | + * @access private |
|
| 281 | + * @return bool |
|
| 282 | + */ |
|
| 283 | + public function replicate($targetTable, $id = null) |
|
| 284 | + { |
|
| 285 | + if (is_null($id)) { |
|
| 286 | + $id = HTTP_Session::id(); |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - // Check if table row already exists |
|
| 290 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 291 | - $targetTable, |
|
| 292 | - $this->db->quoteSmart(md5($id))); |
|
| 293 | - $result = $this->db->getOne($query); |
|
| 294 | - if (DB::isError($result)) { |
|
| 295 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 296 | - return false; |
|
| 297 | - } |
|
| 289 | + // Check if table row already exists |
|
| 290 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 291 | + $targetTable, |
|
| 292 | + $this->db->quoteSmart(md5($id))); |
|
| 293 | + $result = $this->db->getOne($query); |
|
| 294 | + if (DB::isError($result)) { |
|
| 295 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 296 | + return false; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - // Insert new row into dest table |
|
| 300 | - if (0 == intval($result)) { |
|
| 301 | - $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 302 | - $targetTable, |
|
| 303 | - $this->options['table'], |
|
| 304 | - $this->db->quoteSmart(md5($id))); |
|
| 299 | + // Insert new row into dest table |
|
| 300 | + if (0 == intval($result)) { |
|
| 301 | + $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 302 | + $targetTable, |
|
| 303 | + $this->options['table'], |
|
| 304 | + $this->db->quoteSmart(md5($id))); |
|
| 305 | 305 | |
| 306 | - } else { |
|
| 307 | - // Update existing row |
|
| 308 | - $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | - $targetTable, |
|
| 310 | - $this->options['table'], |
|
| 311 | - $this->db->quoteSmart(md5($id))); |
|
| 312 | - } |
|
| 306 | + } else { |
|
| 307 | + // Update existing row |
|
| 308 | + $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | + $targetTable, |
|
| 310 | + $this->options['table'], |
|
| 311 | + $this->db->quoteSmart(md5($id))); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - $result = $this->db->query($query); |
|
| 315 | - if (DB::isError($result)) { |
|
| 316 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 317 | - return false; |
|
| 318 | - } |
|
| 314 | + $result = $this->db->query($query); |
|
| 315 | + if (DB::isError($result)) { |
|
| 316 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 317 | + return false; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - return true; |
|
| 321 | - } |
|
| 320 | + return true; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - /** |
|
| 324 | - * Garbage collection |
|
| 325 | - * |
|
| 326 | - * @param int $maxlifetime Maximum lifetime |
|
| 327 | - * |
|
| 328 | - * @return bool |
|
| 329 | - */ |
|
| 330 | - public function gc($maxlifetime) |
|
| 331 | - { |
|
| 332 | - $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | - $this->options['table'], |
|
| 334 | - time()); |
|
| 335 | - $result = $this->db->query($query); |
|
| 336 | - if (DB::isError($result)) { |
|
| 337 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 338 | - return false; |
|
| 339 | - } |
|
| 340 | - if ($this->options['autooptimize']) { |
|
| 341 | - switch($this->db->phptype) { |
|
| 342 | - case 'mysql': |
|
| 343 | - $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | - break; |
|
| 345 | - case 'pgsql': |
|
| 346 | - $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | - break; |
|
| 348 | - default: |
|
| 349 | - $query = null; |
|
| 350 | - break; |
|
| 351 | - } |
|
| 352 | - if (isset($query)) { |
|
| 353 | - $result = $this->db->query($query); |
|
| 354 | - if (DB::isError($result)) { |
|
| 355 | - new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - } |
|
| 323 | + /** |
|
| 324 | + * Garbage collection |
|
| 325 | + * |
|
| 326 | + * @param int $maxlifetime Maximum lifetime |
|
| 327 | + * |
|
| 328 | + * @return bool |
|
| 329 | + */ |
|
| 330 | + public function gc($maxlifetime) |
|
| 331 | + { |
|
| 332 | + $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | + $this->options['table'], |
|
| 334 | + time()); |
|
| 335 | + $result = $this->db->query($query); |
|
| 336 | + if (DB::isError($result)) { |
|
| 337 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 338 | + return false; |
|
| 339 | + } |
|
| 340 | + if ($this->options['autooptimize']) { |
|
| 341 | + switch($this->db->phptype) { |
|
| 342 | + case 'mysql': |
|
| 343 | + $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | + break; |
|
| 345 | + case 'pgsql': |
|
| 346 | + $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | + break; |
|
| 348 | + default: |
|
| 349 | + $query = null; |
|
| 350 | + break; |
|
| 351 | + } |
|
| 352 | + if (isset($query)) { |
|
| 353 | + $result = $this->db->query($query); |
|
| 354 | + if (DB::isError($result)) { |
|
| 355 | + new DB_Error($result->code, PEAR_ERROR_DIE); |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - return true; |
|
| 362 | - } |
|
| 361 | + return true; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | ?> |
| 365 | 365 | \ No newline at end of file |
@@ -60,305 +60,305 @@ |
||
| 60 | 60 | class HTTP_Session_Container_MDB extends HTTP_Session_Container |
| 61 | 61 | { |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * MDB connection object |
|
| 65 | - * |
|
| 66 | - * @var object MDB |
|
| 67 | - * @access private |
|
| 68 | - */ |
|
| 69 | - public $db = null; |
|
| 63 | + /** |
|
| 64 | + * MDB connection object |
|
| 65 | + * |
|
| 66 | + * @var object MDB |
|
| 67 | + * @access private |
|
| 68 | + */ |
|
| 69 | + public $db = null; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Session data cache id |
|
| 73 | - * |
|
| 74 | - * @var mixed |
|
| 75 | - * @access private |
|
| 76 | - */ |
|
| 77 | - public $crc = false; |
|
| 71 | + /** |
|
| 72 | + * Session data cache id |
|
| 73 | + * |
|
| 74 | + * @var mixed |
|
| 75 | + * @access private |
|
| 76 | + */ |
|
| 77 | + public $crc = false; |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Constructor method |
|
| 81 | - * |
|
| 82 | - * $options is an array with the options.<br> |
|
| 83 | - * The options are: |
|
| 84 | - * <ul> |
|
| 85 | - * <li>'dsn' - The DSN string</li> |
|
| 86 | - * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 87 | - * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 88 | - * the table on garbage collection, default is 'false'.</li> |
|
| 89 | - * </ul> |
|
| 90 | - * |
|
| 91 | - * @param array $options Options |
|
| 92 | - * |
|
| 93 | - * @access public |
|
| 94 | - * @return object |
|
| 95 | - */ |
|
| 96 | - public function HTTP_Session_Container_MDB($options) |
|
| 97 | - { |
|
| 98 | - $this->_setDefaults(); |
|
| 99 | - if (is_array($options)) { |
|
| 100 | - $this->_parseOptions($options); |
|
| 101 | - } else { |
|
| 102 | - $this->options['dsn'] = $options; |
|
| 103 | - } |
|
| 104 | - } |
|
| 79 | + /** |
|
| 80 | + * Constructor method |
|
| 81 | + * |
|
| 82 | + * $options is an array with the options.<br> |
|
| 83 | + * The options are: |
|
| 84 | + * <ul> |
|
| 85 | + * <li>'dsn' - The DSN string</li> |
|
| 86 | + * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 87 | + * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 88 | + * the table on garbage collection, default is 'false'.</li> |
|
| 89 | + * </ul> |
|
| 90 | + * |
|
| 91 | + * @param array $options Options |
|
| 92 | + * |
|
| 93 | + * @access public |
|
| 94 | + * @return object |
|
| 95 | + */ |
|
| 96 | + public function HTTP_Session_Container_MDB($options) |
|
| 97 | + { |
|
| 98 | + $this->_setDefaults(); |
|
| 99 | + if (is_array($options)) { |
|
| 100 | + $this->_parseOptions($options); |
|
| 101 | + } else { |
|
| 102 | + $this->options['dsn'] = $options; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Connect to database by using the given DSN string |
|
| 108 | - * |
|
| 109 | - * @param string $dsn DSN string |
|
| 110 | - * |
|
| 111 | - * @access private |
|
| 112 | - * @return mixed Object on error, otherwise bool |
|
| 113 | - */ |
|
| 114 | - public function _connect($dsn) |
|
| 115 | - { |
|
| 116 | - if (is_string($dsn) || is_array($dsn)) { |
|
| 117 | - $this->db = MDB::connect($dsn); |
|
| 118 | - } else if (is_object($dsn) && is_a($dsn, 'mdb_common')) { |
|
| 119 | - $this->db = $dsn; |
|
| 120 | - } else if (is_object($dsn) && MDB::isError($dsn)) { |
|
| 121 | - return new MDB_Error($dsn->code, PEAR_ERROR_DIE); |
|
| 122 | - } else { |
|
| 123 | - return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 124 | - . " at line " . __LINE__, |
|
| 125 | - 41, |
|
| 126 | - PEAR_ERROR_RETURN, |
|
| 127 | - null, |
|
| 128 | - null |
|
| 129 | - ); |
|
| 106 | + /** |
|
| 107 | + * Connect to database by using the given DSN string |
|
| 108 | + * |
|
| 109 | + * @param string $dsn DSN string |
|
| 110 | + * |
|
| 111 | + * @access private |
|
| 112 | + * @return mixed Object on error, otherwise bool |
|
| 113 | + */ |
|
| 114 | + public function _connect($dsn) |
|
| 115 | + { |
|
| 116 | + if (is_string($dsn) || is_array($dsn)) { |
|
| 117 | + $this->db = MDB::connect($dsn); |
|
| 118 | + } else if (is_object($dsn) && is_a($dsn, 'mdb_common')) { |
|
| 119 | + $this->db = $dsn; |
|
| 120 | + } else if (is_object($dsn) && MDB::isError($dsn)) { |
|
| 121 | + return new MDB_Error($dsn->code, PEAR_ERROR_DIE); |
|
| 122 | + } else { |
|
| 123 | + return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 124 | + . " at line " . __LINE__, |
|
| 125 | + 41, |
|
| 126 | + PEAR_ERROR_RETURN, |
|
| 127 | + null, |
|
| 128 | + null |
|
| 129 | + ); |
|
| 130 | 130 | |
| 131 | - } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - if (MDB::isError($this->db)) { |
|
| 134 | - return new MDB_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 135 | - } |
|
| 133 | + if (MDB::isError($this->db)) { |
|
| 134 | + return new MDB_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - return true; |
|
| 138 | - } |
|
| 137 | + return true; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Set some default options |
|
| 142 | - * |
|
| 143 | - * @access private |
|
| 144 | - * @return void |
|
| 145 | - */ |
|
| 146 | - public function _setDefaults() |
|
| 147 | - { |
|
| 148 | - $this->options['dsn'] = null; |
|
| 149 | - $this->options['table'] = 'sessiondata'; |
|
| 150 | - $this->options['autooptimize'] = false; |
|
| 151 | - } |
|
| 140 | + /** |
|
| 141 | + * Set some default options |
|
| 142 | + * |
|
| 143 | + * @access private |
|
| 144 | + * @return void |
|
| 145 | + */ |
|
| 146 | + public function _setDefaults() |
|
| 147 | + { |
|
| 148 | + $this->options['dsn'] = null; |
|
| 149 | + $this->options['table'] = 'sessiondata'; |
|
| 150 | + $this->options['autooptimize'] = false; |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Establish connection to a database |
|
| 155 | - * |
|
| 156 | - * @param string $save_path Save path |
|
| 157 | - * @param string $session_name Session name |
|
| 158 | - * |
|
| 159 | - * @return bool |
|
| 160 | - */ |
|
| 161 | - public function open($save_path, $session_name) |
|
| 162 | - { |
|
| 163 | - if (MDB::isError($this->_connect($this->options['dsn']))) { |
|
| 164 | - return false; |
|
| 165 | - } else { |
|
| 166 | - return true; |
|
| 167 | - } |
|
| 168 | - } |
|
| 153 | + /** |
|
| 154 | + * Establish connection to a database |
|
| 155 | + * |
|
| 156 | + * @param string $save_path Save path |
|
| 157 | + * @param string $session_name Session name |
|
| 158 | + * |
|
| 159 | + * @return bool |
|
| 160 | + */ |
|
| 161 | + public function open($save_path, $session_name) |
|
| 162 | + { |
|
| 163 | + if (MDB::isError($this->_connect($this->options['dsn']))) { |
|
| 164 | + return false; |
|
| 165 | + } else { |
|
| 166 | + return true; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Free resources |
|
| 172 | - * |
|
| 173 | - * @return bool |
|
| 174 | - */ |
|
| 175 | - public function close() |
|
| 176 | - { |
|
| 177 | - return true; |
|
| 178 | - } |
|
| 170 | + /** |
|
| 171 | + * Free resources |
|
| 172 | + * |
|
| 173 | + * @return bool |
|
| 174 | + */ |
|
| 175 | + public function close() |
|
| 176 | + { |
|
| 177 | + return true; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Read session data |
|
| 182 | - * |
|
| 183 | - * @param string $id Session id |
|
| 184 | - * |
|
| 185 | - * @return mixed |
|
| 186 | - */ |
|
| 187 | - public function read($id) |
|
| 188 | - { |
|
| 189 | - $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 190 | - $this->options['table'], |
|
| 191 | - $this->db->getTextValue(md5($id)), |
|
| 192 | - time()); |
|
| 193 | - $result = $this->db->getOne($query); |
|
| 194 | - if (MDB::isError($result)) { |
|
| 195 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - $this->crc = strlen($result) . crc32($result); |
|
| 199 | - return $result; |
|
| 200 | - } |
|
| 180 | + /** |
|
| 181 | + * Read session data |
|
| 182 | + * |
|
| 183 | + * @param string $id Session id |
|
| 184 | + * |
|
| 185 | + * @return mixed |
|
| 186 | + */ |
|
| 187 | + public function read($id) |
|
| 188 | + { |
|
| 189 | + $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 190 | + $this->options['table'], |
|
| 191 | + $this->db->getTextValue(md5($id)), |
|
| 192 | + time()); |
|
| 193 | + $result = $this->db->getOne($query); |
|
| 194 | + if (MDB::isError($result)) { |
|
| 195 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + $this->crc = strlen($result) . crc32($result); |
|
| 199 | + return $result; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Write session data |
|
| 204 | - * |
|
| 205 | - * @param string $id Session id |
|
| 206 | - * @param mixed $data Data |
|
| 207 | - * |
|
| 208 | - * @return bool |
|
| 209 | - */ |
|
| 210 | - public function write($id, $data) |
|
| 211 | - { |
|
| 212 | - if ((false !== $this->crc) && |
|
| 213 | - ($this->crc === strlen($data) . crc32($data))) { |
|
| 214 | - // $_SESSION hasn't been touched, no need to update the blob column |
|
| 215 | - $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 216 | - $this->options['table'], |
|
| 217 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 218 | - $this->db->getTextValue(md5($id))); |
|
| 219 | - } else { |
|
| 220 | - // Check if table row already exists |
|
| 221 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 222 | - $this->options['table'], |
|
| 223 | - $this->db->getTextValue(md5($id))); |
|
| 224 | - $result = $this->db->getOne($query); |
|
| 225 | - if (MDB::isError($result)) { |
|
| 226 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 229 | - if (0 == intval($result)) { |
|
| 230 | - // Insert new row into table |
|
| 231 | - $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 232 | - $this->options['table'], |
|
| 233 | - $this->db->getTextValue(md5($id)), |
|
| 234 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 235 | - $this->db->getTextValue($data)); |
|
| 236 | - } else { |
|
| 237 | - // Update existing row |
|
| 238 | - $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 239 | - $this->options['table'], |
|
| 240 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 241 | - $this->db->getTextValue($data), |
|
| 242 | - $this->db->getTextValue(md5($id))); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - $result = $this->db->query($query); |
|
| 246 | - if (MDB::isError($result)) { |
|
| 247 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 248 | - return false; |
|
| 249 | - } |
|
| 202 | + /** |
|
| 203 | + * Write session data |
|
| 204 | + * |
|
| 205 | + * @param string $id Session id |
|
| 206 | + * @param mixed $data Data |
|
| 207 | + * |
|
| 208 | + * @return bool |
|
| 209 | + */ |
|
| 210 | + public function write($id, $data) |
|
| 211 | + { |
|
| 212 | + if ((false !== $this->crc) && |
|
| 213 | + ($this->crc === strlen($data) . crc32($data))) { |
|
| 214 | + // $_SESSION hasn't been touched, no need to update the blob column |
|
| 215 | + $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 216 | + $this->options['table'], |
|
| 217 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 218 | + $this->db->getTextValue(md5($id))); |
|
| 219 | + } else { |
|
| 220 | + // Check if table row already exists |
|
| 221 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 222 | + $this->options['table'], |
|
| 223 | + $this->db->getTextValue(md5($id))); |
|
| 224 | + $result = $this->db->getOne($query); |
|
| 225 | + if (MDB::isError($result)) { |
|
| 226 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + if (0 == intval($result)) { |
|
| 230 | + // Insert new row into table |
|
| 231 | + $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 232 | + $this->options['table'], |
|
| 233 | + $this->db->getTextValue(md5($id)), |
|
| 234 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 235 | + $this->db->getTextValue($data)); |
|
| 236 | + } else { |
|
| 237 | + // Update existing row |
|
| 238 | + $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 239 | + $this->options['table'], |
|
| 240 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 241 | + $this->db->getTextValue($data), |
|
| 242 | + $this->db->getTextValue(md5($id))); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + $result = $this->db->query($query); |
|
| 246 | + if (MDB::isError($result)) { |
|
| 247 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - return true; |
|
| 252 | - } |
|
| 251 | + return true; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * Destroy session data |
|
| 256 | - * |
|
| 257 | - * @param string $id Session id |
|
| 258 | - * |
|
| 259 | - * @return bool |
|
| 260 | - */ |
|
| 261 | - public function destroy($id) |
|
| 262 | - { |
|
| 263 | - $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 264 | - $this->options['table'], |
|
| 265 | - $this->db->getTextValue(md5($id))); |
|
| 266 | - $result = $this->db->query($query); |
|
| 267 | - if (MDB::isError($result)) { |
|
| 268 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 269 | - return false; |
|
| 270 | - } |
|
| 254 | + /** |
|
| 255 | + * Destroy session data |
|
| 256 | + * |
|
| 257 | + * @param string $id Session id |
|
| 258 | + * |
|
| 259 | + * @return bool |
|
| 260 | + */ |
|
| 261 | + public function destroy($id) |
|
| 262 | + { |
|
| 263 | + $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 264 | + $this->options['table'], |
|
| 265 | + $this->db->getTextValue(md5($id))); |
|
| 266 | + $result = $this->db->query($query); |
|
| 267 | + if (MDB::isError($result)) { |
|
| 268 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 269 | + return false; |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - return true; |
|
| 273 | - } |
|
| 272 | + return true; |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 277 | - * |
|
| 278 | - * @param string $targetTable Table to replicate to |
|
| 279 | - * @param string $id Id of record to replicate |
|
| 280 | - * |
|
| 281 | - * @access private |
|
| 282 | - * @return bool |
|
| 283 | - */ |
|
| 284 | - public function replicate($targetTable, $id = null) |
|
| 285 | - { |
|
| 286 | - if (is_null($id)) { |
|
| 287 | - $id = HTTP_Session::id(); |
|
| 288 | - } |
|
| 275 | + /** |
|
| 276 | + * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 277 | + * |
|
| 278 | + * @param string $targetTable Table to replicate to |
|
| 279 | + * @param string $id Id of record to replicate |
|
| 280 | + * |
|
| 281 | + * @access private |
|
| 282 | + * @return bool |
|
| 283 | + */ |
|
| 284 | + public function replicate($targetTable, $id = null) |
|
| 285 | + { |
|
| 286 | + if (is_null($id)) { |
|
| 287 | + $id = HTTP_Session::id(); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - // Check if table row already exists |
|
| 291 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 292 | - $targetTable, |
|
| 293 | - $this->db->getTextValue(md5($id))); |
|
| 294 | - $result = $this->db->getOne($query); |
|
| 295 | - if (MDB::isError($result)) { |
|
| 296 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 297 | - return false; |
|
| 298 | - } |
|
| 290 | + // Check if table row already exists |
|
| 291 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 292 | + $targetTable, |
|
| 293 | + $this->db->getTextValue(md5($id))); |
|
| 294 | + $result = $this->db->getOne($query); |
|
| 295 | + if (MDB::isError($result)) { |
|
| 296 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 297 | + return false; |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - // Insert new row into dest table |
|
| 301 | - if (0 == intval($result)) { |
|
| 302 | - $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 303 | - $targetTable, |
|
| 304 | - $this->options['table'], |
|
| 305 | - $this->db->getTextValue(md5($id))); |
|
| 306 | - } else { |
|
| 307 | - // Update existing row |
|
| 308 | - $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | - $targetTable, |
|
| 310 | - $this->options['table'], |
|
| 311 | - $this->db->getTextValue(md5($id))); |
|
| 312 | - } |
|
| 300 | + // Insert new row into dest table |
|
| 301 | + if (0 == intval($result)) { |
|
| 302 | + $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 303 | + $targetTable, |
|
| 304 | + $this->options['table'], |
|
| 305 | + $this->db->getTextValue(md5($id))); |
|
| 306 | + } else { |
|
| 307 | + // Update existing row |
|
| 308 | + $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | + $targetTable, |
|
| 310 | + $this->options['table'], |
|
| 311 | + $this->db->getTextValue(md5($id))); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - $result = $this->db->query($query); |
|
| 315 | - if (MDB::isError($result)) { |
|
| 316 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 317 | - return false; |
|
| 318 | - } |
|
| 314 | + $result = $this->db->query($query); |
|
| 315 | + if (MDB::isError($result)) { |
|
| 316 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 317 | + return false; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - return true; |
|
| 321 | - } |
|
| 320 | + return true; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - /** |
|
| 324 | - * Garbage collection |
|
| 325 | - * |
|
| 326 | - * @param int $maxlifetime Maximum lifetime |
|
| 327 | - * |
|
| 328 | - * @return bool |
|
| 329 | - */ |
|
| 330 | - public function gc($maxlifetime) |
|
| 331 | - { |
|
| 332 | - $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | - $this->options['table'], |
|
| 334 | - time()); |
|
| 335 | - $result = $this->db->query($query); |
|
| 336 | - if (MDB::isError($result)) { |
|
| 337 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 338 | - return false; |
|
| 339 | - } |
|
| 340 | - if ($this->options['autooptimize']) { |
|
| 341 | - switch($this->db->phptype) { |
|
| 342 | - case 'mysql': |
|
| 343 | - $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | - break; |
|
| 345 | - case 'pgsql': |
|
| 346 | - $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | - break; |
|
| 348 | - default: |
|
| 349 | - $query = null; |
|
| 350 | - break; |
|
| 351 | - } |
|
| 352 | - if (isset($query)) { |
|
| 353 | - $result = $this->db->query($query); |
|
| 354 | - if (MDB::isError($result)) { |
|
| 355 | - new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - } |
|
| 323 | + /** |
|
| 324 | + * Garbage collection |
|
| 325 | + * |
|
| 326 | + * @param int $maxlifetime Maximum lifetime |
|
| 327 | + * |
|
| 328 | + * @return bool |
|
| 329 | + */ |
|
| 330 | + public function gc($maxlifetime) |
|
| 331 | + { |
|
| 332 | + $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | + $this->options['table'], |
|
| 334 | + time()); |
|
| 335 | + $result = $this->db->query($query); |
|
| 336 | + if (MDB::isError($result)) { |
|
| 337 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 338 | + return false; |
|
| 339 | + } |
|
| 340 | + if ($this->options['autooptimize']) { |
|
| 341 | + switch($this->db->phptype) { |
|
| 342 | + case 'mysql': |
|
| 343 | + $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | + break; |
|
| 345 | + case 'pgsql': |
|
| 346 | + $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | + break; |
|
| 348 | + default: |
|
| 349 | + $query = null; |
|
| 350 | + break; |
|
| 351 | + } |
|
| 352 | + if (isset($query)) { |
|
| 353 | + $result = $this->db->query($query); |
|
| 354 | + if (MDB::isError($result)) { |
|
| 355 | + new MDB_Error($result->code, PEAR_ERROR_DIE); |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - return true; |
|
| 362 | - } |
|
| 361 | + return true; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | ?> |
| 365 | 365 | \ No newline at end of file |
@@ -43,160 +43,160 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | class HTTP_Session_Container_Memcache extends HTTP_Session_Container |
| 45 | 45 | { |
| 46 | - /** |
|
| 47 | - * Memcache connection object |
|
| 48 | - * |
|
| 49 | - * @var object Memcache |
|
| 50 | - * @access private |
|
| 51 | - */ |
|
| 52 | - public $mc; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Constructor method |
|
| 56 | - * |
|
| 57 | - * $options is an array with the options.<br> |
|
| 58 | - * The options are: |
|
| 59 | - * <ul> |
|
| 60 | - * <li>'memcache' - Memcache object |
|
| 61 | - * <li>'prefix' - Key prefix, default is 'sessiondata:'</li> |
|
| 62 | - * </ul> |
|
| 63 | - * |
|
| 64 | - * @param array $options Options |
|
| 65 | - * |
|
| 66 | - * @access public |
|
| 67 | - * @return object |
|
| 68 | - */ |
|
| 69 | - public function HTTP_Session_Container_Memcache($options) |
|
| 70 | - { |
|
| 71 | - $this->_setDefaults(); |
|
| 72 | - |
|
| 73 | - if (is_array($options)) { |
|
| 74 | - $this->_parseOptions($options); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Connect to database by using the given DSN string |
|
| 80 | - * |
|
| 81 | - * @param string $mc Memcache object |
|
| 82 | - * |
|
| 83 | - * @access private |
|
| 84 | - * @return mixed Object on error, otherwise bool |
|
| 85 | - */ |
|
| 86 | - public function _connect($mc) |
|
| 87 | - { |
|
| 88 | - if (is_object($mc) && is_a($mc, 'Memcache')) { |
|
| 89 | - $this->mc = $mc; |
|
| 90 | - |
|
| 91 | - } else { |
|
| 92 | - |
|
| 93 | - return new PEAR_Error('The given memcache object was not valid in file ' |
|
| 94 | - . __FILE__ . ' at line ' . __LINE__, |
|
| 95 | - 41, |
|
| 96 | - PEAR_ERROR_RETURN, |
|
| 97 | - null, |
|
| 98 | - null |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - return true; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Set some default options |
|
| 107 | - * |
|
| 108 | - * @access private |
|
| 109 | - * @return void |
|
| 110 | - */ |
|
| 111 | - public function _setDefaults() |
|
| 112 | - { |
|
| 113 | - $this->options['prefix'] = 'sessiondata:'; |
|
| 114 | - $this->options['memcache'] = null; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Establish connection to a database |
|
| 119 | - * |
|
| 120 | - * @param string $save_path Save path |
|
| 121 | - * @param string $session_name Session name |
|
| 122 | - * |
|
| 123 | - * @access public |
|
| 124 | - * @return mixed Object on error, otherwise bool |
|
| 125 | - */ |
|
| 126 | - public function open($save_path, $session_name) |
|
| 127 | - { |
|
| 128 | - return $this->_connect($this->options['memcache']); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Free resources |
|
| 133 | - * |
|
| 134 | - * @access public |
|
| 135 | - * @return bool |
|
| 136 | - */ |
|
| 137 | - public function close() |
|
| 138 | - { |
|
| 139 | - return true; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Read session data |
|
| 144 | - * |
|
| 145 | - * @param string $id Session id |
|
| 146 | - * |
|
| 147 | - * @access public |
|
| 148 | - * @return mixed |
|
| 149 | - */ |
|
| 150 | - public function read($id) |
|
| 151 | - { |
|
| 152 | - $result = $this->mc->get($this->options['prefix'] . $id); |
|
| 153 | - return $result; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Write session data |
|
| 158 | - * |
|
| 159 | - * @param string $id Session id |
|
| 160 | - * @param mixed $data Session data |
|
| 161 | - * |
|
| 162 | - * @access public |
|
| 163 | - * @return bool |
|
| 164 | - */ |
|
| 165 | - public function write($id, $data) |
|
| 166 | - { |
|
| 167 | - $this->mc->set($this->options['prefix'] . $id, |
|
| 168 | - $data, |
|
| 169 | - MEMCACHE_COMPRESSED, |
|
| 170 | - time() + ini_get('session.gc_maxlifetime')); |
|
| 171 | - |
|
| 172 | - return true; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Destroy session data |
|
| 177 | - * |
|
| 178 | - * @param string $id Session id |
|
| 179 | - * |
|
| 180 | - * @access public |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - public function destroy($id) |
|
| 184 | - { |
|
| 185 | - $this->mc->delete($this->options['prefix'] . $id); |
|
| 186 | - return true; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Garbage collection |
|
| 191 | - * |
|
| 192 | - * @param int $maxlifetime Maximum lifetime |
|
| 193 | - * |
|
| 194 | - * @access public |
|
| 195 | - * @return bool |
|
| 196 | - */ |
|
| 197 | - public function gc($maxlifetime) |
|
| 198 | - { |
|
| 199 | - return true; |
|
| 200 | - } |
|
| 46 | + /** |
|
| 47 | + * Memcache connection object |
|
| 48 | + * |
|
| 49 | + * @var object Memcache |
|
| 50 | + * @access private |
|
| 51 | + */ |
|
| 52 | + public $mc; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Constructor method |
|
| 56 | + * |
|
| 57 | + * $options is an array with the options.<br> |
|
| 58 | + * The options are: |
|
| 59 | + * <ul> |
|
| 60 | + * <li>'memcache' - Memcache object |
|
| 61 | + * <li>'prefix' - Key prefix, default is 'sessiondata:'</li> |
|
| 62 | + * </ul> |
|
| 63 | + * |
|
| 64 | + * @param array $options Options |
|
| 65 | + * |
|
| 66 | + * @access public |
|
| 67 | + * @return object |
|
| 68 | + */ |
|
| 69 | + public function HTTP_Session_Container_Memcache($options) |
|
| 70 | + { |
|
| 71 | + $this->_setDefaults(); |
|
| 72 | + |
|
| 73 | + if (is_array($options)) { |
|
| 74 | + $this->_parseOptions($options); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Connect to database by using the given DSN string |
|
| 80 | + * |
|
| 81 | + * @param string $mc Memcache object |
|
| 82 | + * |
|
| 83 | + * @access private |
|
| 84 | + * @return mixed Object on error, otherwise bool |
|
| 85 | + */ |
|
| 86 | + public function _connect($mc) |
|
| 87 | + { |
|
| 88 | + if (is_object($mc) && is_a($mc, 'Memcache')) { |
|
| 89 | + $this->mc = $mc; |
|
| 90 | + |
|
| 91 | + } else { |
|
| 92 | + |
|
| 93 | + return new PEAR_Error('The given memcache object was not valid in file ' |
|
| 94 | + . __FILE__ . ' at line ' . __LINE__, |
|
| 95 | + 41, |
|
| 96 | + PEAR_ERROR_RETURN, |
|
| 97 | + null, |
|
| 98 | + null |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + return true; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Set some default options |
|
| 107 | + * |
|
| 108 | + * @access private |
|
| 109 | + * @return void |
|
| 110 | + */ |
|
| 111 | + public function _setDefaults() |
|
| 112 | + { |
|
| 113 | + $this->options['prefix'] = 'sessiondata:'; |
|
| 114 | + $this->options['memcache'] = null; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Establish connection to a database |
|
| 119 | + * |
|
| 120 | + * @param string $save_path Save path |
|
| 121 | + * @param string $session_name Session name |
|
| 122 | + * |
|
| 123 | + * @access public |
|
| 124 | + * @return mixed Object on error, otherwise bool |
|
| 125 | + */ |
|
| 126 | + public function open($save_path, $session_name) |
|
| 127 | + { |
|
| 128 | + return $this->_connect($this->options['memcache']); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Free resources |
|
| 133 | + * |
|
| 134 | + * @access public |
|
| 135 | + * @return bool |
|
| 136 | + */ |
|
| 137 | + public function close() |
|
| 138 | + { |
|
| 139 | + return true; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Read session data |
|
| 144 | + * |
|
| 145 | + * @param string $id Session id |
|
| 146 | + * |
|
| 147 | + * @access public |
|
| 148 | + * @return mixed |
|
| 149 | + */ |
|
| 150 | + public function read($id) |
|
| 151 | + { |
|
| 152 | + $result = $this->mc->get($this->options['prefix'] . $id); |
|
| 153 | + return $result; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Write session data |
|
| 158 | + * |
|
| 159 | + * @param string $id Session id |
|
| 160 | + * @param mixed $data Session data |
|
| 161 | + * |
|
| 162 | + * @access public |
|
| 163 | + * @return bool |
|
| 164 | + */ |
|
| 165 | + public function write($id, $data) |
|
| 166 | + { |
|
| 167 | + $this->mc->set($this->options['prefix'] . $id, |
|
| 168 | + $data, |
|
| 169 | + MEMCACHE_COMPRESSED, |
|
| 170 | + time() + ini_get('session.gc_maxlifetime')); |
|
| 171 | + |
|
| 172 | + return true; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Destroy session data |
|
| 177 | + * |
|
| 178 | + * @param string $id Session id |
|
| 179 | + * |
|
| 180 | + * @access public |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + public function destroy($id) |
|
| 184 | + { |
|
| 185 | + $this->mc->delete($this->options['prefix'] . $id); |
|
| 186 | + return true; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Garbage collection |
|
| 191 | + * |
|
| 192 | + * @param int $maxlifetime Maximum lifetime |
|
| 193 | + * |
|
| 194 | + * @access public |
|
| 195 | + * @return bool |
|
| 196 | + */ |
|
| 197 | + public function gc($maxlifetime) |
|
| 198 | + { |
|
| 199 | + return true; |
|
| 200 | + } |
|
| 201 | 201 | } |
| 202 | 202 | ?> |
| 203 | 203 | \ No newline at end of file |
@@ -59,306 +59,306 @@ |
||
| 59 | 59 | */ |
| 60 | 60 | class HTTP_Session_Container_MDB2 extends HTTP_Session_Container |
| 61 | 61 | { |
| 62 | - /** |
|
| 63 | - * MDB2 connection object |
|
| 64 | - * |
|
| 65 | - * @var object MDB2 |
|
| 66 | - * @access private |
|
| 67 | - */ |
|
| 68 | - public $db = null; |
|
| 62 | + /** |
|
| 63 | + * MDB2 connection object |
|
| 64 | + * |
|
| 65 | + * @var object MDB2 |
|
| 66 | + * @access private |
|
| 67 | + */ |
|
| 68 | + public $db = null; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Session data cache id |
|
| 72 | - * |
|
| 73 | - * @var mixed |
|
| 74 | - * @access private |
|
| 75 | - */ |
|
| 76 | - public $crc = false; |
|
| 70 | + /** |
|
| 71 | + * Session data cache id |
|
| 72 | + * |
|
| 73 | + * @var mixed |
|
| 74 | + * @access private |
|
| 75 | + */ |
|
| 76 | + public $crc = false; |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Constructor method |
|
| 80 | - * |
|
| 81 | - * $options is an array with the options.<br> |
|
| 82 | - * The options are: |
|
| 83 | - * <ul> |
|
| 84 | - * <li>'dsn' - The DSN string</li> |
|
| 85 | - * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 86 | - * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 87 | - * the table on garbage collection, default is 'false'.</li> |
|
| 88 | - * </ul> |
|
| 89 | - * |
|
| 90 | - * @param array $options Options |
|
| 91 | - * |
|
| 92 | - * @access public |
|
| 93 | - * @return void |
|
| 94 | - */ |
|
| 95 | - public function HTTP_Session_Container_MDB2($options) |
|
| 96 | - { |
|
| 97 | - $this->_setDefaults(); |
|
| 98 | - if (is_array($options)) { |
|
| 99 | - $this->_parseOptions($options); |
|
| 100 | - } else { |
|
| 101 | - $this->options['dsn'] = $options; |
|
| 102 | - } |
|
| 103 | - } |
|
| 78 | + /** |
|
| 79 | + * Constructor method |
|
| 80 | + * |
|
| 81 | + * $options is an array with the options.<br> |
|
| 82 | + * The options are: |
|
| 83 | + * <ul> |
|
| 84 | + * <li>'dsn' - The DSN string</li> |
|
| 85 | + * <li>'table' - Table with session data, default is 'sessiondata'</li> |
|
| 86 | + * <li>'autooptimize' - Boolean, 'true' to optimize |
|
| 87 | + * the table on garbage collection, default is 'false'.</li> |
|
| 88 | + * </ul> |
|
| 89 | + * |
|
| 90 | + * @param array $options Options |
|
| 91 | + * |
|
| 92 | + * @access public |
|
| 93 | + * @return void |
|
| 94 | + */ |
|
| 95 | + public function HTTP_Session_Container_MDB2($options) |
|
| 96 | + { |
|
| 97 | + $this->_setDefaults(); |
|
| 98 | + if (is_array($options)) { |
|
| 99 | + $this->_parseOptions($options); |
|
| 100 | + } else { |
|
| 101 | + $this->options['dsn'] = $options; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Connect to database by using the given DSN string |
|
| 107 | - * |
|
| 108 | - * @param string $dsn DSN string |
|
| 109 | - * |
|
| 110 | - * @access private |
|
| 111 | - * @return mixed Object on error, otherwise bool |
|
| 112 | - */ |
|
| 113 | - public function _connect($dsn) |
|
| 114 | - { |
|
| 115 | - if (is_string($dsn) || is_array($dsn)) { |
|
| 116 | - $this->db = MDB2::connect($dsn); |
|
| 117 | - } else if (is_object($dsn) && is_a($dsn, 'MDB2_Driver_Common')) { |
|
| 118 | - $this->db = $dsn; |
|
| 119 | - } else if (is_object($dsn) && MDB2::isError($dsn)) { |
|
| 120 | - return $dsn; |
|
| 121 | - } else { |
|
| 122 | - return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 123 | - . " at line " . __LINE__, |
|
| 124 | - 41, |
|
| 125 | - PEAR_ERROR_RETURN, |
|
| 126 | - null, |
|
| 127 | - null |
|
| 128 | - ); |
|
| 105 | + /** |
|
| 106 | + * Connect to database by using the given DSN string |
|
| 107 | + * |
|
| 108 | + * @param string $dsn DSN string |
|
| 109 | + * |
|
| 110 | + * @access private |
|
| 111 | + * @return mixed Object on error, otherwise bool |
|
| 112 | + */ |
|
| 113 | + public function _connect($dsn) |
|
| 114 | + { |
|
| 115 | + if (is_string($dsn) || is_array($dsn)) { |
|
| 116 | + $this->db = MDB2::connect($dsn); |
|
| 117 | + } else if (is_object($dsn) && is_a($dsn, 'MDB2_Driver_Common')) { |
|
| 118 | + $this->db = $dsn; |
|
| 119 | + } else if (is_object($dsn) && MDB2::isError($dsn)) { |
|
| 120 | + return $dsn; |
|
| 121 | + } else { |
|
| 122 | + return new PEAR_Error("The given dsn was not valid in file " . __FILE__ |
|
| 123 | + . " at line " . __LINE__, |
|
| 124 | + 41, |
|
| 125 | + PEAR_ERROR_RETURN, |
|
| 126 | + null, |
|
| 127 | + null |
|
| 128 | + ); |
|
| 129 | 129 | |
| 130 | - } |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - if (MDB2::isError($this->db)) { |
|
| 133 | - return new MDB2_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 134 | - } |
|
| 132 | + if (MDB2::isError($this->db)) { |
|
| 133 | + return new MDB2_Error($this->db->code, PEAR_ERROR_DIE); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - return true; |
|
| 137 | - } |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Set some default options |
|
| 141 | - * |
|
| 142 | - * @access private |
|
| 143 | - * @return void |
|
| 144 | - */ |
|
| 145 | - public function _setDefaults() |
|
| 146 | - { |
|
| 147 | - $this->options['dsn'] = null; |
|
| 148 | - $this->options['table'] = 'sessiondata'; |
|
| 149 | - $this->options['autooptimize'] = false; |
|
| 150 | - } |
|
| 139 | + /** |
|
| 140 | + * Set some default options |
|
| 141 | + * |
|
| 142 | + * @access private |
|
| 143 | + * @return void |
|
| 144 | + */ |
|
| 145 | + public function _setDefaults() |
|
| 146 | + { |
|
| 147 | + $this->options['dsn'] = null; |
|
| 148 | + $this->options['table'] = 'sessiondata'; |
|
| 149 | + $this->options['autooptimize'] = false; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Establish connection to a database |
|
| 154 | - * |
|
| 155 | - * @param string $save_path Save path |
|
| 156 | - * @param string $session_name Session name |
|
| 157 | - * |
|
| 158 | - * @return bool |
|
| 159 | - */ |
|
| 160 | - public function open($save_path, $session_name) |
|
| 161 | - { |
|
| 162 | - if (MDB2::isError($this->_connect($this->options['dsn']))) { |
|
| 163 | - return false; |
|
| 164 | - } else { |
|
| 165 | - return true; |
|
| 166 | - } |
|
| 167 | - } |
|
| 152 | + /** |
|
| 153 | + * Establish connection to a database |
|
| 154 | + * |
|
| 155 | + * @param string $save_path Save path |
|
| 156 | + * @param string $session_name Session name |
|
| 157 | + * |
|
| 158 | + * @return bool |
|
| 159 | + */ |
|
| 160 | + public function open($save_path, $session_name) |
|
| 161 | + { |
|
| 162 | + if (MDB2::isError($this->_connect($this->options['dsn']))) { |
|
| 163 | + return false; |
|
| 164 | + } else { |
|
| 165 | + return true; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Free resources |
|
| 171 | - * |
|
| 172 | - * @return bool |
|
| 173 | - */ |
|
| 174 | - public function close() |
|
| 175 | - { |
|
| 176 | - return true; |
|
| 177 | - } |
|
| 169 | + /** |
|
| 170 | + * Free resources |
|
| 171 | + * |
|
| 172 | + * @return bool |
|
| 173 | + */ |
|
| 174 | + public function close() |
|
| 175 | + { |
|
| 176 | + return true; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * Read session data |
|
| 181 | - * |
|
| 182 | - * @param string $id Session id |
|
| 183 | - * |
|
| 184 | - * @return mixed |
|
| 185 | - */ |
|
| 186 | - public function read($id) |
|
| 187 | - { |
|
| 188 | - $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 189 | - $this->options['table'], |
|
| 190 | - $this->db->quote(md5($id), 'text'), |
|
| 191 | - time()); |
|
| 192 | - $result = $this->db->queryOne($query); |
|
| 193 | - if (MDB2::isError($result)) { |
|
| 194 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 195 | - return false; |
|
| 196 | - } |
|
| 197 | - $this->crc = strlen($result) . crc32($result); |
|
| 198 | - return $result; |
|
| 199 | - } |
|
| 179 | + /** |
|
| 180 | + * Read session data |
|
| 181 | + * |
|
| 182 | + * @param string $id Session id |
|
| 183 | + * |
|
| 184 | + * @return mixed |
|
| 185 | + */ |
|
| 186 | + public function read($id) |
|
| 187 | + { |
|
| 188 | + $query = sprintf("SELECT data FROM %s WHERE id = %s && expiry >= %d", |
|
| 189 | + $this->options['table'], |
|
| 190 | + $this->db->quote(md5($id), 'text'), |
|
| 191 | + time()); |
|
| 192 | + $result = $this->db->queryOne($query); |
|
| 193 | + if (MDB2::isError($result)) { |
|
| 194 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + $this->crc = strlen($result) . crc32($result); |
|
| 198 | + return $result; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Write session data |
|
| 203 | - * |
|
| 204 | - * @param string $id Session id |
|
| 205 | - * @param mixed $data Data |
|
| 206 | - * |
|
| 207 | - * @return bool |
|
| 208 | - */ |
|
| 209 | - public function write($id, $data) |
|
| 210 | - { |
|
| 211 | - if ((false !== $this->crc) && |
|
| 212 | - ($this->crc === strlen($data) . crc32($data))) { |
|
| 213 | - // $_SESSION hasn't been touched, no need to update the blob column |
|
| 214 | - $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 215 | - $this->options['table'], |
|
| 216 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 217 | - $this->db->quote(md5($id), 'text')); |
|
| 218 | - } else { |
|
| 219 | - // Check if table row already exists |
|
| 220 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 221 | - $this->options['table'], |
|
| 222 | - $this->db->quote(md5($id), 'text')); |
|
| 223 | - $result = $this->db->queryOne($query); |
|
| 224 | - if (MDB2::isError($result)) { |
|
| 225 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - if (0 == intval($result)) { |
|
| 229 | - // Insert new row into table |
|
| 230 | - $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 231 | - $this->options['table'], |
|
| 232 | - $this->db->quote(md5($id), 'text'), |
|
| 233 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 234 | - $this->db->quote($data, 'text')); |
|
| 235 | - } else { |
|
| 236 | - // Update existing row |
|
| 237 | - $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 238 | - $this->options['table'], |
|
| 239 | - time() + ini_get('session.gc_maxlifetime'), |
|
| 240 | - $this->db->quote($data, 'text'), |
|
| 241 | - $this->db->quote(md5($id), 'text')); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - $result = $this->db->query($query); |
|
| 245 | - if (MDB2::isError($result)) { |
|
| 246 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 247 | - return false; |
|
| 248 | - } |
|
| 201 | + /** |
|
| 202 | + * Write session data |
|
| 203 | + * |
|
| 204 | + * @param string $id Session id |
|
| 205 | + * @param mixed $data Data |
|
| 206 | + * |
|
| 207 | + * @return bool |
|
| 208 | + */ |
|
| 209 | + public function write($id, $data) |
|
| 210 | + { |
|
| 211 | + if ((false !== $this->crc) && |
|
| 212 | + ($this->crc === strlen($data) . crc32($data))) { |
|
| 213 | + // $_SESSION hasn't been touched, no need to update the blob column |
|
| 214 | + $query = sprintf("UPDATE %s SET expiry = %d WHERE id = %s", |
|
| 215 | + $this->options['table'], |
|
| 216 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 217 | + $this->db->quote(md5($id), 'text')); |
|
| 218 | + } else { |
|
| 219 | + // Check if table row already exists |
|
| 220 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 221 | + $this->options['table'], |
|
| 222 | + $this->db->quote(md5($id), 'text')); |
|
| 223 | + $result = $this->db->queryOne($query); |
|
| 224 | + if (MDB2::isError($result)) { |
|
| 225 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + if (0 == intval($result)) { |
|
| 229 | + // Insert new row into table |
|
| 230 | + $query = sprintf("INSERT INTO %s (id, expiry, data) VALUES (%s, %d, %s)", |
|
| 231 | + $this->options['table'], |
|
| 232 | + $this->db->quote(md5($id), 'text'), |
|
| 233 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 234 | + $this->db->quote($data, 'text')); |
|
| 235 | + } else { |
|
| 236 | + // Update existing row |
|
| 237 | + $query = sprintf("UPDATE %s SET expiry = %d, data = %s WHERE id = %s", |
|
| 238 | + $this->options['table'], |
|
| 239 | + time() + ini_get('session.gc_maxlifetime'), |
|
| 240 | + $this->db->quote($data, 'text'), |
|
| 241 | + $this->db->quote(md5($id), 'text')); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + $result = $this->db->query($query); |
|
| 245 | + if (MDB2::isError($result)) { |
|
| 246 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - return true; |
|
| 251 | - } |
|
| 250 | + return true; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Destroy session data |
|
| 255 | - * |
|
| 256 | - * @param string $id Session id |
|
| 257 | - * |
|
| 258 | - * @return bool |
|
| 259 | - */ |
|
| 260 | - public function destroy($id) |
|
| 261 | - { |
|
| 262 | - $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 263 | - $this->options['table'], |
|
| 264 | - $this->db->quote(md5($id), 'text')); |
|
| 265 | - $result = $this->db->query($query); |
|
| 266 | - if (MDB2::isError($result)) { |
|
| 267 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 268 | - return false; |
|
| 269 | - } |
|
| 253 | + /** |
|
| 254 | + * Destroy session data |
|
| 255 | + * |
|
| 256 | + * @param string $id Session id |
|
| 257 | + * |
|
| 258 | + * @return bool |
|
| 259 | + */ |
|
| 260 | + public function destroy($id) |
|
| 261 | + { |
|
| 262 | + $query = sprintf("DELETE FROM %s WHERE id = %s", |
|
| 263 | + $this->options['table'], |
|
| 264 | + $this->db->quote(md5($id), 'text')); |
|
| 265 | + $result = $this->db->query($query); |
|
| 266 | + if (MDB2::isError($result)) { |
|
| 267 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 268 | + return false; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - return true; |
|
| 272 | - } |
|
| 271 | + return true; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 276 | - * |
|
| 277 | - * @param string $targetTable Table to replicate to |
|
| 278 | - * @param string $id Id of record to replicate |
|
| 279 | - * |
|
| 280 | - * @access private |
|
| 281 | - * @return bool |
|
| 282 | - */ |
|
| 283 | - public function replicate($targetTable, $id = null) |
|
| 284 | - { |
|
| 285 | - if (is_null($id)) { |
|
| 286 | - $id = HTTP_Session::id(); |
|
| 287 | - } |
|
| 274 | + /** |
|
| 275 | + * Replicate session data to table specified in option 'replicateBeforeDestroy' |
|
| 276 | + * |
|
| 277 | + * @param string $targetTable Table to replicate to |
|
| 278 | + * @param string $id Id of record to replicate |
|
| 279 | + * |
|
| 280 | + * @access private |
|
| 281 | + * @return bool |
|
| 282 | + */ |
|
| 283 | + public function replicate($targetTable, $id = null) |
|
| 284 | + { |
|
| 285 | + if (is_null($id)) { |
|
| 286 | + $id = HTTP_Session::id(); |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - // Check if table row already exists |
|
| 290 | - $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 291 | - $targetTable, |
|
| 292 | - $this->db->quote(md5($id), 'text')); |
|
| 293 | - $result = $this->db->queryOne($query); |
|
| 294 | - if (MDB2::isError($result)) { |
|
| 295 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 296 | - return false; |
|
| 297 | - } |
|
| 289 | + // Check if table row already exists |
|
| 290 | + $query = sprintf("SELECT COUNT(id) FROM %s WHERE id = %s", |
|
| 291 | + $targetTable, |
|
| 292 | + $this->db->quote(md5($id), 'text')); |
|
| 293 | + $result = $this->db->queryOne($query); |
|
| 294 | + if (MDB2::isError($result)) { |
|
| 295 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 296 | + return false; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - // Insert new row into dest table |
|
| 300 | - if (0 == intval($result)) { |
|
| 301 | - $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 302 | - $targetTable, |
|
| 303 | - $this->options['table'], |
|
| 304 | - $this->db->quote(md5($id), 'text')); |
|
| 299 | + // Insert new row into dest table |
|
| 300 | + if (0 == intval($result)) { |
|
| 301 | + $query = sprintf("INSERT INTO %s SELECT * FROM %s WHERE id = %s", |
|
| 302 | + $targetTable, |
|
| 303 | + $this->options['table'], |
|
| 304 | + $this->db->quote(md5($id), 'text')); |
|
| 305 | 305 | |
| 306 | - } else { |
|
| 307 | - // Update existing row |
|
| 308 | - $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | - $targetTable, |
|
| 310 | - $this->options['table'], |
|
| 311 | - $this->db->quote(md5($id), 'text')); |
|
| 312 | - } |
|
| 306 | + } else { |
|
| 307 | + // Update existing row |
|
| 308 | + $query = sprintf("UPDATE %s dst, %s src SET dst.expiry = src.expiry, dst.data = src.data WHERE dst.id = src.id && src.id = %s", |
|
| 309 | + $targetTable, |
|
| 310 | + $this->options['table'], |
|
| 311 | + $this->db->quote(md5($id), 'text')); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - $result = $this->db->query($query); |
|
| 315 | - if (MDB2::isError($result)) { |
|
| 316 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 317 | - return false; |
|
| 318 | - } |
|
| 314 | + $result = $this->db->query($query); |
|
| 315 | + if (MDB2::isError($result)) { |
|
| 316 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 317 | + return false; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - return true; |
|
| 321 | - } |
|
| 320 | + return true; |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - /** |
|
| 324 | - * Garbage collection |
|
| 325 | - * |
|
| 326 | - * @param int $maxlifetime Maximum lifetime |
|
| 327 | - * |
|
| 328 | - * @return bool |
|
| 329 | - */ |
|
| 330 | - public function gc($maxlifetime) |
|
| 331 | - { |
|
| 332 | - $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | - $this->options['table'], |
|
| 334 | - time()); |
|
| 335 | - $result = $this->db->query($query); |
|
| 336 | - if (MDB2::isError($result)) { |
|
| 337 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 338 | - return false; |
|
| 339 | - } |
|
| 340 | - if ($this->options['autooptimize']) { |
|
| 341 | - switch($this->db->phptype) { |
|
| 342 | - case 'mysql': |
|
| 343 | - $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | - break; |
|
| 345 | - case 'pgsql': |
|
| 346 | - $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | - break; |
|
| 348 | - default: |
|
| 349 | - $query = null; |
|
| 350 | - break; |
|
| 351 | - } |
|
| 352 | - if (isset($query)) { |
|
| 353 | - $result = $this->db->query($query); |
|
| 354 | - if (MDB2::isError($result)) { |
|
| 355 | - $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - } |
|
| 323 | + /** |
|
| 324 | + * Garbage collection |
|
| 325 | + * |
|
| 326 | + * @param int $maxlifetime Maximum lifetime |
|
| 327 | + * |
|
| 328 | + * @return bool |
|
| 329 | + */ |
|
| 330 | + public function gc($maxlifetime) |
|
| 331 | + { |
|
| 332 | + $query = sprintf("DELETE FROM %s WHERE expiry < %d", |
|
| 333 | + $this->options['table'], |
|
| 334 | + time()); |
|
| 335 | + $result = $this->db->query($query); |
|
| 336 | + if (MDB2::isError($result)) { |
|
| 337 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 338 | + return false; |
|
| 339 | + } |
|
| 340 | + if ($this->options['autooptimize']) { |
|
| 341 | + switch($this->db->phptype) { |
|
| 342 | + case 'mysql': |
|
| 343 | + $query = sprintf("OPTIMIZE TABLE %s", $this->options['table']); |
|
| 344 | + break; |
|
| 345 | + case 'pgsql': |
|
| 346 | + $query = sprintf("VACUUM %s", $this->options['table']); |
|
| 347 | + break; |
|
| 348 | + default: |
|
| 349 | + $query = null; |
|
| 350 | + break; |
|
| 351 | + } |
|
| 352 | + if (isset($query)) { |
|
| 353 | + $result = $this->db->query($query); |
|
| 354 | + if (MDB2::isError($result)) { |
|
| 355 | + $this->db->raiseError($result->code, PEAR_ERROR_DIE); |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - return true; |
|
| 362 | - } |
|
| 361 | + return true; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | ?> |
| 365 | 365 | \ No newline at end of file |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @access private |
| 66 | 66 | * @param string Whether to prevent multiple vtiger_users from tagging the same object. By default, set to block (ala Upcoming.org) |
| 67 | 67 | */ |
| 68 | - public $_block_multiuser_tag_on_object =0; |
|
| 68 | + public $_block_multiuser_tag_on_object = 0; |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * @access private |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * @return An array of Object ID numbers that reference your original objects. |
| 152 | 152 | */ |
| 153 | 153 | public function get_objects_with_tag($tag, $offset = 0, $limit = 100, $tagger_id = NULL) { |
| 154 | - if(!isset($tag)) { |
|
| 154 | + if (!isset($tag)) { |
|
| 155 | 155 | return false; |
| 156 | 156 | } |
| 157 | 157 | $adb = PearDatabase::getInstance(); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $where = "tag = ? "; |
| 160 | 160 | $params = array($tag); |
| 161 | 161 | |
| 162 | - if(isset($tagger_id) && ($tagger_id > 0)) { |
|
| 162 | + if (isset($tagger_id) && ($tagger_id > 0)) { |
|
| 163 | 163 | $where .= "AND tagger_id = ? "; |
| 164 | 164 | array_push($params, $tagger_id); |
| 165 | 165 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * @return An array of Object ID numbers that reference your original objects. |
| 198 | 198 | */ |
| 199 | 199 | public function get_objects_with_tag_all($tag, $tagger_id = NULL) { |
| 200 | - if(!isset($tag)) { |
|
| 200 | + if (!isset($tag)) { |
|
| 201 | 201 | return false; |
| 202 | 202 | } |
| 203 | 203 | $adb = PearDatabase::getInstance(); |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $where = "tag = ? "; |
| 206 | 206 | $params = array($tag); |
| 207 | 207 | |
| 208 | - if(isset($tagger_id) && ($tagger_id > 0)) { |
|
| 208 | + if (isset($tagger_id) && ($tagger_id > 0)) { |
|
| 209 | 209 | $where .= "AND tagger_id = ? "; |
| 210 | 210 | array_push($params, $tagger_id); |
| 211 | 211 | } |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | return $retarr; |
| 250 | 250 | } |
| 251 | 251 | $params = array($tagArray); |
| 252 | - if(isset($tagger_id) && ($tagger_id > 0)) { |
|
| 252 | + if (isset($tagger_id) && ($tagger_id > 0)) { |
|
| 253 | 253 | $tagger_sql = "AND tagger_id = ?"; |
| 254 | 254 | array_push($params, $tagger_id); |
| 255 | 255 | } else { |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $sql = "SELECT ${prefix}freetagged_objects.object_id, tag, COUNT(DISTINCT tag) AS uniques |
| 271 | 271 | FROM ${prefix}freetagged_objects |
| 272 | 272 | INNER JOIN ${prefix}freetags ON (${prefix}freetagged_objects.tag_id = ${prefix}freetags.id) |
| 273 | - WHERE ${prefix}freetags.tag IN (". generateQuestionMarks($tagArray) .") |
|
| 273 | + WHERE ${prefix}freetags.tag IN (" . generateQuestionMarks($tagArray) . ") |
|
| 274 | 274 | $tagger_sql |
| 275 | 275 | GROUP BY ${prefix}freetagged_objects.object_id |
| 276 | 276 | HAVING uniques = $numTags |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * @return An array of Object ID numbers that reference your original objects. |
| 301 | 301 | */ |
| 302 | 302 | public function get_objects_with_tag_id($tag_id, $offset = 0, $limit = 100, $tagger_id = NULL) { |
| 303 | - if(!isset($tag_id)) { |
|
| 303 | + if (!isset($tag_id)) { |
|
| 304 | 304 | return false; |
| 305 | 305 | } |
| 306 | 306 | $adb = PearDatabase::getInstance(); |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | $where = "id = ? "; |
| 309 | 309 | $params = array($tag_id); |
| 310 | 310 | |
| 311 | - if(isset($tagger_id) && ($tagger_id > 0)) { |
|
| 311 | + if (isset($tagger_id) && ($tagger_id > 0)) { |
|
| 312 | 312 | $where .= "AND tagger_id = ?"; |
| 313 | 313 | array_push($params, $tagger_id); |
| 314 | 314 | } |
@@ -349,19 +349,19 @@ discard block |
||
| 349 | 349 | * - 'tagger_id' => The unique ID of the person who tagged the object with this tag. |
| 350 | 350 | */ |
| 351 | 351 | public function get_tags_on_object($object_id, $offset = 0, $limit = 10, $tagger_id = NULL) { |
| 352 | - if(!isset($object_id)) { |
|
| 352 | + if (!isset($object_id)) { |
|
| 353 | 353 | return false; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | $where = "object_id = ? "; |
| 357 | 357 | $params = array($object_id); |
| 358 | 358 | |
| 359 | - if(isset($tagger_id) && ($tagger_id > 0)) { |
|
| 359 | + if (isset($tagger_id) && ($tagger_id > 0)) { |
|
| 360 | 360 | $where .= "AND tagger_id = ? "; |
| 361 | 361 | array_push($params, $tagger_id); |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - if($limit <= 0) { |
|
| 364 | + if ($limit <= 0) { |
|
| 365 | 365 | $limit_sql = ""; |
| 366 | 366 | } else { |
| 367 | 367 | $limit_sql = "LIMIT $offset, $limit"; |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | */ |
| 407 | 407 | |
| 408 | 408 | public function safe_tag($tagger_id, $object_id, $tag, $module) { |
| 409 | - if(!isset($tagger_id)||!isset($object_id)||!isset($tag)) { |
|
| 409 | + if (!isset($tagger_id) || !isset($object_id) || !isset($tag)) { |
|
| 410 | 410 | die("safe_tag argument missing"); |
| 411 | 411 | return false; |
| 412 | 412 | } |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | |
| 434 | 434 | array_push($params, $object_id, $normalized_tag); |
| 435 | 435 | $rs = $adb->pquery($sql, $params); |
| 436 | - if($rs->fields['count'] > 0) { |
|
| 436 | + if ($rs->fields['count'] > 0) { |
|
| 437 | 437 | return true; |
| 438 | 438 | } |
| 439 | 439 | // Then see if a raw tag in this form exists. |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | WHERE raw_tag = ? "; |
| 443 | 443 | $rs = $adb->pquery($sql, array($tag)); |
| 444 | 444 | $row = $adb->fetch_array($rs); |
| 445 | - if($row) { |
|
| 445 | + if ($row) { |
|
| 446 | 446 | $tag_id = $row['id']; |
| 447 | 447 | } else { |
| 448 | 448 | // Add new tag! |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | $rs = $adb->pquery($sql, $params); |
| 453 | 453 | |
| 454 | 454 | } |
| 455 | - if(!($tag_id > 0)) { |
|
| 455 | + if (!($tag_id > 0)) { |
|
| 456 | 456 | return false; |
| 457 | 457 | } |
| 458 | 458 | $sql = "INSERT INTO ${prefix}freetagged_objects |
@@ -509,14 +509,14 @@ discard block |
||
| 509 | 509 | * @return string Returns the tag in normalized form. |
| 510 | 510 | */ |
| 511 | 511 | public function delete_object_tag($tagger_id, $object_id, $tag) { |
| 512 | - if(!isset($tagger_id)||!isset($object_id)||!isset($tag)) { |
|
| 512 | + if (!isset($tagger_id) || !isset($object_id) || !isset($tag)) { |
|
| 513 | 513 | die("delete_object_tag argument missing"); |
| 514 | 514 | return false; |
| 515 | 515 | } |
| 516 | 516 | $adb = PearDatabase::getInstance(); |
| 517 | 517 | $tag_id = $this->get_raw_tag_id($tag); |
| 518 | 518 | $prefix = $this->_table_prefix; |
| 519 | - if($tag_id > 0) { |
|
| 519 | + if ($tag_id > 0) { |
|
| 520 | 520 | |
| 521 | 521 | $sql = "DELETE FROM ${prefix}freetagged_objects |
| 522 | 522 | WHERE tagger_id = ? && object_id = ? && tag_id = ? LIMIT 1"; |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | public function delete_all_object_tags($object_id) { |
| 544 | 544 | $adb = PearDatabase::getInstance(); |
| 545 | 545 | $prefix = $this->_table_prefix; |
| 546 | - if($object_id > 0) { |
|
| 546 | + if ($object_id > 0) { |
|
| 547 | 547 | $sql = "DELETE FROM ${prefix}freetagged_objects |
| 548 | 548 | WHERE object_id = ? "; |
| 549 | 549 | $rs = $adb->pquery($sql, array($object_id)); |
@@ -570,13 +570,13 @@ discard block |
||
| 570 | 570 | */ |
| 571 | 571 | |
| 572 | 572 | public function delete_all_object_tags_for_user($tagger_id, $object_id) { |
| 573 | - if(!isset($tagger_id)||!isset($object_id)) { |
|
| 573 | + if (!isset($tagger_id) || !isset($object_id)) { |
|
| 574 | 574 | die("delete_all_object_tags_for_user argument missing"); |
| 575 | 575 | return false; |
| 576 | 576 | } |
| 577 | 577 | $adb = PearDatabase::getInstance(); |
| 578 | 578 | $prefix = $this->_table_prefix; |
| 579 | - if($object_id > 0) { |
|
| 579 | + if ($object_id > 0) { |
|
| 580 | 580 | |
| 581 | 581 | $sql = "DELETE FROM ${prefix}freetagged_objects |
| 582 | 582 | WHERE tagger_id = ? && object_id = ?"; |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | * @return string Returns the tag in normalized form. |
| 601 | 601 | */ |
| 602 | 602 | public function get_tag_id($tag) { |
| 603 | - if(!isset($tag)) { |
|
| 603 | + if (!isset($tag)) { |
|
| 604 | 604 | die("get_tag_id argument missing"); |
| 605 | 605 | return false; |
| 606 | 606 | } |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | */ |
| 629 | 629 | |
| 630 | 630 | public function get_raw_tag_id($tag) { |
| 631 | - if(!isset($tag)) { |
|
| 631 | + if (!isset($tag)) { |
|
| 632 | 632 | die("get_tag_id argument missing"); |
| 633 | 633 | return false; |
| 634 | 634 | } |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | * @return string Returns the tag in normalized form. |
| 662 | 662 | */ |
| 663 | 663 | public function tag_object($tagger_id, $object_id, $tag_string, $module, $skip_updates = 1) { |
| 664 | - if($tag_string == '') { |
|
| 664 | + if ($tag_string == '') { |
|
| 665 | 665 | // If an empty string was passed, just return true, don't die. |
| 666 | 666 | // die("Empty tag string passed"); |
| 667 | 667 | return true; |
@@ -702,10 +702,10 @@ discard block |
||
| 702 | 702 | * @return boolean True if successful, false otherwise. |
| 703 | 703 | */ |
| 704 | 704 | public function _tag_object_array($tagger_id, $object_id, $tagArray, $module) { |
| 705 | - foreach($tagArray as $tag) { |
|
| 705 | + foreach ($tagArray as $tag) { |
|
| 706 | 706 | $tag = trim($tag); |
| 707 | - if(($tag != '') && (strlen($tag) <= $this->_MAX_TAG_LENGTH)) { |
|
| 708 | - if(get_magic_quotes_gpc()) { |
|
| 707 | + if (($tag != '') && (strlen($tag) <= $this->_MAX_TAG_LENGTH)) { |
|
| 708 | + if (get_magic_quotes_gpc()) { |
|
| 709 | 709 | $tag = addslashes($tag); |
| 710 | 710 | } |
| 711 | 711 | $this->safe_tag($tagger_id, $object_id, $tag, $module); |
@@ -731,12 +731,12 @@ discard block |
||
| 731 | 731 | return $newwords; |
| 732 | 732 | } |
| 733 | 733 | # Perform tag parsing |
| 734 | - if(get_magic_quotes_gpc()) { |
|
| 734 | + if (get_magic_quotes_gpc()) { |
|
| 735 | 735 | $query = stripslashes(trim($tag_string)); |
| 736 | 736 | } else { |
| 737 | 737 | $query = trim($tag_string); |
| 738 | 738 | } |
| 739 | - $words = preg_split('/(")/', $query,-1,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); |
|
| 739 | + $words = preg_split('/(")/', $query, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); |
|
| 740 | 740 | $delim = 0; |
| 741 | 741 | foreach ($words as $key => $word) |
| 742 | 742 | { |
@@ -782,7 +782,7 @@ discard block |
||
| 782 | 782 | public function get_most_popular_tags($tagger_id = NULL, $offset = 0, $limit = 25) { |
| 783 | 783 | $adb = PearDatabase::getInstance(); |
| 784 | 784 | $params = array(); |
| 785 | - if(isset($tagger_id) && ($tagger_id > 0)) { |
|
| 785 | + if (isset($tagger_id) && ($tagger_id > 0)) { |
|
| 786 | 786 | $tagger_sql = "AND tagger_id = ?"; |
| 787 | 787 | array_push($params, $tagger_id); |
| 788 | 788 | } else { |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | public function count_tags($tagger_id = NULL) { |
| 827 | 827 | $adb = PearDatabase::getInstance(); |
| 828 | 828 | $params = array(); |
| 829 | - if(isset($tagger_id) && ($tagger_id > 0)) { |
|
| 829 | + if (isset($tagger_id) && ($tagger_id > 0)) { |
|
| 830 | 830 | $tagger_sql = "AND tagger_id = ?"; |
| 831 | 831 | array_push($params, $tagger_id); |
| 832 | 832 | } else { |
@@ -870,11 +870,11 @@ discard block |
||
| 870 | 870 | * @return string Returns an HTML snippet that can be used directly as a tag cloud. |
| 871 | 871 | */ |
| 872 | 872 | |
| 873 | - public function get_tag_cloud_html($module="",$tagger_id = NULL,$obj_id= NULL,$num_tags = 100, $min_font_size = 10, $max_font_size = 20, $font_units = 'px', $span_class = '', $tag_page_url = '/tag/') { |
|
| 873 | + public function get_tag_cloud_html($module = "", $tagger_id = NULL, $obj_id = NULL, $num_tags = 100, $min_font_size = 10, $max_font_size = 20, $font_units = 'px', $span_class = '', $tag_page_url = '/tag/') { |
|
| 874 | 874 | global $theme; |
| 875 | - $theme_path="themes/".$theme."/"; |
|
| 876 | - $image_path=$theme_path."images/"; |
|
| 877 | - $tag_list = $this->get_tag_cloud_tags($num_tags, $tagger_id,$module,$obj_id); |
|
| 875 | + $theme_path = "themes/" . $theme . "/"; |
|
| 876 | + $image_path = $theme_path . "images/"; |
|
| 877 | + $tag_list = $this->get_tag_cloud_tags($num_tags, $tagger_id, $module, $obj_id); |
|
| 878 | 878 | if (count($tag_list[0])) { |
| 879 | 879 | // Get the maximum qty of tagged objects in the set |
| 880 | 880 | $max_qty = max(array_values($tag_list[0])); |
@@ -890,7 +890,7 @@ discard block |
||
| 890 | 890 | if (0 == $spread) { // Divide by zero |
| 891 | 891 | $spread = 1; |
| 892 | 892 | } |
| 893 | - $step = ($max_font_size - $min_font_size)/($spread); |
|
| 893 | + $step = ($max_font_size - $min_font_size) / ($spread); |
|
| 894 | 894 | |
| 895 | 895 | // Since the original tag_list is alphabetically ordered, |
| 896 | 896 | // we can now create the tag cloud by just putting a span |
@@ -898,18 +898,18 @@ discard block |
||
| 898 | 898 | // by $step. |
| 899 | 899 | $cloud_html = ''; |
| 900 | 900 | $cloud_spans = array(); |
| 901 | - if($module =='') |
|
| 901 | + if ($module == '') |
|
| 902 | 902 | $module = 'All'; |
| 903 | - if($module != 'All') { |
|
| 903 | + if ($module != 'All') { |
|
| 904 | 904 | foreach ($tag_list[0] as $tag => $qty) { |
| 905 | 905 | $size = $min_font_size + ($qty - $min_qty) * $step; |
| 906 | - $cloud_span[] = '<span id="tag_'.$tag_list[1][$tag].'" class="' . $span_class . '" onMouseOver=$("tagspan_'.$tag_list[1][$tag].'").style.display="inline"; onMouseOut=$("tagspan_'.$tag_list[1][$tag].'").style.display="none";><a class="tagit" href="index.php?module=Home&action=UnifiedSearch&search_module='.$module.'&search_tag=tag_search&query_string='. urlencode($tag) . '" style="font-size: '. $size . $font_units . '">' . htmlspecialchars(stripslashes($tag)) . '</a><span class="'. $span_class .'" id="tagspan_'.$tag_list[1][$tag].'" style="display:none;cursor:pointer;" onClick="DeleteTag('.$tag_list[1][$tag].','.$obj_id.');"><img src="' . vtiger_imageurl('del_tag.gif', $theme) . '"></span></span>'; |
|
| 906 | + $cloud_span[] = '<span id="tag_' . $tag_list[1][$tag] . '" class="' . $span_class . '" onMouseOver=$("tagspan_' . $tag_list[1][$tag] . '").style.display="inline"; onMouseOut=$("tagspan_' . $tag_list[1][$tag] . '").style.display="none";><a class="tagit" href="index.php?module=Home&action=UnifiedSearch&search_module=' . $module . '&search_tag=tag_search&query_string=' . urlencode($tag) . '" style="font-size: ' . $size . $font_units . '">' . htmlspecialchars(stripslashes($tag)) . '</a><span class="' . $span_class . '" id="tagspan_' . $tag_list[1][$tag] . '" style="display:none;cursor:pointer;" onClick="DeleteTag(' . $tag_list[1][$tag] . ',' . $obj_id . ');"><img src="' . vtiger_imageurl('del_tag.gif', $theme) . '"></span></span>'; |
|
| 907 | 907 | |
| 908 | 908 | } |
| 909 | 909 | } else { |
| 910 | - foreach($tag_list[0] as $tag => $qty) { |
|
| 910 | + foreach ($tag_list[0] as $tag => $qty) { |
|
| 911 | 911 | $size = $min_font_size + ($qty - $min_qty) * $step; |
| 912 | - $cloud_span[] = '<span class="' . $span_class . '"><a class="tagit" href="index.php?module=Home&action=UnifiedSearch&search_module='.$module.'&search_tag=tag_search&query_string='. urlencode($tag) . '" style="font-size: '. $size . $font_units . '">' . htmlspecialchars(stripslashes($tag)) . '</a></span>'; |
|
| 912 | + $cloud_span[] = '<span class="' . $span_class . '"><a class="tagit" href="index.php?module=Home&action=UnifiedSearch&search_module=' . $module . '&search_tag=tag_search&query_string=' . urlencode($tag) . '" style="font-size: ' . $size . $font_units . '">' . htmlspecialchars(stripslashes($tag)) . '</a></span>'; |
|
| 913 | 913 | } |
| 914 | 914 | } |
| 915 | 915 | $cloud_html = join("\n ", $cloud_span); |
@@ -934,24 +934,24 @@ discard block |
||
| 934 | 934 | * values are numeric quantity of objects tagged with that tag. |
| 935 | 935 | */ |
| 936 | 936 | |
| 937 | - public function get_tag_cloud_tags($max = 100, $tagger_id = NULL,$module = "",$obj_id = NULL) { |
|
| 937 | + public function get_tag_cloud_tags($max = 100, $tagger_id = NULL, $module = "", $obj_id = NULL) { |
|
| 938 | 938 | $adb = PearDatabase::getInstance(); |
| 939 | 939 | $params = array(); |
| 940 | - if(isset($tagger_id) && ($tagger_id > 0)) { |
|
| 940 | + if (isset($tagger_id) && ($tagger_id > 0)) { |
|
| 941 | 941 | $tagger_sql = " && tagger_id = ?"; |
| 942 | 942 | array_push($params, $tagger_id); |
| 943 | 943 | } else { |
| 944 | 944 | $tagger_sql = ""; |
| 945 | 945 | } |
| 946 | 946 | |
| 947 | - if($module != "") { |
|
| 947 | + if ($module != "") { |
|
| 948 | 948 | $tagger_sql .= " && module = ?"; |
| 949 | 949 | array_push($params, $module); |
| 950 | 950 | } else { |
| 951 | 951 | $tagger_sql .= ""; |
| 952 | 952 | } |
| 953 | 953 | |
| 954 | - if(isset($obj_id) && $obj_id > 0) { |
|
| 954 | + if (isset($obj_id) && $obj_id > 0) { |
|
| 955 | 955 | $tagger_sql .= " && object_id = ?"; |
| 956 | 956 | array_push($params, $obj_id); |
| 957 | 957 | } else { |
@@ -974,10 +974,10 @@ discard block |
||
| 974 | 974 | $retarr[$row['tag']] = $row['quantity']; |
| 975 | 975 | $retarr1[$row['tag']] = $row['tag_id']; |
| 976 | 976 | } |
| 977 | - if($retarr) ksort($retarr); |
|
| 978 | - if($retarr1) ksort($retarr1); |
|
| 979 | - $return_value[]=$retarr; |
|
| 980 | - $return_value[]=$retarr1; |
|
| 977 | + if ($retarr) ksort($retarr); |
|
| 978 | + if ($retarr1) ksort($retarr1); |
|
| 979 | + $return_value[] = $retarr; |
|
| 980 | + $return_value[] = $retarr1; |
|
| 981 | 981 | return $return_value; |
| 982 | 982 | |
| 983 | 983 | } |
@@ -1010,7 +1010,7 @@ discard block |
||
| 1010 | 1010 | |
| 1011 | 1011 | public function similar_tags($tag, $max = 100) { |
| 1012 | 1012 | $retarr = array(); |
| 1013 | - if(!isset($tag)) { |
|
| 1013 | + if (!isset($tag)) { |
|
| 1014 | 1014 | return $retarr; |
| 1015 | 1015 | } |
| 1016 | 1016 | $adb = PearDatabase::getInstance(); |
@@ -1099,7 +1099,7 @@ discard block |
||
| 1099 | 1099 | $sql = "SELECT matches.object_id, COUNT( matches.object_id ) AS num_common_tags |
| 1100 | 1100 | FROM ${prefix}freetagged_objects as matches |
| 1101 | 1101 | INNER JOIN ${prefix}freetags as tags ON ( tags.id = matches.tag_id ) |
| 1102 | - WHERE tags.tag IN (". generateQuestionMarks($tagArray) .") |
|
| 1102 | + WHERE tags.tag IN (" . generateQuestionMarks($tagArray) . ") |
|
| 1103 | 1103 | GROUP BY matches.object_id |
| 1104 | 1104 | HAVING num_common_tags >= ? |
| 1105 | 1105 | ORDER BY num_common_tags DESC |
@@ -1107,7 +1107,7 @@ discard block |
||
| 1107 | 1107 | |
| 1108 | 1108 | $rs = $adb->pquery($sql, array($tagArray, $threshold, $max_objects)); |
| 1109 | 1109 | while ($row = $adb->fetch_array($rs)) { |
| 1110 | - $retarr[] = array ( |
|
| 1110 | + $retarr[] = array( |
|
| 1111 | 1111 | 'object_id' => $row['object_id'], |
| 1112 | 1112 | 'strength' => ($row['num_common_tags'] / $numTags) |
| 1113 | 1113 | ); |
@@ -23,17 +23,17 @@ discard block |
||
| 23 | 23 | if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); |
| 24 | 24 | |
| 25 | 25 | if (!defined('LOG4PHP_LINE_SEP')) { |
| 26 | - if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 27 | - /** |
|
| 28 | - * @ignore |
|
| 29 | - */ |
|
| 30 | - define('LOG4PHP_LINE_SEP', "\r\n"); |
|
| 31 | - } else { |
|
| 32 | - /** |
|
| 33 | - * @ignore |
|
| 34 | - */ |
|
| 35 | - define('LOG4PHP_LINE_SEP', "\n"); |
|
| 36 | - } |
|
| 26 | + if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 27 | + /** |
|
| 28 | + * @ignore |
|
| 29 | + */ |
|
| 30 | + define('LOG4PHP_LINE_SEP', "\r\n"); |
|
| 31 | + } else { |
|
| 32 | + /** |
|
| 33 | + * @ignore |
|
| 34 | + */ |
|
| 35 | + define('LOG4PHP_LINE_SEP', "\n"); |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -53,204 +53,204 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | class LoggerLayoutHtml extends LoggerLayout { |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 58 | - * default, it is set to false which means there will be no location |
|
| 59 | - * information output by this layout. If the the option is set to |
|
| 60 | - * true, then the file name and line number of the statement |
|
| 61 | - * at the origin of the log statement will be output. |
|
| 62 | - * |
|
| 63 | - * <p>If you are embedding this layout within a {@link LoggerAppenderMail} |
|
| 64 | - * or a {@link LoggerAppenderMailEvent} then make sure to set the |
|
| 65 | - * <b>LocationInfo</b> option of that appender as well. |
|
| 66 | - * @var boolean |
|
| 67 | - */ |
|
| 68 | - public $locationInfo = false; |
|
| 56 | + /** |
|
| 57 | + * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 58 | + * default, it is set to false which means there will be no location |
|
| 59 | + * information output by this layout. If the the option is set to |
|
| 60 | + * true, then the file name and line number of the statement |
|
| 61 | + * at the origin of the log statement will be output. |
|
| 62 | + * |
|
| 63 | + * <p>If you are embedding this layout within a {@link LoggerAppenderMail} |
|
| 64 | + * or a {@link LoggerAppenderMailEvent} then make sure to set the |
|
| 65 | + * <b>LocationInfo</b> option of that appender as well. |
|
| 66 | + * @var boolean |
|
| 67 | + */ |
|
| 68 | + public $locationInfo = false; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * The <b>Title</b> option takes a String value. This option sets the |
|
| 72 | - * document title of the generated HTML document. |
|
| 73 | - * Defaults to 'Log4php Log Messages'. |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $title = "Log4php Log Messages"; |
|
| 70 | + /** |
|
| 71 | + * The <b>Title</b> option takes a String value. This option sets the |
|
| 72 | + * document title of the generated HTML document. |
|
| 73 | + * Defaults to 'Log4php Log Messages'. |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $title = "Log4php Log Messages"; |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Constructor |
|
| 80 | - */ |
|
| 81 | - public function LoggerLayoutHtml() |
|
| 82 | - { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 78 | + /** |
|
| 79 | + * Constructor |
|
| 80 | + */ |
|
| 81 | + public function LoggerLayoutHtml() |
|
| 82 | + { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 88 | - * default, it is set to false which means there will be no location |
|
| 89 | - * information output by this layout. If the the option is set to |
|
| 90 | - * true, then the file name and line number of the statement |
|
| 91 | - * at the origin of the log statement will be output. |
|
| 92 | - * |
|
| 93 | - * <p>If you are embedding this layout within a {@link LoggerAppenderMail} |
|
| 94 | - * or a {@link LoggerAppenderMailEvent} then make sure to set the |
|
| 95 | - * <b>LocationInfo</b> option of that appender as well. |
|
| 96 | - */ |
|
| 97 | - public function setLocationInfo($flag) |
|
| 98 | - { |
|
| 99 | - if (is_bool($flag)) { |
|
| 100 | - $this->locationInfo = $flag; |
|
| 101 | - } else { |
|
| 102 | - $this->locationInfo = (bool)(strtolower($flag) == 'true'); |
|
| 103 | - } |
|
| 104 | - } |
|
| 86 | + /** |
|
| 87 | + * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 88 | + * default, it is set to false which means there will be no location |
|
| 89 | + * information output by this layout. If the the option is set to |
|
| 90 | + * true, then the file name and line number of the statement |
|
| 91 | + * at the origin of the log statement will be output. |
|
| 92 | + * |
|
| 93 | + * <p>If you are embedding this layout within a {@link LoggerAppenderMail} |
|
| 94 | + * or a {@link LoggerAppenderMailEvent} then make sure to set the |
|
| 95 | + * <b>LocationInfo</b> option of that appender as well. |
|
| 96 | + */ |
|
| 97 | + public function setLocationInfo($flag) |
|
| 98 | + { |
|
| 99 | + if (is_bool($flag)) { |
|
| 100 | + $this->locationInfo = $flag; |
|
| 101 | + } else { |
|
| 102 | + $this->locationInfo = (bool)(strtolower($flag) == 'true'); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Returns the current value of the <b>LocationInfo</b> option. |
|
| 108 | - */ |
|
| 109 | - public function getLocationInfo() |
|
| 110 | - { |
|
| 111 | - return $this->locationInfo; |
|
| 112 | - } |
|
| 106 | + /** |
|
| 107 | + * Returns the current value of the <b>LocationInfo</b> option. |
|
| 108 | + */ |
|
| 109 | + public function getLocationInfo() |
|
| 110 | + { |
|
| 111 | + return $this->locationInfo; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * The <b>Title</b> option takes a String value. This option sets the |
|
| 116 | - * document title of the generated HTML document. |
|
| 117 | - * Defaults to 'Log4php Log Messages'. |
|
| 118 | - */ |
|
| 119 | - public function setTitle($title) |
|
| 120 | - { |
|
| 121 | - $this->title = $title; |
|
| 122 | - } |
|
| 114 | + /** |
|
| 115 | + * The <b>Title</b> option takes a String value. This option sets the |
|
| 116 | + * document title of the generated HTML document. |
|
| 117 | + * Defaults to 'Log4php Log Messages'. |
|
| 118 | + */ |
|
| 119 | + public function setTitle($title) |
|
| 120 | + { |
|
| 121 | + $this->title = $title; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * @return string Returns the current value of the <b>Title</b> option. |
|
| 126 | - */ |
|
| 127 | - public function getTitle() |
|
| 128 | - { |
|
| 129 | - return $this->title; |
|
| 130 | - } |
|
| 124 | + /** |
|
| 125 | + * @return string Returns the current value of the <b>Title</b> option. |
|
| 126 | + */ |
|
| 127 | + public function getTitle() |
|
| 128 | + { |
|
| 129 | + return $this->title; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * @return string Returns the content type output by this layout, i.e "text/html". |
|
| 134 | - */ |
|
| 135 | - public function getContentType() |
|
| 136 | - { |
|
| 137 | - return "text/html"; |
|
| 138 | - } |
|
| 132 | + /** |
|
| 133 | + * @return string Returns the content type output by this layout, i.e "text/html". |
|
| 134 | + */ |
|
| 135 | + public function getContentType() |
|
| 136 | + { |
|
| 137 | + return "text/html"; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * No options to activate. |
|
| 142 | - */ |
|
| 143 | - public function activateOptions() |
|
| 144 | - { |
|
| 145 | - return true; |
|
| 146 | - } |
|
| 140 | + /** |
|
| 141 | + * No options to activate. |
|
| 142 | + */ |
|
| 143 | + public function activateOptions() |
|
| 144 | + { |
|
| 145 | + return true; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * @param LoggerLoggingEvent $event |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - public function format($event) |
|
| 153 | - { |
|
| 154 | - $sbuf = LOG4PHP_LINE_SEP . "<tr>" . LOG4PHP_LINE_SEP; |
|
| 148 | + /** |
|
| 149 | + * @param LoggerLoggingEvent $event |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + public function format($event) |
|
| 153 | + { |
|
| 154 | + $sbuf = LOG4PHP_LINE_SEP . "<tr>" . LOG4PHP_LINE_SEP; |
|
| 155 | 155 | |
| 156 | - $sbuf .= "<td>"; |
|
| 156 | + $sbuf .= "<td>"; |
|
| 157 | 157 | |
| 158 | - $eventTime = (float)$event->getTimeStamp(); |
|
| 159 | - $eventStartTime = (float)LoggerLoggingEvent::getStartTime(); |
|
| 160 | - $sbuf .= number_format(($eventTime - $eventStartTime) * 1000, 0, '', ''); |
|
| 161 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 158 | + $eventTime = (float)$event->getTimeStamp(); |
|
| 159 | + $eventStartTime = (float)LoggerLoggingEvent::getStartTime(); |
|
| 160 | + $sbuf .= number_format(($eventTime - $eventStartTime) * 1000, 0, '', ''); |
|
| 161 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 162 | 162 | |
| 163 | - $sbuf .= "<td title=\"" . $event->getThreadName() . " thread\">"; |
|
| 164 | - $sbuf .= $event->getThreadName(); |
|
| 165 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 163 | + $sbuf .= "<td title=\"" . $event->getThreadName() . " thread\">"; |
|
| 164 | + $sbuf .= $event->getThreadName(); |
|
| 165 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 166 | 166 | |
| 167 | - $sbuf .= "<td title=\"Level\">"; |
|
| 167 | + $sbuf .= "<td title=\"Level\">"; |
|
| 168 | 168 | |
| 169 | - $level = $event->getLevel(); |
|
| 169 | + $level = $event->getLevel(); |
|
| 170 | 170 | |
| 171 | - if ($level->equals(LoggerLevel::getLevelDebug())) { |
|
| 172 | - $sbuf .= "<font color=\"#339933\">"; |
|
| 173 | - $sbuf .= $level->toString(); |
|
| 174 | - $sbuf .= "</font>"; |
|
| 175 | - }elseif($level->equals(LoggerLevel::getLevelWarn())) { |
|
| 176 | - $sbuf .= "<font color=\"#993300\"><strong>"; |
|
| 177 | - $sbuf .= $level->toString(); |
|
| 178 | - $sbuf .= "</strong></font>"; |
|
| 179 | - } else { |
|
| 180 | - $sbuf .= $level->toString(); |
|
| 181 | - } |
|
| 182 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 171 | + if ($level->equals(LoggerLevel::getLevelDebug())) { |
|
| 172 | + $sbuf .= "<font color=\"#339933\">"; |
|
| 173 | + $sbuf .= $level->toString(); |
|
| 174 | + $sbuf .= "</font>"; |
|
| 175 | + }elseif($level->equals(LoggerLevel::getLevelWarn())) { |
|
| 176 | + $sbuf .= "<font color=\"#993300\"><strong>"; |
|
| 177 | + $sbuf .= $level->toString(); |
|
| 178 | + $sbuf .= "</strong></font>"; |
|
| 179 | + } else { |
|
| 180 | + $sbuf .= $level->toString(); |
|
| 181 | + } |
|
| 182 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 183 | 183 | |
| 184 | - $sbuf .= "<td title=\"" . htmlentities($event->getLoggerName(), ENT_QUOTES) . " category\">"; |
|
| 185 | - $sbuf .= htmlentities($event->getLoggerName(), ENT_QUOTES); |
|
| 186 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 184 | + $sbuf .= "<td title=\"" . htmlentities($event->getLoggerName(), ENT_QUOTES) . " category\">"; |
|
| 185 | + $sbuf .= htmlentities($event->getLoggerName(), ENT_QUOTES); |
|
| 186 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 187 | 187 | |
| 188 | - if ($this->locationInfo) { |
|
| 189 | - $locInfo = $event->getLocationInformation(); |
|
| 190 | - $sbuf .= "<td>"; |
|
| 191 | - $sbuf .= htmlentities($locInfo->getFileName(), ENT_QUOTES). ':' . $locInfo->getLineNumber(); |
|
| 192 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 193 | - } |
|
| 188 | + if ($this->locationInfo) { |
|
| 189 | + $locInfo = $event->getLocationInformation(); |
|
| 190 | + $sbuf .= "<td>"; |
|
| 191 | + $sbuf .= htmlentities($locInfo->getFileName(), ENT_QUOTES). ':' . $locInfo->getLineNumber(); |
|
| 192 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - $sbuf .= "<td title=\"Message\">"; |
|
| 196 | - $sbuf .= htmlentities($event->getRenderedMessage(), ENT_QUOTES); |
|
| 197 | - $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 195 | + $sbuf .= "<td title=\"Message\">"; |
|
| 196 | + $sbuf .= htmlentities($event->getRenderedMessage(), ENT_QUOTES); |
|
| 197 | + $sbuf .= "</td>" . LOG4PHP_LINE_SEP; |
|
| 198 | 198 | |
| 199 | - $sbuf .= "</tr>" . LOG4PHP_LINE_SEP; |
|
| 199 | + $sbuf .= "</tr>" . LOG4PHP_LINE_SEP; |
|
| 200 | 200 | |
| 201 | - if ($event->getNDC() != null) { |
|
| 202 | - $sbuf .= "<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">"; |
|
| 203 | - $sbuf .= "NDC: " . htmlentities($event->getNDC(), ENT_QUOTES); |
|
| 204 | - $sbuf .= "</td></tr>" . LOG4PHP_LINE_SEP; |
|
| 205 | - } |
|
| 201 | + if ($event->getNDC() != null) { |
|
| 202 | + $sbuf .= "<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">"; |
|
| 203 | + $sbuf .= "NDC: " . htmlentities($event->getNDC(), ENT_QUOTES); |
|
| 204 | + $sbuf .= "</td></tr>" . LOG4PHP_LINE_SEP; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - return $sbuf; |
|
| 208 | - } |
|
| 207 | + return $sbuf; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * @return string Returns appropriate HTML headers. |
|
| 212 | - */ |
|
| 213 | - public function getHeader() |
|
| 214 | - { |
|
| 215 | - $sbuf = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" . LOG4PHP_LINE_SEP; |
|
| 216 | - $sbuf .= "<html>" . LOG4PHP_LINE_SEP; |
|
| 217 | - $sbuf .= "<head>" . LOG4PHP_LINE_SEP; |
|
| 218 | - $sbuf .= "<title>" . $this->title . "</title>" . LOG4PHP_LINE_SEP; |
|
| 219 | - $sbuf .= "<style type=\"text/css\">" . LOG4PHP_LINE_SEP; |
|
| 220 | - $sbuf .= "<!--" . LOG4PHP_LINE_SEP; |
|
| 221 | - $sbuf .= "body, table {font-family: arial,sans-serif; font-size: x-small;}" . LOG4PHP_LINE_SEP; |
|
| 222 | - $sbuf .= "th {background: #336699; color: #FFFFFF; text-align: left;}" . LOG4PHP_LINE_SEP; |
|
| 223 | - $sbuf .= "-->" . LOG4PHP_LINE_SEP; |
|
| 224 | - $sbuf .= "</style>" . LOG4PHP_LINE_SEP; |
|
| 225 | - $sbuf .= "</head>" . LOG4PHP_LINE_SEP; |
|
| 226 | - $sbuf .= "<body bgcolor=\"#FFFFFF\" topmargin=\"6\" leftmargin=\"6\">" . LOG4PHP_LINE_SEP; |
|
| 227 | - $sbuf .= "<hr size=\"1\" noshade>" . LOG4PHP_LINE_SEP; |
|
| 228 | - $sbuf .= "Log session start time " . strftime('%c', time()) . "<br>" . LOG4PHP_LINE_SEP; |
|
| 229 | - $sbuf .= "<br>" . LOG4PHP_LINE_SEP; |
|
| 230 | - $sbuf .= "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" bordercolor=\"#224466\" width=\"100%\">" . LOG4PHP_LINE_SEP; |
|
| 231 | - $sbuf .= "<tr>" . LOG4PHP_LINE_SEP; |
|
| 232 | - $sbuf .= "<th>Time</th>" . LOG4PHP_LINE_SEP; |
|
| 233 | - $sbuf .= "<th>Thread</th>" . LOG4PHP_LINE_SEP; |
|
| 234 | - $sbuf .= "<th>Level</th>" . LOG4PHP_LINE_SEP; |
|
| 235 | - $sbuf .= "<th>Category</th>" . LOG4PHP_LINE_SEP; |
|
| 236 | - if ($this->locationInfo) |
|
| 237 | - $sbuf .= "<th>File:Line</th>" . LOG4PHP_LINE_SEP; |
|
| 238 | - $sbuf .= "<th>Message</th>" . LOG4PHP_LINE_SEP; |
|
| 239 | - $sbuf .= "</tr>" . LOG4PHP_LINE_SEP; |
|
| 210 | + /** |
|
| 211 | + * @return string Returns appropriate HTML headers. |
|
| 212 | + */ |
|
| 213 | + public function getHeader() |
|
| 214 | + { |
|
| 215 | + $sbuf = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" . LOG4PHP_LINE_SEP; |
|
| 216 | + $sbuf .= "<html>" . LOG4PHP_LINE_SEP; |
|
| 217 | + $sbuf .= "<head>" . LOG4PHP_LINE_SEP; |
|
| 218 | + $sbuf .= "<title>" . $this->title . "</title>" . LOG4PHP_LINE_SEP; |
|
| 219 | + $sbuf .= "<style type=\"text/css\">" . LOG4PHP_LINE_SEP; |
|
| 220 | + $sbuf .= "<!--" . LOG4PHP_LINE_SEP; |
|
| 221 | + $sbuf .= "body, table {font-family: arial,sans-serif; font-size: x-small;}" . LOG4PHP_LINE_SEP; |
|
| 222 | + $sbuf .= "th {background: #336699; color: #FFFFFF; text-align: left;}" . LOG4PHP_LINE_SEP; |
|
| 223 | + $sbuf .= "-->" . LOG4PHP_LINE_SEP; |
|
| 224 | + $sbuf .= "</style>" . LOG4PHP_LINE_SEP; |
|
| 225 | + $sbuf .= "</head>" . LOG4PHP_LINE_SEP; |
|
| 226 | + $sbuf .= "<body bgcolor=\"#FFFFFF\" topmargin=\"6\" leftmargin=\"6\">" . LOG4PHP_LINE_SEP; |
|
| 227 | + $sbuf .= "<hr size=\"1\" noshade>" . LOG4PHP_LINE_SEP; |
|
| 228 | + $sbuf .= "Log session start time " . strftime('%c', time()) . "<br>" . LOG4PHP_LINE_SEP; |
|
| 229 | + $sbuf .= "<br>" . LOG4PHP_LINE_SEP; |
|
| 230 | + $sbuf .= "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" bordercolor=\"#224466\" width=\"100%\">" . LOG4PHP_LINE_SEP; |
|
| 231 | + $sbuf .= "<tr>" . LOG4PHP_LINE_SEP; |
|
| 232 | + $sbuf .= "<th>Time</th>" . LOG4PHP_LINE_SEP; |
|
| 233 | + $sbuf .= "<th>Thread</th>" . LOG4PHP_LINE_SEP; |
|
| 234 | + $sbuf .= "<th>Level</th>" . LOG4PHP_LINE_SEP; |
|
| 235 | + $sbuf .= "<th>Category</th>" . LOG4PHP_LINE_SEP; |
|
| 236 | + if ($this->locationInfo) |
|
| 237 | + $sbuf .= "<th>File:Line</th>" . LOG4PHP_LINE_SEP; |
|
| 238 | + $sbuf .= "<th>Message</th>" . LOG4PHP_LINE_SEP; |
|
| 239 | + $sbuf .= "</tr>" . LOG4PHP_LINE_SEP; |
|
| 240 | 240 | |
| 241 | - return $sbuf; |
|
| 242 | - } |
|
| 241 | + return $sbuf; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * @return string Returns the appropriate HTML footers. |
|
| 246 | - */ |
|
| 247 | - public function getFooter() |
|
| 248 | - { |
|
| 249 | - $sbuf = "</table>" . LOG4PHP_LINE_SEP; |
|
| 250 | - $sbuf .= "<br>" . LOG4PHP_LINE_SEP; |
|
| 251 | - $sbuf .= "</body></html>"; |
|
| 244 | + /** |
|
| 245 | + * @return string Returns the appropriate HTML footers. |
|
| 246 | + */ |
|
| 247 | + public function getFooter() |
|
| 248 | + { |
|
| 249 | + $sbuf = "</table>" . LOG4PHP_LINE_SEP; |
|
| 250 | + $sbuf .= "<br>" . LOG4PHP_LINE_SEP; |
|
| 251 | + $sbuf .= "</body></html>"; |
|
| 252 | 252 | |
| 253 | - return $sbuf; |
|
| 254 | - } |
|
| 253 | + return $sbuf; |
|
| 254 | + } |
|
| 255 | 255 | } |
| 256 | 256 | ?> |
| 257 | 257 | \ No newline at end of file |
@@ -23,17 +23,17 @@ discard block |
||
| 23 | 23 | if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); |
| 24 | 24 | |
| 25 | 25 | if (!defined('LOG4PHP_LINE_SEP')) { |
| 26 | - if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 27 | - /** |
|
| 28 | - * @ignore |
|
| 29 | - */ |
|
| 30 | - define('LOG4PHP_LINE_SEP', "\r\n"); |
|
| 31 | - } else { |
|
| 32 | - /** |
|
| 33 | - * @ignore |
|
| 34 | - */ |
|
| 35 | - define('LOG4PHP_LINE_SEP', "\n"); |
|
| 36 | - } |
|
| 26 | + if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 27 | + /** |
|
| 28 | + * @ignore |
|
| 29 | + */ |
|
| 30 | + define('LOG4PHP_LINE_SEP', "\r\n"); |
|
| 31 | + } else { |
|
| 32 | + /** |
|
| 33 | + * @ignore |
|
| 34 | + */ |
|
| 35 | + define('LOG4PHP_LINE_SEP', "\n"); |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -76,165 +76,165 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | class LoggerLayoutTTCC extends LoggerLayout { |
| 78 | 78 | |
| 79 | - // Internal representation of options |
|
| 80 | - public $threadPrinting = true; |
|
| 81 | - public $categoryPrefixing = true; |
|
| 82 | - public $contextPrinting = true; |
|
| 83 | - public $microSecondsPrinting = true; |
|
| 79 | + // Internal representation of options |
|
| 80 | + public $threadPrinting = true; |
|
| 81 | + public $categoryPrefixing = true; |
|
| 82 | + public $contextPrinting = true; |
|
| 83 | + public $microSecondsPrinting = true; |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @var string date format. See {@link PHP_MANUAL#strftime} for details |
|
| 87 | - */ |
|
| 88 | - public $dateFormat = '%c'; |
|
| 85 | + /** |
|
| 86 | + * @var string date format. See {@link PHP_MANUAL#strftime} for details |
|
| 87 | + */ |
|
| 88 | + public $dateFormat = '%c'; |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Constructor |
|
| 92 | - * |
|
| 93 | - * @param string date format |
|
| 94 | - * @see dateFormat |
|
| 95 | - */ |
|
| 96 | - public function LoggerLayoutTTCC($dateFormat = '') |
|
| 97 | - { |
|
| 98 | - if (!empty($dateFormat)) |
|
| 99 | - $this->dateFormat = $dateFormat; |
|
| 100 | - return; |
|
| 101 | - } |
|
| 90 | + /** |
|
| 91 | + * Constructor |
|
| 92 | + * |
|
| 93 | + * @param string date format |
|
| 94 | + * @see dateFormat |
|
| 95 | + */ |
|
| 96 | + public function LoggerLayoutTTCC($dateFormat = '') |
|
| 97 | + { |
|
| 98 | + if (!empty($dateFormat)) |
|
| 99 | + $this->dateFormat = $dateFormat; |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * The <b>ThreadPrinting</b> option specifies whether the name of the |
|
| 105 | - * current thread is part of log output or not. This is true by default. |
|
| 106 | - */ |
|
| 107 | - public function setThreadPrinting($threadPrinting) |
|
| 108 | - { |
|
| 103 | + /** |
|
| 104 | + * The <b>ThreadPrinting</b> option specifies whether the name of the |
|
| 105 | + * current thread is part of log output or not. This is true by default. |
|
| 106 | + */ |
|
| 107 | + public function setThreadPrinting($threadPrinting) |
|
| 108 | + { |
|
| 109 | 109 | |
| 110 | - $this->threadPrinting = is_bool($threadPrinting) ? |
|
| 111 | - $threadPrinting : |
|
| 112 | - (bool)(strtolower($threadPrinting) == 'true'); |
|
| 113 | - } |
|
| 110 | + $this->threadPrinting = is_bool($threadPrinting) ? |
|
| 111 | + $threadPrinting : |
|
| 112 | + (bool)(strtolower($threadPrinting) == 'true'); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * @return boolean Returns value of the <b>ThreadPrinting</b> option. |
|
| 117 | - */ |
|
| 118 | - public function getThreadPrinting() { |
|
| 119 | - return $this->threadPrinting; |
|
| 120 | - } |
|
| 115 | + /** |
|
| 116 | + * @return boolean Returns value of the <b>ThreadPrinting</b> option. |
|
| 117 | + */ |
|
| 118 | + public function getThreadPrinting() { |
|
| 119 | + return $this->threadPrinting; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * The <b>CategoryPrefixing</b> option specifies whether {@link Category} |
|
| 124 | - * name is part of log output or not. This is true by default. |
|
| 125 | - */ |
|
| 126 | - public function setCategoryPrefixing($categoryPrefixing) |
|
| 127 | - { |
|
| 128 | - $this->categoryPrefixing = is_bool($categoryPrefixing) ? |
|
| 129 | - $categoryPrefixing : |
|
| 130 | - (bool)(strtolower($categoryPrefixing) == 'true'); |
|
| 131 | - } |
|
| 122 | + /** |
|
| 123 | + * The <b>CategoryPrefixing</b> option specifies whether {@link Category} |
|
| 124 | + * name is part of log output or not. This is true by default. |
|
| 125 | + */ |
|
| 126 | + public function setCategoryPrefixing($categoryPrefixing) |
|
| 127 | + { |
|
| 128 | + $this->categoryPrefixing = is_bool($categoryPrefixing) ? |
|
| 129 | + $categoryPrefixing : |
|
| 130 | + (bool)(strtolower($categoryPrefixing) == 'true'); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * @return boolean Returns value of the <b>CategoryPrefixing</b> option. |
|
| 135 | - */ |
|
| 136 | - public function getCategoryPrefixing() { |
|
| 137 | - return $this->categoryPrefixing; |
|
| 138 | - } |
|
| 133 | + /** |
|
| 134 | + * @return boolean Returns value of the <b>CategoryPrefixing</b> option. |
|
| 135 | + */ |
|
| 136 | + public function getCategoryPrefixing() { |
|
| 137 | + return $this->categoryPrefixing; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * The <b>ContextPrinting</b> option specifies log output will include |
|
| 142 | - * the nested context information belonging to the current thread. |
|
| 143 | - * This is true by default. |
|
| 144 | - */ |
|
| 145 | - public function setContextPrinting($contextPrinting) { |
|
| 146 | - $this->contextPrinting = is_bool($contextPrinting) ? |
|
| 147 | - $contextPrinting : |
|
| 148 | - (bool)(strtolower($contextPrinting) == 'true'); |
|
| 149 | - } |
|
| 140 | + /** |
|
| 141 | + * The <b>ContextPrinting</b> option specifies log output will include |
|
| 142 | + * the nested context information belonging to the current thread. |
|
| 143 | + * This is true by default. |
|
| 144 | + */ |
|
| 145 | + public function setContextPrinting($contextPrinting) { |
|
| 146 | + $this->contextPrinting = is_bool($contextPrinting) ? |
|
| 147 | + $contextPrinting : |
|
| 148 | + (bool)(strtolower($contextPrinting) == 'true'); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * @return boolean Returns value of the <b>ContextPrinting</b> option. |
|
| 153 | - */ |
|
| 154 | - public function getContextPrinting() |
|
| 155 | - { |
|
| 156 | - return $this->contextPrinting; |
|
| 157 | - } |
|
| 151 | + /** |
|
| 152 | + * @return boolean Returns value of the <b>ContextPrinting</b> option. |
|
| 153 | + */ |
|
| 154 | + public function getContextPrinting() |
|
| 155 | + { |
|
| 156 | + return $this->contextPrinting; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * The <b>MicroSecondsPrinting</b> option specifies if microseconds infos |
|
| 161 | - * should be printed at the end of timestamp. |
|
| 162 | - * This is true by default. |
|
| 163 | - */ |
|
| 164 | - public function setMicroSecondsPrinting($microSecondsPrinting) { |
|
| 165 | - $this->microSecondsPrinting = is_bool($microSecondsPrinting) ? |
|
| 166 | - $microSecondsPrinting : |
|
| 167 | - (bool)(strtolower($microSecondsPrinting) == 'true'); |
|
| 168 | - } |
|
| 159 | + /** |
|
| 160 | + * The <b>MicroSecondsPrinting</b> option specifies if microseconds infos |
|
| 161 | + * should be printed at the end of timestamp. |
|
| 162 | + * This is true by default. |
|
| 163 | + */ |
|
| 164 | + public function setMicroSecondsPrinting($microSecondsPrinting) { |
|
| 165 | + $this->microSecondsPrinting = is_bool($microSecondsPrinting) ? |
|
| 166 | + $microSecondsPrinting : |
|
| 167 | + (bool)(strtolower($microSecondsPrinting) == 'true'); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * @return boolean Returns value of the <b>MicroSecondsPrinting</b> option. |
|
| 172 | - */ |
|
| 173 | - public function getMicroSecondsPrinting() |
|
| 174 | - { |
|
| 175 | - return $this->microSecondsPrinting; |
|
| 176 | - } |
|
| 170 | + /** |
|
| 171 | + * @return boolean Returns value of the <b>MicroSecondsPrinting</b> option. |
|
| 172 | + */ |
|
| 173 | + public function getMicroSecondsPrinting() |
|
| 174 | + { |
|
| 175 | + return $this->microSecondsPrinting; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | 178 | |
| 179 | - public function setDateFormat($dateFormat) |
|
| 180 | - { |
|
| 181 | - $this->dateFormat = $dateFormat; |
|
| 182 | - } |
|
| 179 | + public function setDateFormat($dateFormat) |
|
| 180 | + { |
|
| 181 | + $this->dateFormat = $dateFormat; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - public function getDateFormat() |
|
| 188 | - { |
|
| 189 | - return $this->dateFormat; |
|
| 190 | - } |
|
| 184 | + /** |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + public function getDateFormat() |
|
| 188 | + { |
|
| 189 | + return $this->dateFormat; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * In addition to the level of the statement and message, the |
|
| 194 | - * returned string includes time, thread, category. |
|
| 195 | - * <p>Time, thread, category are printed depending on options. |
|
| 196 | - * |
|
| 197 | - * @param LoggerLoggingEvent $event |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - public function format($event) |
|
| 201 | - { |
|
| 202 | - $timeStamp = (float)$event->getTimeStamp(); |
|
| 203 | - $format = strftime($this->dateFormat, (int)$timeStamp); |
|
| 192 | + /** |
|
| 193 | + * In addition to the level of the statement and message, the |
|
| 194 | + * returned string includes time, thread, category. |
|
| 195 | + * <p>Time, thread, category are printed depending on options. |
|
| 196 | + * |
|
| 197 | + * @param LoggerLoggingEvent $event |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + public function format($event) |
|
| 201 | + { |
|
| 202 | + $timeStamp = (float)$event->getTimeStamp(); |
|
| 203 | + $format = strftime($this->dateFormat, (int)$timeStamp); |
|
| 204 | 204 | |
| 205 | - if ($this->microSecondsPrinting) { |
|
| 206 | - $usecs = round(($timeStamp - (int)$timeStamp) * 1000); |
|
| 207 | - $format .= sprintf(',%03d', $usecs); |
|
| 208 | - } |
|
| 205 | + if ($this->microSecondsPrinting) { |
|
| 206 | + $usecs = round(($timeStamp - (int)$timeStamp) * 1000); |
|
| 207 | + $format .= sprintf(',%03d', $usecs); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - $format .= ' '; |
|
| 210 | + $format .= ' '; |
|
| 211 | 211 | |
| 212 | - if ($this->threadPrinting) |
|
| 213 | - $format .= '['.getmypid().'] '; |
|
| 212 | + if ($this->threadPrinting) |
|
| 213 | + $format .= '['.getmypid().'] '; |
|
| 214 | 214 | |
| 215 | - $level = $event->getLevel(); |
|
| 216 | - $format .= $level->toString().' '; |
|
| 215 | + $level = $event->getLevel(); |
|
| 216 | + $format .= $level->toString().' '; |
|
| 217 | 217 | |
| 218 | - if($this->categoryPrefixing) { |
|
| 219 | - $format .= $event->getLoggerName().' '; |
|
| 220 | - } |
|
| 218 | + if($this->categoryPrefixing) { |
|
| 219 | + $format .= $event->getLoggerName().' '; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - if($this->contextPrinting) { |
|
| 223 | - $ndc = $event->getNDC(); |
|
| 224 | - if($ndc != null) { |
|
| 225 | - $format .= $ndc.' '; |
|
| 226 | - } |
|
| 227 | - } |
|
| 222 | + if($this->contextPrinting) { |
|
| 223 | + $ndc = $event->getNDC(); |
|
| 224 | + if($ndc != null) { |
|
| 225 | + $format .= $ndc.' '; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - $format .= '- '.$event->getRenderedMessage(); |
|
| 230 | - $format .= LOG4PHP_LINE_SEP; |
|
| 229 | + $format .= '- '.$event->getRenderedMessage(); |
|
| 230 | + $format .= LOG4PHP_LINE_SEP; |
|
| 231 | 231 | |
| 232 | - return $format; |
|
| 233 | - } |
|
| 232 | + return $format; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - public function ignoresThrowable() |
|
| 236 | - { |
|
| 237 | - return true; |
|
| 238 | - } |
|
| 235 | + public function ignoresThrowable() |
|
| 236 | + { |
|
| 237 | + return true; |
|
| 238 | + } |
|
| 239 | 239 | } |
| 240 | 240 | ?> |
| 241 | 241 | \ No newline at end of file |
@@ -50,157 +50,157 @@ |
||
| 50 | 50 | */ |
| 51 | 51 | class LoggerXmlLayout extends LoggerLayout { |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * The <b>LocationInfo</b> option takes a boolean value. By default, |
|
| 55 | - * it is set to false which means there will be no location |
|
| 56 | - * information output by this layout. If the the option is set to |
|
| 57 | - * true, then the file name and line number of the statement at the |
|
| 58 | - * origin of the log statement will be output. |
|
| 59 | - * @var boolean |
|
| 60 | - */ |
|
| 61 | - public $locationInfo = true; |
|
| 53 | + /** |
|
| 54 | + * The <b>LocationInfo</b> option takes a boolean value. By default, |
|
| 55 | + * it is set to false which means there will be no location |
|
| 56 | + * information output by this layout. If the the option is set to |
|
| 57 | + * true, then the file name and line number of the statement at the |
|
| 58 | + * origin of the log statement will be output. |
|
| 59 | + * @var boolean |
|
| 60 | + */ |
|
| 61 | + public $locationInfo = true; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var boolean set the elements namespace |
|
| 65 | - */ |
|
| 66 | - public $log4jNamespace = false; |
|
| 63 | + /** |
|
| 64 | + * @var boolean set the elements namespace |
|
| 65 | + */ |
|
| 66 | + public $log4jNamespace = false; |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @var string namespace |
|
| 71 | - * @private |
|
| 72 | - */ |
|
| 73 | - public $_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS; |
|
| 69 | + /** |
|
| 70 | + * @var string namespace |
|
| 71 | + * @private |
|
| 72 | + */ |
|
| 73 | + public $_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @var string namespace prefix |
|
| 77 | - * @private |
|
| 78 | - */ |
|
| 79 | - public $_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX; |
|
| 75 | + /** |
|
| 76 | + * @var string namespace prefix |
|
| 77 | + * @private |
|
| 78 | + */ |
|
| 79 | + public $_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX; |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * No options to activate. |
|
| 83 | - */ |
|
| 84 | - public function activateOptions() |
|
| 85 | - { |
|
| 86 | - if ($this->getLog4jNamespace()) { |
|
| 87 | - $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS; |
|
| 88 | - $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS_PREFIX; |
|
| 89 | - } else { |
|
| 90 | - $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS; |
|
| 91 | - $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX; |
|
| 92 | - } |
|
| 93 | - } |
|
| 81 | + /** |
|
| 82 | + * No options to activate. |
|
| 83 | + */ |
|
| 84 | + public function activateOptions() |
|
| 85 | + { |
|
| 86 | + if ($this->getLog4jNamespace()) { |
|
| 87 | + $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS; |
|
| 88 | + $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4J_NS_PREFIX; |
|
| 89 | + } else { |
|
| 90 | + $this->_namespace = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS; |
|
| 91 | + $this->_namespacePrefix = LOG4PHP_LOGGER_XML_LAYOUT_LOG4PHP_NS_PREFIX; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 98 | - public function getHeader() |
|
| 99 | - { |
|
| 100 | - return "<{$this->_namespacePrefix}:eventSet ". |
|
| 101 | - "xmlns:{$this->_namespacePrefix}=\"{$this->_namespace}\" ". |
|
| 102 | - "version=\"0.3\" ". |
|
| 103 | - "includesLocationInfo=\"".($this->getLocationInfo() ? "true" : "false")."\"". |
|
| 104 | - ">\r\n"; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Formats a {@link LoggerLoggingEvent} in conformance with the log4php.dtd. |
|
| 109 | - * |
|
| 110 | - * @param LoggerLoggingEvent $event |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - public function format($event) |
|
| 114 | - { |
|
| 115 | - $loggerName = $event->getLoggerName(); |
|
| 116 | - $timeStamp = number_format((float)($event->getTimeStamp() * 1000), 0, '', ''); |
|
| 117 | - $thread = $event->getThreadName(); |
|
| 118 | - $level = $event->getLevel(); |
|
| 119 | - $levelStr = $level->toString(); |
|
| 120 | - |
|
| 121 | - $buf = "<{$this->_namespacePrefix}:event logger=\"{$loggerName}\" level=\"{$levelStr}\" thread=\"{$thread}\" timestamp=\"{$timeStamp}\">\r\n"; |
|
| 122 | - $buf .= "<{$this->_namespacePrefix}:message><![CDATA["; |
|
| 123 | - LoggerTransform::appendEscapingCDATA($buf, $event->getRenderedMessage()); |
|
| 124 | - $buf .= "]]></{$this->_namespacePrefix}:message>\r\n"; |
|
| 125 | - |
|
| 126 | - $ndc = $event->getNDC(); |
|
| 127 | - if($ndc != null) { |
|
| 128 | - $buf .= "<{$this->_namespacePrefix}:NDC><![CDATA["; |
|
| 129 | - LoggerTransform::appendEscapingCDATA($buf, $ndc); |
|
| 130 | - $buf .= "]]></{$this->_namespacePrefix}:NDC>\r\n"; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if ($this->getLocationInfo()) { |
|
| 134 | - $locationInfo = $event->getLocationInformation(); |
|
| 135 | - $buf .= "<{$this->_namespacePrefix}:locationInfo ". |
|
| 136 | - "class=\"" . $locationInfo->getClassName() . "\" ". |
|
| 137 | - "file=\"" . htmlentities($locationInfo->getFileName(), ENT_QUOTES) . "\" ". |
|
| 138 | - "line=\"" . $locationInfo->getLineNumber() . "\" ". |
|
| 139 | - "method=\"" . $locationInfo->getMethodName() . "\" "; |
|
| 140 | - $buf .= "/>\r\n"; |
|
| 141 | - |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $buf .= "</{$this->_namespacePrefix}:event>\r\n\r\n"; |
|
| 95 | + /** |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | + public function getHeader() |
|
| 99 | + { |
|
| 100 | + return "<{$this->_namespacePrefix}:eventSet ". |
|
| 101 | + "xmlns:{$this->_namespacePrefix}=\"{$this->_namespace}\" ". |
|
| 102 | + "version=\"0.3\" ". |
|
| 103 | + "includesLocationInfo=\"".($this->getLocationInfo() ? "true" : "false")."\"". |
|
| 104 | + ">\r\n"; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Formats a {@link LoggerLoggingEvent} in conformance with the log4php.dtd. |
|
| 109 | + * |
|
| 110 | + * @param LoggerLoggingEvent $event |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + public function format($event) |
|
| 114 | + { |
|
| 115 | + $loggerName = $event->getLoggerName(); |
|
| 116 | + $timeStamp = number_format((float)($event->getTimeStamp() * 1000), 0, '', ''); |
|
| 117 | + $thread = $event->getThreadName(); |
|
| 118 | + $level = $event->getLevel(); |
|
| 119 | + $levelStr = $level->toString(); |
|
| 120 | + |
|
| 121 | + $buf = "<{$this->_namespacePrefix}:event logger=\"{$loggerName}\" level=\"{$levelStr}\" thread=\"{$thread}\" timestamp=\"{$timeStamp}\">\r\n"; |
|
| 122 | + $buf .= "<{$this->_namespacePrefix}:message><![CDATA["; |
|
| 123 | + LoggerTransform::appendEscapingCDATA($buf, $event->getRenderedMessage()); |
|
| 124 | + $buf .= "]]></{$this->_namespacePrefix}:message>\r\n"; |
|
| 125 | + |
|
| 126 | + $ndc = $event->getNDC(); |
|
| 127 | + if($ndc != null) { |
|
| 128 | + $buf .= "<{$this->_namespacePrefix}:NDC><![CDATA["; |
|
| 129 | + LoggerTransform::appendEscapingCDATA($buf, $ndc); |
|
| 130 | + $buf .= "]]></{$this->_namespacePrefix}:NDC>\r\n"; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if ($this->getLocationInfo()) { |
|
| 134 | + $locationInfo = $event->getLocationInformation(); |
|
| 135 | + $buf .= "<{$this->_namespacePrefix}:locationInfo ". |
|
| 136 | + "class=\"" . $locationInfo->getClassName() . "\" ". |
|
| 137 | + "file=\"" . htmlentities($locationInfo->getFileName(), ENT_QUOTES) . "\" ". |
|
| 138 | + "line=\"" . $locationInfo->getLineNumber() . "\" ". |
|
| 139 | + "method=\"" . $locationInfo->getMethodName() . "\" "; |
|
| 140 | + $buf .= "/>\r\n"; |
|
| 141 | + |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $buf .= "</{$this->_namespacePrefix}:event>\r\n\r\n"; |
|
| 145 | 145 | |
| 146 | - return $buf; |
|
| 146 | + return $buf; |
|
| 147 | 147 | |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function getFooter() |
|
| 154 | - { |
|
| 155 | - |
|
| 156 | - return "</{$this->_namespacePrefix}:eventSet>\r\n"; |
|
| 157 | - } |
|
| 150 | + /** |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function getFooter() |
|
| 154 | + { |
|
| 155 | + |
|
| 156 | + return "</{$this->_namespacePrefix}:eventSet>\r\n"; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * @return boolean |
|
| 161 | - */ |
|
| 162 | - public function getLocationInfo() |
|
| 163 | - { |
|
| 164 | - return $this->locationInfo; |
|
| 165 | - } |
|
| 159 | + /** |
|
| 160 | + * @return boolean |
|
| 161 | + */ |
|
| 162 | + public function getLocationInfo() |
|
| 163 | + { |
|
| 164 | + return $this->locationInfo; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * @return boolean |
|
| 169 | - */ |
|
| 170 | - public function getLog4jNamespace() |
|
| 171 | - { |
|
| 172 | - return $this->log4jNamespace; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * The XMLLayout prints and does not ignore exceptions. Hence the |
|
| 177 | - * return value <b>false</b>. |
|
| 178 | - * @return boolean |
|
| 179 | - */ |
|
| 180 | - public function ignoresThrowable() |
|
| 181 | - { |
|
| 182 | - return false; |
|
| 183 | - } |
|
| 167 | + /** |
|
| 168 | + * @return boolean |
|
| 169 | + */ |
|
| 170 | + public function getLog4jNamespace() |
|
| 171 | + { |
|
| 172 | + return $this->log4jNamespace; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * The XMLLayout prints and does not ignore exceptions. Hence the |
|
| 177 | + * return value <b>false</b>. |
|
| 178 | + * @return boolean |
|
| 179 | + */ |
|
| 180 | + public function ignoresThrowable() |
|
| 181 | + { |
|
| 182 | + return false; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * The {@link $locationInfo} option takes a boolean value. By default, |
|
| 187 | - * it is set to false which means there will be no location |
|
| 188 | - * information output by this layout. If the the option is set to |
|
| 189 | - * true, then the file name and line number of the statement at the |
|
| 190 | - * origin of the log statement will be output. |
|
| 191 | - */ |
|
| 192 | - public function setLocationInfo($flag) |
|
| 193 | - { |
|
| 194 | - $this->locationInfo = LoggerOptionConverter::toBoolean($flag, true); |
|
| 195 | - } |
|
| 185 | + /** |
|
| 186 | + * The {@link $locationInfo} option takes a boolean value. By default, |
|
| 187 | + * it is set to false which means there will be no location |
|
| 188 | + * information output by this layout. If the the option is set to |
|
| 189 | + * true, then the file name and line number of the statement at the |
|
| 190 | + * origin of the log statement will be output. |
|
| 191 | + */ |
|
| 192 | + public function setLocationInfo($flag) |
|
| 193 | + { |
|
| 194 | + $this->locationInfo = LoggerOptionConverter::toBoolean($flag, true); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * @param boolean |
|
| 199 | - */ |
|
| 200 | - public function setLog4jNamespace($flag) |
|
| 201 | - { |
|
| 202 | - $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, true); |
|
| 203 | - } |
|
| 197 | + /** |
|
| 198 | + * @param boolean |
|
| 199 | + */ |
|
| 200 | + public function setLog4jNamespace($flag) |
|
| 201 | + { |
|
| 202 | + $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, true); |
|
| 203 | + } |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | ?> |
| 207 | 207 | \ No newline at end of file |