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'] = '
点此删除';
}
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');
}
}