From f3756d0b076a81442e9512b2d3e39de47082cd22 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Mon, 10 Dec 2018 12:23:42 +0100 Subject: media-clean --- app/class/controllermedia.php | 35 +++++++++----------------------- app/class/media.php | 12 ++++++++++- app/class/modelmedia.php | 21 +++++++++++++++++++ app/class/modelrender.php | 12 +++++------ app/view/templates/info.php | 4 +++- app/view/templates/media.php | 47 +++++++++++++++++++++++++++++++++---------- assets/css/home.css | 13 ++++++++++++ 7 files changed, 99 insertions(+), 45 deletions(-) diff --git a/app/class/controllermedia.php b/app/class/controllermedia.php index 26b58ff..f156b35 100644 --- a/app/class/controllermedia.php +++ b/app/class/controllermedia.php @@ -14,7 +14,7 @@ class Controllermedia extends Controller public function desktop() { if($this->user->iseditor()) { - $dir = $_GET['path'] ?? Model::MEDIA_DIR; + $dir = rtrim($_GET['path'] ?? Model::MEDIA_DIR, DIRECTORY_SEPARATOR); $medialist = $this->mediamanager->getlistermedia($dir . DIRECTORY_SEPARATOR); $faviconlist = $this->mediamanager->getlistermedia(Model::FAVICON_DIR); @@ -22,38 +22,21 @@ class Controllermedia extends Controller $dirlist = $this->mediamanager->listdir(Model::MEDIA_DIR); $this->showtemplate('media', ['medialist' => $medialist, 'faviconlist' => $faviconlist, 'dirlist' => $dirlist, 'dir' => $dir]); + } else { + $this->routedirect('home'); } } - public function addmedia() - { - echo $this->templates->render('media', ['interface' => 'addmedia']); - - //$message = $this->mediamanager->addmedia($_FILES, 2 ** 24, $_POST['id']); - - } - public function upload() { + if($this->user->iseditor()) { $target = $_POST['dir'] ?? Model::MEDIA_DIR; - if($target[strlen($target)-1]!='/') - $target=$target.'/'; - $count=0; - foreach ($_FILES['file']['name'] as $filename) - { - $fileinfo = pathinfo($filename); - $extension = idclean($fileinfo['extension']); - $id = idclean($fileinfo['filename']); - - $temp=$target; - $tmp=$_FILES['file']['tmp_name'][$count]; - $count=$count + 1; - $temp .= $id .'.' .$extension; - move_uploaded_file($tmp,$temp); - $temp=''; - $tmp=''; - } + + $this->mediamanager->upload($target); $this->redirect($this->router->generate('media').'?path='.$target); + } else { + $this->routedirect('home'); + } } diff --git a/app/class/media.php b/app/class/media.php index 0cbbd89..01dfd55 100644 --- a/app/class/media.php +++ b/app/class/media.php @@ -56,7 +56,17 @@ class Media public function getfullpath() { - return '/' . Config::basepath() . '/' . $this->path() . $this->id() . '.' . $this->extension(); + $fullpath = '/' . Config::basepath() . '/'. $this->path() . $this->id() . '.' . $this->extension(); + $fullpath = str_replace('\\', '/', $fullpath); + return $fullpath; + } + + public function getincludepath() + { + $includepath = $this->path() . $this->id() . '.' . $this->extension(); + $includepath = str_replace('\\', '/', $includepath); + $includepath = substr($includepath, 6); + return $includepath; } diff --git a/app/class/modelmedia.php b/app/class/modelmedia.php index 89c253f..5706c26 100644 --- a/app/class/modelmedia.php +++ b/app/class/modelmedia.php @@ -132,6 +132,27 @@ class Modelmedia extends Model } + public function upload(string $target) + { + if($target[strlen($target)-1] != DIRECTORY_SEPARATOR) + $target .= DIRECTORY_SEPARATOR; + $count=0; + foreach ($_FILES['file']['name'] as $filename) + { + $fileinfo = pathinfo($filename); + $extension = idclean($fileinfo['extension']); + $id = idclean($fileinfo['filename']); + + $temp=$target; + $tmp=$_FILES['file']['tmp_name'][$count]; + $count=$count + 1; + $temp .= $id .'.' .$extension; + move_uploaded_file($tmp,$temp); + $temp=''; + $tmp=''; + } + } + } diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 7ef7e45..c76fa69 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -322,13 +322,13 @@ class Modelrender extends Modelart foreach ($medialist as $media) { $ul .= '
  • '; if($media->type() == 'image') { - $ul .= ''.$media->id().''; + $ul .= ''.$media->id().''; } elseif ($media->type() == 'sound') { - $ul .= '
  • ' . PHP_EOL; } @@ -337,7 +337,7 @@ class Modelrender extends Modelart return $ul; } else { - return 'directory not founded'; + return 'directory "'.$dir.'" not found'; } }, $text); @@ -402,7 +402,7 @@ class Modelrender extends Modelart } } - $ul = '