Large diffs are not rendered by default.

@@ -8,143 +8,28 @@
defined('MOLAJO') or die;

/**
* Extension Instances
* Sessions
*
* @package Molajo
* @subpackage Model
* @since 1.0
* @link
*/
class MolajoSessionsModel extends MolajoModel
class MolajoSessionsModel extends MolajoCrudModel
{
/**
* Constructor
* @param database A database connector object
*/
function __construct($db)
{
parent::__construct('#__sessions', 'session_id', $db);

$this->username = '';
}

function insert($sessionId, $application_id)
{
$this->session_id = $sessionId;

$this->application_id = $application_id;

$this->session_time = time();
$ret = $this->db->insertObject($this->_tbl, $this, 'session_id');

if (!$ret) {
$this->setError(Services::Language()->sprintf('MOLAJO_DB_ERROR_STORE_FAILED', strtolower(get_class($this)), $this->db->stderr()));
return false;
} else {
return true;
}
}

function update($updateNulls = false)
{
$this->session_time = time();
$ret = $this->db->updateObject($this->_tbl, $this, 'session_id', $updateNulls);

if (!$ret) {
$this->setError(Services::Language()->sprintf('MOLAJO_DB_ERROR_STORE_FAILED', strtolower(get_class($this)), $this->db->stderr()));
return false;
} else {
return true;
}
}

/**
* Destroys the pesisting session
*/
function destroy($userId, $application_ids = array())
{
$application_ids = implode(',', $application_ids);

$query = 'DELETE FROM #__sessions'
. ' WHERE user_id = ' . $this->db->q($userId)
. ' AND application_id IN (' . $application_ids . ')';

$this->db->setQuery($query->__toString());

if (!$this->db->query()) {
$this->setError($this->db->stderr());
return false;
}

return true;
}

/**
* Purge old sessions
*
* @param integer Session age in seconds
*
* @return mixed Resource on success, null on fail
*/
function purge($maxLifetime = 1440)
{
$past = time() - $maxLifetime;
$query = 'DELETE FROM ' . $this->_tbl . ' WHERE (session_time < \'' . (int)$past . '\')'; // Index on 'VARCHAR'
$this->db->setQuery($query->__toString());

return $this->db->query();
}

/**
* Find out if a user has a one or more active sessions
*
* @param integer $user_id The identifier of the user
* __construct
*
* @return boolean True if a session for this user exists
* @param $id
*
* @since 1.0
* $return object
* @since 1.0
*/
function exists($user_id)
public function __construct($id = null)
{
$query = 'SELECT COUNT(user_id) FROM #__sessions'
. ' WHERE user_id = ' . $this->db->q($user_id);

$this->db->setQuery($query->__toString());

if (!$result = $this->db->loadResult()) {
$this->setError($this->db->stderr());
return false;
}

return (boolean)$result;
}

/**
* Overloaded delete method
*
* We must override it because of the non-integer primary key
*
* @return true if successful otherwise returns and error message
*/
function delete($oid = null)
{
$k = $this->_tbl_key;
if ($oid) {
$this->$k = $oid;
}

$query = 'DELETE FROM ' . $this->db->qn($this->_tbl) .
' WHERE ' . $this->_tbl_key . ' = ' . $this->db->q($this->$k);

$this->db->setQuery($query->__toString());
$this->name = get_class($this);
$this->table = '#__sessions';
$this->primary_key = 'session_id';

if ($this->db->query()) {
return true;
}
else
{
$this->setError($this->db->getErrorMsg());
return false;
}
parent::__construct($id);
}
}
@@ -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"?>
<table>
<name>content</name>
<primary_key>id</primary_key>
<security>
<field name="" filter="" escape=""/>
<field name="id" filter="" escape=""/>
<field name="extension_instance_id" filter="" escape=""/>
<field name="asset_type_id" filter="" escape=""/>
<field name="title" filter="" escape=""/>
<field name="subtitle" filter="" escape=""/>
<field name="path" filter="" escape=""/>
<field name="alias" filter="" escape=""/>
<field name="content_text" filter="" escape=""/>
<field name="protected" filter="" escape=""/>
<field name="featured" filter="" escape=""/>
<field name="stickied" filter="" escape=""/>
<field name="status" filter="" escape=""/>
<field name="start_publishing_datetime" filter="" escape=""/>
<field name="stop_publishing_datetime" filter="" escape=""/>
<field name="version" filter="" escape=""/>
<field name="version_of_id" filter="" escape=""/>
<field name="status_prior_to_version" filter="" escape=""/>
<field name="created_datetime" filter="" escape=""/>
<field name="created_by" filter="" escape=""/>
<field name="modified_datetime" filter="" escape=""/>
<field name="modified_by" filter="" escape=""/>
<field name="checked_out_datetime" filter="" escape=""/>
<field name="checked_out_by" filter="" escape=""/>
<field name="root" filter="" escape=""/>
<field name="parent_id" filter="" escape=""/>
<field name="lft" filter="" escape=""/>
<field name="rgt" filter="" escape=""/>
<field name="lvl" filter="" escape=""/>
<field name="home" filter="" escape=""/>
<field name="language" filter="" escape=""/>
<field name="translation_of_id" filter="" escape=""/>
<field name="ordering" filter="" escape=""/>
</security>
<validations>
<foreignkeys>
<fk name="asset_type_id"
source_id="id"
source_table="asset_types"
required="1"
/>
<fk name="checked_out_by"
source_id="id"
source_table="users"
required="0"
/>
<fk name="created_by"
source_id="id"
source_table="users"
required="1"
/>
<fk name="extension_instance_id"
source_id="id"
source_table="extension_instances"
required="1"
/>
<fk name="modified_by"
source_id="id"
source_table="users"
required="1"
/>
</foreignkeys>
<values>
<value field="title" required="1"/>
<value field="status" values="0,1" default="0"/>
<value field="protected" values="0,1" default="0"/>
<value field="featured" values="0,1" default="0"/>
<value field="stickied" values="0,1" default="0"/>
<value field="protected" values="0,1" default="0"/>
</values>
<helper>
<function method="validateCheckedOut" crud="u"/>
<function method="validateAlias" crud="c,u"/>
<function method="validateDates" crud="c,u"/>
<function method="validateLanguage" crud="c,u"/>
</helper>
</validations>
</table>
<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>

