diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2019-03-28 19:45:59 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2019-03-28 19:45:59 +0100 |
commit | 53fcf8ed3cf59f38adfa4d66e925e147a64f7eef (patch) | |
tree | 6c81688e43de8a4746bd981eff2090cf9f6373cb /app/class | |
parent | d97c84ab440b2b68a8068b813638117244864937 (diff) | |
download | wcms-53fcf8ed3cf59f38adfa4d66e925e147a64f7eef.tar.gz wcms-53fcf8ed3cf59f38adfa4d66e925e147a64f7eef.zip |
thumbnail
Diffstat (limited to 'app/class')
-rw-r--r-- | app/class/controllerart.php | 5 | ||||
-rw-r--r-- | app/class/controllermedia.php | 9 | ||||
-rw-r--r-- | app/class/model.php | 6 | ||||
-rw-r--r-- | app/class/modelmedia.php | 53 | ||||
-rw-r--r-- | app/class/modelrender.php | 2 |
5 files changed, 65 insertions, 10 deletions
diff --git a/app/class/controllerart.php b/app/class/controllerart.php index dfdde7f..4d7b1be 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -77,7 +77,7 @@ class Controllerart extends Controller /** * Render given page * - * @var Art2 $art input + * @param Art2 $art input * * @return Art2 rendered $art */ @@ -277,6 +277,9 @@ class Controllerart extends Controller $this->art->addauthor($this->user->id()); $this->art->removeeditby($this->user->id()); + // Add thumbnail image file under 1Mo + $this->mediamanager->simpleupload('thumbnail', Model::THUMBNAIL_DIR . $this->art->id(), 1024*1024, ['jpg', 'jpeg', 'JPG', 'JPEG'], true); + $this->artmanager->update($this->art); diff --git a/app/class/controllermedia.php b/app/class/controllermedia.php index 91f5a03..6bc38d9 100644 --- a/app/class/controllermedia.php +++ b/app/class/controllermedia.php @@ -20,10 +20,13 @@ class Controllermedia extends Controller if ($this->user->iseditor()) { if (!$this->mediamanager->basedircheck()) { - throw new Exception("Error : Cant create /media folder"); + throw new Exception("Media error : Cant create /media folder"); } if (!$this->mediamanager->favicondircheck()) { - throw new Exception("Error : Cant create /media/favicon folder"); + throw new Exception("Media error : Cant create /media/favicon folder"); + } + if (!$this->mediamanager->thumbnaildircheck()) { + throw new Exception("Media error : Cant create /media/thumbnail folder"); } @@ -50,7 +53,7 @@ class Controllermedia extends Controller if ($this->user->iseditor()) { $target = $_POST['dir'] ?? Model::MEDIA_DIR; if (!empty($_FILES['file']['name'][0])) { - $this->mediamanager->upload($target); + $this->mediamanager->multiupload('file', $target); } $this->redirect($this->router->generate('media') . '?path=' . $target); } else { diff --git a/app/class/model.php b/app/class/model.php index 9bc5c67..b514b00 100644 --- a/app/class/model.php +++ b/app/class/model.php @@ -8,6 +8,7 @@ abstract class Model const FONT_DIR = 'fonts' . DIRECTORY_SEPARATOR; const MEDIA_DIR = 'media' . DIRECTORY_SEPARATOR; const FAVICON_DIR = 'media' . DIRECTORY_SEPARATOR . 'favicon' . DIRECTORY_SEPARATOR; + const THUMBNAIL_DIR = 'media' . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR; const TEMPLATES_DIR = '.'. DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; const RENDER_DIR = 'assets'. DIRECTORY_SEPARATOR . 'render' . DIRECTORY_SEPARATOR; const GLOBAL_DIR = 'assets'. DIRECTORY_SEPARATOR . 'global' . DIRECTORY_SEPARATOR; @@ -76,6 +77,11 @@ abstract class Model return self::dirtopath(Model::FAVICON_DIR); } + public static function thumbnailpath() + { + return self::dirtopath(Model::THUMBNAIL_DIR); + } + public static function fontpath() { return self::dirtopath(Model::FONT_DIR); diff --git a/app/class/modelmedia.php b/app/class/modelmedia.php index 42c826c..071483b 100644 --- a/app/class/modelmedia.php +++ b/app/class/modelmedia.php @@ -22,6 +22,15 @@ class Modelmedia extends Model } } + public function thumbnaildircheck() + { + if(!is_dir(Model::THUMBNAIL_DIR)) { + return mkdir(Model::THUMBNAIL_DIR); + } else { + return true; + } + } + public function getmedia($entry, $dir) { $fileinfo = pathinfo($entry); @@ -118,22 +127,56 @@ class Modelmedia extends Model } - public function upload(string $target) + /** + * Upload single file + * + * @param string $index The file id + * @param string $destination File final destination + * @param bool|int $maxsize Max file size in octets + * @param bool|array $extensions List of authorized extensions + * @param bool $jpgrename Change the file exentension to .jpg + * + * @return bool If upload process is a succes or not + */ + function simpleupload(string $index, string $destination, $maxsize = false, $extensions = false, bool $jpgrename = false) : bool + { + //Test1: if the file is corectly uploaded + if (!isset($_FILES[$index]) || $_FILES[$index]['error'] > 0) return false; + //Test2: check file size + if ($maxsize !== false && $_FILES[$index]['size'] > $maxsize) return false; + //Test3: check extension + $ext = substr(strrchr($_FILES[$index]['name'],'.'),1); + if ($extensions !== false && !in_array($ext, $extensions)) return false; + if($jpgrename !== false) { + $destination .= '.jpg'; + } else { + $destination .= '.' . $ext; + } + //Move to dir + return move_uploaded_file($_FILES[$index]['tmp_name'], $destination); + } + + /** + * Upload multiple files + * + * @param string $index Id of the file input + * @param string $target direction to save the files + */ + public function multiupload(string $index, string $target) { if($target[strlen($target)-1] != DIRECTORY_SEPARATOR) $target .= DIRECTORY_SEPARATOR; $count=0; - foreach ($_FILES['file']['name'] as $filename) + foreach ($_FILES[$index]['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 = $target . $id .'.' .$extension; + move_uploaded_file($tmp, $temp); $temp=''; $tmp=''; } diff --git a/app/class/modelrender.php b/app/class/modelrender.php index 3d41fa7..8b62cd2 100644 --- a/app/class/modelrender.php +++ b/app/class/modelrender.php @@ -537,7 +537,7 @@ class Modelrender extends Modelart /** * Autolink Function : transform every word of more than $limit characters in internal link * - * @var string $text The input text to be converted + * @param string $text The input text to be converted * * @return string Conversion output */ |