Skip to content

Commit 5ba456c

Browse files
committed
Fix relative to absolute url conversion
1 parent cb4d0ef commit 5ba456c

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

Embed/Url.php

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -406,24 +406,6 @@ public function getDirectory ($key) {
406406
}
407407

408408

409-
410-
/**
411-
* Remove a portion of the path
412-
*
413-
* @param int $offset The position to start to remove
414-
* @param int $length The number of directories to remove. If not specified, removes until the end
415-
*/
416-
public function splicePath ($offset, $length = null) {
417-
if (isset($length)) {
418-
array_splice($this->info['path'], $offset, $length);
419-
} else {
420-
array_splice($this->info['path'], $offset);
421-
}
422-
423-
$this->buildUrl();
424-
}
425-
426-
427409
/**
428410
* Set a new path
429411
*/
@@ -436,15 +418,25 @@ public function setPath ($path) {
436418
}
437419
}
438420

421+
if (substr($path, -1) !== '/') {
422+
$this->info['file'] = array_pop($this->info['path']);
423+
}
424+
439425
$this->buildUrl();
440426
}
441427

442428

443429
/**
444430
* Return the url path
445431
*/
446-
public function getPath () {
447-
return isset($this->info['path']) ? implode('/', $this->info['path']) : '';
432+
public function getPath ($file = false) {
433+
$path = isset($this->info['path']) ? implode('/', $this->info['path']) : '';
434+
435+
if ($file && !empty($this->info['file'])) {
436+
$path .= '/'.$this->info['file'];
437+
}
438+
439+
return $path;
448440
}
449441

450442

@@ -543,6 +535,10 @@ private function buildUrl ($maintainCache = false) {
543535

544536
$url .= '/'.$this->getPath();
545537

538+
if (isset($this->info['file'])) {
539+
$url .= '/'.$this->info['file'];
540+
}
541+
546542
if (isset($this->info['query'])) {
547543
$url .= '?'.http_build_query($this->info['query']);
548544
}
@@ -577,7 +573,7 @@ private function parseUrl ($url) {
577573
if (isset($this->info['path'])) {
578574
$this->setPath($this->info['path']);
579575

580-
if (preg_match('/\.([\w]+)$/', end($this->info['path']), $match)) {
576+
if (!empty($this->info['file']) && preg_match('/\.([\w]+)$/', $this->info['file'], $match)) {
581577
$this->info['extension'] = $match[1];
582578
}
583579
}
@@ -615,14 +611,13 @@ public function getAbsolute ($url) {
615611
}
616612

617613
if ($url[0] === '?') {
618-
return $this->getScheme().'://'.$this->getHost().$this->getPath().$url;
614+
return $this->getScheme().'://'.$this->getHost().'/'.$this->getPath().$url;
619615
}
620616

621-
if (substr($this->getPath(), -1) === '/') {
622-
return $this->getScheme().'://'.$this->getHost().$this->getPath().$url;
623-
}
624-
625-
return $this->getScheme().'://'.$this->getHost().dirname($this->getPath()).$url;
617+
$path = $this->getPath();
618+
$path = !$path ? '/' : "/$path/";
619+
620+
return $this->getScheme().'://'.$this->getHost().$path.$url;
626621
}
627622
}
628623
?>

0 commit comments

Comments
 (0)