diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-04-17 20:58:27 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-04-17 20:58:27 +0200 |
commit | 1c4182d9d88bb4471f86b08329f1b68a5290872b (patch) | |
tree | e7ccae68902113ece94ab4c8e86fd712dc028d2a /app/class/Media.php | |
parent | dc5613c15b1b414fefadd66912ebf8ff3a5eef9d (diff) | |
download | wcms-1c4182d9d88bb4471f86b08329f1b68a5290872b.tar.gz wcms-1c4182d9d88bb4471f86b08329f1b68a5290872b.zip |
apply psr 12 part 2
Diffstat (limited to 'app/class/Media.php')
-rw-r--r-- | app/class/Media.php | 552 |
1 files changed, 272 insertions, 280 deletions
diff --git a/app/class/Media.php b/app/class/Media.php index 9213c31..def4645 100644 --- a/app/class/Media.php +++ b/app/class/Media.php @@ -8,298 +8,290 @@ use DateTimeZone; class Media extends Item { - Protected $id; - Protected $path; - Protected $extension; - Protected $type; - Protected $size; - Protected $date; - Protected $width; - Protected $height; - Protected $length; - Protected $uid; - Protected $permissions; + protected $id; + protected $path; + protected $extension; + protected $type; + protected $size; + protected $date; + protected $width; + protected $height; + protected $length; + protected $uid; + protected $permissions; - 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'); + public const IMAGE = array('jpg', 'jpeg', 'gif', 'png'); + public const SOUND = array('mp3', 'flac', 'wav', 'ogg'); + public const VIDEO = array('mp4', 'mov', 'avi', 'mkv'); + public const ARCHIVE = array('zip', 'rar'); // _____________________________________________________ F U N ____________________________________________________ - public function __construct(array $donnees) - { - $this->hydrate($donnees); - } - - public function analyse() - { - $this->settype(); - - $this->setdate(); - - $filepath = $this->path . $this->id . '.' . $this->extension; - - if ($this->type == 'image') { - list($width, $height, $type, $attr) = getimagesize($filepath); - $this->width = $width; - $this->height = $height; - } - - $stat = stat($filepath); - - $permissions = decoct(fileperms($filepath) & 0777); - - $this->setpermissions($permissions); - - $this->hydrate($stat); - - - } - - - public function getfullpath() - { - if(!empty(Config::basepath())) { - $base = '/' . Config::basepath(); - } else { - $base = ''; - } - $fullpath = $base . '/'. $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; - } - - public function getfulldir() - { - return $this->path . $this->id . '.' . $this->extension; - } - - /** - * Generate html code depending on media type - * - * @return string html code - */ - public function getcode() : string - { - switch ($this->type) { - case 'image': - $code = ' . ')'; - break; - - case 'sound': - $code = '<audio controls src="' . $this->getincludepath() . '"></audio>'; - break; - - case 'video': - $code = '<video controls=""><source src="' . $this->getincludepath() . '" type="video/' . $this->extension . '"></video>'; - break; - - default : - $code = '[' . $this->id . '](' . $this->getincludepath() . ')'; - break; - - } - - return $code; - - } - - public function getsymbol() - { - switch ($this->type) { - case 'image': - $symbol = "🖼"; - break; - - case 'sound': - $symbol = "🎵"; - break; - - case 'video': - $symbol = "🎞"; - break; - - case 'document': - $symbol = "📓"; - break; - - case 'archive': - $symbol = "🗜"; - break; - - case 'code': - $symbol = "📄"; - break; - - default : - $symbol = "🎲"; - break; - } - return $symbol; - } + public function __construct(array $donnees) + { + $this->hydrate($donnees); + } + + public function analyse() + { + $this->settype(); + + $this->setdate(); + + $filepath = $this->path . $this->id . '.' . $this->extension; + + if ($this->type == 'image') { + list($width, $height, $type, $attr) = getimagesize($filepath); + $this->width = $width; + $this->height = $height; + } + + $stat = stat($filepath); + + $permissions = decoct(fileperms($filepath) & 0777); + + $this->setpermissions($permissions); + + $this->hydrate($stat); + } + + + public function getfullpath() + { + if (!empty(Config::basepath())) { + $base = '/' . Config::basepath(); + } else { + $base = ''; + } + $fullpath = $base . '/' . $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; + } + + public function getfulldir() + { + return $this->path . $this->id . '.' . $this->extension; + } + + /** + * Generate html code depending on media type + * + * @return string html code + */ + public function getcode(): string + { + switch ($this->type) { + case 'image': + $code = ' . ')'; + break; + + case 'sound': + $code = '<audio controls src="' . $this->getincludepath() . '"></audio>'; + break; + + case 'video': + $code = '<video controls=""><source src="' . $this->getincludepath() . '" type="video/' . $this->extension . '"></video>'; + break; + + default: + $code = '[' . $this->id . '](' . $this->getincludepath() . ')'; + break; + } + + return $code; + } + + public function getsymbol() + { + switch ($this->type) { + case 'image': + $symbol = "🖼"; + break; + + case 'sound': + $symbol = "🎵"; + break; + + case 'video': + $symbol = "🎞"; + break; + + case 'document': + $symbol = "📓"; + break; + + case 'archive': + $symbol = "🗜"; + break; + + case 'code': + $symbol = "📄"; + break; + + default: + $symbol = "🎲"; + break; + } + return $symbol; + } // _________________________________________________ G E T ____________________________________________________ - public function id() - { - return $this->id; - } - - public function path() - { - return $this->path; - } - - public function extension() - { - return $this->extension; - } - - public function type() - { - return $this->type; - } - - public function size($display = 'binary') - { - if($display == 'hr') { - return readablesize($this->size) . 'o'; - } else { - return $this->size; - } - } - - public function date($option = 'date') - { - return $this->datetransform('date', $option); - } - - public function width() - { - return $this->width; - } - - public function height() - { - return $this->height; - } - - public function length() - { - return $this->length; - } - - public function surface() - { - $surface = $this->width * $this->height; - return readablesize($surface, 1000) . 'px'; - } - - public function uid($option = 'id') - { - if($option === 'name') { - $userinfo = posix_getpwuid($this->uid); - return $userinfo['name']; - } else { - return $this->uid; - } - } - - public function permissions() - { - return $this->permissions; - } + public function id() + { + return $this->id; + } + + public function path() + { + return $this->path; + } + + public function extension() + { + return $this->extension; + } + + public function type() + { + return $this->type; + } + + public function size($display = 'binary') + { + if ($display == 'hr') { + return readablesize($this->size) . 'o'; + } else { + return $this->size; + } + } + + public function date($option = 'date') + { + return $this->datetransform('date', $option); + } + + public function width() + { + return $this->width; + } + + public function height() + { + return $this->height; + } + + public function length() + { + return $this->length; + } + + public function surface() + { + $surface = $this->width * $this->height; + return readablesize($surface, 1000) . 'px'; + } + + public function uid($option = 'id') + { + if ($option === 'name') { + $userinfo = posix_getpwuid($this->uid); + return $userinfo['name']; + } else { + return $this->uid; + } + } + + public function permissions() + { + return $this->permissions; + } // ___________________________________________________ S E T __________________________________________________ - public function setid($id) - { - if (is_string($id)) { - $this->id = $id; - } - } - - public function setpath($path) - { - if (strlen($path) < 40 and is_string($path)) { - $this->path = strip_tags(strtolower($path)); - } - } - - public function setextension($extension) - { - if (strlen($extension) < 7 and is_string($extension)) { - $this->extension = strip_tags(strtolower($extension)); - } - } - - public function settype() - { - if (!empty($this->extension) && isset(Model::MEDIA_EXT[$this->extension])) { - $this->type = Model::MEDIA_EXT[$this->extension]; - } else { - $this->type = 'other'; - } - } - - public function setsize($size) - { - if (is_int($size)) { - $this->size = $size; - } - } - - public function setdate() - { - $timestamp = filemtime($this->getfulldir()); - $this->date = new DateTimeImmutable("@$timestamp"); - } - - public function setwidth($width) - { - if (is_int($width)) { - $this->width = strip_tags(strtolower($width)); - } - } - - public function setheight($height) - { - if (is_int($height)) { - $this->height = strip_tags(strtolower($height)); - } - } - - public function setlength($length) - { - if ($this->type == 'sound') { - $this->length = $length; - } - } - - public function setuid($uid) - { - $this->uid = $uid; - } - - public function setpermissions($permissions) - { - $this->permissions = $permissions; - } - - - - + public function setid($id) + { + if (is_string($id)) { + $this->id = $id; + } + } + + public function setpath($path) + { + if (strlen($path) < 40 and is_string($path)) { + $this->path = strip_tags(strtolower($path)); + } + } + + public function setextension($extension) + { + if (strlen($extension) < 7 and is_string($extension)) { + $this->extension = strip_tags(strtolower($extension)); + } + } + + public function settype() + { + if (!empty($this->extension) && isset(Model::MEDIA_EXT[$this->extension])) { + $this->type = Model::MEDIA_EXT[$this->extension]; + } else { + $this->type = 'other'; + } + } + + public function setsize($size) + { + if (is_int($size)) { + $this->size = $size; + } + } + + public function setdate() + { + $timestamp = filemtime($this->getfulldir()); + $this->date = new DateTimeImmutable("@$timestamp"); + } + + public function setwidth($width) + { + if (is_int($width)) { + $this->width = strip_tags(strtolower($width)); + } + } + + public function setheight($height) + { + if (is_int($height)) { + $this->height = strip_tags(strtolower($height)); + } + } + + public function setlength($length) + { + if ($this->type == 'sound') { + $this->length = $length; + } + } + + public function setuid($uid) + { + $this->uid = $uid; + } + + public function setpermissions($permissions) + { + $this->permissions = $permissions; + } } |