Changeset 47
- Timestamp:
- 05/15/2007 04:00:09 PM (19 months ago)
- Location:
- trunk
- Files:
-
- 4 modified
-
application/config/config.php (modified) (1 diff)
-
system/libraries/Input.php (modified) (8 diffs)
-
system/libraries/Loader.php (modified) (7 diffs)
-
system/libraries/Router.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/application/config/config.php
r17 r47 115 115 */ 116 116 $config['permitted_uri_chars'] = 'a-z 0-9~%.:_-'; 117 118 119 /* 120 |-------------------------------------------------------------------------- 121 | ENABLE GET 122 |-------------------------------------------------------------------------- 123 | 124 | This option will enable $this->input->get('key') and $_GET['key'], but 125 | will allow you to continue using segment based URLs, unlike the 126 | 'enable_query_strings' option, which will disable segment based URLs. 127 | 128 | Options are: TRUE or FALSE (default) 129 | 130 | NOTE: You do not have to change the permitted_uri_chars option, as GET 131 | requests are not parsed as part of the URI. 132 | 133 */ 134 $config['enable_get_requests'] = FALSE; 117 135 118 136 -
trunk/system/libraries/Input.php
r24 r47 47 47 $CFG =& load_class('Config'); 48 48 $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; 49 $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; 49 $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE 50 OR $CFG->item('enable_get_requests') === TRUE) ? TRUE : FALSE; 50 51 $this->_sanitize_globals(); 51 52 } … … 107 108 { 108 109 foreach($_POST as $key => $val) 109 { 110 { 110 111 $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); 111 } 112 } 112 113 } 113 114 … … 116 117 { 117 118 foreach($_COOKIE as $key => $val) 118 { 119 { 119 120 $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); 120 } 121 } 121 122 } 122 123 … … 188 189 189 190 /** 191 * Fetch an item from a global array 192 * 193 * @access private 194 * @param string 195 * @param string 196 * @param bool 197 * @return string 198 */ 199 function _get_global($global, $index = FALSE, $xss_clean = FALSE) 200 { 201 $global = '_'.strtoupper($global); 202 if ( ! isset($$global)) 203 return FALSE; 204 205 if ($index === FALSE) 206 { 207 return $$global; 208 } 209 210 if ( ! isset($$global[$index])) 211 { 212 return FALSE; 213 } 214 215 if ($xss_clean === TRUE) 216 { 217 if (is_array($$global[$index])) 218 { 219 foreach($$global[$index] as $key => $val) 220 { 221 $$global[$index][$key] = $this->xss_clean($val); 222 } 223 } 224 else 225 { 226 return $this->xss_clean($$global[$index]); 227 } 228 } 229 230 return $$global[$index]; 231 } 232 233 // -------------------------------------------------------------------- 234 235 /** 190 236 * Fetch an item from the GET array 191 237 * … … 195 241 * @return string 196 242 */ 197 function get($index = '', $xss_clean = FALSE) 198 { 199 if ( ! isset($_GET[$index])) 200 { 201 return FALSE; 202 } 203 204 if ($xss_clean === TRUE) 205 { 206 if (is_array($_GET[$index])) 207 { 208 foreach($_GET[$index] as $key => $val) 209 { 210 $_GET[$index][$key] = $this->xss_clean($val); 211 } 212 } 213 else 214 { 215 return $this->xss_clean($_GET[$index]); 216 } 217 } 218 219 return $_GET[$index]; 243 function get($index = FALSE, $xss_clean = FALSE) 244 { 245 return $this->_get_global('get', $index, $xss_clean); 220 246 } 221 247 … … 230 256 * @return string 231 257 */ 232 function post($index = '', $xss_clean = FALSE) 233 { 234 if ( ! isset($_POST[$index])) 235 { 236 return FALSE; 237 } 238 239 if ($xss_clean === TRUE) 240 { 241 if (is_array($_POST[$index])) 242 { 243 foreach($_POST[$index] as $key => $val) 244 { 245 $_POST[$index][$key] = $this->xss_clean($val); 246 } 247 } 248 else 249 { 250 return $this->xss_clean($_POST[$index]); 251 } 252 } 253 254 return $_POST[$index]; 258 function post($index = FALSE, $xss_clean = FALSE) 259 { 260 return $this->_get_global('post', $index, $xss_clean); 255 261 } 256 262 … … 265 271 * @return string 266 272 */ 267 function cookie($index = '', $xss_clean = FALSE) 268 { 269 if ( ! isset($_COOKIE[$index])) 270 { 271 return FALSE; 272 } 273 274 if ($xss_clean === TRUE) 275 { 276 if (is_array($_COOKIE[$index])) 277 { 278 $cookie = array(); 279 foreach($_COOKIE[$index] as $key => $val) 280 { 281 $cookie[$key] = $this->xss_clean($val); 282 } 283 284 return $cookie; 285 } 286 else 287 { 288 return $this->xss_clean($_COOKIE[$index]); 289 } 290 } 291 else 292 { 293 return $_COOKIE[$index]; 294 } 273 function cookie($index = FALSE, $xss_clean = FALSE) 274 { 275 return $this->_get_global('cookie', $index, $xss_clean); 295 276 } 296 277 … … 305 286 * @return string 306 287 */ 307 function server($index = '', $xss_clean = FALSE) 308 { 309 if ( ! isset($_SERVER[$index])) 310 { 311 return FALSE; 312 } 313 314 if ($xss_clean === TRUE) 315 { 316 return $this->xss_clean($_SERVER[$index]); 317 } 318 319 return $_SERVER[$index]; 288 function server($index = FALSE, $xss_clean = FALSE) 289 { 290 return $this->_get_global('server', $index, $xss_clean); 320 291 } 321 292 -
trunk/system/libraries/Loader.php
r24 r47 27 27 * @link http://blueflame.ciforge.com/user_guide/libraries/loader.html 28 28 */ 29 30 if (floor(phpversion()) >= 5) 31 { 32 /** 33 * Autoloader 34 * 35 * Implements auto-loading of libraries in PHP >= 5, using CI_Loader 36 * 37 * @access public 38 * @param string class name 39 */ 40 function __autoload($class) 41 { 42 if (! function_exists('get_instance')) 43 return; 44 45 $CI =& get_instance(); 46 $fp = $CI->load->_ci_find_class($class)); 47 48 if ($fp !== FALSE AND $fp !== TRUE) 49 { 50 require_once($fp); 51 } 52 } 53 } 54 29 55 class CI_Loader { 30 56 … … 73 99 */ 74 100 function library($library = '', $params = NULL) 75 { 101 { 76 102 if ($library == '') 77 103 { … … 119 145 { 120 146 $x = explode('/', $model); 121 $model = end($x); 147 $model = end($x); 122 148 unset($x[count($x)-1]); 123 149 $path = implode('/', $x).'/'; … … 146 172 show_error('Unable to locate the model you have specified: '.$model); 147 173 } 148 174 149 175 if ($db_conn !== FALSE AND ! class_exists('CI_DB')) 150 176 { … … 163 189 164 190 $model = ucfirst($model); 165 191 166 192 $CI->$name = new $model(); 167 193 $CI->$name->_assign_libraries(); 168 194 169 $this->_ci_models[] = $name; 195 $this->_ci_models[] = $name; 170 196 } 171 197 … … 663 689 664 690 // -------------------------------------------------------------------- 665 691 666 692 /** 667 693 * Load class … … 677 703 { 678 704 // Get the class name 679 $class = str_replace(EXT, '', $class);680 705 $class = str_replace(EXT, '', strtolower($class)); 706 681 707 // We'll test for both lowercase and capitalized versions of the file name 682 foreach (array(ucfirst($class), strtolower($class)) as $class) 683 { 684 // Is this a class extension request? 685 if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) 686 { 687 if ( ! file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) 688 { 689 log_message('error', "Unable to load the requested class: ".$class); 690 show_error("Unable to load the requested class: ".$class); 691 } 692 693 include(BASEPATH.'libraries/'.ucfirst($class).EXT); 694 include(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); 695 696 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); 697 } 698 699 // Lets search for the requested library file and load it. 700 $is_duplicate = FALSE; 701 for ($i = 1; $i < 3; $i++) 702 { 703 $path = ($i % 2) ? APPPATH : BASEPATH; 704 $fp = $path.'libraries/'.$class.EXT; 705 706 // Does the file exist? No? Bummer... 707 if ( ! file_exists($fp)) 708 { 709 continue; 710 } 711 712 // Safety: Was the class already loaded by a previous call? 713 if (in_array($fp, $this->_ci_classes)) 714 { 715 $is_duplicate = TRUE; 716 log_message('debug', $class." class already loaded. Second attempt ignored."); 717 return; 718 } 719 708 foreach (array($class, ucfirst($class)) as $class) 709 { 710 $fp = $this->_ci_find_class($class); 711 $ex = $this->_ci_find_class(config_item('subclass_prefix').$class); 712 713 // Extension found, but no class found 714 if ($ex == TRUE AND $fp == FALSE) 715 { 716 log_message('error', "Unable to load the requested class: ".$class); 717 show_error("Unable to load the requested class: ".$class); 718 } 719 720 // Class is already loaded, log a message and stop 721 if ($fp === TRUE) 722 { 723 log_message('debug', $class." class already loaded. Second attempt ignored."); 724 return; 725 } 726 727 // No class found 728 if ($fp == FALSE) 729 { 730 continue; 731 } 732 else 733 { 720 734 include($fp); 721 $this->_ci_classes[] = $fp; 735 } 736 737 // For safety checks 738 $this->_ci_classes[] = $fp; 739 740 // Include extension, if one was found 741 if ($ex == TRUE) 742 { 743 include($ex); 744 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); 745 } 746 else 747 { 722 748 return $this->_ci_init_class($class, '', $params); 723 749 } 724 } // END FOREACH 725 726 // If we got this far we were unable to find the requested class. 727 // We do not issue errors if the load call failed due to a duplicate request 728 if ($is_duplicate == FALSE) 729 { 730 log_message('error', "Unable to load the requested class: ".$class); 731 show_error("Unable to load the requested class: ".$class); 732 } 750 }// END FOREACH 751 752 // If we got this far we were unable to find the requested class 753 log_message('error', "Unable to load the requested class: ".$class); 754 show_error("Unable to load the requested class: ".$class); 755 } 756 757 // -------------------------------------------------------------------- 758 759 /** 760 * Find class 761 * 762 * This function finds the requested class. 763 * 764 * @access private 765 * @param string the item that is being loaded 766 * @param array paths to search in 767 * @return void 768 */ 769 function _ci_find_class($class, $paths = false) 770 { 771 // Default to using the standard paths 772 if ( ! is_array($paths)) 773 { 774 $paths = array(APPPATH, BASEPATH); 775 } 776 777 foreach ($paths as $path) 778 { 779 $fp = $path.'libraries/'.$class.EXT; 780 // Safety: Was the class already loaded by a previous call? 781 if (in_array($fp, $this->_ci_classes)) 782 { 783 return TRUE; 784 } 785 // Does the file exist? 786 if (file_exists($fp)) 787 { 788 return $fp; 789 } 790 } 791 792 // No class was found 793 return FALSE; 733 794 } 734 795 -
trunk/system/libraries/Router.php
r24 r47 404 404 function _filter_uri($str) 405 405 { 406 $str = rawurldecode($str); 407 408 if ($this->config->item('enable_get_requests')) 409 { 410 $end = strpos($str, '?'); 411 $str = ($end !== FALSE) ? substr($str, 0, $end) : $str; 412 } 413 406 414 if ($this->config->item('permitted_uri_chars') != '') 407 415 { … … 410 418 exit('The URI you submitted has disallowed characters.'); 411 419 } 412 } 413 return $str; 420 } 421 422 return $str; 414 423 } 415 424 … … 443 452 if (isset($this->routes[$uri])) 444 453 { 445 $this->_compile_segments(explode('/', $this->routes[$uri])); 454 $this->_compile_segments(explode('/', $this->routes[$uri])); 446 455 return; 447 456 } … … 449 458 // Loop through the route array looking for wild-cards 450 459 foreach (array_slice($this->routes, 1) as $key => $val) 451 { 460 { 452 461 // Convert wild-cards to RegEx 453 462 $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); … … 455 464 // Does the RegEx match? 456 465 if (preg_match('#^'.$key.'$#', $uri)) 457 { 466 { 458 467 // Do we have a back-reference? 459 468 if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) … … 462 471 } 463 472 464 $this->_compile_segments(explode('/', $val)); 473 $this->_compile_segments(explode('/', $val)); 465 474 return; 466 475 }
