* adjust for add tid for session.

This commit is contained in:
王怡栋
2021-08-30 10:56:52 +08:00
parent 1f068e6601
commit aa5a8bdd33
6 changed files with 147 additions and 8 deletions
+1
View File
@@ -20,6 +20,7 @@ $filter->default->paramName = 'reg::paramName';
$filter->default->paramValue = 'reg::paramValue';
$filter->default->get['onlybody'] = 'equal::yes';
$filter->default->get['tid'] = 'reg::word';
$filter->default->get['HTTP_X_REQUESTED_WITH'] = 'equal::XMLHttpRequest';
$filter->default->cookie['lang'] = 'reg::lang';
+18 -3
View File
@@ -160,9 +160,12 @@ class baseHelper
public static function processOnlyBodyParam($link, $onlyBody = false)
{
global $config;
if(!$onlyBody and !self::inOnlyBodyMode()) return $link;
$onlybodyString = strpos($link, '?') === false ? "?onlybody=yes" : "&onlybody=yes";
return $link . $onlybodyString;
$sign = strpos($link, '?') === false ? "?" : "&";
$appendString = '';
if($onlyBody or self::inOnlyBodyMode()) $appendString = $sign . "onlybody=yes";
if(self::isWithTID()) $appendString .= empty($appendString) ? "{$sign}tid={$_GET['tid']}" : "&tid={$_GET['tid']}";
return $link . $appendString;
}
/**
@@ -177,6 +180,18 @@ class baseHelper
return (isset($_GET['onlybody']) and $_GET['onlybody'] == 'yes');
}
/**
* Is with tid.
*
* @static
* @access public
* @return bool
*/
public static function isWithTID()
{
return (!empty($config->tabSession) and isset($_GET['tid']));
}
/**
* 使用helper::import()来引入文件,不要直接使用include或者require.
* Using helper::import() to import a file, instead of include or require.
+122
View File
@@ -855,6 +855,16 @@ class baseRouter
{
if(defined('SESSION_STARTED')) return;
$ztSessionHandler = new ztSessionHandler(zget($_GET, 'tid', ''));
session_set_save_handler(
array($ztSessionHandler, "open"),
array($ztSessionHandler, "close"),
array($ztSessionHandler, "read"),
array($ztSessionHandler, "write"),
array($ztSessionHandler, "destroy"),
array($ztSessionHandler, "gc")
);
/* If request header has token, use it as session for authentication. */
if(isset($_SERVER['HTTP_TOKEN'])) session_id($_SERVER['HTTP_TOKEN']);
@@ -2616,3 +2626,115 @@ class super
if($this->scope == 'global') a($GLOBALS);
}
}
/**
* ZenTao session handler.
*
* @package framework
*/
class ztSessionHandler
{
public $sessSavePath;
public $tagID;
/**
* Construct.
*
* @param string $tagID
* @access public
* @return void
*/
public function __construct($tagID = '')
{
$this->tagID = $tagID;
}
/**
* Open
*
* @param string $savePath
* @param string $sessionName
* @access public
* @return bool
*/
public function open($savePath, $sessionName)
{
$this->sessSavePath = $savePath;
return true;
}
/**
* Close
*
* @access public
* @return bool
*/
public function close()
{
return true;
}
/**
* Read
*
* @param string $id
* @access public
* @return bool
*/
public function read($id)
{
$sessFile = "$this->sessSavePath/sess_$id" . $this->tagID;
if(!file_exists($sessFile))
{
($this->tagID and file_exists("$this->sessSavePath/sess_$id")) ? copy("$this->sessSavePath/sess_$id", $sessFile) : touch($sessFile);
}
return (string) file_get_contents($sessFile);
}
/**
* Write
*
* @param string $id
* @param string $sessData
* @access public
* @return bool
*/
public function write($id, $sessData)
{
$sessFile = "$this->sessSavePath/sess_$id" . $this->tagID;
if(file_put_contents($sessFile, $sessData)) return true;
return false;
}
/**
* Destroy
*
* @param string $id
* @access public
* @return bool
*/
public function destroy($id)
{
$sessFile = "$this->sessSavePath/sess_$id" . $this->tagID;
@unlink($sessFile);
touch($sessFile);
return true;
}
/**
* GC
*
* @param int $maxlifeTime
* @access public
* @return bool
*/
public function gc($maxlifeTime)
{
$time = time();
foreach(glob("$this->sessSavePath/sess_*") as $fileName)
{
if(filemtime($fileName) + $maxlifeTime < $time) @unlink($fileName);
}
return true;
}
}
+2
View File
@@ -1166,7 +1166,9 @@ EOT;
$jsConfig->runMode = $runMode;
$jsConfig->timeout = isset($config->timeout) ? $config->timeout : '';
$jsConfig->pingInterval = isset($config->pingInterval) ? $config->pingInterval : '';
$jsConfig->onlybody = zget($_GET, 'onlybody', 'no');
$jsConfig->tabSession = $config->tabSession;
if($config->tabSession and helper::inTabIDMode()) $jsConfig->tid = zget($_GET, 'tid', '');
$jsLang = new stdclass();
$jsLang->submitting = isset($lang->loading) ? $lang->loading : '';
-1
View File
@@ -19,7 +19,6 @@ $onlybody = zget($_GET, 'onlybody', 'no');
<?php
echo html::title($title . ' - ' . $lang->zentaoPMS);
js::exportConfigVars();
echo '<script>config.onlybody = "' . $onlybody . '";</script>';
if($config->debug)
{
$timestamp = time();
+4 -4
View File
@@ -777,7 +777,7 @@ class user extends control
$canModifyDIR = false;
$floderPath = $this->app->tmpRoot;
}
elseif(!is_dir($this->app->dataRoot) or substr(base_convert(@fileperms($this->app->dataRoot),10,8),-4) != '0777')
elseif(!is_dir($this->app->dataRoot) or substr(base_convert(@fileperms($this->app->dataRoot), 10, 8), -4) != '0777')
{
$canModifyDIR = false;
$floderPath = $this->app->dataRoot;
@@ -827,7 +827,7 @@ class user extends control
}
else
{
$response['locate'] = $this->config->webRoot;
$response['locate'] = $this->config->webRoot . (helper::inTabIDMode() ? "?tid={$this->get->tid}" : '');
return $this->send($response);
}
}
@@ -902,7 +902,7 @@ class user extends control
}
else
{
$response['locate'] = $this->config->webRoot;
$response['locate'] = $this->config->webRoot . (helper::inTabIDMode() ? "?tid={$this->get->tid}" : '');
return $this->send($response);
}
}
@@ -914,7 +914,7 @@ class user extends control
die(helper::removeUTF8Bom(json_encode(array('status' => 'success') + $data)));
}
$response['locate'] = $this->config->webRoot;
$response['locate'] = $this->config->webRoot . (helper::inTabIDMode() ? "?tid={$this->get->tid}" : '');
$response['result'] = 'success';
return $this->send($response);
}