Completed
Push — patch_1-1-4 ( 3f780f...826343 )
by Emanuele
25:17 queued 11:40
created

ManageLanguages.template.php ➔ template_download_language()   C

Complexity

Conditions 14
Paths 37

Size

Total Lines 152

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
nc 37
nop 0
dl 0
loc 152
rs 5.0133
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
 * @name      ElkArte Forum
5
 * @copyright ElkArte Forum contributors
6
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
7
 *
8
 * This file contains code covered by:
9
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
10
 * license:  	BSD, See included LICENSE.TXT for terms and conditions.
11
 *
12
 * @version 1.1
13
 *
14
 */
15
16
/**
17
 * Download a new language file.
18
 */
19
function template_download_language()
20
{
21
	global $context, $settings, $txt, $scripturl;
22
23
	// Actually finished?
24
	if (!empty($context['install_complete']))
25
	{
26
		echo '
27
	<div id="admincenter">
28
		<h2 class="category_header">', $txt['languages_download_complete'], '</h2>
29
		<div class="content">
30
			', $context['install_complete'], '
31
		</div>
32
	</div>';
33
		return;
34
	}
35
36
	// An error?
37
	if (!empty($context['error_message']))
38
		echo '
39
	<div class="errorbox">
40
		', $context['error_message'], '
41
	</div>';
42
43
	// Provide something of an introduction...
44
	echo '
45
	<div id="admincenter">
46
		<form action="', $scripturl, '?action=admin;area=languages;sa=downloadlang;did=', $context['download_id'], ';', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="UTF-8">
47
			<h2 class="category_header">', $txt['languages_download'], '</h2>
48
			<div class="content">
49
				<p>
50
					', $txt['languages_download_note'], '
51
				</p>
52
				<div class="smalltext">
53
					', $txt['languages_download_info'], '
54
				</div>
55
			</div>';
56
57
	// Show the main files.
58
	template_show_list('lang_main_files_list');
59
60
	// Now, all the images and the likes, hidden via javascript 'cause there are so fecking many.
61
	echo '
62
			<br />
63
			<h2 class="category_header">', $txt['languages_download_theme_files'], '</h2>
64
			<table class="table_grid">
65
				<thead>
66
					<tr class="table_head">
67
						<th scope="col">
68
							', $txt['languages_download_filename'], '
69
						</th>
70
						<th scope="col" style="width: 100px;">
71
							', $txt['languages_download_writable'], '
72
						</th>
73
						<th scope="col" style="width: 100px;">
74
							', $txt['languages_download_exists'], '
75
						</th>
76
						<th scope="col" style="width: 4%;">
77
							', $txt['languages_download_copy'], '
78
						</th>
79
					</tr>
80
				</thead>
81
				<tbody>';
82
83
	foreach ($context['files']['images'] as $theme => $group)
84
	{
85
		$count = 0;
86
		echo '
87
				<tr class="secondary_header">
88
					<td colspan="4">
89
						<img class="sort" src="', $settings['images_url'], '/sort_down.png" id="toggle_image_', $theme, '" alt="*" />&nbsp;', isset($context['theme_names'][$theme]) ? $context['theme_names'][$theme] : $theme, '
90
					</td>
91
				</tr>';
92
93
		foreach ($group as $file)
94
		{
95
			echo '
96
				<tr id="', $theme, '-', ($count++), '">
97
					<td>
98
						<strong>', $file['name'], '</strong><br />
99
						<span class="smalltext">', $txt['languages_download_dest'], ': ', $file['destination'], '</span>
100
					</td>
101
					<td>
102
						<span style="color: ', ($file['writable'] ? 'green' : 'red'), ';">', ($file['writable'] ? $txt['yes'] : $txt['no']), '</span>
103
					</td>
104
					<td>
105
						', $file['exists'] ? ($file['exists'] == 'same' ? $txt['languages_download_exists_same'] : $txt['languages_download_exists_different']) : $txt['no'], '
106
					</td>
107
					<td class="centertext">
108
						<input type="checkbox" name="copy_file[]" value="', $file['generaldest'], '"', ($file['default_copy'] ? ' checked="checked"' : ''), ' />
109
					</td>
110
				</tr>';
111
		}
112
	}
113
114
	echo '
115
			</tbody>
116
			</table>';
117
118
	// Do we want some FTP baby?
119
	// If the files are not writable, we might!
120
	if (!empty($context['still_not_writable']))
121
	{
122
		template_ftp_required();
123
	}
124
125
	// Install?
126
	echo '
127
			<div class="submitbutton">
128
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
129
				<input type="hidden" name="', $context['admin-dlang_token_var'], '" value="', $context['admin-dlang_token'], '" />
130
				<input type="submit" name="do_install" value="', $txt['add_language_elk_install'], '" />
131
			</div>
132
		</form>
133
	</div>';
134
135
	// The javascript for expand and collapse of sections.
136
	echo '
137
	<script>';
138
139
	// Each theme gets its own handler.
140
	foreach ($context['files']['images'] as $theme => $group)
141
	{
142
		$count = 0;
143
		echo '
144
			var oTogglePanel_', $theme, ' = new elk_Toggle({
145
				bToggleEnabled: true,
146
				bCurrentlyCollapsed: true,
147
				aSwappableContainers: [';
148
149
		foreach ($group as $file)
150
			echo '
151
					', JavaScriptEscape($theme . '-' . ($count++)), ',';
152
153
		echo '
154
					null
155
				],
156
				aSwapImages: [
157
					{
158
						sId: \'toggle_image_', $theme, '\',
159
						srcExpanded: elk_images_url + \'/selected_open.png\',
160
						altExpanded: \'*\',
161
						srcCollapsed: elk_images_url + \'/selected.png\',
162
						altCollapsed: \'*\'
163
					}
164
				]
165
			});';
166
	}
167
168
	echo '
169
	</script>';
170
}
171
172
/**
173
 * Edit language entries.
174
 */
