diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-04-28 20:18:17 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-04-28 20:24:52 +0200 |
commit | 9090550d241f9f7b3246b24bfd323bd988add749 (patch) | |
tree | 2c2de66510533da53848dd876a9ab392471b38b8 /app/class/Medialist.php | |
parent | 98514a4e0037aa0879e45bbad660aeda8837c624 (diff) | |
download | wcms-9090550d241f9f7b3246b24bfd323bd988add749.tar.gz wcms-9090550d241f9f7b3246b24bfd323bd988add749.zip |
listen to brother Stan and clean some things
Diffstat (limited to 'app/class/Medialist.php')
-rw-r--r-- | app/class/Medialist.php | 236 |
1 files changed, 0 insertions, 236 deletions
diff --git a/app/class/Medialist.php b/app/class/Medialist.php deleted file mode 100644 index e716845..0000000 --- a/app/class/Medialist.php +++ /dev/null @@ -1,236 +0,0 @@ -<?php - -namespace Wcms; - -class Medialist extends Item -{ - /** @var string full regex match */ - protected $fullmatch; - - /** @var string full options code line */ - protected $options = ''; - - /** @var string directory of media */ - protected $path = ''; - - /** @var string */ - protected $sortby = 'id'; - - /** @var int */ - protected $order = 1; - - /** @var array list of media type to display */ - protected $type = []; - - /** @var int display media contents*/ - protected $display = 1; - - /** @var int display download links*/ - protected $links = 0; - - /** @var int display the file name of the file */ - protected $filename = 0; - - public const TYPES = ['image', 'sound', 'video', 'other']; - - - - // ______________________________________________ F U N ________________________________________________________ - - - - public function __construct(array $datas = []) - { - $this->type = Model::mediatypes(); - $this->hydrate($datas); - } - - public function readoptions() - { - parse_str($this->options, $datas); - $this->hydrate($datas); - } - - public function generatecontent() - { - $mediamanager = new Modelmedia(); - $medialist = $mediamanager->getlistermedia($this->dir(), $this->type); - if (!$medialist) { - return false; - } else { - $mediamanager->medialistsort($medialist, $this->sortby, $this->order); - - $dirid = str_replace('/', '-', $this->path); - - $div = '<div class="medialist" id="' . $dirid . '">' . PHP_EOL; - - foreach ($medialist as $media) { - $div .= '<div class="content ' . $media->type() . '">'; - $id = 'id="media_' . $media->id() . '"'; - $path = $media->getincludepath(); - $ext = $media->extension(); - if ($media->type() == 'image') { - $div .= '<img alt="' . $media->id() . '" ' . $id . ' src="' . $path . '" >'; - } elseif ($media->type() == 'sound') { - $div .= '<audio ' . $id . ' controls src="' . $path . '" </audio>'; - } elseif ($media->type() == 'video') { - $source = '<source src="' . $path . '" type="video/' . $ext . '" ' . $id . '>'; - $div .= '<video controls>' . $source . '</video>'; - } else { - $name = $media->id() . '.' . $ext; - $div .= '<a href="' . $path . '" target="_blank" class="media" ' . $id . '>' . $name . '</a>'; - } - $div .= '</div>' . PHP_EOL; - } - - $div .= '</div>' . PHP_EOL; - - return $div; - } - } - - /** - * Generate link adress for table header - * - * @param string $sortby - * @return string link adress - */ - public function getsortbyadress(string $sortby): string - { - if (!in_array($sortby, Model::MEDIA_SORTBY)) { - $sortby = 'id'; - } - if ($this->sortby === $sortby) { - $order = $this->order * -1; - } else { - $order = $this->order; - } - $query = ['path' => $this->path, 'sortby' => $sortby, 'order' => $order]; - if (array_diff(self::TYPES, $this->type) != []) { - $query['type'] = $this->type; - } - return '?' . urldecode(http_build_query($query)); - } - - public function getpathadress(string $path): string - { - $query = ['path' => '/' . $path, 'sortby' => $this->sortby, 'order' => $this->order]; - if (array_diff(self::TYPES, $this->type) != []) { - $query['type'] = $this->type; - } - return '?' . urldecode(http_build_query($query)); - } - - public function getquery() - { - $query = ['path' => $this->path, 'sortby' => $this->sortby, 'order' => $this->order]; - if (array_diff(self::TYPES, $this->type) != []) { - $query['type'] = $this->type; - } - return urldecode(http_build_query($query)); - } - - /** - * Get the code to insert directly - */ - public function getcode(): string - { - return '%MEDIA?' . $this->getquery() . '%'; - } - - public function getadress(): string - { - return '?' . $this->getquery(); - } - - - // ______________________________________________ G E T ________________________________________________________ - - - public function fullmatch() - { - return $this->fullmatch; - } - - public function options() - { - return $this->options; - } - - /** - * @return string formated like `/media/<folder>` - */ - public function path() - { - return $this->path; - } - - /** - * @return string formated like `media/<folder>/` - */ - public function dir() - { - return ltrim($this->path, '/') . '/'; - } - - public function sortby() - { - return $this->sortby; - } - - public function order() - { - return $this->order; - } - - public function type() - { - return $this->type; - } - - // ______________________________________________ S E T ________________________________________________________ - - - public function setfullmatch(string $fullmatch) - { - $this->fullmatch = $fullmatch; - } - - - public function setoptions(string $options) - { - if (!empty($options)) { - $this->options = $options; - } - } - - public function setpath(string $path) - { - if (preg_match('%^\/' . rtrim(Model::MEDIA_DIR, DIRECTORY_SEPARATOR) . '%', $path)) { - $this->path = rtrim($path, DIRECTORY_SEPARATOR); - } elseif (!preg_match('%^\/%', $path)) { - $this->path = '/' . Model::MEDIA_DIR . rtrim($path, DIRECTORY_SEPARATOR); - } - } - - public function setsortby(string $sortby) - { - if (in_array($sortby, Model::MEDIA_SORTBY)) { - $this->sortby = $sortby; - } - } - - public function setorder(int $order) - { - if ($order === -1 || $order === 1) { - $this->order = $order; - } - } - - public function settype($type) - { - if (is_array($type)) { - $this->type = array_intersect(Model::mediatypes(), array_unique($type)); - } - } -} |