Browse Source

work on admin area

master
Dom SP 2 years ago
parent
commit
68753a532c
2 changed files with 98 additions and 11 deletions
  1. +91
    -5
      app/controller/admin.php
  2. +7
    -6
      index.php

+ 91
- 5
app/controller/admin.php View File

namespace Controller; namespace Controller;


class Admin { class Admin {

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

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


function menu() { function menu() {
return '<a class="action" href="#">clear cache</a>'; return '<a class="action" href="#">clear cache</a>';
} }
function receive_edit() {
$f3 = \Base::instance();
$f3->reroute("?admin=1");
}
function index() { 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() { function clear_cache() {
} }
return "erased $count files<br>"; 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 View File

//------------------------------------------------------------------------ //------------------------------------------------------------------------
############################################################################### ###############################################################################


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



// HTML preloading of images // HTML preloading of images
// this could also find some better place // this could also find some better place
$bbb->index(); $bbb->index();


$f3->run(); $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')); echo \Template::instance()->render($f3->get('template'));

Loading…
Cancel
Save