Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sat, Feb 1, 12:47 PM

in-portal

Index: trunk/kernel/units/general/inp_ses_storage.php
===================================================================
--- trunk/kernel/units/general/inp_ses_storage.php (revision 2539)
+++ trunk/kernel/units/general/inp_ses_storage.php (revision 2540)
@@ -1,104 +1,102 @@
<?php
-k4_include_once(KERNEL_PATH.'/session/session.php');
-
class InpSession extends Session
{
function Init($prefix,$special)
{
$this->SessionTimeout = $this->Application->ConfigValue('SessionTimeout');
if (BASE_PATH == '') {
$path = '/';
}
else {
$path = BASE_PATH;
}
if ( defined('ADMIN') && ADMIN )
{
$path = rtrim($path, '/');
$path .= '/admin';
}
$this->SetCookiePath( $path );
$ses_mode = $this->Application->ConfigValue('CookieSessions');
if ($ses_mode == 2) $mode = smAUTO;
if ($ses_mode == 1) $mode = smCOOKIES_ONLY;
if ($ses_mode == 0) $mode = smGET_ONLY;
if ( defined('ADMIN') && ADMIN ) $mode = smAUTO;
$this->SetMode( $mode );
$this->SetCookieDomain( SERVER_NAME );
parent::Init($prefix,$special);
if (!defined('ADMIN')) {
$group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup');
$this->SetField('GroupList', $group_list);
}
}
}
class InpSessionStorage extends SessionStorage {
function Init($prefix,$special)
{
parent::Init($prefix,$special);
$this->setTableName(TABLE_PREFIX.'UserSession');
$this->SessionDataTable = TABLE_PREFIX.'SessionData';
$this->setIDField('SessionKey');
$this->TimestampField = 'LastAccessed';
$this->DataValueField = 'VariableValue';
$this->DataVarField = 'VariableName';
}
function LocateSession($sid)
{
$query = ' SELECT '.$this->TimestampField.' FROM '.$this->TableName.' WHERE '.$this->IDField.' = '.$this->Conn->qstr($sid);
$result = $this->Conn->GetOne($query);
if($result===false) return false;
$this->Expiration = $result + $this->SessionTimeout;
return true;
}
function UpdateSession(&$session)
{
$query = ' UPDATE '.$this->TableName.' SET '.$this->TimestampField.' = unix_timestamp() WHERE '.$this->IDField.' = '.$this->Conn->qstr($session->SID);
$this->Conn->Query($query);
}
function StoreSession(&$session)
{
parent::StoreSession($session);
$this->SetField($session, 'IpAddress', $_SERVER['REMOTE_ADDR']);
$this->SetField($session, 'GroupList', $this->Application->ConfigValue('User_GuestGroup'));
}
function GetExpiredSIDs()
{
$query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.time().' - '.$this->TimestampField.' > '.$this->SessionTimeout;
$ret = $this->Conn->GetCol($query);
if($ret) $this->DeleteEditTables();
return $ret;
}
function DeleteEditTables()
{
$tables = $this->Conn->GetCol('SHOW TABLES');
$mask_edit_table = '/'.TABLE_PREFIX.'ses_(.*)_edit_(.*)/';
$mask_search_table = '/'.TABLE_PREFIX.'ses_(.*)_(.*)/';
$sql='SELECT COUNT(*) FROM '.$this->TableName.' WHERE '.$this->IDField.' = \'%s\'';
foreach($tables as $table)
{
if( preg_match($mask_edit_table,$table,$rets) || preg_match($mask_search_table,$table,$rets) )
{
$sid=$rets[1];
$is_alive = $this->Conn->GetOne( sprintf($sql,$sid) );
if(!$is_alive) $this->Conn->Query('DROP TABLE IF EXISTS '.$table);
}
}
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/general/inp_ses_storage.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.7
\ No newline at end of property
+1.8
\ No newline at end of property
Index: trunk/core/kernel/utility/unit_config_reader.php
===================================================================
--- trunk/core/kernel/utility/unit_config_reader.php (revision 2539)
+++ trunk/core/kernel/utility/unit_config_reader.php (revision 2540)
@@ -1,431 +1,442 @@
<?php
class kUnitConfigReader extends kBase {
/**
* Configs readed
*
* @var Array
* @access private
*/
var $configData=Array();
var $configFiles=Array();
var $CacheExpired = false;
/**
* Module names found during
* config reading
*
* @var Array
*/
var $modules_installed = Array();
/**
* Scan kernel and user classes
* for available configs
*
* @access protected
*/
function Init($prefix,$special)
{
parent::Init($prefix,$special);
$db =& $this->Application->GetADODBConnection();
$this->modules_installed = $db->GetCol('SELECT CONCAT(\'/\',Path) AS Path, Name FROM '.TABLE_PREFIX.'Modules WHERE Loaded = 1','Name');
$this->scanModules(MODULES_PATH);
}
/**
* Checks if config file is allowed for includion (if module of config is installed)
*
* @param string $config_path relative path from in-portal directory
*/
function configAllowed($config_path)
{
$module_found = false;
foreach($this->modules_installed as $module_path)
{
if( substr($config_path, 0, strlen($module_path)) == $module_path )
{
$module_found = true;
break;
}
}
return $module_found;
}
/**
* Returns true if config exists and is allowed for reading
*
* @param string $prefix
* @return bool
*/
function prefixRegistred($prefix)
{
return isset($this->configData[$prefix]) ? true : false;
}
/**
* Read configs from all directories
* on path specified
*
* @param string $folderPath
* @access public
*/
function processFolder($folderPath, $cached)
{
$fh=opendir($folderPath);
while(($sub_folder=readdir($fh)))
{
$full_path=$folderPath.'/'.$sub_folder;
if( $this->isDir($full_path) && file_exists($this->getConfigName($full_path)) )
{
if (filemtime($full_path) > $cached) {
$this->CacheExpired = true;
$file = $this->getConfigName($full_path);
if ( defined('DEBUG_MODE') && dbg_ConstOn('DBG_PROFILE_INCLUDES')) {
if ( in_array($file, get_required_files()) ) return;
global $debugger;
$debugger->IncludeLevel++;
$before_time = getmicrotime();
$before_mem = memory_get_usage();
include_once(DOC_ROOT.BASE_PATH.$file);
$used_time = getmicrotime() - $before_time;
$used_mem = memory_get_usage() - $before_mem;
$debugger->IncludeLevel--;
$debugger->IncludesData['file'][] = str_replace(DOC_ROOT.BASE_PATH, '', $file);
$debugger->IncludesData['mem'][] = $used_mem;
$debugger->IncludesData['time'][] = $used_time;
$debugger->IncludesData['level'][] = -1;
}
else {
include_once($file);
}
$prefix=$config['Prefix'];
$config['BasePath']=$full_path;
$this->configData[$prefix] = $config;
}
}
}
}
function ParseConfigs()
{
foreach ($this->configData as $prefix => $config)
{
$this->parseConfig($prefix);
}
}
function findConfigFiles($folderPath)
{
$folderPath = str_replace(DOC_ROOT.BASE_PATH, '', $folderPath);
$fh=opendir(DOC_ROOT.BASE_PATH.$folderPath);
while(($sub_folder=readdir($fh)))
{
$full_path=DOC_ROOT.BASE_PATH.$folderPath.'/'.$sub_folder;
if( $this->isDir($full_path))
{
if ( file_exists(DOC_ROOT.BASE_PATH.$this->getConfigName($folderPath.'/'.$sub_folder)) ) {
$this->configFiles[] = $this->getConfigName($folderPath.'/'.$sub_folder);
}
$this->findConfigFiles($full_path);
// if (filemtime($full_path) > $cached) { }
}
}
}
function includeConfigFiles()
{
$db =& $this->Application->GetADODBConnection();
foreach ($this->configFiles as $filename)
{
$config_found = file_exists(DOC_ROOT.BASE_PATH.$filename) && $this->configAllowed($filename);
if( defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_INCLUDES'))
{
if ( in_array($filename, get_required_files()) ) return;
global $debugger;
$debugger->IncludeLevel++;
$before_time = getmicrotime();
$before_mem = memory_get_usage();
if($config_found) include_once(DOC_ROOT.BASE_PATH.$filename);
$used_time = getmicrotime() - $before_time;
$used_mem = memory_get_usage() - $before_mem;
$debugger->IncludeLevel--;
$debugger->IncludesData['file'][] = str_replace(DOC_ROOT.BASE_PATH, '', $filename);
$debugger->IncludesData['mem'][] = $used_mem;
$debugger->IncludesData['time'][] = $used_time;
$debugger->IncludesData['level'][] = -1;
}
else
{
if($config_found) include_once(DOC_ROOT.BASE_PATH.$filename);
}
if($config_found)
{
$prefix = $config['Prefix'];
$config['BasePath'] = dirname(DOC_ROOT.BASE_PATH.$filename);
$this->configData[$prefix] = $config;
}
}
}
function scanModules($folderPath)
{
global $debugger;
if (defined('CACHE_CONFIGS_FILES')) {
$conn =& $this->Application->GetADODBConnection();
$data = $conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "config_files"');
if ($data && $data['Cached'] > (time() - 3600) ) {
$this->configFiles = unserialize($data['Data']);
$files_cached = $data['Cached'];
}
else {
$files_cached = 0;
}
}
else {
$files_cached = 0;
}
if (defined('CACHE_CONFIGS_DATA')) {
$conn =& $this->Application->GetADODBConnection();
$data = $conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "config_data"');
if ($data && $data['Cached'] > (time() - 3600) ) {
$this->configData = unserialize($data['Data']);
$data_cached = $data['Cached'];
}
else {
$data_cached = 0;
}
}
else {
$data_cached = 0;
}
if ( !defined('CACHE_CONFIGS_FILES') || $files_cached == 0 ) {
$this->findConfigFiles($folderPath);
}
if ( !defined('CACHE_CONFIGS_DATA') || $data_cached == 0) {
$this->includeConfigFiles();
}
/*// && (time() - $cached) > 600) - to skip checking files modified dates
if ( !defined('CACHE_CONFIGS') ) {
$fh=opendir($folderPath);
while(($sub_folder=readdir($fh)))
{
$full_path=$folderPath.'/'.$sub_folder.'/units';
if( $this->isDir($full_path) )
{
$this->processFolder($full_path, $cached);
}
}
}*/
$this->ParseConfigs();
if (defined('CACHE_CONFIGS_FILES') && $files_cached == 0) {
$conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_files", '.$conn->qstr(serialize($this->configFiles)).', '.time().')');
}
if (defined('CACHE_CONFIGS_DATA') && $data_cached == 0) {
$conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_data", '.$conn->qstr(serialize($this->configData)).', '.time().')');
}
unset($this->configFiles);
// unset($this->configData);
}
/**
* Register nessasary classes
*
* @param string $prefix
* @access private
*/
function parseConfig($prefix)
{
$config =& $this->configData[$prefix];
$event_manager =& $this->Application->recallObject('EventManager');
$class_params=Array('ItemClass','ListClass','EventHandlerClass','TagProcessorClass');
foreach($class_params as $param_name)
{
if ( !(isset($config[$param_name]) ) ) continue;
$class_info =& $config[$param_name];
$pseudo_class = $this->getPrefixByParamName($param_name,$prefix);
$this->Application->registerClass( $class_info['class'],
$config['BasePath'].'/'.$class_info['file'],
$pseudo_class);
$event_manager->registerBuildEvent($pseudo_class,$class_info['build_event']);
+
+ // register classes on which current class depends
+ $require_classes = getArrayValue($class_info, 'require_classes');
+ if($require_classes)
+ {
+ foreach($require_classes as $require_class)
+ {
+ $class_file = $this->Application->Factory->getFileByClassName($require_class);
+ $this->Application->registerClass($class_info['class'], $class_file, $require_class);
+ }
+ }
}
$register_classes = getArrayValue($config,'RegisterClasses');
if($register_classes)
{
foreach($register_classes as $class_info)
{
$this->Application->registerClass( $class_info['class'],
$config['BasePath'].'/'.$class_info['file'],
$class_info['pseudo']);
}
}
$regular_events = getArrayValue($config, 'RegularEvents');
if($regular_events)
{
foreach($regular_events as $short_name => $regular_event_info)
{
$event_manager->registerRegularEvent( $short_name, $config['Prefix'].':'.$regular_event_info['EventName'], $regular_event_info['RunInterval'], $regular_event_info['Type'] );
}
}
if ( is_array(getArrayValue($config, 'Hooks')) ) {
foreach ($config['Hooks'] as $hook) {
$do_prefix = $hook['DoPrefix'] == '' ? $config['Prefix'] : $hook['DoPrefix'];
if ( !is_array($hook['HookToEvent']) ) {
$hook_events = Array( $hook['HookToEvent'] );
}
else {
$hook_events = $hook['HookToEvent'];
}
foreach ($hook_events as $hook_event) {
$this->Application->registerHook($hook['HookToPrefix'], $hook['HookToSpecial'], $hook_event, $hook['Mode'], $do_prefix, $hook['DoSpecial'], $hook['DoEvent'], $hook['Conditional']);
}
}
}
if ( is_array(getArrayValue($config, 'AggregateTags')) ) {
foreach ($config['AggregateTags'] as $aggregate_tag) {
$aggregate_tag['LocalPrefix'] = $config['Prefix'];
$this->Application->registerAggregateTag($aggregate_tag);
}
}
if ( $this->Application->isDebugMode() && dbg_ConstOn('DBG_VALIDATE_CONFIGS') && isset($config['TableName']) )
{
global $debugger;
$tablename = $config['TableName'];
$conn =& $this->Application->GetADODBConnection();
$res = $conn->Query("DESCRIBE $tablename");
foreach ($res as $field) {
$f_name = $field['Field'];
if (getArrayValue($config, 'Fields')) {
if ( !array_key_exists ($f_name, $config['Fields']) ) {
$debugger->appendHTML("<b class='debug_error'>Config Warning: </b>Field $f_name exists in the database, but is not defined in config file for prefix <b>".$config['Prefix']."</b>!");
safeDefine('DBG_RAISE_ON_WARNINGS', 1);
}
else {
$options = $config['Fields'][$f_name];
if ($field['Null'] == '') {
if ( $f_name != $config['IDField'] && !isset($options['not_null']) && !isset($options['required']) ) {
$debugger->appendHTML("<b class='debug_error'>Config Error: </b>Field $f_name in config for prefix <b>".$config['Prefix']."</b> is NOT NULL in the database, but is not configured as not_null or required!");
safeDefine('DBG_RAISE_ON_WARNINGS', 1);
}
if ( isset($options['not_null']) && !isset($options['default']) ) {
$debugger->appendHTML("<b class='debug_error'>Config Error: </b>Field $f_name in config for prefix <b>".$config['Prefix']."</b> is described as NOT NULL, but does not have DEFAULT value!");
safeDefine('DBG_RAISE_ON_WARNINGS', 1);
}
}
}
}
}
}
}
/**
* Reads unit (specified by $prefix)
* option specified by $option
*
* @param string $prefix
* @param string $option
* @return string
* @access public
*/
function getUnitOption($prefix,$name)
{
return isset($this->configData[$prefix][$name]) ? $this->configData[$prefix][$name] : false;
}
/**
* Read all unit with $prefix options
*
* @param string $prefix
* @return Array
* @access public
*/
function getUnitOptions($prefix)
{
return $this->prefixRegistred($prefix) ? $this->configData[$prefix] : false;
}
/**
* Set's new unit option value
*
* @param string $prefix
* @param string $name
* @param string $value
* @access public
*/
function setUnitOption($prefix,$name,$value)
{
$this->configData[$prefix][$name] = $value;
}
function getPrefixByParamName($paramName,$prefix)
{
$pseudo_class_map=Array(
'ItemClass'=>'%s',
'ListClass'=>'%s_List',
'EventHandlerClass'=>'%s_EventHandler',
'TagProcessorClass'=>'%s_TagProcessor'
);
return sprintf($pseudo_class_map[$paramName],$prefix);
}
/**
* Get's config file name based
* on folder name supplied
*
* @param string $folderPath
* @return string
* @access private
*/
function getConfigName($folderPath)
{
return $folderPath.'/'.basename($folderPath).'_config.php';
}
/**
* is_dir ajustment to work with
* directory listings too
*
* @param string $folderPath
* @return bool
* @access private
*/
function isDir($folderPath)
{
$base_name=basename($folderPath);
$ret=!($base_name=='.'||$base_name=='..');
return $ret&&is_dir($folderPath);
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/utility/unit_config_reader.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.9
\ No newline at end of property
+1.10
\ No newline at end of property
Index: trunk/core/kernel/utility/factory.php
===================================================================
--- trunk/core/kernel/utility/factory.php (revision 2539)
+++ trunk/core/kernel/utility/factory.php (revision 2540)
@@ -1,214 +1,219 @@
<?php
class kFactory extends kBase {
/**
* Where all created objects are stored
*
* @var Array
* @access private
*/
var $Storage=Array();
/**
* Map between class name and file name
* where class definition can be found.
* File path absolute!
*
* @var Array
* @access private
*/
var $Files=Array();
/**
* Map class names to their pseudo
* class names, e.g. key=pseudo_class,
* value=real_class_name
*
* @var Array
* @access private
*/
var $realClasses=Array();
var $Dependencies=Array();
/**
* Splits any mixing of prefix and
* special into correct ones
*
* @param string $prefix_special
* @return Array
* @access public
*/
function processPrefix($prefix_special)
{
// l.pick, l, m.test_TagProcessor
//preg_match("/(.*)\.*(.*)(_*)(.*)/", $prefix_special, $regs);
//return Array('prefix'=>$regs[1].$regs[3].$regs[4], 'special'=>$regs[2]);
$tmp=explode('_',$prefix_special,2);
$tmp[0]=explode('.',$tmp[0]);
$prefix=$tmp[0][0];
$prefix_special=$prefix; // new1
if( isset($tmp[1]) )
{
$prefix.='_'.$tmp[1];
}
$special= isset($tmp[0][1]) ? $tmp[0][1] : '';
$prefix_special.='.'.$special; // new2
return Array('prefix'=>$prefix,'special'=>$special,'prefix_special'=>$prefix_special);
}
/**
* Returns object using params specified,
* creates it if is required
*
* @param string $name
* @param string $pseudo_class
* @param Array $event_params
* @return Object
*/
function &getObject($name,$pseudo_class='',$event_params=Array())
{
// $name = 'l.pick', $pseudo_class = 'l'
//echo 'N: '.$name.' - P: '.$pseudo_class."\n";
$ret=$this->processPrefix($name);
if (!$pseudo_class) $pseudo_class = $ret['prefix'];
$name=rtrim($name,'.');
if( isset($this->Storage[$name]) ) return $this->Storage[$name];
if(!isset($this->realClasses[$pseudo_class]))
{
if( $this->Application->isDebugMode() ) $GLOBALS['debugger']->appendTrace();
trigger_error('RealClass not defined for pseudo_class <b>'.$pseudo_class.'</b>', E_USER_ERROR);
}
$funs_args = func_get_args();
array_splice($funs_args, 0, 3, Array($pseudo_class) );
$this->Storage[$name] =& call_user_func_array( Array(&$this,'makeClass'), $funs_args);
$this->Storage[$name]->Init($ret['prefix'],$ret['special'],$event_params);
$prefix=$this->Storage[$name]->Prefix;
$special=$this->Storage[$name]->Special;
$event_manager =& $this->getObject('EventManager');
$event =& $event_manager->getBuildEvent($pseudo_class);
if($event)
{
$event->Init($prefix,$special);
foreach($event_params as $param_name=>$param_value)
{
$event->setEventParam($param_name,$param_value);
}
$this->Application->HandleEvent($event);
}
return $this->Storage[$name];
}
/**
* Removes object from storage, so next time it could be created from scratch
*
* @param string $name Object's name in the Storage
*/
function DestroyObject($name)
{
unset($this->Storage[$name]);
}
/**
* Includes file containing class
* definition for real class name
*
* @param string $real_class
* @access private
*/
function includeClassFile($real_class)
{
if (class_exists($real_class)) return;
if(!$this->Files[$real_class]) trigger_error('Real Class <b>'.$real_class.'</b> is not registered with the Factory', E_USER_ERROR);
if(!file_exists($this->Files[$real_class])) trigger_error('Include file for class <b>'.$real_class.'</b> (<b>'.$this->Files[$real_class].'</b>) does not exists', E_USER_ERROR);
- if ( $deps = getArrayValue($this->Dependencies, $real_class) ) {
- foreach ($deps as $filename) {
- k4_include_once($filename);
- }
+ if( $deps = getArrayValue($this->Dependencies, $real_class) )
+ {
+ foreach($deps as $filename) k4_include_once($filename);
}
k4_include_once($this->Files[$real_class]);
}
/**
* Get's real class name for pseudo class,
* includes class file and creates class
* instance.
* All parameters except first one are passed to object constuctor
* through mediator method makeClass that creates instance of class
*
* @param string $pseudo_class
* @return Object
* @access private
*/
function &makeClass($pseudo_class)
{
$real_class=$this->realClasses[$pseudo_class];
$this->includeClassFile($real_class);
$mem_before = memory_get_usage();
$time_before = getmicrotime();
if( func_num_args() == 1 )
{
$class =& new $real_class();
}
else
{
$func_args = func_get_args();
$pseudo_class = array_shift($func_args);
$class =& call_user_func_array( Array($real_class,'makeClass'), $func_args );
}
if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') )
{
$mem_after = memory_get_usage();
$time_after = getmicrotime();
$mem_used = $mem_after - $mem_before;
$time_used = $time_after - $time_before;
global $debugger;
$debugger->appendHTML('Factroy created <b>'.$real_class.'</b> - used '.round($mem_used/1024, 3).'Kb time: '.round($time_used, 5));
$debugger->profilerAddTotal('objects', null, $mem_used);
}
return $class;
}
/**
* Registers new class in the factory
*
* @param string $real_class
* @param string $file
* @param string $pseudo_class
* @access public
*/
function registerClass($real_class,$file,$pseudo_class=null)
{
if(!isset($pseudo_class)) $pseudo_class = $real_class;
if(!isset($this->Files[$real_class])) $this->Files[$real_class]=$file;
- if (getArrayValue($this->realClasses, $pseudo_class)) {
+ if( getArrayValue($this->realClasses, $pseudo_class) )
+ {
$this->Dependencies[$real_class][] = $this->Files[ $this->realClasses[$pseudo_class] ];
}
$this->realClasses[$pseudo_class]=$real_class;
}
+ function getFileByClassName($class_name)
+ {
+ return getArrayValue($this->Files, $class_name);
+ }
+
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/utility/factory.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.4
\ No newline at end of property
+1.5
\ No newline at end of property
Index: trunk/core/units/general/inp_ses_storage.php
===================================================================
--- trunk/core/units/general/inp_ses_storage.php (revision 2539)
+++ trunk/core/units/general/inp_ses_storage.php (revision 2540)
@@ -1,104 +1,102 @@
<?php
-k4_include_once(KERNEL_PATH.'/session/session.php');
-
class InpSession extends Session
{
function Init($prefix,$special)
{
$this->SessionTimeout = $this->Application->ConfigValue('SessionTimeout');
if (BASE_PATH == '') {
$path = '/';
}
else {
$path = BASE_PATH;
}
if ( defined('ADMIN') && ADMIN )
{
$path = rtrim($path, '/');
$path .= '/admin';
}
$this->SetCookiePath( $path );
$ses_mode = $this->Application->ConfigValue('CookieSessions');
if ($ses_mode == 2) $mode = smAUTO;
if ($ses_mode == 1) $mode = smCOOKIES_ONLY;
if ($ses_mode == 0) $mode = smGET_ONLY;
if ( defined('ADMIN') && ADMIN ) $mode = smAUTO;
$this->SetMode( $mode );
$this->SetCookieDomain( SERVER_NAME );
parent::Init($prefix,$special);
if (!defined('ADMIN')) {
$group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup');
$this->SetField('GroupList', $group_list);
}
}
}
class InpSessionStorage extends SessionStorage {
function Init($prefix,$special)
{
parent::Init($prefix,$special);
$this->setTableName(TABLE_PREFIX.'UserSession');
$this->SessionDataTable = TABLE_PREFIX.'SessionData';
$this->setIDField('SessionKey');
$this->TimestampField = 'LastAccessed';
$this->DataValueField = 'VariableValue';
$this->DataVarField = 'VariableName';
}
function LocateSession($sid)
{
$query = ' SELECT '.$this->TimestampField.' FROM '.$this->TableName.' WHERE '.$this->IDField.' = '.$this->Conn->qstr($sid);
$result = $this->Conn->GetOne($query);
if($result===false) return false;
$this->Expiration = $result + $this->SessionTimeout;
return true;
}
function UpdateSession(&$session)
{
$query = ' UPDATE '.$this->TableName.' SET '.$this->TimestampField.' = unix_timestamp() WHERE '.$this->IDField.' = '.$this->Conn->qstr($session->SID);
$this->Conn->Query($query);
}
function StoreSession(&$session)
{
parent::StoreSession($session);
$this->SetField($session, 'IpAddress', $_SERVER['REMOTE_ADDR']);
$this->SetField($session, 'GroupList', $this->Application->ConfigValue('User_GuestGroup'));
}
function GetExpiredSIDs()
{
$query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.time().' - '.$this->TimestampField.' > '.$this->SessionTimeout;
$ret = $this->Conn->GetCol($query);
if($ret) $this->DeleteEditTables();
return $ret;
}
function DeleteEditTables()
{
$tables = $this->Conn->GetCol('SHOW TABLES');
$mask_edit_table = '/'.TABLE_PREFIX.'ses_(.*)_edit_(.*)/';
$mask_search_table = '/'.TABLE_PREFIX.'ses_(.*)_(.*)/';
$sql='SELECT COUNT(*) FROM '.$this->TableName.' WHERE '.$this->IDField.' = \'%s\'';
foreach($tables as $table)
{
if( preg_match($mask_edit_table,$table,$rets) || preg_match($mask_search_table,$table,$rets) )
{
$sid=$rets[1];
$is_alive = $this->Conn->GetOne( sprintf($sql,$sid) );
if(!$is_alive) $this->Conn->Query('DROP TABLE IF EXISTS '.$table);
}
}
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/general/inp_ses_storage.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.7
\ No newline at end of property
+1.8
\ No newline at end of property

Event Timeline