* Refactoring for extension.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
$lang->mainNav->menuOrder = array();
|
||||
$lang->mainNav->menuOrder[5] = 'my';
|
||||
$lang->mainNav->menuOrder[20] = 'project';
|
||||
$lang->mainNav->menuOrder[35] = 'doc';
|
||||
$lang->mainNav->menuOrder[45] = 'system';
|
||||
$lang->mainNav->menuOrder[65] = 'admin';
|
||||
@@ -479,20 +479,14 @@ class baseControl
|
||||
|
||||
if(!empty($cssExtPath))
|
||||
{
|
||||
$cssMethodExt = $cssExtPath['common'] . $methodName . DS;
|
||||
$cssCommonExt = $cssExtPath['common'] . 'common' . DS;
|
||||
|
||||
$cssExtFiles = glob($cssCommonExt . $devicePrefix . '*.css');
|
||||
if(!empty($cssExtFiles) and is_array($cssExtFiles)) $css .= $this->getExtCSS($cssExtFiles);
|
||||
|
||||
$cssExtFiles = glob($cssMethodExt . $devicePrefix . '*.css');
|
||||
if(!empty($cssExtFiles) and is_array($cssExtFiles)) $css .= $this->getExtCSS($cssExtFiles);
|
||||
|
||||
if(!empty($cssExtPath['site']))
|
||||
foreach($cssExtPath as $cssPath)
|
||||
{
|
||||
$cssMethodExt = $cssExtPath['site'] . $methodName . DS;
|
||||
$cssCommonExt = $cssExtPath['site'] . 'common' . DS;
|
||||
$cssExtFiles = glob($cssCommonExt . $devicePrefix . '*.css');
|
||||
if(empty($cssPath)) continue;
|
||||
|
||||
$cssMethodExt = $cssPath . $methodName . DS;
|
||||
$cssCommonExt = $cssPath . 'common' . DS;
|
||||
|
||||
$cssExtFiles = glob($cssCommonExt . $devicePrefix . '*.css');
|
||||
if(!empty($cssExtFiles) and is_array($cssExtFiles)) $css .= $this->getExtCSS($cssExtFiles);
|
||||
|
||||
$cssExtFiles = glob($cssMethodExt . $devicePrefix . '*.css');
|
||||
@@ -579,19 +573,12 @@ class baseControl
|
||||
|
||||
if(!empty($jsExtPath))
|
||||
{
|
||||
$jsMethodExt = $jsExtPath['common'] . $methodName . DS;
|
||||
$jsCommonExt = $jsExtPath['common'] . 'common' . DS;
|
||||
|
||||
$jsExtFiles = glob($jsCommonExt . $this->devicePrefix . '*.js');
|
||||
if(!empty($jsExtFiles) and is_array($jsExtFiles)) foreach($jsExtFiles as $jsFile) $js .= file_get_contents($jsFile);
|
||||
|
||||
$jsExtFiles = glob($jsMethodExt . $this->devicePrefix . '*.js');
|
||||
if(!empty($jsExtFiles) and is_array($jsExtFiles)) foreach($jsExtFiles as $jsFile) $js .= file_get_contents($jsFile);
|
||||
|
||||
if(!empty($jsExtPath['site']))
|
||||
foreach($jsExtPath as $jsPath)
|
||||
{
|
||||
$jsMethodExt = $jsExtPath['site'] . $methodName . DS;
|
||||
$jsCommonExt = $jsExtPath['site'] . 'common' . DS;
|
||||
if(empty($jsPath)) continue;
|
||||
|
||||
$jsMethodExt = $jsPath . $methodName . DS;
|
||||
$jsCommonExt = $jsPath . 'common' . DS;
|
||||
|
||||
$jsExtFiles = glob($jsCommonExt . $this->devicePrefix . '*.js');
|
||||
if(!empty($jsExtFiles) and is_array($jsExtFiles)) foreach($jsExtFiles as $jsFile) $js .= file_get_contents($jsFile);
|
||||
|
||||
@@ -202,6 +202,21 @@ class baseHelper
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用helper::importControl()来引入Control文件,不要直接使用include或者require.
|
||||
* Using helper::importControl() to import a file, instead of include or require.
|
||||
*
|
||||
* @param string $moduleName.
|
||||
* @static
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
static public function importControl($moduleName)
|
||||
{
|
||||
global $app;
|
||||
return helper::import($app->getModulePath($moduleName) . 'control.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数组或者列表转化成 IN( 'a', 'b') 的形式。
|
||||
* Convert a list to IN('a', 'b') string.
|
||||
|
||||
@@ -406,6 +406,9 @@ class baseRouter
|
||||
if($this->config->framework->autoConnectDB) $this->connectDB();
|
||||
if($this->config->framework->multiLanguage) $this->setClientLang();
|
||||
|
||||
$this->setEdition();
|
||||
$this->setVision();
|
||||
|
||||
$needDetectDevice = zget($this->config->framework->detectDevice, $this->clientLang, false);
|
||||
$this->clientDevice = $needDetectDevice ? $this->setClientDevice() : 'desktop';
|
||||
|
||||
@@ -665,6 +668,34 @@ class baseRouter
|
||||
if(!empty($this->config->debug)) error_reporting(E_ALL & ~ E_STRICT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置版本。
|
||||
* Set edition.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function setEdition()
|
||||
{
|
||||
$edition = substr($this->config->version, 0, 3);
|
||||
if(in_array($edition, array('pro', 'biz', 'max'))) return $this->config->edition = $edition;
|
||||
$this->config->edition = 'open';
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置vision。
|
||||
* set Debug.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function setVision()
|
||||
{
|
||||
$account = isset($_SESSION['user']) ? $_SESSION['user']->account : '';
|
||||
$vision = $this->dbh->query("SELECT * FROM " . TABLE_CONFIG . " WHERE owner = '$account' AND `key` = 'vision' LIMIT 1")->fetch();
|
||||
$this->config->vision = $vision ? $vision->value : 'common';
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置错误处理句柄。
|
||||
* Set the error handler.
|
||||
@@ -812,6 +843,18 @@ class baseRouter
|
||||
return dirname($this->moduleRoot) . DS . $appName . DS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取扩展根目录。
|
||||
* Get the root of extension.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getExtensionRoot()
|
||||
{
|
||||
return $this->basePath . 'extension' . DS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取$webRoot,即应用的路径。
|
||||
* Get the $webRoot var.
|
||||
@@ -1284,7 +1327,7 @@ class baseRouter
|
||||
*/
|
||||
public function setControlFile($exitIfNone = true)
|
||||
{
|
||||
$this->controlFile = $this->moduleRoot . $this->moduleName . DS . 'control.php';
|
||||
$this->controlFile = $this->getModulePath() . 'control.php';
|
||||
if(file_exists($this->controlFile)) return true;
|
||||
$this->triggerError("the control file $this->controlFile not found.", __FILE__, __LINE__, $exitIfNone);
|
||||
}
|
||||
@@ -1314,11 +1357,30 @@ class baseRouter
|
||||
public function getModulePath($appName = '', $moduleName = '')
|
||||
{
|
||||
if($moduleName == '') $moduleName = $this->moduleName;
|
||||
$moduleName = strtolower($moduleName);
|
||||
|
||||
if($this->checkModuleName($moduleName))
|
||||
{
|
||||
$modulePath = $this->getModuleRoot($appName) . strtolower($moduleName) . DS;
|
||||
return $modulePath;
|
||||
/* 1. 如果通用版本里有此模块,优先使用。 If module is in the open edition, use it. */
|
||||
$modulePath = $this->getModuleRoot($appName) . $moduleName . DS;
|
||||
if(is_dir($modulePath)) return $modulePath;
|
||||
|
||||
/* 2. 尝试查找商业版本是否有此模块。 Try to find the module in other editon. */
|
||||
if($this->config->edition != 'open')
|
||||
{
|
||||
$modulePath = $this->getExtensionRoot() . $this->config->edition . DS . $moduleName . DS;
|
||||
if(is_dir($modulePath)) return $modulePath;
|
||||
}
|
||||
|
||||
/* 3. 如果设置过vision,尝试在vision中查找。 If vision is set, try to find the module in the vision. */
|
||||
if($this->config->vision != 'common')
|
||||
{
|
||||
$modulePath = $this->getExtensionRoot() . $this->config->vision . DS . $moduleName . DS;
|
||||
if(is_dir($modulePath)) return $modulePath;
|
||||
}
|
||||
|
||||
/* 4. 最后尝试在定制开发中寻找。 Finally, try to find the module in the custom dir. */
|
||||
return $this->getExtensionRoot() . 'custom' . DS . $moduleName . DS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1340,14 +1402,16 @@ class baseRouter
|
||||
/* 检查失败或者extensionLevel为0,直接返回空。If check failed or extensionLevel == 0, return empty array. */
|
||||
if(!$this->checkModuleName($moduleName) or $this->config->framework->extensionLevel == 0) return array();
|
||||
|
||||
/* When extensionLevel == 1. */
|
||||
$modulePath = $this->getModulePath($appName, $moduleName);
|
||||
$paths = array();
|
||||
$paths['common'] = $modulePath . 'ext' . DS . $ext . DS;
|
||||
|
||||
/* When extensionLevel == 1. */
|
||||
$paths['common'] = $this->config->edition != 'open' ? $this->getExtensionRoot() . $this->config->edition . DS . $moduleName . DS . 'ext' . DS . $ext . DS : '';
|
||||
$paths['vision'] = $this->config->vision == 'common' ? '' : $this->basePath . 'extension' . DS . $this->config->vision . DS . $moduleName . DS . 'ext' . DS . $ext . DS;
|
||||
$paths['custom'] = $this->getExtensionRoot() . 'custom' . DS . $moduleName . DS . 'ext' . DS . $ext . DS;
|
||||
if($this->config->framework->extensionLevel == 1) return $paths;
|
||||
|
||||
/* When extensionLevel == 2. */
|
||||
$paths['site'] = empty($this->siteCode) ? '' : $modulePath . 'ext' . DS . '_' . $this->siteCode . DS . $ext . DS;
|
||||
$paths['site'] = empty($this->siteCode) ? '' : $this->getExtensionRoot() . $this->config->edition . DS . $moduleName . DS . 'ext' . DS . '_' . $this->siteCode . DS . $ext . DS;
|
||||
return $paths;
|
||||
}
|
||||
|
||||
@@ -1396,14 +1460,22 @@ class baseRouter
|
||||
/* 如果扩展目录为空,不包含任何扩展文件。If there's no ext paths return false.*/
|
||||
if(empty($moduleExtPaths)) return false;
|
||||
|
||||
/* 如果extensionLevel == 2,且扩展文件存在,返回该站点扩展文件。If extensionLevel == 2 and site extensionFile exists, return it. */
|
||||
/* 1. 如果extensionLevel == 2,且扩展文件存在,返回该站点扩展文件。 If extensionLevel == 2 and site extensionFile exists, return it. */
|
||||
if($this->config->framework->extensionLevel == 2 and !empty( $moduleExtPaths['site']))
|
||||
{
|
||||
$this->extActionFile = $moduleExtPaths['site'] . $this->methodName . '.php';
|
||||
if(file_exists($this->extActionFile)) return true;
|
||||
}
|
||||
|
||||
/* 然后再尝试寻找公共扩展文件。Then try to find the common extension file. */
|
||||
/* 2. 尝试在定制开发目录寻找扩展文件。Then try to find the custom extension file. */
|
||||
$this->extActionFile = $moduleExtPaths['custom'] . $this->methodName . '.php';
|
||||
if(file_exists($this->extActionFile)) return true;;
|
||||
|
||||
/* 3. 如果设置过vision,尝试在vision中查找扩展文件。If vision is set, try to find the vision extension file. */
|
||||
if($moduleExtPaths['vision']) $this->extActionFile = $moduleExtPaths['vision'] . $this->methodName . '.php';
|
||||
if(file_exists($this->extActionFile)) return true;;
|
||||
|
||||
/* 4. 最后尝试寻找公共扩展文件。Finally, try to find the common extension file. */
|
||||
$this->extActionFile = $moduleExtPaths['common'] . $this->methodName . '.php';
|
||||
return file_exists($this->extActionFile);
|
||||
}
|
||||
@@ -2186,7 +2258,12 @@ class baseRouter
|
||||
|
||||
/* 查找扩展配置文件。Get extension config files. */
|
||||
if($config->framework->extensionLevel > 0) $extConfigPath = $this->getModuleExtPath($appName, $moduleName, 'config');
|
||||
if($config->framework->extensionLevel >= 1 and !empty($extConfigPath['common'])) $commonExtConfigFiles = helper::ls($extConfigPath['common'], '.php');
|
||||
if($config->framework->extensionLevel >= 1)
|
||||
{
|
||||
if(!empty($extConfigPath['common'])) $commonExtConfigFiles = helper::ls($extConfigPath['common'], '.php');
|
||||
if(!empty($extConfigPath['vision'])) $commonExtConfigFiles = array_merge($commonExtConfigFiles, helper::ls($extConfigPath['vision'], '.php'));
|
||||
if(!empty($extConfigPath['custom'])) $commonExtConfigFiles = array_merge($commonExtConfigFiles, helper::ls($extConfigPath['custom'], '.php'));
|
||||
}
|
||||
if($config->framework->extensionLevel == 2 and !empty($extConfigPath['site'])) $siteExtConfigFiles = helper::ls($extConfigPath['site'], '.php');
|
||||
$extConfigFiles = array_merge($commonExtConfigFiles, $siteExtConfigFiles);
|
||||
|
||||
@@ -2301,7 +2378,12 @@ class baseRouter
|
||||
$siteExtLangFiles = array();
|
||||
|
||||
$extLangPath = $this->getModuleExtPath($appName, $moduleName, 'lang');
|
||||
if($this->config->framework->extensionLevel >= 1 and !empty($extLangPath['common'])) $commonExtLangFiles = helper::ls($extLangPath['common'] . $this->clientLang, '.php');
|
||||
if($this->config->framework->extensionLevel >= 1)
|
||||
{
|
||||
if(!empty($extLangPath['common'])) $commonExtLangFiles = helper::ls($extLangPath['common'] . $this->clientLang, '.php');
|
||||
if(!empty($extLangPath['vision'])) $commonExtLangFiles = array_merge($commonExtLangFiles, helper::ls($extLangPath['vision'] . $this->clientLang, '.php'));
|
||||
if(!empty($extLangPath['custom'])) $commonExtLangFiles = array_merge($commonExtLangFiles, helper::ls($extLangPath['custom'] . $this->clientLang, '.php'));
|
||||
}
|
||||
if($this->config->framework->extensionLevel == 2 and !empty($extLangPath['site'])) $siteExtLangFiles = helper::ls($extLangPath['site'] . $this->clientLang, '.php');
|
||||
$extLangFiles = array_merge($commonExtLangFiles, $siteExtLangFiles);
|
||||
}
|
||||
|
||||
@@ -173,18 +173,43 @@ class control extends baseControl
|
||||
if(!empty($viewExtPath))
|
||||
{
|
||||
$commonExtViewFile = $viewExtPath['common'] . $this->devicePrefix . $methodName . ".{$viewType}.php";
|
||||
$visionExtViewFile = $viewExtPath['vision'] . $this->devicePrefix . $methodName . ".{$viewType}.php";
|
||||
$customExtViewFile = $viewExtPath['custom'] . $this->devicePrefix . $methodName . ".{$viewType}.php";
|
||||
$siteExtViewFile = empty($viewExtPath['site']) ? '' : $viewExtPath['site'] . $this->devicePrefix . $methodName . ".{$viewType}.php";
|
||||
|
||||
$viewFile = file_exists($commonExtViewFile) ? $commonExtViewFile : $mainViewFile;
|
||||
$viewFile = (!empty($siteExtViewFile) and file_exists($siteExtViewFile)) ? $siteExtViewFile : $viewFile;
|
||||
if(!is_file($viewFile))
|
||||
/* Get ext files, site > custom > vision > common. */
|
||||
if(!empty($siteExtViewFile) and file_exists($siteExtViewFile))
|
||||
{
|
||||
die(js::error($this->lang->notPage) . js::locate('back'));
|
||||
$viewFile = $siteExtViewFile;
|
||||
}
|
||||
else if(file_exists($customExtViewFile))
|
||||
{
|
||||
$viewFile = $customExtViewFile;
|
||||
}
|
||||
else if(!empty($viewExtPath['vision']) and file_exists($visionExtViewFile))
|
||||
{
|
||||
$viewFile = $visionExtViewFile;
|
||||
}
|
||||
else if(file_exists($commonExtViewFile))
|
||||
{
|
||||
$viewFile = $commonExtViewFile;
|
||||
}
|
||||
|
||||
$commonExtHookFiles = glob($viewExtPath['common'] . $this->devicePrefix . $methodName . ".*.{$viewType}.hook.php");
|
||||
$siteExtHookFiles = empty($viewExtPath['site']) ? '' : glob($viewExtPath['site'] . $this->devicePrefix . $methodName . ".*.{$viewType}.hook.php");
|
||||
$extHookFiles = array_merge((array) $commonExtHookFiles, (array) $siteExtHookFiles);
|
||||
if(!is_file($viewFile)) die(js::error($this->lang->notPage) . js::locate('back'));
|
||||
|
||||
/* Get ext hook files. */
|
||||
if(empty($viewExtPath['vision']))
|
||||
{
|
||||
$commonExtHookFiles = glob($viewExtPath['common'] . $this->devicePrefix . $methodName . ".*.{$viewType}.hook.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
$commonExtHookFiles = glob($viewExtPath['vision'] . $this->devicePrefix . $methodName . ".*.{$viewType}.hook.php");
|
||||
}
|
||||
$customExtHookFiles = glob($viewExtPath['custom'] . $this->devicePrefix . $methodName . ".*.{$viewType}.hook.php");
|
||||
|
||||
$siteExtHookFiles = empty($viewExtPath['site']) ? '' : glob($viewExtPath['site'] . $this->devicePrefix . $methodName . ".*.{$viewType}.hook.php");
|
||||
$extHookFiles = array_merge((array)$commonExtHookFiles, (array)$customExtHookFiles, (array)$siteExtHookFiles);
|
||||
}
|
||||
|
||||
if(!empty($extHookFiles)) return array('viewFile' => $viewFile, 'hookFiles' => $extHookFiles);
|
||||
|
||||
@@ -301,6 +301,7 @@ class router extends baseRouter
|
||||
/* 初始化数组。Init the variables. */
|
||||
$extConfigFiles = array();
|
||||
$commonExtConfigFiles = array();
|
||||
$visionExtConfigFiles = array();
|
||||
$siteExtConfigFiles = array();
|
||||
|
||||
/* 先获得模块的主配置文件。Get the main config file for current module first. */
|
||||
@@ -308,9 +309,13 @@ class router extends baseRouter
|
||||
|
||||
/* 查找扩展配置文件。Get extension config files. */
|
||||
if($config->framework->extensionLevel > 0) $extConfigPath = $this->getModuleExtPath($appName, $moduleName, 'config');
|
||||
if($config->framework->extensionLevel >= 1 and !empty($extConfigPath['common'])) $commonExtConfigFiles = helper::ls($extConfigPath['common'], '.php');
|
||||
if($config->framework->extensionLevel >= 1)
|
||||
{
|
||||
if(!empty($extConfigPath['common'])) $commonExtConfigFiles = helper::ls($extConfigPath['common'], '.php');
|
||||
if(!empty($extConfigPath['vision'])) $visionExtConfigFiles = array_merge($commonExtConfigFiles, helper::ls($extConfigPath['common'], '.php'));
|
||||
}
|
||||
if($config->framework->extensionLevel == 2 and !empty($extConfigPath['site'])) $siteExtConfigFiles = helper::ls($extConfigPath['site'], '.php');
|
||||
$extConfigFiles = array_merge($commonExtConfigFiles, $siteExtConfigFiles);
|
||||
$extConfigFiles = array_merge($commonExtConfigFiles, $visionExtConfigFiles, $siteExtConfigFiles);
|
||||
|
||||
/* 将主配置文件和扩展配置文件合并在一起。Put the main config file and extension config files together. */
|
||||
$configFiles = array_merge(array($mainConfigFile), $extConfigFiles);
|
||||
|
||||
@@ -259,7 +259,7 @@ class commonModel extends model
|
||||
{
|
||||
/* Get configs of system and current user. */
|
||||
$account = isset($this->app->user->account) ? $this->app->user->account : '';
|
||||
if($this->config->db->name) $config = $this->loadModel('setting')->getSysAndPersonalConfig($account);
|
||||
if($this->config->db->name) $config = $this->loadModel('setting')->getSysAndPersonalConfig($account);
|
||||
$this->config->system = isset($config['system']) ? $config['system'] : array();
|
||||
$this->config->personal = isset($config[$account]) ? $config[$account] : array();
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ $app = router::createApp('pms', dirname(dirname(__FILE__)), 'router');
|
||||
/* installed or not. */
|
||||
if(!isset($config->installed) or !$config->installed) die(header('location: install.php'));
|
||||
|
||||
|
||||
/* Run the app. */
|
||||
$common = $app->loadCommon();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user