123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- /*
- |--------------------------------------------------------------------------
- | config.php 后台管理 基本配置管理
- |--------------------------------------------------------------------------
- */
- namespace MazeApp\Manage;
- use Maze;
- use Maze\Security\Internal;
- Maze::load('manage/auth.init');
- class Config
- {
- /**
- * project
- *
- * @var string
- */
- private $project;
- /**
- * dir
- *
- * @var string
- */
- protected $type;
-
- /**
- * config
- *
- * @var array
- */
- protected $config;
- /**
- * __construct
- *
- * @return mixed
- */
- public function __construct()
- {
- $this->project = Maze::input('key');
- $this->type = Maze::input('type', 'config');
-
- $config = Maze::load('manage/project.get');
- if(isset($config[$this->project]))
- {
- $this->config = $config[$this->project];
- }
-
- $type = array('config', 'view', 'database', 'api');
- if(!in_array($this->type, $type))
- {
- Maze::out('error');
- }
- }
-
- /**
- * get
- *
- * @return mixed
- */
- public function get()
- {
- $dir = Maze::input('dir');
- $name = Maze::input('name');
-
- if($dir && $name)
- {
- $dir = $dir . '/' . $name;
- }
- else
- {
- $dir = $this->type;
- }
- Maze::setInput('dir', $dir);
-
- $result = $this->read($dir);
-
- return $result;
- }
-
- /**
- * read
- * @param string $dir
- *
- * @return mixed
- */
- private function read($dir)
- {
- $file = $this->dir($dir);
- if(is_dir($file))
- {
- $result = scandir($file);
- foreach($result as $k => $v)
- {
- if($v == '.' || $v == '..')
- {
- unset($result[$k]);
- }
- }
-
- return $result;
- }
- elseif(is_file($file))
- {
- Maze::$global['temp']['delete'] = '';
- $data_dir = $this->dir($dir, 'data/');
- if(is_file($data_dir))
- {
- $file = $data_dir;
- $name = str_replace(MAZE_PATH, '', $file);
- $md5 = Internal::encode($name);
- $delete = Maze::url('config.del?file=' . $name . '&md5=' . $md5);
- Maze::$global['temp']['delete'] = '<br /><a href="'.$delete.'" class="oper_6">点此删除</a>';
- }
- else
- {
- $name = str_replace(MAZE_PATH, '', $file);
- $md5 = Internal::encode($name);
- }
- $result[] = array('content' => file_get_contents($file), 'file' => $name, 'md5' => $md5, 'key' => $this->project);
-
- return $result;
- }
- else
- {
- Maze::out('error');
- }
- }
-
- /**
- * dir
- * @param string $dir
- *
- * @return mixed
- */
- private function dir($dir, $path = '')
- {
- if(!$this->config['path'])
- {
-
- }
- if($path)
- {
- return Maze::path(MAZE_PATH . $path, $this->config['path'] . $dir);
- }
- return MAZE_PATH . $this->config['path'] . $dir;
- }
- /**
- * set 将内容写入到配置文件中(备份)
- *
- * @return string
- */
- public function set()
- {
- $file = Maze::input('file');
- $value = Maze::input('value');
- $name = Maze::input('name');
- $md5 = Internal::decode(Maze::input('md5'));
- if($file == $md5)
- {
- $file = MAZE_PATH . $file;
- if(is_file($file))
- {
- file_put_contents($this->dir($name, 'data/'), $value);
- }
- }
- highlight_string($value);die;
- }
- /**
- * del 删除后台建立的内容
- *
- * @return mixed
- */
- public function del()
- {
- $file = Maze::input('file');
- $md5 = Internal::decode(Maze::input('md5'));
- if(strpos($file, 'data/') !== false && $file == $md5)
- {
- $file = MAZE_PATH . $file;
- if(is_file($file))
- {
- @unlink($file);
- }
- }
- Maze::out('yes');
- }
- }
|