mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-05 09:41:40 +09:00
Improve and simplify session status detection
This commit is contained in:
parent
3f40434bbd
commit
42d864641f
6 changed files with 28 additions and 24 deletions
|
|
@ -154,12 +154,6 @@ class Context
|
|||
*/
|
||||
public $isSuccessInit = TRUE;
|
||||
|
||||
/**
|
||||
* Session status
|
||||
* @var bool FALSE if session was not started
|
||||
*/
|
||||
public $isSessionStarted = FALSE;
|
||||
|
||||
/**
|
||||
* returns static context object (Singleton). It's to use Context without declaration of an object
|
||||
*
|
||||
|
|
@ -353,13 +347,11 @@ class Context
|
|||
|
||||
if($session_id !== NULL || $this->db_info->cache_friendly != 'Y')
|
||||
{
|
||||
$this->isSessionStarted = TRUE;
|
||||
$this->setCacheControl(0, false);
|
||||
session_start();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->isSessionStarted = FALSE;
|
||||
$this->setCacheControl(-1, true);
|
||||
register_shutdown_function(array($this, 'checkSessionStatus'));
|
||||
$_SESSION = array();
|
||||
|
|
@ -449,6 +441,16 @@ class Context
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the session status
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function getSessionStatus()
|
||||
{
|
||||
return (session_id() !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the session if $_SESSION was touched
|
||||
*
|
||||
|
|
@ -456,16 +458,18 @@ class Context
|
|||
*/
|
||||
function checkSessionStatus()
|
||||
{
|
||||
if($this->isSessionStarted)
|
||||
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
|
||||
|
||||
if($self->getSessionStatus())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(count($_SESSION) && !headers_sent())
|
||||
{
|
||||
$tempSession = $_SESSION;
|
||||
unset($_SESSION);
|
||||
session_start();
|
||||
$_SESSION = $tempSession;
|
||||
$this->isSessionStarted = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1015,7 +1019,7 @@ class Context
|
|||
$self->lang_type = $lang_type;
|
||||
$self->set('lang_type', $lang_type);
|
||||
|
||||
if($this->isSessionStarted)
|
||||
if($self->getSessionStatus())
|
||||
{
|
||||
$_SESSION['lang_type'] = $lang_type;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -788,12 +788,12 @@ class ModuleHandler extends Handler
|
|||
* */
|
||||
function _clearErrorSession()
|
||||
{
|
||||
if($_SESSION['XE_VALIDATOR_ERROR']) $_SESSION['XE_VALIDATOR_ERROR'] = '';
|
||||
if($_SESSION['XE_VALIDATOR_MESSAGE']) $_SESSION['XE_VALIDATOR_MESSAGE'] = '';
|
||||
if($_SESSION['XE_VALIDATOR_MESSAGE_TYPE']) $_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = '';
|
||||
if($_SESSION['XE_VALIDATOR_RETURN_URL']) $_SESSION['XE_VALIDATOR_RETURN_URL'] = '';
|
||||
if($_SESSION['XE_VALIDATOR_ID']) $_SESSION['XE_VALIDATOR_ID'] = '';
|
||||
if($_SESSION['INPUT_ERROR']) $_SESSION['INPUT_ERROR'] = '';
|
||||
unset($_SESSION['XE_VALIDATOR_ERROR']);
|
||||
unset($_SESSION['XE_VALIDATOR_MESSAGE']);
|
||||
unset($_SESSION['XE_VALIDATOR_MESSAGE_TYPE']);
|
||||
unset($_SESSION['XE_VALIDATOR_RETURN_URL']);
|
||||
unset($_SESSION['XE_VALIDATOR_ID']);
|
||||
unset($_SESSION['INPUT_ERROR']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ class commentItem extends Object
|
|||
|
||||
function setAccessible()
|
||||
{
|
||||
if(Context::getInstance()->isSessionStarted)
|
||||
if(Context::getSessionStatus())
|
||||
{
|
||||
$_SESSION['accessibled_comment'][$this->comment_srl] = TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -847,7 +847,7 @@ class documentController extends document
|
|||
if($_SESSION['readed_document'][$document_srl]) return false;
|
||||
|
||||
// Pass if the author's IP address is as same as visitor's.
|
||||
if($oDocument->get('ipaddress') == $_SERVER['REMOTE_ADDR'] && Context::getInstance()->isSessionStarted)
|
||||
if($oDocument->get('ipaddress') == $_SERVER['REMOTE_ADDR'] && Context::getSessionStatus())
|
||||
{
|
||||
$_SESSION['readed_document'][$document_srl] = true;
|
||||
return false;
|
||||
|
|
@ -886,7 +886,7 @@ class documentController extends document
|
|||
}
|
||||
|
||||
// Register session
|
||||
if(!$_SESSION['banned_document'][$document_srl] && Context::getInstance()->isSessionStarted)
|
||||
if(!$_SESSION['banned_document'][$document_srl] && Context::getSessionStatus())
|
||||
{
|
||||
$_SESSION['readed_document'][$document_srl] = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ class documentItem extends Object
|
|||
if($this->isSecret() && !$this->isGranted() && !$this->isAccessible()) return Context::getLang('msg_is_secret');
|
||||
|
||||
$result = $this->_checkAccessibleFromStatus();
|
||||
if($result && Context::getInstance()->isSessionStarted)
|
||||
if($result && Context::getSessionStatus())
|
||||
{
|
||||
$_SESSION['accessible'][$this->document_srl] = true;
|
||||
}
|
||||
|
|
@ -455,7 +455,7 @@ class documentItem extends Object
|
|||
if($this->isSecret() && !$this->isGranted() && !$this->isAccessible()) return Context::getLang('msg_is_secret');
|
||||
|
||||
$result = $this->_checkAccessibleFromStatus();
|
||||
if($result && Context::getInstance()->isSessionStarted)
|
||||
if($result && Context::getSessionStatus())
|
||||
{
|
||||
$_SESSION['accessible'][$this->document_srl] = true;
|
||||
}
|
||||
|
|
@ -732,7 +732,7 @@ class documentItem extends Object
|
|||
// If admin priviledge is granted on parent posts, you can read its child posts.
|
||||
$accessible = array();
|
||||
$comment_list = array();
|
||||
$setAccessibleComments = Context::getInstance()->isSessionStarted;
|
||||
$setAccessibleComments = Context::getSessionStatus();
|
||||
foreach($output->data as $key => $val)
|
||||
{
|
||||
$oCommentItem = new commentItem();
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ class memberModel extends member
|
|||
}
|
||||
}
|
||||
|
||||
if(Context::getInstance()->isSessionStarted)
|
||||
if(Context::getSessionStatus())
|
||||
{
|
||||
$_SESSION['is_logged'] = false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue