1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Koch Framework |
5
|
|
|
* Jens-André Koch © 2005 - onwards. |
6
|
|
|
* |
7
|
|
|
* This file is part of "Koch Framework". |
8
|
|
|
* |
9
|
|
|
* License: GNU/GPL v2 or any later version, see LICENSE file. |
10
|
|
|
* |
11
|
|
|
* This program is free software; you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU General Public License |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Koch\Exception\Renderer; |
26
|
|
|
|
27
|
|
|
use Koch\Exception\Errorhandler; |
28
|
|
|
use Koch\Exception\Exception; |
29
|
|
|
|
30
|
|
|
class YellowScreenOfDeath |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Renders a Koch Framework Exception. |
34
|
|
|
*/ |
35
|
|
|
public static function renderException($message, $string, $code, $file, $line, $trace) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
ob_start(); |
38
|
|
|
|
39
|
|
|
/* |
40
|
|
|
* @todo add backlink to the exception codes list |
41
|
|
|
*/ |
42
|
|
|
if ($code > 0) { |
43
|
|
|
$code = '(#' . $code . ')'; |
44
|
|
|
} else { |
45
|
|
|
$code = ''; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// Header |
49
|
|
|
$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'; |
50
|
|
|
$html .= ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; |
51
|
|
|
$html .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'; |
52
|
|
|
$html .= '<head>'; |
53
|
|
|
$html .= '<title>Koch Framework Exception ' . $code . ' - ' . $message . '</title>'; |
54
|
|
|
$html .= '<link rel="stylesheet" href="' . WWW_ROOT_THEMES_CORE . 'css/error.css" type="text/css" />'; |
55
|
|
|
$html .= '</head>'; |
56
|
|
|
|
57
|
|
|
// Body |
58
|
|
|
$html .= '<body>'; |
59
|
|
|
|
60
|
|
|
// Fieldset |
61
|
|
|
$html .= '<fieldset id="top" class="error_yellow">'; |
62
|
|
|
|
63
|
|
|
// Errorlogo |
64
|
|
|
$html .= '<div style="float: left; margin: 5px; margin-right: 25px; padding: 20px;">'; |
65
|
|
|
$html .= '<img src="' . WWW_ROOT_THEMES_CORE . 'images/Clansuite-Toolbar-Icon-64-exception.png" '; |
66
|
|
|
$html .= 'style="border: 2px groove #000000;" alt="Clansuite Exception Icon" /></div>'; |
67
|
|
|
|
68
|
|
|
// Fieldset Legend |
69
|
|
|
$html .= '<legend>Koch Framework Exception</legend>'; |
70
|
|
|
|
71
|
|
|
// Exception Table |
72
|
|
|
$html .= '<table width="80%"><tr><td>'; |
73
|
|
|
|
74
|
|
|
/* |
75
|
|
|
* Panel 1 |
76
|
|
|
* |
77
|
|
|
* Exception Message and File |
78
|
|
|
*/ |
79
|
|
|
|
80
|
|
|
$html .= '<div id="panel1" class="panel">'; |
81
|
|
|
$html .= '<h3>Exception ' . $code . '</h3><h4>' . $message . '</h4>'; |
82
|
|
|
$html .= '<strong>' . Errorhandler::getFileLink($file, $line) . '.</strong>'; |
83
|
|
|
$html .= '</div>'; |
84
|
|
|
|
85
|
|
|
/* |
86
|
|
|
* Panel 2 |
87
|
|
|
* |
88
|
|
|
* Debug Backtrace |
89
|
|
|
*/ |
90
|
|
|
if (defined('DEBUG') and DEBUG === 1) { |
|
|
|
|
91
|
|
|
// lets get the backtrace as html table |
92
|
|
|
$html .= Errorhandler::getDebugBacktrace($trace); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/* |
96
|
|
|
* Panel 3 |
97
|
|
|
* |
98
|
|
|
* Server Environment Informations |
99
|
|
|
*/ |
100
|
|
|
if (defined('DEBUG') and DEBUG === 1) { |
|
|
|
|
101
|
|
|
$html .= '<div id="panel3" class="panel">'; |
102
|
|
|
$html .= '<h3>Server Environment</h3>'; |
103
|
|
|
$html .= '<table width="95%">'; |
104
|
|
|
$html .= '<tr><td><strong>Date: </strong></td><td>' . date('r') . '</td></tr>'; |
105
|
|
|
$html .= '<tr><td><strong>Remote: </strong></td><td>' . $_SERVER['REMOTE_ADDR'] . '</td></tr>'; |
106
|
|
|
$html .= '<tr><td><strong>Request: </strong></td><td>index.php?' . $_SERVER['QUERY_STRING'] . '</td></tr>'; |
107
|
|
|
$html .= '<tr><td><strong>PHP: </strong></td><td>' . PHP_VERSION . ' ' . PHP_EXTRA_VERSION . '</td></tr>'; |
108
|
|
|
$html .= '<tr><td><strong>Server: </strong></td><td>' . $_SERVER['SERVER_SOFTWARE'] . '</td></tr>'; |
109
|
|
|
$html .= '<tr><td><strong>Agent: </strong></td><td>' . $_SERVER['HTTP_USER_AGENT'] . '</td></tr>'; |
110
|
|
|
$html .= '<tr><td><strong>Application: </strong></td>'; |
111
|
|
|
$html .= '<td>' . APPLICATION_VERSION . ' ' . APPLICATION_VERSION_STATE; |
112
|
|
|
$html .= ' (' . APPLICATION_VERSION_NAME . ')</td></tr>'; |
113
|
|
|
$html .= '</table></div>'; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/* |
117
|
|
|
* Panel 4 |
118
|
|
|
* |
119
|
|
|
* Additional Information |
120
|
|
|
*/ |
121
|
|
|
if (empty(self::$exception_template) === false) { |
122
|
|
|
$html .= '<div id="panel4" class="panel">'; |
123
|
|
|
$html .= '<h3>Additional Information & Solution Suggestion</h3>'; |
124
|
|
|
$html .= self::$exception_template . '</div>'; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/* |
128
|
|
|
* Panel 5 |
129
|
|
|
* |
130
|
|
|
* Rapid Development |
131
|
|
|
*/ |
132
|
|
|
$placeholders = []; |
133
|
|
|
// assign placeholders for replacements in the html |
134
|
|
|
if (strpos($message, 'action_')) { |
135
|
|
|
$placeholders['actionname'] = substr($message, strpos($message, 'action_')); |
136
|
|
|
} elseif (strpos($message, 'module_')) { |
137
|
|
|
$placeholders['classname'] = substr($message, strpos($message, 'module_')); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
if (empty($_GET['mod']) === false) { |
141
|
|
|
$placeholders['modulename'] = (string) stripslashes($_GET['mod']); |
142
|
|
|
} else { |
143
|
|
|
$placeholders['modulename'] = ''; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
// add development helper template to exceptions |
147
|
|
|
if (defined('DEVELOPMENT') and DEVELOPMENT === 1 and defined('RAPIDDEVTPL') and RAPIDDEVTPL === 1) { |
|
|
|
|
148
|
|
|
$html .= '<div id="panel5" class="panel">'; |
149
|
|
|
$html .= '<h3>Rapid Application Development</h3>'; |
150
|
|
|
$html .= Exception::getExceptionDevelopmentTemplate($placeholders) . '</div>'; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/* |
154
|
|
|
* Panel 6 |
155
|
|
|
* |
156
|
|
|
* Backlink to Bugtracker with Exceptionmessage |
157
|
|
|
* @link http://trac.clansuite.com/newticket |
158
|
|
|
*/ |
159
|
|
|
$html .= Errorhandler::getBugtrackerBacklinks($message, $file, $line, $trace); |
160
|
|
|
|
161
|
|
|
// close all html element table |
162
|
|
|
$html .= '</table>'; |
163
|
|
|
|
164
|
|
|
/* |
165
|
|
|
* Panel 7 |
166
|
|
|
* |
167
|
|
|
* Footer with Support-Backlinks |
168
|
|
|
*/ |
169
|
|
|
$html .= Errorhandler::getSupportBacklinks($this); |
|
|
|
|
170
|
|
|
|
171
|
|
|
// close all html elements: fieldset, body+page |
172
|
|
|
$html .= '</fieldset>'; |
173
|
|
|
$html .= '</body></html>'; |
174
|
|
|
|
175
|
|
|
// save session before exit - but only if this is not a pdo exception |
176
|
|
|
// that would trigger a fatal error, when trying to write to the db during session save |
177
|
|
|
if ((bool) session_id() and false === strpos($message, 'SQLSTATE')) { |
|
|
|
|
178
|
|
|
session_write_close(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
// clear all output buffers |
182
|
|
|
if (ob_get_length()) { |
183
|
|
|
ob_end_clean(); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
// Output the errormessage |
187
|
|
|
return $html; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Renders a Koch Framework Error. |
192
|
|
|
* |
193
|
|
|
* @param int $errno |
194
|
|
|
* @param string $errstr |
195
|
|
|
* @param string $errfile |
196
|
|
|
* @param string $errline |
197
|
|
|
* @param int $errline |
198
|
|
|
* @param string $errcontext |
199
|
|
|
* @param string $errorname |
200
|
|
|
*/ |
201
|
|
|
public static function renderError($errno, $errorname, $errstr, $errfile, $errline, $errcontext) |
|
|
|
|
202
|
|
|
{ |
203
|
|
|
// shorten errorfile string by removing the root path |
204
|
|
|
$errfile_short = str_replace(APPLICATION_PATH, '', $errfile); |
|
|
|
|
205
|
|
|
$short_errorstring = \Koch\Functions\Functions::shortenString($errfile, 70, '...'); |
|
|
|
|
206
|
|
|
|
207
|
|
|
// Header |
208
|
|
|
$html = '<html><head>'; |
209
|
|
|
$html .= '<title>Koch Framework Error</title>'; |
210
|
|
|
$html .= '<link rel="stylesheet" href="' . WWW_ROOT_THEMES_CORE . 'css/error.css" type="text/css" />'; |
211
|
|
|
$html .= '</head>'; |
212
|
|
|
|
213
|
|
|
// Body |
214
|
|
|
$html .= '<body>'; |
215
|
|
|
|
216
|
|
|
// Fieldset with Legend |
217
|
|
|
$html .= '<fieldset id="top" class="error_red">'; |
218
|
|
|
$html .= '<legend>Koch Framework Error</legend>'; |
219
|
|
|
|
220
|
|
|
// Add Errorlogo |
221
|
|
|
$html .= '<div style="float: left; margin: 5px; margin-right: 25px; padding: 20px;">'; |
222
|
|
|
$html .= '<img src="' . WWW_ROOT_THEMES_CORE . 'images/Clansuite-Toolbar-Icon-64-error.png"'; |
223
|
|
|
$html .= ' style="border: 2px groove #000000;"/></div>'; |
224
|
|
|
|
225
|
|
|
// Open Error Table |
226
|
|
|
$html .= '<table width="80%"><tr><td>'; |
227
|
|
|
|
228
|
|
|
// Panel 1 - Errormessage |
229
|
|
|
$html .= '<div id="panel1" class="panel">'; |
230
|
|
|
$html .= '<h3>Error - ' . $errorname . ' (' . $errno . ')</h3> '; |
231
|
|
|
$html .= '<p style="font-weight: bold;">' . $errstr . '</p>'; |
232
|
|
|
$html .= '<p>in file "<span style="font-weight: bold;">' . $errfile_short . '</span>"'; |
|
|
|
|
233
|
|
|
$html .= ' on line #<span style="font-weight: bold;">' . $errline . '.</span></p>'; |
234
|
|
|
$html .= '</div>'; |
235
|
|
|
|
236
|
|
|
// Panel 2 - Error Context |
237
|
|
|
$html .= '<div id="panel2" class="panel">'; |
238
|
|
|
$html .= '<h3>Context</h3>'; |
239
|
|
|
$html .= '<p><span class="small">You are viewing the source code of the file "'; |
240
|
|
|
$html .= $errfile . '" around line ' . $errline . '.</span></p>'; |
241
|
|
|
$html .= Errorhandler::getErrorContext($errfile, $errline, 8) . '</div>'; |
242
|
|
|
|
243
|
|
|
// Panel 3 - Debug Backtracing |
244
|
|
|
$html .= Errorhandler::getDebugBacktrace($short_errorstring); |
|
|
|
|
245
|
|
|
|
246
|
|
|
// Panel 4 - Environmental Informations at Errortime |
247
|
|
|
$html .= '<div id="panel4" class="panel">'; |
248
|
|
|
$html .= '<h3>Server Environment</h3>'; |
249
|
|
|
$html .= '<p><table width="95%">'; |
250
|
|
|
$html .= '<tr><td colspan="2"></td></tr>'; |
251
|
|
|
$html .= '<tr><td><strong>Date: </strong></td><td>' . date('r') . '</td></tr>'; |
252
|
|
|
$html .= '<tr><td><strong>Remote: </strong></td><td>' . $_SERVER['REMOTE_ADDR'] . '</td></tr>'; |
253
|
|
|
$html .= '<tr><td><strong>Request: </strong></td><td>' . htmlentities($_SERVER['QUERY_STRING'], ENT_QUOTES); |
254
|
|
|
$html .= '</td></tr>'; |
255
|
|
|
$html .= '<tr><td><strong>PHP: </strong></td><td>' . PHP_VERSION . ' ' . PHP_EXTRA_VERSION . '</td></tr>'; |
256
|
|
|
$html .= '<tr><td><strong>Server: </strong></td><td>' . $_SERVER['SERVER_SOFTWARE'] . '</td></tr>'; |
257
|
|
|
$html .= '<tr><td><strong>Agent: </strong></td><td>' . $_SERVER['HTTP_USER_AGENT'] . '</td></tr>'; |
258
|
|
|
$html .= '<tr><td><strong>Clansuite: </strong></td><td>'; |
259
|
|
|
$html .= APPLICATION_VERSION . ' ' . APPLICATION_VERSION_STATE . ' (' . APPLICATION_VERSION_NAME . ')'; |
260
|
|
|
$html .= '</td></tr>'; |
261
|
|
|
$html .= '</table></p></div>'; |
262
|
|
|
|
263
|
|
|
// Panel 5 - Backlink to Bugtracker with Errormessage -> http://trac.clansuite.com/newticket |
264
|
|
|
$html .= Errorhandler::getBugtrackerBacklinks($errorname, $errfile, $errline, $errcontext); |
265
|
|
|
|
266
|
|
|
// Close Error Table |
267
|
|
|
$html .= '</table>'; |
268
|
|
|
|
269
|
|
|
// Add Footer with Support-Backlinks |
270
|
|
|
$html .= Errorhandler::getSupportBacklinks(); |
271
|
|
|
|
272
|
|
|
// Close all html elements |
273
|
|
|
$html .= '</fieldset><br /><br />'; |
274
|
|
|
$html .= '</body></html>'; |
275
|
|
|
|
276
|
|
|
return $html; |
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.