aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
Diffstat (limited to 'app/class')
-rw-r--r--app/class/Item.php35
-rw-r--r--app/class/Media.php34
-rw-r--r--app/class/Medialist.php2
-rw-r--r--app/class/Page.php29
4 files changed, 62 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;
- }
- }
}