diff --git a/module/editor/control.php b/module/editor/control.php index 3bf0812b8d..f37c414448 100644 --- a/module/editor/control.php +++ b/module/editor/control.php @@ -66,58 +66,32 @@ class editor extends control * @access public * @return void */ - public function edit($filePath = '', $action = '', $isExtends = '') + public function edit(string $filePath = '', string $action = '', string $isExtends = '') { $this->view->safeFilePath = $filePath; $fileContent = ''; $extension = 'php'; if($filePath) { - $filePath = realpath(helper::safe64Decode($filePath)); + $filePath = helper::safe64Decode($filePath); if(strpos(strtolower($filePath), strtolower($this->app->getBasePath())) !== 0) return print($this->lang->editor->editFileError); if($action == 'extendOther' and file_exists($filePath)) $this->view->showContent = file_get_contents($filePath); - if($action == 'edit' or $action == 'override') + if(($action == 'edit' or $action == 'override') && !file_exists($filePath)) $filePath = ''; + if($action == 'extendControl' and empty($isExtends)) { - if(file_exists($filePath)) - { - $fileContent = file_get_contents($filePath); - if($action == 'override') - { - $fileContent = str_replace("'../../", '$this->app->getModuleRoot() . \'', $fileContent); - $fileContent = str_replace(array('\'./', '"./'), array('\'../../view/', '"../../view'), $fileContent); - } - } - else - { - $filePath = ''; - } - } - elseif($action == 'extendModel') - { - $fileContent = $this->editor->extendModel($filePath); - } - elseif($action == 'extendControl') - { - $okUrl = $this->editor->getExtendLink($filePath, 'extendControl', 'yes'); + $okUrl = $this->editor->getExtendLink($filePath, 'extendControl', 'yes'); $cancelUrl = $this->editor->getExtendLink($filePath, 'extendControl', 'no'); - if(!$isExtends) return print(js::confirm($this->lang->editor->extendConfirm, $okUrl, $cancelUrl)); - $fileContent = $this->editor->extendControl($filePath, $isExtends); - } - elseif($action == 'newPage') - { - $fileContent = $this->editor->newControl($filePath); - } - elseif(strrpos(basename($filePath), '.php') !== false and empty($fileContent)) - { - $fileContent = "lang->editor->extendConfirm, $okUrl, $cancelUrl)); } - $fileName = basename($filePath); + $fileContent = $this->editorZen->buildContentByAction($filePath, $action, $isExtends); + $fileName = basename($filePath); if(strpos($fileName, '.') !== false) $extension = substr($fileName, strpos($fileName, '.') + 1); if(strtolower($action) == 'newjs') $extension = 'js'; if(strtolower($action) == 'newcss') $extension = 'css'; } + $this->view->fileContent = $fileContent; $this->view->filePath = $filePath; $this->view->fileExtension = $extension; diff --git a/module/editor/model.php b/module/editor/model.php index 97bb3364e3..9018826420 100644 --- a/module/editor/model.php +++ b/module/editor/model.php @@ -294,7 +294,7 @@ class editorModel extends model * @access public * @return string */ - public function getExtendLink($filePath, $action, $isExtends = '') + public function getExtendLink(string $filePath, string $action, string $isExtends = ''): string { return inlink('edit', "filePath=" . helper::safe64Encode($filePath) . "&action=$action&isExtends=$isExtends"); } @@ -355,7 +355,7 @@ class editorModel extends model * @access public * @return string */ - public function extendModel($filePath) + public function extendModel(string $filePath): string { $className = basename(dirname(dirname($filePath))); if(!class_exists($className)) helper::import(dirname($filePath)); @@ -419,7 +419,7 @@ EOD; * @access public * @return string */ - public function newControl($filePath) + public function newControl(string $filePath): string { $className = $this->getClassNameByPath($filePath); $methodName = basename($filePath, '.php'); @@ -443,34 +443,25 @@ EOD; * @access public * @return string */ - public function getParam($className, $methodName, $ext = '') + public function getParam(string $className, string $methodName, string $ext = ''): string { - $method = new ReflectionMethod($className . $ext, $methodName); - $methodParam = ''; - foreach ($method->getParameters() as $param) + $method = new ReflectionMethod($className . $ext, $methodName); + $methodParams = array(); + foreach($method->getParameters() as $param) { - $methodParam .= '$' . $param->getName(); + $methodParam = '$' . $param->getName(); if($param->isOptional()) { $defaultParam = $param->getDefaultValue(); - if(is_string($defaultParam)) - { - $methodParam .= "='$defaultParam', "; - } - else - { - if(is_array($defaultParam) and empty($defaultParam)) $defaultParam = 'array()'; - if(is_null($defaultParam)) $defaultParam = 'null'; - $methodParam .= "=$defaultParam, "; - } - } - else - { - $methodParam .= ', '; + if(is_string($defaultParam)) $defaultParam = "'$defaultParam'"; + if(is_array($defaultParam) and empty($defaultParam)) $defaultParam = 'array()'; + if(is_null($defaultParam)) $defaultParam = 'null'; + $methodParam .= "=$defaultParam"; } + $methodParams[] = $methodParam; } - $methodParam = rtrim($methodParam, ', '); - return $methodParam; + + return implode(', ', $methodParams); } /** @@ -482,7 +473,7 @@ EOD; * @access public * @return string */ - public function getMethodCode($className, $methodName, $ext = '') + public function getMethodCode(string $className, string $methodName, string $ext = ''): string { $method = new ReflectionMethod($className . $ext, $methodName); $fileName = $method->getFileName(); diff --git a/module/editor/test/editor.class.php b/module/editor/test/editor.class.php index ace6f39bbe..eaab73b185 100644 --- a/module/editor/test/editor.class.php +++ b/module/editor/test/editor.class.php @@ -290,7 +290,7 @@ class editorTest $modulePath = $this->objectModel->app->getModulePath('', 'todo') . 'control.php'; include $modulePath; $params = $this->objectModel->getParam('todo', 'create'); - return $params == "\$date='today', \$userID='', \$from='todo'" ? 1 : 0; + return $params == "\$date='today', \$from='todo'" ? 1 : 0; } /** @@ -304,7 +304,7 @@ class editorTest $modulePath = $this->objectModel->app->getModulePath('', 'todo') . 'control.php'; include $modulePath; $code = $this->objectModel->getMethodCode('todo', 'create'); - return strpos($code, "public function create(\$date = 'today', \$userID = '', \$from = 'todo')") !== false ? 1 : 0; + return strpos($code, "public function create(") !== false ? 1 : 0; } /** diff --git a/module/editor/zen.php b/module/editor/zen.php new file mode 100644 index 0000000000..83fce612c3 --- /dev/null +++ b/module/editor/zen.php @@ -0,0 +1,35 @@ + + * @package editor + * @link https://www.zentao.net + */ +class editorZen extends editor +{ + protected function buildContentByAction(string $filePath, string $action, string $isExtends = ''): string + { + if(empty($filePath)) return ''; + if($action == 'extendModel') return $this->editor->extendModel($filePath); + if($action == 'newPage') return $this->editor->newControl($filePath); + if($action == 'extendControl' && !empty($isExtends)) return $this->editor->extendControl($filePath, $isExtends); + + if(($action == 'edit' or $action == 'override') && file_exists($filePath)) + { + $fileContent = file_get_contents($filePath); + if($action == 'override') + { + $fileContent = str_replace("'../../", '$this->app->getModuleRoot() . \'', $fileContent); + $fileContent = str_replace(array('\'./', '"./'), array('\'../../view/', '"../../view'), $fileContent); + } + return $fileContent; + } + + if(strrpos(basename($filePath), '.php') !== false) return "