From 1a7a60ea3efde53ac2c3b07ca914483cfc25a827 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Mon, 17 Dec 2018 15:34:20 +0100 Subject: media --- app/class/controllermedia.php | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'app/class/controllermedia.php') diff --git a/app/class/controllermedia.php b/app/class/controllermedia.php index f156b35..4421f65 100644 --- a/app/class/controllermedia.php +++ b/app/class/controllermedia.php @@ -2,18 +2,31 @@ class Controllermedia extends Controller { + /** + * @var Modelmedia + */ protected $mediamanager; - public function __construct($render) { + public function __construct($render) + { parent::__construct($render); - + $this->mediamanager = new Modelmedia; } public function desktop() { - if($this->user->iseditor()) { + if ($this->user->iseditor()) { + + if (!$this->mediamanager->basedircheck()) { + throw new Exception("Error : Cant create /media folder"); + } + if (!$this->mediamanager->favicondircheck()) { + throw new Exception("Error : Cant create /media/favicon folder"); + } + + $dir = rtrim($_GET['path'] ?? Model::MEDIA_DIR, DIRECTORY_SEPARATOR); $medialist = $this->mediamanager->getlistermedia($dir . DIRECTORY_SEPARATOR); @@ -29,16 +42,28 @@ class Controllermedia extends Controller public function upload() { - if($this->user->iseditor()) { - $target = $_POST['dir'] ?? Model::MEDIA_DIR; - - $this->mediamanager->upload($target); - $this->redirect($this->router->generate('media').'?path='.$target); + if ($this->user->iseditor()) { + $target = $_POST['dir'] ?? Model::MEDIA_DIR; + if (!empty($_FILES['file']['name'][0])) { + $this->mediamanager->upload($target); + } + $this->redirect($this->router->generate('media') . '?path=' . $target); } else { $this->routedirect('home'); } } + public function folder() + { + if ($this->user->iseditor()) { + $dir = $_POST['dir'] ?? Model::MEDIA_DIR; + $name = $_POST['foldername'] ?? 'new folder'; + $this->mediamanager->adddir($dir, $name); + } + $this->redirect($this->router->generate('media') . '?path=' . $dir . DIRECTORY_SEPARATOR . $name); + + } + } -- cgit v1.2.3