Skip to content

Commit

Permalink
add configediter
Browse files Browse the repository at this point in the history
  • Loading branch information
skywalker512 committed Jul 7, 2018
1 parent e9a572d commit 40a9b4f
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 0 deletions.
37 changes: 37 additions & 0 deletions addons/plugins/ConfigEditor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.buildpath
.project
.settings
.htaccess

# Compiled source
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases
*.log
*.sql
*.sqlite

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
*~
62 changes: 62 additions & 0 deletions addons/plugins/ConfigEditor/ConfigAdminController.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
if (! defined ( "IN_ESOTALK" ))
exit ();
class ConfigAdminController extends ETAdminController {
protected function plugin() {
return ET::$plugins ["ConfigEditor"];
}
/*
* The index page.
* @return void
*/
public function action_index() {
$form = ETFactory::make ( "form" );
$form->action = URL ( "admin/config_editor/save" );
$config = file_get_contents ( PATH_CONFIG . '/config.php' );
if(R("loadbackup") == '1'){
if ($c = file_get_contents ( PATH_CONFIG . '/config_backup.php' )){
$config = $c;
$this->message("加载了上一次的备份。", "success");
}else{
$this->message("找不到备份。", "error");
}

}
$form->setValue ( "content", $config );
$this->data ( "form", $form );
$this->title = "编辑config.php";
$this->render ( $this->plugin ()->view ( "admin/edit" ) );
}
/*
* Save the config.php file and the backup.
* @return void
*/
public function action_save() {
if (! $this->validateToken ())
return;
$config = @file_get_contents ( PATH_CONFIG . '/config.php' );
$config_backup = @file_get_contents ( PATH_CONFIG . '/config_backup.php' );
$message = '';
if($config && $config != $config_backup){
//保存之前备份
if(file_force_contents(PATH_CONFIG. '/config_backup.php', $config))
$message .= '并保存了备份。';
}
if($content = R("content")){
if(file_force_contents(PATH_CONFIG. '/config.php', $content)){
//in SAE
if(!empty($_SERVER['HTTP_APPNAME'])){
$kv = new SaeKV();
// 初始化SaeKV对象
$kv->init();
// 删除key-value
$kv->delete('site_config');
}
$this->message("config.php写入成功!!".$message, "success");
}else{
$this->message("config.php写入失败!!", "error");
}
}
$this->redirect ( URL ( "admin/config_editor" ) );
}
}
Binary file added addons/plugins/ConfigEditor/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
36 changes: 36 additions & 0 deletions addons/plugins/ConfigEditor/plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
if (! defined ( "IN_ESOTALK" ))
exit ();

ET::$pluginInfo ["ConfigEditor"] = array (
"name" => "配置文件编辑器",
"description" => "允许管理员在控制面板编辑配置文件",
"version" => ESOTALK_VERSION,
"author" => "zgq354",
"authorEmail" => "[email protected]",
"authorURL" => "http://izgq.net",
"license" => "GPLv2",
"dependencies" => array (
"esoTalk" => "1.0.0g4"
)
);
class ETPlugin_ConfigEditor extends ETPlugin {
public function __construct($rootDirectory) {
parent::__construct ( $rootDirectory );
// Register the profiles admin controller which provides an interface for
// administrators to edit the config.php.
ETFactory::registerAdminController ( "config_editor", "ConfigAdminController", dirname ( __FILE__ ) . "/ConfigAdminController.class.php" );
}

/*
* |--------------------------------------------------------------------------
* | Admin Page
* |--------------------------------------------------------------------------
*/

// When initializing any admin controller, add a link to the Profiles admin page
// in the admin menu.
public function handler_initAdmin($sender, $menu) {
$menu->add ( "config_editor", "<a href='" . URL ( "admin/config_editor" ) . "'><i class='icon-gear'></i> " . T ( "配置文件编辑器" ) . "</a>" );
}
}
22 changes: 22 additions & 0 deletions addons/plugins/ConfigEditor/views/admin/edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
if (! defined ( "IN_ESOTALK" ))
exit ();

$form = $data ["form"];
?>

<div class='area'>

<h3>直接编辑config.php配置文件</h3>
<p>谨慎修改,提交之前千万要注意有没有语法错误等,若配置文件出错将导致整个网站包括管理页面不能打开!!</p>
<p>
<a href='?loadbackup=1' class="button">加载前一次的备份</a>
</p>
<?php echo $form->open(); ?>
<div>
<?php echo $form->input("content","textarea", array("rows" => "20", "tabindex" => 20, "style"=> 'width: 100%;')); ?>
</div>
<p style="margin-top: 10px;"><?php echo $form->saveButton(); ?></p>

<?php echo $form->close(); ?>
</div>

0 comments on commit 40a9b4f

Please sign in to comment.