@@ -40,46 +40,49 @@ public function __construct($id = null)
* Method to append additional data elements needed to the standard
* array of elements provided by the data source
*
* @param array $data
* @param array $this->data
*
* @return array
* @since 1.0
*/
protected function _getLoadAdditionalData($data)
protected function _getLoadAdditionalData()
{
parent::_getLoadAdditionalData();

/** concatenate name */
$data['name'] = $data['first_name'] . ' ' . $data['last_name'];
$this->data['name'] = $this->data['first_name'] . ' ' . $this->data['last_name'];

/** retrieve applications for which the user is authorized to login */
$m = new MolajoUserApplicationsModel ();
$m->query->select($this->db->qn('application_id'));
$m->query->where($this->db->qn('user_id') . ' = ' . (int)$this->id);
$applications = $m->runQuery();

$applications = $m->loadObjectList();

$x = array();
foreach ($applications as $application) {
$x[] = $application->application_id;
$x[] = $application;
}
$data['applications'] = $x;
$this->data['applications'] = $x;

/** retrieve groups to which the user belongs */
$m = new MolajoUserGroupsModel ();
$m->query->select($this->db->qn('group_id'));
$m->query->where($this->db->qn('user_id') . ' = ' . (int)$this->id);
$groups = $m->runQuery();
$groups = $m->loadObjectList();

$x = array();
foreach ($groups as $group) {
$x[] = $group->group_id;
}
$data['groups'] = $x;
$this->data['groups'] = $x;

/** retrieve system groups to which the user belongs */
$data['public'] = 1;
$data['guest'] = 0;
$data['registered'] = 1;
if (in_array(5, $data['groups'])) {
$data['administrator'] = 1;
$this->data['public'] = 1;
$this->data['guest'] = 0;
$this->data['registered'] = 1;
if (in_array(5, $this->data['groups'])) {
$this->data['administrator'] = 1;
}

/** retrieve view access groups to which the user belongs */
@@ -92,9 +95,9 @@ protected function _getLoadAdditionalData($data)
foreach ($vgroups as $vgroup) {
$x[] = $vgroup->view_group_id;
}
$data['view_groups'] = $x;
$this->data['view_groups'] = $x;

/** return array of primary query and additional data elements */
return $data;
return $this->data;
}
}
@@ -627,7 +627,7 @@ public function validateToList($name)
* @return boolean True if checked out to user
* @since 1.0
*/
public function validateCheckedOut($table)
public function validateCheckedOut($model)
{
$db = Services::DB();
$query = $db->getQuery(true);
@@ -646,7 +646,7 @@ public function validateCheckedOut($table)
* @return boolean
* @since 1.0
*/
public function validateAlias($table)
public function validateAlias($model)
{

}
@@ -659,7 +659,7 @@ public function validateAlias($table)
* @return boolean
* @since 1.0
*/
public function validateDates($table)
public function validateDates($model)
{

}
@@ -672,7 +672,7 @@ public function validateDates($table)
* @return boolean
* @since 1.0
*/
public function validateLanguage($table)
public function validateLanguage($model)
{

}
@@ -102,10 +102,10 @@ protected function getConfiguration()
$appConfig = $this->getApplicationInfo();

$this->metadata = new Registry;
$this->metadata->loadString($appConfig->metadata, 'JSON');
$this->metadata->loadString($appConfig->metadata);

$this->custom_fields = new Registry;
$this->custom_fields->loadString($appConfig->custom_fields, 'JSON');
$this->custom_fields->loadString($appConfig->custom_fields);

// todo: amy check this after the interface is working and not test data
$parameters = substr($appConfig->parameters, 1, strlen($appConfig->parameters) - 2);
@@ -185,7 +185,6 @@ public function getSite()
public function getApplicationInfo()
{
$row = new stdClass();
$id = 0;

if (MOLAJO_APPLICATION == 'installation') {

@@ -204,24 +203,17 @@ public function getApplicationInfo()
$m = new MolajoApplicationsModel ();
$m->query->where($m->db->qn('name') .
' = ' . $m->db->q(MOLAJO_APPLICATION));

$results = $m->runQuery();

if (count($results) == 0) {
// todo: amy error;
}

foreach ($results as $result) {
$row->id = $result->id;
$id = $result->id;
$row->name = $result->name;
$row->path = $result->path;
$row->asset_type_id = $result->asset_type_id;
$row->description = $result->description;
$row->custom_fields = $result->custom_fields;
$row->parameters = $result->parameters;
$row->metadata = $result->metadata;
}
$result = $m->loadObject();

$row->id = $result->id;
$id = $result->id;
$row->name = $result->name;
$row->path = $result->path;
$row->asset_type_id = $result->asset_type_id;
$row->description = $result->description;
$row->custom_fields = $result->custom_fields;
$row->parameters = $result->parameters;
$row->metadata = $result->metadata;
}

if (defined('MOLAJO_APPLICATION_ID')) {
@@ -26,12 +26,12 @@ class MolajoSessionService
protected static $instance;

/**
* $_session
* $this->session
*
* @var object Session
* @since 1.0
*/
protected $_session = null;
protected $session = null;

/**
* getInstance
@@ -61,47 +61,71 @@ public function __construct()
}

/**
* createSession
* create
*
* Create the user session.
* Initiated by Application startup to either a) identify an existing session
* for a user (in which case the last_visit_datetime for the user is updated)
* or b) create a new session (in which case, a session id is generated and
* a new session record created).
*
* Old sessions are flushed based on the configuration value for the cookie
* lifetime. If an existing session, then the last access time is updated.
* If a new session, a session id is generated and a record is created in
* the #__sessions table.
* In addition, this method does general housekeeping on old sessions
*
* @param string $name The sessions name.
* @param string $name
*
* @return MolajoSession May call exit() on database error.
* @return session object
* @since 1.0
*/
public function get($name=null)
public function create($name)
{
$handler =
Services::Configuration()
->get('session_handler', 'none');

$options = array();
$options['name'] = $name;

if (Services::Configuration()->get('force_ssl') == 2) {
$options['force_ssl'] = true;
$options['expire'] =
Services::Configuration()
->get('lifetime', 15)
* 60;

$options['force_ssl'] =
Services::Configuration()
->get('force_ssl', 0);

$this->session = MolajoSession::getInstance($handler, $options);
echo 'out of get instance'.'<br />';
var_dump($this->session);
die;
if ($this->session->getState() == 'expired') {
$this->session->restart();
}

/** retrieve session */
$this->_session = Services::Session()->get($options);

/** unlock */

/** The modulus introduces a little entropy so that queries only fires less than half the time. */
$time = time() % 2;
if ($time) {
} else {
return $this->_session;
}
$time = time();
if ($time % 2)
{
$query = $db->getQuery(true);
$query->delete($query->qn('#__session'))
->where($query->qn('time') . ' < '
. $query->q((int) ($time - $this->session->getExpire())));

$this->_removeExpiredSessions();
$db->setQuery($query);
$db->query();
}

$this->_checkSession();
// Check to see the the session already exists.
if (($this->getCfg('session_handler') != 'database'
&& ($time % 2 || $this->session->isNew()))
|| ($this->getCfg('session_handler') == 'database'
&& $this->session->isNew()))
{
$this->checkSession();
}

return $this->session;
}

return $this->_session;
}

/**
* _removeExpiredSessions
@@ -110,11 +134,12 @@ public function get($name=null)
*/
protected function _removeExpiredSessions()
{
$db = Services::DB();
$m = new MolajoSessionsModel();


$db->setQuery(
'DELETE FROM `#__sessions`' .
' WHERE `session_time` < ' . (int)(time() - $this->_session->getExpire())
' WHERE `session_time` < ' . (int)(time() - $this->session->getExpire())
);
$db->query();
}
@@ -134,25 +159,25 @@ protected function _removeExpiredSessions()
protected function _checkSession()
{
$db = Services::DB();
$session = Services::Session();
$this->session = Services::Session();
$user = Services::User();

$db->setQuery(
'SELECT `session_id`' .
' FROM `#__sessions`' .
' WHERE `session_id` = ' .
$db->q($session->getId()), 0, 1
$db->q($this->session->getId()), 0, 1
);
$exists = $db->loadResult();
if ($exists) {
return;
}

if ($session->isNew()) {
if ($this->session->isNew()) {
$db->setQuery(
'INSERT INTO `#__sessions` '.
'(`session_id`, `application_id`, `session_time`)' .
' VALUES (' . $db->q($session->getId()) .
' VALUES (' . $db->q($this->session->getId()) .
', ' . (int)MOLAJO_APPLICATION_ID .
', ' . (int)time() . ')'
);
@@ -162,9 +187,9 @@ protected function _checkSession()
'INSERT INTO `#__sessions`
(`session_id`, `application_id`, `session_time`, `user_id`)' .
' VALUES (' .
$db->q($session->getId()) . ', ' .
$db->q($this->session->getId()) . ', ' .
(int)MOLAJO_APPLICATION_ID . ', ' .
(int)$session->get('session.timer.start') . ', ' .
(int)$this->session->get('session.timer.start') . ', ' .
(int)$user->get('id') . ')'
);
}
@@ -176,9 +201,9 @@ protected function _checkSession()
}

// Session doesn't exist yet, so create session variables
if ($session->isNew()) {
$session->set('registry', new Registry('session'));
$session->set('user', new MolajoUser());
if ($this->session->isNew()) {
$this->session->set('registry', new Registry('session'));
$this->session->set('user', new MolajoUser());
}
}

@@ -193,6 +218,6 @@ protected function _checkSession()
*/
public function getSession()
{
return $this->_session;
return $this->session;
}
}
@@ -253,7 +253,7 @@ public static function getInstance($id = 0)
protected function __construct($id = 0)
{
$this->id = (int) $id;
$this->_load();
return $this->_load();
}

/**
@@ -269,7 +269,12 @@ protected function __construct($id = 0)
protected function _load()
{
$this->model = new MolajoUsersModel ($this->id);

$results = $this->model->load();
if ($results == false) {
$this->guest = true;
return;
}
$columns = $this->model->getFields();

foreach ($results as $name => $value) {
@@ -118,3 +118,17 @@ GRID_ORDERING_COLUMN_HEADING="Ordering"
GRID_BATCH_OPTIONS="Batch"
GRID_SUBMIT="Submit"
GRID_CLEAR="Clear"
MOLAJO_DB_ERROR_EMPTY_ROW_RETURNED="Load requested for data that does not exist."
CONTENT_FK_ASSET_TYPE="Asset Type ID does not match Asset_Type table"
CONTENT_FK_CHECKED_OUT_BY="Checked out by value does not match User table."
CONTENT_FK_CREATED_BY="Created by value does not match User table."
CONTENT_FK_EXT_INSTANCE_ID="Exension Instance ID is invalid."
CONTENT_FK_MODIFIED_BY="Modified by value does not match User table."
CONTENT_VALUES_TITLE_REQUIRED="Title is required."
CONTENT_VALUES_STATUS="Status is invalid."
CONTENT_VALUES_PROTECTED="Protected must be a 0 or 1."
CONTENT_VALUES_FEATURED="Featured must be 0 or 1."
CONTENT_VALUES_STICKIED="Stickied must be 0 or 1."
CONTENT_VALUES_PROTECTED="Protected must be 0 or 1."
ACTION_TYPES_VALUES_TITLE_REQUIRED="Title is required."
ACTION_TYPES_VALUES_PROTECTED="Protected must be 0 or 1."

Large diffs are not rendered by default.

@@ -1,170 +1,176 @@
<?php
/**
* @package Molajo
* @subpackage Component
* @copyright Copyright (C) 2012 Amy Stephen. All rights reserved.
* @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 http://www.gnu.org/licenses/gpl.html
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('MOLAJO') or die;

defined('JPATH_PLATFORM') 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
* @since 11.1
*/
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])) {
/**
* @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);

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;
}
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');
}
}
@@ -1,37 +1,33 @@
<?php
/**
* @package Molajo
* @subpackage Component
* @subpackage Helper
* @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
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('MOLAJO') or die;

/**
* Database session storage handler for PHP
*
* @package Session
* @subpackage Storage
* @since 1.0
* @package Joomla.Platform
* @subpackage Session
* @see http://www.php.net/manual/en/function.session-set-save-handler.php
* @since 11.1
*/
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.
* @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 1.0
*
* @since 11.1
*/
public function open($save_path, $session_name)
{
@@ -42,189 +38,104 @@ public function open($save_path, $session_name)
* Close the SessionHandler backend.
*
* @return boolean True on success, false otherwise.
* @since 1.0
*
* @since 11.1
*/
public function close()
{
return true;
}

/**
* Read the data for a particular session identifier from the
* SessionHandler backend.
* read
*
* Retrieve data for session
*
* @param string The session identifier.
* @return string The session data.
* @param string $id
*
* @return string session data
* @since 1.0
*/
public function read($id)
{
$db = Services::DB();
if ($db->connected()) {
} else {
echo 'READ FAILED IN MolajoSessionStorageDatabase::read';
die;
}
$m = new MolajoSessionsModel ();

$query = $db->getQuery(true);
$m->query->select($m->db->qn('data'));
$m->query->where($m->db->qn('session_id')
. ' = ' . $m->db->quote($id));

$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();
return (string)$m->loadResult();
}

/**
* Write session data to the SessionHandler backend.
*
* @param string The session identifier.
* @param string The session data.
* @param string $id The session identifier.
* @param string $data The session data.
*
* @return boolean True on success, false otherwise.
* @since 1.0
*
* @since 11.1
*/
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));
/** Does the session exist? */
$m = new MolajoSessionsModel();
$m->query->where($m->db->qn('session_id')
. ' = ' . $m->db->q($id));

