| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <validations> | ||
| <values> | ||
| <value name="title" required="1" message="ACTION_TYPES_VALUES_TITLE_REQUIRED"/> | ||
| <value name="protected" values="0,1" default="0" message="ACTION_TYPES_VALUES_PROTECTED"/> | ||
| </values> | ||
| </validations> |
| @@ -1,83 +1,50 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <validations> | ||
| <fks> | ||
| <fk name="asset_type_id" | ||
| source_id="id" | ||
| source_model="MolajoAssetTypesModel" | ||
| required="1" | ||
| message="CONTENT_FK_ASSET_TYPE" | ||
| /> | ||
| <fk name="checked_out_by" | ||
| source_id="id" | ||
| source_model="MolajoUsersModel" | ||
| required="0" | ||
| message="CONTENT_FK_CHECKED_OUT_BY" | ||
| /> | ||
| <fk name="created_by" | ||
| source_id="id" | ||
| source_model="MolajoUsersModel" | ||
| required="1" | ||
| message="CONTENT_FK_CREATED_BY" | ||
| /> | ||
| <fk name="extension_instance_id" | ||
| source_id="id" | ||
| source_model="MolajoExtensionInstancesModel" | ||
| required="1" | ||
| message="CONTENT_FK_EXT_INSTANCE_ID" | ||
| /> | ||
| <fk name="modified_by" | ||
| source_id="id" | ||
| source_model="MolajoUsersModel" | ||
| required="1" | ||
| message="CONTENT_FK_MODIFIED_BY" | ||
| /> | ||
| </fks> | ||
| <values> | ||
| <value name="title" required="1" message="CONTENT_VALUES_TITLE_REQUIRED"/> | ||
| <value name="status" values="0,1" default="0" message="CONTENT_VALUES_STATUS"/> | ||
| <value name="protected" values="0,1" default="0" message="CONTENT_VALUES_PROTECTED"/> | ||
| <value name="featured" values="0,1" default="0" message="CONTENT_VALUES_FEATURED"/> | ||
| <value name="stickied" values="0,1" default="0" message="CONTENT_VALUES_STICKIED"/> | ||
| <value name="protected" values="0,1" default="0" message="CONTENT_VALUES_PROTECTED"/> | ||
| </values> | ||
| <helper> | ||
| <function name="validateCheckedOut"/> | ||
| <function name="validateAlias"/> | ||
| <function name="validateDates"/> | ||
| <function name="validateLanguage"/> | ||
| </helper> | ||
| </validations> | ||
|
|
| @@ -1,170 +1,176 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| /** | ||
| * Custom session storage handler for PHP | ||
| * | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * @see http://www.php.net/manual/en/function.session-set-save-handler.php | ||
| * @since 11.1 | ||
| */ | ||
| abstract class MolajoSessionStorage extends JObject | ||
| { | ||
| /** | ||
| * @var array MolajoSessionStorage instances container. | ||
| * @since 11.3 | ||
| */ | ||
| protected static $instances = array(); | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @param array $options Optional parameters. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function __construct($options = array()) | ||
| { | ||
| $this->register($options); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a session storage handler object, only creating it if it doesn't already exist. | ||
| * | ||
| * @param string $name The session store to instantiate | ||
| * @param array $options Array of options | ||
| * | ||
| * @return MolajoSessionStorage | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public static function getInstance($name = 'none', $options = array()) | ||
| { | ||
| $name = strtolower(JFilterInput::getInstance()->clean($name, 'word')); | ||
| if (empty(self::$instances[$name])) { | ||
| $class = 'MolajoSessionStorage' . ucfirst($name); | ||
| self::$instances[$name] = new $class($options); | ||
| } | ||
| return self::$instances[$name]; | ||
| } | ||
|
|
||
| /** | ||
| * Register the functions of this class with PHP's session handler | ||
| * | ||
| * @param array $options Optional parameters | ||
| * | ||
| * @return void | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function register($options = array()) | ||
| { | ||
| // Use this object as the session handler | ||
| session_set_save_handler( | ||
| array($this, 'open'), array($this, 'close'), | ||
| array($this, 'read'), array($this, 'write'), | ||
| array($this, 'destroy'), array($this, 'gc') | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Open the SessionHandler backend. | ||
| * | ||
| * @param string $save_path The path to the session object. | ||
| * @param string $session_name The name of the session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function open($save_path, $session_name) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Close the SessionHandler backend. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function close() | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Read the data for a particular session identifier from the | ||
| * SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return string The session data. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function read($id) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * Write session data to the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * @param string $session_data The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function write($id, $session_data) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Destroy the data for a particular session identifier in the | ||
| * SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function destroy($id) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Garbage collect stale sessions from the SessionHandler backend. | ||
| * | ||
| * @param integer $maxlifetime The maximum age of a session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function gc($maxlifetime = null) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Test to see if the SessionHandler is available. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public static function test() | ||
| { | ||
| return true; | ||
| } | ||
| } |
| @@ -0,0 +1,132 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| /** | ||
| * APC session storage handler for PHP | ||
| * | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * @see http://www.php.net/manual/en/function.session-set-save-handler.php | ||
| * @since 11.1 | ||
| */ | ||
| class MolajoSessionStorageApc extends MolajoSessionStorage | ||
| { | ||
| /** | ||
| * Constructor | ||
| * | ||
| * @param array $options Optional parameters | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function __construct($options = array()) | ||
| { | ||
| if (!$this->test()) | ||
| { | ||
| return JError::raiseError(404, JText::_('JLIB_SESSION_APC_EXTENSION_NOT_AVAILABLE')); | ||
| } | ||
|
|
||
| parent::__construct($options); | ||
| } | ||
|
|
||
| /** | ||
| * Open the SessionHandler backend. | ||
| * | ||
| * @param string $save_path The path to the session object. | ||
| * @param string $session_name The name of the session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function open($save_path, $session_name) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Close the SessionHandler backend. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function close() | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Read the data for a particular session identifier from the | ||
| * SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return string The session data. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function read($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| return (string) apc_fetch($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Write session data to the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * @param string $session_data The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function write($id, $session_data) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| return apc_store($sess_id, $session_data, ini_get("session.gc_maxlifetime")); | ||
| } | ||
|
|
||
| /** | ||
| * Destroy the data for a particular session identifier in the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function destroy($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| return apc_delete($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Garbage collect stale sessions from the SessionHandler backend. | ||
| * | ||
| * @param integer $maxlifetime The maximum age of a session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function gc($maxlifetime = null) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Test to see if the SessionHandler is available. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public static function test() | ||
| { | ||
| return extension_loaded('apc'); | ||
| } | ||
| } |
| @@ -0,0 +1,130 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| /** | ||
| * eAccelerator session storage handler for PHP | ||
| * | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * @see http://www.php.net/manual/en/function.session-set-save-handler.php | ||
| * @since 11.1 | ||
| */ | ||
| class MolajoSessionStorageEaccelerator extends MolajoSessionStorage | ||
| { | ||
| /** | ||
| * Constructor | ||
| * | ||
| * @param array $options Optional parameters. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function __construct($options = array()) | ||
| { | ||
| if (!$this->test()) | ||
| { | ||
| return JError::raiseError(404, JText::_('JLIB_SESSION_EACCELERATOR_EXTENSION_NOT_AVAILABLE')); | ||
| } | ||
|
|
||
| parent::__construct($options); | ||
| } | ||
|
|
||
| /** | ||
| * Open the SessionHandler backend. | ||
| * | ||
| * @param string $save_path The path to the session object. | ||
| * @param string $session_name The name of the session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function open($save_path, $session_name) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Close the SessionHandler backend. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function close() | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Read the data for a particular session identifier from the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return string The session data. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function read($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| return (string) eaccelerator_get($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Write session data to the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * @param string $session_data The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function write($id, $session_data) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| return eaccelerator_put($sess_id, $session_data, ini_get("session.gc_maxlifetime")); | ||
| } | ||
|
|
||
| /** | ||
| * Destroy the data for a particular session identifier in the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function destroy($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| return eaccelerator_rm($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Garbage collect stale sessions from the SessionHandler backend. | ||
| * | ||
| * @param integer $maxlifetime The maximum age of a session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function gc($maxlifetime = null) | ||
| { | ||
| eaccelerator_gc(); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Test to see if the SessionHandler is available. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public static function test() | ||
| { | ||
| return (extension_loaded('eaccelerator') && function_exists('eaccelerator_get')); | ||
| } | ||
| } |
| @@ -0,0 +1,225 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| /** | ||
| * Memcache session storage handler for PHP | ||
| * | ||
| * -- Inspired in both design and implementation by the Horde memcache handler -- | ||
| * | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * @see http://www.php.net/manual/en/function.session-set-save-handler.php | ||
| * @since 11.1 | ||
| */ | ||
| class MolajoSessionStorageMemcache extends MolajoSessionStorage | ||
| { | ||
| /** | ||
| * Resource for the current memcached connection. | ||
| * | ||
| * @var resource | ||
| * @since 11.1 | ||
| */ | ||
| private $_db; | ||
|
|
||
| /** | ||
| * Use compression? | ||
| * | ||
| * @var int | ||
| * @since 11.1 | ||
| */ | ||
| private $_compress = null; | ||
|
|
||
| /** | ||
| * Use persistent connections | ||
| * | ||
| * @var boolean | ||
| * @since 11.1 | ||
| */ | ||
| private $_persistent = false; | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @param array $options Optional parameters. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function __construct($options = array()) | ||
| { | ||
| if (!$this->test()) | ||
| { | ||
| return JError::raiseError(404, JText::_('JLIB_SESSION_MEMCACHE_EXTENSION_NOT_AVAILABLE')); | ||
| } | ||
|
|
||
| parent::__construct($options); | ||
|
|
||
| $config = JFactory::getConfig(); | ||
|
|
||
| $this->_compress = $config->get('memcache_compress', false)?MEMCACHE_COMPRESSED:false; | ||
| $this->_persistent = $config->get('memcache_persist', true); | ||
|
|
||
| // This will be an array of loveliness | ||
| // @todo: multiple servers | ||
| $this->_servers = array( | ||
| array( | ||
| 'host' => $config->get('memcache_server_host', 'localhost'), | ||
| 'port' => $config->get('memcache_server_port', 11211) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Open the SessionHandler backend. | ||
| * | ||
| * @param string $save_path The path to the session object. | ||
| * @param string $session_name The name of the session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function open($save_path, $session_name) | ||
| { | ||
| $this->_db = new Memcache; | ||
| for ($i = 0, $n = count($this->_servers); $i < $n; $i++) | ||
| { | ||
| $server = $this->_servers[$i]; | ||
| $this->_db->addServer($server['host'], $server['port'], $this->_persistent); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Close the SessionHandler backend. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function close() | ||
| { | ||
| return $this->_db->close(); | ||
| } | ||
|
|
||
| /** | ||
| * Read the data for a particular session identifier from the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return string The session data. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function read($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| $this->_setExpire($sess_id); | ||
| return $this->_db->get($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Write session data to the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * @param string $session_data The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function write($id, $session_data) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| if ($this->_db->get($sess_id . '_expire')) | ||
| { | ||
| $this->_db->replace($sess_id . '_expire', time(), 0); | ||
| } | ||
| else | ||
| { | ||
| $this->_db->set($sess_id . '_expire', time(), 0); | ||
| } | ||
| if ($this->_db->get($sess_id)) | ||
| { | ||
| $this->_db->replace($sess_id, $session_data, $this->_compress); | ||
| } | ||
| else | ||
| { | ||
| $this->_db->set($sess_id, $session_data, $this->_compress); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * Destroy the data for a particular session identifier in the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function destroy($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| $this->_db->delete($sess_id . '_expire'); | ||
| return $this->_db->delete($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Garbage collect stale sessions from the SessionHandler backend. | ||
| * | ||
| * -- Not Applicable in memcache -- | ||
| * | ||
| * @param integer $maxlifetime The maximum age of a session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function gc($maxlifetime = null) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Test to see if the SessionHandler is available. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| static public function test() | ||
| { | ||
| return (extension_loaded('memcache') && class_exists('Memcache')); | ||
| } | ||
|
|
||
| /** | ||
| * Set expire time on each call since memcache sets it on cache creation. | ||
| * | ||
| * @param string $key Cache key to expire. | ||
| * | ||
| * @return void | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| protected function _setExpire($key) | ||
| { | ||
| $lifetime = ini_get("session.gc_maxlifetime"); | ||
| $expire = $this->_db->get($key . '_expire'); | ||
|
|
||
| // Set prune period | ||
| if ($expire + $lifetime < time()) | ||
| { | ||
| $this->_db->delete($key); | ||
| $this->_db->delete($key . '_expire'); | ||
| } | ||
| else | ||
| { | ||
| $this->_db->replace($key . '_expire', time()); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,226 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| /** | ||
| * Memcached session storage handler for PHP | ||
| * | ||
| * -- Inspired in both design and implementation by the Horde memcached handler -- | ||
| * | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * @see http://www.php.net/manual/en/function.session-set-save-handler.php | ||
| * @since 11.1 | ||
| */ | ||
| class MolajoSessionStorageMemcached extends MolajoSessionStorage | ||
| { | ||
| /** | ||
| * Resource for the current memcached connection. | ||
| * | ||
| * @var resource | ||
| * @since 11.1 | ||
| */ | ||
| private $_db; | ||
|
|
||
| /** | ||
| * Use compression? | ||
| * | ||
| * @var int | ||
| * @since 11.1 | ||
| */ | ||
| private $_compress = null; | ||
|
|
||
| /** | ||
| * Use persistent connections | ||
| * | ||
| * @var boolean | ||
| * @since 11.1 | ||
| */ | ||
| private $_persistent = false; | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @param array $options Optional parameters. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function __construct($options = array()) | ||
| { | ||
| if (!$this->test()) | ||
| { | ||
| return JError::raiseError(404, JText::_('JLIB_SESSION_MEMCACHE_EXTENSION_NOT_AVAILABLE')); | ||
| } | ||
|
|
||
| parent::__construct($options); | ||
|
|
||
| $config = JFactory::getConfig(); | ||
|
|
||
| $this->_compress = $config->get('memcache_compress', false)?Memcached::OPT_COMPRESSION:false; | ||
| $this->_persistent = $config->get('memcache_persist', true); | ||
|
|
||
| // This will be an array of loveliness | ||
| // @todo: multiple servers | ||
| $this->_servers = array( | ||
| array( | ||
| 'host' => $config->get('memcache_server_host', 'localhost'), | ||
| 'port' => $config->get('memcache_server_port', 11211) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Open the SessionHandler backend. | ||
| * | ||
| * @param string $save_path The path to the session object. | ||
| * @param string $session_name The name of the session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function open($save_path, $session_name) | ||
| { | ||
| $this->_db = new Memcached; | ||
| for ($i = 0, $n = count($this->_servers); $i < $n; $i++) | ||
| { | ||
| $server = $this->_servers[$i]; | ||
| $this->_db->addServer($server['host'], $server['port'], $this->_persistent); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Close the SessionHandler backend. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function close() | ||
| { | ||
| // $this->_db->close(); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Read the data for a particular session identifier from the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return string The session data. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function read($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| $this->_setExpire($sess_id); | ||
| return $this->_db->get($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Write session data to the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * @param string $session_data The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function write($id, $session_data) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| if ($this->_db->get($sess_id . '_expire')) | ||
| { | ||
| $this->_db->replace($sess_id . '_expire', time()); | ||
| } | ||
| else | ||
| { | ||
| $this->_db->set($sess_id . '_expire', time()); | ||
| } | ||
| if ($this->_db->get($sess_id)) | ||
| { | ||
| $this->_db->replace($sess_id, $session_data); | ||
| } | ||
| else | ||
| { | ||
| $this->_db->set($sess_id, $session_data); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * Destroy the data for a particular session identifier in the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function destroy($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| $this->_db->delete($sess_id . '_expire'); | ||
| return $this->_db->delete($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Garbage collect stale sessions from the SessionHandler backend. | ||
| * | ||
| * -- Not Applicable in memcached -- | ||
| * | ||
| * @param integer $maxlifetime The maximum age of a session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function gc($maxlifetime = null) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Test to see if the SessionHandler is available. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| static public function test() | ||
| { | ||
| return (extension_loaded('memcached') && class_exists('Memcached')); | ||
| } | ||
|
|
||
| /** | ||
| * Set expire time on each call since memcached sets it on cache creation. | ||
| * | ||
| * @param string $key Cache key to expire. | ||
| * | ||
| * @return void | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| protected function _setExpire($key) | ||
| { | ||
| $lifetime = ini_get("session.gc_maxlifetime"); | ||
| $expire = $this->_db->get($key . '_expire'); | ||
|
|
||
| // Set prune period | ||
| if ($expire + $lifetime < time()) | ||
| { | ||
| $this->_db->delete($key); | ||
| $this->_db->delete($key . '_expire'); | ||
| } | ||
| else | ||
| { | ||
| $this->_db->replace($key . '_expire', time()); | ||
| } | ||
| } | ||
| } |
| @@ -1,118 +1,133 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| /** | ||
| * File session handler for PHP | ||
| * | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * @see http://www.php.net/manual/en/function.session-set-save-handler.php | ||
| * @since 11.1 | ||
| */ | ||
| class MolajoSessionStorageNone extends MolajoSessionStorage | ||
| { | ||
| /** | ||
| * Register the functions of this class with PHP's session handler | ||
| * | ||
| * @param array $options Optional parameters. | ||
| * | ||
| * @return void | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function register($options = array()) | ||
| { | ||
| // Let php handle the session storage | ||
| } | ||
|
|
||
| /** | ||
| * Open the SessionHandler backend. | ||
| * | ||
| * @param string $save_path The path to the session object. | ||
| * @param string $session_name The name of the session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function open($save_path, $session_name) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Close the SessionHandler backend. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function close() | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Read the data for a particular session identifier from the | ||
| * SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return string The session data. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function read($id) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Write session data to the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * @param string $data The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function write($id, $data) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Destroy the data for a particular session identifier in the | ||
| * SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function destroy($id) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Garbage collect stale sessions from the SessionHandler backend. | ||
| * | ||
| * @param integer $lifetime The maximum age of a session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function gc($lifetime = 1440) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Test to see if the SessionHandler is available. | ||
| * | ||
| * @return boolean True on if available, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public static function test() | ||
| { | ||
| return true; | ||
| } | ||
| } |
| @@ -0,0 +1,127 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| /** | ||
| * WINCACHE session storage handler for PHP | ||
| * | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * @see http://www.php.net/manual/en/function.session-set-save-handler.php | ||
| * @since 11.1 | ||
| */ | ||
| class MolajoSessionStorageWincache extends MolajoSessionStorage | ||
| { | ||
| /** | ||
| * Constructor | ||
| * | ||
| * @param array $options Optional parameters. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function __construct($options = array()) | ||
| { | ||
| if (!$this->test()) | ||
| { | ||
| return JError::raiseError(404, JText::_('JLIB_SESSION_WINCACHE_EXTENSION_NOT_AVAILABLE')); | ||
| } | ||
|
|
||
| parent::__construct($options); | ||
| } | ||
|
|
||
| /** | ||
| * Open the SessionHandler backend. | ||
| * | ||
| * @param string $save_path The path to the session object. | ||
| * @param string $session_name The name of the session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function open($save_path, $session_name) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Close the SessionHandler backend. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function close() | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Read the data for a particular session identifier from the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return string The session data. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function read($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| return (string) wincache_ucache_get($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Write session data to the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * @param string $session_data The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function write($id, $session_data) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| return wincache_ucache_set($sess_id, $session_data, ini_get("session.gc_maxlifetime")); | ||
| } | ||
|
|
||
| /** | ||
| * Destroy the data for a particular session identifier in the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function destroy($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| return wincache_ucache_delete($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Garbage collect stale sessions from the SessionHandler backend. | ||
| * | ||
| * @param integer $maxlifetime The maximum age of a session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function gc($maxlifetime = null) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Test to see if the SessionHandler is available. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| static public function test() | ||
| { | ||
| return (extension_loaded('wincache') && function_exists('wincache_ucache_get') && !strcmp(ini_get('wincache.ucenabled'), "1")); | ||
| } | ||
| } |
| @@ -0,0 +1,145 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| /** | ||
| * XCache session storage handler | ||
| * | ||
| * @package Joomla.Platform | ||
| * @subpackage Cache | ||
| * @since 11.1 | ||
| */ | ||
| class MolajoSessionStorageXcache extends MolajoSessionStorage | ||
| { | ||
| /** | ||
| * Constructor | ||
| * | ||
| * @param array $options Optional parameters. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function __construct($options = array()) | ||
| { | ||
| if (!$this->test()) | ||
| { | ||
| return JError::raiseError(404, JText::_('JLIB_SESSION_XCACHE_EXTENSION_NOT_AVAILABLE')); | ||
| } | ||
|
|
||
| parent::__construct($options); | ||
| } | ||
|
|
||
| /** | ||
| * Open the SessionHandler backend. | ||
| * | ||
| * @param string $save_path The path to the session object. | ||
| * @param string $session_name The name of the session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function open($save_path, $session_name) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Close the SessionHandler backend. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function close() | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Read the data for a particular session identifier from the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return string The session data. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function read($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
|
|
||
| // Check if id exists | ||
| if (!xcache_isset($sess_id)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| return (string) xcache_get($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Write session data to the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * @param string $session_data The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function write($id, $session_data) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
| return xcache_set($sess_id, $session_data, ini_get("session.gc_maxlifetime")); | ||
| } | ||
|
|
||
| /** | ||
| * Destroy the data for a particular session identifier in the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function destroy($id) | ||
| { | ||
| $sess_id = 'sess_' . $id; | ||
|
|
||
| if (!xcache_isset($sess_id)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| return xcache_unset($sess_id); | ||
| } | ||
|
|
||
| /** | ||
| * Garbage collect stale sessions from the SessionHandler backend. | ||
| * | ||
| * @param integer $maxlifetime The maximum age of a session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * | ||
| * @since 11.1 | ||
| */ | ||
| public function gc($maxlifetime = null) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Test to see if the SessionHandler is available. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| static public function test() | ||
| { | ||
| return (extension_loaded('xcache')); | ||
| } | ||
| } |
| @@ -0,0 +1,170 @@ | ||
| <?php | ||
| /** | ||
| * @package Molajo | ||
| * @subpackage Component | ||
| * @copyright Copyright (C) 2012 Amy Stephen. All rights reserved. | ||
| * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License Version 2, or later http://www.gnu.org/licenses/gpl.html | ||
| */ | ||
| defined('MOLAJO') or die; | ||
|
|
||
| /** | ||
| * Custom session storage handler for PHP | ||
| * | ||
| * @package Joomla.Platform | ||
| * @subpackage Session | ||
| * @since 11.1 | ||
| * @see http://www.php.net/manual/en/function.session-set-save-handler.php | ||
| */ | ||
| abstract class MolajoSessionStorage extends JObject | ||
| { | ||
| /** | ||
| * Constructor | ||
| * | ||
| * @param array $options Optional parameters. | ||
| */ | ||
| public function __construct($options = array()) | ||
| { | ||
| $this->register($options); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a session storage handler object, only creating it | ||
| * if it doesn't already exist. | ||
| * | ||
| * @param name $name The session store to instantiate | ||
| * | ||
| * @return database A MolajoSessionStorage object | ||
| * @since 1.0 | ||
| */ | ||
| public static function getInstance($name = 'none', $options = array()) | ||
| { | ||
| static $instances; | ||
|
|
||
| if (!isset ($instances)) { | ||
| $instances = array(); | ||
| } | ||
|
|
||
| $name = strtolower(JFilterInput::getInstance()->clean($name, 'word')); | ||
|
|
||
| if (empty ($instances[$name])) { | ||
| $class = 'MolajoSessionStorage' . ucfirst($name); | ||
|
|
||
| if (class_exists($class)) { | ||
| } else { | ||
| $path = __DIR__ . DS . 'storage' . DS . $name . '.php'; | ||
|
|
||
| if (file_exists($path)) { | ||
| require_once $path; | ||
| } else { | ||
| // No call to JError::raiseError here, as it tries to close the non-existing session | ||
| jexit('Unable to load session storage class: ' . $name); | ||
| } | ||
| } | ||
|
|
||
| $instances[$name] = new $class($options); | ||
| } | ||
|
|
||
| return $instances[$name]; | ||
| } | ||
|
|
||
| /** | ||
| * Register the functions of this class with PHP's session handler | ||
| * | ||
| * @param array $options optional parameters | ||
| */ | ||
| public function register($options = array()) | ||
| { | ||
| // use this object as the session handler | ||
| session_set_save_handler( | ||
| array($this, 'open'), | ||
| array($this, 'close'), | ||
| array($this, 'read'), | ||
| array($this, 'write'), | ||
| array($this, 'destroy'), | ||
| array($this, 'gc') | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Open the SessionHandler backend. | ||
| * | ||
| * @param string $save_path The path to the session object. | ||
| * @param string $session_name The name of the session. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function open($save_path, $session_name) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Close the SessionHandler backend. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function close() | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Read the data for a particular session identifier from the | ||
| * SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * @return string The session data. | ||
| */ | ||
| public function read($id) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * Write session data to the SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * @param string $session_data The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function write($id, $session_data) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Destroy the data for a particular session identifier in the | ||
| * SessionHandler backend. | ||
| * | ||
| * @param string $id The session identifier. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function destroy($id) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Garbage collect stale sessions from the SessionHandler backend. | ||
| * | ||
| * @param integer $maxlifetime The maximum age of a session. | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public function gc($maxlifetime = null) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Test to see if the SessionHandler is available. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| */ | ||
| public static function test() | ||
| { | ||
| return true; | ||
| } | ||
| } |
| @@ -0,0 +1,230 @@ | ||
| <?php | ||
| /** | ||
| * @package Molajo | ||
| * @subpackage Component | ||
| * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. | ||
| * @copyright Copyright (C) 2012 Amy Stephen. All rights reserved. | ||
| * @license GNU General Public License Version 2, or later http://www.gnu.org/licenses/gpl.html | ||
| */ | ||
| defined('MOLAJO') or die; | ||
|
|
||
| /** | ||
| * Database session storage handler for PHP | ||
| * | ||
| * @package Session | ||
| * @subpackage Storage | ||
| * @since 1.0 | ||
| */ | ||
| class MolajoSessionStorageDatabase extends MolajoSessionStorage | ||
| { | ||
| /** | ||
| * $_data | ||
| * | ||
| * @var null | ||
| * @since 1.0 | ||
| */ | ||
| protected $_data = null; | ||
|
|
||
| /** | ||
| * Open the SessionHandler backend. | ||
| * | ||
| * @param string The path to the session object. | ||
| * @param string The name of the session. | ||
| * @return boolean True on success, false otherwise. | ||
| * @since 1.0 | ||
| */ | ||
| public function open($save_path, $session_name) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Close the SessionHandler backend. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * @since 1.0 | ||
| */ | ||
| public function close() | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Read the data for a particular session identifier from the | ||
| * SessionHandler backend. | ||
| * | ||
| * @param string The session identifier. | ||
| * @return string The session data. | ||
| * @since 1.0 | ||
| */ | ||
| public function read($id) | ||
| { | ||
| $db = Services::DB(); | ||
| if ($db->connected()) { | ||
| } else { | ||
| echo 'READ FAILED IN MolajoSessionStorageDatabase::read'; | ||
| die; | ||
| } | ||
|
|
||
| $query = $db->getQuery(true); | ||
|
|
||
| $query->select($db->qn('data')); | ||
| $query->from($db->qn('#__sessions')); | ||
| $query->where($db->qn('session_id') . ' = ' . $db->q($id)); | ||
|
|
||
| $db->setQuery($query->__toString()); | ||
|
|
||
| return (string)$db->loadResult(); | ||
| } | ||
|
|
||
| /** | ||
| * Write session data to the SessionHandler backend. | ||
| * | ||
| * @param string The session identifier. | ||
| * @param string The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * @since 1.0 | ||
| */ | ||
| public function write($id, $data) | ||
| { | ||
| $db = Services::DB(); | ||
| if ($db->connected()) { | ||
| } else { | ||
| echo 'WRITE FAILED IN MolajoSessionStorageDatabase::write'; | ||
| die; | ||
| } | ||
|
|
||
| $query = $db->getQuery(true); | ||
|
|
||
| $query->select($db->qn('session_id')); | ||
| $query->from($db->qn('#__sessions')); | ||
| $query->where($db->qn('session_id') . ' = ' . $db->q($id)); | ||
|
|
||
| $db->setQuery($query->__toString()); | ||
| $result = $db->loadResult(); | ||
|
|
||
| if ($result == $id) { | ||
| return (boolean)$this->update($id, $data); | ||
| } else { | ||
| return (boolean)$this->insert($id, $data); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Update session data to the SessionHandler backend. | ||
| * | ||
| * @param string The session identifier. | ||
| * @param string The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * @since 1.0 | ||
| */ | ||
| public function update($id, $data) | ||
| { | ||
| $db = Services::DB(); | ||
| if ($db->connected()) { | ||
| } else { | ||
| echo 'READ FAILED IN MolajoSessionStorageDatabase::update'; | ||
| die; | ||
| } | ||
|
|
||
| $query = $db->getQuery(true); | ||
|
|
||
| $query->update($db->qn('#__sessions')); | ||
| $query->set($db->qn('data') . ' = ' . $db->q($data)); | ||
| $query->set($db->qn('session_time') . ' = ' . (int)time()); | ||
| $query->where($db->qn('session_id') . ' = ' . $db->q($id)); | ||
|
|
||
| $db->setQuery($query->__toString()); | ||
|
|
||
| return (boolean)$db->query(); | ||
| } | ||
|
|
||
| /** | ||
| * Insert session data | ||
| * | ||
| * @param string The session identifier. | ||
| * @param string The session data. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * @since 1.0 | ||
| */ | ||
| public function insert($id, $data) | ||
| { | ||
| $db = Services::DB(); | ||
| if ($db->connected()) { | ||
| } else { | ||
| echo 'READ FAILED IN MolajoSessionStorageDatabase::insert'; | ||
| die; | ||
| } | ||
|
|
||
| $query = $db->getQuery(true); | ||
|
|
||
| $query->insert($db->qn('#__sessions')); | ||
| $query->set($db->qn('session_id') . ' = ' . $db->q($id)); | ||
| $query->set($db->qn('application_id') . ' = ' . $db->q(MOLAJO_APPLICATION_ID)); | ||
| $query->set($db->qn('data') . ' = ' . $db->q($data)); | ||
| $query->set($db->qn('session_time') . ' = ' . (int)time()); | ||
|
|
||
| $db->setQuery($query->__toString()); | ||
|
|
||
| return (boolean)$db->query(); | ||
| } | ||
|
|
||
| /** | ||
| * Destroy the data for a particular session identifier in the | ||
| * SessionHandler backend. | ||
| * | ||
| * @param string The session identifier. | ||
| * | ||
| * @return boolean True on success, false otherwise. | ||
| * @since 1.0 | ||
| */ | ||
| public function destroy($id) | ||
| { | ||
| $db = Services::DB(); | ||
| if ($db->connected()) { | ||
| } else { | ||
| echo 'READ FAILED IN MolajoSessionStorageDatabase::destroy'; | ||
| die; | ||
| } | ||
|
|
||
| $query = $db->getQuery(true); | ||
|
|
||
| $query->delete($db->qn('#__sessions')); | ||
| $query->where($db->qn('session_id') . ' = ' . $db->q($id)); | ||
|
|
||
| $db->setQuery($query->__toString()); | ||
|
|
||
| return (boolean)$db->query(); | ||
| } | ||
|
|
||
| /** | ||
| * Garbage collect stale sessions from the SessionHandler backend. | ||
| * | ||
| * @param integer The maximum age of a session. | ||
| * @return boolean True on success, false otherwise. | ||
| * @since 1.0 | ||
| */ | ||
| function gc($lifetime = 1440) | ||
| { | ||
| $db = Services::DB(); | ||
| if ($db->connected()) { | ||
| } else { | ||
| echo 'READ FAILED IN MolajoSessionStorageDatabase::gc'; | ||
| die; | ||
| } | ||
|
|
||
| $past = time() - $lifetime; | ||
|
|
||
| $query = $db->getQuery(true); | ||
|
|
||
| $query->delete($db->qn('#__sessions')); | ||
| $query->where($db->qn('session_time') . ' = ' . (int)$past); | ||
|
|
||
| $db->setQuery($query->__toString()); | ||
|
|
||
| return (boolean)$db->query(); | ||
| } | ||
| } |