mostly filebased Content Presentation System
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

120 行
3.2KB

  1. <?php
  2. namespace Controller;
  3. class Admin {
  4. private $fff;
  5. public $classes = ['test'];
  6. public $edit_url = "";
  7. function __construct() {
  8. $f3 = \Base::instance();
  9. $this->fff = new \Modules\FilesInFolders(
  10. $f3->get('current_page_folder')
  11. );
  12. }
  13. function menu() {
  14. return '<a class="action" href="#">clear cache</a>';
  15. }
  16. function receive_edit() {
  17. $f3 = \Base::instance();
  18. $f3->reroute("?admin=1");
  19. }
  20. function index() {
  21. $f3 = \Base::instance();
  22. $mods = [];
  23. if ($edit_type = $f3->get("GET.edit")) {
  24. $this->classes[] = 'visible';
  25. switch ($edit_type) {
  26. case 'txt':
  27. $file = $f3->get("GET.file");
  28. $mods[] = $this->text_editor($file);
  29. break;
  30. }
  31. }
  32. $mods[] = $this->list_content_folder();
  33. return implode("",$mods);
  34. //return $this->clear_cache();
  35. }
  36. function clear_cache() {
  37. $CI = new \Modules\CachedImage("rsc/img/default.png");
  38. $cache_dir = $CI->cache_dir;
  39. $ls = scandir($cache_dir);
  40. $count = 0;
  41. foreach($ls as $file) {
  42. if(!strncmp(".",$file,1)) continue;
  43. unlink($cache_dir."".$file);
  44. $count++;
  45. }
  46. return "erased $count files<br>";
  47. }
  48. function get_type($file) {
  49. if (is_dir($file)) {
  50. return 'dir';
  51. } else if (is_file($file)) {
  52. $ex = array_pop(explode(".",$file));
  53. foreach ($this->fff->EXT as $type => $array) {
  54. if (in_array(strtolower($ex),$array)) {
  55. return $type;
  56. }
  57. }
  58. return 'unkown';
  59. }
  60. }
  61. function text_editor($file) {
  62. if (is_file($file)) {
  63. return sprintf('<form method="post" action="%s">'
  64. .'<textarea class="texteditor" cols="80" rows="20">%s</textarea>'
  65. .'<button type="submit">save</button>'
  66. .'</form>',
  67. $this->edit_url . "?".http_build_query([
  68. 'admin'=>1
  69. ]),
  70. file_get_contents($file)
  71. );
  72. }
  73. return "nope";
  74. }
  75. function list_content_folder() {
  76. $f3 = \Base::instance();
  77. $folder = $f3->get("current_page_folder");
  78. $out = "";
  79. $ls = [];
  80. foreach (scandir($folder) as $file) {
  81. $ls[] = (object)[
  82. 'name' => $file,
  83. 'type' => self::get_type($folder.$file),
  84. 'path' => $folder.$file
  85. ];
  86. }
  87. $out .= '<div class="filebrowser"><ul>';
  88. foreach ($ls as $file) {
  89. $edit_link = "?".http_build_query([
  90. "admin"=>1,
  91. "edit"=>$file->type,
  92. "file"=>$file->path
  93. ]);
  94. $out .= sprintf('<li class="filebrowser type-%s"><a href="%s">%s</a></li>',
  95. $file->type,
  96. $edit_link,
  97. $file->name
  98. );
  99. }
  100. $out .= "</ul></div>";
  101. return $out;
  102. }
  103. }