Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author ExpressionEngine Dev Team |
Greg Aker | 0711dc8 | 2011-01-05 10:49:40 -0600 | [diff] [blame] | 9 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 10 | * @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 | /** |
| 19 | * Exceptions Class |
| 20 | * |
| 21 | * @package CodeIgniter |
| 22 | * @subpackage Libraries |
| 23 | * @category Exceptions |
| 24 | * @author ExpressionEngine Dev Team |
| 25 | * @link http://codeigniter.com/user_guide/libraries/exceptions.html |
| 26 | */ |
| 27 | class CI_Exceptions { |
| 28 | var $action; |
| 29 | var $severity; |
| 30 | var $message; |
| 31 | var $filename; |
| 32 | var $line; |
David Behler | 209b2cf | 2011-08-14 23:00:43 +0200 | [diff] [blame^] | 33 | |
| 34 | /** |
| 35 | * Nesting level of the output buffering mechanism |
| 36 | * Used to |
| 37 | * |
| 38 | * @var int |
| 39 | * @access public |
| 40 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 41 | var $ob_level; |
| 42 | |
David Behler | 209b2cf | 2011-08-14 23:00:43 +0200 | [diff] [blame^] | 43 | /** |
| 44 | * List if available error levels |
| 45 | * |
| 46 | * @var array |
| 47 | * @access public |
| 48 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 49 | var $levels = array( |
| 50 | E_ERROR => 'Error', |
| 51 | E_WARNING => 'Warning', |
| 52 | E_PARSE => 'Parsing Error', |
| 53 | E_NOTICE => 'Notice', |
| 54 | E_CORE_ERROR => 'Core Error', |
| 55 | E_CORE_WARNING => 'Core Warning', |
| 56 | E_COMPILE_ERROR => 'Compile Error', |
| 57 | E_COMPILE_WARNING => 'Compile Warning', |
| 58 | E_USER_ERROR => 'User Error', |
| 59 | E_USER_WARNING => 'User Warning', |
| 60 | E_USER_NOTICE => 'User Notice', |
| 61 | E_STRICT => 'Runtime Notice' |
| 62 | ); |
| 63 | |
| 64 | |
| 65 | /** |
| 66 | * Constructor |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 67 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 68 | public function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 69 | { |
| 70 | $this->ob_level = ob_get_level(); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 71 | // Note: Do not log messages from this constructor. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 72 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 73 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 74 | // -------------------------------------------------------------------- |
| 75 | |
| 76 | /** |
| 77 | * Exception Logger |
| 78 | * |
| 79 | * This function logs PHP generated error messages |
| 80 | * |
| 81 | * @access private |
| 82 | * @param string the error severity |
| 83 | * @param string the error string |
| 84 | * @param string the error filepath |
| 85 | * @param string the error line number |
| 86 | * @return string |
| 87 | */ |
| 88 | function log_exception($severity, $message, $filepath, $line) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 89 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 90 | $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 91 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 92 | log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | // -------------------------------------------------------------------- |
| 96 | |
| 97 | /** |
| 98 | * 404 Page Not Found Handler |
| 99 | * |
| 100 | * @access private |
| 101 | * @param string |
| 102 | * @return string |
| 103 | */ |
Derek Allard | 2ddc949 | 2010-08-05 10:08:33 -0400 | [diff] [blame] | 104 | function show_404($page = '', $log_error = TRUE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 105 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 106 | $heading = "404 Page Not Found"; |
| 107 | $message = "The page you requested was not found."; |
| 108 | |
Derek Allard | 2ddc949 | 2010-08-05 10:08:33 -0400 | [diff] [blame] | 109 | // By default we log this, but allow a dev to skip it |
| 110 | if ($log_error) |
| 111 | { |
| 112 | log_message('error', '404 Page Not Found --> '.$page); |
| 113 | } |
| 114 | |
Derek Jones | f6b442b | 2009-07-11 18:23:30 +0000 | [diff] [blame] | 115 | echo $this->show_error($heading, $message, 'error_404', 404); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 116 | exit; |
| 117 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 118 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 119 | // -------------------------------------------------------------------- |
| 120 | |
| 121 | /** |
| 122 | * General Error Page |
| 123 | * |
| 124 | * This function takes an error message as input |
| 125 | * (either as a string or an array) and displays |
| 126 | * it using the specified template. |
| 127 | * |
| 128 | * @access private |
| 129 | * @param string the heading |
| 130 | * @param string the message |
| 131 | * @param string the template name |
| 132 | * @return string |
| 133 | */ |
Derek Jones | 817163a | 2009-07-11 17:05:58 +0000 | [diff] [blame] | 134 | function show_error($heading, $message, $template = 'error_general', $status_code = 500) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 135 | { |
Derek Jones | 817163a | 2009-07-11 17:05:58 +0000 | [diff] [blame] | 136 | set_status_header($status_code); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 137 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 138 | $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>'; |
| 139 | |
| 140 | if (ob_get_level() > $this->ob_level + 1) |
| 141 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 142 | ob_end_flush(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 143 | } |
| 144 | ob_start(); |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 145 | include(APPPATH.'errors/'.$template.'.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 146 | $buffer = ob_get_contents(); |
| 147 | ob_end_clean(); |
| 148 | return $buffer; |
| 149 | } |
| 150 | |
| 151 | // -------------------------------------------------------------------- |
| 152 | |
| 153 | /** |
| 154 | * Native PHP error handler |
| 155 | * |
| 156 | * @access private |
| 157 | * @param string the error severity |
| 158 | * @param string the error string |
| 159 | * @param string the error filepath |
| 160 | * @param string the error line number |
| 161 | * @return string |
| 162 | */ |
| 163 | function show_php_error($severity, $message, $filepath, $line) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 164 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 165 | $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 166 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 167 | $filepath = str_replace("\\", "/", $filepath); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 168 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 169 | // For safety reasons we do not show the full file path |
| 170 | if (FALSE !== strpos($filepath, '/')) |
| 171 | { |
| 172 | $x = explode('/', $filepath); |
| 173 | $filepath = $x[count($x)-2].'/'.end($x); |
| 174 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 175 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 176 | if (ob_get_level() > $this->ob_level + 1) |
| 177 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 178 | ob_end_flush(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 179 | } |
| 180 | ob_start(); |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 181 | include(APPPATH.'errors/error_php.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | $buffer = ob_get_contents(); |
| 183 | ob_end_clean(); |
| 184 | echo $buffer; |
| 185 | } |
| 186 | |
| 187 | |
| 188 | } |
| 189 | // END Exceptions Class |
| 190 | |
| 191 | /* End of file Exceptions.php */ |
Derek Jones | c68dfbf | 2010-03-02 12:59:23 -0600 | [diff] [blame] | 192 | /* Location: ./system/core/Exceptions.php */ |