diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/class/Item.php | 35 | ||||
-rw-r--r-- | app/class/Media.php | 34 | ||||
-rw-r--r-- | app/class/Medialist.php | 2 | ||||
-rw-r--r-- | app/class/Page.php | 29 | ||||
-rw-r--r-- | app/view/templates/media.php | 2 |
5 files changed, 64 insertions, 38 deletions
diff --git a/app/class/Item.php b/app/class/Item.php index 526e630..8bd62d1 100644 --- a/app/class/Item.php +++ b/app/class/Item.php @@ -2,6 +2,10 @@ namespace Wcms; +use DateTime; +use DateTimeImmutable; +use DateTimeZone; + abstract class Item { @@ -42,6 +46,37 @@ abstract class Item $array[$var] = $this->$var; } return $array; + } + + + /** + * Tool for accessing different view of the same DateTimeImmutable var + * + * @param string $property DateTimeImmutable var to access + * @param string $option + * + * @return mixed string or false if propriety does not exist + */ + protected function datetransform(string $property, string $option = 'date') + { + if(property_exists($this, $property)) { + if ($option == 'string') { + return $this->$property->format(DateTime::ISO8601); + } elseif ($option == 'date' || $option == 'sort') { + return $this->$property; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->$property->diff($now)); + } elseif ($option == 'pdate') { + return $this->$property->format('Y-m-d'); + } elseif ($option == 'ptime') { + return $this->$property->format('H:i'); + } elseif ($option = 'dmy') { + return $this->$property->format('d/m/Y'); + } + } else { + return false; + } } } diff --git a/app/class/Media.php b/app/class/Media.php index 5d61bf1..ad36b8e 100644 --- a/app/class/Media.php +++ b/app/class/Media.php @@ -2,16 +2,21 @@ namespace Wcms; +use DateTime; +use DateTimeImmutable; +use DateTimeZone; + class Media extends Item { - private $id; - private $path; - private $extension; - private $type; - private $size; - private $width; - private $height; - private $length; + Protected $id; + Protected $path; + Protected $extension; + Protected $type; + Protected $size; + Protected $date; + Protected $width; + Protected $height; + Protected $length; const IMAGE = array('jpg', 'jpeg', 'gif', 'png'); const SOUND = array('mp3', 'flac', 'wav', 'ogg'); @@ -31,6 +36,8 @@ class Media extends Item { $this->settype(); + $this->setdate(); + $filepath = $this->path . $this->id . '.' . $this->extension; $this->size = filesize($filepath); @@ -167,6 +174,11 @@ class Media extends Item } } + public function date($option = 'string') + { + return $this->datetransform('date', $option); + } + public function width() { return $this->width; @@ -221,6 +233,12 @@ class Media extends Item } } + public function setdate() + { + $timestamp = filemtime($this->getfulldir()); + $this->date = new DateTimeImmutable("@$timestamp"); + } + public function setwidth($width) { if (is_int($width)) { diff --git a/app/class/Medialist.php b/app/class/Medialist.php index ab1dea3..2141d40 100644 --- a/app/class/Medialist.php +++ b/app/class/Medialist.php @@ -31,7 +31,7 @@ class Medialist extends Item /** @var string display the file name of the file */ protected $filename = 0; - const SORT_BY_FILTER = ['id', 'size', 'type']; + const SORT_BY_FILTER = ['id', 'size', 'type', 'date']; const TYPES = ['image', 'sound', 'video', 'other']; diff --git a/app/class/Page.php b/app/class/Page.php index d5b43b5..cf73e98 100644 --- a/app/class/Page.php +++ b/app/class/Page.php @@ -810,35 +810,6 @@ class Page extends Dbitem return $taglist; } - /** - * Tool for accessing different view of the same DateTimeImmutable var - * - * @param string $property DateTimeImmutable var to access - * @param string $option - * - * @return mixed string or false if propriety does not exist - */ - private function datetransform(string $property, string $option = 'date') - { - if(property_exists($this, $property)) { - if ($option == 'string') { - return $this->$property->format(DateTime::ISO8601); - } elseif ($option == 'date' || $option == 'sort') { - return $this->$property; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->$property->diff($now)); - } elseif ($option == 'pdate') { - return $this->$property->format('Y-m-d'); - } elseif ($option == 'ptime') { - return $this->$property->format('H:i'); - } elseif ($option = 'dmy') { - return $this->$property->format('d/m/Y'); - } - } else { - return false; - } - } } diff --git a/app/view/templates/media.php b/app/view/templates/media.php index 59d0836..054022a 100644 --- a/app/view/templates/media.php +++ b/app/view/templates/media.php @@ -81,6 +81,7 @@ $this->layout('layout', ['title' => 'media', 'stylesheets' => [$css . 'home.css' <th>ext</th> <th><a href="<?= $mediaopt->getsortbyadress('type') ?>">type</a></th> <th><a href="<?= $mediaopt->getsortbyadress('size') ?>">size</a></th> + <th><a href="<?= $mediaopt->getsortbyadress('date') ?>">date</a></th> <th>width</th> <th>height</th> <th>lengh</th> @@ -96,6 +97,7 @@ $this->layout('layout', ['title' => 'media', 'stylesheets' => [$css . 'home.css' <td><?= $media->extension() ?></td> <td class="nowrap"><a href="<?= $media->getfullpath() ?>" target="_blank"><?= $media->type() == 'image' ? '<span class="thumbnail">' . $media->getsymbol() . '<img src="' . $media->getfullpath() . '"></span>' : $media->getsymbol() ?></a></td> <td class="nowrap"><?= $media->size('hr') ?></td> + <td class="nowrap"><?= $media->date('hrdi') ?></td> <td><?= $media->width() ?></td> <td><?= $media->height() ?></td> <td><?= $media->length() ?></td> |