175
function template_modify_language_entries()
176
{
177
	global $context, $txt, $scripturl;
178
179
	echo '
180
	<div id="admincenter">
181
		<form id="admin_form_wrapper" action="', $scripturl, '?action=admin;area=languages;sa=editlang;lid=', $context['lang_id'], '" method="post" accept-charset="UTF-8">
182
			<h2 class="category_header">', $txt['edit_languages'], '</h2>
183
			<div class="information">
184
				', $txt['edit_language_entries_primary'], '
185
			</div>';
186
187
	// Not writable?
188
	if ($context['lang_file_not_writable_message'])
189
	{
190
		// Oops, show an error for ya.
191
		echo '
192
			<div class="errorbox">
193
				', $context['lang_file_not_writable_message'], '
194
			</div>';
195
	}
196
197
	// Show the language entries
198
	echo '
199
			<div class="content">
200
				<fieldset>
201
					<legend>', $context['primary_settings']['name'], '</legend>
202
					<dl class="settings">
203
						<dt>
204
							<label for="locale">', $txt['languages_locale'], ':</label>
205
						</dt>
206
						<dd>
207
							<input type="text" name="locale" id="locale" size="20" value="', $context['primary_settings']['locale'], '"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' class="input_text" />
208
						</dd>
209
						<dt>
210
							<label for="dictionary">', $txt['languages_dictionary'], ':</label>
211
						</dt>
212
						<dd>
213
							<input type="text" name="dictionary" id="dictionary" size="20" value="', $context['primary_settings']['dictionary'], '"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' class="input_text" />
214
						</dd>
215
						<dt>
216
							<label for="spelling">', $txt['languages_spelling'], ':</label>
217
						</dt>
218
						<dd>
219
							<input type="text" name="spelling" id="spelling" size="20" value="', $context['primary_settings']['spelling'], '"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' class="input_text" />
220
						</dd>
221
						<dt>
222
							<label for="rtl">', $txt['languages_rtl'], ':</label>
223
						</dt>
224
						<dd>
225
							<input type="checkbox" name="rtl" id="rtl" ', $context['primary_settings']['rtl'] ? ' checked="checked"' : '', ' class="input_check"', (empty($context['file_entries']) ? '' : ' disabled="disabled"'), ' />
226
						</dd>
227
					</dl>
228
				</fieldset>
229
				<div class="submitbutton">
230
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
231
					<input type="hidden" name="', $context['admin-mlang_token_var'], '" value="', $context['admin-mlang_token'], '" />
232
					<input type="submit" name="save_main" value="', $txt['save'], '"', $context['lang_file_not_writable_message'] || !empty($context['file_entries']) ? ' disabled="disabled"' : '', ' />';
233
234
	// Allow deleting entries.
235
	if (!empty($context['langpack_uninstall_link']))
236
	{
237
		// English can't be deleted though.
238
		echo '
239
					<a href="', $context['langpack_uninstall_link'], '" class="linkbutton">' . $txt['delete'] . '</a>';
240
	}
241
242
	echo '
243
				</div>
244
			</div>
245
		</form>
246
247
		<form id="entry_form" action="', $scripturl, '?action=admin;area=languages;sa=editlang;lid=', $context['lang_id'], ';entries#entry_form" method="post" accept-charset="UTF-8">
248
			<div class="category_header">
249
				<h3 class="floatleft">
250
					', $txt['edit_language_entries'], '
251
				</h3>
252
				<div id="taskpad" class="floatright">
253
					<label for="tfid">', $txt['edit_language_entries_file'], '</label>:
254
					<select id="tfid" name="tfid" onchange="if (this.value != -1) document.forms.entry_form.submit();">';
255
256
	foreach ($context['possible_files'] as $id_theme => $theme)
257
	{
258
		echo '
259
						<option value="-1">', $theme['name'], '</option>';
260
261
		foreach ($theme['files'] as $file)
262
			echo '
263
						<option value="', $id_theme, '+', $file['id'], '"', $file['selected'] ? ' selected="selected"' : '', '> =&gt; ', $file['name'], '</option>';
264
	}
265
266
	echo '
267
					</select>
268
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
269
					<input type="hidden" name="', $context['admin-mlang_token_var'], '" value="', $context['admin-mlang_token'], '" />
270
					<noscript><input type="submit" value="', $txt['go'], '" /></noscript>
271
				</div>
272
			</div>';
273
274
	// Is it not writable?
275
	// Show an error.
276
	if (!empty($context['entries_not_writable_message']))
277
		echo '
278
			<div class="errorbox">
279
				', $context['entries_not_writable_message'], '
280
			</div>';
281
282
	// Already have some file entries?
283
	if (!empty($context['file_entries']))
284
	{
285
		echo '
286
			<div class="content">
287
				<ul class="strings_edit settings">';
288
289
		foreach ($context['file_entries'] as $entry)
290
		{
291
			echo '
292
					<li>
293
						<label for="entry_', $entry['key'], '" class="smalltext">', $entry['display_key'], '</label>
294
						<input type="hidden" name="comp[', $entry['key'], ']" value="', $entry['value'], '" />
295
						<textarea id="entry_', $entry['key'], '" name="entry[', $entry['key'], ']" cols="40" rows="', $entry['rows'] < 2 ? 2 : $entry['rows'], '">', $entry['value'], '</textarea>
296
					</li>';
297
		}
298
299
		echo '
300
				</ul>
301
				<div class="submitbutton">
302
					<input type="submit" name="save_entries" value="', $txt['save'], '"', !empty($context['entries_not_writable_message']) ? ' disabled="disabled"' : '', ' />
303
				</div>
304
			</div>';
305
	}
306
307
	echo '
308
		</form>
309
	</div>';
310
}
311
312
/**
313
 * Add a new language
314
 */
