Skip to content

Commit

Permalink
put url::solveRelative in my own code
Browse files Browse the repository at this point in the history
Seems like no merge is coming for
getkirby-v2/toolkit#213
  • Loading branch information
sebsel committed Jul 24, 2017
1 parent 0751d5d commit 32c07e1
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/mentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@
use Tpl;
use Exception;

function url__solveRelative($base, $path) {
if(url::isAbsolute($path)) return $path;
$fragments = url::fragments($path);
// If the path is not /absolute, take $home in account
if(!str::startsWith($path, '/')) {
$pathFragments = $fragments;
$baseFragments = url::fragments($base);
// If $base is not a folder, remove the last part
if(!str::endsWith($base, '/')) array_pop($baseFragments);
$fragments = $baseFragments;
foreach($pathFragments as $f) $fragments []= $f;
}
$filter = array(
'hash' => '',
'query' => '',
'params' => array(),
'fragments' => $fragments,
);
return url::build($filter, $base);
}

class Mentions extends Collection {

public $options = array();
Expand Down Expand Up @@ -163,7 +184,7 @@ static public function discoverEndpoint($url) {

if(preg_match('!\<(.*?)\>;\s*rel="?(.*?\s?)webmention(\s?.*?)"?!', $link, $match)) {

$endpoint = url::makeAbsolute($match[1], $url);
$endpoint = url__solveRelative($match[1], $url);

// return valid endpoint or continue searching
if(v::url($endpoint)) {
Expand All @@ -190,7 +211,7 @@ static public function discoverEndpoint($url) {
return $url;
}

$endpoint = url::makeAbsolute($match[1], $url);
$endpoint = url__solveRelative($match[1], $url);

// invalid endpoint
if(!v::url($endpoint)) {
Expand Down

0 comments on commit 32c07e1

Please sign in to comment.