* mereg zentaophp framework to zentao.

This commit is contained in:
wangyidong
2017-06-09 17:06:18 +08:00
parent c27f1f7d34
commit a37df65bc8
11 changed files with 1514 additions and 1364 deletions
+156 -61
View File
@@ -1,8 +1,9 @@
<?php
/**
<?php /**
* ZenTaoPHP的baseControl类。
* The baseControl class file of ZenTaoPHP framework.
*
* @package framework
*
* The author disclaims copyright to this source code. In place of
* a legal notice, here is a blessing:
*
@@ -10,13 +11,6 @@
* May you find forgiveness for yourself and forgive others.
* May you share freely, never taking more than you give.
*/
/**
* baseControl基类.
* The base class of control.
*
* @package framework
*/
class baseControl
{
/**
@@ -254,8 +248,8 @@ class baseControl
}
/**
* set the method name.
* 设置方法名。
* Set the method name.
*
* @param string $methodName 方法名,如果为空,则从$app中获取。The method name, if empty, get it from $app.
* @access public
@@ -279,7 +273,7 @@ class baseControl
{
if(empty($moduleName)) $moduleName = $this->moduleName;
if(empty($appName)) $appName = $this->appName;
$modelFile = helper::setModelFile($moduleName, $appName);
$modelFile = $this->app->setModelFile($moduleName, $appName);
/**
* 如果没有model文件,尝试加载config配置信息。
@@ -287,7 +281,7 @@ class baseControl
*/
if(!helper::import($modelFile))
{
$this->app->loadConfig($moduleName, $appName, false);
$this->app->loadModuleConfig($moduleName, $appName, false);
$this->app->loadLang($moduleName, $appName);
$this->dao = new dao();
return false;
@@ -308,7 +302,10 @@ class baseControl
* 初始化model对象,在control对象中可以通过$this->$moduleName来引用。同时将dao对象赋为control对象的成员变量,方便引用。
* Init the model object thus you can try $this->$moduleName to access it. Also assign the $dao object as a member of control object.
*/
$this->$moduleName = new $modelClass($appName);
static $singleModule = array();
if(!isset($singleModule["$moduleName"])) $singleModule["$moduleName"] = new $modelClass($appName);
$this->$moduleName = $singleModule["$moduleName"];
$this->dao = $this->$moduleName->dao;
return $this->$moduleName;
}
@@ -327,7 +324,6 @@ class baseControl
$this->server = $this->app->server;
$this->session = $this->app->session;
$this->cookie = $this->app->cookie;
$this->global = $this->app->global;
}
/**
@@ -372,19 +368,24 @@ class baseControl
$modulePath = $this->app->getModulePath($this->appName, $moduleName);
$viewExtPath = $this->app->getModuleExtPath($this->appName, $moduleName, 'view');
$viewType = $this->viewType == 'mhtml' ? 'html' : $this->viewType;
$mainViewFile = $modulePath . 'view' . DS . $this->devicePrefix . $methodName . '.' . $viewType . '.php';
$commonExtViewFile = $viewExtPath['common'] . $this->devicePrefix . $methodName . ".{$viewType}.php";
$siteExtViewFile = empty($viewExtPath['site']) ? '' : $viewExtPath['site'] . $this->devicePrefix . $methodName . ".{$viewType}.php";
$viewType = $this->viewType == 'mhtml' ? 'html' : $this->viewType;
$mainViewFile = $modulePath . 'view' . DS . $this->devicePrefix . $methodName . '.' . $viewType . '.php';
$viewFile = $mainViewFile;
$viewFile = file_exists($commonExtViewFile) ? $commonExtViewFile : $mainViewFile;
$viewFile = (!empty($siteExtViewFile) and file_exists($siteExtViewFile)) ? $siteExtViewFile : $viewFile;
if(!is_file($viewFile)) $this->app->triggerError("the view file $viewFile not found", __FILE__, __LINE__, $exit = true);
if(!empty($viewExtPath))
{
$commonExtViewFile = $viewExtPath['common'] . $this->devicePrefix . $methodName . ".{$viewType}.php";
$siteExtViewFile = empty($viewExtPath['site']) ? '' : $viewExtPath['site'] . $this->devicePrefix . $methodName . ".{$viewType}.php";
$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);
$viewFile = file_exists($commonExtViewFile) ? $commonExtViewFile : $mainViewFile;
$viewFile = (!empty($siteExtViewFile) and file_exists($siteExtViewFile)) ? $siteExtViewFile : $viewFile;
if(!is_file($viewFile)) $this->app->triggerError("the view file $viewFile not found", __FILE__, __LINE__, $exit = true);
$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(!empty($extHookFiles)) return array('viewFile' => $viewFile, 'hookFiles' => $extHookFiles);
return $viewFile;
@@ -404,9 +405,9 @@ class baseControl
* 首先找sitecode下的扩展文件,如果没有,再找ext下的扩展文件。
* Find extViewFile in ext/_$siteCode/view first, then try ext/view/.
*/
if($this->config->site->code)
if($this->app->siteCode)
{
$extPath = dirname(dirname(realpath($viewFile))) . "/ext/_{$this->config->site->code}/view";
$extPath = dirname(dirname(realpath($viewFile))) . "/ext/_{$this->app->siteCode}/view";
$extViewFile = $extPath . basename($viewFile);
if(file_exists($extViewFile))
@@ -442,8 +443,6 @@ class baseControl
$modulePath = $this->app->getModulePath($this->appName, $moduleName);
$cssExtPath = $this->app->getModuleExtPath($this->appName, $moduleName, 'css') ;
$cssMethodExt = $cssExtPath['common'] . $methodName . DS;
$cssCommonExt = $cssExtPath['common'] . 'common' . DS;
$css = '';
$mainCssFile = $modulePath . 'css' . DS . $this->devicePrefix . 'common.css';
@@ -451,21 +450,27 @@ class baseControl
if(file_exists($mainCssFile)) $css .= file_get_contents($mainCssFile);
if(is_file($methodCssFile)) $css .= file_get_contents($methodCssFile);
$cssExtFiles = glob($cssCommonExt . $this->devicePrefix . '*.css');
if(!empty($cssExtFiles) and is_array($cssExtFiles)) foreach($cssExtFiles as $cssFile) $css .= file_get_contents($cssFile);
$cssExtFiles = glob($cssMethodExt . $this->devicePrefix . '*.css');
if(!empty($cssExtFiles) and is_array($cssExtFiles)) foreach($cssExtFiles as $cssFile) $css .= file_get_contents($cssFile);
if(!empty($cssExtPath['site']))
if(!empty($cssExtPath))
{
$cssMethodExt = $cssExtPath['site'] . $methodName . DS;
$cssCommonExt = $cssExtPath['site'] . 'common' . DS;
$cssMethodExt = $cssExtPath['common'] . $methodName . DS;
$cssCommonExt = $cssExtPath['common'] . 'common' . DS;
$cssExtFiles = glob($cssCommonExt . $this->devicePrefix . '*.css');
if(!empty($cssExtFiles) and is_array($cssExtFiles)) foreach($cssExtFiles as $cssFile) $css .= file_get_contents($cssFile);
$cssExtFiles = glob($cssMethodExt . $this->devicePrefix . '*.css');
if(!empty($cssExtFiles) and is_array($cssExtFiles)) foreach($cssExtFiles as $cssFile) $css .= file_get_contents($cssFile);
if(!empty($cssExtPath['site']))
{
$cssMethodExt = $cssExtPath['site'] . $methodName . DS;
$cssCommonExt = $cssExtPath['site'] . 'common' . DS;
$cssExtFiles = glob($cssCommonExt . $this->devicePrefix . '*.css');
if(!empty($cssExtFiles) and is_array($cssExtFiles)) foreach($cssExtFiles as $cssFile) $css .= file_get_contents($cssFile);
$cssExtFiles = glob($cssMethodExt . $this->devicePrefix . '*.css');
if(!empty($cssExtFiles) and is_array($cssExtFiles)) foreach($cssExtFiles as $cssFile) $css .= file_get_contents($cssFile);
}
}
return $css;
@@ -487,8 +492,6 @@ class baseControl
$modulePath = $this->app->getModulePath($this->appName, $moduleName);
$jsExtPath = $this->app->getModuleExtPath($this->appName, $moduleName, 'js');
$jsMethodExt = $jsExtPath['common'] . $methodName . DS;
$jsCommonExt = $jsExtPath['common'] . 'common' . DS;
$js = '';
$mainJsFile = $modulePath . 'js' . DS . $this->devicePrefix . 'common.js';
@@ -496,24 +499,30 @@ class baseControl
if(file_exists($mainJsFile)) $js .= file_get_contents($mainJsFile);
if(is_file($methodJsFile)) $js .= file_get_contents($methodJsFile);
$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']))
if(!empty($jsExtPath))
{
$jsMethodExt = $jsExtPath['site'] . $methodName . DS;
$jsCommonExt = $jsExtPath['site'] . 'common' . DS;
$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']))
{
$jsMethodExt = $jsExtPath['site'] . $methodName . DS;
$jsCommonExt = $jsExtPath['site'] . '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);
}
}
return $js;
}
@@ -588,7 +597,7 @@ class baseControl
$output['data'] = json_encode($this->view);
$output['md5'] = md5(json_encode($this->view));
$this->output = json_encode($output);
$this->output = json_encode($output);
}
/**
@@ -659,6 +668,10 @@ class baseControl
*/
public function fetch($moduleName = '', $methodName = '', $params = array(), $appName = '')
{
/**
* 如果模块名为空,则调用该模块、该方法。
* If the module name is empty, then use the current module and method.
*/
if($moduleName == '') $moduleName = $this->moduleName;
if($methodName == '') $methodName = $this->methodName;
if($appName == '') $appName = $this->appName;
@@ -668,20 +681,47 @@ class baseControl
return $this->output;
}
$currentModuleName = $this->moduleName;
$currentMethodName = $this->methodName;
$currentAppName = $this->appName;
/**
* 设置调用指定模块的指定方法。
* chang the dir to the previous.
*/
$this->app->setModuleName($moduleName);
$this->app->setMethodName($methodName);
if(!is_array($params)) parse_str($params, $params);
$currentPWD = getcwd();
/**
* 设置引用的文件和路径。
* Set the pathes and files to included.
**/
*/
$modulePath = $this->app->getModulePath($appName, $moduleName);
$moduleControlFile = $modulePath . 'control.php';
$actionExtPath = $this->app->getModuleExtPath($appName, $moduleName, 'control');
$file2Included = $moduleControlFile;
$commonActionExtFile = $actionExtPath['common'] . strtolower($methodName) . '.php';
$file2Included = file_exists($commonActionExtFile) ? $commonActionExtFile : $moduleControlFile;
if(!empty($actionExtPath['site']))
if(!empty($actionExtPath))
{
$siteActionExtFile = $actionExtPath['site'] . strtolower($methodName) . '.php';
$file2Included = file_exists($siteActionExtFile) ? $siteActionExtFile : $file2Included;
/**
* 设置公共扩展。
* set common extension.
*/
$commonActionExtFile = $actionExtPath['common'] . strtolower($methodName) . '.php';
$file2Included = file_exists($commonActionExtFile) ? $commonActionExtFile : $moduleControlFile;
if(!empty($actionExtPath['site']))
{
/**
* 设置站点扩展。
* every site has it's extension.
*/
$siteActionExtFile = $actionExtPath['site'] . strtolower($methodName) . '.php';
$file2Included = file_exists($siteActionExtFile) ? $siteActionExtFile : $file2Included;
}
}
/**
@@ -689,7 +729,6 @@ class baseControl
* Load the control file.
*/
if(!is_file($file2Included)) $this->app->triggerError("The control file $file2Included not found", __FILE__, __LINE__, $exit = true);
$currentPWD = getcwd();
chdir(dirname($file2Included));
if($moduleName != $this->moduleName) helper::import($file2Included);
@@ -704,7 +743,6 @@ class baseControl
* 解析参数,创建模块control对象。
* Parse the params, create the $module control object.
*/
if(!is_array($params)) parse_str($params, $params);
$module = new $className($moduleName, $methodName, $appName);
/**
@@ -715,13 +753,70 @@ class baseControl
call_user_func_array(array($module, $methodName), $params);
$output = ob_get_contents();
ob_end_clean();
unset($module);
/**
* 切换回之前的模块和方法。
* Chang the module、method to the previous.
*/
$this->app->setModuleName($currentModuleName);
$this->app->setMethodName($currentMethodName);
$currentClassName = class_exists("my$currentModuleName") ? "my$currentModuleName" : $currentModuleName;
if(!class_exists($currentClassName)) $this->app->triggerError(" The class $currentClassName not found", __FILE__, __LINE__, $exit = true);
/* include default value for module*/
$defaultValueFiles = glob($this->app->getTmpRoot() . "defaultvalue/*.php");
if($defaultValueFiles) foreach($defaultValueFiles as $file) include $file;
/*
* 使用反射机制获取函数参数的默认值。
* Get the default settings of the method to be called using the reflecting.
*
* */
$defaultParams = array();
$methodReflect = new reflectionMethod($currentClassName, $currentMethodName);
foreach($methodReflect->getParameters() as $param)
{
$name = $param->getName();
$default = '_NOT_SET';
if(isset($paramDefaultValue[$currentAppName][$currentClassName][$currentMethodName][$name]))
{
$default = $paramDefaultValue[$currentAppName][$currentClassName][$currentMethodName][$name];
}
elseif(isset($paramDefaultValue[$currentClassName][$currentMethodName][$name]))
{
$default = $paramDefaultValue[$currentClassName][$currentMethodName][$name];
}
elseif($param->isDefaultValueAvailable())
{
$default = $param->getDefaultValue();
}
$defaultParams[$name] = $default;
}
/**
* 根据PATH_INFO或者GET方式设置请求的参数。
* Set params according PATH_INFO or GET.
*/
if($this->config->requestType != 'GET')
{
$this->app->setParamsByPathInfo($defaultParams);
}
else
{
$this->app->setParamsByGET($defaultParams);
}
chdir($currentPWD);
/**
* 返回内容。
* Return the content.
*/
unset($module);
chdir($currentPWD);
return $output;
}
@@ -754,7 +849,7 @@ class baseControl
if($type != 'json') die();
$data = (array) $data;
if(helper::isAjaxRequest()) print(json_encode($data)) and die(helper::removeUTF8Bom(ob_get_clean()));
if(helper::isAjaxRequest() or $this->viewType == 'json') print(json_encode($data)) and die(helper::removeUTF8Bom(ob_get_clean()));
/**
* 响应非ajax的请求。
File diff suppressed because it is too large Load Diff
+22 -19
View File
@@ -3,6 +3,8 @@
* ZenTaoPHP的baseModel类。
* The baseModel class file of ZenTaoPHP framework.
*
* @package framework
*
* The author disclaims copyright to this source code. In place of
* a legal notice, here is a blessing:
*
@@ -10,13 +12,6 @@
* May you find forgiveness for yourself and forgive others.
* May you share freely, never taking more than you give.
*/
/**
* baseModel基类。
* The base class of model.
*
* @package framework
*/
class baseModel
{
/**
@@ -150,8 +145,8 @@ class baseModel
$this->appName = empty($appName) ? $this->app->getAppName() : $appName;
$moduleName = $this->getModuleName();
$this->app->loadLang($moduleName, $this->appName);
$this->app->loadConfig($moduleName, $this->appName, $exitIfNone = false);
if($this->config->framework->multiLanguage) $this->app->loadLang($moduleName, $this->appName);
if($moduleName != 'common') $this->app->loadModuleConfig($moduleName, $this->appName, $exitIfNone = false);
$this->loadDAO();
$this->setSuperVars();
@@ -196,7 +191,6 @@ class baseModel
$this->server = $this->app->server;
$this->cookie = $this->app->cookie;
$this->session = $this->app->session;
$this->global = $this->app->global;
}
/**
@@ -213,7 +207,7 @@ class baseModel
{
if(empty($moduleName)) return false;
if(empty($appName)) $appName = $this->appName;
$modelFile = helper::setModelFile($moduleName, $appName);
$modelFile = $this->app->setModelFile($moduleName, $appName);
if(!helper::import($modelFile)) return false;
$modelClass = class_exists('ext' . $appName . $moduleName. 'model') ? 'ext' . $appName . $moduleName . 'model' : $appName . $moduleName . 'model';
@@ -228,8 +222,17 @@ class baseModel
}
/**
* 加载model的class扩展。
* Load extension class of a model. Saved to $moduleName/ext/model/class/$extensionName.class.php.
* 加载model的class扩展,主要是为了开发加密代码使用。
* 可以将主要的逻辑存放到$moduleName/ext/model/class/$extensionName.class.php中。
* 然后在ext/model/$extension.php的扩展里面使用$this->loadExtension()来调用相应的方法。
* ext/model/class/*.class.php代码可以加密。而ext/model/*.php可以不用加密。
* 因为框架对model的扩展是采取合并文件的方式,ext/model/*.php文件不能加密。
*
* Load extension class of a model thus user can encrypt the code.
* You can put the main extension logic codes in $moduleName/ext/model/class/$extensionName.class.php.
* And call them by the ext/model/$extension.php like this: $this->loadExtension('myextension')->method().
* You can encrypt the code in ext/model/class/*.class.php.
* Because the framework will merge the extension files in ext/model/*.php to the module/model.php.
*
* @param string $extensionName
* @param string $moduleName
@@ -240,22 +243,22 @@ class baseModel
{
if(empty($extensionName)) return false;
/* Set extenson name and extension file. */
/* 设置扩展的名字和相应的文件。Set extenson name and extension file. */
$extensionName = strtolower($extensionName);
$moduleName = $moduleName ? $moduleName : $this->getModuleName();
$moduleExtPath = $this->app->getModuleExtPath($this->appName, $moduleName, 'model');
if(!empty($moduleExtPath['site']))$extensionFile = $moduleExtPath['site'] . 'class/' . $extensionName . '.class.php';
if(!empty($moduleExtPath['site'])) $extensionFile = $moduleExtPath['site'] . 'class/' . $extensionName . '.class.php';
if(!isset($extensionFile) or !file_exists($extensionFile)) $extensionFile = $moduleExtPath['common'] . 'class/' . $extensionName . '.class.php';
/* Try to import parent model file auto and then import the extension file. */
/* 载入父类。Try to import parent model file auto and then import the extension file. */
if(!class_exists($moduleName . 'Model')) helper::import($this->app->getModulePath($this->appName, $moduleName) . 'model.php');
if(!helper::import($extensionFile)) return false;
/* Set the extension class name. */
/* 设置扩展类的名字。Set the extension class name. */
$extensionClass = $extensionName . ucfirst($moduleName);
if(!class_exists($extensionClass)) return false;
/* Create an instance of the extension class and return it. */
/* 实例化扩展类。Create an instance of the extension class and return it. */
$extensionObject = new $extensionClass;
$extensionClass = str_replace('Model', '', $extensionClass);
$this->$extensionClass = $extensionObject;
@@ -275,7 +278,7 @@ class baseModel
}
/**
* 删除记录
* 删除记录。
* Delete one record.
*
* @param string $table the table name
File diff suppressed because it is too large Load Diff
+12
View File
@@ -112,3 +112,15 @@ class helper extends baseHelper
return $string;
}
}
/**
* 检查是否是onlybody模式。
* Check exist onlybody param.
*
* @access public
* @return void
*/
function isonlybody()
{
return helper::inOnlyBodyMode();
}
+31 -1
View File
@@ -77,7 +77,32 @@ class router extends baseRouter
$lang->projectCommon = isset($this->config->projectCommonList[$this->clientLang][(int)$projectCommon]) ? $this->config->projectCommonList[$this->clientLang][(int)$projectCommon] : $this->config->projectCommonList['zh-cn'][0];
}
return parent::loadLang($moduleName, $appName);
parent::loadLang($moduleName, $appName);
/* Merge from the db lang. */
if($moduleName != 'common' and isset($lang->db->custom[$moduleName]))
{
foreach($lang->db->custom[$moduleName] as $section => $fields)
{
if(isset($lang->{$moduleName}->{$section}['']))
{
$nullKey = '';
$nullValue = $lang->{$moduleName}->{$section}[$nullKey];
}
elseif(isset($lang->{$moduleName}->{$section}[0]))
{
$nullKey = 0;
$nullValue = $lang->{$moduleName}->{$section}[0];
}
unset($lang->{$moduleName}->{$section});
if(isset($nullKey))$lang->{$moduleName}->{$section}[$nullKey] = $nullValue;
foreach($fields as $key => $value) $lang->{$moduleName}->{$section}[$key] = $value;
unset($nullKey);
unset($nullValue);
}
}
return $lang;
}
/**
@@ -99,4 +124,9 @@ class router extends baseRouter
if(isset($fatalLevel[$level])) $this->config->debug = true;
parent::saveError($level, $message, $file, $line);
}
public function loadConfig($moduleName, $appName = '')
{
return parent::loadModuleConfig($moduleName, $appName);
}
}