Created
March 28, 2012 09:53
-
-
Save kemo/2225132 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class url { | |
protected $_static_extensions = array('ico','jpg','gif','bmp','png','js','css'); | |
/** | |
* Fetches an absolute site URL based on a URI segment. | |
* | |
* @param string site URI to convert | |
* @param string non-default protocol | |
* @return string | |
*/ | |
public static function site($uri = '', $protocol = FALSE) | |
{ | |
if ($path = trim(parse_url($uri, PHP_URL_PATH), '/')) | |
{ | |
$extension = pathinfo($path, PATHINFO_EXTENSION); | |
if ( ! in_array($extension, url::$_static_extensions)) | |
{ | |
// Add path suffix | |
$path .= Kohana::config('core.url_suffix'); | |
} | |
} | |
if ($query = parse_url($uri, PHP_URL_QUERY)) | |
{ | |
// ?query=string | |
$query = '?'.$query; | |
} | |
if ($fragment = parse_url($uri, PHP_URL_FRAGMENT)) | |
{ | |
// #fragment | |
$fragment = '#'.$fragment; | |
} | |
// Concat the URL | |
return url::base(TRUE, $protocol).$path.$query.$fragment; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment