diff --git a/framework/base/control.class.php b/framework/base/control.class.php index 6461cf4aef..4541ea851d 100644 --- a/framework/base/control.class.php +++ b/framework/base/control.class.php @@ -971,13 +971,12 @@ class baseControl return; } - define('ZIN', true); - if(empty($moduleName)) $moduleName = $this->moduleName; if(empty($methodName)) $methodName = $this->methodName; /* Load zin lib */ $this->app->loadClass('zin', true); + \zin\loadConfig(); /** * 设置视图文件。(PHP7有一个bug,不能直接$viewFile = $this->setViewFile())。 @@ -1007,6 +1006,11 @@ class baseControl /** * Set zin context data */ + \zin\zin::$globalRenderList = array(); + \zin\zin::$enabledGlobalRender = true; + \zin\zin::$rendered = false; + \zin\zin::$rawContentCalled = false; + \zin\zin::$data = (array)$this->view; \zin\zin::$data['zinDebug'] = array(); if($this->config->debug && $this->config->debug >= 2) @@ -1184,7 +1188,7 @@ class baseControl */ public function locate(string $url) { - header("location: $url"); + helper::header('location', $url); helper::end(); } } diff --git a/framework/base/router.class.php b/framework/base/router.class.php index fdbbdb399c..dba016bfd7 100644 --- a/framework/base/router.class.php +++ b/framework/base/router.class.php @@ -267,6 +267,26 @@ class baseRouter */ public $config; + /** + * 已加载的配置文件. + * Configs loaded. + * + * @static + * @var array + * @access public + */ + static $loadedConfigs = array(); + + /** + * 已加载的语言文件. + * Languages loaded. + * + * @static + * @var array + * @access public + */ + static $loadedLangs = array(); + /** * 全局$lang对象。 * The global $lang object. @@ -414,8 +434,6 @@ class baseRouter $this->loadClass('mobile', $static = true); $this->setCookieSecure(); - $this->setOpenApp(); - $this->setSuperVars(); $this->setDebug(); $this->setErrorHandler(); $this->setTimezone(); @@ -439,6 +457,9 @@ class baseRouter */ public function setClient(): void { + $this->setOpenApp(); + $this->setSuperVars(); + $this->startSession(); if($this->config->framework->multiSite) $this->setSiteCode() && $this->loadExtraConfig(); @@ -1157,7 +1178,7 @@ class baseRouter $module = $this->rawModule; $this->tab = 'my'; - if(isset($this->lang->navGroup)) $this->tab = zget($this->lang->navGroup, $module, 'my'); + if(isset($this->lang->navGroup) && $module) $this->tab = zget($this->lang->navGroup, $module, 'my'); if(isset($_COOKIE['tab']) and $_COOKIE['tab'] and preg_match('/^\w+$/', (string) $_COOKIE['tab'])) $this->tab = $_COOKIE['tab']; } @@ -1510,11 +1531,27 @@ class baseRouter helper::import($commonModelFile); - if($this->config->framework->extensionLevel == 0 and class_exists('commonModel')) return new commonModel(); - if($this->config->framework->extensionLevel > 0 and class_exists('extCommonModel')) return new extCommonModel(); + if($this->config->framework->extensionLevel == 0 and class_exists('commonModel')) + { + $common = new commonModel(); + } + elseif($this->config->framework->extensionLevel > 0 and class_exists('extCommonModel')) + { + $common = new extCommonModel(); + } + elseif(class_exists('commonModel')) + { + $common = new commonModel(); + } + else + { + return false; + } - if(class_exists('commonModel')) return new commonModel(); - return false; + $this->loadLang('company'); + $common->setUserConfig(); + + return $common; } /** @@ -2682,15 +2719,15 @@ class baseRouter /* 将主配置文件和扩展配置文件合并在一起。Put the main config file and extension config files together. */ $configFiles = $this->getMainAndExtFiles($moduleName, $appName, 'config'); + if(empty($configFiles)) return false; /* 加载每一个配置文件。Load every config file. */ - static $loadedConfigs = array(); foreach($configFiles as $configFile) { - if(in_array($configFile, $loadedConfigs)) continue; + if(in_array($configFile, self::$loadedConfigs)) continue; if(is_string($configFile) && file_exists($configFile)) include $configFile; - $loadedConfigs[] = $configFile; + self::$loadedConfigs[] = $configFile; } /* 加载数据库中与本模块相关的配置项。Merge from the db configs. */ @@ -2833,12 +2870,11 @@ class baseRouter if(!is_object($lang)) $lang = new language(); if(!isset($lang->$moduleName)) $lang->$moduleName = new stdclass(); - static $loadedLangs = array(); foreach($langFilesToLoad as $langFile) { - if(in_array($langFile, $loadedLangs)) continue; + if(in_array($langFile, self::$loadedLangs)) continue; include $langFile; - $loadedLangs[] = $langFile; + self::$loadedLangs[] = $langFile; } $this->lang = $lang; diff --git a/framework/router.class.php b/framework/router.class.php index a5f5d71642..0b976db3d3 100755 --- a/framework/router.class.php +++ b/framework/router.class.php @@ -396,12 +396,11 @@ class router extends baseRouter $configFiles = array_merge(array($mainConfigFile), $configDirFiles, $extConfigFiles); /* 加载每一个配置文件。Load every config file. */ - static $loadedConfigs = array(); foreach($configFiles as $configFile) { - if(in_array($configFile, $loadedConfigs)) continue; + if(in_array($configFile, self::$loadedConfigs)) continue; if(file_exists($configFile)) include $configFile; - $loadedConfigs[] = $configFile; + self::$loadedConfigs[] = $configFile; } /* 加载数据库中与本模块相关的配置项。Merge from the db configs. */ @@ -422,7 +421,7 @@ class router extends baseRouter */ public function loadConfig($moduleName, $appName = '') { - return parent::loadModuleConfig($moduleName); + return $this->loadModuleConfig($moduleName); } /** diff --git a/framework/zand/router.class.php b/framework/zand/router.class.php index 908dabc7c3..876b0640aa 100644 --- a/framework/zand/router.class.php +++ b/framework/zand/router.class.php @@ -33,6 +33,16 @@ include dirname(__DIR__) . '/router.class.php'; class zandRouter extends router { + /** + * 全局变量的快照 + * Snaps for global variables. + * + * @static + * @var array + * @access public + */ + static $snaps = array(); + /** * 构造方法, 设置路径,类,超级变量等。注意: * 1.应该使用createApp()方法实例化router类; @@ -59,6 +69,57 @@ class zandRouter extends router $this->consumer = new Consumer(); parent::__construct($appName, $appRoot); + + /* Snap. */ + global $filter; + + self::$snaps['config'] = clone $this->config; + self::$snaps['lang'] = clone $this->lang; + self::$snaps['filter'] = clone $filter; + } + + /** + * 初始化全局变量和客户端信息。 + * Init global variables and client. + * + * @access public + * @return void + */ + public function initRequest(): void + { + global $config, $lang, $filter, $loadedTargets; + + $config = clone self::$snaps['config']; + $lang = clone self::$snaps['lang']; + $filter = clone self::$snaps['filter']; + $loadedTargets = array(); + + $this->config = $config; + $this->lang = $lang; + $this->moduleName = NULL; + $this->methodName = NULL; + $this->rawModule = NULL; + $this->rawMethod = NULL; + + self::$loadedConfigs = array(); + self::$loadedLangs = array(); + + $this->setClient(); + } + + /** + * 关闭请求会话 + * Close request. + * + * @access public + * @return void + */ + public function closeRequest() + { + $obLevel = ob_get_level(); + for($i = 0; $i < $obLevel; $i++) ob_end_clean(); + + session_write_close(); } /** @@ -68,7 +129,7 @@ class zandRouter extends router * @access public * @return void */ - public function startSession() + public function startSession(): void { $sessionName = $this->config->sessionVar; @@ -219,6 +280,13 @@ class zandWorker $_SERVER['PATH_TRANSLATED'] = 'index.php'; $_SERVER['HTTP_HOST'] = $_SERVER['SERVER_NAME'] . (in_array($_SERVER['SERVER_PORT'], array(80, 443)) ? '' : ':' . $_SERVER['SERVER_PORT']); + $query = $request->getUri()->getQuery(); + if(!empty($query)) + { + $_SERVER['REQUEST_URI'] .= '?' . $query; + $_SERVER['QUERY_STRING'] = $query; + } + $_GET = $request->getQueryParams(); $_POST = $request->getParsedBody(); $_COOKIE = $request->getCookieParams(); @@ -342,7 +410,7 @@ class zandSession */ public function destroy($id) { - $this->dao->delete(TABLE_SESSION)->where('id')->eq($id)->exec(); + $this->dao->delete()->from(TABLE_SESSION)->where('id')->eq($id)->exec(); return true; } diff --git a/lib/zin/config.php b/lib/zin/config.php index 0da4b03096..68a1adbfc5 100644 --- a/lib/zin/config.php +++ b/lib/zin/config.php @@ -11,11 +11,14 @@ namespace zin; -global $app, $config; +function loadConfig() +{ + global $app, $config; -$config->zin = new \stdClass(); + $config->zin = new \stdClass(); -$config->zin->lang = $app->getClientLang(); -$config->zin->wgVer = isset($config->wgVer) ? $config->wgVer : '1'; -$config->zin->wgVerMap = isset($config->wgVerMap) ? $config->wgVerMap : array(); -$config->zin->zuiPath = isset($config->zuiPath) ? $config->zuiPath : ($app->getWebRoot() . 'js/zui3/'); + $config->zin->lang = $app->getClientLang(); + $config->zin->wgVer = isset($config->wgVer) ? $config->wgVer : '1'; + $config->zin->wgVerMap = isset($config->wgVerMap) ? $config->wgVerMap : array(); + $config->zin->zuiPath = isset($config->zuiPath) ? $config->zuiPath : ($app->getWebRoot() . 'js/zui3/'); +} diff --git a/lib/zin/core/wg.class.php b/lib/zin/core/wg.class.php index 7d68e8cebc..6370a2c056 100644 --- a/lib/zin/core/wg.class.php +++ b/lib/zin/core/wg.class.php @@ -188,6 +188,7 @@ class wg $result = str_replace('', $rawContent, $result); } + ob_start(); echo $result; $this->displayed = true; diff --git a/lib/zin/wg/mainnavbar/v1.php b/lib/zin/wg/mainnavbar/v1.php index 5b6fa06061..854dd1e7fb 100644 --- a/lib/zin/wg/mainnavbar/v1.php +++ b/lib/zin/wg/mainnavbar/v1.php @@ -42,9 +42,10 @@ class mainNavbar extends nav $currentMethod = $app->getMethodName(); if($app->tab == 'admin') $app->control->loadModel('admin')->setMenu(); - commonModel::setMainMenu(); - $activeMenu = commonModel::printMainMenu(false); + \commonModel::setMainMenu(); + $activeMenu = \commonModel::printMainMenu(false); $items = \customModel::getModuleMenu($activeMenu); + if($items) { $items = json_decode(json_encode($items), true); diff --git a/module/common/model.php b/module/common/model.php index d703e035fd..10f97a1fba 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -13,23 +13,6 @@ class commonModel extends model { public static $requestErrors = array(); - /** - * The construc method, to do some auto things. - * - * @access public - * @return void - */ - public function __construct() - { - parent::__construct(); - if(!defined('FIRST_RUN')) - { - define('FIRST_RUN', true); - $this->app->loadLang('company'); - $this->setUserConfig(); - } - } - /** * Set config of user. * diff --git a/module/user/model.php b/module/user/model.php index b03b26e536..3d30e45872 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -1365,15 +1365,12 @@ class userModel extends model $fails ++; if($fails < $this->config->user->failTimes) { - $locked = '0000-00-00 00:00:00'; - $failTimes = $fails; + $this->dao->update(TABLE_USER)->set('fails')->eq($fails)->set('locked = NULL')->where('account')->eq($account)->exec(); } else { - $locked = date('Y-m-d H:i:s'); - $failTimes = 0; + $this->dao->update(TABLE_USER)->set('fails')->eq(0)->set('locked')->eq(date('Y-m-d H:i:s'))->where('account')->eq($account)->exec(); } - $this->dao->update(TABLE_USER)->set('fails')->eq($failTimes)->set('locked')->eq($locked)->where('account')->eq($account)->exec(); return $fails; }