| 10582 |
lgm |
1 |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
2 |
/**
|
|
|
3 |
* CodeIgniter
|
|
|
4 |
*
|
|
|
5 |
* An open source application development framework for PHP 5.1.6 or newer
|
|
|
6 |
*
|
|
|
7 |
* @package CodeIgniter
|
|
|
8 |
* @author ExpressionEngine Dev Team
|
|
|
9 |
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
|
|
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 |
|
|
|
34 |
/**
|
|
|
35 |
* Nesting level of the output buffering mechanism
|
|
|
36 |
*
|
|
|
37 |
* @var int
|
|
|
38 |
* @access public
|
|
|
39 |
*/
|
|
|
40 |
var $ob_level;
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* List if available error levels
|
|
|
44 |
*
|
|
|
45 |
* @var array
|
|
|
46 |
* @access public
|
|
|
47 |
*/
|
|
|
48 |
var $levels = array(
|
|
|
49 |
E_ERROR => 'Error',
|
|
|
50 |
E_WARNING => 'Warning',
|
|
|
51 |
E_PARSE => 'Parsing Error',
|
|
|
52 |
E_NOTICE => 'Notice',
|
|
|
53 |
E_CORE_ERROR => 'Core Error',
|
|
|
54 |
E_CORE_WARNING => 'Core Warning',
|
|
|
55 |
E_COMPILE_ERROR => 'Compile Error',
|
|
|
56 |
E_COMPILE_WARNING => 'Compile Warning',
|
|
|
57 |
E_USER_ERROR => 'User Error',
|
|
|
58 |
E_USER_WARNING => 'User Warning',
|
|
|
59 |
E_USER_NOTICE => 'User Notice',
|
|
|
60 |
E_STRICT => 'Runtime Notice'
|
|
|
61 |
);
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* Constructor
|
|
|
66 |
*/
|
|
|
67 |
public function __construct()
|
|
|
68 |
{
|
|
|
69 |
$this->ob_level = ob_get_level();
|
|
|
70 |
// Note: Do not log messages from this constructor.
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
// --------------------------------------------------------------------
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* Exception Logger
|
|
|
77 |
*
|
|
|
78 |
* This function logs PHP generated error messages
|
|
|
79 |
*
|
|
|
80 |
* @access private
|
|
|
81 |
* @param string the error severity
|
|
|
82 |
* @param string the error string
|
|
|
83 |
* @param string the error filepath
|
|
|
84 |
* @param string the error line number
|
|
|
85 |
* @return string
|
|
|
86 |
*/
|
|
|
87 |
function log_exception($severity, $message, $filepath, $line)
|
|
|
88 |
{
|
|
|
89 |
$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
|
|
|
90 |
|
|
|
91 |
log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
// --------------------------------------------------------------------
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* 404 Page Not Found Handler
|
|
|
98 |
*
|
|
|
99 |
* @access private
|
|
|
100 |
* @param string the page
|
|
|
101 |
* @param bool log error yes/no
|
|
|
102 |
* @return string
|
|
|
103 |
*/
|
|
|
104 |
function show_404($page = '', $log_error = TRUE)
|
|
|
105 |
{
|
|
|
106 |
$heading = "404 Page Not Found";
|
|
|
107 |
$message = "The page you requested was not found.";
|
|
|
108 |
|
|
|
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 |
|
|
|
115 |
echo $this->show_error($heading, $message, 'error_404', 404);
|
|
|
116 |
exit;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
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 |
* @param int the status code
|
|
|
133 |
* @return string
|
|
|
134 |
*/
|
|
|
135 |
function show_error($heading, $message, $template = 'error_general', $status_code = 500)
|
|
|
136 |
{
|
|
|
137 |
set_status_header($status_code);
|
|
|
138 |
|
|
|
139 |
$message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';
|
|
|
140 |
|
|
|
141 |
if (ob_get_level() > $this->ob_level + 1)
|
|
|
142 |
{
|
|
|
143 |
ob_end_flush();
|
|
|
144 |
}
|
|
|
145 |
ob_start();
|
|
|
146 |
include(APPPATH.'errors/'.$template.'.php');
|
|
|
147 |
$buffer = ob_get_contents();
|
|
|
148 |
ob_end_clean();
|
|
|
149 |
return $buffer;
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
// --------------------------------------------------------------------
|
|
|
153 |
|
|
|
154 |
/**
|
|
|
155 |
* Native PHP error handler
|
|
|
156 |
*
|
|
|
157 |
* @access private
|
|
|
158 |
* @param string the error severity
|
|
|
159 |
* @param string the error string
|
|
|
160 |
* @param string the error filepath
|
|
|
161 |
* @param string the error line number
|
|
|
162 |
* @return string
|
|
|
163 |
*/
|
|
|
164 |
function show_php_error($severity, $message, $filepath, $line)
|
|
|
165 |
{
|
|
|
166 |
$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
|
|
|
167 |
|
|
|
168 |
$filepath = str_replace("\\", "/", $filepath);
|
|
|
169 |
|
|
|
170 |
// For safety reasons we do not show the full file path
|
|
|
171 |
if (FALSE !== strpos($filepath, '/'))
|
|
|
172 |
{
|
|
|
173 |
$x = explode('/', $filepath);
|
|
|
174 |
$filepath = $x[count($x)-2].'/'.end($x);
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
if (ob_get_level() > $this->ob_level + 1)
|
|
|
178 |
{
|
|
|
179 |
ob_end_flush();
|
|
|
180 |
}
|
|
|
181 |
ob_start();
|
|
|
182 |
include(APPPATH.'errors/error_php.php');
|
|
|
183 |
$buffer = ob_get_contents();
|
|
|
184 |
ob_end_clean();
|
|
|
185 |
echo $buffer;
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
}
|
|
|
190 |
// END Exceptions Class
|
|
|
191 |
|
|
|
192 |
/* End of file Exceptions.php */
|
|
|
193 |
/* Location: ./system/core/Exceptions.php */
|