315
function template_add_language()
316
{
317
	global $context, $txt, $scripturl;
318
319
	echo '
320
	<div id="admincenter">
321
		<form id="admin_form_wrapper"action="', $scripturl, '?action=admin;area=languages;sa=add;', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="UTF-8">
322
			<h2 class="category_header">', $txt['add_language'], '</h2>
323
			<div class="content">
324
				<fieldset>
325
					<legend>', $txt['add_language_elk'], '</legend>
326
					<label for="lang_add" class="smalltext">', $txt['add_language_elk_browse'], '</label>
327
					<input type="text" id="lang_add" name="lang_add" size="40" value="', !empty($context['elk_search_term']) ? $context['elk_search_term'] : '', '" class="input_text" />';
328
329
	// Do we have some errors? Too bad.
330
	if (!empty($context['langfile_error']))
331
	{
332
		// Display a little error box.
333
		echo '
334
					<div>
335
						<br />
336
						<p class="errorbox">', $txt['add_language_error_' . $context['langfile_error']], '</p>
337
					</div>';
338
	}
339
340
	echo '
341
				</fieldset>
342
				<div class="submitbutton">
343
					<input type="submit" name="lang_add_sub" value="', $txt['search'], '" />
344
				</div>
345
			</div>';
346
347
	// Had some results?
348
	if (!empty($context['languages']))
349
	{
350
		echo '
351
			<div class="information">', $txt['add_language_elk_found'], '</div>';
352
353
		template_show_list('languages');
354
	}
355
356
	echo '
357
		</form>
358
	</div>';
359
}
360