Passed
Push — development ( 4fadb5...e3a728 )
by Spuds
01:02 queued 21s
created

template_show_backtrace()   B

Complexity

Conditions 8
Paths 2

Size

Total Lines 49
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 15
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 49
rs 8.4444
1
<?php
2
3
/**
4
 * @package   ElkArte Forum
5
 * @copyright ElkArte Forum contributors
6
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
7
 *
8
 * This file contains code covered by:
9
 * copyright: 2011 Simple Machines (http://www.simplemachines.org)
10
 *
11
 * @version 2.0 Beta 1
12
 *
13
 */
14
15
/**
16
 * Show an error message...
17
 *
18
 * It is shown when a fatal error occurs and should show at least a back
19
 * button and $context['error_message'].
20
 */
21
function template_fatal_error()
22
{
23
	global $context, $txt;
24
25
	echo '
26
	<div id="fatal_error">
27
		<h2 class="category_header">', $context['error_title'], '</h2>
28
		<div class="generic_list_wrapper">
29
			<div class="', ($context['error_class'] ?? 'errorbox') . '" ', $context['error_code'], '>', $context['error_message'], '</div>
30
		</div>
31
	</div>
32
	<div class="centertext">
33
		<a class="linkbutton" href="javascript:window.location.assign(document.referrer);">', $txt['back'], '</a>
34
	</div>';
35
}
36
37
/**
38
 * Shows the forum error log in all it's detail
39
 * Supports filtering for viewing all errors of a 'type'
40
 */
41
function template_error_log()
42
{
43
	global $context, $settings, $scripturl, $txt;
44
45
	echo '
46
		<form class="generic_list_wrapper" action="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] === 'down' ? ';desc' : '', ';start=', $context['start'], $context['has_filter'] ? $context['$page_filter'] : '', '" method="post" accept-charset="UTF-8">
47
			<h2 class="category_header">
48
				<a class="hdicon i-help help" href="', $scripturl, '?action=quickhelp;help=error_log" onclick="return reqOverlayDiv(this.href);" title="', $txt['help'], '"></a> ', $txt['errlog'], '
49
			</h2>
50
			<div class="flow_flex">';
51
52
	template_pagesection();
53
54
	echo '
55
				<div class="flow_flex_right submitbutton">
56
					<input type="submit" name="removeSelection" value="' . $txt['remove_selection'] . '" onclick="return confirm(\'' . $txt['remove_selection_confirm'] . '\');" />
57
					<input type="submit" name="delall" value="', $context['has_filter'] ? $txt['remove_filtered_results'] : $txt['remove_all'], '" onclick="return confirm(\'', $context['has_filter'] ? $txt['remove_filtered_results_confirm'] : $txt['sure_about_errorlog_remove'], '\');" />
58
				</div>
59
			</div>';
60
61
	echo '
62
			<table class="table_grid" id="error_log">
63
				<tr>
64
					<td colspan="3">
65
						&nbsp;&nbsp;', $txt['apply_filter_of_type'], ':';
66
67
	$error_types = [];
68
	foreach ($context['error_types'] as $details)
69
	{
70
		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt="" /> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'class="selected"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
71
	}
72
73
	echo '
74
						', implode('&nbsp;|&nbsp;', $error_types), '
75
					</td>
76
				</tr>';
77
78
	if ($context['has_filter'])
79
	{
80
		echo '
81
				<tr>
82
					<td colspan="3">
83
						<strong>&nbsp;&nbsp;', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], '&nbsp;&nbsp;[<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] === 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
84
					</td>
85
				</tr>';
86
	}
87
88
	echo '
89
				<tr class="secondary_header">
90
					<td colspan="3" class="righttext">
91
						<label for="check_all1"><strong>', $txt['check_all'], '</strong></label>&nbsp;
92
						<input type="checkbox" id="check_all1" onclick="invertAll(this, this.form, \'delete[]\'); this.form.check_all2.checked = this.checked;" />
93
					</td>
94
				</tr>';
95
96
	// No errors, then show a message
97
	if (count($context['errors']) === 0)
98
	{
99
		echo '
100
				<tr>
101
					<td class="centertext" colspan="3">', $txt['errlog_no_entries'], '</td>
102
				</tr>';
103
	}
104
105
	// We have some errors, show them...
106
	foreach ($context['errors'] as $error)
107
	{
108
		echo '
109
				<tr>
110
					<td class="grid60">
111
						<div>
112
							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] === 'down' ? ';desc' : '', ';filter=error_type;value=', $error['error_type']['type'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_type'], '" class="nosel icon i-search"></a>
113
							', $txt['error_type'], ': ', $error['error_type']['name'], '
114
						</div>
115
						<div>
116
							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] === 'down' ? ';desc' : '', ';filter=message;value=', $error['message']['href'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_message'], '" class="nosel icon i-search"></a>
117
						', $error['message']['html'], '
118
						</div>
119
						<div>
120
							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] === 'down' ? ';desc' : '', ';filter=url;value=', $error['url']['href'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_url'], '" class="nosel icon i-search"></a>
121
							<a href="', $error['url']['html'], '">', $error['url']['html'], '</a>
122
						</div>';
123
124
		if (!empty($error['file']))
125
		{
126
			echo '
127
						<div>
128
							<a class="scope" href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] === 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '" class="nosel icon i-search"></a>
129
							<i class="icon i-eye"></i> ', $txt['file'], ': ', $error['file']['link'];
130
131
			if (!empty($error['backtrace']))
132
			{
133
				echo '
134
							<i class="icon i-bug"></i>', $error['backtrace']['link'];
135
			}
136
137
			echo '
138
						</div>';
139
		}
140
141
		echo '
142
					</td>
143
					<td>
144
						<div>
145
							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] === 'down' ? ';desc' : '', ';filter=id_member;value=', $error['member']['id'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_member'], '" class="nosel icon i-search"></a>
146
							<strong>', $error['member']['link'], '</strong>
147
						</div>
148
						<div>
149
							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] === 'down' ? '' : ';desc', $context['has_filter'] ? $context['$page_filter'] : '', '" title="', $txt['reverse_direction'], '">
