Show
Ignore:
Timestamp:
05/06/2008 12:50:05 AM (7 months ago)
Author:
Shadowhand
Message:

Updated url::site() with a completely new method based on parse_url() rather than custom extraction. It benchmarks *very* slightly slower than the code it is replacing, but I believe increased dependability makes it worthwhile.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/helpers/url.php

    r2593 r2641  
    6767 
    6868        /** 
    69          * Fetches a site URL based on a URI segment. 
     69         * Fetches an absolute site URL based on a URI segment. 
    7070         * 
    7171         * @param   string  site URI to convert 
     
    7575        public static function site($uri = '', $protocol = FALSE) 
    7676        { 
    77                 $uri = trim($uri, '/'); 
     77                // uri/path 
     78                $path = trim(parse_url($uri, PHP_URL_PATH), '/'); 
    7879 
    79                 $qs = ''; // anchor?query=string 
    80                 $id = ''; // anchor#id 
     80                // ?query=string 
     81                $query = parse_url($uri, PHP_URL_QUERY); 
    8182 
    82                 if (strpos($uri, '?') !== FALSE) 
    83                 { 
    84                         list ($uri, $qs) = explode('?', $uri, 2); 
    85                         $qs = '?'.$qs; 
    86                 } 
     83                // #fragment 
     84                $fragment = parse_url($uri, PHP_URL_FRAGMENT); 
    8785 
    88                 if (strpos($uri, '#') !== FALSE) 
    89                 { 
    90                         list ($uri, $id) = explode('#', $uri, 2); 
    91                         $id = '#'.$id; 
    92                 } 
     86                // Set the URL suffix 
     87                $suffix = ($path !== '') ? Config::item('core.url_suffix') : ''; 
    9388 
    94                 $index_page = Config::item('core.index_page', TRUE); 
    95                 $url_suffix = ($uri !== '') ? Config::item('core.url_suffix') : ''; 
    96  
    97                 return url::base(FALSE, $protocol).$index_page.$uri.$url_suffix.$qs.$id; 
     89                // Concat the URL 
     90                return url::base(TRUE, $protocol).$path.$suffix.$query.$fragment; 
    9891        } 
    9992