@@ -19,159 +19,159 @@ discard block |
||
19 | 19 | class ExceptionStackTraceDisplay |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var string |
|
24 | - * @since $VID:$ |
|
25 | - */ |
|
26 | - private $class_name = ''; |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + * @since $VID:$ |
|
25 | + */ |
|
26 | + private $class_name = ''; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var string |
|
30 | - * @since $VID:$ |
|
31 | - */ |
|
32 | - private $error_code = ''; |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + * @since $VID:$ |
|
31 | + */ |
|
32 | + private $error_code = ''; |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * @param Exception $exception |
|
37 | - * @throws Exception |
|
38 | - */ |
|
39 | - public function __construct(Exception $exception) |
|
40 | - { |
|
41 | - if (WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
42 | - $this->displayException($exception); |
|
43 | - } else { |
|
44 | - throw $exception; |
|
45 | - } |
|
46 | - } |
|
35 | + /** |
|
36 | + * @param Exception $exception |
|
37 | + * @throws Exception |
|
38 | + */ |
|
39 | + public function __construct(Exception $exception) |
|
40 | + { |
|
41 | + if (WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
42 | + $this->displayException($exception); |
|
43 | + } else { |
|
44 | + throw $exception; |
|
45 | + } |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * @access protected |
|
51 | - * @param Exception $exception |
|
52 | - * @throws ReflectionException |
|
53 | - */ |
|
54 | - protected function displayException(Exception $exception) |
|
55 | - { |
|
56 | - // get separate user and developer messages if they exist |
|
57 | - $msg = explode('||', $exception->getMessage()); |
|
58 | - $user_msg = $msg[0]; |
|
59 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
60 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
61 | - // process trace info |
|
62 | - $trace_details = $this->traceDetails($exception); |
|
63 | - $code = $exception->getCode() ?: $this->error_code; |
|
64 | - // add helpful developer messages if debugging is on |
|
65 | - // or generic non-identifying messages for non-privileged users |
|
66 | - $error_message = WP_DEBUG |
|
67 | - ? $this->developerError($exception, $msg, $code, $trace_details) |
|
68 | - : $this->genericError($msg, $code); |
|
69 | - // start gathering output |
|
70 | - $output = ' |
|
49 | + /** |
|
50 | + * @access protected |
|
51 | + * @param Exception $exception |
|
52 | + * @throws ReflectionException |
|
53 | + */ |
|
54 | + protected function displayException(Exception $exception) |
|
55 | + { |
|
56 | + // get separate user and developer messages if they exist |
|
57 | + $msg = explode('||', $exception->getMessage()); |
|
58 | + $user_msg = $msg[0]; |
|
59 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
60 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
61 | + // process trace info |
|
62 | + $trace_details = $this->traceDetails($exception); |
|
63 | + $code = $exception->getCode() ?: $this->error_code; |
|
64 | + // add helpful developer messages if debugging is on |
|
65 | + // or generic non-identifying messages for non-privileged users |
|
66 | + $error_message = WP_DEBUG |
|
67 | + ? $this->developerError($exception, $msg, $code, $trace_details) |
|
68 | + : $this->genericError($msg, $code); |
|
69 | + // start gathering output |
|
70 | + $output = ' |
|
71 | 71 | <div id="ee-error-message" class="error"> |
72 | 72 | ' . $error_message . ' |
73 | 73 | </div>'; |
74 | - $styles = $this->exceptionStyles(); |
|
75 | - $scripts = $this->printScripts(true); |
|
76 | - if (defined('DOING_AJAX')) { |
|
77 | - echo wp_json_encode(array('error' => $styles . $output . $scripts)); |
|
78 | - exit(); |
|
79 | - } |
|
80 | - echo $styles, $output, $scripts; // already escaped |
|
81 | - } |
|
74 | + $styles = $this->exceptionStyles(); |
|
75 | + $scripts = $this->printScripts(true); |
|
76 | + if (defined('DOING_AJAX')) { |
|
77 | + echo wp_json_encode(array('error' => $styles . $output . $scripts)); |
|
78 | + exit(); |
|
79 | + } |
|
80 | + echo $styles, $output, $scripts; // already escaped |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - private function genericError($msg, $code) |
|
85 | - { |
|
86 | - return ' |
|
84 | + private function genericError($msg, $code) |
|
85 | + { |
|
86 | + return ' |
|
87 | 87 | <p> |
88 | 88 | <span class="ee-error-user-msg-spn">' . trim($msg) . '</span> <sup>' . $code . '</sup> |
89 | 89 | </p>'; |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @throws ReflectionException |
|
95 | - */ |
|
96 | - private function developerError(Exception $exception, $msg, $code, $trace_details) |
|
97 | - { |
|
98 | - $time = time(); |
|
99 | - return ' |
|
93 | + /** |
|
94 | + * @throws ReflectionException |
|
95 | + */ |
|
96 | + private function developerError(Exception $exception, $msg, $code, $trace_details) |
|
97 | + { |
|
98 | + $time = time(); |
|
99 | + return ' |
|
100 | 100 | <div class="ee-error-dev-msg-dv"> |
101 | 101 | <p class="ee-error-dev-msg-pg"> |
102 | 102 | ' |
103 | - . sprintf( |
|
104 | - esc_html__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'), |
|
105 | - '<strong class="ee-error-dev-msg-str">', |
|
106 | - get_class($exception), |
|
107 | - '</strong> <span>', |
|
108 | - $code . '</span>' |
|
109 | - ) |
|
110 | - . '<br /> |
|
103 | + . sprintf( |
|
104 | + esc_html__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'), |
|
105 | + '<strong class="ee-error-dev-msg-str">', |
|
106 | + get_class($exception), |
|
107 | + '</strong> <span>', |
|
108 | + $code . '</span>' |
|
109 | + ) |
|
110 | + . '<br /> |
|
111 | 111 | <span class="big-text">"' . trim($msg) . '"</span><br/> |
112 | 112 | <a id="display-ee-error-trace-1' |
113 | - . $time |
|
114 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
|
115 | - . $time |
|
116 | - . '"> |
|
113 | + . $time |
|
114 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
|
115 | + . $time |
|
116 | + . '"> |
|
117 | 117 | ' . esc_html__('click to view backtrace and class/method details', 'event_espresso') . ' |
118 | 118 | </a><br /> |
119 | 119 | ' |
120 | - . $exception->getFile() |
|
121 | - . sprintf( |
|
122 | - esc_html__('%1$s( line no: %2$s )%3$s', 'event_espresso'), |
|
123 | - ' <span class="small-text lt-grey-text">', |
|
124 | - $exception->getLine(), |
|
125 | - '</span>' |
|
126 | - ) |
|
127 | - . ' |
|
120 | + . $exception->getFile() |
|
121 | + . sprintf( |
|
122 | + esc_html__('%1$s( line no: %2$s )%3$s', 'event_espresso'), |
|
123 | + ' <span class="small-text lt-grey-text">', |
|
124 | + $exception->getLine(), |
|
125 | + '</span>' |
|
126 | + ) |
|
127 | + . ' |
|
128 | 128 | </p> |
129 | 129 | <div id="ee-error-trace-1' |
130 | - . $time |
|
131 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
130 | + . $time |
|
131 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
132 | 132 | ' |
133 | - . $trace_details |
|
134 | - . $this->classDetails() . ' |
|
133 | + . $trace_details |
|
134 | + . $this->classDetails() . ' |
|
135 | 135 | </div> |
136 | 136 | </div>'; |
137 | - } |
|
137 | + } |
|
138 | 138 | |
139 | 139 | |
140 | - /** |
|
141 | - * @throws ReflectionException |
|
142 | - */ |
|
143 | - private function classDetails() |
|
144 | - { |
|
145 | - if (empty($this->class_name)) { |
|
146 | - return ''; |
|
147 | - } |
|
148 | - $a = new ReflectionClass($this->class_name); |
|
149 | - return ' |
|
140 | + /** |
|
141 | + * @throws ReflectionException |
|
142 | + */ |
|
143 | + private function classDetails() |
|
144 | + { |
|
145 | + if (empty($this->class_name)) { |
|
146 | + return ''; |
|
147 | + } |
|
148 | + $a = new ReflectionClass($this->class_name); |
|
149 | + return ' |
|
150 | 150 | <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;"> |
151 | 151 | <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;"> |
152 | 152 | <h3>' . esc_html__('Class Details', 'event_espresso') . '</h3> |
153 | 153 | <pre>' . $a . '</pre> |
154 | 154 | </div> |
155 | 155 | </div>'; |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * @param Exception $exception |
|
160 | - * @return string |
|
161 | - * @throws ReflectionException |
|
162 | - * @since $VID:$ |
|
163 | - */ |
|
164 | - private function traceDetails(Exception $exception) |
|
165 | - { |
|
166 | - $trace = $exception->getTrace(); |
|
167 | - if (empty($trace)) { |
|
168 | - return esc_html__( |
|
169 | - 'Sorry, but no trace information was available for this exception.', |
|
170 | - 'event_espresso' |
|
171 | - ); |
|
172 | - } |
|
158 | + /** |
|
159 | + * @param Exception $exception |
|
160 | + * @return string |
|
161 | + * @throws ReflectionException |
|
162 | + * @since $VID:$ |
|
163 | + */ |
|
164 | + private function traceDetails(Exception $exception) |
|
165 | + { |
|
166 | + $trace = $exception->getTrace(); |
|
167 | + if (empty($trace)) { |
|
168 | + return esc_html__( |
|
169 | + 'Sorry, but no trace information was available for this exception.', |
|
170 | + 'event_espresso' |
|
171 | + ); |
|
172 | + } |
|
173 | 173 | |
174 | - $trace_details = ' |
|
174 | + $trace_details = ' |
|
175 | 175 | <div id="ee-trace-details"> |
176 | 176 | <table> |
177 | 177 | <tr> |
@@ -180,160 +180,160 @@ discard block |
||
180 | 180 | <th scope="col" class="ee-align-left" style="width:40%;">File</th> |
181 | 181 | <th scope="col" class="ee-align-left"> |
182 | 182 | ' . esc_html__('Class', 'event_espresso') |
183 | - . '->' |
|
184 | - . esc_html__('Method( arguments )', 'event_espresso') . ' |
|
183 | + . '->' |
|
184 | + . esc_html__('Method( arguments )', 'event_espresso') . ' |
|
185 | 185 | </th> |
186 | 186 | </tr>'; |
187 | - $last_on_stack = count($trace) - 1; |
|
188 | - // reverse array so that stack is in proper chronological order |
|
189 | - $sorted_trace = array_reverse($trace); |
|
190 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
191 | - $this->class_name = isset($trace['class']) ? $trace['class'] : ''; |
|
192 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
193 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
194 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
195 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
196 | - $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
197 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
198 | - if (empty($file) && ! empty($this->class_name)) { |
|
199 | - $a = new ReflectionClass($this->class_name); |
|
200 | - $file = $a->getFileName(); |
|
201 | - if (empty($line) && ! empty($function)) { |
|
202 | - try { |
|
203 | - // if $function is a closure, this throws an exception |
|
204 | - $b = new ReflectionMethod($this->class_name, $function); |
|
205 | - $line = $b->getStartLine(); |
|
206 | - } catch (Exception $closure_exception) { |
|
207 | - $line = 'unknown'; |
|
208 | - } |
|
209 | - } |
|
210 | - } |
|
211 | - if ($nmbr === $last_on_stack) { |
|
212 | - $file = $exception->getFile() ?: $file; |
|
213 | - $line = $exception->getLine() ?: $line; |
|
214 | - $this->error_code = $this->generate_error_code($file, $trace['function'], $line); |
|
215 | - } |
|
216 | - $file = EEH_File::standardise_directory_separators($file); |
|
217 | - $nmbr = ! empty($nmbr) ? $nmbr : ' '; |
|
218 | - $line = ! empty($line) ? $line : ' '; |
|
219 | - $file = ! empty($file) ? $file : ' '; |
|
220 | - $type = ! empty($type) ? $type : ''; |
|
221 | - $function = ! empty($function) ? $function : ''; |
|
222 | - $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
223 | - $trace_details .= ' |
|
187 | + $last_on_stack = count($trace) - 1; |
|
188 | + // reverse array so that stack is in proper chronological order |
|
189 | + $sorted_trace = array_reverse($trace); |
|
190 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
191 | + $this->class_name = isset($trace['class']) ? $trace['class'] : ''; |
|
192 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
193 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
194 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
195 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
196 | + $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
197 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
198 | + if (empty($file) && ! empty($this->class_name)) { |
|
199 | + $a = new ReflectionClass($this->class_name); |
|
200 | + $file = $a->getFileName(); |
|
201 | + if (empty($line) && ! empty($function)) { |
|
202 | + try { |
|
203 | + // if $function is a closure, this throws an exception |
|
204 | + $b = new ReflectionMethod($this->class_name, $function); |
|
205 | + $line = $b->getStartLine(); |
|
206 | + } catch (Exception $closure_exception) { |
|
207 | + $line = 'unknown'; |
|
208 | + } |
|
209 | + } |
|
210 | + } |
|
211 | + if ($nmbr === $last_on_stack) { |
|
212 | + $file = $exception->getFile() ?: $file; |
|
213 | + $line = $exception->getLine() ?: $line; |
|
214 | + $this->error_code = $this->generate_error_code($file, $trace['function'], $line); |
|
215 | + } |
|
216 | + $file = EEH_File::standardise_directory_separators($file); |
|
217 | + $nmbr = ! empty($nmbr) ? $nmbr : ' '; |
|
218 | + $line = ! empty($line) ? $line : ' '; |
|
219 | + $file = ! empty($file) ? $file : ' '; |
|
220 | + $type = ! empty($type) ? $type : ''; |
|
221 | + $function = ! empty($function) ? $function : ''; |
|
222 | + $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
223 | + $trace_details .= ' |
|
224 | 224 | <tr> |
225 | 225 | <td class="ee-align-right">' . $nmbr . '</td> |
226 | 226 | <td class="ee-align-right">' . $line . '</td> |
227 | 227 | <td class="ee-align-left">' . $file . '</td> |
228 | 228 | <td class="ee-align-left">' . $this->class_name . $type . $function . $args . '</td> |
229 | 229 | </tr>'; |
230 | - } |
|
231 | - $trace_details .= ' |
|
230 | + } |
|
231 | + $trace_details .= ' |
|
232 | 232 | </table> |
233 | 233 | </div>'; |
234 | - return $trace_details; |
|
235 | - } |
|
234 | + return $trace_details; |
|
235 | + } |
|
236 | 236 | |
237 | 237 | |
238 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
239 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
238 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
239 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
240 | 240 | |
241 | - /** |
|
242 | - * generate string from exception trace args |
|
243 | - * |
|
244 | - * @param array $arguments |
|
245 | - * @param int $indent |
|
246 | - * @param bool $array |
|
247 | - * @return string |
|
248 | - */ |
|
249 | - private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) |
|
250 | - { |
|
251 | - $args = array(); |
|
252 | - $args_count = count($arguments); |
|
253 | - if ($args_count > 2) { |
|
254 | - $indent++; |
|
255 | - $args[] = '<br />'; |
|
256 | - } |
|
257 | - $x = 0; |
|
258 | - foreach ($arguments as $arg) { |
|
259 | - $x++; |
|
260 | - for ($i = 0; $i < $indent; $i++) { |
|
261 | - $args[] = ' '; |
|
262 | - } |
|
263 | - if (is_string($arg)) { |
|
264 | - if (! $array && strlen($arg) > 75) { |
|
265 | - $args[] = '<br />'; |
|
266 | - for ($i = 0; $i <= $indent; $i++) { |
|
267 | - $args[] = ' '; |
|
268 | - } |
|
269 | - $args[] = "'" . $arg . "'<br />"; |
|
270 | - } else { |
|
271 | - $args[] = " '" . $arg . "'"; |
|
272 | - } |
|
273 | - } elseif (is_array($arg)) { |
|
274 | - $arg_count = count($arg); |
|
275 | - if ($arg_count > 2) { |
|
276 | - $indent++; |
|
277 | - $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
278 | - $indent--; |
|
279 | - } elseif ($arg_count === 0) { |
|
280 | - $args[] = ' array()'; |
|
281 | - } else { |
|
282 | - $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
283 | - } |
|
284 | - } elseif ($arg === null) { |
|
285 | - $args[] = ' null'; |
|
286 | - } elseif (is_bool($arg)) { |
|
287 | - $args[] = $arg ? ' true' : ' false'; |
|
288 | - } elseif (is_object($arg)) { |
|
289 | - $args[] = get_class($arg); |
|
290 | - } elseif (is_resource($arg)) { |
|
291 | - $args[] = get_resource_type($arg); |
|
292 | - } else { |
|
293 | - $args[] = $arg; |
|
294 | - } |
|
295 | - if ($x === $args_count) { |
|
296 | - if ($args_count > 2) { |
|
297 | - $args[] = '<br />'; |
|
298 | - $indent--; |
|
299 | - for ($i = 1; $i < $indent; $i++) { |
|
300 | - $args[] = ' '; |
|
301 | - } |
|
302 | - } |
|
303 | - } else { |
|
304 | - $args[] = $args_count > 2 ? ',<br />' : ', '; |
|
305 | - } |
|
306 | - } |
|
307 | - return implode('', $args); |
|
308 | - } |
|
241 | + /** |
|
242 | + * generate string from exception trace args |
|
243 | + * |
|
244 | + * @param array $arguments |
|
245 | + * @param int $indent |
|
246 | + * @param bool $array |
|
247 | + * @return string |
|
248 | + */ |
|
249 | + private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) |
|
250 | + { |
|
251 | + $args = array(); |
|
252 | + $args_count = count($arguments); |
|
253 | + if ($args_count > 2) { |
|
254 | + $indent++; |
|
255 | + $args[] = '<br />'; |
|
256 | + } |
|
257 | + $x = 0; |
|
258 | + foreach ($arguments as $arg) { |
|
259 | + $x++; |
|
260 | + for ($i = 0; $i < $indent; $i++) { |
|
261 | + $args[] = ' '; |
|
262 | + } |
|
263 | + if (is_string($arg)) { |
|
264 | + if (! $array && strlen($arg) > 75) { |
|
265 | + $args[] = '<br />'; |
|
266 | + for ($i = 0; $i <= $indent; $i++) { |
|
267 | + $args[] = ' '; |
|
268 | + } |
|
269 | + $args[] = "'" . $arg . "'<br />"; |
|
270 | + } else { |
|
271 | + $args[] = " '" . $arg . "'"; |
|
272 | + } |
|
273 | + } elseif (is_array($arg)) { |
|
274 | + $arg_count = count($arg); |
|
275 | + if ($arg_count > 2) { |
|
276 | + $indent++; |
|
277 | + $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
278 | + $indent--; |
|
279 | + } elseif ($arg_count === 0) { |
|
280 | + $args[] = ' array()'; |
|
281 | + } else { |
|
282 | + $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
283 | + } |
|
284 | + } elseif ($arg === null) { |
|
285 | + $args[] = ' null'; |
|
286 | + } elseif (is_bool($arg)) { |
|
287 | + $args[] = $arg ? ' true' : ' false'; |
|
288 | + } elseif (is_object($arg)) { |
|
289 | + $args[] = get_class($arg); |
|
290 | + } elseif (is_resource($arg)) { |
|
291 | + $args[] = get_resource_type($arg); |
|
292 | + } else { |
|
293 | + $args[] = $arg; |
|
294 | + } |
|
295 | + if ($x === $args_count) { |
|
296 | + if ($args_count > 2) { |
|
297 | + $args[] = '<br />'; |
|
298 | + $indent--; |
|
299 | + for ($i = 1; $i < $indent; $i++) { |
|
300 | + $args[] = ' '; |
|
301 | + } |
|
302 | + } |
|
303 | + } else { |
|
304 | + $args[] = $args_count > 2 ? ',<br />' : ', '; |
|
305 | + } |
|
306 | + } |
|
307 | + return implode('', $args); |
|
308 | + } |
|
309 | 309 | |
310 | 310 | |
311 | - /** |
|
312 | - * create error code from filepath, function name, |
|
313 | - * and line number where exception or error was thrown |
|
314 | - * |
|
315 | - * @access protected |
|
316 | - * @param string $file |
|
317 | - * @param string $func |
|
318 | - * @param string $line |
|
319 | - * @return string |
|
320 | - */ |
|
321 | - protected function generate_error_code($file = '', $func = '', $line = '') |
|
322 | - { |
|
323 | - $file_bits = explode('.', basename($file)); |
|
324 | - $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
|
325 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
326 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
327 | - return $error_code; |
|
328 | - } |
|
311 | + /** |
|
312 | + * create error code from filepath, function name, |
|
313 | + * and line number where exception or error was thrown |
|
314 | + * |
|
315 | + * @access protected |
|
316 | + * @param string $file |
|
317 | + * @param string $func |
|
318 | + * @param string $line |
|
319 | + * @return string |
|
320 | + */ |
|
321 | + protected function generate_error_code($file = '', $func = '', $line = '') |
|
322 | + { |
|
323 | + $file_bits = explode('.', basename($file)); |
|
324 | + $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
|
325 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
326 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
327 | + return $error_code; |
|
328 | + } |
|
329 | 329 | |
330 | 330 | |
331 | - /** |
|
332 | - * @return string |
|
333 | - */ |
|
334 | - private function exceptionStyles() |
|
335 | - { |
|
336 | - return ' |
|
331 | + /** |
|
332 | + * @return string |
|
333 | + */ |
|
334 | + private function exceptionStyles() |
|
335 | + { |
|
336 | + return ' |
|
337 | 337 | <style media="screen"> |
338 | 338 | #ee-error-message { |
339 | 339 | max-width:90% !important; |
@@ -391,34 +391,34 @@ discard block |
||
391 | 391 | color: #999; |
392 | 392 | } |
393 | 393 | </style>'; |
394 | - } |
|
394 | + } |
|
395 | 395 | |
396 | 396 | |
397 | - /** |
|
398 | - * _print_scripts |
|
399 | - * |
|
400 | - * @param bool $force_print |
|
401 | - * @return string |
|
402 | - */ |
|
403 | - private function printScripts($force_print = false) |
|
404 | - { |
|
405 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
406 | - // if script is already enqueued then we can just get out |
|
407 | - if (wp_script_is('ee_error_js')) { |
|
408 | - return ''; |
|
409 | - } |
|
410 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
411 | - wp_enqueue_style('espresso_default'); |
|
412 | - wp_enqueue_style('espresso_custom_css'); |
|
413 | - wp_enqueue_script('ee_error_js'); |
|
414 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
415 | - return ''; |
|
416 | - } |
|
417 | - } |
|
418 | - $jquery = esc_url_raw(includes_url() . 'js/jquery/jquery.js'); |
|
419 | - $core = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version()); |
|
420 | - $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version()); |
|
421 | - return ' |
|
397 | + /** |
|
398 | + * _print_scripts |
|
399 | + * |
|
400 | + * @param bool $force_print |
|
401 | + * @return string |
|
402 | + */ |
|
403 | + private function printScripts($force_print = false) |
|
404 | + { |
|
405 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
406 | + // if script is already enqueued then we can just get out |
|
407 | + if (wp_script_is('ee_error_js')) { |
|
408 | + return ''; |
|
409 | + } |
|
410 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
411 | + wp_enqueue_style('espresso_default'); |
|
412 | + wp_enqueue_style('espresso_custom_css'); |
|
413 | + wp_enqueue_script('ee_error_js'); |
|
414 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
415 | + return ''; |
|
416 | + } |
|
417 | + } |
|
418 | + $jquery = esc_url_raw(includes_url() . 'js/jquery/jquery.js'); |
|
419 | + $core = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version()); |
|
420 | + $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version()); |
|
421 | + return ' |
|
422 | 422 | <script> |
423 | 423 | /* <![CDATA[ */ |
424 | 424 | const ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -428,5 +428,5 @@ discard block |
||
428 | 428 | <script src="' . $core . '" type="text/javascript" ></script> |
429 | 429 | <script src="' . $ee_error . '" type="text/javascript" ></script> |
430 | 430 | '; |
431 | - } |
|
431 | + } |
|
432 | 432 | } |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | // start gathering output |
70 | 70 | $output = ' |
71 | 71 | <div id="ee-error-message" class="error"> |
72 | - ' . $error_message . ' |
|
72 | + ' . $error_message.' |
|
73 | 73 | </div>'; |
74 | 74 | $styles = $this->exceptionStyles(); |
75 | 75 | $scripts = $this->printScripts(true); |
76 | 76 | if (defined('DOING_AJAX')) { |
77 | - echo wp_json_encode(array('error' => $styles . $output . $scripts)); |
|
77 | + echo wp_json_encode(array('error' => $styles.$output.$scripts)); |
|
78 | 78 | exit(); |
79 | 79 | } |
80 | 80 | echo $styles, $output, $scripts; // already escaped |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | { |
86 | 86 | return ' |
87 | 87 | <p> |
88 | - <span class="ee-error-user-msg-spn">' . trim($msg) . '</span> <sup>' . $code . '</sup> |
|
88 | + <span class="ee-error-user-msg-spn">' . trim($msg).'</span> <sup>'.$code.'</sup> |
|
89 | 89 | </p>'; |
90 | 90 | } |
91 | 91 | |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | '<strong class="ee-error-dev-msg-str">', |
106 | 106 | get_class($exception), |
107 | 107 | '</strong> <span>', |
108 | - $code . '</span>' |
|
108 | + $code.'</span>' |
|
109 | 109 | ) |
110 | 110 | . '<br /> |
111 | - <span class="big-text">"' . trim($msg) . '"</span><br/> |
|
111 | + <span class="big-text">"' . trim($msg).'"</span><br/> |
|
112 | 112 | <a id="display-ee-error-trace-1' |
113 | 113 | . $time |
114 | 114 | . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
115 | 115 | . $time |
116 | 116 | . '"> |
117 | - ' . esc_html__('click to view backtrace and class/method details', 'event_espresso') . ' |
|
117 | + ' . esc_html__('click to view backtrace and class/method details', 'event_espresso').' |
|
118 | 118 | </a><br /> |
119 | 119 | ' |
120 | 120 | . $exception->getFile() |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
132 | 132 | ' |
133 | 133 | . $trace_details |
134 | - . $this->classDetails() . ' |
|
134 | + . $this->classDetails().' |
|
135 | 135 | </div> |
136 | 136 | </div>'; |
137 | 137 | } |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | return ' |
150 | 150 | <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;"> |
151 | 151 | <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;"> |
152 | - <h3>' . esc_html__('Class Details', 'event_espresso') . '</h3> |
|
153 | - <pre>' . $a . '</pre> |
|
152 | + <h3>' . esc_html__('Class Details', 'event_espresso').'</h3> |
|
153 | + <pre>' . $a.'</pre> |
|
154 | 154 | </div> |
155 | 155 | </div>'; |
156 | 156 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | <th scope="col" class="ee-align-left"> |
182 | 182 | ' . esc_html__('Class', 'event_espresso') |
183 | 183 | . '->' |
184 | - . esc_html__('Method( arguments )', 'event_espresso') . ' |
|
184 | + . esc_html__('Method( arguments )', 'event_espresso').' |
|
185 | 185 | </th> |
186 | 186 | </tr>'; |
187 | 187 | $last_on_stack = count($trace) - 1; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $type = isset($trace['type']) ? $trace['type'] : ''; |
194 | 194 | $function = isset($trace['function']) ? $trace['function'] : ''; |
195 | 195 | $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
196 | - $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
196 | + $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />'.$args.'<br />' : $args; |
|
197 | 197 | $line = isset($trace['line']) ? $trace['line'] : ''; |
198 | 198 | if (empty($file) && ! empty($this->class_name)) { |
199 | 199 | $a = new ReflectionClass($this->class_name); |
@@ -219,13 +219,13 @@ discard block |
||
219 | 219 | $file = ! empty($file) ? $file : ' '; |
220 | 220 | $type = ! empty($type) ? $type : ''; |
221 | 221 | $function = ! empty($function) ? $function : ''; |
222 | - $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
222 | + $args = ! empty($args) ? '( '.$args.' )' : '()'; |
|
223 | 223 | $trace_details .= ' |
224 | 224 | <tr> |
225 | - <td class="ee-align-right">' . $nmbr . '</td> |
|
226 | - <td class="ee-align-right">' . $line . '</td> |
|
227 | - <td class="ee-align-left">' . $file . '</td> |
|
228 | - <td class="ee-align-left">' . $this->class_name . $type . $function . $args . '</td> |
|
225 | + <td class="ee-align-right">' . $nmbr.'</td> |
|
226 | + <td class="ee-align-right">' . $line.'</td> |
|
227 | + <td class="ee-align-left">' . $file.'</td> |
|
228 | + <td class="ee-align-left">' . $this->class_name.$type.$function.$args.'</td> |
|
229 | 229 | </tr>'; |
230 | 230 | } |
231 | 231 | $trace_details .= ' |
@@ -261,25 +261,25 @@ discard block |
||
261 | 261 | $args[] = ' '; |
262 | 262 | } |
263 | 263 | if (is_string($arg)) { |
264 | - if (! $array && strlen($arg) > 75) { |
|
264 | + if ( ! $array && strlen($arg) > 75) { |
|
265 | 265 | $args[] = '<br />'; |
266 | 266 | for ($i = 0; $i <= $indent; $i++) { |
267 | 267 | $args[] = ' '; |
268 | 268 | } |
269 | - $args[] = "'" . $arg . "'<br />"; |
|
269 | + $args[] = "'".$arg."'<br />"; |
|
270 | 270 | } else { |
271 | - $args[] = " '" . $arg . "'"; |
|
271 | + $args[] = " '".$arg."'"; |
|
272 | 272 | } |
273 | 273 | } elseif (is_array($arg)) { |
274 | 274 | $arg_count = count($arg); |
275 | 275 | if ($arg_count > 2) { |
276 | 276 | $indent++; |
277 | - $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
277 | + $args[] = ' array('.$this->_convert_args_to_string($arg, $indent, true).')'; |
|
278 | 278 | $indent--; |
279 | 279 | } elseif ($arg_count === 0) { |
280 | 280 | $args[] = ' array()'; |
281 | 281 | } else { |
282 | - $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
282 | + $args[] = ' array( '.$this->_convert_args_to_string($arg).' )'; |
|
283 | 283 | } |
284 | 284 | } elseif ($arg === null) { |
285 | 285 | $args[] = ' null'; |
@@ -322,8 +322,8 @@ discard block |
||
322 | 322 | { |
323 | 323 | $file_bits = explode('.', basename($file)); |
324 | 324 | $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
325 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
326 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
325 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
326 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
327 | 327 | return $error_code; |
328 | 328 | } |
329 | 329 | |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | */ |
403 | 403 | private function printScripts($force_print = false) |
404 | 404 | { |
405 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
405 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
406 | 406 | // if script is already enqueued then we can just get out |
407 | 407 | if (wp_script_is('ee_error_js')) { |
408 | 408 | return ''; |
@@ -415,18 +415,18 @@ discard block |
||
415 | 415 | return ''; |
416 | 416 | } |
417 | 417 | } |
418 | - $jquery = esc_url_raw(includes_url() . 'js/jquery/jquery.js'); |
|
419 | - $core = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version()); |
|
420 | - $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version()); |
|
418 | + $jquery = esc_url_raw(includes_url().'js/jquery/jquery.js'); |
|
419 | + $core = esc_url_raw(EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js?ver='.espresso_version()); |
|
420 | + $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js?ver='.espresso_version()); |
|
421 | 421 | return ' |
422 | 422 | <script> |
423 | 423 | /* <![CDATA[ */ |
424 | -const ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
424 | +const ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
425 | 425 | /* ]]> */ |
426 | 426 | </script> |
427 | -<script src="' . $jquery . '" type="text/javascript" ></script> |
|
428 | -<script src="' . $core . '" type="text/javascript" ></script> |
|
429 | -<script src="' . $ee_error . '" type="text/javascript" ></script> |
|
427 | +<script src="' . $jquery.'" type="text/javascript" ></script> |
|
428 | +<script src="' . $core.'" type="text/javascript" ></script> |
|
429 | +<script src="' . $ee_error.'" type="text/javascript" ></script> |
|
430 | 430 | '; |
431 | 431 | } |
432 | 432 | } |