Changeset 58
- Timestamp:
- 05/21/2007 08:50:07 AM (19 months ago)
- Location:
- trunk/system/libraries
- Files:
-
- 6 modified
-
Calendar.php (modified) (2 diffs)
-
Config.php (modified) (8 diffs)
-
Ftp.php (modified) (2 diffs)
-
Router.php (modified) (15 diffs)
-
URI.php (modified) (6 diffs)
-
Upload.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/Calendar.php
r24 r58 149 149 $this->parse_template(); 150 150 151 // Begin building the calendar output 151 // Begin building the calendar output 152 152 $out = $this->temp['table_open']; 153 153 $out .= "\n"; … … 160 160 if ($this->show_next_prev == TRUE) 161 161 { 162 // Add a trailing slash to the URL if needed163 $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, '/').'/'; 164 164 165 165 $adjusted_date = $this->adjust_date($month - 1, $year); -
trunk/system/libraries/Config.php
r24 r58 47 47 $this->config =& get_config(); 48 48 log_message('debug', "Config Class Initialized"); 49 } 50 49 } 50 51 51 // -------------------------------------------------------------------- 52 52 … … 75 75 show_error('The configuration file '.$file.EXT.' does not exist.'); 76 76 } 77 77 78 78 include(APPPATH.'config/'.$file.EXT); 79 79 80 80 if ( ! isset($config) OR ! is_array($config)) 81 81 { … … 83 83 { 84 84 return FALSE; 85 } 85 } 86 86 show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); 87 87 } … … 123 123 */ 124 124 function item($item, $index = '') 125 { 125 { 126 126 if ($index == '') 127 127 { … … 167 167 { 168 168 if ( ! isset($this->config[$item])) 169 {170 169 return FALSE; 171 }172 170 173 171 $pref = $this->config[$item]; 174 172 175 173 if ($pref != '') 176 { 177 if (ereg("/$", $pref) === FALSE) 178 { 179 $pref .= '/'; 180 } 181 } 182 174 $pref = rtrim($pref, "/")."/"; 175 183 176 return $pref; 184 177 } … … 192 185 * @param string the URI string 193 186 * @return string 194 */ 187 */ 195 188 function site_url($uri = '') 196 189 { 197 190 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; 211 199 } 212 200 … … 218 206 * @access public 219 207 * @return string 220 */ 208 */ 221 209 function system_url() 222 210 { 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)."/"; 225 213 } 226 214 … … 234 222 * @param string the config item value 235 223 * @return void 236 */ 224 */ 237 225 function set_item($item, $value) 238 226 { -
trunk/system/libraries/Ftp.php
r24 r58 375 375 } 376 376 377 // Add a trailing slash to the file path if needed378 $filepath = preg_replace("/(.+?)\/*$/", "\\1/", $filepath);377 // Add a trailing slash to the file path 378 $filepath = rtrim($filepath, '/').'/'; 379 379 380 380 $list = $this->list_files($filepath); … … 383 383 { 384 384 foreach ($list as $item) 385 { 385 { 386 386 // If we can't delete the item it's probaly a folder so 387 387 // we'll recursively call delete_dir() -
trunk/system/libraries/Router.php
r47 r58 66 66 */ 67 67 function _set_route_mapping() 68 { 68 { 69 69 // Are query strings enabled in the config file? 70 70 // If so, we're done since segment based URIs are not used with query strings. … … 88 88 // Set the default controller so we can display it in the event 89 89 // 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']); 91 91 92 92 // Fetch the complete URI string … … 123 123 // Explode the URI Segments. The individual segments will 124 124 // 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) 126 126 { 127 127 // Filter segments for security … … 129 129 130 130 if ($val != '') 131 { 131 132 $this->segments[] = $val; 133 } 132 134 } 133 135 … … 154 156 */ 155 157 function _compile_segments($segments = array()) 156 { 158 { 157 159 $segments = $this->_validate_segments($segments); 158 160 159 161 if (count($segments) == 0) 160 {161 162 return; 162 } 163 163 164 164 $this->set_class($segments[0]); 165 165 … … 205 205 // Is the controller in a sub-folder? 206 206 if (is_dir(APPPATH.'controllers/'.$segments[0])) 207 { 207 { 208 208 // Set the directory and remove it from the segment array 209 209 $this->set_directory($segments[0]); … … 231 231 232 232 } 233 233 234 234 return $segments; 235 235 } … … 255 255 // Is the routed segment array different then the main segment array? 256 256 $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; 257 257 258 258 $i = 1; 259 259 foreach ($this->segments as $val) … … 290 290 if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') 291 291 { 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 304 307 // 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'); 307 310 if ($path != '' AND $path != "/".SELF) 308 {309 311 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; 317 319 } 318 320 … … 320 322 $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); 321 323 if ($path != '' AND $path != "/".SELF) 322 {323 324 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(); 328 328 } 329 329 else … … 332 332 333 333 if ($uri == 'REQUEST_URI') 334 {335 334 return $this->_parse_request_uri(); 336 }337 335 338 336 return (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); … … 355 353 { 356 354 if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') 357 {358 355 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 363 359 if ($request_uri == '' OR $request_uri == SELF) 364 {365 360 return ''; 366 } 367 368 $fc_path = FCPATH; 361 362 $fc_path = FCPATH; 369 363 if (strpos($request_uri, '?') !== FALSE) 370 364 { … … 373 367 374 368 $parsed_uri = explode("/", $request_uri); 375 369 376 370 $i = 0; 377 371 foreach(explode("/", $fc_path) as $segment) 378 372 { 379 373 if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) 380 {381 374 $i++; 382 }383 375 } 384 376 … … 444 436 return; 445 437 } 446 438 447 439 // Turn the segment array into a URI string 448 440 $uri = implode('/', $this->segments); … … 455 447 return; 456 448 } 457 449 458 450 // Loop through the route array looking for wild-cards 459 451 foreach (array_slice($this->routes, 1) as $key => $val) -
trunk/system/libraries/URI.php
r24 r58 144 144 145 145 if ( ! is_numeric($n)) 146 {147 146 return $default; 148 }149 147 150 148 if (isset($this->keyval[$n])) 151 {152 149 return $this->keyval[$n]; 153 }154 150 155 151 if ($this->$total_segments() < $n) 156 152 { 157 153 if (count($default) == 0) 158 {159 154 return array(); 160 }161 155 162 156 $retval = array(); … … 164 158 { 165 159 $retval[$val] = FALSE; 166 } 160 } 167 161 return $retval; 168 162 } 169 163 170 164 $segments = array_slice($this->$segment_array(), ($n - 1)); 171 165 172 166 $i = 0; 173 $lastval = '';167 $lastval = ""; 174 168 $retval = array(); 175 169 foreach ($segments as $seg) … … 212 206 * @return array 213 207 */ function assoc_to_uri($array) 214 { 208 { 215 209 $temp = array(); 216 210 foreach ((array)$array as $key => $val) … … 220 214 } 221 215 222 return implode( '/', $temp);216 return implode("/", $temp); 223 217 } 224 218 … … 268 262 if ($where == 'trailing') 269 263 { 270 $trailing = '/';271 $leading = '';264 $trailing = "/"; 265 $leading = ""; 272 266 } 273 267 elseif ($where == 'leading') 274 268 { 275 $leading = '/';276 $trailing = '';269 $leading = "/"; 270 $trailing = ""; 277 271 } 278 272 else 279 273 { 280 $leading = '/';281 $trailing = '/';274 $leading = "/"; 275 $trailing = "/"; 282 276 } 283 277 return $leading.$this->$which($n).$trailing; … … 360 354 function ruri_string() 361 355 { 362 return '/'.implode('/', $this->rsegment_array()).'/';356 return "/".implode("/", $this->rsegment_array())."/"; 363 357 } 364 358 -
trunk/system/libraries/Upload.php
r24 r58 622 622 } 623 623 624 $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path);624 $this->upload_path = rtrim($this->upload_path, '/').'/'; 625 625 return TRUE; 626 626 }