150
								<i class="nosel icon icon-small i-sort-numeric-', $context['sort_direction'], '" title="', $txt['reverse_direction'], '"></i>
151
							</a>
152
							', $error['time'], '
153
						</div>
154
						<div>
155
							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] === 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '" class="nosel icon i-search"></a>
156
							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>
157
						</div>';
158
159
		if ($error['member']['session'] !== '')
160
		{
161
			echo '
162
						<div>
163
							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] === 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '" class="nosel icon i-search"></a>
164
							', $error['member']['session'], '
165
						</div>';
166
		}
167
168
		echo '
169
					</td>
170
					<td class="checkbox_column">
171
						<input type="checkbox" name="delete[]" value="', $error['id'], '" />
172
					</td>
173
				</tr>';
174
	}
175
176
	echo '
177
				<tr class="secondary_header">
178
					<td colspan="3" class="righttext">
179
						<label for="check_all2"><strong>', $txt['check_all'], '</strong></label>&nbsp;
180
						<input type="checkbox" id="check_all2" onclick="invertAll(this, this.form, \'delete[]\'); this.form.check_all1.checked = this.checked;" />
181
					</td>
182
				</tr>
183
			</table>
184
			<div class="flow_flex">';
185
186
	template_pagesection();
187
188
	echo '
189
				<div class="flow_flex_right submitbutton">
190
					<input type="submit" name="removeSelection" value="' . $txt['remove_selection'] . '" onclick="return confirm(\'' . $txt['remove_selection_confirm'] . '\');" />
