From 49273cba81ea86639a23dfd5a43bda2f6b01f075 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Mon, 20 Jan 2020 01:56:57 +0100 Subject: fix media little problems --- app/class/Medialist.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'app/class/Medialist.php') diff --git a/app/class/Medialist.php b/app/class/Medialist.php index d36e5d1..b208fef 100644 --- a/app/class/Medialist.php +++ b/app/class/Medialist.php @@ -113,14 +113,20 @@ class Medialist } else { $order = $this->order; } - $query = ['path' => $this->path, 'sortby' => $sortby, 'order' => $order, 'type' => $this->type]; + $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, 'type' => $this->type]; + $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)); } @@ -147,6 +153,9 @@ class Medialist return $this->filter; } + /** + * @return string formated like `/media/` + */ public function path() { return $this->path; @@ -193,10 +202,10 @@ class Medialist public function setpath(string $path) { - if(preg_match('%^\/' . Model::MEDIA_DIR . '%', $path)) { - $this->path = $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 . $path; + $this->path = '/' . Model::MEDIA_DIR . rtrim($path, DIRECTORY_SEPARATOR); } } -- cgit v1.2.3