From ffd58aebb71c1b963d1378afd5ff4d221cbc25be Mon Sep 17 00:00:00 2001 From: wangyidong Date: Tue, 1 Mar 2016 14:48:02 +0800 Subject: [PATCH] + add myrouter class. --- config/config.php | 5 +- framework/myrouter.class.php | 94 ++++++++++++++++++++++++++++++++++++ framework/router.class.php | 4 +- 3 files changed, 99 insertions(+), 4 deletions(-) create mode 100755 framework/myrouter.class.php diff --git a/config/config.php b/config/config.php index 4c207ae16a..4a18c538ba 100644 --- a/config/config.php +++ b/config/config.php @@ -107,8 +107,9 @@ $config->slaveDB->checkCentOS= true; /* Framework config. */ $config->framework = new stdclass(); -$config->framework->jsWithPrefix = false; -$config->framework->autoRepairTable = true; +$config->framework->jsWithPrefix = false; +$config->framework->autoRepairTable = true; +$config->framework->logDays = 14; /* Include the custom config file. */ $configRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR; diff --git a/framework/myrouter.class.php b/framework/myrouter.class.php new file mode 100755 index 0000000000..43207b18cd --- /dev/null +++ b/framework/myrouter.class.php @@ -0,0 +1,94 @@ +setModuleName('common'); + $commonModelFile = helper::setModelFile('common'); + if(file_exists($commonModelFile)) + { + helper::import($commonModelFile); + if(class_exists('extcommonModel')) + { + $commonClass = 'class common extends extcommonModel{}'; + eval($commonClass); + return new extcommonModel(); + } + elseif(class_exists('commonModel')) + { + $commonClass = 'class common extends commonModel{}'; + eval($commonClass); + return new commonModel(); + } + else + { + return false; + } + } + } + + public function loadLang($moduleName, $appName = '') + { + $modulePath = $this->getModulePath($appName, $moduleName); + $mainLangFile = $modulePath . 'lang' . DS . $this->clientLang . '.php'; + $extLangPath = $this->getModuleExtPath($appName, $moduleName, 'lang'); + $commonExtLangFiles = helper::ls($extLangPath['common'] . $this->clientLang, '.php'); + $siteExtLangFiles = helper::ls($extLangPath['site'] . $this->clientLang, '.php'); + $extLangFiles = array_merge($commonExtLangFiles, $siteExtLangFiles); + + /* Set the files to includ. */ + if(!is_file($mainLangFile)) + { + if(empty($extLangFiles)) return false; // also no extension file. + $langFiles = $extLangFiles; + } + else + { + $langFiles = array_merge(array($mainLangFile), $extLangFiles); + } + + global $lang; + if(!is_object($lang)) $lang = new language(); + + /* Set productCommon and projectCommon for flow. */ + if($moduleName == 'common') + { + $productProject = false; + if($this->dbh and !empty($this->config->db->name)) $productProject = $this->dbh->query('SELECT value FROM' . TABLE_CONFIG . "WHERE `owner`='system' AND `module`='custom' AND `key`='productproject'")->fetch(); + + $productCommon = $projectCommon = 0; + if($productProject) + { + $productProject = $productProject->value; + list($productCommon, $projectCommon) = explode('_', $productProject); + } + $lang->productCommon = isset($this->config->productCommonList[$this->clientLang][(int)$productCommon]) ? $this->config->productCommonList[$this->clientLang][(int)$productCommon] : $this->config->productCommonList['zh-cn'][0]; + $lang->projectCommon = isset($this->config->projectCommonList[$this->clientLang][(int)$projectCommon]) ? $this->config->projectCommonList[$this->clientLang][(int)$projectCommon] : $this->config->projectCommonList['zh-cn'][0]; + } + + static $loadedLangs = array(); + foreach($langFiles as $langFile) + { + if(in_array($langFile, $loadedLangs)) continue; + include $langFile; + $loadedLangs[] = $langFile; + } + + /* Merge from the db lang. */ + if($moduleName != 'common' and isset($lang->db->custom[$moduleName])) + { + foreach($lang->db->custom[$moduleName] as $section => $fields) + { + foreach($fields as $key => $value) + { + unset($lang->{$moduleName}->{$section}[$key]); + $lang->{$moduleName}->{$section}[$key] = $value; + } + } + } + + $this->lang = $lang; + return $lang; + } +} diff --git a/framework/router.class.php b/framework/router.class.php index 3926072079..da24a837e3 100644 --- a/framework/router.class.php +++ b/framework/router.class.php @@ -367,10 +367,10 @@ class router $this->setWwwRoot(); $this->setDataRoot(); - $this->filterSuperVars(); $this->setSuperVars(); - $this->loadConfig('common'); + $this->filterSuperVars(); + $this->setDebug(); $this->setErrorHandler();