public static getCleanPath ( string $path ) : string | ||
$path | string | |
return | string |
public static function getCleanPath($path)
{
$path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
$absolutes = [];
foreach ($parts as $part) {
if ('.' == $part) {
continue;
}
if ('..' == $part) {
array_pop($absolutes);
} else {
$absolutes[] = $part;
}
}
return implode(DIRECTORY_SEPARATOR, $absolutes);
}
private function findImage($src, $tag, Content $file, $callback) { //for protocol relative or http requests : keep the original one if (substr($src, 0, strlen('http')) === 'http' || substr($src, 0, strlen('//')) === '//') { return $src; } //Get the path to the file, relative to the root of the documentation $url = DauxHelper::getCleanPath(dirname($file->getUrl()) . '/' . $src); //Get any file corresponding to the right one $file = DauxHelper::getFile($this->tree, $url); if ($file === false) { return false; } $result = $callback($src, $this->getAttributes($tag), $file); return $result ?: $src; }