a156ee761206cac01d09e2288dd45d347b5d9f9b.svn-base 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | config.php 后台管理 基本配置管理
  5. |--------------------------------------------------------------------------
  6. */
  7. namespace MazeApp\Manage;
  8. use Maze;
  9. use Maze\Security\Internal;
  10. Maze::load('manage/auth.init');
  11. class Config
  12. {
  13. /**
  14. * project
  15. *
  16. * @var string
  17. */
  18. private $project;
  19. /**
  20. * dir
  21. *
  22. * @var string
  23. */
  24. protected $type;
  25. /**
  26. * config
  27. *
  28. * @var array
  29. */
  30. protected $config;
  31. /**
  32. * __construct
  33. *
  34. * @return mixed
  35. */
  36. public function __construct()
  37. {
  38. $this->project = Maze::input('key');
  39. $this->type = Maze::input('type', 'config');
  40. $config = Maze::load('manage/project.get');
  41. if(isset($config[$this->project]))
  42. {
  43. $this->config = $config[$this->project];
  44. }
  45. $type = array('config', 'view', 'database', 'api');
  46. if(!in_array($this->type, $type))
  47. {
  48. Maze::out('error');
  49. }
  50. }
  51. /**
  52. * get
  53. *
  54. * @return mixed
  55. */
  56. public function get()
  57. {
  58. $dir = Maze::input('dir');
  59. $name = Maze::input('name');
  60. if($dir && $name)
  61. {
  62. $dir = $dir . '/' . $name;
  63. }
  64. else
  65. {
  66. $dir = $this->type;
  67. }
  68. Maze::setInput('dir', $dir);
  69. $result = $this->read($dir);
  70. return $result;
  71. }
  72. /**
  73. * read
  74. * @param string $dir
  75. *
  76. * @return mixed
  77. */
  78. private function read($dir)
  79. {
  80. $file = $this->dir($dir);
  81. if(is_dir($file))
  82. {
  83. $result = scandir($file);
  84. foreach($result as $k => $v)
  85. {
  86. if($v == '.' || $v == '..')
  87. {
  88. unset($result[$k]);
  89. }
  90. }
  91. return $result;
  92. }
  93. elseif(is_file($file))
  94. {
  95. Maze::$global['temp']['delete'] = '';
  96. $data_dir = $this->dir($dir, 'data/');
  97. if(is_file($data_dir))
  98. {
  99. $file = $data_dir;
  100. $name = str_replace(MAZE_PATH, '', $file);
  101. $md5 = Internal::encode($name);
  102. $delete = Maze::url('config.del?file=' . $name . '&md5=' . $md5);
  103. Maze::$global['temp']['delete'] = '<br /><a href="'.$delete.'" class="oper_6">点此删除</a>';
  104. }
  105. else
  106. {
  107. $name = str_replace(MAZE_PATH, '', $file);
  108. $md5 = Internal::encode($name);
  109. }
  110. $result[] = array('content' => file_get_contents($file), 'file' => $name, 'md5' => $md5, 'key' => $this->project);
  111. return $result;
  112. }
  113. else
  114. {
  115. Maze::out('error');
  116. }
  117. }
  118. /**
  119. * dir
  120. * @param string $dir
  121. *
  122. * @return mixed
  123. */
  124. private function dir($dir, $path = '')
  125. {
  126. if(!$this->config['path'])
  127. {
  128. }
  129. if($path)
  130. {
  131. return Maze::path(MAZE_PATH . $path, $this->config['path'] . $dir);
  132. }
  133. return MAZE_PATH . $this->config['path'] . $dir;
  134. }
  135. /**
  136. * set 将内容写入到配置文件中(备份)
  137. *
  138. * @return string
  139. */
  140. public function set()
  141. {
  142. $file = Maze::input('file');
  143. $value = Maze::input('value');
  144. $name = Maze::input('name');
  145. $md5 = Internal::decode(Maze::input('md5'));
  146. if($file == $md5)
  147. {
  148. $file = MAZE_PATH . $file;
  149. if(is_file($file))
  150. {
  151. file_put_contents($this->dir($name, 'data/'), $value);
  152. }
  153. }
  154. highlight_string($value);die;
  155. }
  156. /**
  157. * del 删除后台建立的内容
  158. *
  159. * @return mixed
  160. */
  161. public function del()
  162. {
  163. $file = Maze::input('file');
  164. $md5 = Internal::decode(Maze::input('md5'));
  165. if(strpos($file, 'data/') !== false && $file == $md5)
  166. {
  167. $file = MAZE_PATH . $file;
  168. if(is_file($file))
  169. {
  170. @unlink($file);
  171. }
  172. }
  173. Maze::out('yes');
  174. }
  175. }