Skip to content

Commit

Permalink
fixed trailing slashes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Dec 23, 2013
1 parent af07105 commit 01b29d0
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions Embed/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 !== '') {
Expand All @@ -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;
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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;
}
}
?>

0 comments on commit 01b29d0

Please sign in to comment.