Passed
Push — development ( 69387f...a254f4 )
by Spuds
01:03 queued 20s
created

template_maintenance()   B

Complexity

Conditions 8
Paths 32

Size

Total Lines 179
Code Lines 80

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 80
c 1
b 0
f 0
nc 32
nop 0
dl 0
loc 179
rs 7.1919

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
 * Forum maintenance page.
17
 */
18
function template_maintenance()
19
{
20
	global $context, $txt, $modSettings;
21
22
	echo '
23
	<div id="manage_attachments">
24
		<h2 class="category_header hdicon i-pie-chart">', $txt['attachment_stats'], '</h2>
25
		<div class="content">
26
			<dl class="settings">
27
				<dt><label>', $txt['attachment_total'], ':</label></dt>
28
				<dd>', $context['num_attachments'], '</dd>
29
				<dt><label>', $txt['attachment_manager_total_avatars'], ':</label></dt>
30
				<dd>', $context['num_avatars'], '</dd>
31
				<dt><label>', $txt['attachmentdir_size'], ':</label></dt>
32
				<dd>', $context['attachment_total_size'], '</dd>
33
				<dt><label>', $txt['attach_current_dir'], ':</label></dt>
34
				<dd>', $context['attach_dirs'][$modSettings['currentAttachmentUploadDir']], '</dd>
35
				<dt><label>', $txt['attachmentdir_size_current'], ':</label></dt>
36
				<dd>', $context['attachment_current_size'], '</dd>
37
				<dt><label>', $txt['attachment_space'], ':</label></dt>
38
				<dd>', $context['attachment_space'] ?? $txt['attachmentdir_size_not_set'], '</dd>
39
				<dt><label>', $txt['attachmentdir_files_current'], ':</label></dt>
40
				<dd>', $context['attachment_current_files'], '</dd>
41
				<dt><label>', $txt['attachment_files'], ':</label></dt>
42
				<dd>', $context['attachment_files'] ?? $txt['attachmentdir_files_not_set'], '</dd>
43
			</dl>
44
		</div>
45
		<div class="separator"></div>
46
		<h2 class="category_header">', $txt['attachment_integrity_check'], '</h2>
47
		<div class="content">
48
			<form action="', getUrl('admin', ['action' => 'admin', 'area' => 'manageattachments', 'sa' => 'repair', '{session_data}']), '" method="post" accept-charset="UTF-8">
49
				<p>', $txt['attachment_integrity_check_desc'], '</p>
50
				<div class="submitbutton">
51
					<input type="submit" name="repair" value="', $txt['attachment_check_now'], '" />
52
				</div>
53
			</form>
54
		</div>
55
		<div class="separator"></div>
56
		<h2 class="category_header">', $txt['attachment_pruning'], '</h2>
57
		<div class="content">
58
			<form action="', getUrl('admin', ['action' => 'admin', 'area' => 'manageattachments']), '" method="post" accept-charset="UTF-8" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');">
59
				<label for="age">', sprintf($txt['attachment_remove_old'], ' <input type="text" id="age" name="age" value="25" size="4" class="input_text" /> '), '</label><br />
60
				<label for="age_notice">', $txt['attachment_pruning_message'], '</label>: <input type="text" id="age_notice" name="notice" value="', $txt['attachment_delete_admin'], '" size="40" class="input_text" /><br />
61
				<div class="submitbutton">
62
					<input type="submit" name="remove" value="', $txt['remove'], '" />
63
					<input type="hidden" name="type" value="attachments" />
64
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
65
					<input type="hidden" name="sa" value="byAge" />
66
				</div>
67
			</form>
68
			<hr />
69
			<form action="', getUrl('admin', ['action' => 'admin', 'area' => 'manageattachments']), '" method="post" accept-charset="UTF-8" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');">
70
				<label for="size">', sprintf($txt['attachment_remove_size'], ' <input type="text" name="size" id="size" value="1000" size="5" class="input_text" /> '), '</label><br />
71
				<label for="size_notice">', $txt['attachment_pruning_message'], '</label>: <input type="text" id="size_notice" name="notice" value="', $txt['attachment_delete_admin'], '" size="40" class="input_text" /><br />
72
				<div class="submitbutton">
73
					<input type="submit" name="remove" value="', $txt['remove'], '" />
74
					<input type="hidden" name="type" value="attachments" />
75
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
76
					<input type="hidden" name="sa" value="bySize" />
77
				</div>
78
			</form>
79
			<hr />
80
			<form action="', getUrl('admin', ['action' => 'admin', 'area' => 'manageattachments']), '" method="post" accept-charset="UTF-8" onsubmit="return confirm(\'', $txt['attachment_pruning_warning'], '\');">
81
				<label for="avatar_age">', sprintf($txt['attachment_manager_avatars_older'], '
82
 					<input type="text" id="avatar_age" name="age" value="45" size="4" class="input_text" /> '), '
83
				</label>
84
				<div class="submitbutton">
85
					<input type="submit" name="remove" value="', $txt['remove'], '" />
86
					<input type="hidden" name="type" value="avatars" />
87
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
88
					<input type="hidden" name="sa" value="byAge" />
89
				</div>
90
			</form>
91
		</div>
92
		<div class="separator"></div>';
93
94
	// Transfer Attachments section
95
	echo '
96
		<h2 id="transfer" class="category_header">', $txt['attachment_transfer'], '</h2>';
97
98
	// Any results to show
99
	if (!empty($context['results']))
100
	{
101
		echo '
102
		<div class="successbox">', $context['results'], '</div>';
103
	}
104
105
	// Lots-o-options
106
	echo '
107
		<div class="content">
108
			<form action="', getUrl('admin', ['action' => 'admin', 'area' => 'manageattachments', 'sa' => 'transfer']), '" method="post" accept-charset="UTF-8">
109
				<p class="infobox">', $txt['attachment_transfer_desc'], '</p>
110
				<dl class="settings">
111
					<dt>
112
						<label for="from">', $txt['attachment_transfer_from'], '</label>
113
					</dt>
114
					<dd>
115
						<select id="from" name="from">
116
							<option value="0">', $txt['attachment_transfer_select'], '</option>';
117
118
	foreach ($context['attach_dirs'] as $id => $dir)
119
	{
120
		echo '
121
								<option value="', $id, '">', $dir, '</option>';
122
	}
123
124
	echo '
125
						</select>
126
					</dd>
127
					<dt>
128
						<label for="auto">', $txt['attachment_transfer_auto'], '</label>
129
					</dt>
130
					<dd>
131
						<select id="auto" name="auto" onchange="transferAttachOptions();">
132
							<option value="0">', $txt['attachment_transfer_auto_select'], '</option>
133
							<option value="-1">', $txt['attachment_transfer_forum_root'], '</option>';
134
135
	if (!empty($context['base_dirs']))
136
	{
137
		foreach ($context['base_dirs'] as $id => $dir)
138
		{
139
			echo '
140
							<option value="', $id, '">', $dir, '</option>';
141
		}
142
	}
143
	else
144
	{
145
		echo '
146
							<option value="0" disabled="disabled">', $txt['attachment_transfer_no_base'], '</option>';
147
	}
148
149
	echo '
150
						</select>
151
					</dd>
152
					<dt>
153
						<label for="to">', $txt['attachment_transfer_to'], '</label>
154
					</dt>
155
					<dd>
156
						<select id="to" name="to" onchange="transferAttachOptions();" >
157
							<option value="0">', $txt['attachment_transfer_select'], '</option>';
158
159
	foreach ($context['attach_dirs'] as $id => $dir)
160
	{
161
		echo '
162
							<option value="', $id, '">', $dir, '</option>';
163
	}
164
165
	echo '
166
						</select>
167
					</dd>';
168
169
	// If there are directory limits to impose, give the option to enforce it
170
	if (!empty($modSettings['attachmentDirFileLimit']))
171
	{
172
		echo '
173
					<dt>
174
						<a href="' . getUrl('action', ['action' => 'quickhelp', 'help' => 'attachment_transfer_empty']), '" onclick="return reqOverlayDiv(this.href);" class="helpicon i-help"><s>' . $txt['help'] . '</s></a>', $txt['attachment_transfer_empty'], '
175
					</dt>
176
					<dd>
177
						<input type="checkbox" name="empty_it"', $context['checked'] ? ' checked="checked"' : '', ' />
178
					</dd>';
179
	}
180
181
	echo '
182
				</dl>
183
				<div class="submitbutton">
184
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
185
					<input type="submit" onclick="start_progress()" name="transfer" value="', $txt['attachment_transfer_now'], '" />
186
				</div>
187
				<div id="progress_msg"></div>
188
				<div id="show_progress"></div>
189
			</form>
190
			<script>
191
				function start_progress() {
192
					setTimeout(function() {show_msg();}, 1000);
193
				}
194
195
				function show_msg() {
196
					$(\'#progress_msg\').html(\'<div><i class="icon i-oval"></i>&nbsp;', $txt['attachment_transfer_progress'], '<\/div>\');
197
					show_progress();
198
				}
199
200
				function show_progress() {
201
					$(\'#show_progress\').load("progress.php");
202
					setTimeout(function() {show_progress();}, 1500);
203
				}
204
205
			</script>
206
		</div>
207
	</div>';
208
}
209
210
/**
211
 * Repair attachments page
212
 */
213
function template_attachment_repair()
214
{
215
	global $context, $txt;
216
217
	// If we've completed just let them know!
218
	if ($context['completed'])
219
	{
220
		echo '
221
	<div id="manage_attachments">
222
		<div class="content">
223
			', $txt['repair_attachments_complete_desc'], '
224
		</div>
225
	</div>';
226
	}
227
	// What about if no errors were even found?
228
	elseif (!$context['errors_found'])
229
	{
230
		echo '
231
	<div id="manage_attachments">
232
		<h2 class="category_header">', $txt['repair_attachments_complete'], '</h2>
233
		<div class="content">
234
			', $txt['repair_attachments_no_errors'], '
235
		</div>
236
	</div>';
237
	}
238
	// Otherwise, I'm sad to say, we have a problem!
239
	else
240
	{
241
		echo '
242
	<form id="admin_form_wrapper" action="', getUrl('admin', ['action' => 'admin', 'area' => 'manageattachments', 'sa' => 'repair', 'fixErrors' => 1, 'step' => 0, 'substep' => 0, '{session_data}']), '" method="post" accept-charset="UTF-8">
243
		<h2 class="category_header">', $txt['repair_attachments'], '</h2>
244
		<div class="content">
245
			<p>', $txt['repair_attachments_error_desc'], '</p>';
246
247
		// Loop through each error reporting the status
248
		foreach ($context['repair_errors'] as $error => $number)
249
		{
250
			if (!empty($number))
251
			{
252
				echo '
253
			<input type="checkbox" name="to_fix[]" id="', $error, '" value="', $error, '" />
254
			<label for="', $error, '">', sprintf($txt['attach_repair_' . $error], $number), '</label>
255
			<br />';
256
			}
257
		}
258
259
		echo '
260
			<div class="submitbutton">
261
				<input type="submit" value="', $txt['repair_attachments_continue'], '" />
262
				<input type="submit" name="cancel" value="', $txt['repair_attachments_cancel'], '" />
263
			</div>
264
		</div>
265
	</form>';
266
	}
267
}
268
269
/**
270
 * Section on the page for attachments directories paths.
271
 */
272
function template_attach_paths()
273
{
274
	global $modSettings;
275
276
	if (!empty($modSettings['attachment_basedirectories']))
277
	{
278
		template_show_list('base_paths');
279
	}
280
281
	template_show_list('attach_paths');
282
}
283