Changeset 58

Show
Ignore:
Timestamp:
05/21/2007 08:50:07 AM (19 months ago)
Author:
Shadowhand
Message:

Fixed bug #17, make Router more compatible with the "enable_get_requests" option, enabled REQUEST_URI to be used when "uri_protocol" is set to AUTO

Location:
trunk/system/libraries
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Calendar.php

    r24 r58  
    149149                $this->parse_template(); 
    150150         
    151                 // Begin building the calendar output                                            
     151                // Begin building the calendar output 
    152152                $out = $this->temp['table_open']; 
    153153                $out .= "\n";    
     
    160160                if ($this->show_next_prev == TRUE) 
    161161                { 
    162                         // Add a trailing slash to the  URL if needed 
    163                         $this->next_prev_url = preg_replace("/(.+?)\/*$/", "\\1/",  $this->next_prev_url); 
     162                        // Add a trailing slash to the  URL 
     163                        $this->next_prev_url = rtrim($this->next_prev_url, '/').'/'; 
    164164                 
    165165                        $adjusted_date = $this->adjust_date($month - 1, $year); 
  • trunk/system/libraries/Config.php

    r24 r58  
    4747                $this->config =& get_config(); 
    4848                log_message('debug', "Config Class Initialized"); 
    49         }        
    50          
     49        } 
     50         
    5151        // -------------------------------------------------------------------- 
    5252 
     
    7575                        show_error('The configuration file '.$file.EXT.' does not exist.'); 
    7676                } 
    77          
     77                 
    7878                include(APPPATH.'config/'.$file.EXT); 
    79  
     79                 
    8080                if ( ! isset($config) OR ! is_array($config)) 
    8181                { 
     
    8383                        { 
    8484                                return FALSE; 
    85                         }                
     85                        } 
    8686                        show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); 
    8787                } 
     
    123123         */              
    124124        function item($item, $index = '') 
    125         {                        
     125        { 
    126126                if ($index == '') 
    127127                {        
     
    167167        { 
    168168                if ( ! isset($this->config[$item])) 
    169                 { 
    170169                        return FALSE; 
    171                 } 
    172170                 
    173171                $pref = $this->config[$item]; 
    174172                 
    175173                if ($pref != '') 
    176                 {                        
    177                         if (ereg("/$", $pref) === FALSE) 
    178                         { 
    179                                 $pref .= '/'; 
    180                         } 
    181                 } 
    182  
     174                        $pref = rtrim($pref, "/")."/"; 
     175                 
    183176                return $pref; 
    184177        } 
     
    192185         * @param       string  the URI string 
    193186         * @return      string 
    194          */              
     187         */ 
    195188        function site_url($uri = '') 
    196189        { 
    197190                if (is_array($uri)) 
    198                 { 
    199                         $uri = implode('/', $uri); 
    200                 } 
    201                  
    202                 if ($uri == '') 
    203                 { 
    204                         return $this->slash_item('base_url').$this->item('index_page'); 
    205                 } 
    206                 else 
    207                 { 
    208                         $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');                 
    209                         return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; 
    210                 } 
     191                        $uri = implode("/", $uri); 
     192                 
     193                $url = $this->slash_item('base_url').$this->item('index_page'); 
     194                // Append uri to the site_url 
     195                if ($uri != '') 
     196                        $url .= rtrim($uri, "/")."/".$this->item('url_suffix'); 
     197                 
     198                return $url; 
    211199        } 
    212200         
     
    218206         * @access      public 
    219207         * @return      string 
    220          */              
     208         */ 
    221209        function system_url() 
    222210        { 
    223                 $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); 
    224                 return $this->slash_item('base_url').end($x).'/'; 
     211                $uri = explode("/", rtrim(BASEPATH, "/")); 
     212                return $this->slash_item('base_url').end($uri)."/"; 
    225213        } 
    226214         
     
    234222         * @param       string  the config item value 
    235223         * @return      void 
    236          */              
     224         */ 
    237225        function set_item($item, $value) 
    238226        { 
  • trunk/system/libraries/Ftp.php

    r24 r58  
    375375                } 
    376376 
    377                 // Add a trailing slash to the file path if needed 
    378                 $filepath = preg_replace("/(.+?)\/*$/", "\\1/",  $filepath); 
     377                // Add a trailing slash to the file path 
     378                $filepath = rtrim($filepath, '/').'/'; 
    379379                 
    380380                $list = $this->list_files($filepath); 
     
    383383                { 
    384384                        foreach ($list as $item) 
    385                         {                        
     385                        { 
    386386                                // If we can't delete the item it's probaly a folder so 
    387387                                // we'll recursively call delete_dir() 
  • trunk/system/libraries/Router.php

    r47 r58  
    6666         */ 
    6767        function _set_route_mapping() 
    68         {                
     68        { 
    6969                // Are query strings enabled in the config file? 
    7070                // If so, we're done since segment based URIs are not used with query strings. 
     
    8888                // Set the default controller so we can display it in the event 
    8989                // the URI doesn't correlated to a valid controller. 
    90                 $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);      
     90                $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); 
    9191                 
    9292                // Fetch the complete URI string 
     
    123123                // Explode the URI Segments. The individual segments will 
    124124                // be stored in the $this->segments array.       
    125                 foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) 
     125                foreach(explode("/", trim(rtrim($this->uri_string, "/"), "/") as $val) 
    126126                { 
    127127                        // Filter segments for security 
     
    129129                         
    130130                        if ($val != '') 
     131                        { 
    131132                                $this->segments[] = $val; 
     133                        } 
    132134                } 
    133135                 
     
    154156         */ 
    155157        function _compile_segments($segments = array()) 
    156         {        
     158        { 
    157159                $segments = $this->_validate_segments($segments); 
    158160                 
    159161                if (count($segments) == 0) 
    160                 { 
    161162                        return; 
    162                 } 
    163                                                  
     163                 
    164164                $this->set_class($segments[0]); 
    165165                 
     
    205205                // Is the controller in a sub-folder? 
    206206                if (is_dir(APPPATH.'controllers/'.$segments[0])) 
    207                 {                
     207                { 
    208208                        // Set the directory and remove it from the segment array 
    209209                        $this->set_directory($segments[0]); 
     
    231231                         
    232232                        } 
    233                                  
     233                         
    234234                        return $segments; 
    235235                } 
     
    255255                // Is the routed segment array different then the main segment array? 
    256256                $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; 
    257          
     257                 
    258258                $i = 1; 
    259259                foreach ($this->segments as $val) 
     
    290290                if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') 
    291291                { 
    292                         // If the URL has a question mark then it's simplest to just 
    293                         // build the URI string from the zero index of the $_GET array. 
    294                         // This avoids having to deal with $_SERVER variables, which 
    295                         // can be unreliable in some environments 
    296                         if (is_array($_GET) AND count($_GET) == 1) 
    297                         { 
    298                                 // Note: Due to a bug in current() that affects some versions 
    299                                 // of PHP we can not pass function call directly into it 
    300                                 $keys = array_keys($_GET); 
    301                                 return current($keys); 
    302                         } 
    303                  
     292                        if ($this->config->item('enable_get_requests') == FALSE) 
     293                        { 
     294                                // If the URL has a question mark then it's simplest to just 
     295                                // build the URI string from the zero index of the $_GET array. 
     296                                // This avoids having to deal with $_SERVER variables, which 
     297                                // can be unreliable in some environments 
     298                                if (is_array($_GET) AND count($_GET) == 1) 
     299                                { 
     300                                        // Note: Due to a bug in current() that affects some versions 
     301                                        // of PHP we can not pass function call directly into it 
     302                                        $keys = array_keys($_GET); 
     303                                        return current($keys); 
     304                                } 
     305                        } 
     306                         
    304307                        // Is there a PATH_INFO variable? 
    305                         // Note: some servers seem to have trouble with getenv() so we'll test it two ways               
    306                         $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');   
     308                        // Note: some servers seem to have trouble with getenv() so we'll test it two ways 
     309                        $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); 
    307310                        if ($path != '' AND $path != "/".SELF) 
    308                         { 
    309311                                return $path; 
    310                         } 
    311                                          
    312                         // No PATH_INFO?... What about QUERY_STRING? 
    313                         $path =  (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');         
    314                         if ($path != '') 
    315                         { 
    316                                 return $path; 
     312                         
     313                        if ($this->config->item('enable_get_requests') == FALSE)  
     314                        { 
     315                                // No PATH_INFO?... What about QUERY_STRING? 
     316                                $path =  (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); 
     317                                if ($path != '') 
     318                                        return $path; 
    317319                        } 
    318320                         
     
    320322                        $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');    
    321323                        if ($path != '' AND $path != "/".SELF) 
    322                         { 
    323324                                return $path; 
    324                         } 
    325  
    326                         // We've exhausted all our options... 
    327                         return ''; 
     325                         
     326                        // We've exhausted all our options, try REQUEST_URI 
     327                        return $this->_parse_request_uri(); 
    328328                } 
    329329                else 
     
    332332                         
    333333                        if ($uri == 'REQUEST_URI') 
    334                         { 
    335334                                return $this->_parse_request_uri(); 
    336                         } 
    337335                         
    338336                        return (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); 
     
    355353        { 
    356354                if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') 
    357                 { 
    358355                        return ''; 
    359                 } 
    360                  
    361                 $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); 
    362  
     356                 
     357                $request_uri = trim(str_replace("\\", "/", $_SERVER['REQUEST_URI']), '/'); 
     358                 
    363359                if ($request_uri == '' OR $request_uri == SELF) 
    364                 { 
    365360                        return ''; 
    366                 } 
    367                  
    368                 $fc_path = FCPATH;               
     361                 
     362                $fc_path = FCPATH; 
    369363                if (strpos($request_uri, '?') !== FALSE) 
    370364                { 
     
    373367                 
    374368                $parsed_uri = explode("/", $request_uri); 
    375                                  
     369                 
    376370                $i = 0; 
    377371                foreach(explode("/", $fc_path) as $segment) 
    378372                { 
    379373                        if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) 
    380                         { 
    381374                                $i++; 
    382                         } 
    383375                } 
    384376                 
     
    444436                        return; 
    445437                } 
    446  
     438                 
    447439                // Turn the segment array into a URI string 
    448440                $uri = implode('/', $this->segments); 
     
    455447                        return; 
    456448                } 
    457                                  
     449                 
    458450                // Loop through the route array looking for wild-cards 
    459451                foreach (array_slice($this->routes, 1) as $key => $val) 
  • trunk/system/libraries/URI.php

    r24 r58  
    144144                 
    145145                if ( ! is_numeric($n)) 
    146                 { 
    147146                        return $default; 
    148                 } 
    149147         
    150148                if (isset($this->keyval[$n])) 
    151                 { 
    152149                        return $this->keyval[$n]; 
    153                 } 
    154150         
    155151                if ($this->$total_segments() < $n) 
    156152                { 
    157153                        if (count($default) == 0) 
    158                         { 
    159154                                return array(); 
    160                         } 
    161155                         
    162156                        $retval = array(); 
     
    164158                        { 
    165159                                $retval[$val] = FALSE; 
    166                         }                
     160                        } 
    167161                        return $retval; 
    168162                } 
    169  
     163                 
    170164                $segments = array_slice($this->$segment_array(), ($n - 1)); 
    171  
     165                 
    172166                $i = 0; 
    173                 $lastval = ''; 
     167                $lastval = ""; 
    174168                $retval  = array(); 
    175169                foreach ($segments as $seg) 
     
    212206         * @return      array 
    213207         */     function assoc_to_uri($array) 
    214         {        
     208        { 
    215209                $temp = array(); 
    216210                foreach ((array)$array as $key => $val) 
     
    220214                } 
    221215                 
    222                 return implode('/', $temp); 
     216                return implode("/", $temp); 
    223217        } 
    224218 
     
    268262                if ($where == 'trailing') 
    269263                { 
    270                         $trailing       = '/'; 
    271                         $leading        = ''; 
     264                        $trailing       = "/"; 
     265                        $leading        = ""; 
    272266                } 
    273267                elseif ($where == 'leading') 
    274268                { 
    275                         $leading        = '/'; 
    276                         $trailing       = ''; 
     269                        $leading        = "/"; 
     270                        $trailing       = ""; 
    277271                } 
    278272                else 
    279273                { 
    280                         $leading        = '/'; 
    281                         $trailing       = '/'; 
     274                        $leading        = "/"; 
     275                        $trailing       = "/"; 
    282276                } 
    283277                return $leading.$this->$which($n).$trailing; 
     
    360354        function ruri_string() 
    361355        { 
    362                 return '/'.implode('/', $this->rsegment_array()).'/'; 
     356                return "/".implode("/", $this->rsegment_array())."/"; 
    363357        } 
    364358 
  • trunk/system/libraries/Upload.php

    r24 r58  
    622622                } 
    623623 
    624                 $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/",  $this->upload_path); 
     624                $this->upload_path = rtrim($this->upload_path, '/').'/'; 
    625625                return TRUE; 
    626626        }