public relativeUrl ( $url ) |
public function relativeUrl($url)
{
// If string contains ://, it is considered as absolute
if (preg_match('/:\\/\\//mUsi', $url)) {
return $url;
}
// If string begins with "/", the "/" is removed to resolve the
// relative path
if (strlen($url) && $url[0] == '/') {
$url = substr($url, 1);
if ($this->samePrefix($url)) {
// If the prefix is the same, simply returns the file name
$relative = basename($url);
} else {
// Else, returns enough ../ to get upper
$relative = '';
for ($k = 0; $k < $this->getDepth(); $k++) {
$relative .= '../';
}
$relative .= $url;
}
} else {
$relative = $url;
}
return $relative;
}
public function resolve(Environment $environment, $data) { $metas = $environment->getMetas(); $file = $environment->canonicalUrl($data); if ($metas) { $entry = $metas->get($file); $entry['url'] = $environment->relativeUrl('/' . $entry['url']); } else { $entry = array('title' => '(unresolved)', 'url' => '#'); } return $entry; }