diff --git a/system/url.php b/system/url.php index 9bf47dd5..5235b68c 100644 --- a/system/url.php +++ b/system/url.php @@ -5,33 +5,27 @@ class URL { /** * Generate an application URL. * + * If the given URL is already well-formed, it will be returned unchanged. + * * @param string $url * @param bool $https - * @param bool $asset * @return string */ - public static function to($url = '', $https = false, $asset = false) + public static function to($url = '', $https = false) { - if (strpos($url, '://') !== false) + if (filter_var($url, FILTER_VALIDATE_URL) !== false) { return $url; } - $base = Config::get('application.url'); + $base = Config::get('application.url').'/'.Config::get('application.index'); - // If the URL is being generated for a public asset such as an - // image, we do not want to include "index.php" in the path. - if ( ! $asset) - { - $base .= '/'.Config::get('application.index'); - } - - if (strpos($base, 'http://') === 0 and $https) + if ($https and strpos($base, 'http://') === 0) { $base = 'https://'.substr($base, 7); } - return rtrim($base, '/').'/'.trim($url, '/'); + return $base.'/'.ltrim($url, '/'); } /** @@ -52,9 +46,9 @@ public static function to_secure($url = '') * @param string $url * @return string */ - public static function to_asset($url = '') + public static function to_asset($url) { - return static::to($url, Request::is_secure(), true); + return str_replace('/'.Config::get('application.index'), '', static::to($url, Request::is_secure())); } /**