diff --git a/module/editor/control.php b/module/editor/control.php index ea31e343df..54fc1bc61c 100644 --- a/module/editor/control.php +++ b/module/editor/control.php @@ -17,21 +17,45 @@ class editor extends control * @access public * @return void */ - public function index($editFileName = '', $action = '') + public function index($filePath = '', $action = '', $isExtends = '') { $allModules = $this->editor->getModuleFiles(); - $this->view->tree = $this->editor->printTree($allModules); - $editFileName = helper::safe64Decode($editFileName); + $this->view->tree = $this->editor->printTree($allModules); + $this->view->safeFilePath = $filePath; + $filePath = helper::safe64Decode($filePath); $fileContent = ''; - if($editFileName and file_exists($editFileName)) + if($filePath) { - if($action == 'edit') + if($action == 'extendOther' and file_exists($filePath)) { - $fileContent = file_get_contents($editFileName); + $this->view->showContent = htmlspecialchars(file_get_contents($filePath)); + } + elseif($action == 'edit' or $action == 'override') + { + if(file_exists($filePath)) + { + $fileContent = file_get_contents($filePath); + } + else + { + $filePath = ''; + } + } + elseif($action == 'extendModel') + { + $fileContent = $this->editor->extendModel($filePath); + } + elseif($action == 'extendControl') + { + $okUrl = $this->editor->getExtendLink($filePath, 'extendControl', 'yes'); + $cancelUrl = $this->editor->getExtendLink($filePath, 'extendControl', 'no'); + if(!$isExtends) die(js::confirm($this->lang->editor->extendConfirm, $okUrl, $cencelUrl)); + $fileContent = $this->editor->extendControl($filePath); } } $this->view->fileContent = $fileContent; - $this->view->filePath = empty($fileContent) ? '' : $editFileName; + $this->view->filePath = $filePath; + $this->view->action = $action; $this->display(); } @@ -42,13 +66,15 @@ class editor extends control * @access public * @return void */ - public function save($filePath = '') + public function save($filePath = '', $action = '') { if($filePath and $_POST) { $filePath = helper::safe64Decode($filePath); + if($action != 'edit') $filePath = $this->editor->getSavePath($filePath, $action); + if($action != 'edit' and file_exists($filePath) and !$this->post->override) die(js::error($this->lang->editor->repeatFile)); $this->editor->save($filePath); - die(js::reload('parent')); + die(js::locate(inlink('index', "filePath=" . helper::safe64Encode($filePath) . "&action=edit"), 'parent')); } } @@ -68,7 +94,7 @@ class editor extends control } $filePath = helper::safe64Decode($filePath); if(file_exists($filePath) and unlink($filePath)) die(js::reload('parent')); - die(js::alert($this->lang->editor->noDelete)); + die(js::alert($this->lang->editor->notDelete)); } } diff --git a/module/editor/lang/en.php b/module/editor/lang/en.php new file mode 100644 index 0000000000..1da62d26f5 --- /dev/null +++ b/module/editor/lang/en.php @@ -0,0 +1,27 @@ +editor->newMethod = 'New method'; +$lang->editor->extend = 'Extend'; +$lang->editor->newLang = 'New language'; +$lang->editor->newConfig = 'New config'; +$lang->editor->newHook = 'New hook'; +$lang->editor->newExtend = 'Nwe extend'; +$lang->editor->cover = 'Cover'; +$lang->editor->edit = 'Edit extend'; + +$lang->editor->filePath = "File Path:"; +$lang->editor->fileName = "Extend file name:"; +$lang->editor->fileContent = "File content"; +$lang->editor->overrideFile = "Override File"; +$lang->editor->isOverride = "Is override"; +$lang->editor->exampleHook = "For example:***.html.hook.php"; +$lang->editor->exampleJs = "For example:***.js"; +$lang->editor->exampleCss = "For example:***.css"; +$lang->editor->examplePHP = "For example:***.php"; + +$lang->editor->deleteConfirm = 'Are you sure?'; +$lang->editor->extendConfirm = 'Would you reuse the code.'; +$lang->editor->repeatFile = 'File name repeat'; + +$lang->editor->notWritable = "Can't writable, maybe no power. please try chmod 777 -R "; +$lang->editor->notDelete = "Can't delete, please check power!"; +$lang->editor->emptyFileName = 'Please write file name'; diff --git a/module/editor/lang/zh-cn.php b/module/editor/lang/zh-cn.php new file mode 100644 index 0000000000..88b0d12866 --- /dev/null +++ b/module/editor/lang/zh-cn.php @@ -0,0 +1,27 @@ +editor->newMethod = '新增方法'; +$lang->editor->extend = '扩展'; +$lang->editor->newLang = '新增语言'; +$lang->editor->newConfig = '新增配置'; +$lang->editor->newHook = '新增钩子'; +$lang->editor->newExtend = '新增扩展'; +$lang->editor->override = '覆盖'; +$lang->editor->edit = '编辑扩展'; + +$lang->editor->filePath = "文件路径:"; +$lang->editor->fileName = "扩展文件名:"; +$lang->editor->fileContent = "文件内容:"; +$lang->editor->overrideFile = "覆盖文件"; +$lang->editor->isOverride = "是否覆盖"; +$lang->editor->exampleHook = "例如:***.html.hook.php"; +$lang->editor->exampleJs = "例如:***.js"; +$lang->editor->exampleCss = "例如:***.css"; +$lang->editor->examplePHP = "例如:***.php"; + +$lang->editor->deleteConfirm = '是否要删除?'; +$lang->editor->extendConfirm = '是否要重用原来代码?'; +$lang->editor->repeatFile = '文件名重复'; + +$lang->editor->notWritable = "无法写入,可能没有权限。请尝试执行 chmod 777 -R "; +$lang->editor->notDelete = '无法删除,请检查权限!'; +$lang->editor->emptyFileName = '请写入一个文件名!'; diff --git a/module/editor/model.php b/module/editor/model.php index 8f608254cf..48fd99e0fa 100644 --- a/module/editor/model.php +++ b/module/editor/model.php @@ -14,7 +14,6 @@ class editorModel extends model /** * Get module files, contain control's methods and model's method but except ext. * - * @param string $moduleRoot * @access public * @return array */ @@ -42,7 +41,8 @@ class editorModel extends model } elseif(is_dir($moduleFullFile)) { - foreach(glob($moduleFullFile . '/' . '*.php') as $fileName) $allModules[$moduleFullDir][$moduleFullFile][$fileName] = basename($fileName); + $ext = ($moduleFile == 'js' or $moduleFile == 'css') ? $moduleFile : 'php'; + foreach(glob($moduleFullFile . '/' . "*.$ext") as $fileName) $allModules[$moduleFullDir][$moduleFullFile][$fileName] = basename($fileName); } else { @@ -74,23 +74,8 @@ class editorModel extends model /* extend of lang is more a grade of directroy. */ if($extensionDir == 'lang' or $extensionDir == 'js' or $extensionDir == 'css') { - $langDirs = scandir($extensionFullDir); - foreach($langDirs as $langDir) - { - if($langDir == '.' or $langDir == '..' or $langDir == '.svn') continue; - $langFullDir = $extensionFullDir . '/' . $langDir; - $extensionList[$extensionFullDir][$langFullDir] = array(); - if(is_dir($langFullDir)) - { - $langFiles = scandir($langFullDir); - foreach($langFiles as $langFile) - { - if($langFile == '.' or $langFile == '..' or $langFile == '.svn') continue; - $langFullFile = $langFullDir . '/' . $langFile; - $extensionList[$extensionFullDir][$langFullDir][$langFullFile] = $langFile; - } - } - } + + $extensionList[$extensionFullDir] = $this->getTwoGradeFiles($extensionFullDir); continue; } $extensionFiles = scandir($extensionFullDir); @@ -105,6 +90,36 @@ class editorModel extends model return $extensionList; } + /** + * if a directory has two grage, this method will get files + * + * @param string $extensionFullDir + * @access public + * @return string + */ + public function getTwoGradeFiles($extensionFullDir) + { + $fileList = array(); + $langDirs = scandir($extensionFullDir); + foreach($langDirs as $langDir) + { + if($langDir == '.' or $langDir == '..' or $langDir == '.svn') continue; + $langFullDir = $extensionFullDir . '/' . $langDir; + $fileList[$langFullDir] = array(); + if(is_dir($langFullDir)) + { + $langFiles = scandir($langFullDir); + foreach($langFiles as $langFile) + { + if($langFile == '.' or $langFile == '..' or $langFile == '.svn') continue; + $langFullFile = $langFullDir . '/' . $langFile; + $fileList[$langFullDir][$langFullFile] = $langFile; + } + } + } + return $fileList; + } + /** * Analysis methods of control and model. * @@ -125,7 +140,7 @@ class editorModel extends model { $methodName = $method->name; if($method->getFileName() != $fileName) continue; - $classMethod[$methodName] = $methodName; + $classMethod[$fileName . '/' . $methodName] = $methodName; } return $classMethod; } @@ -146,19 +161,12 @@ class editorModel extends model $tree .= "
| + |
|
- editor->editFile,$filePath)?> - + |