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