diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-01-23 01:18:33 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-01-23 01:18:33 +0100 |
commit | a66df8c97f4aa70977b25478fc3b6413ebd9b9db (patch) | |
tree | 564670e31f82083411dd6749ccfb27f5038907fe | |
parent | 11c729472634682fbcaa40caa5c510d490acfa4a (diff) | |
download | wcms-a66df8c97f4aa70977b25478fc3b6413ebd9b9db.tar.gz wcms-a66df8c97f4aa70977b25478fc3b6413ebd9b9db.zip |
new media types
-rw-r--r-- | app/class/Media.php | 45 | ||||
-rw-r--r-- | app/class/Medialist.php | 5 | ||||
-rw-r--r-- | app/class/Model.php | 47 | ||||
-rw-r--r-- | app/class/Modelmedia.php | 4 | ||||
-rw-r--r-- | app/fn/fn.php | 14 | ||||
-rw-r--r-- | app/view/templates/media.php | 13 |
6 files changed, 96 insertions, 32 deletions
diff --git a/app/class/Media.php b/app/class/Media.php index 4053bed..0be2013 100644 --- a/app/class/Media.php +++ b/app/class/Media.php @@ -16,6 +16,7 @@ class Media const IMAGE = array('jpg', 'jpeg', 'gif', 'png'); const SOUND = array('mp3', 'flac', 'wav', 'ogg'); const VIDEO = array('mp4', 'mov', 'avi', 'mkv'); + const ARCHIVE = array('zip', 'rar'); @@ -92,17 +93,17 @@ class Media case 'image': $code = ' . ')'; break; - - case 'other': - $code = '[' . $this->id . '](' . $this->getincludepath() . ')'; - break; - + case 'sound': - $code = '<audio controls src="' . $this->getincludepath() . '"></audio>'; + $code = '<audio controls src="' . $this->getincludepath() . '"></audio>'; break; - + case 'video': - $code = '<video controls=""><source src="' . $this->getincludepath() . '" type="video/' . $this->extension . '"></video>'; + $code = '<video controls=""><source src="' . $this->getincludepath() . '" type="video/' . $this->extension . '"></video>'; + break; + + default : + $code = '[' . $this->id . '](' . $this->getincludepath() . ')'; break; } @@ -125,10 +126,22 @@ class Media case 'video': $symbol = "🎞"; break; + + case 'document': + $symbol = "📓"; + break; - case 'other': + case 'archive': + $symbol = "🗜"; + break; + + case 'code': $symbol = "📄"; break; + + default : + $symbol = "🎲"; + break; } return $symbol; } @@ -206,16 +219,10 @@ class Media public function settype() { - if (isset($this->extension)) { - if (in_array($this->extension, $this::IMAGE)) { - $this->type = "image"; - } elseif (in_array($this->extension, $this::SOUND)) { - $this->type = "sound"; - } elseif (in_array($this->extension, $this::VIDEO)) { - $this->type = "video"; - } else { - $this->type = "other"; - } + if (!empty($this->extension) && isset(Model::MEDIA_EXT[$this->extension])) { + $this->type = Model::MEDIA_EXT[$this->extension]; + } else { + $this->type = 'other'; } } diff --git a/app/class/Medialist.php b/app/class/Medialist.php index b208fef..2c17fa0 100644 --- a/app/class/Medialist.php +++ b/app/class/Medialist.php @@ -20,7 +20,7 @@ class Medialist protected $order = 1; /** @var array list of media type to display */ - protected $type = ['image', 'sound', 'video', 'other']; + protected $type = []; /** @var int display media contents*/ protected $display = 1; @@ -42,6 +42,7 @@ class Medialist public function __construct(array $datas = []) { + $this->type = Model::mediatypes(); $this->hydrate($datas); } @@ -226,7 +227,7 @@ class Medialist public function settype($type) { if(is_array($type)) { - $this->type = array_intersect(self::TYPES, array_unique($type)); + $this->type = array_intersect(Model::mediatypes(), array_unique($type)); } } } diff --git a/app/class/Model.php b/app/class/Model.php index 913dc34..f48b555 100644 --- a/app/class/Model.php +++ b/app/class/Model.php @@ -20,8 +20,43 @@ abstract class Model const GLOBAL_DIR = 'assets'. DIRECTORY_SEPARATOR . 'global' . DIRECTORY_SEPARATOR; const DATABASE_DIR = '.' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR; - const MEDIA_EXTENSIONS = array('jpeg', 'jpg', 'JPG', 'png', 'gif', 'mp3', 'mp4', 'mov', 'wav', 'flac', 'pdf'); - const MEDIA_TYPES = ['image', 'video', 'sound', 'other']; + const MEDIA_EXT = [ + 'jpg' => 'image', + 'jpeg' => 'image', + 'png' => 'image', + 'gif' => 'image', + 'ico' => 'image', + 'tiff' => 'image', + 'bmp' => 'image', + 'mp3' => 'sound', + 'opus' => 'sound', + 'wav' => 'sound', + 'ogg' => 'sound', + 'flac' => 'sound', + 'aiff' => 'sound', + 'm4a' => 'sound', + 'mp4' => 'video', + 'mkv' => 'video', + 'avi' => 'video', + 'mov' => 'video', + 'wmv' => 'video', + 'm4v' => 'video', + 'zip' => 'archive', + '7zip' => 'archive', + 'pdf' => 'document', + 'odt' => 'document', + 'doc' => 'document', + 'docx' => 'document', + 'woff' => 'font', + 'woff2' => 'font', + 'otf' => 'font', + 'ttf' => 'font', + 'js' => 'code', + 'html' => 'code', + 'css' => 'code', + 'php' => 'code', + '' => 'other' + ]; const COLUMNS = ['id', 'title', 'description', 'tag', 'date', 'datemodif', 'datecreation', 'secure', 'linkfrom', 'linkto', 'visitcount', 'affcount', 'editcount']; @@ -113,4 +148,12 @@ abstract class Model } } + /** + * + */ + public static function mediatypes() + { + return array_unique(array_values(self::MEDIA_EXT)); + } + } diff --git a/app/class/Modelmedia.php b/app/class/Modelmedia.php index d1da829..a6a682b 100644 --- a/app/class/Modelmedia.php +++ b/app/class/Modelmedia.php @@ -49,7 +49,7 @@ class Modelmedia extends Model * * @return array of Media objects */ - public function getlistermedia($dir, $type = Model::MEDIA_TYPES) + public function getlistermedia($dir, $type = []) { if (is_dir($dir)) { if ($handle = opendir($dir)) { @@ -63,7 +63,7 @@ class Modelmedia extends Model $media->analyse(); - if (in_array($media->type(), $type)) { + if (empty($type) || in_array($media->type(), $type)) { $list[] = $media; } } diff --git a/app/fn/fn.php b/app/fn/fn.php index 583227a..61c2312 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -230,6 +230,20 @@ function treecount(array $dir, string $dirname, int $deepness, string $path, str } } +function checkboxes(string $name, array $optionlist = [], array $checkedlist = []) +{ + $checkboxes = ''; + foreach ($optionlist as $option) { + $checkboxes .= '<li><input type="checkbox" name="' . $name . '[]" id="' . $option . '" value="' . $option . '"'; + if(in_array($option, $checkedlist)) { + $checkboxes .= ' checked'; + } + $checkboxes .= '><label for="' . $option . '">' . $option . '</label></li>'; + $checkboxes .= PHP_EOL; + } + return '<ul>' . PHP_EOL . $checkboxes . PHP_EOL . '</ul>'; +} + diff --git a/app/view/templates/media.php b/app/view/templates/media.php index 1f70d35..ba385cb 100644 --- a/app/view/templates/media.php +++ b/app/view/templates/media.php @@ -1,4 +1,8 @@ -<?php $this->layout('layout', ['title' => 'media', 'css' => $css . 'home.css']) ?> +<?php + +use Wcms\Model; + +$this->layout('layout', ['title' => 'media', 'css' => $css . 'home.css']) ?> <?php $this->start('page') ?> @@ -39,12 +43,7 @@ <form action="" method="get"> <fieldset> <legend>Type</legend> - <ul> - <li><input type="checkbox" name="type[]" id="image" value="image" <?= in_array('image', $mediaopt->type()) ? 'checked' : '' ?>><label for="image">image</label></li> - <li><input type="checkbox" name="type[]" id="sound" value="sound" <?= in_array('sound', $mediaopt->type()) ? 'checked' : '' ?>><label for="sound">sound</label></li> - <li><input type="checkbox" name="type[]" id="video" value="video" <?= in_array('video', $mediaopt->type()) ? 'checked' : '' ?>><label for="video">video</label></li> - <li><input type="checkbox" name="type[]" id="other" value="other" <?= in_array('other', $mediaopt->type()) ? 'checked' : '' ?>><label for="other">other</label></li> - </ul> + <?= checkboxes('type', Model::mediatypes(), $mediaopt->type()) ?> </fieldset> <fieldset> <legend>Sort</legend> |