From 01b29d067737c6aa0de2310c85b79a022391c654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20Otero?= Date: Tue, 24 Dec 2013 00:43:47 +0100 Subject: [PATCH] fixed trailing slashes #12 --- Embed/Url.php | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/Embed/Url.php b/Embed/Url.php index 24cf956b..70ec46df 100644 --- a/Embed/Url.php +++ b/Embed/Url.php @@ -393,6 +393,7 @@ public function getDirectory ($key) { */ public function setPath ($path) { $this->info['path'] = array(); + $this->info['file'] = null; foreach (explode('/', $path) as $dir) { if ($dir !== '') { @@ -412,10 +413,10 @@ public function setPath ($path) { * Return the url path */ public function getPath ($file = false) { - $path = isset($this->info['path']) ? implode('/', $this->info['path']) : ''; + $path = isset($this->info['path']) ? '/'.implode('/', $this->info['path']).'/' : '/'; if ($file && !empty($this->info['file'])) { - $path .= '/'.$this->info['file']; + $path .= $this->info['file']; } return $path; @@ -515,13 +516,7 @@ private function buildUrl ($maintainCache = false) { $url .= $this->info['host']; } - if (($path = $this->getPath())) { - $url .= '/'.$path; - } - - if (isset($this->info['file'])) { - $url .= '/'.$this->info['file']; - } + $url .= $this->getPath(true); if (isset($this->info['query'])) { $url .= '?'.http_build_query($this->info['query']); @@ -594,14 +589,6 @@ public function getAbsolute ($url) { return $this->getScheme().'://'.$this->getHost().$url; } - if ($url[0] === '?') { - return $this->getScheme().'://'.$this->getHost().'/'.$this->getPath().$url; - } - - $path = $this->getPath(); - $path = !$path ? '/' : "/$path/"; - - return $this->getScheme().'://'.$this->getHost().$path.$url; + return $this->getScheme().'://'.$this->getHost().$this->getPath().$url; } } -?>