191
					<input type="submit" name="delall" value="', $context['has_filter'] ? $txt['remove_filtered_results'] : $txt['remove_all'], '" onclick="return confirm(\'', $context['has_filter'] ? $txt['remove_filtered_results_confirm'] : $txt['sure_about_errorlog_remove'], '\');" />';
192
193
	if ($context['sort_direction'] === 'down')
194
	{
195
		echo '
196
					<input type="hidden" name="desc" value="1" />';
197
	}
198
199
	echo '
200
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
201
					<input type="hidden" name="', $context['admin-el_token_var'], '" value="', $context['admin-el_token'], '" />
202
				</div>
203
			</div>
204
		</form>';
205
}
206
207
/**
208
 * Shows the subsection of a file where an error occurred
209
 */
210
function template_show_file()
211
{
212
	global $context;
213
214
	echo '<!DOCTYPE html>
215
<html ', $context['right_to_left'] ? 'dir="rtl"' : '', '>
216
	<head>
217
		<title>', $context['file_data']['file'], '</title>
218
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
219
		<style>
220
			body {
221
				color: #222;
222
				background-color: #FAFAFA;
223
				font-family: Verdana, arial, helvetica, serif;
224
				font-size: small;
225
			}
226
			a {color: #49643D;}
227
			.curline {background: #ffe; display: inline-block; font-weight: bold;}
228
			.lineno {color:#222;}
229
		</style>
230
	</head>
231
	<body>
232
		<div style="overflow: auto;"><pre style="margin: 0;">';
233
234
	foreach ($context['file_data']['contents'] as $line => $content)
235
	{
236
		printf(
237
			'<span class="lineno">%d:</span> ',
238
			$line
239
		);
240
241
		echo $content, "\n";
242
	}
243
244
	echo '
245
		</pre></div>
246
	</body>
247
</html>';
248
}
249
250
/**
251
 * When an attachment fails to upload, this template will show
252
 * all the issues to the user
253
 */
254
function template_attachment_errors()
255
{
256
	global $context, $txt;
257
258
	echo '
259
	<div>
260
		<h2 class="category_header">', $txt['attach_error_title'], '</h2>
261
		<div class="content">';
262
263
	foreach ($context['attachment_error_keys'] as $key)
264
	{
265
		template_show_error($key);
266
	}
267
268
	echo '
269
		</div>
270
	</div>';
271
}
272
273
/**
274
 * This template shows an error log backtrace
275
 */
276
function template_show_backtrace()
277
{
278
	global $context, $txt;
279
280
	echo '<!DOCTYPE html>
281
<html ', $context['right_to_left'] ? 'dir="rtl"' : '', '>
282
	<head>
283
		<title>', $context['backtrace_data']['file'], '</title>
284
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
285
		<style>
286
			body {
287
				color: #222;
288
				background-color: #FAFAFA;
289
				font-family: SFMono-Regular, ui-monospace, Menlo, Monaco, Consolas, "DejaVu Sans Mono", "Liberation Mono", "Courier New", monospace;
290
				font-variant-numeric: tabular-nums;
291
				font-size: small;
292
			}
293
		</style>
294
	</head>
295
	<body>
296
		<h3 class="category_header">
297
			', $context['backtrace_data']['message'], '
298
		</h3>
299
		<ul style="list-style: none;">';
300
301
	if (!empty($context['backtrace_data']['contents']))
302
	{
303
		foreach ($context['backtrace_data']['contents'] as $line => $content)
304
		{
305
			// Check for existing
306
			if (!property_exists($content, 'file') || empty($content->file))
307
			{
308
				$content->file = $txt['unknown'];
309
			}
310
311
			if (!property_exists($content, 'line') || empty($content->line))
312
			{
313
				$content->line = -1;
314
			}
315
316
			echo '
317
				<li>', sprintf($txt['backtrace_info'], $line, $content->function, $content->file, $content->line), '</li>';
318
		}
319
320
		echo '
321
			</ul>';
322
	}
323
324
	echo '
325
	</body>
326
</html>';
327
}
328