blob: d1e8e77e92a9d2b86552111ffd69daf6272ac57b [file] [log] [blame]
Derek Jones4b9c6292011-07-01 17:40:48 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Greg Aker0711dc82011-01-05 10:49:40 -06009 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060019 * Common Functions
20 *
21 * Loads the base classes and executes the request.
22 *
23 * @package CodeIgniter
24 * @subpackage codeigniter
25 * @category Common Functions
26 * @author ExpressionEngine Dev Team
27 * @link http://codeigniter.com/user_guide/
28 */
29
30// ------------------------------------------------------------------------
31
32/**
Derek Jones086ee5a2009-07-28 14:42:12 +000033* Determines if the current version of PHP is greater then the supplied value
34*
35* Since there are a few places where we conditionally test for PHP > 5
36* we'll set a static variable.
37*
38* @access public
Derek Jones77b513b2009-08-06 14:39:25 +000039* @param string
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060040* @return bool TRUE if the current version is $version or higher
Derek Jones086ee5a2009-07-28 14:42:12 +000041*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060042 function is_php($version = '5.0.0')
Derek Jones086ee5a2009-07-28 14:42:12 +000043 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060044 static $_is_php;
45 $version = (string)$version;
Barry Mienydd671972010-10-04 16:33:58 +020046
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060047 if ( ! isset($_is_php[$version]))
48 {
49 $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE;
50 }
Derek Jones086ee5a2009-07-28 14:42:12 +000051
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060052 return $_is_php[$version];
53 }
Derek Jones5bcfd2e2009-07-28 14:42:42 +000054
Derek Jones086ee5a2009-07-28 14:42:12 +000055// ------------------------------------------------------------------------
56
57/**
Derek Allard2067d1a2008-11-13 22:59:24 +000058 * Tests for file writability
59 *
Barry Mienydd671972010-10-04 16:33:58 +020060 * is_writable() returns TRUE on Windows servers when you really can't write to
Derek Jones4b9c6292011-07-01 17:40:48 -050061 * the file, based on the read-only attribute. is_writable() is also unreliable
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060062 * on Unix servers if safe_mode is on.
Derek Allard2067d1a2008-11-13 22:59:24 +000063 *
64 * @access private
65 * @return void
Barry Mienydd671972010-10-04 16:33:58 +020066 */
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060067 function is_really_writable($file)
Derek Allard2067d1a2008-11-13 22:59:24 +000068 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060069 // If we're on a Unix server with safe_mode off we call is_writable
70 if (DIRECTORY_SEPARATOR == '/' AND @ini_get("safe_mode") == FALSE)
71 {
72 return is_writable($file);
73 }
Derek Allard2067d1a2008-11-13 22:59:24 +000074
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060075 // For windows servers and safe_mode "on" installations we'll actually
Derek Jones4b9c6292011-07-01 17:40:48 -050076 // write a file then read it. Bah...
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060077 if (is_dir($file))
78 {
79 $file = rtrim($file, '/').'/'.md5(mt_rand(1,100).mt_rand(1,100));
Derek Allard2067d1a2008-11-13 22:59:24 +000080
Derek Jonesdc8e9ea2010-03-02 13:17:19 -060081 if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
82 {
83 return FALSE;
84 }
85
86 fclose($fp);
87 @chmod($file, DIR_WRITE_MODE);
88 @unlink($file);
89 return TRUE;
90 }
Eric Barnes15083012011-03-21 22:13:12 -040091 elseif ( ! is_file($file) OR ($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +000092 {
93 return FALSE;
94 }
95
96 fclose($fp);
Derek Allard2067d1a2008-11-13 22:59:24 +000097 return TRUE;
98 }
Derek Allard2067d1a2008-11-13 22:59:24 +000099
100// ------------------------------------------------------------------------
101
102/**
103* Class registry
104*
Derek Jones4b9c6292011-07-01 17:40:48 -0500105* This function acts as a singleton. If the requested class does not
106* exist it is instantiated and set to a static variable. If it has
Derek Allard2067d1a2008-11-13 22:59:24 +0000107* previously been instantiated the variable is returned.
108*
109* @access public
110* @param string the class name being requested
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600111* @param string the directory where the class should be found
112* @param string the class name prefix
Derek Allard2067d1a2008-11-13 22:59:24 +0000113* @return object
114*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600115 function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600117 static $_classes = array();
Barry Mienydd671972010-10-04 16:33:58 +0200118
Derek Jones4b9c6292011-07-01 17:40:48 -0500119 // Does the class exist? If so, we're done...
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600120 if (isset($_classes[$class]))
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600122 return $_classes[$class];
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 }
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600124
125 $name = FALSE;
126
127 // Look for the class first in the native system/libraries folder
128 // thenin the local application/libraries folder
129 foreach (array(BASEPATH, APPPATH) as $path)
Barry Mienydd671972010-10-04 16:33:58 +0200130 {
Greg Aker3a746652011-04-19 10:59:47 -0500131 if (file_exists($path.$directory.'/'.$class.'.php'))
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600132 {
133 $name = $prefix.$class;
Barry Mienydd671972010-10-04 16:33:58 +0200134
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600135 if (class_exists($name) === FALSE)
136 {
Greg Aker3a746652011-04-19 10:59:47 -0500137 require($path.$directory.'/'.$class.'.php');
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600138 }
Barry Mienydd671972010-10-04 16:33:58 +0200139
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600140 break;
141 }
142 }
143
Derek Jones4b9c6292011-07-01 17:40:48 -0500144 // Is the request a class extension? If so we load it too
Greg Aker3a746652011-04-19 10:59:47 -0500145 if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
Barry Mienydd671972010-10-04 16:33:58 +0200146 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600147 $name = config_item('subclass_prefix').$class;
Barry Mienydd671972010-10-04 16:33:58 +0200148
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600149 if (class_exists($name) === FALSE)
150 {
Greg Aker3a746652011-04-19 10:59:47 -0500151 require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php');
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600152 }
153 }
154
155 // Did we find the class?
156 if ($name === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000157 {
Barry Mienydd671972010-10-04 16:33:58 +0200158 // Note: We use exit() rather then show_error() in order to avoid a
159 // self-referencing loop with the Excptions class
Greg Aker3a746652011-04-19 10:59:47 -0500160 exit('Unable to locate the specified class: '.$class.'.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 }
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600162
163 // Keep track of what we just loaded
164 is_loaded($class);
165
Pascal Kriete58560022010-11-10 16:01:20 -0500166 $_classes[$class] = new $name();
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600167 return $_classes[$class];
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 }
169
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600170// --------------------------------------------------------------------
171
172/**
Derek Jones4b9c6292011-07-01 17:40:48 -0500173* Keeps track of which libraries have been loaded. This function is
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600174* called by the load_class() function above
175*
176* @access public
177* @return array
178*/
179 function is_loaded($class = '')
180 {
181 static $_is_loaded = array();
182
183 if ($class != '')
184 {
185 $_is_loaded[strtolower($class)] = $class;
186 }
187
188 return $_is_loaded;
189 }
190
191// ------------------------------------------------------------------------
Derek Jonesf0a9b332009-07-29 14:19:18 +0000192
193/**
Derek Allard2067d1a2008-11-13 22:59:24 +0000194* Loads the main config.php file
195*
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600196* This function lets us grab the config file even if the Config class
197* hasn't been instantiated yet
198*
Derek Allard2067d1a2008-11-13 22:59:24 +0000199* @access private
200* @return array
201*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600202 function &get_config($replace = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000203 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600204 static $_config;
Barry Mienydd671972010-10-04 16:33:58 +0200205
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600206 if (isset($_config))
207 {
208 return $_config[0];
Barry Mienydd671972010-10-04 16:33:58 +0200209 }
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600210
Phil Sturgeon05fa6112011-04-06 22:57:43 +0100211 // Is the config file in the environment folder?
Greg Aker3a746652011-04-19 10:59:47 -0500212 if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
Phil Sturgeon05fa6112011-04-06 22:57:43 +0100213 {
Greg Aker3a746652011-04-19 10:59:47 -0500214 $file_path = APPPATH.'config/config.php';
Phil Sturgeon05fa6112011-04-06 22:57:43 +0100215 }
joelcox2035fd82011-01-16 16:50:36 +0100216
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600217 // Fetch the config file
joelcox2035fd82011-01-16 16:50:36 +0100218 if ( ! file_exists($file_path))
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 {
Phil Sturgeon05fa6112011-04-06 22:57:43 +0100220 exit('The configuration file does not exist.');
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600221 }
Phil Sturgeon05fa6112011-04-06 22:57:43 +0100222
joelcox2035fd82011-01-16 16:50:36 +0100223 require($file_path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000224
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600225 // Does the $config array exist in the file?
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 if ( ! isset($config) OR ! is_array($config))
227 {
228 exit('Your config file does not appear to be formatted correctly.');
229 }
230
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600231 // Are any values being dynamically replaced?
232 if (count($replace) > 0)
233 {
234 foreach ($replace as $key => $val)
235 {
236 if (isset($config[$key]))
237 {
238 $config[$key] = $val;
239 }
240 }
241 }
Barry Mienydd671972010-10-04 16:33:58 +0200242
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600243 return $_config[0] =& $config;
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 }
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600245
246// ------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000247
248/**
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600249* Returns the specified config item
Derek Allard2067d1a2008-11-13 22:59:24 +0000250*
251* @access public
252* @return mixed
253*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600254 function config_item($item)
Derek Allard2067d1a2008-11-13 22:59:24 +0000255 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600256 static $_config_item = array();
Barry Mienydd671972010-10-04 16:33:58 +0200257
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600258 if ( ! isset($_config_item[$item]))
Derek Allard2067d1a2008-11-13 22:59:24 +0000259 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600260 $config =& get_config();
Barry Mienydd671972010-10-04 16:33:58 +0200261
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600262 if ( ! isset($config[$item]))
263 {
264 return FALSE;
265 }
266 $_config_item[$item] = $config[$item];
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 }
Barry Mienydd671972010-10-04 16:33:58 +0200268
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600269 return $_config_item[$item];
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 }
271
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600272// ------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000273
274/**
275* Error Handler
276*
277* This function lets us invoke the exception class and
278* display errors using the standard error template located
279* in application/errors/errors.php
280* This function will send the error page directly to the
281* browser and exit.
282*
283* @access public
284* @return void
285*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600286 function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
287 {
288 $_error =& load_class('Exceptions', 'core');
289 echo $_error->show_error($heading, $message, 'error_general', $status_code);
290 exit;
291 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000292
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600293// ------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000294
295/**
296* 404 Page Handler
297*
298* This function is similar to the show_error() function above
299* However, instead of the standard error template it displays
300* 404 errors.
301*
302* @access public
303* @return void
304*/
Derek Allard2ddc9492010-08-05 10:08:33 -0400305 function show_404($page = '', $log_error = TRUE)
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600306 {
307 $_error =& load_class('Exceptions', 'core');
Derek Allard2ddc9492010-08-05 10:08:33 -0400308 $_error->show_404($page, $log_error);
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600309 exit;
310 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000311
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600312// ------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000313
314/**
315* Error Logging Interface
316*
317* We use this as a simple mechanism to access the logging
318* class and send messages to be logged.
319*
320* @access public
321* @return void
322*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600323 function log_message($level = 'error', $message, $php_error = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600325 static $_log;
326
327 if (config_item('log_threshold') == 0)
328 {
329 return;
330 }
Barry Mienydd671972010-10-04 16:33:58 +0200331
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600332 $_log =& load_class('Log');
333 $_log->write_log($level, $message, $php_error);
Derek Allard2067d1a2008-11-13 22:59:24 +0000334 }
335
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600336// ------------------------------------------------------------------------
Derek Jones817163a2009-07-11 17:05:58 +0000337
338/**
339 * Set HTTP Status Header
340 *
341 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200342 * @param int the status code
343 * @param string
Derek Jones817163a2009-07-11 17:05:58 +0000344 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200345 */
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600346 function set_status_header($code = 200, $text = '')
Derek Jones817163a2009-07-11 17:05:58 +0000347 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600348 $stati = array(
349 200 => 'OK',
350 201 => 'Created',
351 202 => 'Accepted',
352 203 => 'Non-Authoritative Information',
353 204 => 'No Content',
354 205 => 'Reset Content',
355 206 => 'Partial Content',
Derek Jones817163a2009-07-11 17:05:58 +0000356
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600357 300 => 'Multiple Choices',
358 301 => 'Moved Permanently',
359 302 => 'Found',
360 304 => 'Not Modified',
361 305 => 'Use Proxy',
362 307 => 'Temporary Redirect',
363
364 400 => 'Bad Request',
365 401 => 'Unauthorized',
366 403 => 'Forbidden',
367 404 => 'Not Found',
368 405 => 'Method Not Allowed',
369 406 => 'Not Acceptable',
370 407 => 'Proxy Authentication Required',
371 408 => 'Request Timeout',
372 409 => 'Conflict',
373 410 => 'Gone',
374 411 => 'Length Required',
375 412 => 'Precondition Failed',
376 413 => 'Request Entity Too Large',
377 414 => 'Request-URI Too Long',
378 415 => 'Unsupported Media Type',
379 416 => 'Requested Range Not Satisfiable',
380 417 => 'Expectation Failed',
381
382 500 => 'Internal Server Error',
383 501 => 'Not Implemented',
384 502 => 'Bad Gateway',
385 503 => 'Service Unavailable',
386 504 => 'Gateway Timeout',
387 505 => 'HTTP Version Not Supported'
388 );
389
390 if ($code == '' OR ! is_numeric($code))
391 {
392 show_error('Status codes must be numeric', 500);
393 }
394
395 if (isset($stati[$code]) AND $text == '')
Barry Mienydd671972010-10-04 16:33:58 +0200396 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600397 $text = $stati[$code];
398 }
Barry Mienydd671972010-10-04 16:33:58 +0200399
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600400 if ($text == '')
401 {
Derek Jones4b9c6292011-07-01 17:40:48 -0500402 show_error('No status text available. Please check your status code number or supply your own message text.', 500);
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600403 }
Barry Mienydd671972010-10-04 16:33:58 +0200404
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600405 $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;
406
407 if (substr(php_sapi_name(), 0, 3) == 'cgi')
408 {
409 header("Status: {$code} {$text}", TRUE);
410 }
411 elseif ($server_protocol == 'HTTP/1.1' OR $server_protocol == 'HTTP/1.0')
412 {
413 header($server_protocol." {$code} {$text}", TRUE, $code);
414 }
415 else
416 {
417 header("HTTP/1.1 {$code} {$text}", TRUE, $code);
418 }
Derek Jones817163a2009-07-11 17:05:58 +0000419 }
Barry Mienydd671972010-10-04 16:33:58 +0200420
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600421// --------------------------------------------------------------------
Derek Jones817163a2009-07-11 17:05:58 +0000422
Derek Allard2067d1a2008-11-13 22:59:24 +0000423/**
424* Exception Handler
425*
426* This is the custom exception handler that is declaired at the top
Derek Jones4b9c6292011-07-01 17:40:48 -0500427* of Codeigniter.php. The main reason we use this is to permit
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600428* PHP errors to be logged in our own log files since the user may
Derek Allard2067d1a2008-11-13 22:59:24 +0000429* not have access to server logs. Since this function
430* effectively intercepts PHP errors, however, we also need
431* to display errors based on the current error_reporting level.
432* We do that with the use of a PHP error template.
433*
434* @access private
435* @return void
436*/
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600437 function _exception_handler($severity, $message, $filepath, $line)
Barry Mienydd671972010-10-04 16:33:58 +0200438 {
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600439 // We don't bother with "strict" notices since they tend to fill up
440 // the log file with excess information that isn't normally very helpful.
Barry Mienydd671972010-10-04 16:33:58 +0200441 // For example, if you are running PHP 5 and you use version 4 style
442 // class functions (without prefixes like "public", "private", etc.)
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600443 // you'll get notices telling you that these have been deprecated.
444 if ($severity == E_STRICT)
445 {
446 return;
447 }
Barry Mienydd671972010-10-04 16:33:58 +0200448
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600449 $_error =& load_class('Exceptions', 'core');
Barry Mienydd671972010-10-04 16:33:58 +0200450
451 // Should we display the error? We'll get the current error_reporting
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600452 // level and add its bits with the severity bits to find out.
453 if (($severity & error_reporting()) == $severity)
454 {
455 $_error->show_php_error($severity, $message, $filepath, $line);
456 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000457
Derek Jones4b9c6292011-07-01 17:40:48 -0500458 // Should we log the error? No? We're done...
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600459 if (config_item('log_threshold') == 0)
460 {
461 return;
462 }
Barry Mienydd671972010-10-04 16:33:58 +0200463
Derek Jonesdc8e9ea2010-03-02 13:17:19 -0600464 $_error->log_exception($severity, $message, $filepath, $line);
465 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000466
Greg Aker757dda62010-04-14 19:06:19 -0500467 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200468
Greg Aker757dda62010-04-14 19:06:19 -0500469 /**
470 * Remove Invisible Characters
471 *
472 * This prevents sandwiching null characters
473 * between ascii characters, like Java\0script.
474 *
475 * @access public
476 * @param string
477 * @return string
478 */
Pascal Kriete0ff50262011-04-05 14:52:03 -0400479 function remove_invisible_characters($str, $url_encoded = TRUE)
Greg Aker757dda62010-04-14 19:06:19 -0500480 {
Pascal Kriete0ff50262011-04-05 14:52:03 -0400481 $non_displayables = array();
Derek Jones4b9c6292011-07-01 17:40:48 -0500482
Pascal Kriete0ff50262011-04-05 14:52:03 -0400483 // every control character except newline (dec 10)
484 // carriage return (dec 13), and horizontal tab (dec 09)
Derek Jones4b9c6292011-07-01 17:40:48 -0500485
Pascal Kriete0ff50262011-04-05 14:52:03 -0400486 if ($url_encoded)
Greg Aker757dda62010-04-14 19:06:19 -0500487 {
Pascal Kriete0ff50262011-04-05 14:52:03 -0400488 $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
489 $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
Greg Aker757dda62010-04-14 19:06:19 -0500490 }
Derek Jones4b9c6292011-07-01 17:40:48 -0500491
Pascal Kriete0ff50262011-04-05 14:52:03 -0400492 $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
Greg Aker757dda62010-04-14 19:06:19 -0500493
494 do
495 {
Pascal Kriete0ff50262011-04-05 14:52:03 -0400496 $str = preg_replace($non_displayables, '', $str, -1, $count);
Greg Aker757dda62010-04-14 19:06:19 -0500497 }
Pascal Kriete0ff50262011-04-05 14:52:03 -0400498 while ($count);
Greg Aker757dda62010-04-14 19:06:19 -0500499
500 return $str;
501 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000502
503
504/* End of file Common.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -0600505/* Location: ./system/core/Common.php */