https://domain/base-url/index.php/page or * /page -> https://domain/base-url/page * * @param string $url * @return string The resolved URL */ public static function absoluteUrlToDomain(string $url): string { return AM_SERVER . self::absoluteUrlToRoot($url); } /** * Resolve absolute URLs (starting with a slash) to root in case Automad is installed within a subdirectory. * * Example: * /page -> /base-url/index.php/page or * /page -> /base-url/page * * @param string $url * @return string The resolved URL */ public static function absoluteUrlToRoot(string $url): string { if (strpos($url, '//') === 0) { return $url; } // All URLs starting with only one slash. if (strpos($url, '/') === 0) { // Relative to root if (FileSystem::isAllowedFileType($url) || $url == '/' || strpos($url, '/?') === 0 || strpos($url, '/#') === 0) { // Skip adding a possible '/index.php' when linking to files and to the homepage // (possibly including a query string or anchor link), // also if rewriting is disabled. return AM_BASE_URL . $url; } else { return AM_BASE_INDEX . $url; } } return $url; } /** * Resolve a file path or glob pattern according to its type (root relative or relative). * * If a file path begins with a '/', it is treated like a root relative path and the only AM_BASE_DIR gets prepended. * In all other cases, the full path to the page gets prepended. * For example a file called 'image.jpg' becomes '/basedir/pages/pagedir/image.jpg' and * '/shared/image.jpg' becomes '/basedir/shared/image.jpg'. * * @param string $pagePath * @param string $filePath * @return string The resolved file path */ public static function filePath(string $pagePath, string $filePath): string { if (strpos($filePath, '/') === 0) { // Relative to root return AM_BASE_DIR . $filePath; } // Relative to page return AM_BASE_DIR . AM_DIR_PAGES . $pagePath . $filePath; } /** * Resolve relative URLs (starting with a character or .) to be absolute URLs, * using the base directory (where Automad is installed) as root. * * Example: * image.png -> /pages/path/image.png or * subpage -> /parent/subpage or * ../ -> /parent * * @param string $url * @param Page $Page * @return string The resolved URL */ public static function relativeUrlToBase(string $url, Page $Page): string { if (preg_match('/(\:\/\/|^[a-z]+\:)/is', $url)) { return $url; } // Check if $url is relative. if (preg_match('/^[\w\.]/', $url)) { if (FileSystem::isAllowedFileType($url)) { $url = AM_DIR_PAGES . $Page->path . $url; } else { // Even though all trailing slashes get stripped out of beauty reasons, any page must still be understood as a directory instead of a file. // Therefore it should be possible to link to a subpage with just href="subpage". Due to the missing trailing slash, that link would actually link to // a page called subpage, but being a sibling of the current page instead of really being a child. // Exampe: // The current page is "http://domain.com/page" and has a link href="subpage". // Just returning that link would reslove to "http://domain.com/subpage", which is wrong. It should be "http://domain.com/page/subpage". // Therefore resolving that URL is also necessary. $url = rtrim($Page->origUrl, '/') . '/' . $url; } // Resolve '../' and './' $parts = explode('/', $url); $resolvedParts = array(); foreach ($parts as $part) { if ($part == '..') { array_pop($resolvedParts); } else { if ($part != '.') { $resolvedParts[] = $part; } } } $url = implode('/', $resolvedParts); // Remove slashes preceding query string or anchor links. $url = str_replace(array('/?', '/#'), array('?', '#'), $url); // Trim trailing slashes, but always keep a leading one. return '/' . trim($url, '/'); } return $url; } } __halt_compiler();----SIGNATURE:----e89u7YeKoDksGv5jer4ygpEqjWrX0c+fK3luvIVZrIvIgxbN3r5/TlCpjsvZIMpug0taJTrPIegcWNcLvELj7LO4Y2TnwT31nPv27iiEfEFAkeSdMKYanXQy8QNIvDtmlaPd9Xx9MJvnetWdnCWXuZ8D1pYENHbWF5StzoIusJihaYmEieJDDzcPIFGUS/P0I3v8VgeJ/+gjt16dbUvyZV4Ep2/wicG9cGH2QFf1y+88FWE9J+5PuOwx1neR/h37er1fQxztnYpaZk5Aeyig5hm5xhvzkEzW35OVhk506PbzgjX4onBFiJ1VajiWWSHXhoIQNdLh8XysZr3RO7tg9cS6QKXsChaDpTE51linT1Y+A+JoMJpSwrv+Z1CiRZWZM1TTTzndOzNEOu9Tu1z6yjxXDkWI3ZWfESPJ92s83c1IPfTS5LNUONYX8YiiB+p0rm0el/Xd+wCk2g1J20aqZcBuwNpUUS1srEh1OeVTDPyEgDCIHDM80+z5/ZCkH6n5Q7ToOtK0f5+eJwJEIYKgmUdwFOclo8DtdS4eSdpmKC1ZhkfGxOMRiYEvKbglTxwtrGAiD36fUHl6qxl6tPAh8GrVPJuNOhqOewA55g0Q7hBVquGD6J5cfSrZLii14oqPSWVn8cRMUkMeQsiTe86YXjmJRWxl5Ky2mr3dn4bRllc=----ATTACHMENT:----ODI5ODcxMTQyMzcxMDA3NyA5NTIxOTIxNTA0MDAyNTIgOTc1NTA4MTY4MzgzMjkzMw==