Passed
Pull Request — development (#3540)
by Emanuele
07:11
created

template_modify_language_entries()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 106
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 8
eloc 39
nc 8
nop 0
dl 0
loc 106
rs 8.0515
c 3
b 0
f 0

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