Преглед на файлове

work on admin area

master
Dom SP преди 2 години
родител
ревизия
68753a532c
променени са 2 файла, в които са добавени 98 реда и са изтрити 11 реда
  1. +91
    -5
      app/controller/admin.php
  2. +7
    -6
      index.php

+ 91
- 5
app/controller/admin.php Целия файл

@@ -3,18 +3,39 @@
namespace Controller;

class Admin {

private $fff;
public $classes = ['test'];
public $edit_url = "";
function __construct() {

$f3 = \Base::instance();
$this->fff = new \Modules\FilesInFolders(
$f3->get('current_page_folder')
);
}

function menu() {
return '<a class="action" href="#">clear cache</a>';
}
function receive_edit() {
$f3 = \Base::instance();
$f3->reroute("?admin=1");
}
function index() {
// return $this->menu();
return $this->clear_cache();
$f3 = \Base::instance();
$mods = [];
if ($edit_type = $f3->get("GET.edit")) {
$this->classes[] = 'visible';
switch ($edit_type) {
case 'txt':
$file = $f3->get("GET.file");
$mods[] = $this->text_editor($file);
break;
}
}
$mods[] = $this->list_content_folder();
return implode("",$mods);
//return $this->clear_cache();
}

function clear_cache() {
@@ -30,4 +51,69 @@ class Admin {
}
return "erased $count files<br>";
}
function get_type($file) {
if (is_dir($file)) {
return 'dir';
} else if (is_file($file)) {
$ex = array_pop(explode(".",$file));
foreach ($this->fff->EXT as $type => $array) {
if (in_array(strtolower($ex),$array)) {
return $type;
}
}
return 'unkown';
}
}
function text_editor($file) {
if (is_file($file)) {
return sprintf('<form method="post" action="%s">'
.'<textarea class="texteditor" cols="80" rows="20">%s</textarea>'
.'<button type="submit">save</button>'
.'</form>',
$this->edit_url . "?".http_build_query([
'admin'=>1
]),
file_get_contents($file)
);
}
return "nope";
}
function list_content_folder() {
$f3 = \Base::instance();
$folder = $f3->get("current_page_folder");
$out = "";

$ls = [];
foreach (scandir($folder) as $file) {
$ls[] = (object)[
'name' => $file,
'type' => self::get_type($folder.$file),
'path' => $folder.$file
];
}
$out .= '<div class="filebrowser"><ul>';
foreach ($ls as $file) {
$edit_link = "?".http_build_query([
"admin"=>1,
"edit"=>$file->type,
"file"=>$file->path
]);
$out .= sprintf('<li class="filebrowser type-%s"><a href="%s">%s</a></li>',
$file->type,
$edit_link,
$file->name
);
}
$out .= "</ul></div>";
return $out;
}
}

+ 7
- 6
index.php Целия файл

@@ -228,12 +228,7 @@ function pic_cache($in1,$inwidth=360){
//------------------------------------------------------------------------
###############################################################################

if ($f3->get("GET.admin")) {
$admin = new \Controller\Admin;
$f3->set('backend',$admin->index());
} else {
$f3->set('backend',false);
}


// HTML preloading of images
// this could also find some better place
@@ -249,4 +244,10 @@ $bbb = new \Controller\Cart();
$bbb->index();

$f3->run();
if ($f3->get("GET.admin")) {
$admin = new \Controller\Admin;
$f3->set('backend',$admin->index());
} else {
$f3->set('backend',false);
}
echo \Template::instance()->render($f3->get('template'));

Loading…
Отказ
Запис