Take two:
[www-register-wizard.git] / libraries / Exceptions.php
1 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
2 /**\r
3  * CodeIgniter\r
4  *\r
5  * An open source application development framework for PHP 4.3.2 or newer\r
6  *\r
7  * @package             CodeIgniter\r
8  * @author              ExpressionEngine Dev Team\r
9  * @copyright   Copyright (c) 2008, EllisLab, Inc.\r
10  * @license             http://codeigniter.com/user_guide/license.html\r
11  * @link                http://codeigniter.com\r
12  * @since               Version 1.0\r
13  * @filesource\r
14  */\r
15 \r
16 // ------------------------------------------------------------------------\r
17 \r
18 /**\r
19  * Exceptions Class\r
20  *\r
21  * @package             CodeIgniter\r
22  * @subpackage  Libraries\r
23  * @category    Exceptions\r
24  * @author              ExpressionEngine Dev Team\r
25  * @link                http://codeigniter.com/user_guide/libraries/exceptions.html\r
26  */\r
27 class CI_Exceptions {\r
28         var $action;\r
29         var $severity;\r
30         var $message;\r
31         var $filename;\r
32         var $line;\r
33         var $ob_level;\r
34 \r
35         var $levels = array(\r
36                                                 E_ERROR                         =>      'Error',\r
37                                                 E_WARNING                       =>      'Warning',\r
38                                                 E_PARSE                         =>      'Parsing Error',\r
39                                                 E_NOTICE                        =>      'Notice',\r
40                                                 E_CORE_ERROR            =>      'Core Error',\r
41                                                 E_CORE_WARNING          =>      'Core Warning',\r
42                                                 E_COMPILE_ERROR         =>      'Compile Error',\r
43                                                 E_COMPILE_WARNING       =>      'Compile Warning',\r
44                                                 E_USER_ERROR            =>      'User Error',\r
45                                                 E_USER_WARNING          =>      'User Warning',\r
46                                                 E_USER_NOTICE           =>      'User Notice',\r
47                                                 E_STRICT                        =>      'Runtime Notice'\r
48                                         );\r
49 \r
50 \r
51         /**\r
52          * Constructor\r
53          *\r
54          */     \r
55         function CI_Exceptions()\r
56         {\r
57                 $this->ob_level = ob_get_level();\r
58                 // Note:  Do not log messages from this constructor.\r
59         }\r
60         \r
61         // --------------------------------------------------------------------\r
62 \r
63         /**\r
64          * Exception Logger\r
65          *\r
66          * This function logs PHP generated error messages\r
67          *\r
68          * @access      private\r
69          * @param       string  the error severity\r
70          * @param       string  the error string\r
71          * @param       string  the error filepath\r
72          * @param       string  the error line number\r
73          * @return      string\r
74          */\r
75         function log_exception($severity, $message, $filepath, $line)\r
76         {       \r
77                 $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];\r
78                 \r
79                 log_message('error', 'Severity: '.$severity.'  --> '.$message. ' '.$filepath.' '.$line, TRUE);\r
80         }\r
81 \r
82         // --------------------------------------------------------------------\r
83 \r
84         /**\r
85          * 404 Page Not Found Handler\r
86          *\r
87          * @access      private\r
88          * @param       string\r
89          * @return      string\r
90          */\r
91         function show_404($page = '')\r
92         {       \r
93                 $heading = "404 Page Not Found";\r
94                 $message = "The page you requested was not found.";\r
95 \r
96                 log_message('error', '404 Page Not Found --> '.$page);\r
97                 echo $this->show_error($heading, $message, 'error_404');\r
98                 exit;\r
99         }\r
100         \r
101         // --------------------------------------------------------------------\r
102 \r
103         /**\r
104          * General Error Page\r
105          *\r
106          * This function takes an error message as input\r
107          * (either as a string or an array) and displays\r
108          * it using the specified template.\r
109          *\r
110          * @access      private\r
111          * @param       string  the heading\r
112          * @param       string  the message\r
113          * @param       string  the template name\r
114          * @return      string\r
115          */\r
116         function show_error($heading, $message, $template = 'error_general')\r
117         {\r
118                 $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';\r
119 \r
120                 if (ob_get_level() > $this->ob_level + 1)\r
121                 {\r
122                         ob_end_flush(); \r
123                 }\r
124                 ob_start();\r
125                 include(APPPATH.'errors/'.$template.EXT);\r
126                 $buffer = ob_get_contents();\r
127                 ob_end_clean();\r
128                 return $buffer;\r
129         }\r
130 \r
131         // --------------------------------------------------------------------\r
132 \r
133         /**\r
134          * Native PHP error handler\r
135          *\r
136          * @access      private\r
137          * @param       string  the error severity\r
138          * @param       string  the error string\r
139          * @param       string  the error filepath\r
140          * @param       string  the error line number\r
141          * @return      string\r
142          */\r
143         function show_php_error($severity, $message, $filepath, $line)\r
144         {       \r
145                 $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];\r
146         \r
147                 $filepath = str_replace("\\", "/", $filepath);\r
148                 \r
149                 // For safety reasons we do not show the full file path\r
150                 if (FALSE !== strpos($filepath, '/'))\r
151                 {\r
152                         $x = explode('/', $filepath);\r
153                         $filepath = $x[count($x)-2].'/'.end($x);\r
154                 }\r
155                 \r
156                 if (ob_get_level() > $this->ob_level + 1)\r
157                 {\r
158                         ob_end_flush(); \r
159                 }\r
160                 ob_start();\r
161                 include(APPPATH.'errors/error_php'.EXT);\r
162                 $buffer = ob_get_contents();\r
163                 ob_end_clean();\r
164                 echo $buffer;\r
165         }\r
166 \r
167 \r
168 }\r
169 // END Exceptions Class\r
170 \r
171 /* End of file Exceptions.php */\r
172 /* Location: ./system/libraries/Exceptions.php */