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 ? "\n" : "\n";
if($isRoot)
{
- $module = basename(dirname(key($files)));
-
- $langFile = dirname(key($files)) . DS . 'lang' . DS . $this->cookie->lang. '.php';
+ $module = basename(dirname(key($files)));
+ $langFile = dirname(key($files)) . DS . 'lang' . DS . $this->app->getClientLang() . '.php';
if(file_exists($langFile))
{
- if(!isset($lang)) $lang = $this->lang;
+ if(!isset($lang)) $lang = new stdclass();
if(!isset($lang->$module)) $lang->$module = new stdclass();
- include_once $langFile;
+ include $langFile;
}
- if(isset($lang->$module))
- {
- $this->module = $lang->$module;
- }
- elseif(isset($this->lang->$module))
- {
- $this->module = $this->lang->$module;
- }
- else
- {
- $this->module = '';
- }
+ $this->module = '';
+ if(isset($lang->$module)) $this->module = $lang->$module;
+ if(isset($this->lang->$module)) $this->module = $this->lang->$module;
}
+
foreach($files as $key => $file)
{
$tree .= "- \n";
@@ -220,20 +190,12 @@ class editorModel extends model
*/
public function addLink4Dir($filePath)
{
- $tree = '';
+ $tree = '';
$fileName = basename($filePath);
- if(isset($this->lang->editor->modules[$fileName]))
- {
- $file = "" . $this->lang->editor->modules[$fileName] . '';
- }
- elseif(isset($this->lang->editor->translate[$fileName]))
- {
- $file = "" . $this->lang->editor->translate[$fileName] . '';
- }
- else
- {
- $file = "$fileName";
- }
+ $file = "$fileName";
+ if(isset($this->lang->editor->modules[$fileName])) $file = "" . $this->lang->editor->modules[$fileName] . '';
+ if(isset($this->lang->editor->translate[$fileName])) $file = "" . $this->lang->editor->translate[$fileName] . '';
+
if(strpos($filePath, DS . 'ext' . DS) !== false)
{
switch($fileName)
@@ -284,7 +246,7 @@ class editorModel extends model
else
{
$parentDir = basename(dirname($filePath));
- $action = 'extendOther';
+ $action = 'extendOther';
if($parentDir == 'control.php') $action = 'extendControl';
if($parentDir == 'model.php') $action = 'extendModel';
@@ -329,18 +291,24 @@ class editorModel extends model
*
* @param string $filePath
* @access public
- * @return void
+ * @return bool
*/
public function save($filePath)
{
+ /* Reduce expiration time for check safe file. */
+ $this->config->safeFileTimeout = 15 * 60;
$statusFile = $this->loadModel('common')->checkSafeFile();
- if($statusFile) die(js::alert(sprintf($this->lang->editor->noticeOkFile, str_replace('\\', '/', $statusFile))));
+ if($statusFile)
+ {
+ print(js::alert(sprintf($this->lang->editor->noticeOkFile, str_replace('\\', '/', $statusFile))));
+ return false;
+ }
- $dirPath = dirname($filePath);
+ $dirPath = dirname($filePath);
$extFilePath = substr($filePath, 0, strpos($filePath, DS . 'ext' . DS) + 4);
if(!is_dir($dirPath) and is_writable($extFilePath)) mkdir($dirPath, 0777, true);
- if(!is_dir($dirPath) or !is_writable($dirPath)) die(js::alert($this->lang->editor->notWritable . $extFilePath));
- if(strpos(strtolower(realpath($dirPath)), strtolower($this->app->getBasePath())) !== 0) die(js::alert($this->lang->editor->editFileError));
+ if(!is_dir($dirPath) or !is_writable($dirPath)) return print(js::alert($this->lang->editor->notWritable . $extFilePath));
+ if(strpos(strtolower(realpath($dirPath)), strtolower($this->app->getBasePath())) !== 0) return print(js::alert($this->lang->editor->editFileError));
$fileContent = $this->post->fileContent;
$evils = array('eval', 'exec', 'passthru', 'proc_open', 'shell_exec', 'system', '$$', 'include', 'require', 'assert', 'javascript', 'onclick');
@@ -349,6 +317,7 @@ class editorModel extends model
if(get_magic_quotes_gpc()) $fileContent = stripslashes($fileContent);
file_put_contents($filePath, $fileContent);
+ return true;
}
/**
@@ -362,9 +331,10 @@ class editorModel extends model
{
$className = basename(dirname(dirname($filePath)));
if(!class_exists($className)) helper::import(dirname($filePath));
- $methodName = basename($filePath);
+
+ $methodName = basename($filePath);
$methodParam = $this->getParam($className, $methodName, 'Model');
- return $fileContent = <<getParam($className, $methodName);
- return $fileContent = <<getMethodCode($className, $methodName);
- return $fileContent = <<getFileName();
$startLine = $method->getStartLine();
$endLine = $method->getEndLine();
+
$file = file($fileName);
$code = '';
- for($i = $startLine - 1; $i <= $endLine; $i++)
- {
- $code .= $file[$i];
- }
+ for($i = $startLine - 1; $i <= $endLine; $i++) $code .= $file[$i];
return $code;
}
@@ -502,18 +470,23 @@ EOD;
*/
public function getSavePath($filePath, $action)
{
+ $fileExtension = 'php';
+ $sourceFileName = basename($filePath);
+ if(strpos($sourceFileName, '.') !== false) $fileExtension = substr($sourceFileName, strpos($sourceFileName, '.') + 1);
+
$fileName = empty($_POST['fileName']) ? '' : trim($this->post->fileName);
$moduleName = strstr($filePath, DS . 'module' . DS);
$moduleName = substr($moduleName, 0, strpos($moduleName, DS, 9));
$moduleName = basename($moduleName);
$extPath = $this->app->getExtensionRoot() . 'custom' . DS . $moduleName . DS . 'ext' . DS;
+ if($fileName and (strpos($fileName, '.' . $fileExtension) !== (strlen($fileName) - strlen($fileExtension) - 1))) $fileName .= '.' . $fileExtension;
switch($action)
{
case 'extendModel':
- $fileName = empty($fileName) ? strtolower(basename($filePath)) . '.php' : $fileName;
+ $fileName = empty($fileName) ? strtolower(basename($filePath)) . ".{$fileExtension}" : $fileName;
return $extPath . 'model' . DS . $fileName;
case 'extendControl':
- $fileName = strtolower(basename($filePath)) . '.php';
+ $fileName = strtolower(basename($filePath)) . ".{$fileExtension}";
return $extPath . 'control' . DS . $fileName;
case 'override':
$fileName = basename($filePath);
@@ -522,18 +495,19 @@ EOD;
$editName = basename($filePath);
$fileName = empty($fileName) ? $editName: $fileName;
if($editName == 'config.php') return $extPath . 'config' .DS . $fileName;
- elseif(strpos($editName, '.php') !== false) return $extPath . 'lang' . DS . str_replace('.php', '', $editName) . DS . $fileName;
- else return $extPath . substr($editName, strrpos($editName, '.') + 1) . DS . substr($editName, 0, strrpos($editName, '.')) . DS . $fileName;
+ if(strpos($editName, '.php') !== false) return $extPath . 'lang' . DS . basename($editName, ".{$fileExtension}") . DS . $fileName;
+ return $extPath . $fileExtension . DS . basename($editName, ".{$fileExtension}") . DS . $fileName;
default:
- if(empty($fileName)) die(js::error($this->lang->editor->emptyFileName));
+ if(empty($fileName)) return print(js::error($this->lang->editor->emptyFileName));
+
$action = strtolower(str_replace('new', '', $action));
- if($action == 'hook') return $extPath . 'view' . DS . $fileName;
- elseif($action == 'method') return $extPath . basename($filePath, '.php') . DS . $fileName;
- elseif($action == 'extend') return $filePath . DS . $fileName;
- elseif($action == 'config') return $extPath . 'config' . DS . $fileName;
- elseif($action == 'js') return $extPath . 'js' . DS . substr($fileName, 0, strrpos($fileName, '.')) . DS . $fileName;
- elseif($action == 'css') return $extPath . 'css' . DS . substr($fileName, 0, strrpos($fileName, '.')) . DS . $fileName;
- else return $extPath . 'lang' . DS . str_replace('_', '-', $action) . DS . $fileName;
+ if($action == 'hook') return $extPath . 'view' . DS . $fileName;
+ if($action == 'method') return $extPath . basename($filePath, ".{$fileExtension}") . DS . $fileName;
+ if($action == 'extend') return $filePath . DS . $fileName;
+ if($action == 'config') return $extPath . 'config' . DS . $fileName;
+ if($action == 'js') return $extPath . 'js' . DS . basename($fileName, ".{$fileExtension}") . DS . $fileName;
+ if($action == 'css') return $extPath . 'css' . DS . basename($fileName, ".{$fileExtension}") . DS . $fileName;
+ return $extPath . 'lang' . DS . str_replace('_', '-', $action) . DS . $fileName;
}
}
}
diff --git a/module/editor/view/edit.html.php b/module/editor/view/edit.html.php
index b53615b56b..d016de8ecd 100644
--- a/module/editor/view/edit.html.php
+++ b/module/editor/view/edit.html.php
@@ -10,6 +10,7 @@
* @link http://www.zentao.net
*/
?>
+
getModuleRoot() . 'common/view/header.lite.html.php';?>
-
+
+
|
-
-
|
+
|
@@ -123,7 +124,8 @@ $(function()
automaticLayout: true,
minimap: {enabled: false}
});
- var codeHeight = top.window.innerHeight - 300;
+ var codeHeight = top.window.innerHeight - 280;
+ if($('#fileNameBox').length == 0) codeHeight += 56;
contentHeight = showContentEditor.getContentHeight();
if(contentHeight > 300) contentHeight = 300;
|