$db->setQuery($query->__toString());
$result = $db->loadResult();
$results = $m->loadResult();

if ($result == $id) {
return (boolean)$this->update($id, $data);
if (empty($results)) {
$action = 'insert';
} 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;
$action = 'update';
}

$query = $db->getQuery(true);
$m->session_id = $id;
$m->data = $data;

$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));
$results = $m->$action();

$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';
if ($results === false) {
echo 'false false false';
die;
}
echo 'true true true';
die;
if ($results == false) {
echo 'false';
} else {
echo 'true';
}

$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.
* Destroy the data for a particular session identifier in the SessionHandler backend.
*
* @param string The session identifier.
* @param string $id The session identifier.
*
* @return boolean True on success, false otherwise.
* @since 1.0
*
* @since 11.1
*/
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.
* @param integer $lifetime The maximum age of a session.
*
* @return boolean True on success, false otherwise.
* @since 1.0
*
* @since 11.1
*/
function gc($lifetime = 1440)
public 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();
}
}
@@ -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 Molajo
* @subpackage Component
* @copyright Copyright (C) 2012 Amy Stephen. All rights reserved.
* @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 http://www.gnu.org/licenses/gpl.html
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('MOLAJO') or die;

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
* @see http://www.php.net/manual/en/function.session-set-save-handler.php
*/
class MolajoSessionStorageNone extends MolajoSessionStorage
{
/**
* Register the functions of this class with PHP's session handler
*
* @param array $options optional parameters
*/
public function register($options = array())
{
//let php handle the session storage
}
/**
* 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 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;
}
/**
* 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 1.0
*/
public function close()
{
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 The session identifier.
* @return string The session data.
* @since 1.0
*/
public function read($id)
{
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 The session identifier.
* @param string The session data.
*
* @return boolean True on success, false otherwise.
* @since 1.0
*/
public function write($id, $data)
{
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 The session identifier.
*
* @return boolean True on success, false otherwise.
* @since 1.0
*/
public function destroy($id)
{
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 The maximum age of a session.
* @return boolean True on success, false otherwise.
* @since 1.0
*/
function gc($lifetime = 1440)
{
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 1.0
*/
public static function test()
{
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'));
}
}
File renamed without changes.

Large diffs are not rendered by default.

@@ -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();
}
}
File renamed without changes.