Changeset 2178

Show
Ignore:
Timestamp:
02/27/2008 02:12:48 PM (11 months ago)
Author:
gregmac
Message:

Allow html::base() to return absolute paths (no protocol/domain) when possible; change defaults for site_domain and site_protocol to be '/kohana/' and blank, respectively

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/application/config/config.php

    r2177 r2178  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    22/** 
    3  * Domain name, with the installation directory. Default: localhost/kohana/ 
    4  * If this starts with a /, Kohana will try to get the domain from HTTP_HOST 
    5  * from  the web server. 
     3 * Base path of the web site. If this includes a domain, (eg, "localhost/kohana/") then 
     4 * a full URL will be used (eg, "http://localhost/kohana/"). If it only includes the path,  
     5 * and a site_protocol is specified, the domain will be auto-detected. 
    66 */ 
    7 $config['site_domain'] = 'localhost/kohana/'; 
     7$config['site_domain'] = '/kohana/'; 
    88 
    99/** 
    10  * Default protocol used to access the website. Default: http 
     10 * Force a default protocol to be used by the site. If no site_protocol is specified, then the  
     11 * current protocol is used, or when possible, only an absolute path (with no protocol/domain)  
     12 * is used. 
    1113 */ 
    12 $config['site_protocol'] = 'http'; 
     14$config['site_protocol'] = ''; 
    1315 
    1416/** 
  • trunk/system/helpers/url.php

    r2177 r2178  
    1515         * Base URL, with or without the index page. 
    1616         * 
     17         * If protocol (and core.site_protocol) and core.site_domain are both empty,  
     18         * then  
     19         * 
    1720         * @param   boolean  include the index page 
    1821         * @param   boolean  non-default protocol 
     
    2225        { 
    2326                $protocol = ($protocol == FALSE) ? Config::item('core.site_protocol') : strtolower($protocol); 
    24                 // try to auto-detect protocol 
    25                 empty($protocol) AND $protocol = (isset($_SERVER['HTTPS']) AND ($_SERVER['HTTPS'] != '')) ? 'https' : 'http'; 
    26  
     27                 
    2728                $site_domain = Config::item('core.site_domain', TRUE); 
    28                 // Add current servername if site_domain starts with a / 
    29                 (strlen($site_domain) > 0 AND $site_domain[0] == '/') AND $site_domain = $_SERVER['HTTP_HOST'].$site_domain; 
    3029                 
    31                 // if site_domain is empty, no base url. This results in  
    32                 // a relative path (eg, "index.php/") being returned 
    33                 $base_url = (!empty($site_domain)) ? $protocol.'://'.$site_domain : ''; 
     30                if (empty($protocol)) 
     31                { 
     32                        if (strlen($site_domain) > 0 AND $site_domain[0] != '/')  
     33                        { 
     34                                // try to guess protocol, provide full http://domain/path... 
     35                                $base_url = (!empty($_SERVER['HTTPS']) ? 'https' : 'http').'://'.$site_domain; 
     36                        } 
     37                        else 
     38                        { 
     39                                // provide only path, eg /path... 
     40                                $base_url = !empty($site_domain) ? $site_domain : ''; 
     41                        } 
     42                } 
     43                else 
     44                { 
     45                        // return a full url 
     46                         
     47                        // Add current servername if site_domain starts with a / 
     48                        if (empty($site_domain) OR $site_domain[0] == '/') 
     49                        { 
     50                                $base_url = $protocol.'://'.$_SERVER['HTTP_HOST'].(!empty($site_domain) ? $site_domain : ''); 
     51                        } 
     52                        else  
     53                        { 
     54                                $base_url = $protocol.'://'.(!empty($site_domain) ? $site_domain : ''); 
     55                        } 
     56                } 
    3457                 
     58                // make sure base_url ends in a slash 
     59                (!empty($base_url) AND ($base_url[strlen($base_url)-1] != '/')) AND $base_url .= '/'; 
     60                 
     61                // add index.php if needed 
    3562                if ($index == TRUE AND $index = Config::item('core.index_page')) 
    3663                {