aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
Diffstat (limited to 'app/class')
-rw-r--r--app/class/Media.php45
-rw-r--r--app/class/Medialist.php5
-rw-r--r--app/class/Model.php47
-rw-r--r--app/class/Modelmedia.php4
4 files changed, 76 insertions, 25 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 = '![' . $this->id . '](' . $this->getincludepath() . ')';
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;
}
}