/** * Absolutize to current url – use in templates */ public static function absolutize($sUrl, $sPort = null) { /* return if already absolute URL */ if (parse_url($sUrl, PHP_URL_SCHEME) != '') { return $sUrl; } /* queries and anchors */ if (!$sUrl || $sUrl[0] == '#' || $sUrl[0] == '?') { return M::SITE_ROOT() . $sUrl; } /* parse base URL and convert to local variables: $scheme, $host, $path */ extract(parse_url(M::SITE_ROOT())); /* remove non-directory element from path */ // $path = preg_replace('#/[^/]*$#', '', $path); if (!isset($scheme)) { $scheme = ''; } else { $scheme = $scheme . ':'; } if (!isset($host)) { $host = ''; } if (!isset($path)) { $path = ''; } if ($sPort) { $host = $host . ':' . $sPort; } /* destroy path if relative url points to root */ //if ($sUrl[0] == '/') { $path = ''; } /* dirty absolute URL */ $sAbs = "{$host}{$path}/{$sUrl}"; /* replace '//' or '/./' or '/foo/../' with '/' */ $aRegex = array('#(/\\.?/)#', '#/(?!\\.\\.)[^/]+/\\.\\./#'); for ($n = 1; $n > 0; $sAbs = preg_replace($aRegex, '/', $sAbs, -1, $n)) { } /* absolute URL is ready! */ return $scheme . '//' . $sAbs; }
public static function redirectTo($sUrl) { self::$_bReadyToSend = true; if ($sUrl[0] == '/') { $sUrl = M::SITE_ROOT() . $sUrl; } debug('Redirecting to ' . $sUrl); // self::setHeader('HTTP/1.1 301 Moved Permanently'); self::setHeader("Location: {$sUrl}"); self::end(); }