diff --git a/module/editor/control.php b/module/editor/control.php index 44c0c2aca6..ea31e343df 100644 --- a/module/editor/control.php +++ b/module/editor/control.php @@ -17,11 +17,59 @@ class editor extends control * @access public * @return void */ - public function index() + public function index($editFileName = '', $action = '') { $allModules = $this->editor->getModuleFiles(); - $this->view->tree = $this->editor->printTree($allModules); + $this->view->tree = $this->editor->printTree($allModules); + $editFileName = helper::safe64Decode($editFileName); + $fileContent = ''; + if($editFileName and file_exists($editFileName)) + { + if($action == 'edit') + { + $fileContent = file_get_contents($editFileName); + } + } + $this->view->fileContent = $fileContent; + $this->view->filePath = empty($fileContent) ? '' : $editFileName; $this->display(); } + + /** + * Save file to extension. + * + * @param string $filePath + * @access public + * @return void + */ + public function save($filePath = '') + { + if($filePath and $_POST) + { + $filePath = helper::safe64Decode($filePath); + $this->editor->save($filePath); + die(js::reload('parent')); + } + } + + /** + * Delete extension file. + * + * @param string $filePath + * @param string $confirm + * @access public + * @return void + */ + public function delete($filePath = '', $confirm = 'no') + { + if($confirm == 'no') + { + die(js::confirm($this->lang->editor->deleteConfirm, inlink('delete', "filePath=$filePath&confirm=yes"))); + } + $filePath = helper::safe64Decode($filePath); + if(file_exists($filePath) and unlink($filePath)) die(js::reload('parent')); + die(js::alert($this->lang->editor->noDelete)); + + } } diff --git a/module/editor/model.php b/module/editor/model.php index af4d0452a9..2b6ebcf03b 100644 --- a/module/editor/model.php +++ b/module/editor/model.php @@ -34,21 +34,77 @@ class editorModel extends model $moduleFullFile = $moduleFullDir . '/' . $moduleFile; if($moduleFile == 'control.php' or $moduleFile == 'model.php') { - $allModules[$moduleDir][$moduleFullFile] = $this->analysis($moduleFullFile); + $allModules[$moduleFullDir][$moduleFullFile] = $this->analysis($moduleFullFile); + } + elseif($moduleFile == 'ext') + { + $allModules[$moduleFullDir][$moduleFullFile] = $this->getExtensionFiles($moduleFullFile); } elseif(is_dir($moduleFullFile)) { - foreach(glob($moduleFullFile . '/' . '*.php') as $fileName) $allModules[$moduleDir][$moduleFile][$fileName] = basename($fileName); + foreach(glob($moduleFullFile . '/' . '*.php') as $fileName) $allModules[$moduleFullDir][$moduleFullFile][$fileName] = basename($fileName); } else { - $allModules[$moduleDir][$moduleFullFile] = $moduleFile; + $allModules[$moduleFullDir][$moduleFullFile] = $moduleFile; } } } return $allModules; } + /** + * Get extension files. + * + * @param int $extPath + * @access public + * @return void + */ + public function getExtensionFiles($extPath) + { + $extensionList = array(); + $extensionDirs = scandir($extPath); + foreach($extensionDirs as $extensionDir) + { + if($extensionDir == '.' or $extensionDir == '..' or $extensionDir == '.svn') continue; + $extensionFullDir = $extPath . '/' . $extensionDir; + if(is_dir($extensionFullDir)) + { + $extensionList[$extensionFullDir] = array(); + /* extend of lang is more a grade of directroy. */ + if($extensionDir == 'lang') + { + $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; + } + } + } + continue; + } + $extensionFiles = scandir($extensionFullDir); + foreach($extensionFiles as $extensionFile) + { + if($extensionFile == '.' or $extensionFile == '..' or $extensionFile == '.svn') continue; + $extensionFullFile = $extensionFullDir . '/' . $extensionFile; + $extensionList[$extensionFullDir][$extensionFullFile] = $extensionFile; + } + } + } + return $extensionList; + } + /** * Analysis methods of control and model. * @@ -95,11 +151,39 @@ class editorModel extends model } else { - $tree .= $file . "\n"; + if(strpos($key, '/ext/') !== false) + { + $tree .= $file . html::a(inlink('index', "editFileName=" . helper::safe64Encode($key) . "&action=edit"), $this->lang->edit) . html::a(inlink('delete', 'path=' . helper::safe64Encode($key)), $this->lang->delete, 'hiddenwin') . "\n"; + } + else + { + $tree .= $file . "\n"; + } } $tree .= "\n"; } $tree .= "\n"; return $tree; } + + /** + * Save file to extension. + * + * @param string $filePath + * @access public + * @return void + */ + public function save($filePath) + { + $fileContent = $this->post->fileContent; + if(get_magic_quotes_gpc()) $fileContent = stripslashes($fileContent); + if(is_writable($filePath)) + { + file_put_contents($filePath, $fileContent); + } + else + { + die(js::alert($this->lang->editor->noWritable)); + } + } } diff --git a/module/editor/view/index.html.php b/module/editor/view/index.html.php index abbe68d358..cc9c268bf6 100644 --- a/module/editor/view/index.html.php +++ b/module/editor/view/index.html.php @@ -13,13 +13,20 @@
|
-
- - |
-- | -
|
+
+ + |
+ + editor->editFile,$filePath)?> + + | +