From 1064bef3a7dc600b7889f6bc1691d2494a5c2b36 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Fri, 3 Mar 2023 14:19:31 +0800 Subject: [PATCH] * adjust code for editor. --- lib/zfile/zfile.class.php | 46 +++++----- module/editor/control.php | 36 ++++---- module/editor/model.php | 146 +++++++++++++------------------ module/editor/view/edit.html.php | 10 ++- 4 files changed, 107 insertions(+), 131 deletions(-) diff --git a/lib/zfile/zfile.class.php b/lib/zfile/zfile.class.php index cfa3ce58f8..1acd6ef771 100644 --- a/lib/zfile/zfile.class.php +++ b/lib/zfile/zfile.class.php @@ -13,11 +13,11 @@ class zfile { /** * Copy a directory from an directory to another directory. - * - * @param string $from - * @param string $to + * + * @param string $from + * @param string $to * @param bool $logLevel - * @param string $logFile + * @param string $logFile * @param array $excludeFiles * @param bool $toIsLink * @access public @@ -110,9 +110,9 @@ class zfile /** * Get count. - * - * @param string $dir - * @param array $excludeFiles + * + * @param string $dir + * @param array $excludeFiles * @access public * @return int */ @@ -136,8 +136,8 @@ class zfile /** * Remove a dir. - * - * @param string $dir + * + * @param string $dir * @access public * @return bool */ @@ -171,9 +171,9 @@ class zfile /** * Get files under a directory recursive. - * - * @param string $dir - * @param array $exceptions + * + * @param string $dir + * @param array $exceptions * @access private * @return array */ @@ -207,8 +207,8 @@ class zfile /** * Make a dir. - * - * @param string $dir + * + * @param string $dir * @access public * @return bool */ @@ -219,8 +219,8 @@ class zfile /** * Remove a file - * - * @param string $file + * + * @param string $file * @access public * @return bool */ @@ -232,7 +232,7 @@ class zfile /** * Batch remove files. use glob function. - * + * * @param string $patern * @access public * @return void @@ -245,7 +245,7 @@ class zfile /** * Remove a file - * + * * @param string from * @param string to * @access public @@ -258,7 +258,7 @@ class zfile /** * Rename a file or directory. - * + * * @param string from * @param string to * @access public @@ -271,8 +271,8 @@ class zfile /** * Get file size. - * - * @param string $file + * + * @param string $file * @access public * @return int */ @@ -283,10 +283,10 @@ class zfile /** * Get directory size. - * + * * @param string $dir * @access public - * @return int + * @return int */ public function getDirSize($dir) { diff --git a/module/editor/control.php b/module/editor/control.php index 21e88d7d7a..9e96b7c09f 100644 --- a/module/editor/control.php +++ b/module/editor/control.php @@ -74,10 +74,8 @@ class editor extends control { $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 == 'extendOther' and file_exists($filePath)) $this->view->showContent = file_get_contents($filePath); + if($action == 'edit' or $action == 'override') { if(file_exists($filePath)) @@ -141,7 +139,7 @@ class editor extends control if(file_exists($saveFilePath) and !$this->post->override) return print(js::confirm($this->lang->editor->repeatPage, $extendLink, '', 'parent')); return print(js::locate($extendLink, 'parent')); } - $this->view->filePath = $filePath; + $this->view->filePath = $filePath; $this->display(); } @@ -154,20 +152,13 @@ class editor extends control */ public function save($filePath = '', $action = '') { - /* Reduce expiration time for check safe file. */ - $this->config->safeFileTimeout = 15 * 60; - $statusFile = $this->loadModel('common')->checkSafeFile(); - if($statusFile) - { - return print(js::alert(sprintf($this->lang->editor->noticeOkFile, str_replace('\\', '/', $statusFile)))); - } if($filePath and $_POST) { $filePath = helper::safe64Decode($filePath); if(strpos(strtolower($filePath), strtolower($this->app->getBasePath())) !== 0) return print($this->lang->editor->editFileError); if($action != 'edit' and $action != 'newPage') $filePath = $this->editor->getSavePath($filePath, $action); if($action != 'edit' and $action != 'newPage' and file_exists($filePath) and !$this->post->override) return print(js::error($this->lang->editor->repeatFile)); - $this->editor->save($filePath); + if(!$this->editor->save($filePath)) return; echo js::reload('parent.parent.extendWin'); return print(js::locate(inlink('edit', "filePath=" . helper::safe64Encode($filePath) . "&action=edit"), 'parent')); } @@ -183,16 +174,25 @@ class editor extends control */ public function delete($filePath = '', $confirm = 'no') { - if($confirm == 'no') - { - return print(js::confirm($this->lang->editor->deleteConfirm, inlink('delete', "filePath=$filePath&confirm=yes"))); - } + if($confirm == 'no') return print(js::confirm($this->lang->editor->deleteConfirm, inlink('delete', "filePath=$filePath&confirm=yes"))); + $filePath = helper::safe64Decode($filePath); - if(file_exists($filePath) and unlink($filePath)) return print(js::reload('parent')); + if(file_exists($filePath) and unlink($filePath)) + { + echo js::locate(inlink('edit'), 'parent.parent.editWin'); + return print(js::reload('parent')); + } return print(js::alert($this->lang->editor->notDelete)); } + /** + * Switch editor feature. + * + * @param int $status 1|0 + * @access public + * @return void + */ public function switch($status) { $this->loadModel('setting')->setItem('system.common.global.editor', $status); diff --git a/module/editor/model.php b/module/editor/model.php index 9caf1e4ce1..ad1d5a2470 100644 --- a/module/editor/model.php +++ b/module/editor/model.php @@ -11,27 +11,6 @@ */ class editorModel extends model { - /** - * Get all modules - * - * @access public - * @return string - */ - public function getModules() - { - $modules = glob($this->app->getModuleRoot() . '*'); - $moduleList = "
"; - foreach($modules as $module) - { - $module = basename($module); - if($module == 'editor' or $module == 'help' or $module == 'setting') continue; - $moduleName = !empty($this->lang->editor->modules[$module]) ? $this->lang->editor->modules[$module] : $module; - $moduleList .= html::a(inlink('extend', "moduleDir=$module"), $moduleName, 'extendWin', "class='list-group-item'"); - } - $moduleList .= '
'; - return $moduleList; - } - /** * Get module files, contain control's methods and model's method but except ext. * @@ -100,19 +79,18 @@ class editorModel extends model */ public function getTwoGradeFiles($extensionFullDir) { + $zfile = $this->app->loadClass('zfile'); $fileList = array(); - $langDirs = scandir($extensionFullDir); + $langDirs = $zfile->readDir($extensionFullDir); foreach($langDirs as $langDir) { - if($langDir == '.' or $langDir == '..' or $langDir == '.svn') continue; $langFullDir = $extensionFullDir . DS . $langDir; $fileList[$langFullDir] = array(); if(is_dir($langFullDir)) { - $langFiles = scandir($langFullDir); + $langFiles = $zfile->readDir($langFullDir); foreach($langFiles as $langFile) { - if($langFile == '.' or $langFile == '..' or $langFile == '.svn') continue; $langFullFile = $langFullDir . DS . $langFile; $fileList[$langFullDir][$langFullFile] = $langFile; } @@ -131,7 +109,7 @@ class editorModel extends model public function analysis($fileName) { $classMethod = array(); - $class = strstr($fileName, DS . 'module' . DS); + $class = strstr($fileName, DS . 'module' . DS); if(empty($class)) { $class = strstr($fileName, DS . 'extension' . DS); @@ -167,32 +145,24 @@ class editorModel extends model public function printTree($files, $isRoot = true) { if(empty($files) or !is_array($files)) return false; + $tree = $isRoot ? "