Completed
Push — release-2.1 ( e15e64...996344 )
by Mathias
11s
created
Themes/default/Errors.template.php 1 patch
Braces   +24 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 {
24 24
 	global $context, $txt;
25 25
 
26
-	if (!empty($context['simple_action']))
27
-		echo '
26
+	if (!empty($context['simple_action'])) {
27
+			echo '
28 28
 	<strong>
29 29
 		', $context['error_title'], '
30 30
 	</strong><br>
31 31
 	<div ', $context['error_code'], 'class="padding">
32 32
 		', $context['error_message'], '
33 33
 	</div>';
34
-	else
34
+	} else
35 35
 	{
36 36
 		echo '
37 37
 	<div id="fatal_error">
@@ -85,21 +85,23 @@  discard block
 block discarded – undo
85 85
 
86 86
 	$error_types = array();
87 87
 
88
-	foreach ($context['error_types'] as $type => $details)
89
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
88
+	foreach ($context['error_types'] as $type => $details) {
89
+			$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
90
+	}
90 91
 
91 92
 	echo '
92 93
 						', implode(' | ', $error_types), '
93 94
 					</td>
94 95
 				</tr>';
95 96
 
96
-	if ($context['has_filter'])
97
-		echo '
97
+	if ($context['has_filter']) {
98
+			echo '
98 99
 				<tr>
99 100
 					<td colspan="3" class="windowbg">
100 101
 						<strong>', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], ' [<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
101 102
 					</td>
102 103
 				</tr>';
104
+	}
103 105
 
104 106
 	echo '
105 107
 				<tr>
@@ -110,11 +112,12 @@  discard block
 block discarded – undo
110 112
 				</tr>';
111 113
 
112 114
 	// No errors, then show a message
113
-	if (count($context['errors']) == 0)
114
-		echo '
115
+	if (count($context['errors']) == 0) {
116
+			echo '
115 117
 				<tr class="windowbg">
116 118
 					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
117 119
 				</tr>';
120
+	}
118 121
 
119 122
 	// We have some errors, must be some mods installed :P
120 123
 	foreach ($context['errors'] as $error)
@@ -128,16 +131,18 @@  discard block
 block discarded – undo
128 131
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a>
129 132
 							', $error['time'], '<br>';
130 133
 
131
-		if (!empty($error['member']['ip']))
132
-			echo '
134
+		if (!empty($error['member']['ip'])) {
135
+					echo '
133 136
 							<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'], '"><span class="generic_icons filter centericon"></span></a>
134 137
 							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>';
138
+		}
135 139
 		
136
-		if ($error['member']['session'] != '')
137
-			echo '
140
+		if ($error['member']['session'] != '') {
141
+					echo '
138 142
 							<br>
139 143
 							<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'], '"><span class="generic_icons filter centericon"></span></a>
140 144
 							', $error['member']['session'], '<br>';
145
+		}
141 146
 
142 147
 		echo '
143 148
 						</div>
@@ -152,12 +157,13 @@  discard block
 block discarded – undo
152 157
 							<a href="', $error['url']['html'], '">', $error['url']['html'], '</a>
153 158
 ';
154 159
 
155
-		if (!empty($error['file']))
156
-			echo '
160
+		if (!empty($error['file'])) {
161
+					echo '
157 162
 							<div>
158 163
 								<a 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'], '">'
159 164
 				. '					<span class="generic_icons filter"></span></a> ', $error['file']['link'], ' (', $txt['line'], ' ', $error['file']['line'], ')
160 165
 							</div>';
166
+		}
161 167
 
162 168
 		echo '
163 169
 						</div>
@@ -186,9 +192,10 @@  discard block
 block discarded – undo
186 192
 				</div>
187 193
 			</div>';
188 194
 
189
-	if ($context['sort_direction'] == 'down')
190
-		echo '
195
+	if ($context['sort_direction'] == 'down') {
196
+			echo '
191 197
 			<input type="hidden" name="desc" value="1">';
198
+	}
192 199
 
193 200
 	echo '
194 201
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
Please login to merge, or discard this patch.
Themes/default/Profile.template.php 1 patch
Braces   +508 added lines, -392 removed lines patch added patch discarded remove patch
@@ -18,23 +18,25 @@  discard block
 block discarded – undo
18 18
 	global $context;
19 19
 
20 20
 	// Prevent Chrome from auto completing fields when viewing/editing other members profiles
21
-	if (isBrowser('is_chrome') && !$context['user']['is_owner'])
22
-		echo '
21
+	if (isBrowser('is_chrome') && !$context['user']['is_owner']) {
22
+			echo '
23 23
 			<script>
24 24
 				disableAutoComplete();
25 25
 			</script>';
26
+	}
26 27
 
27 28
 	// If an error occurred while trying to save previously, give the user a clue!
28 29
 	echo '
29 30
 			', template_error_message();
30 31
 
31 32
 	// If the profile was update successfully, let the user know this.
32
-	if (!empty($context['profile_updated']))
33
-		echo '
33
+	if (!empty($context['profile_updated'])) {
34
+			echo '
34 35
 			<div class="infobox">
35 36
 				', $context['profile_updated'], '
36 37
 			</div>';
37
-}
38
+	}
39
+	}
38 40
 
39 41
 /**
40 42
  * Template for any HTML needed below the profile (closing off divs/tables, etc.)
@@ -99,19 +101,19 @@  discard block
 block discarded – undo
99 101
 		</div>
100 102
 		<div class="alerts_unread">';
101 103
 
102
-	if (empty($context['unread_alerts']))
103
-		template_alerts_all_read();
104
-
105
-	else
104
+	if (empty($context['unread_alerts'])) {
105
+			template_alerts_all_read();
106
+	} else
106 107
 	{
107
-		foreach ($context['unread_alerts'] as $id_alert => $details)
108
-			echo '
108
+		foreach ($context['unread_alerts'] as $id_alert => $details) {
109
+					echo '
109 110
 			<div class="unread">
110 111
 				', !empty($details['sender']) ? $details['sender']['avatar']['image'] : '', '
111 112
 				<div class="details">
112 113
 					', !empty($details['icon']) ? $details['icon'] : '', '<span>', $details['text'], '</span> - ', $details['time'], '
113 114
 				</div>
114 115
 			</div>';
116
+		}
115 117
 	}
116 118
 
117 119
 	echo '
@@ -161,10 +163,11 @@  discard block
 block discarded – undo
161 163
 			<div class="custom_fields_above_name">
162 164
 				<ul>';
163 165
 
164
-		foreach ($context['print_custom_fields']['above_member'] as $field)
165
-			if (!empty($field['output_html']))
166
+		foreach ($context['print_custom_fields']['above_member'] as $field) {
167
+					if (!empty($field['output_html']))
166 168
 				echo '
167 169
 					<li>', $field['output_html'], '</li>';
170
+		}
168 171
 
169 172
 		echo '
170 173
 				</ul>
@@ -176,20 +179,22 @@  discard block
 block discarded – undo
176 179
 			<div class="username clear">
177 180
 				<h4>';
178 181
 
179
-	if (!empty($context['print_custom_fields']['before_member']))
180
-		foreach ($context['print_custom_fields']['before_member'] as $field)
182
+	if (!empty($context['print_custom_fields']['before_member'])) {
183
+			foreach ($context['print_custom_fields']['before_member'] as $field)
181 184
 			if (!empty($field['output_html']))
182 185
 				echo '
183 186
 					<span>', $field['output_html'], '</span>';
187
+	}
184 188
 
185 189
 	echo '
186 190
 					', $context['member']['name'];
187 191
 
188
-	if (!empty($context['print_custom_fields']['after_member']))
189
-		foreach ($context['print_custom_fields']['after_member'] as $field)
192
+	if (!empty($context['print_custom_fields']['after_member'])) {
193
+			foreach ($context['print_custom_fields']['after_member'] as $field)
190 194
 			if (!empty($field['output_html']))
191 195
 				echo '
192 196
 					<span>', $field['output_html'], '</span>';
197
+	}
193 198
 
194 199
 
195 200
 	echo '
@@ -205,10 +210,11 @@  discard block
 block discarded – undo
205 210
 			<div class="custom_fields_below_avatar">
206 211
 				<ul>';
207 212
 
208
-		foreach ($context['print_custom_fields']['below_avatar'] as $field)
209
-			if (!empty($field['output_html']))
213
+		foreach ($context['print_custom_fields']['below_avatar'] as $field) {
214
+					if (!empty($field['output_html']))
210 215
 				echo '
211 216
 					<li>', $field['output_html'], '</li>';
217
+		}
212 218
 
213 219
 		echo '
214 220
 				</ul>
@@ -220,22 +226,25 @@  discard block
 block discarded – undo
220 226
 			<ul class="clear">';
221 227
 
222 228
 	// Email is only visible if it's your profile or you have the moderate_forum permission
223
-	if ($context['member']['show_email'])
224
-		echo '
229
+	if ($context['member']['show_email']) {
230
+			echo '
225 231
 				<li><a href="mailto:', $context['member']['email'], '" title="', $context['member']['email'], '" rel="nofollow"><span class="generic_icons mail" title="' . $txt['email'] . '"></span></a></li>';
232
+	}
226 233
 
227 234
 	// Don't show an icon if they haven't specified a website.
228
-	if ($context['member']['website']['url'] !== '' && !isset($context['disabled_fields']['website']))
229
-		echo '
235
+	if ($context['member']['website']['url'] !== '' && !isset($context['disabled_fields']['website'])) {
236
+			echo '
230 237
 				<li><a href="', $context['member']['website']['url'], '" title="' . $context['member']['website']['title'] . '" target="_blank" rel="noopener">', ($settings['use_image_buttons'] ? '<span class="generic_icons www" title="' . $context['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
238
+	}
231 239
 
232 240
 	// Are there any custom profile fields as icons?
233 241
 	if (!empty($context['print_custom_fields']['icons']))
234 242
 	{
235
-		foreach ($context['print_custom_fields']['icons'] as $field)
236
-			if (!empty($field['output_html']))
243
+		foreach ($context['print_custom_fields']['icons'] as $field) {
244
+					if (!empty($field['output_html']))
237 245
 				echo '
238 246
 				<li class="custom_field">', $field['output_html'], '</li>';
247
+		}
239 248
 	}
240 249
 
241 250
 	echo '
@@ -244,24 +253,27 @@  discard block
 block discarded – undo
244 253
 				', $context['can_send_pm'] ? '<a href="' . $context['member']['online']['href'] . '" title="' . $context['member']['online']['text'] . '" rel="nofollow">' : '', $settings['use_image_buttons'] ? '<span class="' . ($context['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $context['member']['online']['text'] . '"></span>' : $context['member']['online']['label'], $context['can_send_pm'] ? '</a>' : '', $settings['use_image_buttons'] ? '<span class="smalltext"> ' . $context['member']['online']['label'] . '</span>' : '';
245 254
 
246 255
 	// Can they add this member as a buddy?
247
-	if (!empty($context['can_have_buddy']) && !$context['user']['is_owner'])
248
-		echo '
256
+	if (!empty($context['can_have_buddy']) && !$context['user']['is_owner']) {
257
+			echo '
249 258
 				<br>
250 259
 				<a href="', $scripturl, '?action=buddy;u=', $context['id_member'], ';', $context['session_var'], '=', $context['session_id'], '">[', $txt['buddy_' . ($context['member']['is_buddy'] ? 'remove' : 'add')], ']</a>';
260
+	}
251 261
 
252 262
 	echo '
253 263
 			</span>';
254 264
 
255
-	if (!$context['user']['is_owner'] && $context['can_send_pm'])
256
-		echo '
265
+	if (!$context['user']['is_owner'] && $context['can_send_pm']) {
266
+			echo '
257 267
 			<a href="', $scripturl, '?action=pm;sa=send;u=', $context['id_member'], '" class="infolinks">', $txt['profile_sendpm_short'], '</a>';
268
+	}
258 269
 
259 270
 	echo '
260 271
 			<a href="', $scripturl, '?action=profile;area=showposts;u=', $context['id_member'], '" class="infolinks">', $txt['showPosts'], '</a>';
261 272
 
262
-	if ($context['user']['is_owner'] && !empty($modSettings['drafts_post_enabled']))
263
-		echo '
273
+	if ($context['user']['is_owner'] && !empty($modSettings['drafts_post_enabled'])) {
274
+			echo '
264 275
 			<a href="', $scripturl, '?action=profile;area=showdrafts;u=', $context['id_member'], '" class="infolinks">', $txt['drafts_show'], '</a>';
276
+	}
265 277
 
266 278
 	echo '
267 279
 			<a href="', $scripturl, '?action=profile;area=statistics;u=', $context['id_member'], '" class="infolinks">', $txt['statPanel'], '</a>';
@@ -273,10 +285,11 @@  discard block
 block discarded – undo
273 285
 			<div class="custom_fields_bottom">
274 286
 				<ul class="nolist">';
275 287
 
276
-		foreach ($context['print_custom_fields']['bottom_poster'] as $field)
277
-			if (!empty($field['output_html']))
288
+		foreach ($context['print_custom_fields']['bottom_poster'] as $field) {
289
+					if (!empty($field['output_html']))
278 290
 				echo '
279 291
 					<li>', $field['output_html'], '</li>';
292
+		}
280 293
 
281 294
 		echo '
282 295
 				</ul>
@@ -289,30 +302,35 @@  discard block
 block discarded – undo
289 302
 		<div id="detailedinfo">
290 303
 			<dl class="settings">';
291 304
 
292
-	if ($context['user']['is_owner'] || $context['user']['is_admin'])
293
-		echo '
305
+	if ($context['user']['is_owner'] || $context['user']['is_admin']) {
306
+			echo '
294 307
 				<dt>', $txt['username'], ': </dt>
295 308
 				<dd>', $context['member']['username'], '</dd>';
309
+	}
296 310
 
297
-	if (!isset($context['disabled_fields']['posts']))
298
-		echo '
311
+	if (!isset($context['disabled_fields']['posts'])) {
312
+			echo '
299 313
 				<dt>', $txt['profile_posts'], ': </dt>
300 314
 				<dd>', $context['member']['posts'], ' (', $context['member']['posts_per_day'], ' ', $txt['posts_per_day'], ')</dd>';
315
+	}
301 316
 
302
-	if ($context['member']['show_email'])
303
-		echo '
317
+	if ($context['member']['show_email']) {
318
+			echo '
304 319
 				<dt>', $txt['email'], ': </dt>
305 320
 				<dd><a href="mailto:', $context['member']['email'], '">', $context['member']['email'], '</a></dd>';
321
+	}
306 322
 
307
-	if (!empty($modSettings['titlesEnable']) && !empty($context['member']['title']))
308
-		echo '
323
+	if (!empty($modSettings['titlesEnable']) && !empty($context['member']['title'])) {
324
+			echo '
309 325
 				<dt>', $txt['custom_title'], ': </dt>
310 326
 				<dd>', $context['member']['title'], '</dd>';
327
+	}
311 328
 
312
-	if (!empty($context['member']['blurb']))
313
-		echo '
329
+	if (!empty($context['member']['blurb'])) {
330
+			echo '
314 331
 				<dt>', $txt['personal_text'], ': </dt>
315 332
 				<dd>', $context['member']['blurb'], '</dd>';
333
+	}
316 334
 
317 335
 	echo '
318 336
 				<dt>', $txt['age'], ':</dt>
@@ -326,19 +344,21 @@  discard block
 block discarded – undo
326 344
 	{
327 345
 		$fields = array();
328 346
 
329
-		foreach ($context['print_custom_fields']['standard'] as $field)
330
-			if (!empty($field['output_html']))
347
+		foreach ($context['print_custom_fields']['standard'] as $field) {
348
+					if (!empty($field['output_html']))
331 349
 				$fields[] = $field;
350
+		}
332 351
 
333 352
 		if (count($fields) > 0)
334 353
 		{
335 354
 			echo '
336 355
 			<dl class="settings">';
337 356
 
338
-			foreach ($fields as $field)
339
-				echo '
357
+			foreach ($fields as $field) {
358
+							echo '
340 359
 				<dt>', $field['name'], ':</dt>
341 360
 				<dd>', $field['output_html'], '</dd>';
361
+			}
342 362
 
343 363
 			echo '
344 364
 			</dl>';
@@ -358,9 +378,10 @@  discard block
 block discarded – undo
358 378
 					<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=', ($context['can_issue_warning'] && !$context['user']['is_owner'] ? 'issuewarning' : 'viewwarning'), '">', $context['member']['warning'], '%</a>';
359 379
 
360 380
 		// Can we provide information on what this means?
361
-		if (!empty($context['warning_status']))
362
-			echo '
381
+		if (!empty($context['warning_status'])) {
382
+					echo '
363 383
 					<span class="smalltext">(', $context['warning_status'], ')</span>';
384
+		}
364 385
 
365 386
 		echo '
366 387
 				</dd>';
@@ -371,11 +392,12 @@  discard block
 block discarded – undo
371 392
 	{
372 393
 
373 394
 		// If the person looking at the summary has permission, and the account isn't activated, give the viewer the ability to do it themselves.
374
-		if (!empty($context['activate_message']))
375
-			echo '
395
+		if (!empty($context['activate_message'])) {
396
+					echo '
376 397
 				<dt class="clear">
377 398
 					<span class="alert">', $context['activate_message'], '</span> (<a href="', $context['activate_link'], '"', ($context['activate_type'] == 4 ? ' class="you_sure" data-confirm="' . $txt['profileConfirm'] . '"' : ''), '>', $context['activate_link_text'], '</a>)
378 399
 				</dt>';
400
+		}
379 401
 
380 402
 		// If the current member is banned, show a message and possibly a link to the ban.
381 403
 		if (!empty($context['member']['bans']))
@@ -387,10 +409,11 @@  discard block
 block discarded – undo
387 409
 				<dt class="clear" id="ban_info" style="display: none;">
388 410
 					<strong>', $txt['user_banned_by_following'], ':</strong>';
389 411
 
390
-			foreach ($context['member']['bans'] as $ban)
391
-				echo '
412
+			foreach ($context['member']['bans'] as $ban) {
413
+							echo '
392 414
 					<br>
393 415
 					<span class="smalltext">', $ban['explanation'], '</span>';
416
+			}
394 417
 
395 418
 			echo '
396 419
 				</dt>';
@@ -404,30 +427,34 @@  discard block
 block discarded – undo
404 427
 	// If the person looking is allowed, they can check the members IP address and hostname.
405 428
 	if ($context['can_see_ip'])
406 429
 	{
407
-		if (!empty($context['member']['ip']))
408
-		echo '
430
+		if (!empty($context['member']['ip'])) {
431
+				echo '
409 432
 				<dt>', $txt['ip'], ': </dt>
410 433
 				<dd><a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['member']['ip'], ';u=', $context['member']['id'], '">', $context['member']['ip'], '</a></dd>';
434
+		}
411 435
 
412
-		if (empty($modSettings['disableHostnameLookup']) && !empty($context['member']['ip']))
413
-			echo '
436
+		if (empty($modSettings['disableHostnameLookup']) && !empty($context['member']['ip'])) {
437
+					echo '
414 438
 				<dt>', $txt['hostname'], ': </dt>
415 439
 				<dd>', $context['member']['hostname'], '</dd>';
440
+		}
416 441
 	}
417 442
 
418 443
 	echo '
419 444
 				<dt>', $txt['local_time'], ':</dt>
420 445
 				<dd>', $context['member']['local_time'], '</dd>';
421 446
 
422
-	if (!empty($modSettings['userLanguage']) && !empty($context['member']['language']))
423
-		echo '
447
+	if (!empty($modSettings['userLanguage']) && !empty($context['member']['language'])) {
448
+			echo '
424 449
 				<dt>', $txt['language'], ':</dt>
425 450
 				<dd>', $context['member']['language'], '</dd>';
451
+	}
426 452
 
427
-	if ($context['member']['show_last_login'])
428
-		echo '
453
+	if ($context['member']['show_last_login']) {
454
+			echo '
429 455
 				<dt>', $txt['lastLoggedIn'], ': </dt>
430 456
 				<dd>', $context['member']['last_login'], (!empty($context['member']['is_hidden']) ? ' (' . $txt['hidden'] . ')' : ''), '</dd>';
457
+	}
431 458
 
432 459
 	echo '
433 460
 			</dl>';
@@ -439,10 +466,11 @@  discard block
 block discarded – undo
439 466
 			<div class="custom_fields_above_signature">
440 467
 				<ul class="nolist">';
441 468
 
442
-		foreach ($context['print_custom_fields']['above_signature'] as $field)
443
-			if (!empty($field['output_html']))
469
+		foreach ($context['print_custom_fields']['above_signature'] as $field) {
470
+					if (!empty($field['output_html']))
444 471
 				echo '
445 472
 					<li>', $field['output_html'], '</li>';
473
+		}
446 474
 
447 475
 		echo '
448 476
 				</ul>
@@ -450,12 +478,13 @@  discard block
 block discarded – undo
450 478
 	}
451 479
 
452 480
 	// Show the users signature.
453
-	if ($context['signature_enabled'] && !empty($context['member']['signature']))
454
-		echo '
481
+	if ($context['signature_enabled'] && !empty($context['member']['signature'])) {
482
+			echo '
455 483
 			<div class="signature">
456 484
 				<h5>', $txt['signature'], ':</h5>
457 485
 				', $context['member']['signature'], '
458 486
 			</div>';
487
+	}
459 488
 
460 489
 	// Are there any custom profile fields for below the signature?
461 490
 	if (!empty($context['print_custom_fields']['below_signature']))
@@ -464,10 +493,11 @@  discard block
 block discarded – undo
464 493
 			<div class="custom_fields_below_signature">
465 494
 				<ul class="nolist">';
466 495
 
467
-		foreach ($context['print_custom_fields']['below_signature'] as $field)
468
-			if (!empty($field['output_html']))
496
+		foreach ($context['print_custom_fields']['below_signature'] as $field) {
497
+					if (!empty($field['output_html']))
469 498
 				echo '
470 499
 					<li>', $field['output_html'], '</li>';
500
+		}
471 501
 
472 502
 		echo '
473 503
 				</ul>
@@ -513,62 +543,70 @@  discard block
 block discarded – undo
513 543
 			</div>
514 544
 			<div class="list_posts">';
515 545
 
516
-			if (!$post['approved'])
517
-				echo '
546
+			if (!$post['approved']) {
547
+							echo '
518 548
 				<div class="approve_post">
519 549
 					<em>', $txt['post_awaiting_approval'], '</em>
520 550
 				</div>';
551
+			}
521 552
 
522 553
 			echo '
523 554
 				', $post['body'], '
524 555
 			</div>';
525 556
 
526
-			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
527
-				echo '
557
+			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
558
+							echo '
528 559
 			<div class="floatright">
529 560
 				<ul class="quickbuttons">';
561
+			}
530 562
 
531 563
 			// If they *can* reply?
532
-			if ($post['can_reply'])
533
-				echo '
564
+			if ($post['can_reply']) {
565
+							echo '
534 566
 					<li><a href="', $scripturl, '?action=post;topic=', $post['topic'], '.', $post['start'], '"><span class="generic_icons reply_button"></span>', $txt['reply'], '</a></li>';
567
+			}
535 568
 
536 569
 			// If they *can* quote?
537
-			if ($post['can_quote'])
538
-				echo '
570
+			if ($post['can_quote']) {
571
+							echo '
539 572
 					<li><a href="', $scripturl . '?action=post;topic=', $post['topic'], '.', $post['start'], ';quote=', $post['id'], '"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>';
573
+			}
540 574
 
541 575
 			// How about... even... remove it entirely?!
542
-			if ($post['can_delete'])
543
-				echo '
576
+			if ($post['can_delete']) {
577
+							echo '
544 578
 					<li><a href="', $scripturl, '?action=deletemsg;msg=', $post['id'], ';topic=', $post['topic'], ';profile;u=', $context['member']['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['remove_message'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove'], '</a></li>';
579
+			}
545 580
 
546
-			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete'])
547
-				echo '
581
+			if ($post['can_reply'] || $post['can_quote'] || $post['can_delete']) {
582
+							echo '
548 583
 				</ul>
549 584
 			</div><!-- .floatright -->';
585
+			}
550 586
 
551 587
 			echo '
552 588
 		</div><!-- $post[css_class] -->';
553 589
 		}
590
+	} else {
591
+			template_show_list('attachments');
554 592
 	}
555
-	else
556
-		template_show_list('attachments');
557 593
 
558 594
 	// No posts? Just end with a informative message.
559
-	if ((isset($context['attachments']) && empty($context['attachments'])) || (!isset($context['attachments']) && empty($context['posts'])))
560
-		echo '
595
+	if ((isset($context['attachments']) && empty($context['attachments'])) || (!isset($context['attachments']) && empty($context['posts']))) {
596
+			echo '
561 597
 		<div class="windowbg2">
562 598
 			', isset($context['attachments']) ? $txt['show_attachments_none'] : ($context['is_topics'] ? $txt['show_topics_none'] : $txt['show_posts_none']), '
563 599
 		</div>';
600
+	}
564 601
 
565 602
 	// Show more page numbers.
566
-	if (!empty($context['page_index']))
567
-		echo '
603
+	if (!empty($context['page_index'])) {
604
+			echo '
568 605
 		<div class="pagesection">
569 606
 			<div class="pagelinks">', $context['page_index'], '</div>
570 607
 		</div>';
571
-}
608
+	}
609
+	}
572 610
 
573 611
 /**
574 612
  * Template for showing alerts within the alerts popup
@@ -578,11 +616,12 @@  discard block
 block discarded – undo
578 616
 	global $context, $txt, $scripturl;
579 617
 
580 618
 	// Do we have an update message?
581
-	if (!empty($context['update_message']))
582
-		echo '
619
+	if (!empty($context['update_message'])) {
620
+			echo '
583 621
 		<div class="infobox">
584 622
 			', $context['update_message'], '.
585 623
 		</div>';
624
+	}
586 625
 
587 626
 	echo '
588 627
 		<div class="cat_bar">
@@ -591,13 +630,12 @@  discard block
 block discarded – undo
591 630
 			</h3>
592 631
 		</div>';
593 632
 
594
-	if (empty($context['alerts']))
595
-		echo '
633
+	if (empty($context['alerts'])) {
634
+			echo '
596 635
 		<div class="information">
597 636
 			', $txt['alerts_none'], '
598 637
 		</div>';
599
-
600
-	else
638
+	} else
601 639
 	{
602 640
 		// Start the form.
603 641
 		echo '
@@ -659,12 +697,12 @@  discard block
 block discarded – undo
659 697
 		</div>' : '';
660 698
 
661 699
 	// No drafts? Just show an informative message.
662
-	if (empty($context['drafts']))
663
-		echo '
700
+	if (empty($context['drafts'])) {
701
+			echo '
664 702
 		<div class="windowbg2 centertext">
665 703
 			', $txt['draft_none'], '
666 704
 		</div>';
667
-	else
705
+	} else
668 706
 	{
669 707
 		// For every draft to be displayed, give it its own div, and show the important details of the draft.
670 708
 		foreach ($context['drafts'] as $draft)
@@ -676,13 +714,15 @@  discard block
 block discarded – undo
676 714
 				<h5>
677 715
 					<strong><a href="', $scripturl, '?board=', $draft['board']['id'], '.0">', $draft['board']['name'], '</a> / ', $draft['topic']['link'], '</strong> &nbsp; &nbsp;';
678 716
 
679
-			if (!empty($draft['sticky']))
680
-				echo '
717
+			if (!empty($draft['sticky'])) {
718
+							echo '
681 719
 					<span class="generic_icons sticky" title="', $txt['sticky_topic'], '"></span>';
720
+			}
682 721
 
683
-			if (!empty($draft['locked']))
684
-				echo '
722
+			if (!empty($draft['locked'])) {
723
+							echo '
685 724
 					<span class="generic_icons lock" title="', $txt['locked_topic'], '"></span>';
725
+			}
686 726
 
687 727
 			echo '
688 728
 				</h5>
@@ -715,13 +755,13 @@  discard block
 block discarded – undo
715 755
 {
716 756
 	global $context, $scripturl, $txt;
717 757
 
718
-	if (!empty($context['saved_successful']))
719
-		echo '
758
+	if (!empty($context['saved_successful'])) {
759
+			echo '
720 760
 	<div class="infobox">', $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $context['member']['name']), '</div>';
721
-
722
-	elseif (!empty($context['saved_failed']))
723
-		echo '
761
+	} elseif (!empty($context['saved_failed'])) {
762
+			echo '
724 763
 	<div class="errorbox">', $context['saved_failed'], '</div>';
764
+	}
725 765
 
726 766
 	echo '
727 767
 	<div id="edit_buddies">
@@ -736,14 +776,16 @@  discard block
 block discarded – undo
736 776
 					<th scope="col" class="quarter_table">', $txt['name'], '</th>
737 777
 					<th scope="col">', $txt['status'], '</th>';
738 778
 
739
-	if (allowedTo('moderate_forum'))
740
-		echo '
779
+	if (allowedTo('moderate_forum')) {
780
+			echo '
741 781
 					<th scope="col">', $txt['email'], '</th>';
782
+	}
742 783
 
743
-	if (!empty($context['custom_pf']))
744
-		foreach ($context['custom_pf'] as $column)
784
+	if (!empty($context['custom_pf'])) {
785
+			foreach ($context['custom_pf'] as $column)
745 786
 				echo '
746 787
 					<th scope="col">', $column['label'], '</th>';
788
+	}
747 789
 
748 790
 	echo '
749 791
 					<th scope="col">', $txt['remove'], '</th>
@@ -752,13 +794,14 @@  discard block
 block discarded – undo
752 794
 			<tbody>';
753 795
 
754 796
 	// If they don't have any buddies don't list them!
755
-	if (empty($context['buddies']))
756
-		echo '
797
+	if (empty($context['buddies'])) {
798
+			echo '
757 799
 				<tr class="windowbg">
758 800
 					<td colspan="', allowedTo('moderate_forum') ? '10' : '9', '">
759 801
 						<strong>', $txt['no_buddies'], '</strong>
760 802
 					</td>
761 803
 				</tr>';
804
+	}
762 805
 
763 806
 		// Now loop through each buddy showing info on each.
764 807
 	else
@@ -772,17 +815,19 @@  discard block
 block discarded – undo
772 815
 						<a href="', $buddy['online']['href'], '"><span class="' . ($buddy['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $buddy['online']['text'] . '"></span></a>
773 816
 					</td>';
774 817
 
775
-			if ($buddy['show_email'])
776
-				echo '
818
+			if ($buddy['show_email']) {
819
+							echo '
777 820
 					<td>
778 821
 						<a href="mailto:' . $buddy['email'] . '" rel="nofollow"><span class="generic_icons mail icon" title="' . $txt['email'] . ' ' . $buddy['name'] . '"></span></a>
779 822
 					</td>';
823
+			}
780 824
 
781 825
 			// Show the custom profile fields for this user.
782
-			if (!empty($context['custom_pf']))
783
-				foreach ($context['custom_pf'] as $key => $column)
826
+			if (!empty($context['custom_pf'])) {
827
+							foreach ($context['custom_pf'] as $key => $column)
784 828
 					echo '
785 829
 					<td class="lefttext">', $buddy['options'][$key], '</td>';
830
+			}
786 831
 
787 832
 			echo '
788 833
 					<td>
@@ -815,9 +860,10 @@  discard block
 block discarded – undo
815 860
 			</dl>
816 861
 		</div>';
817 862
 
818
-	if (!empty($context['token_check']))
819
-		echo '
863
+	if (!empty($context['token_check'])) {
864
+			echo '
820 865
 		<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
866
+	}
821 867
 
822 868
 	echo '
823 869
 		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -843,13 +889,13 @@  discard block
 block discarded – undo
843 889
 {
844 890
 	global $context, $scripturl, $txt;
845 891
 
846
-	if (!empty($context['saved_successful']))
847
-		echo '
892
+	if (!empty($context['saved_successful'])) {
893
+			echo '
848 894
 	<div class="infobox">', $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $context['member']['name']), '</div>';
849
-
850
-	elseif (!empty($context['saved_failed']))
851
-		echo '
895
+	} elseif (!empty($context['saved_failed'])) {
896
+			echo '
852 897
 	<div class="errorbox">', $context['saved_failed'], '</div>';
898
+	}
853 899
 
854 900
 	echo '
855 901
 	<div id="edit_buddies">
@@ -864,9 +910,10 @@  discard block
 block discarded – undo
864 910
 					<th scope="col" class="quarter_table">', $txt['name'], '</th>
865 911
 					<th scope="col">', $txt['status'], '</th>';
866 912
 
867
-	if (allowedTo('moderate_forum'))
868
-		echo '
913
+	if (allowedTo('moderate_forum')) {
914
+			echo '
869 915
 					<th scope="col">', $txt['email'], '</th>';
916
+	}
870 917
 
871 918
 	echo '
872 919
 					<th scope="col">', $txt['ignore_remove'], '</th>
@@ -875,13 +922,14 @@  discard block
 block discarded – undo
875 922
 			<tbody>';
876 923
 
877 924
 	// If they don't have anyone on their ignore list, don't list it!
878
-	if (empty($context['ignore_list']))
879
-		echo '
925
+	if (empty($context['ignore_list'])) {
926
+			echo '
880 927
 				<tr class="windowbg">
881 928
 					<td colspan="', allowedTo('moderate_forum') ? '4' : '3', '">
882 929
 						<strong>', $txt['no_ignore'], '</strong>
883 930
 					</td>
884 931
 				</tr>';
932
+	}
885 933
 
886 934
 	// Now loop through each buddy showing info on each.
887 935
 	foreach ($context['ignore_list'] as $member)
@@ -893,11 +941,12 @@  discard block
 block discarded – undo
893 941
 						<a href="', $member['online']['href'], '"><span class="' . ($member['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $member['online']['text'] . '"></span></a>
894 942
 					</td>';
895 943
 
896
-		if ($member['show_email'])
897
-			echo '
944
+		if ($member['show_email']) {
945
+					echo '
898 946
 					<td>
899 947
 						<a href="mailto:' . $member['email'] . '" rel="nofollow"><span class="generic_icons mail icon" title="' . $txt['email'] . ' ' . $member['name'] . '"></span></a>
900 948
 					</td>';
949
+		}
901 950
 		echo '
902 951
 					<td>
903 952
 						<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons delete" title="', $txt['ignore_remove'], '"></span></a>
@@ -927,9 +976,10 @@  discard block
 block discarded – undo
927 976
 			</dl>
928 977
 		</div>';
929 978
 
930
-	if (!empty($context['token_check']))
931
-		echo '
979
+	if (!empty($context['token_check'])) {
980
+			echo '
932 981
 		<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
982
+	}
933 983
 
934 984
 	echo '
935 985
 		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -975,9 +1025,10 @@  discard block
 block discarded – undo
975 1025
 					<a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip'], ';u=', $context['member']['id'], '">', $context['last_ip'], '</a>';
976 1026
 
977 1027
 	// Second address detected?
978
-	if (!empty($context['last_ip2']))
979
-		echo '
1028
+	if (!empty($context['last_ip2'])) {
1029
+			echo '
980 1030
 					, <a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip2'], ';u=', $context['member']['id'], '">', $context['last_ip2'], '</a>';
1031
+	}
981 1032
 
982 1033
 	echo '
983 1034
 				</dd>';
@@ -1043,9 +1094,10 @@  discard block
 block discarded – undo
1043 1094
 		</div>
1044 1095
 		<div class="windowbg2 noup">';
1045 1096
 
1046
-		foreach ($context['whois_servers'] as $server)
1047
-			echo '
1097
+		foreach ($context['whois_servers'] as $server) {
1098
+					echo '
1048 1099
 			<a href="', $server['url'], '" target="_blank" rel="noopener"', isset($context['auto_whois_server']) && $context['auto_whois_server']['name'] == $server['name'] ? ' style="font-weight: bold;"' : '', '>', $server['name'], '</a><br>';
1100
+		}
1049 1101
 		echo '
1050 1102
 		</div>
1051 1103
 		<br>';
@@ -1057,13 +1109,12 @@  discard block
 block discarded – undo
1057 1109
 			<h3 class="catbg">', $txt['members_from_ip'], ' ', $context['ip'], '</h3>
1058 1110
 		</div>';
1059 1111
 
1060
-	if (empty($context['ips']))
1061
-		echo '
1112
+	if (empty($context['ips'])) {
1113
+			echo '
1062 1114
 		<p class="windowbg2 description">
1063 1115
 			<em>', $txt['no_members_from_ip'], '</em>
1064 1116
 		</p>';
1065
-
1066
-	else
1117
+	} else
1067 1118
 	{
1068 1119
 		echo '
1069 1120
 		<table class="table_grid">
@@ -1076,12 +1127,13 @@  discard block
 block discarded – undo
1076 1127
 			<tbody>';
1077 1128
 
1078 1129
 		// Loop through each of the members and display them.
1079
-		foreach ($context['ips'] as $ip => $memberlist)
1080
-			echo '
1130
+		foreach ($context['ips'] as $ip => $memberlist) {
1131
+					echo '
1081 1132
 				<tr class="windowbg">
1082 1133
 					<td><a href="', $context['base_url'], ';searchip=', $ip, '">', $ip, '</a></td>
1083 1134
 					<td>', implode(', ', $memberlist), '</td>
1084 1135
 				</tr>';
1136
+		}
1085 1137
 
1086 1138
 		echo '
1087 1139
 			</tbody>
@@ -1123,11 +1175,10 @@  discard block
 block discarded – undo
1123 1175
 			</h3>
1124 1176
 		</div>';
1125 1177
 
1126
-	if ($context['member']['has_all_permissions'])
1127
-		echo '
1178
+	if ($context['member']['has_all_permissions']) {
1179
+			echo '
1128 1180
 		<div class="information">', $txt['showPermissions_all'], '</div>';
1129
-
1130
-	else
1181
+	} else
1131 1182
 	{
1132 1183
 		echo '
1133 1184
 		<div class="information">',$txt['showPermissions_help'], '</div>
@@ -1142,9 +1193,10 @@  discard block
 block discarded – undo
1142 1193
 			<div class="windowbg smalltext">
1143 1194
 				', $txt['showPermissions_restricted_boards_desc'], ':<br>';
1144 1195
 
1145
-			foreach ($context['no_access_boards'] as $no_access_board)
1146
-				echo '
1196
+			foreach ($context['no_access_boards'] as $no_access_board) {
1197
+							echo '
1147 1198
 				<a href="', $scripturl, '?board=', $no_access_board['id'], '.0">', $no_access_board['name'], '</a>', $no_access_board['is_last'] ? '' : ', ';
1199
+			}
1148 1200
 			echo '
1149 1201
 			</div>';
1150 1202
 		}
@@ -1176,12 +1228,13 @@  discard block
 block discarded – undo
1176 1228
 							</td>
1177 1229
 							<td class="smalltext">';
1178 1230
 
1179
-				if ($permission['is_denied'])
1180
-					echo '
1231
+				if ($permission['is_denied']) {
1232
+									echo '
1181 1233
 								<span class="alert">', $txt['showPermissions_denied'], ': ', implode(', ', $permission['groups']['denied']), '</span>';
1182
-				else
1183
-					echo '
1234
+				} else {
1235
+									echo '
1184 1236
 								', $txt['showPermissions_given'], ': ', implode(', ', $permission['groups']['allowed']);
1237
+				}
1185 1238
 
1186 1239
 				echo '
1187 1240
 							</td>
@@ -1192,10 +1245,10 @@  discard block
 block discarded – undo
1192 1245
 				</table>
1193 1246
 			</div><!-- .tborder -->
1194 1247
 			<br>';
1195
-		}
1196
-		else
1197
-			echo '
1248
+		} else {
1249
+					echo '
1198 1250
 			<p class="windowbg2">', $txt['showPermissions_none_general'], '</p>';
1251
+		}
1199 1252
 
1200 1253
 		// Board permission section.
1201 1254
 		echo '
@@ -1206,14 +1259,16 @@  discard block
 block discarded – undo
1206 1259
 						<select name="board" onchange="if (this.options[this.selectedIndex].value) this.form.submit();">
1207 1260
 							<option value="0"', $context['board'] == 0 ? ' selected' : '', '>', $txt['showPermissions_global'], '</option>';
1208 1261
 
1209
-		if (!empty($context['boards']))
1210
-			echo '
1262
+		if (!empty($context['boards'])) {
1263
+					echo '
1211 1264
 							<option value="" disabled>---------------------------</option>';
1265
+		}
1212 1266
 
1213 1267
 		// Fill the box with any local permission boards.
1214
-		foreach ($context['boards'] as $board)
1215
-			echo '
1268
+		foreach ($context['boards'] as $board) {
1269
+					echo '
1216 1270
 							<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['name'], ' (', $board['profile_name'], ')</option>';
1271
+		}
1217 1272
 
1218 1273
 		echo '
1219 1274
 						</select>
@@ -1242,13 +1297,13 @@  discard block
 block discarded – undo
1242 1297
 						</td>
1243 1298
 						<td class="smalltext">';
1244 1299
 
1245
-				if ($permission['is_denied'])
1246
-					echo '
1300
+				if ($permission['is_denied']) {
1301
+									echo '
1247 1302
 							<span class="alert">', $txt['showPermissions_denied'], ': ', implode(', ', $permission['groups']['denied']), '</span>';
1248
-
1249
-				else
1250
-					echo '
1303
+				} else {
1304
+									echo '
1251 1305
 							', $txt['showPermissions_given'], ': ', implode(', ', $permission['groups']['allowed']);
1306
+				}
1252 1307
 
1253 1308
 				echo '
1254 1309
 						</td>
@@ -1257,10 +1312,10 @@  discard block
 block discarded – undo
1257 1312
 			echo '
1258 1313
 				</tbody>
1259 1314
 			</table>';
1260
-		}
1261
-		else
1262
-			echo '
1315
+		} else {
1316
+					echo '
1263 1317
 			<p class="windowbg2">', $txt['showPermissions_none_board'], '</p>';
1318
+		}
1264 1319
 	echo '
1265 1320
 		</div><!-- #permissions -->';
1266 1321
 	}
@@ -1301,9 +1356,10 @@  discard block
 block discarded – undo
1301 1356
 			</div>';
1302 1357
 
1303 1358
 	// If they haven't post at all, don't draw the graph.
1304
-	if (empty($context['posts_by_time']))
1305
-		echo '
1359
+	if (empty($context['posts_by_time'])) {
1360
+			echo '
1306 1361
 			<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1362
+	}
1307 1363
 
1308 1364
 	// Otherwise do!
1309 1365
 	else
@@ -1312,8 +1368,8 @@  discard block
 block discarded – undo
1312 1368
 			<ul class="activity_stats flow_hidden">';
1313 1369
 
1314 1370
 		// The labels.
1315
-		foreach ($context['posts_by_time'] as $time_of_day)
1316
-			echo '
1371
+		foreach ($context['posts_by_time'] as $time_of_day) {
1372
+					echo '
1317 1373
 				<li', $time_of_day['is_last'] ? ' class="last"' : '', '>
1318 1374
 					<div class="bar" style="padding-top: ', ((int) (100 - $time_of_day['relative_percent'])), 'px;" title="', sprintf($txt['statPanel_activityTime_posts'], $time_of_day['posts'], $time_of_day['posts_percent']), '">
1319 1375
 						<div style="height: ', (int) $time_of_day['relative_percent'], 'px;">
@@ -1322,6 +1378,7 @@  discard block
 block discarded – undo
1322 1378
 					</div>
1323 1379
 					<span class="stats_hour">', $time_of_day['hour_format'], '</span>
1324 1380
 				</li>';
1381
+		}
1325 1382
 
1326 1383
 		echo '
1327 1384
 			</ul>';
@@ -1340,11 +1397,10 @@  discard block
 block discarded – undo
1340 1397
 					</h3>
1341 1398
 				</div>';
1342 1399
 
1343
-	if (empty($context['popular_boards']))
1344
-		echo '
1400
+	if (empty($context['popular_boards'])) {
1401
+			echo '
1345 1402
 				<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1346
-
1347
-	else
1403
+	} else
1348 1404
 	{
1349 1405
 		echo '
1350 1406
 				<dl class="stats">';
@@ -1374,10 +1430,10 @@  discard block
 block discarded – undo
1374 1430
 					</h3>
1375 1431
 				</div>';
1376 1432
 
1377
-	if (empty($context['board_activity']))
1378
-		echo '
1433
+	if (empty($context['board_activity'])) {
1434
+			echo '
1379 1435
 				<p class="centertext padding">', $txt['statPanel_noPosts'], '</p>';
1380
-	else
1436
+	} else
1381 1437
 	{
1382 1438
 		echo '
1383 1439
 				<dl class="stats">';
@@ -1428,90 +1484,97 @@  discard block
 block discarded – undo
1428 1484
 				<h3 class="catbg profile_hd">';
1429 1485
 
1430 1486
 		// Don't say "Profile" if this isn't the profile...
1431
-		if (!empty($context['profile_header_text']))
1432
-			echo '
1487
+		if (!empty($context['profile_header_text'])) {
1488
+					echo '
1433 1489
 					', $context['profile_header_text'];
1434
-		else
1435
-			echo '
1490
+		} else {
1491
+					echo '
1436 1492
 					', $txt['profile'];
1493
+		}
1437 1494
 
1438 1495
 		echo '
1439 1496
 				</h3>
1440 1497
 			</div>';
1441 1498
 
1442 1499
 	// Have we some description?
1443
-	if ($context['page_desc'])
1444
-		echo '
1500
+	if ($context['page_desc']) {
1501
+			echo '
1445 1502
 			<p class="information">', $context['page_desc'], '</p>';
1503
+	}
1446 1504
 
1447 1505
 	echo '
1448 1506
 			<div class="roundframe">';
1449 1507
 
1450 1508
 	// Any bits at the start?
1451
-	if (!empty($context['profile_prehtml']))
1452
-		echo '
1509
+	if (!empty($context['profile_prehtml'])) {
1510
+			echo '
1453 1511
 				<div>', $context['profile_prehtml'], '</div>';
1512
+	}
1454 1513
 
1455
-	if (!empty($context['profile_fields']))
1456
-		echo '
1514
+	if (!empty($context['profile_fields'])) {
1515
+			echo '
1457 1516
 				<dl class="settings">';
1517
+	}
1458 1518
 
1459 1519
 	// Start the big old loop 'of love.
1460 1520
 	$lastItem = 'hr';
1461 1521
 	foreach ($context['profile_fields'] as $key => $field)
1462 1522
 	{
1463 1523
 		// We add a little hack to be sure we never get more than one hr in a row!
1464
-		if ($lastItem == 'hr' && $field['type'] == 'hr')
1465
-			continue;
1524
+		if ($lastItem == 'hr' && $field['type'] == 'hr') {
1525
+					continue;
1526
+		}
1466 1527
 
1467 1528
 		$lastItem = $field['type'];
1468
-		if ($field['type'] == 'hr')
1469
-			echo '
1529
+		if ($field['type'] == 'hr') {
1530
+					echo '
1470 1531
 				</dl>
1471 1532
 				<hr>
1472 1533
 				<dl class="settings">';
1473
-
1474
-		elseif ($field['type'] == 'callback')
1534
+		} elseif ($field['type'] == 'callback')
1475 1535
 		{
1476 1536
 			if (isset($field['callback_func']) && function_exists('template_profile_' . $field['callback_func']))
1477 1537
 			{
1478 1538
 				$callback_func = 'template_profile_' . $field['callback_func'];
1479 1539
 				$callback_func();
1480 1540
 			}
1481
-		}
1482
-		else
1541
+		} else
1483 1542
 		{
1484 1543
 			echo '
1485 1544
 					<dt>
1486 1545
 						<strong', !empty($field['is_error']) ? ' class="error"' : '', '>', $field['type'] !== 'label' ? '<label for="' . $key . '">' : '', $field['label'], $field['type'] !== 'label' ? '</label>' : '', '</strong>';
1487 1546
 
1488 1547
 			// Does it have any subtext to show?
1489
-			if (!empty($field['subtext']))
1490
-				echo '
1548
+			if (!empty($field['subtext'])) {
1549
+							echo '
1491 1550
 						<br>
1492 1551
 						<span class="smalltext">', $field['subtext'], '</span>';
1552
+			}
1493 1553
 
1494 1554
 			echo '
1495 1555
 					</dt>
1496 1556
 					<dd>';
1497 1557
 
1498 1558
 			// Want to put something infront of the box?
1499
-			if (!empty($field['preinput']))
1500
-				echo '
1559
+			if (!empty($field['preinput'])) {
1560
+							echo '
1501 1561
 						', $field['preinput'];
1562
+			}
1502 1563
 
1503 1564
 			// What type of data are we showing?
1504
-			if ($field['type'] == 'label')
1505
-				echo '
1565
+			if ($field['type'] == 'label') {
1566
+							echo '
1506 1567
 						', $field['value'];
1568
+			}
1507 1569
 
1508 1570
 			// Maybe it's a text box - very likely!
1509 1571
 			elseif (in_array($field['type'], array('int', 'float', 'text', 'password', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'number', 'time', 'url')))
1510 1572
 			{
1511
-				if ($field['type'] == 'int' || $field['type'] == 'float')
1512
-					$type = 'number';
1513
-				else
1514
-					$type = $field['type'];
1573
+				if ($field['type'] == 'int' || $field['type'] == 'float') {
1574
+									$type = 'number';
1575
+				} else {
1576
+									$type = $field['type'];
1577
+				}
1515 1578
 				$step = $field['type'] == 'float' ? ' step="0.1"' : '';
1516 1579
 
1517 1580
 
@@ -1519,10 +1582,11 @@  discard block
 block discarded – undo
1519 1582
 						<input type="', $type, '" name="', $key, '" id="', $key, '" size="', empty($field['size']) ? 30 : $field['size'], '" value="', $field['value'], '" ', $field['input_attr'], ' ', $step, '>';
1520 1583
 			}
1521 1584
 			// You "checking" me out? ;)
1522
-			elseif ($field['type'] == 'check')
1523
-				echo '
1585
+			elseif ($field['type'] == 'check') {
1586
+							echo '
1524 1587
 						<input type="hidden" name="', $key, '" value="0">
1525 1588
 						<input type="checkbox" name="', $key, '" id="', $key, '"', !empty($field['value']) ? ' checked' : '', ' value="1" ', $field['input_attr'], '>';
1589
+			}
1526 1590
 
1527 1591
 			// Always fun - select boxes!
1528 1592
 			elseif ($field['type'] == 'select')
@@ -1533,14 +1597,16 @@  discard block
 block discarded – undo
1533 1597
 				if (isset($field['options']))
1534 1598
 				{
1535 1599
 					// Is this some code to generate the options?
1536
-					if (!is_array($field['options']))
1537
-						$field['options'] = $field['options']();
1600
+					if (!is_array($field['options'])) {
1601
+											$field['options'] = $field['options']();
1602
+					}
1538 1603
 
1539 1604
 					// Assuming we now have some!
1540
-					if (is_array($field['options']))
1541
-						foreach ($field['options'] as $value => $name)
1605
+					if (is_array($field['options'])) {
1606
+											foreach ($field['options'] as $value => $name)
1542 1607
 							echo '
1543 1608
 							<option value="', $value, '"', $value == $field['value'] ? ' selected' : '', '>', $name, '</option>';
1609
+					}
1544 1610
 				}
1545 1611
 
1546 1612
 				echo '
@@ -1548,31 +1614,34 @@  discard block
 block discarded – undo
1548 1614
 			}
1549 1615
 
1550 1616
 			// Something to end with?
1551
-			if (!empty($field['postinput']))
1552
-				echo '
1617
+			if (!empty($field['postinput'])) {
1618
+							echo '
1553 1619
 						', $field['postinput'];
1620
+			}
1554 1621
 
1555 1622
 			echo '
1556 1623
 					</dd>';
1557 1624
 		}
1558 1625
 	}
1559 1626
 
1560
-	if (!empty($context['profile_fields']))
1561
-		echo '
1627
+	if (!empty($context['profile_fields'])) {
1628
+			echo '
1562 1629
 				</dl>';
1630
+	}
1563 1631
 
1564 1632
 	// Are there any custom profile fields - if so print them!
1565 1633
 	if (!empty($context['custom_fields']))
1566 1634
 	{
1567
-		if ($lastItem != 'hr')
1568
-			echo '
1635
+		if ($lastItem != 'hr') {
1636
+					echo '
1569 1637
 				<hr>';
1638
+		}
1570 1639
 
1571 1640
 		echo '
1572 1641
 				<dl class="settings">';
1573 1642
 
1574
-		foreach ($context['custom_fields'] as $field)
1575
-			echo '
1643
+		foreach ($context['custom_fields'] as $field) {
1644
+					echo '
1576 1645
 					<dt>
1577 1646
 						<strong>', $field['name'], ': </strong><br>
1578 1647
 						<span class="smalltext">', $field['desc'], '</span>
@@ -1580,6 +1649,7 @@  discard block
 block discarded – undo
1580 1649
 					<dd>
1581 1650
 						', $field['input_html'], '
1582 1651
 					</dd>';
1652
+		}
1583 1653
 
1584 1654
 		echo '
1585 1655
 				</dl>';
@@ -1587,13 +1657,14 @@  discard block
 block discarded – undo
1587 1657
 	}
1588 1658
 
1589 1659
 	// Any closing HTML?
1590
-	if (!empty($context['profile_posthtml']))
1591
-		echo '
1660
+	if (!empty($context['profile_posthtml'])) {
1661
+			echo '
1592 1662
 				<div>', $context['profile_posthtml'], '</div>';
1663
+	}
1593 1664
 
1594 1665
 	// Only show the password box if it's actually needed.
1595
-	if ($context['require_password'])
1596
-		echo '
1666
+	if ($context['require_password']) {
1667
+			echo '
1597 1668
 				<dl class="settings">
1598 1669
 					<dt>
1599 1670
 						<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '><label for="oldpasswrd">', $txt['current_password'], ': </label></strong><br>
@@ -1603,18 +1674,21 @@  discard block
 block discarded – undo
1603 1674
 						<input type="password" name="oldpasswrd" id="oldpasswrd" size="20">
1604 1675
 					</dd>
1605 1676
 				</dl>';
1677
+	}
1606 1678
 
1607 1679
 	// The button shouldn't say "Change profile" unless we're changing the profile...
1608
-	if (!empty($context['submit_button_text']))
1609
-		echo '
1680
+	if (!empty($context['submit_button_text'])) {
1681
+			echo '
1610 1682
 				<input type="submit" name="save" value="', $context['submit_button_text'], '" class="button floatright">';
1611
-	else
1612
-		echo '
1683
+	} else {
1684
+			echo '
1613 1685
 				<input type="submit" name="save" value="', $txt['change_profile'], '" class="button floatright">';
1686
+	}
1614 1687
 
1615
-	if (!empty($context['token_check']))
1616
-		echo '
1688
+	if (!empty($context['token_check'])) {
1689
+			echo '
1617 1690
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
1691
+	}
1618 1692
 
1619 1693
 	echo '
1620 1694
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -1624,10 +1698,11 @@  discard block
 block discarded – undo
1624 1698
 		</form>';
1625 1699
 
1626 1700
 	// Any final spellchecking stuff?
1627
-	if (!empty($context['show_spellchecking']))
1628
-		echo '
1701
+	if (!empty($context['show_spellchecking'])) {
1702
+			echo '
1629 1703
 		<form name="spell_form" id="spell_form" method="post" accept-charset="', $context['character_set'], '" target="spellWindow" action="', $scripturl, '?action=spellcheck"><input type="hidden" name="spellstring" value=""></form>';
1630
-}
1704
+	}
1705
+	}
1631 1706
 
1632 1707
 /**
1633 1708
  * Personal Message settings.
@@ -1664,10 +1739,11 @@  discard block
 block discarded – undo
1664 1739
 						<select name="pm_receive_from" id="pm_receive_from">
1665 1740
 							<option value="0"', empty($context['receive_from']) || (empty($modSettings['enable_buddylist']) && $context['receive_from'] < 3) ? ' selected' : '', '>', $txt['pm_receive_from_everyone'], '</option>';
1666 1741
 
1667
-	if (!empty($modSettings['enable_buddylist']))
1668
-		echo '
1742
+	if (!empty($modSettings['enable_buddylist'])) {
1743
+			echo '
1669 1744
 							<option value="1"', !empty($context['receive_from']) && $context['receive_from'] == 1 ? ' selected' : '', '>', $txt['pm_receive_from_ignore'], '</option>
1670 1745
 							<option value="2"', !empty($context['receive_from']) && $context['receive_from'] == 2 ? ' selected' : '', '>', $txt['pm_receive_from_buddies'], '</option>';
1746
+	}
1671 1747
 
1672 1748
 	echo '
1673 1749
 							<option value="3"', !empty($context['receive_from']) && $context['receive_from'] > 2 ? ' selected' : '', '>', $txt['pm_receive_from_admins'], '</option>
@@ -1710,11 +1786,12 @@  discard block
 block discarded – undo
1710 1786
 		if (empty($setting) || !is_array($setting))
1711 1787
 		{
1712 1788
 			// Insert a separator (unless this is the first item in the list)
1713
-			if ($i !== $first_option_key)
1714
-				echo '
1789
+			if ($i !== $first_option_key) {
1790
+							echo '
1715 1791
 				</dl>
1716 1792
 				<hr>
1717 1793
 				<dl class="settings">';
1794
+			}
1718 1795
 
1719 1796
 			// Should we give a name to this section?
1720 1797
 			if (is_string($setting) && !empty($setting))
@@ -1723,69 +1800,67 @@  discard block
 block discarded – undo
1723 1800
 				echo '
1724 1801
 					<dt><strong>' . $setting . '</strong></dt>
1725 1802
 					<dd></dd>';
1803
+			} else {
1804
+							$titled_section = false;
1726 1805
 			}
1727
-			else
1728
-				$titled_section = false;
1729 1806
 
1730 1807
 			continue;
1731 1808
 		}
1732 1809
 
1733 1810
 		// Is this disabled?
1734
-		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled']))
1735
-			continue;
1736
-
1737
-		elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
1738
-			continue;
1739
-
1740
-		elseif ($setting['id'] == 'show_no_censored' && empty($modSettings['allow_no_censored']))
1741
-			continue;
1742
-
1743
-		elseif ($setting['id'] == 'posts_apply_ignore_list' && empty($modSettings['enable_buddylist']))
1744
-			continue;
1745
-
1746
-		elseif ($setting['id'] == 'wysiwyg_default' && !empty($modSettings['disable_wysiwyg']))
1747
-			continue;
1748
-
1749
-		elseif ($setting['id'] == 'drafts_autosave_enabled' && (empty($modSettings['drafts_autosave_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled']))))
1750
-			continue;
1751
-
1752
-		elseif ($setting['id'] == 'drafts_show_saved_enabled' && (empty($modSettings['drafts_show_saved_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled']))))
1753
-			continue;
1811
+		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled'])) {
1812
+					continue;
1813
+		} elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage'])) {
1814
+					continue;
1815
+		} elseif ($setting['id'] == 'show_no_censored' && empty($modSettings['allow_no_censored'])) {
1816
+					continue;
1817
+		} elseif ($setting['id'] == 'posts_apply_ignore_list' && empty($modSettings['enable_buddylist'])) {
1818
+					continue;
1819
+		} elseif ($setting['id'] == 'wysiwyg_default' && !empty($modSettings['disable_wysiwyg'])) {
1820
+					continue;
1821
+		} elseif ($setting['id'] == 'drafts_autosave_enabled' && (empty($modSettings['drafts_autosave_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled'])))) {
1822
+					continue;
1823
+		} elseif ($setting['id'] == 'drafts_show_saved_enabled' && (empty($modSettings['drafts_show_saved_enabled']) || (empty($modSettings['drafts_post_enabled']) && empty($modSettings['drafts_pm_enabled'])))) {
1824
+					continue;
1825
+		}
1754 1826
 
1755 1827
 		// Some of these may not be set...  Set to defaults here
1756 1828
 		$opts = array('topics_per_page', 'messages_per_page', 'display_quick_mod');
1757
-		if (in_array($setting['id'], $opts) && !isset($context['member']['options'][$setting['id']]))
1758
-			$context['member']['options'][$setting['id']] = 0;
1759
-
1760
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
1761
-			$setting['type'] = 'checkbox';
1762
-
1763
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
1764
-			$setting['type'] = 'number';
1829
+		if (in_array($setting['id'], $opts) && !isset($context['member']['options'][$setting['id']])) {
1830
+					$context['member']['options'][$setting['id']] = 0;
1831
+		}
1765 1832
 
1766
-		elseif ($setting['type'] == 'string')
1767
-			$setting['type'] = 'text';
1833
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
1834
+					$setting['type'] = 'checkbox';
1835
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
1836
+					$setting['type'] = 'number';
1837
+		} elseif ($setting['type'] == 'string') {
1838
+					$setting['type'] = 'text';
1839
+		}
1768 1840
 
1769
-		if (isset($setting['options']))
1770
-			$setting['type'] = 'list';
1841
+		if (isset($setting['options'])) {
1842
+					$setting['type'] = 'list';
1843
+		}
1771 1844
 
1772 1845
 		echo '
1773 1846
 					<dt>
1774 1847
 						<label for="', $setting['id'], '">', !$titled_section ? '<strong>' : '', $setting['label'], !$titled_section ? '</strong>' : '', '</label>';
1775 1848
 
1776
-		if (isset($setting['description']))
1777
-			echo '
1849
+		if (isset($setting['description'])) {
1850
+					echo '
1778 1851
 						<br>
1779 1852
 						<span class="smalltext">', $setting['description'], '</span>';
1853
+		}
1780 1854
 		echo '
1781 1855
 					</dt>
1782 1856
 					<dd>';
1783 1857
 
1784 1858
 		// Display checkbox options
1785
-		if ($setting['type'] == 'checkbox')
1786
-			echo '
1859
+		if ($setting['type'] == 'checkbox') {
1860
+					echo '
1787 1861
 						<input type="hidden" name="default_options[' . $setting['id'] . ']" value="0">
1788 1862
 						<input type="checkbox" name="default_options[', $setting['id'], ']" id="', $setting['id'], '"', !empty($context['member']['options'][$setting['id']]) ? ' checked' : '', ' value="1">';
1863
+		}
1789 1864
 
1790 1865
 		// How about selection lists, we all love them
1791 1866
 		elseif ($setting['type'] == 'list')
@@ -1793,9 +1868,10 @@  discard block
 block discarded – undo
1793 1868
 			echo '
1794 1869
 						<select name="default_options[', $setting['id'], ']" id="', $setting['id'], '"', '>';
1795 1870
 
1796
-			foreach ($setting['options'] as $value => $label)
1797
-				echo '
1871
+			foreach ($setting['options'] as $value => $label) {
1872
+							echo '
1798 1873
 							<option value="', $value, '"', $value == $context['member']['options'][$setting['id']] ? ' selected' : '', '>', $label, '</option>';
1874
+			}
1799 1875
 
1800 1876
 			echo '
1801 1877
 						</select>';
@@ -1811,14 +1887,13 @@  discard block
 block discarded – undo
1811 1887
 
1812 1888
 				echo '
1813 1889
 						<input type="number"', $min . $max . $step;
1814
-			}
1815
-			elseif (isset($setting['type']) && $setting['type'] == 'url')
1816
-				echo'
1890
+			} elseif (isset($setting['type']) && $setting['type'] == 'url') {
1891
+							echo'
1817 1892
 						<input type="url"';
1818
-
1819
-			else
1820
-				echo '
1893
+			} else {
1894
+							echo '
1821 1895
 						<input type="text"';
1896
+			}
1822 1897
 
1823 1898
 			echo ' name="default_options[', $setting['id'], ']" id="', $setting['id'], '" value="', isset($context['member']['options'][$setting['id']]) ? $context['member']['options'][$setting['id']] : $setting['value'], '"', $setting['type'] == 'number' ? ' size="5"' : '', '>';
1824 1899
 		}
@@ -1855,8 +1930,8 @@  discard block
 block discarded – undo
1855 1930
 				<dl class="settings">';
1856 1931
 
1857 1932
 	// Allow notification on announcements to be disabled?
1858
-	if (!empty($modSettings['allow_disableAnnounce']))
1859
-		echo '
1933
+	if (!empty($modSettings['allow_disableAnnounce'])) {
1934
+			echo '
1860 1935
 					<dt>
1861 1936
 						<label for="notify_announcements">', $txt['notify_important_email'], '</label>
1862 1937
 					</dt>
@@ -1864,15 +1939,17 @@  discard block
 block discarded – undo
1864 1939
 						<input type="hidden" name="notify_announcements" value="0">
1865 1940
 						<input type="checkbox" id="notify_announcements" name="notify_announcements" value="1"', !empty($context['member']['notify_announcements']) ? ' checked' : '', '>
1866 1941
 					</dd>';
1942
+	}
1867 1943
 
1868
-	if (!empty($modSettings['enable_ajax_alerts']))
1869
-		echo '
1944
+	if (!empty($modSettings['enable_ajax_alerts'])) {
1945
+			echo '
1870 1946
 					<dt>
1871 1947
 						<label for="notify_send_body">', $txt['notify_alert_timeout'], '</label>
1872 1948
 					</dt>
1873 1949
 					<dd>
1874 1950
 						<input type="number" size="4" id="notify_alert_timeout" name="opt_alert_timeout" min="0" value="', $context['member']['alert_timeout'], '">
1875 1951
 					</dd>';
1952
+	}
1876 1953
 
1877 1954
 	echo '
1878 1955
 				</dl>
@@ -1904,9 +1981,10 @@  discard block
 block discarded – undo
1904 1981
 
1905 1982
 				$label = $txt['alert_opt_' . $opts[1]];
1906 1983
 				$label_pos = isset($opts['label']) ? $opts['label'] : '';
1907
-				if ($label_pos == 'before')
1908
-					echo '
1984
+				if ($label_pos == 'before') {
1985
+									echo '
1909 1986
 						<label for="opt_', $opts[1], '">', $label, '</label>';
1987
+				}
1910 1988
 
1911 1989
 				$this_value = isset($context['alert_prefs'][$opts[1]]) ? $context['alert_prefs'][$opts[1]] : 0;
1912 1990
 				switch ($opts[0])
@@ -1920,17 +1998,19 @@  discard block
 block discarded – undo
1920 1998
 						echo '
1921 1999
 						<select name="opt_', $opts[1], '" id="opt_', $opts[1], '">';
1922 2000
 
1923
-						foreach ($opts['opts'] as $k => $v)
1924
-							echo '
2001
+						foreach ($opts['opts'] as $k => $v) {
2002
+													echo '
1925 2003
 							<option value="', $k, '"', $this_value == $k ? ' selected' : '', '>', $v, '</option>';
2004
+						}
1926 2005
 						echo '
1927 2006
 						</select>';
1928 2007
 						break;
1929 2008
 				}
1930 2009
 
1931
-				if ($label_pos == 'after')
1932
-					echo '
2010
+				if ($label_pos == 'after') {
2011
+									echo '
1933 2012
 						<label for="opt_', $opts[1], '">', $label, '</label>';
2013
+				}
1934 2014
 
1935 2015
 				echo '
1936 2016
 					</td>
@@ -2047,11 +2127,12 @@  discard block
 block discarded – undo
2047 2127
 			<p class="information">', $txt['groupMembership_info'], '</p>';
2048 2128
 
2049 2129
 	// Do we have an update message?
2050
-	if (!empty($context['update_message']))
2051
-		echo '
2130
+	if (!empty($context['update_message'])) {
2131
+			echo '
2052 2132
 			<div class="infobox">
2053 2133
 				', $context['update_message'], '.
2054 2134
 			</div>';
2135
+	}
2055 2136
 
2056 2137
 	echo '
2057 2138
 			<div id="groups">';
@@ -2073,8 +2154,7 @@  discard block
 block discarded – undo
2073 2154
 						</div>
2074 2155
 					</div>
2075 2156
 				</div><!-- .groupmembership -->';
2076
-	}
2077
-	else
2157
+	} else
2078 2158
 	{
2079 2159
 		echo '
2080 2160
 				<div class="title_bar">
@@ -2086,27 +2166,30 @@  discard block
 block discarded – undo
2086 2166
 			echo '
2087 2167
 				<div class="windowbg" id="primdiv_', $group['id'], '">';
2088 2168
 
2089
-				if ($context['can_edit_primary'])
2090
-					echo '
2169
+				if ($context['can_edit_primary']) {
2170
+									echo '
2091 2171
 					<input type="radio" name="primary" id="primary_', $group['id'], '" value="', $group['id'], '"', $group['is_primary'] ? ' checked' : '', ' onclick="highlightSelected(\'primdiv_' . $group['id'] . '\');"', $group['can_be_primary'] ? '' : ' disabled', '>';
2172
+				}
2092 2173
 
2093 2174
 				echo '
2094 2175
 					<label for="primary_', $group['id'], '"><strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br><span class="smalltext">' . $group['desc'] . '</span>' : ''), '</label>';
2095 2176
 
2096 2177
 				// Can they leave their group?
2097
-				if ($group['can_leave'])
2098
-					echo '
2178
+				if ($group['can_leave']) {
2179
+									echo '
2099 2180
 					<a href="' . $scripturl . '?action=profile;save;u=' . $context['id_member'] . ';area=groupmembership;' . $context['session_var'] . '=' . $context['session_id'] . ';gid=' . $group['id'] . ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '">' . $txt['leave_group'] . '</a>';
2181
+				}
2100 2182
 
2101 2183
 				echo '
2102 2184
 				</div><!-- .windowbg -->';
2103 2185
 		}
2104 2186
 
2105
-		if ($context['can_edit_primary'])
2106
-			echo '
2187
+		if ($context['can_edit_primary']) {
2188
+					echo '
2107 2189
 				<div class="padding righttext">
2108 2190
 					<input type="submit" value="', $txt['make_primary'], '" class="button">
2109 2191
 				</div>';
2192
+		}
2110 2193
 
2111 2194
 		// Any groups they can join?
2112 2195
 		if (!empty($context['groups']['available']))
@@ -2122,17 +2205,16 @@  discard block
 block discarded – undo
2122 2205
 				<div class="windowbg">
2123 2206
 					<strong>', (empty($group['color']) ? $group['name'] : '<span style="color: ' . $group['color'] . '">' . $group['name'] . '</span>'), '</strong>', (!empty($group['desc']) ? '<br><span class="smalltext">' . $group['desc'] . '</span>' : ''), '';
2124 2207
 
2125
-				if ($group['type'] == 3)
2126
-					echo '
2208
+				if ($group['type'] == 3) {
2209
+									echo '
2127 2210
 					<a href="', $scripturl, '?action=profile;save;u=', $context['id_member'], ';area=groupmembership;', $context['session_var'], '=', $context['session_id'], ';gid=', $group['id'], ';', $context[$context['token_check'] . '_token_var'], '=', $context[$context['token_check'] . '_token'], '" class="button floatright">', $txt['join_group'], '</a>';
2128
-
2129
-				elseif ($group['type'] == 2 && $group['pending'])
2130
-					echo '
2211
+				} elseif ($group['type'] == 2 && $group['pending']) {
2212
+									echo '
2131 2213
 					<span class="floatright">', $txt['approval_pending'], '</span>';
2132
-
2133
-				elseif ($group['type'] == 2)
2134
-					echo '
2214
+				} elseif ($group['type'] == 2) {
2215
+									echo '
2135 2216
 					<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=groupmembership;request=', $group['id'], '" class="button floatright">', $txt['request_group'], '</a>';
2217
+				}
2136 2218
 
2137 2219
 				echo '
2138 2220
 				</div><!-- .windowbg -->';
@@ -2155,9 +2237,10 @@  discard block
 block discarded – undo
2155 2237
 
2156 2238
 						prevDiv.className = "windowbg";
2157 2239
 					}';
2158
-		if (isset($context['groups']['member'][$context['primary_group']]))
2159
-			echo '
2240
+		if (isset($context['groups']['member'][$context['primary_group']])) {
2241
+					echo '
2160 2242
 					highlightSelected("primdiv_' . $context['primary_group'] . '");';
2243
+		}
2161 2244
 
2162 2245
 		echo '
2163 2246
 				</script>';
@@ -2166,9 +2249,10 @@  discard block
 block discarded – undo
2166 2249
 	echo '
2167 2250
 			</div><!-- #groups -->';
2168 2251
 
2169
-	if (!empty($context['token_check']))
2170
-		echo '
2252
+	if (!empty($context['token_check'])) {
2253
+			echo '
2171 2254
 			<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2255
+	}
2172 2256
 
2173 2257
 	echo '
2174 2258
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2216,14 +2300,15 @@  discard block
 block discarded – undo
2216 2300
 
2217 2301
 		foreach ($category['boards'] as $board)
2218 2302
 		{
2219
-			if ($i == $limit)
2220
-				echo '
2303
+			if ($i == $limit) {
2304
+							echo '
2221 2305
 						</ul>
2222 2306
 					</li>
2223 2307
 				</ul>
2224 2308
 				<ul class="ignoreboards floatright">
2225 2309
 					<li class="category">
2226 2310
 						<ul>';
2311
+			}
2227 2312
 
2228 2313
 			echo '
2229 2314
 							<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
@@ -2269,10 +2354,11 @@  discard block
 block discarded – undo
2269 2354
 
2270 2355
 	// Work out the starting color.
2271 2356
 	$context['current_color'] = $context['colors'][0];
2272
-	foreach ($context['colors'] as $limit => $color)
2273
-		if ($context['member']['warning'] >= $limit)
2357
+	foreach ($context['colors'] as $limit => $color) {
2358
+			if ($context['member']['warning'] >= $limit)
2274 2359
 			$context['current_color'] = $color;
2275
-}
2360
+	}
2361
+	}
2276 2362
 
2277 2363
 // Show all warnings of a user?
2278 2364
 function template_viewWarning()
@@ -2311,14 +2397,15 @@  discard block
 block discarded – undo
2311 2397
 				</dd>';
2312 2398
 
2313 2399
 	// There's some impact of this?
2314
-	if (!empty($context['level_effects'][$context['current_level']]))
2315
-		echo '
2400
+	if (!empty($context['level_effects'][$context['current_level']])) {
2401
+			echo '
2316 2402
 				<dt>
2317 2403
 					<strong>', $txt['profile_viewwarning_impact'], ':</strong>
2318 2404
 				</dt>
2319 2405
 				<dd>
2320 2406
 					', $context['level_effects'][$context['current_level']], '
2321 2407
 				</dd>';
2408
+	}
2322 2409
 
2323 2410
 	echo '
2324 2411
 			</dl>
@@ -2356,10 +2443,11 @@  discard block
 block discarded – undo
2356 2443
 
2357 2444
 			// Otherwise see what we can do...';
2358 2445
 
2359
-	foreach ($context['notification_templates'] as $k => $type)
2360
-		echo '
2446
+	foreach ($context['notification_templates'] as $k => $type) {
2447
+			echo '
2361 2448
 			if (index == ', $k, ')
2362 2449
 				document.getElementById(\'warn_body\').value = "', strtr($type['body'], array('"' => "'", "\n" => '\\n', "\r" => '')), '";';
2450
+	}
2363 2451
 
2364 2452
 	echo '
2365 2453
 		}
@@ -2369,10 +2457,11 @@  discard block
 block discarded – undo
2369 2457
 			// Also set the right effect.
2370 2458
 			effectText = "";';
2371 2459
 
2372
-	foreach ($context['level_effects'] as $limit => $text)
2373
-		echo '
2460
+	foreach ($context['level_effects'] as $limit => $text) {
2461
+			echo '
2374 2462
 			if (slideAmount >= ', $limit, ')
2375 2463
 				effectText = "', $text, '";';
2464
+	}
2376 2465
 
2377 2466
 	echo '
2378 2467
 			setInnerHTML(document.getElementById(\'cur_level_div\'), slideAmount + \'% (\' + effectText + \')\');
@@ -2387,32 +2476,35 @@  discard block
 block discarded – undo
2387 2476
 			</h3>
2388 2477
 		</div>';
2389 2478
 
2390
-	if (!$context['user']['is_owner'])
2391
-		echo '
2479
+	if (!$context['user']['is_owner']) {
2480
+			echo '
2392 2481
 		<p class="information">', $txt['profile_warning_desc'], '</p>';
2482
+	}
2393 2483
 
2394 2484
 	echo '
2395 2485
 		<div class="windowbg">
2396 2486
 			<dl class="settings">';
2397 2487
 
2398
-	if (!$context['user']['is_owner'])
2399
-		echo '
2488
+	if (!$context['user']['is_owner']) {
2489
+			echo '
2400 2490
 				<dt>
2401 2491
 					<strong>', $txt['profile_warning_name'], ':</strong>
2402 2492
 				</dt>
2403 2493
 				<dd>
2404 2494
 					<strong>', $context['member']['name'], '</strong>
2405 2495
 				</dd>';
2496
+	}
2406 2497
 
2407 2498
 	echo '
2408 2499
 				<dt>
2409 2500
 					<strong>', $txt['profile_warning_level'], ':</strong>';
2410 2501
 
2411 2502
 	// Is there only so much they can apply?
2412
-	if ($context['warning_limit'])
2413
-		echo '
2503
+	if ($context['warning_limit']) {
2504
+			echo '
2414 2505
 					<br>
2415 2506
 					<span class="smalltext">', sprintf($txt['profile_warning_limit_attribute'], $context['warning_limit']), '</span>';
2507
+	}
2416 2508
 
2417 2509
 	echo '
2418 2510
 				</dt>
@@ -2467,9 +2559,10 @@  discard block
 block discarded – undo
2467 2559
 						<option value="-1">', $txt['profile_warning_notify_template'], '</option>
2468 2560
 						<option value="-1" disabled>------------------------------</option>';
2469 2561
 
2470
-		foreach ($context['notification_templates'] as $id_template => $template)
2471
-			echo '
2562
+		foreach ($context['notification_templates'] as $id_template => $template) {
2563
+					echo '
2472 2564
 						<option value="', $id_template, '">', $template['title'], '</option>';
2565
+		}
2473 2566
 
2474 2567
 		echo '
2475 2568
 					</select>
@@ -2482,9 +2575,10 @@  discard block
 block discarded – undo
2482 2575
 			</dl>
2483 2576
 			<div class="righttext">';
2484 2577
 
2485
-	if (!empty($context['token_check']))
2486
-		echo '
2578
+	if (!empty($context['token_check'])) {
2579
+			echo '
2487 2580
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2581
+	}
2488 2582
 
2489 2583
 	echo '
2490 2584
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2500,8 +2594,8 @@  discard block
 block discarded – undo
2500 2594
 	echo '
2501 2595
 	<script>';
2502 2596
 
2503
-	if (!$context['user']['is_owner'])
2504
-		echo '
2597
+	if (!$context['user']['is_owner']) {
2598
+			echo '
2505 2599
 		modifyWarnNotify();
2506 2600
 		$(document).ready(function() {
2507 2601
 			$("#preview_button").click(function() {
@@ -2540,6 +2634,7 @@  discard block
 block discarded – undo
2540 2634
 			});
2541 2635
 			return false;
2542 2636
 		}';
2637
+	}
2543 2638
 
2544 2639
 	echo '
2545 2640
 	</script>';
@@ -2562,17 +2657,19 @@  discard block
 block discarded – undo
2562 2657
 			</div>';
2563 2658
 
2564 2659
 	// If deleting another account give them a lovely info box.
2565
-	if (!$context['user']['is_owner'])
2566
-		echo '
2660
+	if (!$context['user']['is_owner']) {
2661
+			echo '
2567 2662
 			<p class="information">', $txt['deleteAccount_desc'], '</p>';
2663
+	}
2568 2664
 
2569 2665
 	echo '
2570 2666
 			<div class="windowbg2">';
2571 2667
 
2572 2668
 	// If they are deleting their account AND the admin needs to approve it - give them another piece of info ;)
2573
-	if ($context['needs_approval'])
2574
-		echo '
2669
+	if ($context['needs_approval']) {
2670
+			echo '
2575 2671
 				<div class="errorbox">', $txt['deleteAccount_approval'], '</div>';
2672
+	}
2576 2673
 
2577 2674
 	// If the user is deleting their own account warn them first - and require a password!
2578 2675
 	if ($context['user']['is_owner'])
@@ -2584,9 +2681,10 @@  discard block
 block discarded – undo
2584 2681
 					<input type="password" name="oldpasswrd" size="20">
2585 2682
 					<input type="submit" value="', $txt['yes'], '" class="button">';
2586 2683
 
2587
-		if (!empty($context['token_check']))
2588
-			echo '
2684
+		if (!empty($context['token_check'])) {
2685
+					echo '
2589 2686
 					<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2687
+		}
2590 2688
 
2591 2689
 		echo '
2592 2690
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2616,10 +2714,11 @@  discard block
 block discarded – undo
2616 2714
 						<option value="topics">', $txt['deleteAccount_topics'], '</option>
2617 2715
 					</select>';
2618 2716
 
2619
-			if ($context['show_perma_delete'])
2620
-				echo '
2717
+			if ($context['show_perma_delete']) {
2718
+							echo '
2621 2719
 					<br>
2622 2720
 					<label for="perma_delete"><input type="checkbox" name="perma_delete" id="perma_delete" value="1">', $txt['deleteAccount_permanent'], ':</label>';
2721
+			}
2623 2722
 
2624 2723
 			echo '
2625 2724
 				</div>';
@@ -2632,9 +2731,10 @@  discard block
 block discarded – undo
2632 2731
 				<div>
2633 2732
 					<input type="submit" value="', $txt['delete'], '" class="button">';
2634 2733
 
2635
-		if (!empty($context['token_check']))
2636
-			echo '
2734
+		if (!empty($context['token_check'])) {
2735
+					echo '
2637 2736
 				<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2737
+		}
2638 2738
 
2639 2739
 		echo '
2640 2740
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -2660,8 +2760,8 @@  discard block
 block discarded – undo
2660 2760
 					<hr>';
2661 2761
 
2662 2762
 	// Only show the password box if it's actually needed.
2663
-	if ($context['require_password'])
2664
-		echo '
2763
+	if ($context['require_password']) {
2764
+			echo '
2665 2765
 					<dl class="settings">
2666 2766
 						<dt>
2667 2767
 							<strong', isset($context['modify_error']['bad_password']) || isset($context['modify_error']['no_password']) ? ' class="error"' : '', '>', $txt['current_password'], ': </strong><br>
@@ -2671,13 +2771,15 @@  discard block
 block discarded – undo
2671 2771
 							<input type="password" name="oldpasswrd" size="20">
2672 2772
 						</dd>
2673 2773
 					</dl>';
2774
+	}
2674 2775
 
2675 2776
 	echo '
2676 2777
 					<div class="righttext">';
2677 2778
 
2678
-	if (!empty($context['token_check']))
2679
-		echo '
2779
+	if (!empty($context['token_check'])) {
2780
+			echo '
2680 2781
 						<input type="hidden" name="', $context[$context['token_check'] . '_token_var'], '" value="', $context[$context['token_check'] . '_token'], '">';
2782
+	}
2681 2783
 
2682 2784
 	echo '
2683 2785
 						<input type="submit" value="', $txt['change_profile'], '" class="button">
@@ -2704,9 +2806,10 @@  discard block
 block discarded – undo
2704 2806
 			<ul id="list_errors">';
2705 2807
 
2706 2808
 		// Cycle through each error and display an error message.
2707
-		foreach ($context['post_errors'] as $error)
2708
-			echo '
2809
+		foreach ($context['post_errors'] as $error) {
2810
+					echo '
2709 2811
 				<li>', isset($txt['profile_error_' . $error]) ? $txt['profile_error_' . $error] : $error, '</li>';
2812
+		}
2710 2813
 
2711 2814
 		echo '
2712 2815
 			</ul>';
@@ -2732,12 +2835,13 @@  discard block
 block discarded – undo
2732 2835
 								<select name="id_group" ', ($context['user']['is_owner'] && $context['member']['group_id'] == 1 ? 'onchange="if (this.value != 1 &amp;&amp; !confirm(\'' . $txt['deadmin_confirm'] . '\')) this.value = 1;"' : ''), '>';
2733 2836
 
2734 2837
 	// Fill the select box with all primary member groups that can be assigned to a member.
2735
-	foreach ($context['member_groups'] as $member_group)
2736
-		if (!empty($member_group['can_be_primary']))
2838
+	foreach ($context['member_groups'] as $member_group) {
2839
+			if (!empty($member_group['can_be_primary']))
2737 2840
 			echo '
2738 2841
 									<option value="', $member_group['id'], '"', $member_group['is_primary'] ? ' selected' : '', '>
2739 2842
 										', $member_group['name'], '
2740 2843
 									</option>';
2844
+	}
2741 2845
 
2742 2846
 	echo '
2743 2847
 								</select>
@@ -2750,10 +2854,11 @@  discard block
 block discarded – undo
2750 2854
 									<input type="hidden" name="additional_groups[]" value="0">';
2751 2855
 
2752 2856
 	// For each membergroup show a checkbox so members can be assigned to more than one group.
2753
-	foreach ($context['member_groups'] as $member_group)
2754
-		if ($member_group['can_be_additional'])
2857
+	foreach ($context['member_groups'] as $member_group) {
2858
+			if ($member_group['can_be_additional'])
2755 2859
 			echo '
2756 2860
 									<label for="additional_groups-', $member_group['id'], '"><input type="checkbox" name="additional_groups[]" value="', $member_group['id'], '" id="additional_groups-', $member_group['id'], '"', $member_group['is_additional'] ? ' checked' : '', '> ', $member_group['name'], '</label><br>';
2861
+	}
2757 2862
 
2758 2863
 	echo '
2759 2864
 								</span>
@@ -2813,9 +2918,10 @@  discard block
 block discarded – undo
2813 2918
 								<span class="smalltext">', $txt['sig_info'], '</span><br>
2814 2919
 								<br>';
2815 2920
 
2816
-	if ($context['show_spellchecking'])
2817
-		echo '
2921
+	if ($context['show_spellchecking']) {
2922
+			echo '
2818 2923
 								<input type="button" value="', $txt['spell_check'], '" onclick="spellCheck(\'creator\', \'signature\');" class="button">';
2924
+	}
2819 2925
 
2820 2926
 	echo '
2821 2927
 							</dt>
@@ -2823,17 +2929,20 @@  discard block
 block discarded – undo
2823 2929
 								<textarea class="editor" onkeyup="calcCharLeft();" id="signature" name="signature" rows="5" cols="50">', $context['member']['signature'], '</textarea><br>';
2824 2930
 
2825 2931
 	// If there is a limit at all!
2826
-	if (!empty($context['signature_limits']['max_length']))
2827
-		echo '
2932
+	if (!empty($context['signature_limits']['max_length'])) {
2933
+			echo '
2828 2934
 								<span class="smalltext">', sprintf($txt['max_sig_characters'], $context['signature_limits']['max_length']), ' <span id="signatureLeft">', $context['signature_limits']['max_length'], '</span></span><br>';
2935
+	}
2829 2936
 
2830
-	if (!empty($context['show_preview_button']))
2831
-		echo '
2937
+	if (!empty($context['show_preview_button'])) {
2938
+			echo '
2832 2939
 								<input type="button" name="preview_signature" id="preview_button" value="', $txt['preview_signature'], '" class="button floatright">';
2940
+	}
2833 2941
 
2834
-	if ($context['signature_warning'])
2835
-		echo '
2942
+	if ($context['signature_warning']) {
2943
+			echo '
2836 2944
 								<span class="smalltext">', $context['signature_warning'], '</span>';
2945
+	}
2837 2946
 
2838 2947
 	// Some javascript used to count how many characters have been used so far in the signature.
2839 2948
 	echo '
@@ -2878,9 +2987,10 @@  discard block
 block discarded – undo
2878 2987
 										<select name="cat" id="cat" size="10" onchange="changeSel(\'\');" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'server_stored\');">';
2879 2988
 
2880 2989
 		// This lists all the file categories.
2881
-		foreach ($context['avatars'] as $avatar)
2882
-			echo '
2990
+		foreach ($context['avatars'] as $avatar) {
2991
+					echo '
2883 2992
 											<option value="', $avatar['filename'] . ($avatar['is_dir'] ? '/' : ''), '"', ($avatar['checked'] ? ' selected' : ''), '>', $avatar['name'], '</option>';
2993
+		}
2884 2994
 
2885 2995
 		echo '
2886 2996
 										</select>
@@ -2912,20 +3022,22 @@  discard block
 block discarded – undo
2912 3022
 	}
2913 3023
 
2914 3024
 	// If the user can link to an off server avatar, show them a box to input the address.
2915
-	if (!empty($context['member']['avatar']['allow_external']))
2916
-		echo '
3025
+	if (!empty($context['member']['avatar']['allow_external'])) {
3026
+			echo '
2917 3027
 								<div id="avatar_external">
2918 3028
 									<div class="smalltext">', $txt['avatar_by_url'], '</div>', !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_download_and_resize' ? template_max_size('external') : '', '
2919 3029
 									<input type="text" name="userpicpersonal" size="45" value="', ((stristr($context['member']['avatar']['external'], 'http://') || stristr($context['member']['avatar']['external'], 'https://')) ? $context['member']['avatar']['external'] : 'http://'), '" onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'external\');" onchange="if (typeof(previewExternalAvatar) != \'undefined\') previewExternalAvatar(this.value);">
2920 3030
 								</div>';
3031
+	}
2921 3032
 
2922 3033
 	// If the user is able to upload avatars to the server show them an upload box.
2923
-	if (!empty($context['member']['avatar']['allow_upload']))
2924
-		echo '
3034
+	if (!empty($context['member']['avatar']['allow_upload'])) {
3035
+			echo '
2925 3036
 								<div id="avatar_upload">
2926 3037
 									<input type="file" size="44" name="attachment" id="avatar_upload_box" value="" onchange="readfromUpload(this)"  onfocus="selectRadioByName(document.forms.creator.avatar_choice, \'upload\');" accept="image/gif, image/jpeg, image/jpg, image/png">', template_max_size('upload'), '
2927 3038
 									', (!empty($context['member']['avatar']['id_attach']) ? '<br><img src="' . $context['member']['avatar']['href'] . (strpos($context['member']['avatar']['href'], '?') === false ? '?' : '&amp;') . 'time=' . time() . '" alt="" id="attached_image"><input type="hidden" name="id_attach" value="' . $context['member']['avatar']['id_attach'] . '">' : ''), '
2928 3039
 								</div>';
3040
+	}
2929 3041
 
2930 3042
 	// if the user is able to use Gravatar avatars show then the image preview
2931 3043
 	if (!empty($context['member']['avatar']['allow_gravatar']))
@@ -2934,16 +3046,17 @@  discard block
 block discarded – undo
2934 3046
 								<div id="avatar_gravatar">
2935 3047
 									<img src="' . $context['member']['avatar']['href'] . '" alt="">';
2936 3048
 
2937
-		if (empty($modSettings['gravatarAllowExtraEmail']))
2938
-			echo '
3049
+		if (empty($modSettings['gravatarAllowExtraEmail'])) {
3050
+					echo '
2939 3051
 									<div class="smalltext">', $txt['gravatar_noAlternateEmail'], '</div>';
2940
-		else
3052
+		} else
2941 3053
 		{
2942 3054
 			// Depending on other stuff, the stored value here might have some odd things in it from other areas.
2943
-			if ($context['member']['avatar']['external'] == $context['member']['email'])
2944
-				$textbox_value = '';
2945
-			else
2946
-				$textbox_value = $context['member']['avatar']['external'];
3055
+			if ($context['member']['avatar']['external'] == $context['member']['email']) {
3056
+							$textbox_value = '';
3057
+			} else {
3058
+							$textbox_value = $context['member']['avatar']['external'];
3059
+			}
2947 3060
 
2948 3061
 			echo '
2949 3062
 									<div class="smalltext">', $txt['gravatar_alternateEmail'], '</div>
@@ -3015,8 +3128,9 @@  discard block
 block discarded – undo
3015 3128
 	$h = !empty($modSettings['avatar_max_height_' . $type]) ? comma_format($modSettings['avatar_max_height_' . $type]) : 0;
3016 3129
 
3017 3130
 	$suffix = (!empty($w) ? 'w' : '') . (!empty($h) ? 'h' : '');
3018
-	if (empty($suffix))
3019
-		return;
3131
+	if (empty($suffix)) {
3132
+			return;
3133
+	}
3020 3134
 
3021 3135
 	echo '
3022 3136
 								<div class="smalltext">', sprintf($txt['avatar_max_size_' . $suffix], $w, $h), '</div>';
@@ -3041,9 +3155,10 @@  discard block
 block discarded – undo
3041 3155
 								<select name="easyformat" id="easyformat" onchange="document.forms.creator.time_format.value = this.options[this.selectedIndex].value;">';
3042 3156
 
3043 3157
 	// Help the user by showing a list of common time formats.
3044
-	foreach ($context['easy_timeformats'] as $time_format)
3045
-		echo '
3158
+	foreach ($context['easy_timeformats'] as $time_format) {
3159
+			echo '
3046 3160
 									<option value="', $time_format['format'], '"', $time_format['format'] == $context['member']['time_format'] ? ' selected' : '', '>', $time_format['title'], '</option>';
3161
+	}
3047 3162
 
3048 3163
 	echo '
3049 3164
 								</select>
@@ -3081,9 +3196,10 @@  discard block
 block discarded – undo
3081 3196
 							<dd>
3082 3197
 								<select name="smiley_set" id="smiley_set" onchange="document.getElementById(\'smileypr\').src = this.selectedIndex == 0 ? \'', $settings['images_url'], '/blank.png\' : \'', $modSettings['smileys_url'], '/\' + (this.selectedIndex != 1 ? this.options[this.selectedIndex].value : \'', !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'], '\') + \'/smiley.png\';">';
3083 3198
 
3084
-	foreach ($context['smiley_sets'] as $set)
3085
-		echo '
3199
+	foreach ($context['smiley_sets'] as $set) {
3200
+			echo '
3086 3201
 									<option value="', $set['id'], '"', $set['selected'] ? ' selected' : '', '>', $set['name'], '</option>';
3202
+	}
3087 3203
 
3088 3204
 	echo '
3089 3205
 								</select>
@@ -3135,10 +3251,11 @@  discard block
 block discarded – undo
3135 3251
 										<img src="', $context['tfa_qr_url'], '" alt="">
3136 3252
 									</div>';
3137 3253
 
3138
-	if (!empty($context['from_ajax']))
3139
-		echo '
3254
+	if (!empty($context['from_ajax'])) {
3255
+			echo '
3140 3256
 					<br>
3141 3257
 					<a href="javascript:self.close();"></a>';
3258
+	}
3142 3259
 
3143 3260
 	echo '
3144 3261
 				</div>
@@ -3178,17 +3295,16 @@  discard block
 block discarded – undo
3178 3295
 							</dt>
3179 3296
 							<dd>';
3180 3297
 
3181
-	if (!$context['tfa_enabled'] && $context['user']['is_owner'])
3182
-		echo '
3298
+	if (!$context['tfa_enabled'] && $context['user']['is_owner']) {
3299
+			echo '
3183 3300
 								<a href="', !empty($modSettings['force_ssl']) ? strtr($scripturl, array('http://' => 'https://')) : $scripturl, '?action=profile;area=tfasetup" id="enable_tfa">', $txt['tfa_profile_enable'], '</a>';
3184
-
3185
-	elseif (!$context['tfa_enabled'])
3186
-		echo '
3301
+	} elseif (!$context['tfa_enabled']) {
3302
+			echo '
3187 3303
 								', $txt['tfa_profile_disabled'];
3188
-
3189
-	else
3190
-		echo '
3304
+	} else {
3305
+			echo '
3191 3306
 								', sprintf($txt['tfa_profile_enabled'], $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=tfasetup;disable');
3307
+	}
3192 3308
 
3193 3309
 	echo '
3194 3310
 							</dd>';
Please login to merge, or discard this patch.
Sources/Profile-Modify.php 1 patch
Braces   +703 added lines, -527 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This defines every profile field known to man.
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $sourcedir, $profile_vars;
30 31
 
31 32
 	// Don't load this twice!
32
-	if (!empty($profile_fields) && !$force_reload)
33
-		return;
33
+	if (!empty($profile_fields) && !$force_reload) {
34
+			return;
35
+	}
34 36
 
35 37
 	/* This horrific array defines all the profile fields in the whole world!
36 38
 		In general each "field" has one array - the key of which is the database column name associated with said field. Each item
@@ -103,13 +105,14 @@  discard block
 block discarded – undo
103 105
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 106
 				{
105 107
 					// Set to blank?
106
-					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
107
-						$value = '1004-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '1004-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
112
+					}
113
+				} else {
114
+									$value = '1004-01-01';
110 115
 				}
111
-				else
112
-					$value = '1004-01-01';
113 116
 
114 117
 				$profile_vars['birthdate'] = $value;
115 118
 				$cur_profile['birthdate'] = $value;
@@ -127,8 +130,7 @@  discard block
 block discarded – undo
127 130
 				{
128 131
 					$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '1004-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '1004-01-01' : $cur_profile['birthdate'];
134 136
 					return false;
@@ -150,10 +152,11 @@  discard block
 block discarded – undo
150 152
 					return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
151 153
 				}
152 154
 				// As long as it doesn't equal "N/A"...
153
-				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
154
-					$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
155
-				else
156
-					$value = $cur_profile['date_registered'];
155
+				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) {
156
+									$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
157
+				} else {
158
+									$value = $cur_profile['date_registered'];
159
+				}
157 160
 
158 161
 				return true;
159 162
 			},
@@ -177,8 +180,9 @@  discard block
 block discarded – undo
177 180
 			{
178 181
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 182
 
180
-				if (strtolower($value) == strtolower($old_profile['email_address']))
181
-					return false;
183
+				if (strtolower($value) == strtolower($old_profile['email_address'])) {
184
+									return false;
185
+				}
182 186
 
183 187
 				$isValid = profileValidateEmail($value, $context['id_member']);
184 188
 
@@ -254,11 +258,11 @@  discard block
 block discarded – undo
254 258
 
255 259
 				if (isset($context['profile_languages'][$value]))
256 260
 				{
257
-					if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
258
-						$_SESSION['language'] = $value;
261
+					if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) {
262
+											$_SESSION['language'] = $value;
263
+					}
259 264
 					return true;
260
-				}
261
-				else
265
+				} else
262 266
 				{
263 267
 					$value = $cur_profile['lngfile'];
264 268
 					return false;
@@ -282,13 +286,14 @@  discard block
 block discarded – undo
282 286
 
283 287
 					// Maybe they are trying to change their password as well?
284 288
 					$resetPassword = true;
285
-					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
286
-						$resetPassword = false;
289
+					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) {
290
+											$resetPassword = false;
291
+					}
287 292
 
288 293
 					// Do the reset... this will send them an email too.
289
-					if ($resetPassword)
290
-						resetPassword($context['id_member'], $value);
291
-					elseif ($value !== null)
294
+					if ($resetPassword) {
295
+											resetPassword($context['id_member'], $value);
296
+					} elseif ($value !== null)
292 297
 					{
293 298
 						validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
294 299
 						updateMemberData($context['id_member'], array('member_name' => $value));
@@ -312,20 +317,23 @@  discard block
 block discarded – undo
312 317
 			'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 318
 			{
314 319
 				// If we didn't try it then ignore it!
315
-				if ($value == '')
316
-					return false;
320
+				if ($value == '') {
321
+									return false;
322
+				}
317 323
 
318 324
 				// Do the two entries for the password even match?
319
-				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
320
-					return 'bad_new_password';
325
+				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) {
326
+									return 'bad_new_password';
327
+				}
321 328
 
322 329
 				// Let's get the validation function into play...
323 330
 				require_once($sourcedir . '/Subs-Auth.php');
324 331
 				$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
325 332
 
326 333
 				// Were there errors?
327
-				if ($passwordErrors != null)
328
-					return 'password_' . $passwordErrors;
334
+				if ($passwordErrors != null) {
335
+									return 'password_' . $passwordErrors;
336
+				}
329 337
 
330 338
 				// Set up the new password variable... ready for storage.
331 339
 				$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
@@ -350,8 +358,9 @@  discard block
 block discarded – undo
350 358
 			'permission' => 'profile_blurb',
351 359
 			'input_validate' => function(&$value) use ($smcFunc)
352 360
 			{
353
-				if ($smcFunc['strlen']($value) > 50)
354
-					return 'personal_text_too_long';
361
+				if ($smcFunc['strlen']($value) > 50) {
362
+									return 'personal_text_too_long';
363
+				}
355 364
 
356 365
 				return true;
357 366
 			},
@@ -386,10 +395,11 @@  discard block
 block discarded – undo
386 395
 			'permission' => 'moderate_forum',
387 396
 			'input_validate' => function(&$value)
388 397
 			{
389
-				if (!is_numeric($value))
390
-					return 'digits_only';
391
-				else
392
-					$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
398
+				if (!is_numeric($value)) {
399
+									return 'digits_only';
400
+				} else {
401
+									$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
402
+				}
393 403
 				return true;
394 404
 			},
395 405
 		),
@@ -405,15 +415,16 @@  discard block
 block discarded – undo
405 415
 			{
406 416
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 417
 
408
-				if (trim($value) == '')
409
-					return 'no_name';
410
-				elseif ($smcFunc['strlen']($value) > 60)
411
-					return 'name_too_long';
412
-				elseif ($cur_profile['real_name'] != $value)
418
+				if (trim($value) == '') {
419
+									return 'no_name';
420
+				} elseif ($smcFunc['strlen']($value) > 60) {
421
+									return 'name_too_long';
422
+				} elseif ($cur_profile['real_name'] != $value)
413 423
 				{
414 424
 					require_once($sourcedir . '/Subs-Members.php');
415
-					if (isReservedName($value, $context['id_member']))
416
-						return 'name_taken';
425
+					if (isReservedName($value, $context['id_member'])) {
426
+											return 'name_taken';
427
+					}
417 428
 				}
418 429
 				return true;
419 430
 			},
@@ -471,8 +482,9 @@  discard block
 block discarded – undo
471 482
 						'selected' => $set == $context['member']['smiley_set']['id']
472 483
 					);
473 484
 
474
-					if ($context['smiley_sets'][$i]['selected'])
475
-						$context['member']['smiley_set']['name'] = $set_names[$i];
485
+					if ($context['smiley_sets'][$i]['selected']) {
486
+											$context['member']['smiley_set']['name'] = $set_names[$i];
487
+					}
476 488
 				}
477 489
 				return true;
478 490
 			},
@@ -481,8 +493,9 @@  discard block
 block discarded – undo
481 493
 				global $modSettings;
482 494
 
483 495
 				$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
484
-				if (!in_array($value, $smiley_sets) && $value != 'none')
485
-					$value = '';
496
+				if (!in_array($value, $smiley_sets) && $value != 'none') {
497
+									$value = '';
498
+				}
486 499
 				return true;
487 500
 			},
488 501
 		),
@@ -497,8 +510,9 @@  discard block
 block discarded – undo
497 510
 				loadLanguage('Settings');
498 511
 
499 512
 				$context['allow_no_censored'] = false;
500
-				if ($user_info['is_admin'] || $context['user']['is_owner'])
501
-					$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
513
+				if ($user_info['is_admin'] || $context['user']['is_owner']) {
514
+									$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
515
+				}
502 516
 
503 517
 				return true;
504 518
 			},
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 			'input_validate' => function($value)
546 560
 			{
547 561
 				$tz = smf_list_timezones();
548
-				if (!isset($tz[$value]))
549
-					return 'bad_timezone';
562
+				if (!isset($tz[$value])) {
563
+									return 'bad_timezone';
564
+				}
550 565
 
551 566
 				return true;
552 567
 			},
@@ -561,8 +576,9 @@  discard block
 block discarded – undo
561 576
 			'enabled' => !empty($modSettings['titlesEnable']),
562 577
 			'input_validate' => function(&$value) use ($smcFunc)
563 578
 			{
564
-				if ($smcFunc['strlen']($value) > 50)
565
-					return 'user_title_too_long';
579
+				if ($smcFunc['strlen']($value) > 50) {
580
+									return 'user_title_too_long';
581
+				}
566 582
 
567 583
 				return true;
568 584
 			},
@@ -584,10 +600,12 @@  discard block
 block discarded – undo
584 600
 			// Fix the URL...
585 601
 			'input_validate' => function(&$value)
586 602
 			{
587
-				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588
-					$value = 'http://' . $value;
589
-				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
590
-					$value = '';
603
+				if (strlen(trim($value)) > 0 && strpos($value, '://') === false) {
604
+									$value = 'http://' . $value;
605
+				}
606
+				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) {
607
+									$value = '';
608
+				}
591 609
 				return true;
592 610
 			},
593 611
 			'link_with' => 'website',
@@ -601,16 +619,19 @@  discard block
 block discarded – undo
601 619
 	foreach ($profile_fields as $key => $field)
602 620
 	{
603 621
 		// Do we have permission to do this?
604
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
605
-			unset($profile_fields[$key]);
622
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
623
+					unset($profile_fields[$key]);
624
+		}
606 625
 
607 626
 		// Is it enabled?
608
-		if (isset($field['enabled']) && !$field['enabled'])
609
-			unset($profile_fields[$key]);
627
+		if (isset($field['enabled']) && !$field['enabled']) {
628
+					unset($profile_fields[$key]);
629
+		}
610 630
 
611 631
 		// Is it specifically disabled?
612
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
613
-			unset($profile_fields[$key]);
632
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
633
+					unset($profile_fields[$key]);
634
+		}
614 635
 	}
615 636
 }
616 637
 
@@ -635,9 +656,10 @@  discard block
 block discarded – undo
635 656
 	loadProfileFields(true);
636 657
 
637 658
 	// First check for any linked sets.
638
-	foreach ($profile_fields as $key => $field)
639
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
659
+	foreach ($profile_fields as $key => $field) {
660
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
640 661
 			$fields[] = $key;
662
+	}
641 663
 
642 664
 	$i = 0;
643 665
 	$last_type = '';
@@ -649,38 +671,46 @@  discard block
 block discarded – undo
649 671
 			$cur_field = &$profile_fields[$field];
650 672
 
651 673
 			// Does it have a preload and does that preload succeed?
652
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
653
-				continue;
674
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
675
+							continue;
676
+			}
654 677
 
655 678
 			// If this is anything but complex we need to do more cleaning!
656 679
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
657 680
 			{
658
-				if (!isset($cur_field['label']))
659
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
681
+				if (!isset($cur_field['label'])) {
682
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
683
+				}
660 684
 
661 685
 				// Everything has a value!
662
-				if (!isset($cur_field['value']))
663
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
686
+				if (!isset($cur_field['value'])) {
687
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
688
+				}
664 689
 
665 690
 				// Any input attributes?
666 691
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
667 692
 			}
668 693
 
669 694
 			// Was there an error with this field on posting?
670
-			if (isset($context['profile_errors'][$field]))
671
-				$cur_field['is_error'] = true;
695
+			if (isset($context['profile_errors'][$field])) {
696
+							$cur_field['is_error'] = true;
697
+			}
672 698
 
673 699
 			// Any javascript stuff?
674
-			if (!empty($cur_field['js_submit']))
675
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
676
-			if (!empty($cur_field['js']))
677
-				$context['profile_javascript'] .= $cur_field['js'];
700
+			if (!empty($cur_field['js_submit'])) {
701
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
702
+			}
703
+			if (!empty($cur_field['js'])) {
704
+							$context['profile_javascript'] .= $cur_field['js'];
705
+			}
678 706
 
679 707
 			// Any template stuff?
680
-			if (!empty($cur_field['prehtml']))
681
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
682
-			if (!empty($cur_field['posthtml']))
683
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
708
+			if (!empty($cur_field['prehtml'])) {
709
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
710
+			}
711
+			if (!empty($cur_field['posthtml'])) {
712
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
713
+			}
684 714
 
685 715
 			// Finally put it into context?
686 716
 			if ($cur_field['type'] != 'hidden')
@@ -713,12 +743,14 @@  discard block
 block discarded – undo
713 743
 	}, false);' : ''), true);
714 744
 
715 745
 	// Any onsubmit javascript?
716
-	if (!empty($context['profile_onsubmit_javascript']))
717
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
746
+	if (!empty($context['profile_onsubmit_javascript'])) {
747
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
748
+	}
718 749
 
719 750
 	// Any totally custom stuff?
720
-	if (!empty($context['profile_javascript']))
721
-		addInlineJavaScript($context['profile_javascript'], true);
751
+	if (!empty($context['profile_javascript'])) {
752
+			addInlineJavaScript($context['profile_javascript'], true);
753
+	}
722 754
 
723 755
 	// Free up some memory.
724 756
 	unset($profile_fields);
@@ -739,8 +771,9 @@  discard block
 block discarded – undo
739 771
 
740 772
 	// This allows variables to call activities when they save - by default just to reload their settings
741 773
 	$context['profile_execute_on_save'] = array();
742
-	if ($context['user']['is_owner'])
743
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
774
+	if ($context['user']['is_owner']) {
775
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
776
+	}
744 777
 
745 778
 	// Assume we log nothing.
746 779
 	$context['log_changes'] = array();
@@ -748,8 +781,9 @@  discard block
 block discarded – undo
748 781
 	// Cycle through the profile fields working out what to do!
749 782
 	foreach ($profile_fields as $key => $field)
750 783
 	{
751
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
752
-			continue;
784
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
785
+					continue;
786
+		}
753 787
 
754 788
 		// What gets updated?
755 789
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -777,12 +811,13 @@  discard block
 block discarded – undo
777 811
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
778 812
 
779 813
 		// Finally, clean up certain types.
780
-		if ($field['cast_type'] == 'int')
781
-			$_POST[$key] = (int) $_POST[$key];
782
-		elseif ($field['cast_type'] == 'float')
783
-			$_POST[$key] = (float) $_POST[$key];
784
-		elseif ($field['cast_type'] == 'check')
785
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
814
+		if ($field['cast_type'] == 'int') {
815
+					$_POST[$key] = (int) $_POST[$key];
816
+		} elseif ($field['cast_type'] == 'float') {
817
+					$_POST[$key] = (float) $_POST[$key];
818
+		} elseif ($field['cast_type'] == 'check') {
819
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
820
+		}
786 821
 
787 822
 		// If we got here we're doing OK.
788 823
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -793,11 +828,12 @@  discard block
 block discarded – undo
793 828
 			$cur_profile[$key] = $_POST[$key];
794 829
 
795 830
 			// Are we logging it?
796
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
797
-				$context['log_changes'][$key] = array(
831
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
832
+							$context['log_changes'][$key] = array(
798 833
 					'previous' => $old_profile[$key],
799 834
 					'new' => $_POST[$key],
800 835
 				);
836
+			}
801 837
 		}
802 838
 
803 839
 		// Logging group changes are a bit different...
@@ -830,10 +866,11 @@  discard block
 block discarded – undo
830 866
 				{
831 867
 					foreach ($groups as $id => $group)
832 868
 					{
833
-						if (isset($context['member_groups'][$group]))
834
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
835
-						else
836
-							unset($additional_groups[$type][$id]);
869
+						if (isset($context['member_groups'][$group])) {
870
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
871
+						} else {
872
+													unset($additional_groups[$type][$id]);
873
+						}
837 874
 					}
838 875
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
839 876
 				}
@@ -844,10 +881,11 @@  discard block
 block discarded – undo
844 881
 	}
845 882
 
846 883
 	// @todo Temporary
847
-	if ($context['user']['is_owner'])
848
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
849
-	else
850
-		$changeOther = allowedTo('profile_extra_any');
884
+	if ($context['user']['is_owner']) {
885
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
886
+	} else {
887
+			$changeOther = allowedTo('profile_extra_any');
888
+	}
851 889
 	if ($changeOther && empty($post_errors))
852 890
 	{
853 891
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -855,8 +893,9 @@  discard block
 block discarded – undo
855 893
 		{
856 894
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
857 895
 
858
-			if (!empty($custom_fields_errors))
859
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
896
+			if (!empty($custom_fields_errors)) {
897
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
898
+			}
860 899
 		}
861 900
 	}
862 901
 
@@ -882,9 +921,9 @@  discard block
 block discarded – undo
882 921
 	if ($context['user']['is_owner'])
883 922
 	{
884 923
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
924
+	} else {
925
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
885 926
 	}
886
-	else
887
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
888 927
 
889 928
 	// Arrays of all the changes - makes things easier.
890 929
 	$profile_bools = array();
@@ -895,22 +934,25 @@  discard block
 block discarded – undo
895 934
 		'ignore_boards',
896 935
 	);
897 936
 
898
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
899
-		$_POST['ignore_brd'] = array();
937
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
938
+			$_POST['ignore_brd'] = array();
939
+	}
900 940
 
901 941
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
902 942
 	if (isset($_POST['ignore_brd']))
903 943
 	{
904
-		if (!is_array($_POST['ignore_brd']))
905
-			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
944
+		if (!is_array($_POST['ignore_brd'])) {
945
+					$_POST['ignore_brd'] = array($_POST['ignore_brd']);
946
+		}
906 947
 
907 948
 		foreach ($_POST['ignore_brd'] as $k => $d)
908 949
 		{
909 950
 			$d = (int) $d;
910
-			if ($d != 0)
911
-				$_POST['ignore_brd'][$k] = $d;
912
-			else
913
-				unset($_POST['ignore_brd'][$k]);
951
+			if ($d != 0) {
952
+							$_POST['ignore_brd'][$k] = $d;
953
+			} else {
954
+							unset($_POST['ignore_brd'][$k]);
955
+			}
914 956
 		}
915 957
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
916 958
 		unset($_POST['ignore_brd']);
@@ -923,21 +965,26 @@  discard block
 block discarded – undo
923 965
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
924 966
 		//makeAvatarChanges($memID, $post_errors);
925 967
 
926
-		if (!empty($_REQUEST['sa']))
927
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
968
+		if (!empty($_REQUEST['sa'])) {
969
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
970
+		}
928 971
 
929
-		foreach ($profile_bools as $var)
930
-			if (isset($_POST[$var]))
972
+		foreach ($profile_bools as $var) {
973
+					if (isset($_POST[$var]))
931 974
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
932
-		foreach ($profile_ints as $var)
933
-			if (isset($_POST[$var]))
975
+		}
976
+		foreach ($profile_ints as $var) {
977
+					if (isset($_POST[$var]))
934 978
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
935
-		foreach ($profile_floats as $var)
936
-			if (isset($_POST[$var]))
979
+		}
980
+		foreach ($profile_floats as $var) {
981
+					if (isset($_POST[$var]))
937 982
 				$profile_vars[$var] = (float) $_POST[$var];
938
-		foreach ($profile_strings as $var)
939
-			if (isset($_POST[$var]))
983
+		}
984
+		foreach ($profile_strings as $var) {
985
+					if (isset($_POST[$var]))
940 986
 				$profile_vars[$var] = $_POST[$var];
987
+		}
941 988
 	}
942 989
 }
943 990
 
@@ -971,8 +1018,9 @@  discard block
 block discarded – undo
971 1018
 	);
972 1019
 
973 1020
 	// Can't change reserved vars.
974
-	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
975
-		fatal_lang_error('no_access', false);
1021
+	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) {
1022
+			fatal_lang_error('no_access', false);
1023
+	}
976 1024
 
977 1025
 	// Don't allow any overriding of custom fields with default or non-default options.
978 1026
 	$request = $smcFunc['db_query']('', '
@@ -984,8 +1032,9 @@  discard block
 block discarded – undo
984 1032
 		)
985 1033
 	);
986 1034
 	$custom_fields = array();
987
-	while ($row = $smcFunc['db_fetch_assoc']($request))
988
-		$custom_fields[] = $row['col_name'];
1035
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1036
+			$custom_fields[] = $row['col_name'];
1037
+	}
989 1038
 	$smcFunc['db_free_result']($request);
990 1039
 
991 1040
 	// These are the theme changes...
@@ -994,33 +1043,39 @@  discard block
 block discarded – undo
994 1043
 	{
995 1044
 		foreach ($_POST['options'] as $opt => $val)
996 1045
 		{
997
-			if (in_array($opt, $custom_fields))
998
-				continue;
1046
+			if (in_array($opt, $custom_fields)) {
1047
+							continue;
1048
+			}
999 1049
 
1000 1050
 			// These need to be controlled.
1001
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1002
-				$val = max(0, min($val, 50));
1051
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1052
+							$val = max(0, min($val, 50));
1053
+			}
1003 1054
 			// We don't set this per theme anymore.
1004
-			elseif ($opt == 'allow_no_censored')
1005
-				continue;
1055
+			elseif ($opt == 'allow_no_censored') {
1056
+							continue;
1057
+			}
1006 1058
 
1007 1059
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1008 1060
 		}
1009 1061
 	}
1010 1062
 
1011 1063
 	$erase_options = array();
1012
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1013
-		foreach ($_POST['default_options'] as $opt => $val)
1064
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1065
+			foreach ($_POST['default_options'] as $opt => $val)
1014 1066
 		{
1015 1067
 			if (in_array($opt, $custom_fields))
1016 1068
 				continue;
1069
+	}
1017 1070
 
1018 1071
 			// These need to be controlled.
1019
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1020
-				$val = max(0, min($val, 50));
1072
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1073
+							$val = max(0, min($val, 50));
1074
+			}
1021 1075
 			// Only let admins and owners change the censor.
1022
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1023
-					continue;
1076
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1077
+								continue;
1078
+			}
1024 1079
 
1025 1080
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1026 1081
 			$erase_options[] = $opt;
@@ -1056,8 +1111,9 @@  discard block
 block discarded – undo
1056 1111
 
1057 1112
 		// Admins can choose any theme, even if it's not enabled...
1058 1113
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1059
-		foreach ($themes as $t)
1060
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1114
+		foreach ($themes as $t) {
1115
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1116
+		}
1061 1117
 	}
1062 1118
 }
1063 1119
 
@@ -1076,8 +1132,9 @@  discard block
 block discarded – undo
1076 1132
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1077 1133
 	{
1078 1134
 		// Make sure only integers are deleted.
1079
-		foreach ($_POST['notify_boards'] as $index => $id)
1080
-			$_POST['notify_boards'][$index] = (int) $id;
1135
+		foreach ($_POST['notify_boards'] as $index => $id) {
1136
+					$_POST['notify_boards'][$index] = (int) $id;
1137
+		}
1081 1138
 
1082 1139
 		// id_board = 0 is reserved for topic notifications.
1083 1140
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1096,8 +1153,9 @@  discard block
 block discarded – undo
1096 1153
 	// We are editing topic notifications......
1097 1154
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1098 1155
 	{
1099
-		foreach ($_POST['notify_topics'] as $index => $id)
1100
-			$_POST['notify_topics'][$index] = (int) $id;
1156
+		foreach ($_POST['notify_topics'] as $index => $id) {
1157
+					$_POST['notify_topics'][$index] = (int) $id;
1158
+		}
1101 1159
 
1102 1160
 		// Make sure there are no zeros left.
1103 1161
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1111,16 +1169,18 @@  discard block
 block discarded – undo
1111 1169
 				'selected_member' => $memID,
1112 1170
 			)
1113 1171
 		);
1114
-		foreach ($_POST['notify_topics'] as $topic)
1115
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1172
+		foreach ($_POST['notify_topics'] as $topic) {
1173
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1174
+		}
1116 1175
 	}
1117 1176
 
1118 1177
 	// We are removing topic preferences
1119 1178
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1120 1179
 	{
1121 1180
 		$prefs = array();
1122
-		foreach ($_POST['notify_topics'] as $topic)
1123
-			$prefs[] = 'topic_notify_' . $topic;
1181
+		foreach ($_POST['notify_topics'] as $topic) {
1182
+					$prefs[] = 'topic_notify_' . $topic;
1183
+		}
1124 1184
 		deleteNotifyPrefs($memID, $prefs);
1125 1185
 	}
1126 1186
 
@@ -1128,8 +1188,9 @@  discard block
 block discarded – undo
1128 1188
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1129 1189
 	{
1130 1190
 		$prefs = array();
1131
-		foreach ($_POST['notify_boards'] as $board)
1132
-			$prefs[] = 'board_notify_' . $board;
1191
+		foreach ($_POST['notify_boards'] as $board) {
1192
+					$prefs[] = 'board_notify_' . $board;
1193
+		}
1133 1194
 		deleteNotifyPrefs($memID, $prefs);
1134 1195
 	}
1135 1196
 }
@@ -1150,8 +1211,9 @@  discard block
 block discarded – undo
1150 1211
 
1151 1212
 	$errors = array();
1152 1213
 
1153
-	if ($sanitize && isset($_POST['customfield']))
1154
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1214
+	if ($sanitize && isset($_POST['customfield'])) {
1215
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1216
+	}
1155 1217
 
1156 1218
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1157 1219
 
@@ -1176,26 +1238,29 @@  discard block
 block discarded – undo
1176 1238
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1177 1239
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1178 1240
 		*/
1179
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1180
-			continue;
1241
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1242
+					continue;
1243
+		}
1181 1244
 
1182 1245
 		// Validate the user data.
1183
-		if ($row['field_type'] == 'check')
1184
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1185
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1246
+		if ($row['field_type'] == 'check') {
1247
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1248
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1186 1249
 		{
1187 1250
 			$value = $row['default_value'];
1188
-			foreach (explode(',', $row['field_options']) as $k => $v)
1189
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1251
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1252
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1190 1253
 					$value = $v;
1254
+			}
1191 1255
 		}
1192 1256
 		// Otherwise some form of text!
1193 1257
 		else
1194 1258
 		{
1195 1259
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1196 1260
 
1197
-			if ($row['field_length'])
1198
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1261
+			if ($row['field_length']) {
1262
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1263
+			}
1199 1264
 
1200 1265
 			// Any masks?
1201 1266
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
@@ -1204,36 +1269,34 @@  discard block
 block discarded – undo
1204 1269
 				$valueReference = un_htmlspecialchars($value);
1205 1270
 
1206 1271
 				// Try and avoid some checks. '0' could be a valid non-empty value.
1207
-				if (empty($value) && !is_numeric($value))
1208
-					$value = '';
1272
+				if (empty($value) && !is_numeric($value)) {
1273
+									$value = '';
1274
+				}
1209 1275
 
1210 1276
 				if ($row['mask'] == 'nohtml' && ($valueReference != strip_tags($valueReference) || $value != filter_var($value, FILTER_SANITIZE_STRING) || preg_match('/<(.+?)[\s]*\/?[\s]*>/si', $valueReference)))
1211 1277
 				{
1212
-					if ($returnErrors)
1213
-						$errors[] = 'custom_field_nohtml_fail';
1214
-
1215
-					else
1216
-						$value = '';
1217
-				}
1218
-				elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1278
+					if ($returnErrors) {
1279
+											$errors[] = 'custom_field_nohtml_fail';
1280
+					} else {
1281
+											$value = '';
1282
+					}
1283
+				} elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1219 1284
 				{
1220
-					if ($returnErrors)
1221
-						$errors[] = 'custom_field_mail_fail';
1222
-
1223
-					else
1224
-						$value = '';
1225
-				}
1226
-				elseif ($row['mask'] == 'number')
1285
+					if ($returnErrors) {
1286
+											$errors[] = 'custom_field_mail_fail';
1287
+					} else {
1288
+											$value = '';
1289
+					}
1290
+				} elseif ($row['mask'] == 'number')
1227 1291
 				{
1228 1292
 					$value = (int) $value;
1229
-				}
1230
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1293
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1231 1294
 				{
1232
-					if ($returnErrors)
1233
-						$errors[] = 'custom_field_regex_fail';
1234
-
1235
-					else
1236
-						$value = '';
1295
+					if ($returnErrors) {
1296
+											$errors[] = 'custom_field_regex_fail';
1297
+					} else {
1298
+											$value = '';
1299
+					}
1237 1300
 				}
1238 1301
 
1239 1302
 				unset($valueReference);
@@ -1261,8 +1324,9 @@  discard block
 block discarded – undo
1261 1324
 
1262 1325
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1263 1326
 
1264
-	if (!empty($hook_errors) && is_array($hook_errors))
1265
-		$errors = array_merge($errors, $hook_errors);
1327
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1328
+			$errors = array_merge($errors, $hook_errors);
1329
+	}
1266 1330
 
1267 1331
 	// Make those changes!
1268 1332
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1280,9 +1344,10 @@  discard block
 block discarded – undo
1280 1344
 		}
1281 1345
 	}
1282 1346
 
1283
-	if ($returnErrors)
1284
-		return $errors;
1285
-}
1347
+	if ($returnErrors) {
1348
+			return $errors;
1349
+	}
1350
+	}
1286 1351
 
1287 1352
 /**
1288 1353
  * Show all the users buddies, as well as a add/delete interface.
@@ -1294,8 +1359,9 @@  discard block
 block discarded – undo
1294 1359
 	global $context, $txt, $modSettings;
1295 1360
 
1296 1361
 	// Do a quick check to ensure people aren't getting here illegally!
1297
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1298
-		fatal_lang_error('no_access', false);
1362
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1363
+			fatal_lang_error('no_access', false);
1364
+	}
1299 1365
 
1300 1366
 	// Can we email the user direct?
1301 1367
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1325,9 +1391,10 @@  discard block
 block discarded – undo
1325 1391
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1326 1392
 	$call = call_helper($subActions[$context['list_area']][0], true);
1327 1393
 
1328
-	if (!empty($call))
1329
-		call_user_func($call, $memID);
1330
-}
1394
+	if (!empty($call)) {
1395
+			call_user_func($call, $memID);
1396
+	}
1397
+	}
1331 1398
 
1332 1399
 /**
1333 1400
  * Show all the users buddies, as well as a add/delete interface.
@@ -1341,9 +1408,10 @@  discard block
 block discarded – undo
1341 1408
 
1342 1409
 	// For making changes!
1343 1410
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1344
-	foreach ($buddiesArray as $k => $dummy)
1345
-		if ($dummy == '')
1411
+	foreach ($buddiesArray as $k => $dummy) {
1412
+			if ($dummy == '')
1346 1413
 			unset($buddiesArray[$k]);
1414
+	}
1347 1415
 
1348 1416
 	// Removing a buddy?
1349 1417
 	if (isset($_GET['remove']))
@@ -1355,10 +1423,11 @@  discard block
 block discarded – undo
1355 1423
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1356 1424
 
1357 1425
 		// Heh, I'm lazy, do it the easy way...
1358
-		foreach ($buddiesArray as $key => $buddy)
1359
-			if ($buddy == (int) $_GET['remove'])
1426
+		foreach ($buddiesArray as $key => $buddy) {
1427
+					if ($buddy == (int) $_GET['remove'])
1360 1428
 			{
1361 1429
 				unset($buddiesArray[$key]);
1430
+		}
1362 1431
 				$_SESSION['prf-save'] = true;
1363 1432
 			}
1364 1433
 
@@ -1368,8 +1437,7 @@  discard block
 block discarded – undo
1368 1437
 
1369 1438
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1370 1439
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1371
-	}
1372
-	elseif (isset($_POST['new_buddy']))
1440
+	} elseif (isset($_POST['new_buddy']))
1373 1441
 	{
1374 1442
 		checkSession();
1375 1443
 
@@ -1382,8 +1450,9 @@  discard block
 block discarded – undo
1382 1450
 		{
1383 1451
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1384 1452
 
1385
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1386
-				unset($new_buddies[$k]);
1453
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1454
+							unset($new_buddies[$k]);
1455
+			}
1387 1456
 		}
1388 1457
 
1389 1458
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1403,16 +1472,18 @@  discard block
 block discarded – undo
1403 1472
 				)
1404 1473
 			);
1405 1474
 
1406
-			if ($smcFunc['db_num_rows']($request) != 0)
1407
-				$_SESSION['prf-save'] = true;
1475
+			if ($smcFunc['db_num_rows']($request) != 0) {
1476
+							$_SESSION['prf-save'] = true;
1477
+			}
1408 1478
 
1409 1479
 			// Add the new member to the buddies array.
1410 1480
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1411 1481
 			{
1412
-				if (in_array($row['id_member'], $buddiesArray))
1413
-					continue;
1414
-				else
1415
-					$buddiesArray[] = (int) $row['id_member'];
1482
+				if (in_array($row['id_member'], $buddiesArray)) {
1483
+									continue;
1484
+				} else {
1485
+									$buddiesArray[] = (int) $row['id_member'];
1486
+				}
1416 1487
 			}
1417 1488
 			$smcFunc['db_free_result']($request);
1418 1489
 
@@ -1442,18 +1513,20 @@  discard block
 block discarded – undo
1442 1513
 
1443 1514
 	$context['custom_pf'] = array();
1444 1515
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1445
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1446
-		if (!isset($disabled_fields[$row['col_name']]))
1516
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1517
+			if (!isset($disabled_fields[$row['col_name']]))
1447 1518
 			$context['custom_pf'][$row['col_name']] = array(
1448 1519
 				'label' => $row['field_name'],
1449 1520
 				'type' => $row['field_type'],
1450 1521
 				'bbc' => !empty($row['bbc']),
1451 1522
 				'enclose' => $row['enclose'],
1452 1523
 			);
1524
+	}
1453 1525
 
1454 1526
 	// Gotta disable the gender option.
1455
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None')
1456
-		unset($context['custom_pf']['cust_gender']);
1527
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None') {
1528
+			unset($context['custom_pf']['cust_gender']);
1529
+	}
1457 1530
 
1458 1531
 	$smcFunc['db_free_result']($request);
1459 1532
 
@@ -1470,8 +1543,9 @@  discard block
 block discarded – undo
1470 1543
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1471 1544
 			)
1472 1545
 		);
1473
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1474
-			$buddies[] = $row['id_member'];
1546
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1547
+					$buddies[] = $row['id_member'];
1548
+		}
1475 1549
 		$smcFunc['db_free_result']($result);
1476 1550
 	}
1477 1551
 
@@ -1499,30 +1573,32 @@  discard block
 block discarded – undo
1499 1573
 					continue;
1500 1574
 				}
1501 1575
 
1502
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1503
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1504
-
1505
-				elseif ($column['type'] == 'check')
1506
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1576
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1577
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1578
+				} elseif ($column['type'] == 'check') {
1579
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1580
+				}
1507 1581
 
1508 1582
 				// Enclosing the user input within some other text?
1509
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1510
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1583
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1584
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1511 1585
 						'{SCRIPTURL}' => $scripturl,
1512 1586
 						'{IMAGES_URL}' => $settings['images_url'],
1513 1587
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1514 1588
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1515 1589
 					));
1590
+				}
1516 1591
 			}
1517 1592
 		}
1518 1593
 	}
1519 1594
 
1520 1595
 	if (isset($_SESSION['prf-save']))
1521 1596
 	{
1522
-		if ($_SESSION['prf-save'] === true)
1523
-			$context['saved_successful'] = true;
1524
-		else
1525
-			$context['saved_failed'] = $_SESSION['prf-save'];
1597
+		if ($_SESSION['prf-save'] === true) {
1598
+					$context['saved_successful'] = true;
1599
+		} else {
1600
+					$context['saved_failed'] = $_SESSION['prf-save'];
1601
+		}
1526 1602
 
1527 1603
 		unset($_SESSION['prf-save']);
1528 1604
 	}
@@ -1542,9 +1618,10 @@  discard block
 block discarded – undo
1542 1618
 
1543 1619
 	// For making changes!
1544 1620
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1545
-	foreach ($ignoreArray as $k => $dummy)
1546
-		if ($dummy == '')
1621
+	foreach ($ignoreArray as $k => $dummy) {
1622
+			if ($dummy == '')
1547 1623
 			unset($ignoreArray[$k]);
1624
+	}
1548 1625
 
1549 1626
 	// Removing a member from the ignore list?
1550 1627
 	if (isset($_GET['remove']))
@@ -1554,10 +1631,11 @@  discard block
 block discarded – undo
1554 1631
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1555 1632
 
1556 1633
 		// Heh, I'm lazy, do it the easy way...
1557
-		foreach ($ignoreArray as $key => $id_remove)
1558
-			if ($id_remove == (int) $_GET['remove'])
1634
+		foreach ($ignoreArray as $key => $id_remove) {
1635
+					if ($id_remove == (int) $_GET['remove'])
1559 1636
 			{
1560 1637
 				unset($ignoreArray[$key]);
1638
+		}
1561 1639
 				$_SESSION['prf-save'] = true;
1562 1640
 			}
1563 1641
 
@@ -1567,8 +1645,7 @@  discard block
 block discarded – undo
1567 1645
 
1568 1646
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1569 1647
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1570
-	}
1571
-	elseif (isset($_POST['new_ignore']))
1648
+	} elseif (isset($_POST['new_ignore']))
1572 1649
 	{
1573 1650
 		checkSession();
1574 1651
 		// Prepare the string for extraction...
@@ -1580,8 +1657,9 @@  discard block
 block discarded – undo
1580 1657
 		{
1581 1658
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1582 1659
 
1583
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1584
-				unset($new_entries[$k]);
1660
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1661
+							unset($new_entries[$k]);
1662
+			}
1585 1663
 		}
1586 1664
 
1587 1665
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1599,16 +1677,18 @@  discard block
 block discarded – undo
1599 1677
 				)
1600 1678
 			);
1601 1679
 
1602
-			if ($smcFunc['db_num_rows']($request) != 0)
1603
-				$_SESSION['prf-save'] = true;
1680
+			if ($smcFunc['db_num_rows']($request) != 0) {
1681
+							$_SESSION['prf-save'] = true;
1682
+			}
1604 1683
 
1605 1684
 			// Add the new member to the buddies array.
1606 1685
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1607 1686
 			{
1608
-				if (in_array($row['id_member'], $ignoreArray))
1609
-					continue;
1610
-				else
1611
-					$ignoreArray[] = (int) $row['id_member'];
1687
+				if (in_array($row['id_member'], $ignoreArray)) {
1688
+									continue;
1689
+				} else {
1690
+									$ignoreArray[] = (int) $row['id_member'];
1691
+				}
1612 1692
 			}
1613 1693
 			$smcFunc['db_free_result']($request);
1614 1694
 
@@ -1637,8 +1717,9 @@  discard block
 block discarded – undo
1637 1717
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1638 1718
 			)
1639 1719
 		);
1640
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1641
-			$ignored[] = $row['id_member'];
1720
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1721
+					$ignored[] = $row['id_member'];
1722
+		}
1642 1723
 		$smcFunc['db_free_result']($result);
1643 1724
 	}
1644 1725
 
@@ -1657,10 +1738,11 @@  discard block
 block discarded – undo
1657 1738
 
1658 1739
 	if (isset($_SESSION['prf-save']))
1659 1740
 	{
1660
-		if ($_SESSION['prf-save'] === true)
1661
-			$context['saved_successful'] = true;
1662
-		else
1663
-			$context['saved_failed'] = $_SESSION['prf-save'];
1741
+		if ($_SESSION['prf-save'] === true) {
1742
+					$context['saved_successful'] = true;
1743
+		} else {
1744
+					$context['saved_failed'] = $_SESSION['prf-save'];
1745
+		}
1664 1746
 
1665 1747
 		unset($_SESSION['prf-save']);
1666 1748
 	}
@@ -1676,8 +1758,9 @@  discard block
 block discarded – undo
1676 1758
 	global $context, $txt;
1677 1759
 
1678 1760
 	loadThemeOptions($memID);
1679
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1680
-		loadCustomFields($memID, 'account');
1761
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1762
+			loadCustomFields($memID, 'account');
1763
+	}
1681 1764
 
1682 1765
 	$context['sub_template'] = 'edit_options';
1683 1766
 	$context['page_desc'] = $txt['account_info'];
@@ -1704,8 +1787,9 @@  discard block
 block discarded – undo
1704 1787
 	global $context, $txt;
1705 1788
 
1706 1789
 	loadThemeOptions($memID);
1707
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1708
-		loadCustomFields($memID, 'forumprofile');
1790
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1791
+			loadCustomFields($memID, 'forumprofile');
1792
+	}
1709 1793
 
1710 1794
 	$context['sub_template'] = 'edit_options';
1711 1795
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1738,18 +1822,21 @@  discard block
 block discarded – undo
1738 1822
 	$dirs = array();
1739 1823
 	$files = array();
1740 1824
 
1741
-	if (!$dir)
1742
-		return array();
1825
+	if (!$dir) {
1826
+			return array();
1827
+	}
1743 1828
 
1744 1829
 	while ($line = $dir->read())
1745 1830
 	{
1746
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1747
-			continue;
1831
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1832
+					continue;
1833
+		}
1748 1834
 
1749
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1750
-			$dirs[] = $line;
1751
-		else
1752
-			$files[] = $line;
1835
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1836
+					$dirs[] = $line;
1837
+		} else {
1838
+					$files[] = $line;
1839
+		}
1753 1840
 	}
1754 1841
 	$dir->close();
1755 1842
 
@@ -1770,14 +1857,15 @@  discard block
 block discarded – undo
1770 1857
 	foreach ($dirs as $line)
1771 1858
 	{
1772 1859
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1773
-		if (!empty($tmp))
1774
-			$result[] = array(
1860
+		if (!empty($tmp)) {
1861
+					$result[] = array(
1775 1862
 				'filename' => $smcFunc['htmlspecialchars']($line),
1776 1863
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1777 1864
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1778 1865
 				'is_dir' => true,
1779 1866
 				'files' => $tmp
1780 1867
 		);
1868
+		}
1781 1869
 		unset($tmp);
1782 1870
 	}
1783 1871
 
@@ -1787,8 +1875,9 @@  discard block
 block discarded – undo
1787 1875
 		$extension = substr(strrchr($line, '.'), 1);
1788 1876
 
1789 1877
 		// Make sure it is an image.
1790
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1791
-			continue;
1878
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1879
+					continue;
1880
+		}
1792 1881
 
1793 1882
 		$result[] = array(
1794 1883
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1796,8 +1885,9 @@  discard block
 block discarded – undo
1796 1885
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1797 1886
 			'is_dir' => false
1798 1887
 		);
1799
-		if ($level == 1)
1800
-			$context['avatar_list'][] = $directory . '/' . $line;
1888
+		if ($level == 1) {
1889
+					$context['avatar_list'][] = $directory . '/' . $line;
1890
+		}
1801 1891
 	}
1802 1892
 
1803 1893
 	return $result;
@@ -1819,8 +1909,9 @@  discard block
 block discarded – undo
1819 1909
 	call_integration_hook('integrate_theme_options');
1820 1910
 
1821 1911
 	loadThemeOptions($memID);
1822
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1823
-		loadCustomFields($memID, 'theme');
1912
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1913
+			loadCustomFields($memID, 'theme');
1914
+	}
1824 1915
 
1825 1916
 	$context['sub_template'] = 'edit_options';
1826 1917
 	$context['page_desc'] = $txt['theme_info'];
@@ -1874,16 +1965,19 @@  discard block
 block discarded – undo
1874 1965
 {
1875 1966
 	global $txt, $context, $modSettings, $smcFunc, $sourcedir;
1876 1967
 
1877
-	if (!isset($context['token_check']))
1878
-		$context['token_check'] = 'profile-nt' . $memID;
1968
+	if (!isset($context['token_check'])) {
1969
+			$context['token_check'] = 'profile-nt' . $memID;
1970
+	}
1879 1971
 
1880 1972
 	is_not_guest();
1881
-	if (!$context['user']['is_owner'])
1882
-		isAllowedTo('profile_extra_any');
1973
+	if (!$context['user']['is_owner']) {
1974
+			isAllowedTo('profile_extra_any');
1975
+	}
1883 1976
 
1884 1977
 	// Set the post action if we're coming from the profile...
1885
-	if (!isset($context['action']))
1886
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1978
+	if (!isset($context['action'])) {
1979
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1980
+	}
1887 1981
 
1888 1982
 	// What options are set
1889 1983
 	loadThemeOptions($memID);
@@ -1970,28 +2064,34 @@  discard block
 block discarded – undo
1970 2064
 	);
1971 2065
 
1972 2066
 	// There are certain things that are disabled at the group level.
1973
-	if (empty($modSettings['cal_enabled']))
1974
-		unset($alert_types['calendar']);
2067
+	if (empty($modSettings['cal_enabled'])) {
2068
+			unset($alert_types['calendar']);
2069
+	}
1975 2070
 
1976 2071
 	// Disable paid subscriptions at group level if they're disabled
1977
-	if (empty($modSettings['paid_enabled']))
1978
-		unset($alert_types['paidsubs']);
2072
+	if (empty($modSettings['paid_enabled'])) {
2073
+			unset($alert_types['paidsubs']);
2074
+	}
1979 2075
 
1980 2076
 	// Disable membergroup requests at group level if they're disabled
1981
-	if (empty($modSettings['show_group_membership']))
1982
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2077
+	if (empty($modSettings['show_group_membership'])) {
2078
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2079
+	}
1983 2080
 
1984 2081
 	// Disable mentions if they're disabled
1985
-	if (empty($modSettings['enable_mentions']))
1986
-		unset($alert_types['msg']['msg_mention']);
2082
+	if (empty($modSettings['enable_mentions'])) {
2083
+			unset($alert_types['msg']['msg_mention']);
2084
+	}
1987 2085
 
1988 2086
 	// Disable likes if they're disabled
1989
-	if (empty($modSettings['enable_likes']))
1990
-		unset($alert_types['msg']['msg_like']);
2087
+	if (empty($modSettings['enable_likes'])) {
2088
+			unset($alert_types['msg']['msg_like']);
2089
+	}
1991 2090
 
1992 2091
 	// Disable buddy requests if they're disabled
1993
-	if (empty($modSettings['enable_buddylist']))
1994
-		unset($alert_types['members']['buddy_request']);
2092
+	if (empty($modSettings['enable_buddylist'])) {
2093
+			unset($alert_types['members']['buddy_request']);
2094
+	}
1995 2095
 
1996 2096
 	// Now, now, we could pass this through global but we should really get into the habit of
1997 2097
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -2019,15 +2119,17 @@  discard block
 block discarded – undo
2019 2119
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
2020 2120
 		}
2021 2121
 
2022
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2023
-			unset($alert_types['members']['request_group']);
2122
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2123
+					unset($alert_types['members']['request_group']);
2124
+		}
2024 2125
 
2025 2126
 		foreach ($alert_types as $group => $items)
2026 2127
 		{
2027 2128
 			foreach ($items as $alert_key => $alert_value)
2028 2129
 			{
2029
-				if (!isset($alert_value['permission']))
2030
-					continue;
2130
+				if (!isset($alert_value['permission'])) {
2131
+									continue;
2132
+				}
2031 2133
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2032 2134
 				{
2033 2135
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2035,12 +2137,14 @@  discard block
 block discarded – undo
2035 2137
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2036 2138
 				}
2037 2139
 
2038
-				if (!$perms_cache[$alert_value['permission']['name']])
2039
-					unset ($alert_types[$group][$alert_key]);
2140
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2141
+									unset ($alert_types[$group][$alert_key]);
2142
+				}
2040 2143
 			}
2041 2144
 
2042
-			if (empty($alert_types[$group]))
2043
-				unset ($alert_types[$group]);
2145
+			if (empty($alert_types[$group])) {
2146
+							unset ($alert_types[$group]);
2147
+			}
2044 2148
 		}
2045 2149
 	}
2046 2150
 
@@ -2072,9 +2176,9 @@  discard block
 block discarded – undo
2072 2176
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2073 2177
 						break;
2074 2178
 					case 'select':
2075
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2076
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2077
-						else
2179
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2180
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2181
+						} else
2078 2182
 						{
2079 2183
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2080 2184
 							$keys = array_keys($this_option['opts']);
@@ -2094,23 +2198,28 @@  discard block
 block discarded – undo
2094 2198
 				$this_value = 0;
2095 2199
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2096 2200
 				{
2097
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2098
-						$this_value |= $bitvalue;
2201
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2202
+											$this_value |= $bitvalue;
2203
+					}
2204
+				}
2205
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2206
+									$update_prefs[$item_key] = $this_value;
2099 2207
 				}
2100
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2101
-					$update_prefs[$item_key] = $this_value;
2102 2208
 			}
2103 2209
 		}
2104 2210
 
2105
-		if (!empty($_POST['opt_alert_timeout']))
2106
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2211
+		if (!empty($_POST['opt_alert_timeout'])) {
2212
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2213
+		}
2107 2214
 
2108
-		if (!empty($_POST['notify_announcements']))
2109
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2215
+		if (!empty($_POST['notify_announcements'])) {
2216
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2217
+		}
2110 2218
 
2111 2219
 		setNotifyPrefs((int) $memID, $update_prefs);
2112
-		foreach ($update_prefs as $pref => $value)
2113
-			$context['alert_prefs'][$pref] = $value;
2220
+		foreach ($update_prefs as $pref => $value) {
2221
+					$context['alert_prefs'][$pref] = $value;
2222
+		}
2114 2223
 
2115 2224
 		makeNotificationChanges($memID);
2116 2225
 
@@ -2140,8 +2249,9 @@  discard block
 block discarded – undo
2140 2249
 
2141 2250
 	// Now we're all set up.
2142 2251
 	is_not_guest();
2143
-	if (!$context['user']['is_owner'])
2144
-		fatal_error('no_access');
2252
+	if (!$context['user']['is_owner']) {
2253
+			fatal_error('no_access');
2254
+	}
2145 2255
 
2146 2256
 	checkSession('get');
2147 2257
 
@@ -2173,8 +2283,9 @@  discard block
 block discarded – undo
2173 2283
 {
2174 2284
 	global $smcFunc;
2175 2285
 
2176
-	if (empty($toMark) || empty($memID))
2177
-		return false;
2286
+	if (empty($toMark) || empty($memID)) {
2287
+			return false;
2288
+	}
2178 2289
 
2179 2290
 	$toMark = (array) $toMark;
2180 2291
 
@@ -2208,8 +2319,9 @@  discard block
 block discarded – undo
2208 2319
 {
2209 2320
 	global $smcFunc;
2210 2321
 
2211
-	if (empty($toDelete))
2212
-		return false;
2322
+	if (empty($toDelete)) {
2323
+			return false;
2324
+	}
2213 2325
 
2214 2326
 	$toDelete = (array) $toDelete;
2215 2327
 
@@ -2244,8 +2356,9 @@  discard block
 block discarded – undo
2244 2356
 {
2245 2357
 	global $smcFunc;
2246 2358
 
2247
-	if (empty($memID))
2248
-		return false;
2359
+	if (empty($memID)) {
2360
+			return false;
2361
+	}
2249 2362
 
2250 2363
 	$request = $smcFunc['db_query']('', '
2251 2364
 		SELECT id_alert
@@ -2322,8 +2435,9 @@  discard block
 block discarded – undo
2322 2435
 					{
2323 2436
 						$link = $topic['link'];
2324 2437
 
2325
-						if ($topic['new'])
2326
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2438
+						if ($topic['new']) {
2439
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2440
+						}
2327 2441
 
2328 2442
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2329 2443
 
@@ -2474,8 +2588,9 @@  discard block
 block discarded – undo
2474 2588
 					{
2475 2589
 						$link = $board['link'];
2476 2590
 
2477
-						if ($board['new'])
2478
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2591
+						if ($board['new']) {
2592
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2593
+						}
2479 2594
 
2480 2595
 						return $link;
2481 2596
 					},
@@ -2675,8 +2790,8 @@  discard block
 block discarded – undo
2675 2790
 		)
2676 2791
 	);
2677 2792
 	$notification_boards = array();
2678
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2679
-		$notification_boards[] = array(
2793
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2794
+			$notification_boards[] = array(
2680 2795
 			'id' => $row['id_board'],
2681 2796
 			'name' => $row['name'],
2682 2797
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2684,6 +2799,7 @@  discard block
 block discarded – undo
2684 2799
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2685 2800
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2686 2801
 		);
2802
+	}
2687 2803
 	$smcFunc['db_free_result']($request);
2688 2804
 
2689 2805
 	return $notification_boards;
@@ -2698,17 +2814,18 @@  discard block
 block discarded – undo
2698 2814
 {
2699 2815
 	global $context, $options, $cur_profile, $smcFunc;
2700 2816
 
2701
-	if (isset($_POST['default_options']))
2702
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2817
+	if (isset($_POST['default_options'])) {
2818
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2819
+	}
2703 2820
 
2704 2821
 	if ($context['user']['is_owner'])
2705 2822
 	{
2706 2823
 		$context['member']['options'] = $options;
2707
-		if (isset($_POST['options']) && is_array($_POST['options']))
2708
-			foreach ($_POST['options'] as $k => $v)
2824
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2825
+					foreach ($_POST['options'] as $k => $v)
2709 2826
 				$context['member']['options'][$k] = $v;
2710
-	}
2711
-	else
2827
+		}
2828
+	} else
2712 2829
 	{
2713 2830
 		$request = $smcFunc['db_query']('', '
2714 2831
 			SELECT id_member, variable, value
@@ -2729,8 +2846,9 @@  discard block
 block discarded – undo
2729 2846
 				continue;
2730 2847
 			}
2731 2848
 
2732
-			if (isset($_POST['options'][$row['variable']]))
2733
-				$row['value'] = $_POST['options'][$row['variable']];
2849
+			if (isset($_POST['options'][$row['variable']])) {
2850
+							$row['value'] = $_POST['options'][$row['variable']];
2851
+			}
2734 2852
 			$context['member']['options'][$row['variable']] = $row['value'];
2735 2853
 		}
2736 2854
 		$smcFunc['db_free_result']($request);
@@ -2738,8 +2856,9 @@  discard block
 block discarded – undo
2738 2856
 		// Load up the default theme options for any missing.
2739 2857
 		foreach ($temp as $k => $v)
2740 2858
 		{
2741
-			if (!isset($context['member']['options'][$k]))
2742
-				$context['member']['options'][$k] = $v;
2859
+			if (!isset($context['member']['options'][$k])) {
2860
+							$context['member']['options'][$k] = $v;
2861
+			}
2743 2862
 		}
2744 2863
 	}
2745 2864
 }
@@ -2754,8 +2873,9 @@  discard block
 block discarded – undo
2754 2873
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2755 2874
 
2756 2875
 	// Have the admins enabled this option?
2757
-	if (empty($modSettings['allow_ignore_boards']))
2758
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2876
+	if (empty($modSettings['allow_ignore_boards'])) {
2877
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2878
+	}
2759 2879
 
2760 2880
 	// Find all the boards this user is allowed to see.
2761 2881
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2775,12 +2895,13 @@  discard block
 block discarded – undo
2775 2895
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2776 2896
 	{
2777 2897
 		// This category hasn't been set up yet..
2778
-		if (!isset($context['categories'][$row['id_cat']]))
2779
-			$context['categories'][$row['id_cat']] = array(
2898
+		if (!isset($context['categories'][$row['id_cat']])) {
2899
+					$context['categories'][$row['id_cat']] = array(
2780 2900
 				'id' => $row['id_cat'],
2781 2901
 				'name' => $row['cat_name'],
2782 2902
 				'boards' => array()
2783 2903
 			);
2904
+		}
2784 2905
 
2785 2906
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2786 2907
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2810,18 +2931,20 @@  discard block
 block discarded – undo
2810 2931
 	}
2811 2932
 
2812 2933
 	$max_boards = ceil(count($temp_boards) / 2);
2813
-	if ($max_boards == 1)
2814
-		$max_boards = 2;
2934
+	if ($max_boards == 1) {
2935
+			$max_boards = 2;
2936
+	}
2815 2937
 
2816 2938
 	// Now, alternate them so they can be shown left and right ;).
2817 2939
 	$context['board_columns'] = array();
2818 2940
 	for ($i = 0; $i < $max_boards; $i++)
2819 2941
 	{
2820 2942
 		$context['board_columns'][] = $temp_boards[$i];
2821
-		if (isset($temp_boards[$i + $max_boards]))
2822
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2823
-		else
2824
-			$context['board_columns'][] = array();
2943
+		if (isset($temp_boards[$i + $max_boards])) {
2944
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2945
+		} else {
2946
+					$context['board_columns'][] = array();
2947
+		}
2825 2948
 	}
2826 2949
 
2827 2950
 	loadThemeOptions($memID);
@@ -2890,8 +3013,9 @@  discard block
 block discarded – undo
2890 3013
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2891 3014
 	{
2892 3015
 		// We should skip the administrator group if they don't have the admin_forum permission!
2893
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2894
-			continue;
3016
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
3017
+					continue;
3018
+		}
2895 3019
 
2896 3020
 		$context['member_groups'][$row['id_group']] = array(
2897 3021
 			'id' => $row['id_group'],
@@ -2937,16 +3061,17 @@  discard block
 block discarded – undo
2937 3061
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2938 3062
 	// Warning message for signature image limits?
2939 3063
 	$context['signature_warning'] = '';
2940
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2941
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2942
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2943
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3064
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3065
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3066
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3067
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3068
+	}
2944 3069
 
2945 3070
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2946 3071
 
2947
-	if (empty($context['do_preview']))
2948
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2949
-	else
3072
+	if (empty($context['do_preview'])) {
3073
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3074
+	} else
2950 3075
 	{
2951 3076
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2952 3077
 		$validation = profileValidateSignature($signature);
@@ -2956,8 +3081,9 @@  discard block
 block discarded – undo
2956 3081
 			$context['post_errors'] = array();
2957 3082
 		}
2958 3083
 		$context['post_errors'][] = 'signature_not_yet_saved';
2959
-		if ($validation !== true && $validation !== false)
2960
-			$context['post_errors'][] = $validation;
3084
+		if ($validation !== true && $validation !== false) {
3085
+					$context['post_errors'][] = $validation;
3086
+		}
2961 3087
 
2962 3088
 		censorText($context['member']['signature']);
2963 3089
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2967,8 +3093,9 @@  discard block
 block discarded – undo
2967 3093
 	}
2968 3094
 
2969 3095
 	// Load the spell checker?
2970
-	if ($context['show_spellchecking'])
2971
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3096
+	if ($context['show_spellchecking']) {
3097
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3098
+	}
2972 3099
 
2973 3100
 	return true;
2974 3101
 }
@@ -3002,8 +3129,7 @@  discard block
 block discarded – undo
3002 3129
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
3003 3130
 		);
3004 3131
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
3005
-	}
3006
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3132
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3007 3133
 	{
3008 3134
 		$context['member']['avatar'] += array(
3009 3135
 			'choice' => 'upload',
@@ -3013,33 +3139,34 @@  discard block
 block discarded – undo
3013 3139
 		$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
3014 3140
 	}
3015 3141
 	// Use "avatar_original" here so we show what the user entered even if the image proxy is enabled
3016
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
3017
-		$context['member']['avatar'] += array(
3142
+	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3143
+			$context['member']['avatar'] += array(
3018 3144
 			'choice' => 'external',
3019 3145
 			'server_pic' => 'blank.png',
3020 3146
 			'external' => $cur_profile['avatar_original']
3021 3147
 		);
3022
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3023
-		$context['member']['avatar'] += array(
3148
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3149
+			$context['member']['avatar'] += array(
3024 3150
 			'choice' => 'server_stored',
3025 3151
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3026 3152
 			'external' => 'http://'
3027 3153
 		);
3028
-	else
3029
-		$context['member']['avatar'] += array(
3154
+	} else {
3155
+			$context['member']['avatar'] += array(
3030 3156
 			'choice' => 'none',
3031 3157
 			'server_pic' => 'blank.png',
3032 3158
 			'external' => 'http://'
3033 3159
 		);
3160
+	}
3034 3161
 
3035 3162
 	// Get a list of all the avatars.
3036 3163
 	if ($context['member']['avatar']['allow_server_stored'])
3037 3164
 	{
3038 3165
 		$context['avatar_list'] = array();
3039 3166
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3167
+	} else {
3168
+			$context['avatars'] = array();
3040 3169
 	}
3041
-	else
3042
-		$context['avatars'] = array();
3043 3170
 
3044 3171
 	// Second level selected avatar...
3045 3172
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3068,19 +3195,22 @@  discard block
 block discarded – undo
3068 3195
 			)
3069 3196
 		);
3070 3197
 		$protected_groups = array(1);
3071
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3072
-			$protected_groups[] = $row['id_group'];
3198
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3199
+					$protected_groups[] = $row['id_group'];
3200
+		}
3073 3201
 		$smcFunc['db_free_result']($request);
3074 3202
 
3075 3203
 		$protected_groups = array_unique($protected_groups);
3076 3204
 	}
3077 3205
 
3078 3206
 	// The account page allows the change of your id_group - but not to a protected group!
3079
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3080
-		$value = (int) $value;
3207
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3208
+			$value = (int) $value;
3209
+	}
3081 3210
 	// ... otherwise it's the old group sir.
3082
-	else
3083
-		$value = $old_profile['id_group'];
3211
+	else {
3212
+			$value = $old_profile['id_group'];
3213
+	}
3084 3214
 
3085 3215
 	// Find the additional membergroups (if any)
3086 3216
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3089,16 +3219,18 @@  discard block
 block discarded – undo
3089 3219
 		foreach ($_POST['additional_groups'] as $group_id)
3090 3220
 		{
3091 3221
 			$group_id = (int) $group_id;
3092
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3093
-				$additional_groups[] = $group_id;
3222
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3223
+							$additional_groups[] = $group_id;
3224
+			}
3094 3225
 		}
3095 3226
 
3096 3227
 		// Put the protected groups back in there if you don't have permission to take them away.
3097 3228
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3098 3229
 		foreach ($old_additional_groups as $group_id)
3099 3230
 		{
3100
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3101
-				$additional_groups[] = $group_id;
3231
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3232
+							$additional_groups[] = $group_id;
3233
+			}
3102 3234
 		}
3103 3235
 
3104 3236
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3130,18 +3262,20 @@  discard block
 block discarded – undo
3130 3262
 			list ($another) = $smcFunc['db_fetch_row']($request);
3131 3263
 			$smcFunc['db_free_result']($request);
3132 3264
 
3133
-			if (empty($another))
3134
-				fatal_lang_error('at_least_one_admin', 'critical');
3265
+			if (empty($another)) {
3266
+							fatal_lang_error('at_least_one_admin', 'critical');
3267
+			}
3135 3268
 		}
3136 3269
 	}
3137 3270
 
3138 3271
 	// If we are changing group status, update permission cache as necessary.
3139 3272
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3140 3273
 	{
3141
-		if ($context['user']['is_owner'])
3142
-			$_SESSION['mc']['time'] = 0;
3143
-		else
3144
-			updateSettings(array('settings_updated' => time()));
3274
+		if ($context['user']['is_owner']) {
3275
+					$_SESSION['mc']['time'] = 0;
3276
+		} else {
3277
+					updateSettings(array('settings_updated' => time()));
3278
+		}
3145 3279
 	}
3146 3280
 
3147 3281
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3162,8 +3296,9 @@  discard block
 block discarded – undo
3162 3296
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3163 3297
 
3164 3298
 	$memID = $context['id_member'];
3165
-	if (empty($memID) && !empty($context['password_auth_failed']))
3166
-		return false;
3299
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3300
+			return false;
3301
+	}
3167 3302
 
3168 3303
 	require_once($sourcedir . '/ManageAttachments.php');
3169 3304
 
@@ -3174,8 +3309,9 @@  discard block
 block discarded – undo
3174 3309
 	$downloadedExternalAvatar = false;
3175 3310
 	if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
3176 3311
 	{
3177
-		if (!is_writable($uploadDir))
3178
-			fatal_lang_error('attachments_no_write', 'critical');
3312
+		if (!is_writable($uploadDir)) {
3313
+					fatal_lang_error('attachments_no_write', 'critical');
3314
+		}
3179 3315
 
3180 3316
 		require_once($sourcedir . '/Subs-Package.php');
3181 3317
 
@@ -3219,19 +3355,18 @@  discard block
 block discarded – undo
3219 3355
 
3220 3356
 		// Get rid of their old avatar. (if uploaded.)
3221 3357
 		removeAttachments(array('id_member' => $memID));
3222
-	}
3223
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3358
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3224 3359
 	{
3225 3360
 		// One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar.
3226
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3227
-			$profile_vars['avatar'] = 'gravatar://';
3228
-		else
3229
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3361
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3362
+					$profile_vars['avatar'] = 'gravatar://';
3363
+		} else {
3364
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3365
+		}
3230 3366
 
3231 3367
 		// Get rid of their old avatar. (if uploaded.)
3232 3368
 		removeAttachments(array('id_member' => $memID));
3233
-	}
3234
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3369
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3235 3370
 	{
3236 3371
 		// We need these clean...
3237 3372
 		$cur_profile['id_attach'] = 0;
@@ -3243,11 +3378,13 @@  discard block
 block discarded – undo
3243 3378
 
3244 3379
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3245 3380
 
3246
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3247
-			$profile_vars['avatar'] = '';
3381
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3382
+					$profile_vars['avatar'] = '';
3383
+		}
3248 3384
 		// Trying to make us do something we'll regret?
3249
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3250
-			return 'bad_avatar_invalid_url';
3385
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3386
+					return 'bad_avatar_invalid_url';
3387
+		}
3251 3388
 		// Should we check dimensions?
3252 3389
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3253 3390
 		{
@@ -3257,9 +3394,9 @@  discard block
 block discarded – undo
3257 3394
 			if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
3258 3395
 			{
3259 3396
 				// Houston, we have a problem. The avatar is too large!!
3260
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3261
-					return 'bad_avatar_too_large';
3262
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3397
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3398
+									return 'bad_avatar_too_large';
3399
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3263 3400
 				{
3264 3401
 					// @todo remove this if appropriate
3265 3402
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3269,26 +3406,27 @@  discard block
 block discarded – undo
3269 3406
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3270 3407
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3271 3408
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3409
+					} else {
3410
+											return 'bad_avatar';
3272 3411
 					}
3273
-					else
3274
-						return 'bad_avatar';
3275 3412
 				}
3276 3413
 			}
3277 3414
 		}
3278
-	}
3279
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3415
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3280 3416
 	{
3281 3417
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3282 3418
 		{
3283 3419
 			// Get the dimensions of the image.
3284 3420
 			if (!$downloadedExternalAvatar)
3285 3421
 			{
3286
-				if (!is_writable($uploadDir))
3287
-					fatal_lang_error('attachments_no_write', 'critical');
3422
+				if (!is_writable($uploadDir)) {
3423
+									fatal_lang_error('attachments_no_write', 'critical');
3424
+				}
3288 3425
 
3289 3426
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3290
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3291
-					fatal_lang_error('attach_timeout', 'critical');
3427
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3428
+									fatal_lang_error('attach_timeout', 'critical');
3429
+				}
3292 3430
 
3293 3431
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3294 3432
 			}
@@ -3401,17 +3539,19 @@  discard block
 block discarded – undo
3401 3539
 			$profile_vars['avatar'] = '';
3402 3540
 
3403 3541
 			// Delete any temporary file.
3404
-			if (file_exists($_FILES['attachment']['tmp_name']))
3405
-				@unlink($_FILES['attachment']['tmp_name']);
3542
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3543
+							@unlink($_FILES['attachment']['tmp_name']);
3544
+			}
3406 3545
 		}
3407 3546
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3408
-		else
3547
+		else {
3548
+					$profile_vars['avatar'] = '';
3549
+		}
3550
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3551
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3552
+	} else {
3409 3553
 			$profile_vars['avatar'] = '';
3410 3554
 	}
3411
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3412
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3413
-	else
3414
-		$profile_vars['avatar'] = '';
3415 3555
 
3416 3556
 	// Setup the profile variables so it shows things right on display!
3417 3557
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3459,9 +3599,9 @@  discard block
 block discarded – undo
3459 3599
 		$smiley_parsed = $unparsed_signature;
3460 3600
 		parsesmileys($smiley_parsed);
3461 3601
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3462
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3463
-			return 'signature_allow_smileys';
3464
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3602
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3603
+					return 'signature_allow_smileys';
3604
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3465 3605
 		{
3466 3606
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3467 3607
 			return 'signature_max_smileys';
@@ -3474,14 +3614,15 @@  discard block
 block discarded – undo
3474 3614
 			{
3475 3615
 				$limit_broke = 0;
3476 3616
 				// Attempt to allow all sizes of abuse, so to speak.
3477
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3478
-					$limit_broke = $sig_limits[7] . 'px';
3479
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3480
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3481
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3482
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3483
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3484
-					$limit_broke = 'large';
3617
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3618
+									$limit_broke = $sig_limits[7] . 'px';
3619
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3620
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3621
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3622
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3623
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3624
+									$limit_broke = 'large';
3625
+				}
3485 3626
 
3486 3627
 				if ($limit_broke)
3487 3628
 				{
@@ -3523,24 +3664,26 @@  discard block
 block discarded – undo
3523 3664
 					$width = -1; $height = -1;
3524 3665
 
3525 3666
 					// Does it have predefined restraints? Width first.
3526
-					if ($matches[6][$key])
3527
-						$matches[2][$key] = $matches[6][$key];
3667
+					if ($matches[6][$key]) {
3668
+											$matches[2][$key] = $matches[6][$key];
3669
+					}
3528 3670
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3529 3671
 					{
3530 3672
 						$width = $sig_limits[5];
3531 3673
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3674
+					} elseif ($matches[2][$key]) {
3675
+											$width = $matches[2][$key];
3532 3676
 					}
3533
-					elseif ($matches[2][$key])
3534
-						$width = $matches[2][$key];
3535 3677
 					// ... and height.
3536 3678
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3537 3679
 					{
3538 3680
 						$height = $sig_limits[6];
3539
-						if ($width != -1)
3540
-							$width = $width * ($height / $matches[4][$key]);
3681
+						if ($width != -1) {
3682
+													$width = $width * ($height / $matches[4][$key]);
3683
+						}
3684
+					} elseif ($matches[4][$key]) {
3685
+											$height = $matches[4][$key];
3541 3686
 					}
3542
-					elseif ($matches[4][$key])
3543
-						$height = $matches[4][$key];
3544 3687
 
3545 3688
 					// If the dimensions are still not fixed - we need to check the actual image.
3546 3689
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3558,21 +3701,24 @@  discard block
 block discarded – undo
3558 3701
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3559 3702
 							{
3560 3703
 								$height = $sig_limits[6];
3561
-								if ($width == -1)
3562
-									$width = $sizes[0];
3704
+								if ($width == -1) {
3705
+																	$width = $sizes[0];
3706
+								}
3563 3707
 								$width = $width * ($height / $sizes[1]);
3708
+							} elseif ($width != -1) {
3709
+															$height = $sizes[1];
3564 3710
 							}
3565
-							elseif ($width != -1)
3566
-								$height = $sizes[1];
3567 3711
 						}
3568 3712
 					}
3569 3713
 
3570 3714
 					// Did we come up with some changes? If so remake the string.
3571
-					if ($width != -1 || $height != -1)
3572
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3715
+					if ($width != -1 || $height != -1) {
3716
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3717
+					}
3718
+				}
3719
+				if (!empty($replaces)) {
3720
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3573 3721
 				}
3574
-				if (!empty($replaces))
3575
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3576 3722
 			}
3577 3723
 		}
3578 3724
 
@@ -3616,10 +3762,12 @@  discard block
 block discarded – undo
3616 3762
 	$email = strtr($email, array('&#039;' => '\''));
3617 3763
 
3618 3764
 	// Check the name and email for validity.
3619
-	if (trim($email) == '')
3620
-		return 'no_email';
3621
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3622
-		return 'bad_email';
3765
+	if (trim($email) == '') {
3766
+			return 'no_email';
3767
+	}
3768
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3769
+			return 'bad_email';
3770
+	}
3623 3771
 
3624 3772
 	// Email addresses should be and stay unique.
3625 3773
 	$request = $smcFunc['db_query']('', '
@@ -3634,8 +3782,9 @@  discard block
 block discarded – undo
3634 3782
 		)
3635 3783
 	);
3636 3784
 
3637
-	if ($smcFunc['db_num_rows']($request) > 0)
3638
-		return 'email_taken';
3785
+	if ($smcFunc['db_num_rows']($request) > 0) {
3786
+			return 'email_taken';
3787
+	}
3639 3788
 	$smcFunc['db_free_result']($request);
3640 3789
 
3641 3790
 	return true;
@@ -3648,8 +3797,9 @@  discard block
 block discarded – undo
3648 3797
 {
3649 3798
 	global $modSettings, $context, $cur_profile;
3650 3799
 
3651
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3652
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3800
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3801
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3802
+	}
3653 3803
 
3654 3804
 	loadUserSettings();
3655 3805
 	writeLog();
@@ -3665,8 +3815,9 @@  discard block
 block discarded – undo
3665 3815
 	require_once($sourcedir . '/Subs-Post.php');
3666 3816
 
3667 3817
 	// Shouldn't happen but just in case.
3668
-	if (empty($profile_vars['email_address']))
3669
-		return;
3818
+	if (empty($profile_vars['email_address'])) {
3819
+			return;
3820
+	}
3670 3821
 
3671 3822
 	$replacements = array(
3672 3823
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3689,8 +3840,9 @@  discard block
 block discarded – undo
3689 3840
 	$_SESSION['log_time'] = 0;
3690 3841
 	$_SESSION['login_' . $cookiename] = $smcFunc['json_encode'](array(0, '', 0));
3691 3842
 
3692
-	if (isset($_COOKIE[$cookiename]))
3693
-		$_COOKIE[$cookiename] = '';
3843
+	if (isset($_COOKIE[$cookiename])) {
3844
+			$_COOKIE[$cookiename] = '';
3845
+	}
3694 3846
 
3695 3847
 	loadUserSettings();
3696 3848
 
@@ -3723,11 +3875,13 @@  discard block
 block discarded – undo
3723 3875
 	$groups[] = $curMember['id_group'];
3724 3876
 
3725 3877
 	// Ensure the query doesn't croak!
3726
-	if (empty($groups))
3727
-		$groups = array(0);
3878
+	if (empty($groups)) {
3879
+			$groups = array(0);
3880
+	}
3728 3881
 	// Just to be sure...
3729
-	foreach ($groups as $k => $v)
3730
-		$groups[$k] = (int) $v;
3882
+	foreach ($groups as $k => $v) {
3883
+			$groups[$k] = (int) $v;
3884
+	}
3731 3885
 
3732 3886
 	// Get all the membergroups they can join.
3733 3887
 	$request = $smcFunc['db_query']('', '
@@ -3757,12 +3911,14 @@  discard block
 block discarded – undo
3757 3911
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3758 3912
 	{
3759 3913
 		// Can they edit their primary group?
3760
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3761
-			$context['can_edit_primary'] = true;
3914
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3915
+					$context['can_edit_primary'] = true;
3916
+		}
3762 3917
 
3763 3918
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3764
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3765
-			continue;
3919
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3920
+					continue;
3921
+		}
3766 3922
 
3767 3923
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3768 3924
 			'id' => $row['id_group'],
@@ -3791,13 +3947,15 @@  discard block
 block discarded – undo
3791 3947
 	);
3792 3948
 
3793 3949
 	// No changing primary one unless you have enough groups!
3794
-	if (count($context['groups']['member']) < 2)
3795
-		$context['can_edit_primary'] = false;
3950
+	if (count($context['groups']['member']) < 2) {
3951
+			$context['can_edit_primary'] = false;
3952
+	}
3796 3953
 
3797 3954
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3798
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3799
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3800
-}
3955
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3956
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3957
+	}
3958
+	}
3801 3959
 
3802 3960
 /**
3803 3961
  * This function actually makes all the group changes
@@ -3812,10 +3970,12 @@  discard block
 block discarded – undo
3812 3970
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3813 3971
 
3814 3972
 	// Let's be extra cautious...
3815
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3816
-		isAllowedTo('manage_membergroups');
3817
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3818
-		fatal_lang_error('no_access', false);
3973
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3974
+			isAllowedTo('manage_membergroups');
3975
+	}
3976
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3977
+			fatal_lang_error('no_access', false);
3978
+	}
3819 3979
 
3820 3980
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3821 3981
 
@@ -3834,8 +3994,9 @@  discard block
 block discarded – undo
3834 3994
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3835 3995
 
3836 3996
 	// Sanity check!!
3837
-	if ($group_id == 1)
3838
-		isAllowedTo('admin_forum');
3997
+	if ($group_id == 1) {
3998
+			isAllowedTo('admin_forum');
3999
+	}
3839 4000
 	// Protected groups too!
3840 4001
 	else
3841 4002
 	{
@@ -3852,8 +4013,9 @@  discard block
 block discarded – undo
3852 4013
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3853 4014
 		$smcFunc['db_free_result']($request);
3854 4015
 
3855
-		if ($is_protected == 1)
3856
-			isAllowedTo('admin_forum');
4016
+		if ($is_protected == 1) {
4017
+					isAllowedTo('admin_forum');
4018
+		}
3857 4019
 	}
3858 4020
 
3859 4021
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3875,36 +4037,43 @@  discard block
 block discarded – undo
3875 4037
 			$group_name = $row['group_name'];
3876 4038
 
3877 4039
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3878
-			if ($changeType == 'request' && $row['group_type'] != 2)
3879
-				fatal_lang_error('no_access', false);
4040
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4041
+							fatal_lang_error('no_access', false);
4042
+			}
3880 4043
 			// What about leaving a requestable group we are not a member of?
3881
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3882
-				fatal_lang_error('no_access', false);
3883
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3884
-				fatal_lang_error('no_access', false);
4044
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4045
+							fatal_lang_error('no_access', false);
4046
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4047
+							fatal_lang_error('no_access', false);
4048
+			}
3885 4049
 
3886 4050
 			// We can't change the primary group if this is hidden!
3887
-			if ($row['hidden'] == 2)
3888
-				$canChangePrimary = false;
4051
+			if ($row['hidden'] == 2) {
4052
+							$canChangePrimary = false;
4053
+			}
3889 4054
 		}
3890 4055
 
3891 4056
 		// If this is their old primary, can we change it?
3892
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3893
-			$canChangePrimary = 1;
4057
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4058
+					$canChangePrimary = 1;
4059
+		}
3894 4060
 
3895 4061
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3896
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3897
-			$canChangePrimary = false;
4062
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4063
+					$canChangePrimary = false;
4064
+		}
3898 4065
 
3899 4066
 		// If this is the one we are acting on, can we even act?
3900
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3901
-			$canChangePrimary = false;
4067
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4068
+					$canChangePrimary = false;
4069
+		}
3902 4070
 	}
3903 4071
 	$smcFunc['db_free_result']($request);
3904 4072
 
3905 4073
 	// Didn't find the target?
3906
-	if (!$foundTarget)
3907
-		fatal_lang_error('no_access', false);
4074
+	if (!$foundTarget) {
4075
+			fatal_lang_error('no_access', false);
4076
+	}
3908 4077
 
3909 4078
 	// Final security check, don't allow users to promote themselves to admin.
3910 4079
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3924,8 +4093,9 @@  discard block
 block discarded – undo
3924 4093
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3925 4094
 		$smcFunc['db_free_result']($request);
3926 4095
 
3927
-		if ($disallow)
3928
-			isAllowedTo('admin_forum');
4096
+		if ($disallow) {
4097
+					isAllowedTo('admin_forum');
4098
+		}
3929 4099
 	}
3930 4100
 
3931 4101
 	// If we're requesting, add the note then return.
@@ -3943,8 +4113,9 @@  discard block
 block discarded – undo
3943 4113
 				'status_open' => 0,
3944 4114
 			)
3945 4115
 		);
3946
-		if ($smcFunc['db_num_rows']($request) != 0)
3947
-			fatal_lang_error('profile_error_already_requested_group');
4116
+		if ($smcFunc['db_num_rows']($request) != 0) {
4117
+					fatal_lang_error('profile_error_already_requested_group');
4118
+		}
3948 4119
 		$smcFunc['db_free_result']($request);
3949 4120
 
3950 4121
 		// Log the request.
@@ -3978,10 +4149,11 @@  discard block
 block discarded – undo
3978 4149
 		// Are we leaving?
3979 4150
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3980 4151
 		{
3981
-			if ($old_profile['id_group'] == $group_id)
3982
-				$newPrimary = 0;
3983
-			else
3984
-				unset($addGroups[$group_id]);
4152
+			if ($old_profile['id_group'] == $group_id) {
4153
+							$newPrimary = 0;
4154
+			} else {
4155
+							unset($addGroups[$group_id]);
4156
+			}
3985 4157
 		}
3986 4158
 		// ... if not, must be joining.
3987 4159
 		else
@@ -3989,36 +4161,42 @@  discard block
 block discarded – undo
3989 4161
 			// Can we change the primary, and do we want to?
3990 4162
 			if ($canChangePrimary)
3991 4163
 			{
3992
-				if ($old_profile['id_group'] != 0)
3993
-					$addGroups[$old_profile['id_group']] = -1;
4164
+				if ($old_profile['id_group'] != 0) {
4165
+									$addGroups[$old_profile['id_group']] = -1;
4166
+				}
3994 4167
 				$newPrimary = $group_id;
3995 4168
 			}
3996 4169
 			// Otherwise it's an additional group...
3997
-			else
3998
-				$addGroups[$group_id] = -1;
4170
+			else {
4171
+							$addGroups[$group_id] = -1;
4172
+			}
3999 4173
 		}
4000 4174
 	}
4001 4175
 	// Finally, we must be setting the primary.
4002 4176
 	elseif ($canChangePrimary)
4003 4177
 	{
4004
-		if ($old_profile['id_group'] != 0)
4005
-			$addGroups[$old_profile['id_group']] = -1;
4006
-		if (isset($addGroups[$group_id]))
4007
-			unset($addGroups[$group_id]);
4178
+		if ($old_profile['id_group'] != 0) {
4179
+					$addGroups[$old_profile['id_group']] = -1;
4180
+		}
4181
+		if (isset($addGroups[$group_id])) {
4182
+					unset($addGroups[$group_id]);
4183
+		}
4008 4184
 		$newPrimary = $group_id;
4009 4185
 	}
4010 4186
 
4011 4187
 	// Finally, we can make the changes!
4012
-	foreach ($addGroups as $id => $dummy)
4013
-		if (empty($id))
4188
+	foreach ($addGroups as $id => $dummy) {
4189
+			if (empty($id))
4014 4190
 			unset($addGroups[$id]);
4191
+	}
4015 4192
 	$addGroups = implode(',', array_flip($addGroups));
4016 4193
 
4017 4194
 	// Ensure that we don't cache permissions if the group is changing.
4018
-	if ($context['user']['is_owner'])
4019
-		$_SESSION['mc']['time'] = 0;
4020
-	else
4021
-		updateSettings(array('settings_updated' => time()));
4195
+	if ($context['user']['is_owner']) {
4196
+			$_SESSION['mc']['time'] = 0;
4197
+	} else {
4198
+			updateSettings(array('settings_updated' => time()));
4199
+	}
4022 4200
 
4023 4201
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4024 4202
 
@@ -4041,8 +4219,9 @@  discard block
 block discarded – undo
4041 4219
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4042 4220
 	{
4043 4221
 		// Check to ensure we're forcing SSL for authentication
4044
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
4045
-			fatal_lang_error('login_ssl_required');
4222
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
4223
+					fatal_lang_error('login_ssl_required');
4224
+		}
4046 4225
 
4047 4226
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4048 4227
 		// we do not want too much AJAX to confuse them.
@@ -4079,8 +4258,7 @@  discard block
 block discarded – undo
4079 4258
 				$context['sub_template'] = 'tfasetup_backup';
4080 4259
 
4081 4260
 				return;
4082
-			}
4083
-			else
4261
+			} else
4084 4262
 			{
4085 4263
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4086 4264
 				$context['tfa_error'] = !$valid_code;
@@ -4088,8 +4266,7 @@  discard block
 block discarded – undo
4088 4266
 				$context['tfa_pass_value'] = $_POST['passwd'];
4089 4267
 				$context['tfa_value'] = $_POST['tfa_code'];
4090 4268
 			}
4091
-		}
4092
-		else
4269
+		} else
4093 4270
 		{
4094 4271
 			$totp = new \TOTP\Auth();
4095 4272
 			$secret = $totp->generateCode();
@@ -4099,17 +4276,16 @@  discard block
 block discarded – undo
4099 4276
 		}
4100 4277
 
4101 4278
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4102
-	}
4103
-	elseif (isset($_REQUEST['disable']))
4279
+	} elseif (isset($_REQUEST['disable']))
4104 4280
 	{
4105 4281
 		updateMemberData($memID, array(
4106 4282
 			'tfa_secret' => '',
4107 4283
 			'tfa_backup' => '',
4108 4284
 		));
4109 4285
 		redirectexit('action=profile;area=account;u=' . $memID);
4286
+	} else {
4287
+			redirectexit('action=profile;area=account;u=' . $memID);
4288
+	}
4110 4289
 	}
4111
-	else
4112
-		redirectexit('action=profile;area=account;u=' . $memID);
4113
-}
4114 4290
 
4115 4291
 ?>
4116 4292
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Themes.php 1 patch
Braces   +348 added lines, -271 removed lines patch added patch discarded remove patch
@@ -30,8 +30,9 @@  discard block
 block discarded – undo
30 30
  * @version 2.1 Beta 4
31 31
  */
32 32
 
33
-if (!defined('SMF'))
33
+if (!defined('SMF')) {
34 34
 	die('No direct access...');
35
+}
35 36
 
36 37
 /**
37 38
  * Subaction handler - manages the action and delegates control to the proper
@@ -103,12 +104,12 @@  discard block
 block discarded – undo
103 104
 	cache_put_data('minimized_css', null);
104 105
 
105 106
 	// Follow the sa or just go to administration.
106
-	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']]))
107
-		call_helper($subActions[$_GET['sa']]);
108
-
109
-	else
110
-		call_helper($subActions['admin']);
111
-}
107
+	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) {
108
+			call_helper($subActions[$_GET['sa']]);
109
+	} else {
110
+			call_helper($subActions['admin']);
111
+	}
112
+	}
112 113
 
113 114
 /**
114 115
  * This function allows administration of themes and their settings,
@@ -130,15 +131,16 @@  discard block
 block discarded – undo
130 131
 		checkSession();
131 132
 		validateToken('admin-tm');
132 133
 
133
-		if (isset($_POST['options']['known_themes']))
134
-			foreach ($_POST['options']['known_themes'] as $key => $id)
134
+		if (isset($_POST['options']['known_themes'])) {
135
+					foreach ($_POST['options']['known_themes'] as $key => $id)
135 136
 				$_POST['options']['known_themes'][$key] = (int) $id;
137
+		} else {
138
+					fatal_lang_error('themes_none_selectable', false);
139
+		}
136 140
 
137
-		else
138
-			fatal_lang_error('themes_none_selectable', false);
139
-
140
-		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes']))
141
-			fatal_lang_error('themes_default_selectable', false);
141
+		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) {
142
+					fatal_lang_error('themes_default_selectable', false);
143
+		}
142 144
 
143 145
 		// Commit the new settings.
144 146
 		updateSettings(array(
@@ -146,8 +148,9 @@  discard block
 block discarded – undo
146 148
 			'theme_guests' => $_POST['options']['theme_guests'],
147 149
 			'knownThemes' => implode(',', $_POST['options']['known_themes']),
148 150
 		));
149
-		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes']))
150
-			updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
151
+		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) {
152
+					updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
153
+		}
151 154
 
152 155
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=admin');
153 156
 	}
@@ -166,8 +169,9 @@  discard block
 block discarded – undo
166 169
 	// Look for a non existent theme directory. (ie theme87.)
167 170
 	$theme_dir = $boarddir . '/Themes/theme';
168 171
 	$i = 1;
169
-	while (file_exists($theme_dir . $i))
170
-		$i++;
172
+	while (file_exists($theme_dir . $i)) {
173
+			$i++;
174
+	}
171 175
 
172 176
 	$context['new_theme_name'] = 'theme' . $i;
173 177
 
@@ -189,8 +193,9 @@  discard block
 block discarded – undo
189 193
 	loadLanguage('Admin');
190 194
 	isAllowedTo('admin_forum');
191 195
 
192
-	if (isset($_REQUEST['th']))
193
-		return SetThemeSettings();
196
+	if (isset($_REQUEST['th'])) {
197
+			return SetThemeSettings();
198
+	}
194 199
 
195 200
 	if (isset($_POST['save']))
196 201
 	{
@@ -274,12 +279,13 @@  discard block
 block discarded – undo
274 279
 		$context['themes'] = array();
275 280
 		while ($row = $smcFunc['db_fetch_assoc']($request))
276 281
 		{
277
-			if (!isset($context['themes'][$row['id_theme']]))
278
-				$context['themes'][$row['id_theme']] = array(
282
+			if (!isset($context['themes'][$row['id_theme']])) {
283
+							$context['themes'][$row['id_theme']] = array(
279 284
 					'id' => $row['id_theme'],
280 285
 					'num_default_options' => 0,
281 286
 					'num_members' => 0,
282 287
 				);
288
+			}
283 289
 			$context['themes'][$row['id_theme']][$row['variable']] = $row['value'];
284 290
 		}
285 291
 		$smcFunc['db_free_result']($request);
@@ -293,8 +299,9 @@  discard block
 block discarded – undo
293 299
 				'guest_member' => -1,
294 300
 			)
295 301
 		);
296
-		while ($row = $smcFunc['db_fetch_assoc']($request))
297
-			$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
302
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
303
+					$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
304
+		}
298 305
 		$smcFunc['db_free_result']($request);
299 306
 
300 307
 		// Need to make sure we don't do custom fields.
@@ -305,8 +312,9 @@  discard block
 block discarded – undo
305 312
 			)
306 313
 		);
307 314
 		$customFields = array();
308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
309
-			$customFields[] = $row['col_name'];
315
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
316
+					$customFields[] = $row['col_name'];
317
+		}
310 318
 		$smcFunc['db_free_result']($request);
311 319
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
312 320
 
@@ -321,14 +329,16 @@  discard block
 block discarded – undo
321 329
 				'custom_fields' => empty($customFields) ? array() : $customFields,
322 330
 			)
323 331
 		);
324
-		while ($row = $smcFunc['db_fetch_assoc']($request))
325
-			$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
332
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
333
+					$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
334
+		}
326 335
 		$smcFunc['db_free_result']($request);
327 336
 
328 337
 		// There has to be a Settings template!
329
-		foreach ($context['themes'] as $k => $v)
330
-			if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
338
+		foreach ($context['themes'] as $k => $v) {
339
+					if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
331 340
 				unset($context['themes'][$k]);
341
+		}
332 342
 
333 343
 		loadTemplate('Themes');
334 344
 		$context['sub_template'] = 'reset_list';
@@ -343,16 +353,19 @@  discard block
 block discarded – undo
343 353
 		checkSession();
344 354
 		validateToken('admin-sto');
345 355
 
346
-		if (empty($_POST['options']))
347
-			$_POST['options'] = array();
348
-		if (empty($_POST['default_options']))
349
-			$_POST['default_options'] = array();
356
+		if (empty($_POST['options'])) {
357
+					$_POST['options'] = array();
358
+		}
359
+		if (empty($_POST['default_options'])) {
360
+					$_POST['default_options'] = array();
361
+		}
350 362
 
351 363
 		// Set up the sql query.
352 364
 		$setValues = array();
353 365
 
354
-		foreach ($_POST['options'] as $opt => $val)
355
-			$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
366
+		foreach ($_POST['options'] as $opt => $val) {
367
+					$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
368
+		}
356 369
 
357 370
 		$old_settings = array();
358 371
 		foreach ($_POST['default_options'] as $opt => $val)
@@ -366,8 +379,8 @@  discard block
 block discarded – undo
366 379
 		if (!empty($setValues))
367 380
 		{
368 381
 			// Are there options in non-default themes set that should be cleared?
369
-			if (!empty($old_settings))
370
-				$smcFunc['db_query']('', '
382
+			if (!empty($old_settings)) {
383
+							$smcFunc['db_query']('', '
371 384
 					DELETE FROM {db_prefix}themes
372 385
 					WHERE id_theme != {int:default_theme}
373 386
 						AND id_member = {int:guest_member}
@@ -378,6 +391,7 @@  discard block
 block discarded – undo
378 391
 						'old_settings' => $old_settings,
379 392
 					)
380 393
 				);
394
+			}
381 395
 
382 396
 			$smcFunc['db_insert']('replace',
383 397
 				'{db_prefix}themes',
@@ -391,8 +405,7 @@  discard block
 block discarded – undo
391 405
 		cache_put_data('theme_settings-1', null, 90);
392 406
 
393 407
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
394
-	}
395
-	elseif (isset($_POST['submit']) && $_POST['who'] == 1)
408
+	} elseif (isset($_POST['submit']) && $_POST['who'] == 1)
396 409
 	{
397 410
 		checkSession();
398 411
 		validateToken('admin-sto');
@@ -405,9 +418,9 @@  discard block
 block discarded – undo
405 418
 		$old_settings = array();
406 419
 		foreach ($_POST['default_options'] as $opt => $val)
407 420
 		{
408
-			if ($_POST['default_options_master'][$opt] == 0)
409
-				continue;
410
-			elseif ($_POST['default_options_master'][$opt] == 1)
421
+			if ($_POST['default_options_master'][$opt] == 0) {
422
+							continue;
423
+			} elseif ($_POST['default_options_master'][$opt] == 1)
411 424
 			{
412 425
 				// Delete then insert for ease of database compatibility!
413 426
 				$smcFunc['db_query']('substring', '
@@ -433,8 +446,7 @@  discard block
 block discarded – undo
433 446
 				);
434 447
 
435 448
 				$old_settings[] = $opt;
436
-			}
437
-			elseif ($_POST['default_options_master'][$opt] == 2)
449
+			} elseif ($_POST['default_options_master'][$opt] == 2)
438 450
 			{
439 451
 				$smcFunc['db_query']('', '
440 452
 					DELETE FROM {db_prefix}themes
@@ -449,8 +461,8 @@  discard block
 block discarded – undo
449 461
 		}
450 462
 
451 463
 		// Delete options from other themes.
452
-		if (!empty($old_settings))
453
-			$smcFunc['db_query']('', '
464
+		if (!empty($old_settings)) {
465
+					$smcFunc['db_query']('', '
454 466
 				DELETE FROM {db_prefix}themes
455 467
 				WHERE id_theme != {int:default_theme}
456 468
 					AND id_member > {int:no_member}
@@ -461,12 +473,13 @@  discard block
 block discarded – undo
461 473
 					'old_settings' => $old_settings,
462 474
 				)
463 475
 			);
476
+		}
464 477
 
465 478
 		foreach ($_POST['options'] as $opt => $val)
466 479
 		{
467
-			if ($_POST['options_master'][$opt] == 0)
468
-				continue;
469
-			elseif ($_POST['options_master'][$opt] == 1)
480
+			if ($_POST['options_master'][$opt] == 0) {
481
+							continue;
482
+			} elseif ($_POST['options_master'][$opt] == 1)
470 483
 			{
471 484
 				// Delete then insert for ease of database compatibility - again!
472 485
 				$smcFunc['db_query']('substring', '
@@ -491,8 +504,7 @@  discard block
 block discarded – undo
491 504
 						'value' => (is_array($val) ? implode(',', $val) : $val),
492 505
 					)
493 506
 				);
494
-			}
495
-			elseif ($_POST['options_master'][$opt] == 2)
507
+			} elseif ($_POST['options_master'][$opt] == 2)
496 508
 			{
497 509
 				$smcFunc['db_query']('', '
498 510
 					DELETE FROM {db_prefix}themes
@@ -509,8 +521,7 @@  discard block
 block discarded – undo
509 521
 		}
510 522
 
511 523
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
512
-	}
513
-	elseif (!empty($_GET['who']) && $_GET['who'] == 2)
524
+	} elseif (!empty($_GET['who']) && $_GET['who'] == 2)
514 525
 	{
515 526
 		checkSession('get');
516 527
 		validateToken('admin-stor', 'request');
@@ -525,8 +536,9 @@  discard block
 block discarded – undo
525 536
 				)
526 537
 			);
527 538
 			$customFields = array();
528
-			while ($row = $smcFunc['db_fetch_assoc']($request))
529
-				$customFields[] = $row['col_name'];
539
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
540
+							$customFields[] = $row['col_name'];
541
+			}
530 542
 			$smcFunc['db_free_result']($request);
531 543
 		}
532 544
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
@@ -581,13 +593,13 @@  discard block
 block discarded – undo
581 593
 			)
582 594
 		);
583 595
 		$context['theme_options'] = array();
584
-		while ($row = $smcFunc['db_fetch_assoc']($request))
585
-			$context['theme_options'][$row['variable']] = $row['value'];
596
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
597
+					$context['theme_options'][$row['variable']] = $row['value'];
598
+		}
586 599
 		$smcFunc['db_free_result']($request);
587 600
 
588 601
 		$context['theme_options_reset'] = false;
589
-	}
590
-	else
602
+	} else
591 603
 	{
592 604
 		$context['theme_options'] = array();
593 605
 		$context['theme_options_reset'] = true;
@@ -596,30 +608,32 @@  discard block
 block discarded – undo
596 608
 	foreach ($context['options'] as $i => $setting)
597 609
 	{
598 610
 		// Just skip separators
599
-		if (!is_array($setting))
600
-			continue;
611
+		if (!is_array($setting)) {
612
+					continue;
613
+		}
601 614
 
602 615
 		// Is this disabled?
603 616
 		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled']))
604 617
 		{
605 618
 			unset($context['options'][$i]);
606 619
 			continue;
607
-		}
608
-		elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
620
+		} elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
609 621
 		{
610 622
 			unset($context['options'][$i]);
611 623
 			continue;
612 624
 		}
613 625
 
614
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
615
-			$context['options'][$i]['type'] = 'checkbox';
616
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
617
-			$context['options'][$i]['type'] = 'number';
618
-		elseif ($setting['type'] == 'string')
619
-			$context['options'][$i]['type'] = 'text';
626
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
627
+					$context['options'][$i]['type'] = 'checkbox';
628
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
629
+					$context['options'][$i]['type'] = 'number';
630
+		} elseif ($setting['type'] == 'string') {
631
+					$context['options'][$i]['type'] = 'text';
632
+		}
620 633
 
621
-		if (isset($setting['options']))
622
-			$context['options'][$i]['type'] = 'list';
634
+		if (isset($setting['options'])) {
635
+					$context['options'][$i]['type'] = 'list';
636
+		}
623 637
 
624 638
 		$context['options'][$i]['value'] = !isset($context['theme_options'][$setting['id']]) ? '' : $context['theme_options'][$setting['id']];
625 639
 	}
@@ -644,8 +658,9 @@  discard block
 block discarded – undo
644 658
 {
645 659
 	global $txt, $context, $settings, $modSettings, $smcFunc;
646 660
 
647
-	if (empty($_GET['th']) && empty($_GET['id']))
648
-		return ThemeAdmin();
661
+	if (empty($_GET['th']) && empty($_GET['id'])) {
662
+			return ThemeAdmin();
663
+	}
649 664
 
650 665
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
651 666
 
@@ -656,8 +671,9 @@  discard block
 block discarded – undo
656 671
 	isAllowedTo('admin_forum');
657 672
 
658 673
 	// Validate inputs/user.
659
-	if (empty($_GET['th']))
660
-		fatal_lang_error('no_theme', false);
674
+	if (empty($_GET['th'])) {
675
+			fatal_lang_error('no_theme', false);
676
+	}
661 677
 
662 678
 	// Fetch the smiley sets...
663 679
 	$sets = explode(',', 'none,' . $modSettings['smiley_sets_known']);
@@ -665,8 +681,9 @@  discard block
 block discarded – undo
665 681
 	$context['smiley_sets'] = array(
666 682
 		'' => $txt['smileys_no_default']
667 683
 	);
668
-	foreach ($sets as $i => $set)
669
-		$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
684
+	foreach ($sets as $i => $set) {
685
+			$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
686
+	}
670 687
 
671 688
 	$old_id = $settings['theme_id'];
672 689
 	$old_settings = $settings;
@@ -691,8 +708,9 @@  discard block
 block discarded – undo
691 708
 	if (file_exists($settings['theme_dir'] . '/index.template.php'))
692 709
 	{
693 710
 		$file_contents = implode('', file($settings['theme_dir'] . '/index.template.php'));
694
-		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches))
695
-				eval('global $settings;' . $matches[0]);
711
+		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) {
712
+						eval('global $settings;' . $matches[0]);
713
+		}
696 714
 	}
697 715
 
698 716
 	// Let mods hook into the theme settings.
@@ -704,37 +722,45 @@  discard block
 block discarded – undo
704 722
 		checkSession();
705 723
 		validateToken('admin-sts');
706 724
 
707
-		if (empty($_POST['options']))
708
-			$_POST['options'] = array();
709
-		if (empty($_POST['default_options']))
710
-			$_POST['default_options'] = array();
725
+		if (empty($_POST['options'])) {
726
+					$_POST['options'] = array();
727
+		}
728
+		if (empty($_POST['default_options'])) {
729
+					$_POST['default_options'] = array();
730
+		}
711 731
 
712 732
 		// Make sure items are cast correctly.
713 733
 		foreach ($context['theme_settings'] as $item)
714 734
 		{
715 735
 			// Disregard this item if this is just a separator.
716
-			if (!is_array($item))
717
-				continue;
736
+			if (!is_array($item)) {
737
+							continue;
738
+			}
718 739
 
719 740
 			foreach (array('options', 'default_options') as $option)
720 741
 			{
721
-				if (!isset($_POST[$option][$item['id']]))
722
-					continue;
742
+				if (!isset($_POST[$option][$item['id']])) {
743
+									continue;
744
+				}
723 745
 				// Checkbox.
724
-				elseif (empty($item['type']))
725
-					$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
746
+				elseif (empty($item['type'])) {
747
+									$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
748
+				}
726 749
 				// Number
727
-				elseif ($item['type'] == 'number')
728
-					$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
750
+				elseif ($item['type'] == 'number') {
751
+									$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
752
+				}
729 753
 			}
730 754
 		}
731 755
 
732 756
 		// Set up the sql query.
733 757
 		$inserts = array();
734
-		foreach ($_POST['options'] as $opt => $val)
735
-			$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
736
-		foreach ($_POST['default_options'] as $opt => $val)
737
-			$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
758
+		foreach ($_POST['options'] as $opt => $val) {
759
+					$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
760
+		}
761
+		foreach ($_POST['default_options'] as $opt => $val) {
762
+					$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
763
+		}
738 764
 		// If we're actually inserting something..
739 765
 		if (!empty($inserts))
740 766
 		{
@@ -760,8 +786,9 @@  discard block
 block discarded – undo
760 786
 
761 787
 	foreach ($settings as $setting => $dummy)
762 788
 	{
763
-		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs')))
764
-			$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
789
+		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) {
790
+					$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
791
+		}
765 792
 	}
766 793
 
767 794
 	$context['settings'] = $context['theme_settings'];
@@ -770,18 +797,21 @@  discard block
 block discarded – undo
770 797
 	foreach ($context['settings'] as $i => $setting)
771 798
 	{
772 799
 		// Separators are dummies, so leave them alone.
773
-		if (!is_array($setting))
774
-			continue;
800
+		if (!is_array($setting)) {
801
+					continue;
802
+		}
775 803
 
776
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
777
-			$context['settings'][$i]['type'] = 'checkbox';
778
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
779
-			$context['settings'][$i]['type'] = 'number';
780
-		elseif ($setting['type'] == 'string')
781
-			$context['settings'][$i]['type'] = 'text';
804
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
805
+					$context['settings'][$i]['type'] = 'checkbox';
806
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
807
+					$context['settings'][$i]['type'] = 'number';
808
+		} elseif ($setting['type'] == 'string') {
809
+					$context['settings'][$i]['type'] = 'text';
810
+		}
782 811
 
783
-		if (isset($setting['options']))
784
-			$context['settings'][$i]['type'] = 'list';
812
+		if (isset($setting['options'])) {
813
+					$context['settings'][$i]['type'] = 'list';
814
+		}
785 815
 
786 816
 		$context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']];
787 817
 	}
@@ -834,8 +864,9 @@  discard block
 block discarded – undo
834 864
 	$themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
835 865
 
836 866
 	// You can't delete the default theme!
837
-	if ($themeID == 1)
838
-		fatal_lang_error('no_access', false);
867
+	if ($themeID == 1) {
868
+			fatal_lang_error('no_access', false);
869
+	}
839 870
 
840 871
 	$theme_info = get_single_theme($themeID);
841 872
 
@@ -843,8 +874,9 @@  discard block
 block discarded – undo
843 874
 	remove_theme($themeID);
844 875
 
845 876
 	// And remove all its files and folders too.
846
-	if (!empty($theme_info) && !empty($theme_info['theme_dir']))
847
-		remove_dir($theme_info['theme_dir']);
877
+	if (!empty($theme_info) && !empty($theme_info['theme_dir'])) {
878
+			remove_dir($theme_info['theme_dir']);
879
+	}
848 880
 
849 881
 	// Go back to the list page.
850 882
 	redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id'] . ';done=removing');
@@ -869,12 +901,14 @@  discard block
 block discarded – undo
869 901
 	$enableThemes = explode(',', $modSettings['enableThemes']);
870 902
 
871 903
 	// Are we disabling it?
872
-	if (isset($_GET['disabled']))
873
-		$enableThemes = array_diff($enableThemes, array($themeID));
904
+	if (isset($_GET['disabled'])) {
905
+			$enableThemes = array_diff($enableThemes, array($themeID));
906
+	}
874 907
 
875 908
 	// Nope? then enable it!
876
-	else
877
-		$enableThemes[] = (string) $themeID;
909
+	else {
910
+			$enableThemes[] = (string) $themeID;
911
+	}
878 912
 
879 913
 	// Update the setting.
880 914
 	$enableThemes = strtr(implode(',', $enableThemes), array(',,' => ','));
@@ -909,18 +943,21 @@  discard block
 block discarded – undo
909 943
 
910 944
 	$_SESSION['id_theme'] = 0;
911 945
 
912
-	if (isset($_GET['id']))
913
-		$_GET['th'] = $_GET['id'];
946
+	if (isset($_GET['id'])) {
947
+			$_GET['th'] = $_GET['id'];
948
+	}
914 949
 
915 950
 	// Saving a variant cause JS doesn't work - pretend it did ;)
916 951
 	if (isset($_POST['save']))
917 952
 	{
918 953
 		// Which theme?
919
-		foreach ($_POST['save'] as $k => $v)
920
-			$_GET['th'] = (int) $k;
954
+		foreach ($_POST['save'] as $k => $v) {
955
+					$_GET['th'] = (int) $k;
956
+		}
921 957
 
922
-		if (isset($_POST['vrt'][$k]))
923
-			$_GET['vrt'] = $_POST['vrt'][$k];
958
+		if (isset($_POST['vrt'][$k])) {
959
+					$_GET['vrt'] = $_POST['vrt'][$k];
960
+		}
924 961
 	}
925 962
 
926 963
 	// Have we made a decision, or are we just browsing?
@@ -998,8 +1035,9 @@  discard block
 block discarded – undo
998 1035
 		else
999 1036
 		{
1000 1037
 			// The forum's default theme is always 0 and we
1001
-			if (isset($_GET['th']) && $_GET['th'] == 0)
1002
-					$_GET['th'] = $modSettings['theme_guests'];
1038
+			if (isset($_GET['th']) && $_GET['th'] == 0) {
1039
+								$_GET['th'] = $modSettings['theme_guests'];
1040
+			}
1003 1041
 
1004 1042
 			updateMemberData((int) $_REQUEST['u'], array('id_theme' => (int) $_GET['th']));
1005 1043
 
@@ -1013,8 +1051,9 @@  discard block
 block discarded – undo
1013 1051
 				);
1014 1052
 				cache_put_data('theme_settings-' . $_GET['th'] . ':' . (int) $_REQUEST['u'], null, 90);
1015 1053
 
1016
-				if ($user_info['id'] == $_REQUEST['u'])
1017
-					$_SESSION['id_variant'] = 0;
1054
+				if ($user_info['id'] == $_REQUEST['u']) {
1055
+									$_SESSION['id_variant'] = 0;
1056
+				}
1018 1057
 			}
1019 1058
 
1020 1059
 			redirectexit('action=profile;u=' . (int) $_REQUEST['u'] . ';area=theme');
@@ -1083,12 +1122,13 @@  discard block
 block discarded – undo
1083 1122
 		);
1084 1123
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1085 1124
 		{
1086
-			if (!isset($context['available_themes'][$row['id_theme']]))
1087
-				$context['available_themes'][$row['id_theme']] = array(
1125
+			if (!isset($context['available_themes'][$row['id_theme']])) {
1126
+							$context['available_themes'][$row['id_theme']] = array(
1088 1127
 					'id' => $row['id_theme'],
1089 1128
 					'selected' => $context['current_theme'] == $row['id_theme'],
1090 1129
 					'num_users' => 0
1091 1130
 				);
1131
+			}
1092 1132
 			$context['available_themes'][$row['id_theme']][$row['variable']] = $row['value'];
1093 1133
 		}
1094 1134
 		$smcFunc['db_free_result']($request);
@@ -1101,9 +1141,9 @@  discard block
 block discarded – undo
1101 1141
 			'num_users' => 0
1102 1142
 		);
1103 1143
 		$guest_theme = 0;
1144
+	} else {
1145
+			$guest_theme = $modSettings['theme_guests'];
1104 1146
 	}
1105
-	else
1106
-		$guest_theme = $modSettings['theme_guests'];
1107 1147
 
1108 1148
 	$request = $smcFunc['db_query']('', '
1109 1149
 		SELECT id_theme, COUNT(*) AS the_count
@@ -1116,15 +1156,17 @@  discard block
 block discarded – undo
1116 1156
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1117 1157
 	{
1118 1158
 		// Figure out which theme it is they are REALLY using.
1119
-		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes'])))
1120
-			$row['id_theme'] = $guest_theme;
1121
-		elseif (empty($modSettings['theme_allow']))
1122
-			$row['id_theme'] = $guest_theme;
1159
+		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) {
1160
+					$row['id_theme'] = $guest_theme;
1161
+		} elseif (empty($modSettings['theme_allow'])) {
1162
+					$row['id_theme'] = $guest_theme;
1163
+		}
1123 1164
 
1124
-		if (isset($context['available_themes'][$row['id_theme']]))
1125
-			$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1126
-		else
1127
-			$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1165
+		if (isset($context['available_themes'][$row['id_theme']])) {
1166
+					$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1167
+		} else {
1168
+					$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1169
+		}
1128 1170
 	}
1129 1171
 	$smcFunc['db_free_result']($request);
1130 1172
 
@@ -1143,8 +1185,9 @@  discard block
 block discarded – undo
1143 1185
 				'id_member' => isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? array(-1, $context['current_member']) : array(-1),
1144 1186
 			)
1145 1187
 		);
1146
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1147
-			$variant_preferences[$row['id_theme']] = $row['value'];
1188
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1189
+					$variant_preferences[$row['id_theme']] = $row['value'];
1190
+		}
1148 1191
 		$smcFunc['db_free_result']($request);
1149 1192
 	}
1150 1193
 
@@ -1155,17 +1198,18 @@  discard block
 block discarded – undo
1155 1198
 	foreach ($context['available_themes'] as $id_theme => $theme_data)
1156 1199
 	{
1157 1200
 		// Don't try to load the forum or board default theme's data... it doesn't have any!
1158
-		if ($id_theme == 0)
1159
-			continue;
1201
+		if ($id_theme == 0) {
1202
+					continue;
1203
+		}
1160 1204
 
1161 1205
 		// The thumbnail needs the correct path.
1162 1206
 		$settings['images_url'] = &$theme_data['images_url'];
1163 1207
 
1164
-		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'))
1165
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1166
-		elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'))
1167
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1168
-		else
1208
+		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) {
1209
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1210
+		} elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) {
1211
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1212
+		} else
1169 1213
 		{
1170 1214
 			$txt['theme_thumbnail_href'] = $theme_data['images_url'] . '/thumbnail.png';
1171 1215
 			$txt['theme_description'] = '';
@@ -1190,15 +1234,17 @@  discard block
 block discarded – undo
1190 1234
 					loadLanguage('Settings');
1191 1235
 
1192 1236
 					$context['available_themes'][$id_theme]['variants'] = array();
1193
-					foreach ($settings['theme_variants'] as $variant)
1194
-						$context['available_themes'][$id_theme]['variants'][$variant] = array(
1237
+					foreach ($settings['theme_variants'] as $variant) {
1238
+											$context['available_themes'][$id_theme]['variants'][$variant] = array(
1195 1239
 							'label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant,
1196 1240
 							'thumbnail' => !file_exists($theme_data['theme_dir'] . '/images/thumbnail.png') || file_exists($theme_data['theme_dir'] . '/images/thumbnail_' . $variant . '.png') ? $theme_data['images_url'] . '/thumbnail_' . $variant . '.png' : ($theme_data['images_url'] . '/thumbnail.png'),
1197 1241
 						);
1242
+					}
1198 1243
 
1199 1244
 					$context['available_themes'][$id_theme]['selected_variant'] = isset($_GET['vrt']) ? $_GET['vrt'] : (!empty($variant_preferences[$id_theme]) ? $variant_preferences[$id_theme] : (!empty($settings['default_variant']) ? $settings['default_variant'] : $settings['theme_variants'][0]));
1200
-					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail']))
1201
-						$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1245
+					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) {
1246
+											$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1247
+					}
1202 1248
 
1203 1249
 					$context['available_themes'][$id_theme]['thumbnail_href'] = $context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'];
1204 1250
 					// Allow themes to override the text.
@@ -1214,8 +1260,9 @@  discard block
 block discarded – undo
1214 1260
 	// As long as we're not doing the default theme...
1215 1261
 	if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0)
1216 1262
 	{
1217
-		if ($guest_theme != 0)
1218
-			$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1263
+		if ($guest_theme != 0) {
1264
+					$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1265
+		}
1219 1266
 
1220 1267
 		$context['available_themes'][0]['id'] = 0;
1221 1268
 		$context['available_themes'][0]['name'] = $txt['theme_forum_default'];
@@ -1264,14 +1311,16 @@  discard block
 block discarded – undo
1264 1311
 		$action = $smcFunc['htmlspecialchars'](trim($_GET['do']));
1265 1312
 
1266 1313
 		// Got any info from the specific form?
1267
-		if (!isset($_POST['save_' . $action]))
1268
-			fatal_lang_error('theme_install_no_action', false);
1314
+		if (!isset($_POST['save_' . $action])) {
1315
+					fatal_lang_error('theme_install_no_action', false);
1316
+		}
1269 1317
 
1270 1318
 		validateToken('admin-t-' . $action);
1271 1319
 
1272 1320
 		// Hopefully the themes directory is writable, or we might have a problem.
1273
-		if (!is_writable($themedir))
1274
-			fatal_lang_error('theme_install_write_error', 'critical');
1321
+		if (!is_writable($themedir)) {
1322
+					fatal_lang_error('theme_install_write_error', 'critical');
1323
+		}
1275 1324
 
1276 1325
 		// Call the function and handle the result.
1277 1326
 		$result = $subActions[$action]();
@@ -1286,9 +1335,10 @@  discard block
 block discarded – undo
1286 1335
 	}
1287 1336
 
1288 1337
 	// Nope, show a nice error.
1289
-	else
1290
-		fatal_lang_error('theme_install_no_action', false);
1291
-}
1338
+	else {
1339
+			fatal_lang_error('theme_install_no_action', false);
1340
+	}
1341
+	}
1292 1342
 
1293 1343
 /**
1294 1344
  * Installs a theme from a theme package.
@@ -1304,8 +1354,9 @@  discard block
 block discarded – undo
1304 1354
 	$dirtemp = $themedir . '/temp';
1305 1355
 
1306 1356
 	// Make sure the temp dir doesn't already exist
1307
-	if (file_exists($dirtemp))
1308
-		remove_dir($dirtemp);
1357
+	if (file_exists($dirtemp)) {
1358
+			remove_dir($dirtemp);
1359
+	}
1309 1360
 
1310 1361
 	// Create the temp dir.
1311 1362
 	mkdir($dirtemp, 0777);
@@ -1317,17 +1368,20 @@  discard block
 block discarded – undo
1317 1368
 		smf_chmod($dirtemp, '0755');
1318 1369
 
1319 1370
 		// How about now?
1320
-		if (!is_writable($dirtemp))
1321
-			fatal_lang_error('theme_install_write_error', 'critical');
1371
+		if (!is_writable($dirtemp)) {
1372
+					fatal_lang_error('theme_install_write_error', 'critical');
1373
+		}
1322 1374
 	}
1323 1375
 
1324 1376
 	// This happens when the admin session is gone and the user has to login again.
1325
-	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz']))
1326
-		redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1377
+	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) {
1378
+			redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1379
+	}
1327 1380
 
1328 1381
 	// Another error check layer, something went wrong with the upload.
1329
-	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0)
1330
-		fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1382
+	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) {
1383
+			fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1384
+	}
1331 1385
 
1332 1386
 	// Get the theme's name.
1333 1387
 	$name = pathinfo($_FILES['theme_gz']['name'], PATHINFO_FILENAME);
@@ -1358,11 +1412,10 @@  discard block
 block discarded – undo
1358 1412
 
1359 1413
 		// return all the info.
1360 1414
 		return $context['to_install'];
1415
+	} else {
1416
+			fatal_lang_error('theme_install_error_title', false);
1417
+	}
1361 1418
 	}
1362
-
1363
-	else
1364
-		fatal_lang_error('theme_install_error_title', false);
1365
-}
1366 1419
 
1367 1420
 /**
1368 1421
  * Makes a copy from the default theme, assigns a name for it and installs it.
@@ -1376,15 +1429,17 @@  discard block
 block discarded – undo
1376 1429
 	global $forum_version;
1377 1430
 
1378 1431
 	// There's gotta be something to work with.
1379
-	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy']))
1380
-		fatal_lang_error('theme_install_error_title', false);
1432
+	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) {
1433
+			fatal_lang_error('theme_install_error_title', false);
1434
+	}
1381 1435
 
1382 1436
 	// Get a cleaner version.
1383 1437
 	$name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']);
1384 1438
 
1385 1439
 	// Is there a theme already named like this?
1386
-	if (file_exists($themedir . '/' . $name))
1387
-		fatal_lang_error('theme_install_already_dir', false);
1440
+	if (file_exists($themedir . '/' . $name)) {
1441
+			fatal_lang_error('theme_install_already_dir', false);
1442
+	}
1388 1443
 
1389 1444
 	// This is a brand new theme so set all possible values.
1390 1445
 	$context['to_install'] = array(
@@ -1404,8 +1459,9 @@  discard block
 block discarded – undo
1404 1459
 
1405 1460
 	// Buy some time.
1406 1461
 	@set_time_limit(600);
1407
-	if (function_exists('apache_reset_timeout'))
1408
-		@apache_reset_timeout();
1462
+	if (function_exists('apache_reset_timeout')) {
1463
+			@apache_reset_timeout();
1464
+	}
1409 1465
 
1410 1466
 	// Create subdirectories for css and javascript files.
1411 1467
 	mkdir($context['to_install']['theme_dir'] . '/css', 0777);
@@ -1441,12 +1497,13 @@  discard block
 block discarded – undo
1441 1497
 
1442 1498
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1443 1499
 	{
1444
-		if ($row['variable'] == 'theme_templates')
1445
-			$theme_templates = $row['value'];
1446
-		elseif ($row['variable'] == 'theme_layers')
1447
-			$theme_layers = $row['value'];
1448
-		else
1449
-			continue;
1500
+		if ($row['variable'] == 'theme_templates') {
1501
+					$theme_templates = $row['value'];
1502
+		} elseif ($row['variable'] == 'theme_layers') {
1503
+					$theme_layers = $row['value'];
1504
+		} else {
1505
+					continue;
1506
+		}
1450 1507
 	}
1451 1508
 
1452 1509
 	$smcFunc['db_free_result']($request);
@@ -1505,12 +1562,14 @@  discard block
 block discarded – undo
1505 1562
 	global $themedir, $themeurl, $context;
1506 1563
 
1507 1564
 	// Cannot use the theme dir as a theme dir.
1508
-	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir))
1509
-		fatal_lang_error('theme_install_invalid_dir', false);
1565
+	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) {
1566
+			fatal_lang_error('theme_install_invalid_dir', false);
1567
+	}
1510 1568
 
1511 1569
 	// Check is there is "something" on the dir.
1512
-	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml'))
1513
-		fatal_lang_error('theme_install_error', false);
1570
+	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) {
1571
+			fatal_lang_error('theme_install_error', false);
1572
+	}
1514 1573
 
1515 1574
 	$name = basename($_REQUEST['theme_dir']);
1516 1575
 	$name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);
@@ -1554,24 +1613,27 @@  discard block
 block discarded – undo
1554 1613
 	}
1555 1614
 
1556 1615
 	// Any special layers?
1557
-	if (isset($settings['catch_action']['layers']))
1558
-		$context['template_layers'] = $settings['catch_action']['layers'];
1616
+	if (isset($settings['catch_action']['layers'])) {
1617
+			$context['template_layers'] = $settings['catch_action']['layers'];
1618
+	}
1559 1619
 
1560 1620
 	// Any function to call?
1561 1621
 	if (isset($settings['catch_action']['function']))
1562 1622
 	{
1563 1623
 		$hook = $settings['catch_action']['function'];
1564 1624
 
1565
-		if (!isset($settings['catch_action']['filename']))
1566
-			$settings['catch_action']['filename'] = '';
1625
+		if (!isset($settings['catch_action']['filename'])) {
1626
+					$settings['catch_action']['filename'] = '';
1627
+		}
1567 1628
 
1568 1629
 		add_integration_function('integrate_wrap_action', $hook, false, $settings['catch_action']['filename'], false);
1569 1630
 		call_integration_hook('integrate_wrap_action');
1570 1631
 	}
1571 1632
 	// And finally, the main sub template ;).
1572
-	if (isset($settings['catch_action']['sub_template']))
1573
-		$context['sub_template'] = $settings['catch_action']['sub_template'];
1574
-}
1633
+	if (isset($settings['catch_action']['sub_template'])) {
1634
+			$context['sub_template'] = $settings['catch_action']['sub_template'];
1635
+	}
1636
+	}
1575 1637
 
1576 1638
 /**
1577 1639
  * Set an option via javascript.
@@ -1590,12 +1652,14 @@  discard block
 block discarded – undo
1590 1652
 	checkSession('get');
1591 1653
 
1592 1654
 	// This good-for-nothing pixel is being used to keep the session alive.
1593
-	if (empty($_GET['var']) || !isset($_GET['val']))
1594
-		redirectexit($settings['images_url'] . '/blank.png');
1655
+	if (empty($_GET['var']) || !isset($_GET['val'])) {
1656
+			redirectexit($settings['images_url'] . '/blank.png');
1657
+	}
1595 1658
 
1596 1659
 	// Sorry, guests can't go any further than this.
1597
-	if ($user_info['is_guest'] || $user_info['id'] == 0)
1598
-		obExit(false);
1660
+	if ($user_info['is_guest'] || $user_info['id'] == 0) {
1661
+			obExit(false);
1662
+	}
1599 1663
 
1600 1664
 	$reservedVars = array(
1601 1665
 		'actual_theme_url',
@@ -1618,8 +1682,9 @@  discard block
 block discarded – undo
1618 1682
 	);
1619 1683
 
1620 1684
 	// Can't change reserved vars.
1621
-	if (in_array(strtolower($_GET['var']), $reservedVars))
1622
-		redirectexit($settings['images_url'] . '/blank.png');
1685
+	if (in_array(strtolower($_GET['var']), $reservedVars)) {
1686
+			redirectexit($settings['images_url'] . '/blank.png');
1687
+	}
1623 1688
 
1624 1689
 	// Use a specific theme?
1625 1690
 	if (isset($_GET['th']) || isset($_GET['id']))
@@ -1635,8 +1700,9 @@  discard block
 block discarded – undo
1635 1700
 	{
1636 1701
 		$options['admin_preferences'] = !empty($options['admin_preferences']) ? $smcFunc['json_decode']($options['admin_preferences'], true) : array();
1637 1702
 		// New thingy...
1638
-		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5)
1639
-			$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1703
+		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) {
1704
+					$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1705
+		}
1640 1706
 
1641 1707
 		// Change the value to be something nice,
1642 1708
 		$_GET['val'] = $smcFunc['json_encode']($options['admin_preferences']);
@@ -1666,8 +1732,9 @@  discard block
 block discarded – undo
1666 1732
 	global $context, $scripturl, $boarddir, $smcFunc, $txt;
1667 1733
 
1668 1734
 	// @todo Should this be removed?
1669
-	if (isset($_REQUEST['preview']))
1670
-		die('die() with fire');
1735
+	if (isset($_REQUEST['preview'])) {
1736
+			die('die() with fire');
1737
+	}
1671 1738
 
1672 1739
 	isAllowedTo('admin_forum');
1673 1740
 	loadTemplate('Themes');
@@ -1681,11 +1748,11 @@  discard block
 block discarded – undo
1681 1748
 		foreach ($context['themes'] as $key => $theme)
1682 1749
 		{
1683 1750
 			// There has to be a Settings template!
1684
-			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css'))
1685
-				unset($context['themes'][$key]);
1686
-
1687
-			else
1688
-				$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1751
+			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) {
1752
+							unset($context['themes'][$key]);
1753
+			} else {
1754
+							$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1755
+			}
1689 1756
 		}
1690 1757
 
1691 1758
 		$context['sub_template'] = 'edit_list';
@@ -1700,22 +1767,24 @@  discard block
 block discarded – undo
1700 1767
 	$context['theme_id'] = $currentTheme['id'];
1701 1768
 	$context['browse_title'] = sprintf($txt['themeadmin_browsing_theme'], $currentTheme['name']);
1702 1769
 
1703
-	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css'))
1704
-		fatal_lang_error('theme_edit_missing', false);
1770
+	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) {
1771
+			fatal_lang_error('theme_edit_missing', false);
1772
+	}
1705 1773
 
1706 1774
 	if (!isset($_REQUEST['filename']))
1707 1775
 	{
1708 1776
 		if (isset($_GET['directory']))
1709 1777
 		{
1710
-			if (substr($_GET['directory'], 0, 1) == '.')
1711
-				$_GET['directory'] = '';
1712
-			else
1778
+			if (substr($_GET['directory'], 0, 1) == '.') {
1779
+							$_GET['directory'] = '';
1780
+			} else
1713 1781
 			{
1714 1782
 				$_GET['directory'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_GET['directory']);
1715 1783
 
1716 1784
 				$temp = realpath($currentTheme['theme_dir'] . '/' . $_GET['directory']);
1717
-				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1718
-					$_GET['directory'] = '';
1785
+				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1786
+									$_GET['directory'] = '';
1787
+				}
1719 1788
 			}
1720 1789
 		}
1721 1790
 
@@ -1734,37 +1803,39 @@  discard block
 block discarded – undo
1734 1803
 				'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $temp,
1735 1804
 				'size' => '',
1736 1805
 			));
1806
+		} else {
1807
+					$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1737 1808
 		}
1738
-		else
1739
-			$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1740 1809
 
1741 1810
 		$context['sub_template'] = 'edit_browse';
1742 1811
 
1743 1812
 		return;
1744
-	}
1745
-	else
1813
+	} else
1746 1814
 	{
1747
-		if (substr($_REQUEST['filename'], 0, 1) == '.')
1748
-			$_REQUEST['filename'] = '';
1749
-		else
1815
+		if (substr($_REQUEST['filename'], 0, 1) == '.') {
1816
+					$_REQUEST['filename'] = '';
1817
+		} else
1750 1818
 		{
1751 1819
 			$_REQUEST['filename'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_REQUEST['filename']);
1752 1820
 
1753 1821
 			$temp = realpath($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1754
-			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1755
-				$_REQUEST['filename'] = '';
1822
+			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1823
+							$_REQUEST['filename'] = '';
1824
+			}
1756 1825
 		}
1757 1826
 
1758
-		if (empty($_REQUEST['filename']))
1759
-			fatal_lang_error('theme_edit_missing', false);
1827
+		if (empty($_REQUEST['filename'])) {
1828
+					fatal_lang_error('theme_edit_missing', false);
1829
+		}
1760 1830
 	}
1761 1831
 
1762 1832
 	if (isset($_POST['save']))
1763 1833
 	{
1764 1834
 		if (checkSession('post', '', false) == '' && validateToken('admin-te-' . md5($_GET['th'] . '-' . $_REQUEST['filename']), 'post', false) == true)
1765 1835
 		{
1766
-			if (is_array($_POST['entire_file']))
1767
-				$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1836
+			if (is_array($_POST['entire_file'])) {
1837
+							$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1838
+			}
1768 1839
 
1769 1840
 			$_POST['entire_file'] = rtrim(strtr($_POST['entire_file'], array("\r" => '', '   ' => "\t")));
1770 1841
 
@@ -1776,10 +1847,11 @@  discard block
 block discarded – undo
1776 1847
 				fclose($fp);
1777 1848
 
1778 1849
 				$error = @file_get_contents($currentTheme['theme_url'] . '/tmp_' . session_id() . '.php');
1779
-				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0)
1780
-					$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1781
-				else
1782
-					unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1850
+				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) {
1851
+									$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1852
+				} else {
1853
+									unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1854
+				}
1783 1855
 			}
1784 1856
 
1785 1857
 			if (!isset($error_file))
@@ -1800,10 +1872,11 @@  discard block
 block discarded – undo
1800 1872
 			$context['sub_template'] = 'edit_file';
1801 1873
 
1802 1874
 			// Recycle the submitted data.
1803
-			if (is_array($_POST['entire_file']))
1804
-				$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1805
-			else
1806
-				$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1875
+			if (is_array($_POST['entire_file'])) {
1876
+							$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1877
+			} else {
1878
+							$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1879
+			}
1807 1880
 
1808 1881
 			$context['edit_filename'] = $smcFunc['htmlspecialchars']($_POST['filename']);
1809 1882
 
@@ -1826,17 +1899,17 @@  discard block
 block discarded – undo
1826 1899
 		$context['sub_template'] = 'edit_style';
1827 1900
 
1828 1901
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(file_get_contents($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']), array("\t" => '   ')));
1829
-	}
1830
-	elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1902
+	} elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1831 1903
 	{
1832 1904
 		$context['sub_template'] = 'edit_template';
1833 1905
 
1834
-		if (!isset($error_file))
1835
-			$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1836
-		else
1906
+		if (!isset($error_file)) {
1907
+					$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1908
+		} else
1837 1909
 		{
1838
-			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0)
1839
-				$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1910
+			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) {
1911
+							$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1912
+			}
1840 1913
 			$file_data = file($error_file);
1841 1914
 			unlink($error_file);
1842 1915
 		}
@@ -1850,8 +1923,9 @@  discard block
 block discarded – undo
1850 1923
 				// Try to format the functions a little nicer...
1851 1924
 				$context['file_parts'][$j]['data'] = trim($context['file_parts'][$j]['data']) . "\n";
1852 1925
 
1853
-				if (empty($context['file_parts'][$j]['lines']))
1854
-					unset($context['file_parts'][$j]);
1926
+				if (empty($context['file_parts'][$j]['lines'])) {
1927
+									unset($context['file_parts'][$j]);
1928
+				}
1855 1929
 				$context['file_parts'][++$j] = array('lines' => 0, 'line' => $i + 1, 'data' => '');
1856 1930
 			}
1857 1931
 
@@ -1860,8 +1934,7 @@  discard block
 block discarded – undo
1860 1934
 		}
1861 1935
 
1862 1936
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(implode('', $file_data), array("\t" => '   ')));
1863
-	}
1864
-	else
1937
+	} else
1865 1938
 	{
1866 1939
 		$context['sub_template'] = 'edit_file';
1867 1940
 
@@ -1887,8 +1960,9 @@  discard block
 block discarded – undo
1887 1960
 
1888 1961
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
1889 1962
 
1890
-	if (empty($_GET['th']))
1891
-		fatal_lang_error('theme_install_invalid_id');
1963
+	if (empty($_GET['th'])) {
1964
+			fatal_lang_error('theme_install_invalid_id');
1965
+	}
1892 1966
 
1893 1967
 	// Get the theme info.
1894 1968
 	$theme = get_single_theme($_GET['th']);
@@ -1896,25 +1970,24 @@  discard block
 block discarded – undo
1896 1970
 
1897 1971
 	if (isset($_REQUEST['template']) && preg_match('~[\./\\\\:\0]~', $_REQUEST['template']) == 0)
1898 1972
 	{
1899
-		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'))
1900
-			$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1901
-
1902
-		else
1903
-			fatal_lang_error('no_access', false);
1973
+		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) {
1974
+					$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1975
+		} else {
1976
+					fatal_lang_error('no_access', false);
1977
+		}
1904 1978
 
1905 1979
 		$fp = fopen($theme['theme_dir'] . '/' . $_REQUEST['template'] . '.template.php', 'w');
1906 1980
 		fwrite($fp, file_get_contents($filename));
1907 1981
 		fclose($fp);
1908 1982
 
1909 1983
 		redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy');
1910
-	}
1911
-	elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1984
+	} elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1912 1985
 	{
1913
-		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'))
1914
-			$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1915
-
1916
-		else
1917
-			fatal_lang_error('no_access', false);
1986
+		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) {
1987
+					$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1988
+		} else {
1989
+					fatal_lang_error('no_access', false);
1990
+		}
1918 1991
 
1919 1992
 		$fp = fopen($theme['theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php', 'w');
1920 1993
 		fwrite($fp, file_get_contents($filename));
@@ -1929,16 +2002,18 @@  discard block
 block discarded – undo
1929 2002
 	$dir = dir($settings['default_theme_dir']);
1930 2003
 	while ($entry = $dir->read())
1931 2004
 	{
1932
-		if (substr($entry, -13) == '.template.php')
1933
-			$templates[] = substr($entry, 0, -13);
2005
+		if (substr($entry, -13) == '.template.php') {
2006
+					$templates[] = substr($entry, 0, -13);
2007
+		}
1934 2008
 	}
1935 2009
 	$dir->close();
1936 2010
 
1937 2011
 	$dir = dir($settings['default_theme_dir'] . '/languages');
1938 2012
 	while ($entry = $dir->read())
1939 2013
 	{
1940
-		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches))
1941
-			$lang_files[] = $matches[1];
2014
+		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) {
2015
+					$lang_files[] = $matches[1];
2016
+		}
1942 2017
 	}
1943 2018
 	$dir->close();
1944 2019
 
@@ -1946,21 +2021,23 @@  discard block
 block discarded – undo
1946 2021
 	natcasesort($lang_files);
1947 2022
 
1948 2023
 	$context['available_templates'] = array();
1949
-	foreach ($templates as $template)
1950
-		$context['available_templates'][$template] = array(
2024
+	foreach ($templates as $template) {
2025
+			$context['available_templates'][$template] = array(
1951 2026
 			'filename' => $template . '.template.php',
1952 2027
 			'value' => $template,
1953 2028
 			'already_exists' => false,
1954 2029
 			'can_copy' => is_writable($theme['theme_dir']),
1955 2030
 		);
2031
+	}
1956 2032
 	$context['available_language_files'] = array();
1957
-	foreach ($lang_files as $file)
1958
-		$context['available_language_files'][$file] = array(
2033
+	foreach ($lang_files as $file) {
2034
+			$context['available_language_files'][$file] = array(
1959 2035
 			'filename' => $file . '.php',
1960 2036
 			'value' => $file,
1961 2037
 			'already_exists' => false,
1962 2038
 			'can_copy' => file_exists($theme['theme_dir'] . '/languages') ? is_writable($theme['theme_dir'] . '/languages') : is_writable($theme['theme_dir']),
1963 2039
 		);
2040
+	}
1964 2041
 
1965 2042
 	$dir = dir($theme['theme_dir']);
1966 2043
 	while ($entry = $dir->read())
Please login to merge, or discard this patch.
Sources/Post.php 1 patch
Braces   +674 added lines, -521 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -58,12 +61,14 @@  discard block
 block discarded – undo
58 61
 	{
59 62
 		// Get ids of all the boards they can post in.
60 63
 		$post_permissions = array('post_new');
61
-		if ($modSettings['postmod_active'])
62
-			$post_permissions[] = 'post_unapproved_topics';
64
+		if ($modSettings['postmod_active']) {
65
+					$post_permissions[] = 'post_unapproved_topics';
66
+		}
63 67
 
64 68
 		$boards = boardsAllowedTo($post_permissions);
65
-		if (empty($boards))
66
-			fatal_lang_error('cannot_post_new', false);
69
+		if (empty($boards)) {
70
+					fatal_lang_error('cannot_post_new', false);
71
+		}
67 72
 
68 73
 		// Get a list of boards for the select menu
69 74
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -76,8 +81,9 @@  discard block
 block discarded – undo
76 81
 		$board_list = getBoardList($boardListOptions);
77 82
 	}
78 83
 	// Let's keep things simple for ourselves below
79
-	else
80
-		$boards = array($board);
84
+	else {
85
+			$boards = array($board);
86
+	}
81 87
 
82 88
 	require_once($sourcedir . '/Subs-Post.php');
83 89
 
@@ -100,10 +106,11 @@  discard block
 block discarded – undo
100 106
 			array(
101 107
 				'msg' => (int) $_REQUEST['msg'],
102 108
 		));
103
-		if ($smcFunc['db_num_rows']($request) != 1)
104
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
105
-		else
106
-			list ($topic) = $smcFunc['db_fetch_row']($request);
109
+		if ($smcFunc['db_num_rows']($request) != 1) {
110
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
111
+		} else {
112
+					list ($topic) = $smcFunc['db_fetch_row']($request);
113
+		}
107 114
 		$smcFunc['db_free_result']($request);
108 115
 	}
109 116
 
@@ -130,33 +137,36 @@  discard block
 block discarded – undo
130 137
 		$smcFunc['db_free_result']($request);
131 138
 
132 139
 		// If this topic already has a poll, they sure can't add another.
133
-		if (isset($_REQUEST['poll']) && $pollID > 0)
134
-			unset($_REQUEST['poll']);
140
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
141
+					unset($_REQUEST['poll']);
142
+		}
135 143
 
136 144
 		if (empty($_REQUEST['msg']))
137 145
 		{
138
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
139
-				is_not_guest();
146
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
147
+							is_not_guest();
148
+			}
140 149
 
141 150
 			// By default the reply will be approved...
142 151
 			$context['becomes_approved'] = true;
143 152
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
144 153
 			{
145
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
146
-					$context['becomes_approved'] = false;
147
-				else
148
-					isAllowedTo('post_reply_any');
149
-			}
150
-			elseif (!allowedTo('post_reply_any'))
154
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
155
+									$context['becomes_approved'] = false;
156
+				} else {
157
+									isAllowedTo('post_reply_any');
158
+				}
159
+			} elseif (!allowedTo('post_reply_any'))
151 160
 			{
152
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
153
-					$context['becomes_approved'] = false;
154
-				else
155
-					isAllowedTo('post_reply_own');
161
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
162
+									$context['becomes_approved'] = false;
163
+				} else {
164
+									isAllowedTo('post_reply_own');
165
+				}
156 166
 			}
167
+		} else {
168
+					$context['becomes_approved'] = true;
157 169
 		}
158
-		else
159
-			$context['becomes_approved'] = true;
160 170
 
161 171
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
162 172
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -171,17 +181,18 @@  discard block
 block discarded – undo
171 181
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
172 182
 
173 183
 		// Check whether this is a really old post being bumped...
174
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
175
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
176
-	}
177
-	else
184
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
185
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
186
+		}
187
+	} else
178 188
 	{
179 189
 		// @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu
180 190
 		$context['becomes_approved'] = true;
181
-		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true))
182
-			$context['becomes_approved'] = false;
183
-		else
184
-			isAllowedTo('post_new', $boards, true);
191
+		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) {
192
+					$context['becomes_approved'] = false;
193
+		} else {
194
+					isAllowedTo('post_new', $boards, true);
195
+		}
185 196
 
186 197
 		$locked = 0;
187 198
 		$context['already_locked'] = 0;
@@ -211,27 +222,32 @@  discard block
 block discarded – undo
211 222
 	if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached']))
212 223
 	{
213 224
 		require_once($sourcedir . '/ManageAttachments.php');
214
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
215
-			removeAttachments(array('id_attach' => $attachID));
225
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
226
+					removeAttachments(array('id_attach' => $attachID));
227
+		}
216 228
 
217 229
 		unset($_SESSION['already_attached']);
218 230
 	}
219 231
 
220 232
 	// Don't allow a post if it's locked and you aren't all powerful.
221
-	if ($locked && !allowedTo('moderate_board'))
222
-		fatal_lang_error('topic_locked', false);
233
+	if ($locked && !allowedTo('moderate_board')) {
234
+			fatal_lang_error('topic_locked', false);
235
+	}
223 236
 	// Check the users permissions - is the user allowed to add or post a poll?
224 237
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
225 238
 	{
226 239
 		// New topic, new poll.
227
-		if (empty($topic))
228
-			isAllowedTo('poll_post');
240
+		if (empty($topic)) {
241
+					isAllowedTo('poll_post');
242
+		}
229 243
 		// This is an old topic - but it is yours!  Can you add to it?
230
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
231
-			isAllowedTo('poll_add_own');
244
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
245
+					isAllowedTo('poll_add_own');
246
+		}
232 247
 		// If you're not the owner, can you add to any poll?
233
-		else
234
-			isAllowedTo('poll_add_any');
248
+		else {
249
+					isAllowedTo('poll_add_any');
250
+		}
235 251
 
236 252
 		if (!empty($board))
237 253
 		{
@@ -240,8 +256,9 @@  discard block
 block discarded – undo
240 256
 			$guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']);
241 257
 		}
242 258
 		// No board, so we'll have to check this again in Post2
243
-		else
244
-			$guest_vote_enabled = true;
259
+		else {
260
+					$guest_vote_enabled = true;
261
+		}
245 262
 
246 263
 		// Set up the poll options.
247 264
 		$context['poll_options'] = array(
@@ -267,8 +284,9 @@  discard block
 block discarded – undo
267 284
 	if ($context['make_event'])
268 285
 	{
269 286
 		// They might want to pick a board.
270
-		if (!isset($context['current_board']))
271
-			$context['current_board'] = 0;
287
+		if (!isset($context['current_board'])) {
288
+					$context['current_board'] = 0;
289
+		}
272 290
 
273 291
 		// Start loading up the event info.
274 292
 		$context['event'] = array();
@@ -282,10 +300,11 @@  discard block
 block discarded – undo
282 300
 		isAllowedTo('calendar_post');
283 301
 
284 302
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
285
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
286
-			$time_string = '%k:%M';
287
-		else
288
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
303
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
304
+					$time_string = '%k:%M';
305
+		} else {
306
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
307
+		}
289 308
 
290 309
 		$js_time_string = str_replace(
291 310
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -307,8 +326,7 @@  discard block
 block discarded – undo
307 326
 			require_once($sourcedir . '/Subs-Calendar.php');
308 327
 			$eventProperties = getEventProperties($context['event']['id']);
309 328
 			$context['event'] = array_merge($context['event'], $eventProperties);
310
-		}
311
-		else
329
+		} else
312 330
 		{
313 331
 			// Get the current event information.
314 332
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -316,10 +334,12 @@  discard block
 block discarded – undo
316 334
 			$context['event'] = array_merge($context['event'], $eventProperties);
317 335
 
318 336
 			// Make sure the year and month are in the valid range.
319
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
320
-				fatal_lang_error('invalid_month', false);
321
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
322
-				fatal_lang_error('invalid_year', false);
337
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
338
+							fatal_lang_error('invalid_month', false);
339
+			}
340
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
341
+							fatal_lang_error('invalid_year', false);
342
+			}
323 343
 
324 344
 			$context['event']['categories'] = $board_list;
325 345
 		}
@@ -430,10 +450,11 @@  discard block
 block discarded – undo
430 450
 
431 451
 			if (!empty($context['new_replies']))
432 452
 			{
433
-				if ($context['new_replies'] == 1)
434
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
435
-				else
436
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
453
+				if ($context['new_replies'] == 1) {
454
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
455
+				} else {
456
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
457
+				}
437 458
 
438 459
 				$post_errors[] = 'new_replies';
439 460
 
@@ -445,9 +466,9 @@  discard block
 block discarded – undo
445 466
 	// Get a response prefix (like 'Re:') in the default forum language.
446 467
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
447 468
 	{
448
-		if ($language === $user_info['language'])
449
-			$context['response_prefix'] = $txt['response_prefix'];
450
-		else
469
+		if ($language === $user_info['language']) {
470
+					$context['response_prefix'] = $txt['response_prefix'];
471
+		} else
451 472
 		{
452 473
 			loadLanguage('index', $language, false);
453 474
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -460,23 +481,26 @@  discard block
 block discarded – undo
460 481
 	// Do we have a body, but an error happened.
461 482
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
462 483
 	{
463
-		if (isset($_REQUEST['quickReply']))
464
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
484
+		if (isset($_REQUEST['quickReply'])) {
485
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
486
+		}
465 487
 
466 488
 		// Validate inputs.
467 489
 		if (empty($context['post_error']))
468 490
 		{
469 491
 			// This means they didn't click Post and get an error.
470 492
 			$really_previewing = true;
471
-		}
472
-		else
493
+		} else
473 494
 		{
474
-			if (!isset($_REQUEST['subject']))
475
-				$_REQUEST['subject'] = '';
476
-			if (!isset($_REQUEST['message']))
477
-				$_REQUEST['message'] = '';
478
-			if (!isset($_REQUEST['icon']))
479
-				$_REQUEST['icon'] = 'xx';
495
+			if (!isset($_REQUEST['subject'])) {
496
+							$_REQUEST['subject'] = '';
497
+			}
498
+			if (!isset($_REQUEST['message'])) {
499
+							$_REQUEST['message'] = '';
500
+			}
501
+			if (!isset($_REQUEST['icon'])) {
502
+							$_REQUEST['icon'] = 'xx';
503
+			}
480 504
 
481 505
 			// They are previewing if they asked to preview (i.e. came from quick reply).
482 506
 			$really_previewing = !empty($_POST['preview']);
@@ -492,8 +516,9 @@  discard block
 block discarded – undo
492 516
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
493 517
 
494 518
 		// Make sure the subject isn't too long - taking into account special characters.
495
-		if ($smcFunc['strlen']($form_subject) > 100)
496
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
519
+		if ($smcFunc['strlen']($form_subject) > 100) {
520
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
521
+		}
497 522
 
498 523
 		if (isset($_REQUEST['poll']))
499 524
 		{
@@ -505,8 +530,9 @@  discard block
 block discarded – undo
505 530
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
506 531
 			foreach ($_POST['options'] as $option)
507 532
 			{
508
-				if (trim($option) == '')
509
-					continue;
533
+				if (trim($option) == '') {
534
+									continue;
535
+				}
510 536
 
511 537
 				$context['choices'][] = array(
512 538
 					'id' => $choice_id++,
@@ -568,13 +594,14 @@  discard block
 block discarded – undo
568 594
 				$context['preview_subject'] = $form_subject;
569 595
 
570 596
 				censorText($context['preview_subject']);
597
+			} else {
598
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
571 599
 			}
572
-			else
573
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
574 600
 
575 601
 			// Protect any CDATA blocks.
576
-			if (isset($_REQUEST['xml']))
577
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
602
+			if (isset($_REQUEST['xml'])) {
603
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
604
+			}
578 605
 		}
579 606
 
580 607
 		// Set up the checkboxes.
@@ -613,29 +640,32 @@  discard block
 block discarded – undo
613 640
 			);
614 641
 			// The message they were trying to edit was most likely deleted.
615 642
 			// @todo Change this error message?
616
-			if ($smcFunc['db_num_rows']($request) == 0)
617
-				fatal_lang_error('no_board', false);
643
+			if ($smcFunc['db_num_rows']($request) == 0) {
644
+							fatal_lang_error('no_board', false);
645
+			}
618 646
 			$row = $smcFunc['db_fetch_assoc']($request);
619 647
 
620 648
 			$attachment_stuff = array($row);
621
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
622
-				$attachment_stuff[] = $row2;
649
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
650
+							$attachment_stuff[] = $row2;
651
+			}
623 652
 			$smcFunc['db_free_result']($request);
624 653
 
625 654
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
626 655
 			{
627 656
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
628
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
629
-					fatal_lang_error('modify_post_time_passed', false);
630
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
631
-					isAllowedTo('modify_replies');
632
-				else
633
-					isAllowedTo('modify_own');
657
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
658
+									fatal_lang_error('modify_post_time_passed', false);
659
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
660
+									isAllowedTo('modify_replies');
661
+				} else {
662
+									isAllowedTo('modify_own');
663
+				}
664
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
665
+							isAllowedTo('modify_replies');
666
+			} else {
667
+							isAllowedTo('modify_any');
634 668
 			}
635
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
636
-				isAllowedTo('modify_replies');
637
-			else
638
-				isAllowedTo('modify_any');
639 669
 
640 670
 			if ($context['can_announce'] && !empty($row['id_action']))
641 671
 			{
@@ -659,8 +689,9 @@  discard block
 block discarded – undo
659 689
 
660 690
 				while ($row = $smcFunc['db_fetch_assoc']($request))
661 691
 				{
662
-					if ($row['filesize'] <= 0)
663
-						continue;
692
+					if ($row['filesize'] <= 0) {
693
+											continue;
694
+					}
664 695
 					$context['current_attachments'][$row['id_attach']] = array(
665 696
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
666 697
 						'size' => $row['filesize'],
@@ -730,29 +761,32 @@  discard block
 block discarded – undo
730 761
 			)
731 762
 		);
732 763
 		// The message they were trying to edit was most likely deleted.
733
-		if ($smcFunc['db_num_rows']($request) == 0)
734
-			fatal_lang_error('no_message', false);
764
+		if ($smcFunc['db_num_rows']($request) == 0) {
765
+					fatal_lang_error('no_message', false);
766
+		}
735 767
 		$row = $smcFunc['db_fetch_assoc']($request);
736 768
 
737 769
 		$attachment_stuff = array($row);
738
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
739
-			$attachment_stuff[] = $row2;
770
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
771
+					$attachment_stuff[] = $row2;
772
+		}
740 773
 		$smcFunc['db_free_result']($request);
741 774
 
742 775
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
743 776
 		{
744 777
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
745
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
746
-				fatal_lang_error('modify_post_time_passed', false);
747
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
748
-				isAllowedTo('modify_replies');
749
-			else
750
-				isAllowedTo('modify_own');
778
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
779
+							fatal_lang_error('modify_post_time_passed', false);
780
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
781
+							isAllowedTo('modify_replies');
782
+			} else {
783
+							isAllowedTo('modify_own');
784
+			}
785
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
786
+					isAllowedTo('modify_replies');
787
+		} else {
788
+					isAllowedTo('modify_any');
751 789
 		}
752
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
753
-			isAllowedTo('modify_replies');
754
-		else
755
-			isAllowedTo('modify_any');
756 790
 
757 791
 		if ($context['can_announce'] && !empty($row['id_action']))
758 792
 		{
@@ -779,15 +813,17 @@  discard block
 block discarded – undo
779 813
 		$context['icon'] = $row['icon'];
780 814
 
781 815
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
782
-		if (!$row['approved'] && !$context['show_approval'])
783
-			$context['show_approval'] = allowedTo('approve_posts');
816
+		if (!$row['approved'] && !$context['show_approval']) {
817
+					$context['show_approval'] = allowedTo('approve_posts');
818
+		}
784 819
 
785 820
 		// Sort the attachments so they are in the order saved
786 821
 		$temp = array();
787 822
 		foreach ($attachment_stuff as $attachment)
788 823
 		{
789
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
790
-				$temp[$attachment['id_attach']] = $attachment;
824
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
825
+							$temp[$attachment['id_attach']] = $attachment;
826
+			}
791 827
 
792 828
 		}
793 829
 		ksort($temp);
@@ -849,14 +885,16 @@  discard block
 block discarded – undo
849 885
 					'is_approved' => 1,
850 886
 				)
851 887
 			);
852
-			if ($smcFunc['db_num_rows']($request) == 0)
853
-				fatal_lang_error('quoted_post_deleted', false);
888
+			if ($smcFunc['db_num_rows']($request) == 0) {
889
+							fatal_lang_error('quoted_post_deleted', false);
890
+			}
854 891
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
855 892
 			$smcFunc['db_free_result']($request);
856 893
 
857 894
 			// Add 'Re: ' to the front of the quoted subject.
858
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
859
-				$form_subject = $context['response_prefix'] . $form_subject;
895
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
896
+							$form_subject = $context['response_prefix'] . $form_subject;
897
+			}
860 898
 
861 899
 			// Censor the message and subject.
862 900
 			censorText($form_message);
@@ -869,10 +907,11 @@  discard block
 block discarded – undo
869 907
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
870 908
 				{
871 909
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
872
-					if ($i % 4 == 0)
873
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
910
+					if ($i % 4 == 0) {
911
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
874 912
 						{
875 913
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
914
+					}
876 915
 						}, $parts[$i]);
877 916
 				}
878 917
 				$form_message = implode('', $parts);
@@ -881,8 +920,9 @@  discard block
 block discarded – undo
881 920
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
882 921
 
883 922
 			// Remove any nested quotes, if necessary.
884
-			if (!empty($modSettings['removeNestedQuotes']))
885
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
923
+			if (!empty($modSettings['removeNestedQuotes'])) {
924
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
925
+			}
886 926
 
887 927
 			// Add a quote string on the front and end.
888 928
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -894,15 +934,15 @@  discard block
 block discarded – undo
894 934
 			$form_subject = $first_subject;
895 935
 
896 936
 			// Add 'Re: ' to the front of the subject.
897
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
898
-				$form_subject = $context['response_prefix'] . $form_subject;
937
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
938
+							$form_subject = $context['response_prefix'] . $form_subject;
939
+			}
899 940
 
900 941
 			// Censor the subject.
901 942
 			censorText($form_subject);
902 943
 
903 944
 			$form_message = '';
904
-		}
905
-		else
945
+		} else
906 946
 		{
907 947
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
908 948
 			$form_message = '';
@@ -921,13 +961,15 @@  discard block
 block discarded – undo
921 961
 		if (isset($_REQUEST['msg']))
922 962
 		{
923 963
 			$context['attachments']['quantity'] = count($context['current_attachments']);
924
-			foreach ($context['current_attachments'] as $attachment)
925
-				$context['attachments']['total_size'] += $attachment['size'];
964
+			foreach ($context['current_attachments'] as $attachment) {
965
+							$context['attachments']['total_size'] += $attachment['size'];
966
+			}
926 967
 		}
927 968
 
928 969
 		// A bit of house keeping first.
929
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
930
-			unset($_SESSION['temp_attachments']);
970
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
971
+					unset($_SESSION['temp_attachments']);
972
+		}
931 973
 
932 974
 		if (!empty($_SESSION['temp_attachments']))
933 975
 		{
@@ -936,9 +978,10 @@  discard block
 block discarded – undo
936 978
 			{
937 979
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
938 980
 				{
939
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
940
-						if (file_exists($attachment['tmp_name']))
981
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
982
+											if (file_exists($attachment['tmp_name']))
941 983
 							unlink($attachment['tmp_name']);
984
+					}
942 985
 				}
943 986
 				$post_errors[] = 'temp_attachments_gone';
944 987
 				$_SESSION['temp_attachments'] = array();
@@ -952,8 +995,9 @@  discard block
 block discarded – undo
952 995
 					// See if any files still exist before showing the warning message and the files attached.
953 996
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
954 997
 					{
955
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
956
-							continue;
998
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
999
+													continue;
1000
+						}
957 1001
 
958 1002
 						if (file_exists($attachment['tmp_name']))
959 1003
 						{
@@ -963,20 +1007,21 @@  discard block
 block discarded – undo
963 1007
 							break;
964 1008
 						}
965 1009
 					}
966
-				}
967
-				else
1010
+				} else
968 1011
 				{
969 1012
 					// Since, they don't belong here. Let's inform the user that they exist..
970
-					if (!empty($topic))
971
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
972
-					else
973
-						$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1013
+					if (!empty($topic)) {
1014
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
1015
+					} else {
1016
+											$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1017
+					}
974 1018
 
975 1019
 					// Compile a list of the files to show the user.
976 1020
 					$file_list = array();
977
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
978
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1021
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1022
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
979 1023
 							$file_list[] = $attachment['name'];
1024
+					}
980 1025
 
981 1026
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
982 1027
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -988,8 +1033,7 @@  discard block
 block discarded – undo
988 1033
 
989 1034
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
990 1035
 						$context['ignore_temp_attachments'] = true;
991
-					}
992
-					else
1036
+					} else
993 1037
 					{
994 1038
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
995 1039
 						$context['ignore_temp_attachments'] = true;
@@ -997,16 +1041,19 @@  discard block
 block discarded – undo
997 1041
 				}
998 1042
 			}
999 1043
 
1000
-			if (!empty($context['we_are_history']))
1001
-				$post_errors[] = $context['we_are_history'];
1044
+			if (!empty($context['we_are_history'])) {
1045
+							$post_errors[] = $context['we_are_history'];
1046
+			}
1002 1047
 
1003 1048
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1004 1049
 			{
1005
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
1006
-					break;
1050
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1051
+									break;
1052
+				}
1007 1053
 
1008
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1009
-					continue;
1054
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1055
+									continue;
1056
+				}
1010 1057
 
1011 1058
 				if ($attachID == 'initial_error')
1012 1059
 				{
@@ -1021,15 +1068,17 @@  discard block
 block discarded – undo
1021 1068
 				{
1022 1069
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1023 1070
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1024
-					foreach ($attachment['errors'] as $error)
1025
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1071
+					foreach ($attachment['errors'] as $error) {
1072
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1073
+					}
1026 1074
 					$txt['error_attach_errors'] .= '</div>';
1027 1075
 					$post_errors[] = 'attach_errors';
1028 1076
 
1029 1077
 					// Take out the trash.
1030 1078
 					unset($_SESSION['temp_attachments'][$attachID]);
1031
-					if (file_exists($attachment['tmp_name']))
1032
-						unlink($attachment['tmp_name']);
1079
+					if (file_exists($attachment['tmp_name'])) {
1080
+											unlink($attachment['tmp_name']);
1081
+					}
1033 1082
 					continue;
1034 1083
 				}
1035 1084
 
@@ -1042,8 +1091,9 @@  discard block
 block discarded – undo
1042 1091
 
1043 1092
 				$context['attachments']['quantity']++;
1044 1093
 				$context['attachments']['total_size'] += $attachment['size'];
1045
-				if (!isset($context['files_in_session_warning']))
1046
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1094
+				if (!isset($context['files_in_session_warning'])) {
1095
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1096
+				}
1047 1097
 
1048 1098
 				$context['current_attachments'][$attachID] = array(
1049 1099
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1071,8 +1121,9 @@  discard block
 block discarded – undo
1071 1121
 	}
1072 1122
 
1073 1123
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1074
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1075
-		$post_errors[] = 'need_qr_verification';
1124
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1125
+			$post_errors[] = 'need_qr_verification';
1126
+	}
1076 1127
 
1077 1128
 	/*
1078 1129
 	 * There are two error types: serious and minor. Serious errors
@@ -1089,52 +1140,56 @@  discard block
 block discarded – undo
1089 1140
 	{
1090 1141
 		loadLanguage('Errors');
1091 1142
 		$context['error_type'] = 'minor';
1092
-		foreach ($post_errors as $post_error)
1093
-			if (is_array($post_error))
1143
+		foreach ($post_errors as $post_error) {
1144
+					if (is_array($post_error))
1094 1145
 			{
1095 1146
 				$post_error_id = $post_error[0];
1147
+		}
1096 1148
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1097 1149
 
1098 1150
 				// If it's not a minor error flag it as such.
1099
-				if (!in_array($post_error_id, $minor_errors))
1100
-					$context['error_type'] = 'serious';
1101
-			}
1102
-			else
1151
+				if (!in_array($post_error_id, $minor_errors)) {
1152
+									$context['error_type'] = 'serious';
1153
+				}
1154
+			} else
1103 1155
 			{
1104 1156
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1105 1157
 
1106 1158
 				// If it's not a minor error flag it as such.
1107
-				if (!in_array($post_error, $minor_errors))
1108
-					$context['error_type'] = 'serious';
1159
+				if (!in_array($post_error, $minor_errors)) {
1160
+									$context['error_type'] = 'serious';
1161
+				}
1109 1162
 			}
1110 1163
 	}
1111 1164
 
1112 1165
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1113
-	if (isset($_REQUEST['poll']))
1114
-		$context['page_title'] = $txt['new_poll'];
1115
-	elseif ($context['make_event'])
1116
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1117
-	elseif (isset($_REQUEST['msg']))
1118
-		$context['page_title'] = $txt['modify_msg'];
1119
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1120
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1121
-	elseif (empty($topic))
1122
-		$context['page_title'] = $txt['start_new_topic'];
1123
-	else
1124
-		$context['page_title'] = $txt['post_reply'];
1166
+	if (isset($_REQUEST['poll'])) {
1167
+			$context['page_title'] = $txt['new_poll'];
1168
+	} elseif ($context['make_event']) {
1169
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1170
+	} elseif (isset($_REQUEST['msg'])) {
1171
+			$context['page_title'] = $txt['modify_msg'];
1172
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1173
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1174
+	} elseif (empty($topic)) {
1175
+			$context['page_title'] = $txt['start_new_topic'];
1176
+	} else {
1177
+			$context['page_title'] = $txt['post_reply'];
1178
+	}
1125 1179
 
1126 1180
 	// Build the link tree.
1127
-	if (empty($topic))
1128
-		$context['linktree'][] = array(
1181
+	if (empty($topic)) {
1182
+			$context['linktree'][] = array(
1129 1183
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1130 1184
 		);
1131
-	else
1132
-		$context['linktree'][] = array(
1185
+	} else {
1186
+			$context['linktree'][] = array(
1133 1187
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1134 1188
 			'name' => $form_subject,
1135 1189
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1136 1190
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1137 1191
 		);
1192
+	}
1138 1193
 
1139 1194
 	$context['subject'] = addcslashes($form_subject, '"');
1140 1195
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1178,8 +1233,9 @@  discard block
 block discarded – undo
1178 1233
 	// Message icons - customized icons are off?
1179 1234
 	$context['icons'] = getMessageIcons(!empty($board) ? $board : 0);
1180 1235
 
1181
-	if (!empty($context['icons']))
1182
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1236
+	if (!empty($context['icons'])) {
1237
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1238
+	}
1183 1239
 
1184 1240
 	// Are we starting a poll? if set the poll icon as selected if its available
1185 1241
 	if (isset($_REQUEST['poll']))
@@ -1199,8 +1255,9 @@  discard block
 block discarded – undo
1199 1255
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1200 1256
 	{
1201 1257
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1202
-		if ($context['icons'][$i]['selected'])
1203
-			$context['icon_url'] = $context['icons'][$i]['url'];
1258
+		if ($context['icons'][$i]['selected']) {
1259
+					$context['icon_url'] = $context['icons'][$i]['url'];
1260
+		}
1204 1261
 	}
1205 1262
 	if (empty($context['icon_url']))
1206 1263
 	{
@@ -1214,8 +1271,9 @@  discard block
 block discarded – undo
1214 1271
 		));
1215 1272
 	}
1216 1273
 
1217
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1218
-		getTopic();
1274
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1275
+			getTopic();
1276
+	}
1219 1277
 
1220 1278
 	// If the user can post attachments prepare the warning labels.
1221 1279
 	if ($context['can_post_attachment'])
@@ -1226,12 +1284,13 @@  discard block
 block discarded – undo
1226 1284
 		$context['attachment_restrictions'] = array();
1227 1285
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1228 1286
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1229
-		foreach ($attachmentRestrictionTypes as $type)
1230
-			if (!empty($modSettings[$type]))
1287
+		foreach ($attachmentRestrictionTypes as $type) {
1288
+					if (!empty($modSettings[$type]))
1231 1289
 			{
1232 1290
 				// Show the max number of attachments if not 0.
1233 1291
 				if ($type == 'attachmentNumPerPostLimit')
1234 1292
 					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1293
+		}
1235 1294
 			}
1236 1295
 	}
1237 1296
 
@@ -1265,8 +1324,8 @@  discard block
 block discarded – undo
1265 1324
 
1266 1325
 	if (!empty($context['current_attachments']))
1267 1326
 	{
1268
-		foreach ($context['current_attachments'] as $key => $mock)
1269
-			addInlineJavaScript('
1327
+		foreach ($context['current_attachments'] as $key => $mock) {
1328
+					addInlineJavaScript('
1270 1329
 	current_attachments.push({
1271 1330
 		name: '. JavaScriptEscape($mock['name']) . ',
1272 1331
 		size: '. $mock['size'] . ',
@@ -1275,6 +1334,7 @@  discard block
 block discarded – undo
1275 1334
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1276 1335
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1277 1336
 	});', true);
1337
+		}
1278 1338
 	}
1279 1339
 
1280 1340
 	// File Upload.
@@ -1349,9 +1409,10 @@  discard block
 block discarded – undo
1349 1409
 			$context['posting_fields']['board']['dd'] .= '
1350 1410
 							<optgroup label="' . $category['name'] . '">';
1351 1411
 
1352
-			foreach ($category['boards'] as $brd)
1353
-				$context['posting_fields']['board']['dd'] .= '
1412
+			foreach ($category['boards'] as $brd) {
1413
+							$context['posting_fields']['board']['dd'] .= '
1354 1414
 								<option value="' . $brd['id'] . '"' . ($brd['selected'] ? ' selected' : '') . '>' . ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=&gt;' : '') . ' ' . $brd['name'] . '</option>';
1415
+			}
1355 1416
 
1356 1417
 			$context['posting_fields']['board']['dd'] .= '
1357 1418
 							</optgroup>';
@@ -1382,8 +1443,9 @@  discard block
 block discarded – undo
1382 1443
 
1383 1444
 
1384 1445
 	// Finally, load the template.
1385
-	if (!isset($_REQUEST['xml']))
1386
-		loadTemplate('Post');
1446
+	if (!isset($_REQUEST['xml'])) {
1447
+			loadTemplate('Post');
1448
+	}
1387 1449
 
1388 1450
 	call_integration_hook('integrate_post_end');
1389 1451
 }
@@ -1404,13 +1466,14 @@  discard block
 block discarded – undo
1404 1466
 	// Sneaking off, are we?
1405 1467
 	if (empty($_POST) && empty($topic))
1406 1468
 	{
1407
-		if (empty($_SERVER['CONTENT_LENGTH']))
1408
-			redirectexit('action=post;board=' . $board . '.0');
1409
-		else
1410
-			fatal_lang_error('post_upload_error', false);
1469
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1470
+					redirectexit('action=post;board=' . $board . '.0');
1471
+		} else {
1472
+					fatal_lang_error('post_upload_error', false);
1473
+		}
1474
+	} elseif (empty($_POST) && !empty($topic)) {
1475
+			redirectexit('action=post;topic=' . $topic . '.0');
1411 1476
 	}
1412
-	elseif (empty($_POST) && !empty($topic))
1413
-		redirectexit('action=post;topic=' . $topic . '.0');
1414 1477
 
1415 1478
 	// No need!
1416 1479
 	$context['robot_no_index'] = true;
@@ -1422,8 +1485,9 @@  discard block
 block discarded – undo
1422 1485
 	$post_errors = array();
1423 1486
 
1424 1487
 	// If the session has timed out, let the user re-submit their form.
1425
-	if (checkSession('post', '', false) != '')
1426
-		$post_errors[] = 'session_timeout';
1488
+	if (checkSession('post', '', false) != '') {
1489
+			$post_errors[] = 'session_timeout';
1490
+	}
1427 1491
 
1428 1492
 	// Wrong verification code?
1429 1493
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1433,33 +1497,38 @@  discard block
 block discarded – undo
1433 1497
 			'id' => 'post',
1434 1498
 		);
1435 1499
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1436
-		if (is_array($context['require_verification']))
1437
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1500
+		if (is_array($context['require_verification'])) {
1501
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1502
+		}
1438 1503
 	}
1439 1504
 
1440 1505
 	require_once($sourcedir . '/Subs-Post.php');
1441 1506
 	loadLanguage('Post');
1442 1507
 
1443 1508
 	// Drafts enabled and needed?
1444
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1445
-		require_once($sourcedir . '/Drafts.php');
1509
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1510
+			require_once($sourcedir . '/Drafts.php');
1511
+	}
1446 1512
 
1447 1513
 	// First check to see if they are trying to delete any current attachments.
1448 1514
 	if (isset($_POST['attach_del']))
1449 1515
 	{
1450 1516
 		$keep_temp = array();
1451 1517
 		$keep_ids = array();
1452
-		foreach ($_POST['attach_del'] as $dummy)
1453
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1518
+		foreach ($_POST['attach_del'] as $dummy) {
1519
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1454 1520
 				$keep_temp[] = $dummy;
1455
-			else
1456
-				$keep_ids[] = (int) $dummy;
1521
+		}
1522
+			else {
1523
+							$keep_ids[] = (int) $dummy;
1524
+			}
1457 1525
 
1458
-		if (isset($_SESSION['temp_attachments']))
1459
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1526
+		if (isset($_SESSION['temp_attachments'])) {
1527
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1460 1528
 			{
1461 1529
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1462 1530
 					continue;
1531
+		}
1463 1532
 
1464 1533
 				unset($_SESSION['temp_attachments'][$attachID]);
1465 1534
 				unlink($attachment['tmp_name']);
@@ -1491,8 +1560,9 @@  discard block
 block discarded – undo
1491 1560
 	{
1492 1561
 		require_once($sourcedir . '/ManageAttachments.php');
1493 1562
 
1494
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
1495
-			removeAttachments(array('id_attach' => $attachID));
1563
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
1564
+					removeAttachments(array('id_attach' => $attachID));
1565
+		}
1496 1566
 
1497 1567
 		unset($_SESSION['already_attached']);
1498 1568
 
@@ -1515,12 +1585,14 @@  discard block
 block discarded – undo
1515 1585
 		$smcFunc['db_free_result']($request);
1516 1586
 
1517 1587
 		// Though the topic should be there, it might have vanished.
1518
-		if (!is_array($topic_info))
1519
-			fatal_lang_error('topic_doesnt_exist', 404);
1588
+		if (!is_array($topic_info)) {
1589
+					fatal_lang_error('topic_doesnt_exist', 404);
1590
+		}
1520 1591
 
1521 1592
 		// Did this topic suddenly move? Just checking...
1522
-		if ($topic_info['id_board'] != $board)
1523
-			fatal_lang_error('not_a_topic');
1593
+		if ($topic_info['id_board'] != $board) {
1594
+					fatal_lang_error('not_a_topic');
1595
+		}
1524 1596
 
1525 1597
 		// Do the permissions and approval stuff...
1526 1598
 		$becomesApproved = true;
@@ -1543,49 +1615,50 @@  discard block
 block discarded – undo
1543 1615
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1544 1616
 	{
1545 1617
 		// Don't allow a post if it's locked.
1546
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1547
-			fatal_lang_error('topic_locked', false);
1618
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1619
+					fatal_lang_error('topic_locked', false);
1620
+		}
1548 1621
 
1549 1622
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1550
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1551
-			unset($_REQUEST['poll']);
1552
-
1553
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1554
-		{
1555
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1556
-				$becomesApproved = false;
1557
-
1558
-			else
1559
-				isAllowedTo('post_reply_any');
1560
-		}
1561
-		elseif (!allowedTo('post_reply_any'))
1623
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1624
+					unset($_REQUEST['poll']);
1625
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1626
+		{
1627
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1628
+							$becomesApproved = false;
1629
+			} else {
1630
+							isAllowedTo('post_reply_any');
1631
+			}
1632
+		} elseif (!allowedTo('post_reply_any'))
1562 1633
 		{
1563
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1564
-				$becomesApproved = false;
1565
-
1566
-			else
1567
-				isAllowedTo('post_reply_own');
1634
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1635
+							$becomesApproved = false;
1636
+			} else {
1637
+							isAllowedTo('post_reply_own');
1638
+			}
1568 1639
 		}
1569 1640
 
1570 1641
 		if (isset($_POST['lock']))
1571 1642
 		{
1572 1643
 			// Nothing is changed to the lock.
1573
-			if (empty($topic_info['locked']) == empty($_POST['lock']))
1574
-				unset($_POST['lock']);
1644
+			if (empty($topic_info['locked']) == empty($_POST['lock'])) {
1645
+							unset($_POST['lock']);
1646
+			}
1575 1647
 
1576 1648
 			// You're have no permission to lock this topic.
1577
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1578
-				unset($_POST['lock']);
1649
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1650
+							unset($_POST['lock']);
1651
+			}
1579 1652
 
1580 1653
 			// You are allowed to (un)lock your own topic only.
1581 1654
 			elseif (!allowedTo('lock_any'))
1582 1655
 			{
1583 1656
 				// You cannot override a moderator lock.
1584
-				if ($topic_info['locked'] == 1)
1585
-					unset($_POST['lock']);
1586
-
1587
-				else
1588
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1657
+				if ($topic_info['locked'] == 1) {
1658
+									unset($_POST['lock']);
1659
+				} else {
1660
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1661
+				}
1589 1662
 			}
1590 1663
 			// Hail mighty moderator, (un)lock this topic immediately.
1591 1664
 			else
@@ -1593,19 +1666,21 @@  discard block
 block discarded – undo
1593 1666
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1594 1667
 
1595 1668
 				// Did someone (un)lock this while you were posting?
1596
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1597
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1669
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1670
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1671
+				}
1598 1672
 			}
1599 1673
 		}
1600 1674
 
1601 1675
 		// So you wanna (un)sticky this...let's see.
1602
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1603
-			unset($_POST['sticky']);
1604
-		elseif (isset($_POST['sticky']))
1676
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1677
+					unset($_POST['sticky']);
1678
+		} elseif (isset($_POST['sticky']))
1605 1679
 		{
1606 1680
 			// Did someone (un)sticky this while you were posting?
1607
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1608
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1681
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1682
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1683
+			}
1609 1684
 		}
1610 1685
 
1611 1686
 		// If drafts are enabled, then pass this off
@@ -1632,26 +1707,31 @@  discard block
 block discarded – undo
1632 1707
 
1633 1708
 		// Do like, the permissions, for safety and stuff...
1634 1709
 		$becomesApproved = true;
1635
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1636
-			$becomesApproved = false;
1637
-		else
1638
-			isAllowedTo('post_new');
1710
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1711
+					$becomesApproved = false;
1712
+		} else {
1713
+					isAllowedTo('post_new');
1714
+		}
1639 1715
 
1640 1716
 		if (isset($_POST['lock']))
1641 1717
 		{
1642 1718
 			// New topics are by default not locked.
1643
-			if (empty($_POST['lock']))
1644
-				unset($_POST['lock']);
1719
+			if (empty($_POST['lock'])) {
1720
+							unset($_POST['lock']);
1721
+			}
1645 1722
 			// Besides, you need permission.
1646
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1647
-				unset($_POST['lock']);
1723
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1724
+							unset($_POST['lock']);
1725
+			}
1648 1726
 			// A moderator-lock (1) can override a user-lock (2).
1649
-			else
1650
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1727
+			else {
1728
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1729
+			}
1651 1730
 		}
1652 1731
 
1653
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1654
-			unset($_POST['sticky']);
1732
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1733
+					unset($_POST['sticky']);
1734
+		}
1655 1735
 
1656 1736
 		// Saving your new topic as a draft first?
1657 1737
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1676,31 +1756,37 @@  discard block
 block discarded – undo
1676 1756
 				'id_msg' => $_REQUEST['msg'],
1677 1757
 			)
1678 1758
 		);
1679
-		if ($smcFunc['db_num_rows']($request) == 0)
1680
-			fatal_lang_error('cant_find_messages', false);
1759
+		if ($smcFunc['db_num_rows']($request) == 0) {
1760
+					fatal_lang_error('cant_find_messages', false);
1761
+		}
1681 1762
 		$row = $smcFunc['db_fetch_assoc']($request);
1682 1763
 		$smcFunc['db_free_result']($request);
1683 1764
 
1684
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1685
-			fatal_lang_error('topic_locked', false);
1765
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1766
+					fatal_lang_error('topic_locked', false);
1767
+		}
1686 1768
 
1687 1769
 		if (isset($_POST['lock']))
1688 1770
 		{
1689 1771
 			// Nothing changes to the lock status.
1690
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1691
-				unset($_POST['lock']);
1772
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1773
+							unset($_POST['lock']);
1774
+			}
1692 1775
 			// You're simply not allowed to (un)lock this.
1693
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1694
-				unset($_POST['lock']);
1776
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1777
+							unset($_POST['lock']);
1778
+			}
1695 1779
 			// You're only allowed to lock your own topics.
1696 1780
 			elseif (!allowedTo('lock_any'))
1697 1781
 			{
1698 1782
 				// You're not allowed to break a moderator's lock.
1699
-				if ($topic_info['locked'] == 1)
1700
-					unset($_POST['lock']);
1783
+				if ($topic_info['locked'] == 1) {
1784
+									unset($_POST['lock']);
1785
+				}
1701 1786
 				// Lock it with a soft lock or unlock it.
1702
-				else
1703
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1787
+				else {
1788
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1789
+				}
1704 1790
 			}
1705 1791
 			// You must be the moderator.
1706 1792
 			else
@@ -1708,44 +1794,46 @@  discard block
 block discarded – undo
1708 1794
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1709 1795
 
1710 1796
 				// Did someone (un)lock this while you were posting?
1711
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1712
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1797
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1798
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1799
+				}
1713 1800
 			}
1714 1801
 		}
1715 1802
 
1716 1803
 		// Change the sticky status of this topic?
1717
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1718
-			unset($_POST['sticky']);
1719
-		elseif (isset($_POST['sticky']))
1804
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1805
+					unset($_POST['sticky']);
1806
+		} elseif (isset($_POST['sticky']))
1720 1807
 		{
1721 1808
 			// Did someone (un)sticky this while you were posting?
1722
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1723
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1809
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1810
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1811
+			}
1724 1812
 		}
1725 1813
 
1726 1814
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1727 1815
 		{
1728
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1729
-				fatal_lang_error('modify_post_time_passed', false);
1730
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1731
-				isAllowedTo('modify_replies');
1732
-			else
1733
-				isAllowedTo('modify_own');
1734
-		}
1735
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1816
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1817
+							fatal_lang_error('modify_post_time_passed', false);
1818
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1819
+							isAllowedTo('modify_replies');
1820
+			} else {
1821
+							isAllowedTo('modify_own');
1822
+			}
1823
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1736 1824
 		{
1737 1825
 			isAllowedTo('modify_replies');
1738 1826
 
1739 1827
 			// If you're modifying a reply, I say it better be logged...
1740 1828
 			$moderationAction = true;
1741
-		}
1742
-		else
1829
+		} else
1743 1830
 		{
1744 1831
 			isAllowedTo('modify_any');
1745 1832
 
1746 1833
 			// Log it, assuming you're not modifying your own post.
1747
-			if ($row['id_member'] != $user_info['id'])
1748
-				$moderationAction = true;
1834
+			if ($row['id_member'] != $user_info['id']) {
1835
+							$moderationAction = true;
1836
+			}
1749 1837
 		}
1750 1838
 
1751 1839
 		// If drafts are enabled, then lets send this off to save
@@ -1784,20 +1872,24 @@  discard block
 block discarded – undo
1784 1872
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1785 1873
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1786 1874
 
1787
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1788
-			$post_errors[] = 'no_name';
1789
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1790
-			$post_errors[] = 'long_name';
1875
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1876
+					$post_errors[] = 'no_name';
1877
+		}
1878
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1879
+					$post_errors[] = 'long_name';
1880
+		}
1791 1881
 
1792 1882
 		if (empty($modSettings['guest_post_no_email']))
1793 1883
 		{
1794 1884
 			// Only check if they changed it!
1795 1885
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1796 1886
 			{
1797
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1798
-					$post_errors[] = 'no_email';
1799
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1800
-					$post_errors[] = 'bad_email';
1887
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1888
+									$post_errors[] = 'no_email';
1889
+				}
1890
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1891
+									$post_errors[] = 'bad_email';
1892
+				}
1801 1893
 			}
1802 1894
 
1803 1895
 			// Now make sure this email address is not banned from posting.
@@ -1813,75 +1905,89 @@  discard block
 block discarded – undo
1813 1905
 	}
1814 1906
 
1815 1907
 	// Coming from the quickReply?
1816
-	if (isset($_POST['quickReply']))
1817
-		$_POST['message'] = $_POST['quickReply'];
1908
+	if (isset($_POST['quickReply'])) {
1909
+			$_POST['message'] = $_POST['quickReply'];
1910
+	}
1818 1911
 
1819 1912
 	// Check the subject and message.
1820
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1821
-		$post_errors[] = 'no_subject';
1822
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1823
-		$post_errors[] = 'no_message';
1824
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1825
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1826
-	else
1913
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1914
+			$post_errors[] = 'no_subject';
1915
+	}
1916
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1917
+			$post_errors[] = 'no_message';
1918
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1919
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1920
+	} else
1827 1921
 	{
1828 1922
 		// Prepare the message a bit for some additional testing.
1829 1923
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1830 1924
 
1831 1925
 		// Preparse code. (Zef)
1832
-		if ($user_info['is_guest'])
1833
-			$user_info['name'] = $_POST['guestname'];
1926
+		if ($user_info['is_guest']) {
1927
+					$user_info['name'] = $_POST['guestname'];
1928
+		}
1834 1929
 		preparsecode($_POST['message']);
1835 1930
 
1836 1931
 		// Let's see if there's still some content left without the tags.
1837
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1838
-			$post_errors[] = 'no_message';
1932
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1933
+					$post_errors[] = 'no_message';
1934
+		}
1935
+	}
1936
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1937
+			$post_errors[] = 'no_event';
1839 1938
 	}
1840
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1841
-		$post_errors[] = 'no_event';
1842 1939
 	// You are not!
1843
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1844
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1940
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1941
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1942
+	}
1845 1943
 
1846 1944
 	// Validate the poll...
1847 1945
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1848 1946
 	{
1849
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1850
-			fatal_lang_error('no_access', false);
1947
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
1948
+					fatal_lang_error('no_access', false);
1949
+		}
1851 1950
 
1852 1951
 		// This is a new topic... so it's a new poll.
1853
-		if (empty($topic))
1854
-			isAllowedTo('poll_post');
1952
+		if (empty($topic)) {
1953
+					isAllowedTo('poll_post');
1954
+		}
1855 1955
 		// Can you add to your own topics?
1856
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1857
-			isAllowedTo('poll_add_own');
1956
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
1957
+					isAllowedTo('poll_add_own');
1958
+		}
1858 1959
 		// Can you add polls to any topic, then?
1859
-		else
1860
-			isAllowedTo('poll_add_any');
1960
+		else {
1961
+					isAllowedTo('poll_add_any');
1962
+		}
1861 1963
 
1862
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1863
-			$post_errors[] = 'no_question';
1964
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
1965
+					$post_errors[] = 'no_question';
1966
+		}
1864 1967
 
1865 1968
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1866 1969
 
1867 1970
 		// Get rid of empty ones.
1868
-		foreach ($_POST['options'] as $k => $option)
1869
-			if ($option == '')
1971
+		foreach ($_POST['options'] as $k => $option) {
1972
+					if ($option == '')
1870 1973
 				unset($_POST['options'][$k], $_POST['options'][$k]);
1974
+		}
1871 1975
 
1872 1976
 		// What are you going to vote between with one choice?!?
1873
-		if (count($_POST['options']) < 2)
1874
-			$post_errors[] = 'poll_few';
1875
-		elseif (count($_POST['options']) > 256)
1876
-			$post_errors[] = 'poll_many';
1977
+		if (count($_POST['options']) < 2) {
1978
+					$post_errors[] = 'poll_few';
1979
+		} elseif (count($_POST['options']) > 256) {
1980
+					$post_errors[] = 'poll_many';
1981
+		}
1877 1982
 	}
1878 1983
 
1879 1984
 	if ($posterIsGuest)
1880 1985
 	{
1881 1986
 		// If user is a guest, make sure the chosen name isn't taken.
1882 1987
 		require_once($sourcedir . '/Subs-Members.php');
1883
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1884
-			$post_errors[] = 'bad_name';
1988
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
1989
+					$post_errors[] = 'bad_name';
1990
+		}
1885 1991
 	}
1886 1992
 	// If the user isn't a guest, get his or her name and email.
1887 1993
 	elseif (!isset($_REQUEST['msg']))
@@ -1912,8 +2018,9 @@  discard block
 block discarded – undo
1912 2018
 	}
1913 2019
 
1914 2020
 	// Make sure the user isn't spamming the board.
1915
-	if (!isset($_REQUEST['msg']))
1916
-		spamProtection('post');
2021
+	if (!isset($_REQUEST['msg'])) {
2022
+			spamProtection('post');
2023
+	}
1917 2024
 
1918 2025
 	// At about this point, we're posting and that's that.
1919 2026
 	ignore_user_abort(true);
@@ -1926,32 +2033,36 @@  discard block
 block discarded – undo
1926 2033
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1927 2034
 
1928 2035
 	// At this point, we want to make sure the subject isn't too long.
1929
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1930
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2036
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
2037
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2038
+	}
1931 2039
 
1932 2040
 	// Same with the "why did you edit this" text.
1933
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1934
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2041
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2042
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2043
+	}
1935 2044
 
1936 2045
 	// Make the poll...
1937 2046
 	if (isset($_REQUEST['poll']))
1938 2047
 	{
1939 2048
 		// Make sure that the user has not entered a ridiculous number of options..
1940
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1941
-			$_POST['poll_max_votes'] = 1;
1942
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1943
-			$_POST['poll_max_votes'] = count($_POST['options']);
1944
-		else
1945
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2049
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
2050
+					$_POST['poll_max_votes'] = 1;
2051
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
2052
+					$_POST['poll_max_votes'] = count($_POST['options']);
2053
+		} else {
2054
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2055
+		}
1946 2056
 
1947 2057
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
1948 2058
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
1949 2059
 
1950 2060
 		// Just set it to zero if it's not there..
1951
-		if (!isset($_POST['poll_hide']))
1952
-			$_POST['poll_hide'] = 0;
1953
-		else
1954
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2061
+		if (!isset($_POST['poll_hide'])) {
2062
+					$_POST['poll_hide'] = 0;
2063
+		} else {
2064
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2065
+		}
1955 2066
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
1956 2067
 
1957 2068
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -1960,16 +2071,19 @@  discard block
 block discarded – undo
1960 2071
 		{
1961 2072
 			require_once($sourcedir . '/Subs-Members.php');
1962 2073
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
1963
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
1964
-				$_POST['poll_guest_vote'] = 0;
2074
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
2075
+							$_POST['poll_guest_vote'] = 0;
2076
+			}
1965 2077
 		}
1966 2078
 
1967 2079
 		// If the user tries to set the poll too far in advance, don't let them.
1968
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
1969
-			fatal_lang_error('poll_range_error', false);
2080
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
2081
+					fatal_lang_error('poll_range_error', false);
2082
+		}
1970 2083
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
1971
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
1972
-			$_POST['poll_hide'] = 1;
2084
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
2085
+					$_POST['poll_hide'] = 1;
2086
+		}
1973 2087
 
1974 2088
 		// Clean up the question and answers.
1975 2089
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -1983,13 +2097,15 @@  discard block
 block discarded – undo
1983 2097
 	{
1984 2098
 		$attachIDs = array();
1985 2099
 		$attach_errors = array();
1986
-		if (!empty($context['we_are_history']))
1987
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2100
+		if (!empty($context['we_are_history'])) {
2101
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2102
+		}
1988 2103
 
1989 2104
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
1990 2105
 		{
1991
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1992
-				continue;
2106
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2107
+							continue;
2108
+			}
1993 2109
 
1994 2110
 			// If there was an initial error just show that message.
1995 2111
 			if ($attachID == 'initial_error')
@@ -2018,12 +2134,13 @@  discard block
 block discarded – undo
2018 2134
 				if (createAttachment($attachmentOptions))
2019 2135
 				{
2020 2136
 					$attachIDs[] = $attachmentOptions['id'];
2021
-					if (!empty($attachmentOptions['thumb']))
2022
-						$attachIDs[] = $attachmentOptions['thumb'];
2137
+					if (!empty($attachmentOptions['thumb'])) {
2138
+											$attachIDs[] = $attachmentOptions['thumb'];
2139
+					}
2023 2140
 				}
2141
+			} else {
2142
+							$attach_errors[] = '<dt>&nbsp;</dt>';
2024 2143
 			}
2025
-			else
2026
-				$attach_errors[] = '<dt>&nbsp;</dt>';
2027 2144
 
2028 2145
 			if (!empty($attachmentOptions['errors']))
2029 2146
 			{
@@ -2035,14 +2152,16 @@  discard block
 block discarded – undo
2035 2152
 					if (!is_array($error))
2036 2153
 					{
2037 2154
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
2038
-						if (in_array($error, $log_these))
2039
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2155
+						if (in_array($error, $log_these)) {
2156
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2157
+						}
2158
+					} else {
2159
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2040 2160
 					}
2041
-					else
2042
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2043 2161
 				}
2044
-				if (file_exists($attachment['tmp_name']))
2045
-					unlink($attachment['tmp_name']);
2162
+				if (file_exists($attachment['tmp_name'])) {
2163
+									unlink($attachment['tmp_name']);
2164
+				}
2046 2165
 			}
2047 2166
 		}
2048 2167
 		unset($_SESSION['temp_attachments']);
@@ -2083,24 +2202,24 @@  discard block
 block discarded – undo
2083 2202
 		);
2084 2203
 
2085 2204
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2205
+	} else {
2206
+			$id_poll = 0;
2086 2207
 	}
2087
-	else
2088
-		$id_poll = 0;
2089 2208
 
2090 2209
 	// Creating a new topic?
2091 2210
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2092 2211
 
2093 2212
 	// Check the icon.
2094
-	if (!isset($_POST['icon']))
2095
-		$_POST['icon'] = 'xx';
2096
-
2097
-	else
2213
+	if (!isset($_POST['icon'])) {
2214
+			$_POST['icon'] = 'xx';
2215
+	} else
2098 2216
 	{
2099 2217
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2100 2218
 
2101 2219
 		// Need to figure it out if this is a valid icon name.
2102
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2103
-			$_POST['icon'] = 'xx';
2220
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2221
+					$_POST['icon'] = 'xx';
2222
+		}
2104 2223
 	}
2105 2224
 
2106 2225
 	// Collect all parameters for the creation or modification of a post.
@@ -2141,8 +2260,9 @@  discard block
 block discarded – undo
2141 2260
 		}
2142 2261
 
2143 2262
 		// This will save some time...
2144
-		if (empty($approve_has_changed))
2145
-			unset($msgOptions['approved']);
2263
+		if (empty($approve_has_changed)) {
2264
+					unset($msgOptions['approved']);
2265
+		}
2146 2266
 
2147 2267
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2148 2268
 	}
@@ -2151,8 +2271,9 @@  discard block
 block discarded – undo
2151 2271
 	{
2152 2272
 		createPost($msgOptions, $topicOptions, $posterOptions);
2153 2273
 
2154
-		if (isset($topicOptions['id']))
2155
-			$topic = $topicOptions['id'];
2274
+		if (isset($topicOptions['id'])) {
2275
+					$topic = $topicOptions['id'];
2276
+		}
2156 2277
 	}
2157 2278
 
2158 2279
 	// Are there attachments already uploaded and waiting to be assigned?
@@ -2164,8 +2285,9 @@  discard block
 block discarded – undo
2164 2285
 	}
2165 2286
 
2166 2287
 	// If we had a draft for this, its time to remove it since it was just posted
2167
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2168
-		DeleteDraft($_POST['id_draft']);
2288
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2289
+			DeleteDraft($_POST['id_draft']);
2290
+	}
2169 2291
 
2170 2292
 	// Editing or posting an event?
2171 2293
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2184,8 +2306,7 @@  discard block
 block discarded – undo
2184 2306
 			'member' => $user_info['id'],
2185 2307
 		);
2186 2308
 		insertEvent($eventOptions);
2187
-	}
2188
-	elseif (isset($_POST['calendar']))
2309
+	} elseif (isset($_POST['calendar']))
2189 2310
 	{
2190 2311
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2191 2312
 
@@ -2213,14 +2334,15 @@  discard block
 block discarded – undo
2213 2334
 		}
2214 2335
 
2215 2336
 		// Delete it?
2216
-		if (isset($_REQUEST['deleteevent']))
2217
-			$smcFunc['db_query']('', '
2337
+		if (isset($_REQUEST['deleteevent'])) {
2338
+					$smcFunc['db_query']('', '
2218 2339
 				DELETE FROM {db_prefix}calendar
2219 2340
 				WHERE id_event = {int:id_event}',
2220 2341
 				array(
2221 2342
 					'id_event' => $_REQUEST['eventid'],
2222 2343
 				)
2223 2344
 			);
2345
+		}
2224 2346
 		// ... or just update it?
2225 2347
 		else
2226 2348
 		{
@@ -2262,9 +2384,8 @@  discard block
 block discarded – undo
2262 2384
 			array($user_info['id'], $topic, 0),
2263 2385
 			array('id_member', 'id_topic', 'id_board')
2264 2386
 		);
2265
-	}
2266
-	elseif (!$newTopic)
2267
-		$smcFunc['db_query']('', '
2387
+	} elseif (!$newTopic) {
2388
+			$smcFunc['db_query']('', '
2268 2389
 			DELETE FROM {db_prefix}log_notify
2269 2390
 			WHERE id_member = {int:current_member}
2270 2391
 				AND id_topic = {int:current_topic}',
@@ -2273,16 +2394,20 @@  discard block
 block discarded – undo
2273 2394
 				'current_topic' => $topic,
2274 2395
 			)
2275 2396
 		);
2397
+	}
2276 2398
 
2277 2399
 	// Log an act of moderation - modifying.
2278
-	if (!empty($moderationAction))
2279
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2400
+	if (!empty($moderationAction)) {
2401
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2402
+	}
2280 2403
 
2281
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2282
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2404
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2405
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2406
+	}
2283 2407
 
2284
-	if (isset($_POST['sticky']))
2285
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2408
+	if (isset($_POST['sticky'])) {
2409
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2410
+	}
2286 2411
 
2287 2412
 	// Returning to the topic?
2288 2413
 	if (!empty($_REQUEST['goback']))
@@ -2301,26 +2426,31 @@  discard block
 block discarded – undo
2301 2426
 		);
2302 2427
 	}
2303 2428
 
2304
-	if ($board_info['num_topics'] == 0)
2305
-		cache_put_data('board-' . $board, null, 120);
2429
+	if ($board_info['num_topics'] == 0) {
2430
+			cache_put_data('board-' . $board, null, 120);
2431
+	}
2306 2432
 
2307 2433
 	call_integration_hook('integrate_post2_end');
2308 2434
 
2309
-	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic'))
2310
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2435
+	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) {
2436
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2437
+	}
2311 2438
 
2312
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2313
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2439
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2440
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2441
+	}
2314 2442
 
2315 2443
 	// Return to post if the mod is on.
2316
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2317
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2318
-	elseif (!empty($_REQUEST['goback']))
2319
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2444
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2445
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2446
+	} elseif (!empty($_REQUEST['goback'])) {
2447
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2448
+	}
2320 2449
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2321
-	else
2322
-		redirectexit('board=' . $board . '.0');
2323
-}
2450
+	else {
2451
+			redirectexit('board=' . $board . '.0');
2452
+	}
2453
+	}
2324 2454
 
2325 2455
 /**
2326 2456
  * Handle the announce topic function (action=announce).
@@ -2338,8 +2468,9 @@  discard block
 block discarded – undo
2338 2468
 
2339 2469
 	validateSession();
2340 2470
 
2341
-	if (empty($topic))
2342
-		fatal_lang_error('topic_gone', false);
2471
+	if (empty($topic)) {
2472
+			fatal_lang_error('topic_gone', false);
2473
+	}
2343 2474
 
2344 2475
 	loadLanguage('Post');
2345 2476
 	loadTemplate('Post');
@@ -2366,8 +2497,9 @@  discard block
 block discarded – undo
2366 2497
 	global $txt, $context, $topic, $board_info, $smcFunc;
2367 2498
 
2368 2499
 	$groups = array_merge($board_info['groups'], array(1));
2369
-	foreach ($groups as $id => $group)
2370
-		$groups[$id] = (int) $group;
2500
+	foreach ($groups as $id => $group) {
2501
+			$groups[$id] = (int) $group;
2502
+	}
2371 2503
 
2372 2504
 	$context['groups'] = array();
2373 2505
 	if (in_array(0, $groups))
@@ -2410,8 +2542,9 @@  discard block
 block discarded – undo
2410 2542
 			'group_list' => $groups,
2411 2543
 		)
2412 2544
 	);
2413
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2414
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2545
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2546
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2547
+	}
2415 2548
 	$smcFunc['db_free_result']($request);
2416 2549
 
2417 2550
 	// Get the subject of the topic we're about to announce.
@@ -2453,16 +2586,19 @@  discard block
 block discarded – undo
2453 2586
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2454 2587
 	$groups = array_merge($board_info['groups'], array(1));
2455 2588
 
2456
-	if (isset($_POST['membergroups']))
2457
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2589
+	if (isset($_POST['membergroups'])) {
2590
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2591
+	}
2458 2592
 
2459 2593
 	// Check whether at least one membergroup was selected.
2460
-	if (empty($_POST['who']))
2461
-		fatal_lang_error('no_membergroup_selected');
2594
+	if (empty($_POST['who'])) {
2595
+			fatal_lang_error('no_membergroup_selected');
2596
+	}
2462 2597
 
2463 2598
 	// Make sure all membergroups are integers and can access the board of the announcement.
2464
-	foreach ($_POST['who'] as $id => $mg)
2465
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2599
+	foreach ($_POST['who'] as $id => $mg) {
2600
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2601
+	}
2466 2602
 
2467 2603
 	// Get the topic subject and censor it.
2468 2604
 	$request = $smcFunc['db_query']('', '
@@ -2508,12 +2644,13 @@  discard block
 block discarded – undo
2508 2644
 	if ($smcFunc['db_num_rows']($request) == 0)
2509 2645
 	{
2510 2646
 		logAction('announce_topic', array('topic' => $topic), 'user');
2511
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2512
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2513
-		elseif (!empty($_REQUEST['goback']))
2514
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2515
-		else
2516
-			redirectexit('board=' . $board . '.0');
2647
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2648
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2649
+		} elseif (!empty($_REQUEST['goback'])) {
2650
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2651
+		} else {
2652
+					redirectexit('board=' . $board . '.0');
2653
+		}
2517 2654
 	}
2518 2655
 
2519 2656
 	$announcements = array();
@@ -2532,8 +2669,9 @@  discard block
 block discarded – undo
2532 2669
 	foreach ($rows as $row)
2533 2670
 	{
2534 2671
 		// Force them to have it?
2535
-		if (empty($prefs[$row['id_member']]['announcements']))
2536
-			continue;
2672
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2673
+					continue;
2674
+		}
2537 2675
 
2538 2676
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2539 2677
 
@@ -2561,8 +2699,9 @@  discard block
 block discarded – undo
2561 2699
 	}
2562 2700
 
2563 2701
 	// For each language send a different mail - low priority...
2564
-	foreach ($announcements as $lang => $mail)
2565
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2702
+	foreach ($announcements as $lang => $mail) {
2703
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2704
+	}
2566 2705
 
2567 2706
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2568 2707
 
@@ -2572,9 +2711,10 @@  discard block
 block discarded – undo
2572 2711
 	$context['sub_template'] = 'announcement_send';
2573 2712
 
2574 2713
 	// Go back to the correct language for the user ;).
2575
-	if (!empty($modSettings['userLanguage']))
2576
-		loadLanguage('Post');
2577
-}
2714
+	if (!empty($modSettings['userLanguage'])) {
2715
+			loadLanguage('Post');
2716
+	}
2717
+	}
2578 2718
 
2579 2719
 /**
2580 2720
  * Get the topic for display purposes.
@@ -2587,12 +2727,13 @@  discard block
 block discarded – undo
2587 2727
 {
2588 2728
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2589 2729
 
2590
-	if (isset($_REQUEST['xml']))
2591
-		$limit = '
2730
+	if (isset($_REQUEST['xml'])) {
2731
+			$limit = '
2592 2732
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2593
-	else
2594
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2733
+	} else {
2734
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2595 2735
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2736
+	}
2596 2737
 
2597 2738
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2598 2739
 	$request = $smcFunc['db_query']('', '
@@ -2630,8 +2771,9 @@  discard block
 block discarded – undo
2630 2771
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2631 2772
 		);
2632 2773
 
2633
-		if (!empty($context['new_replies']))
2634
-			$context['new_replies']--;
2774
+		if (!empty($context['new_replies'])) {
2775
+					$context['new_replies']--;
2776
+		}
2635 2777
 	}
2636 2778
 	$smcFunc['db_free_result']($request);
2637 2779
 }
@@ -2648,8 +2790,9 @@  discard block
 block discarded – undo
2648 2790
 	global $sourcedir, $smcFunc;
2649 2791
 
2650 2792
 	loadLanguage('Post');
2651
-	if (!isset($_REQUEST['xml']))
2652
-		loadTemplate('Post');
2793
+	if (!isset($_REQUEST['xml'])) {
2794
+			loadTemplate('Post');
2795
+	}
2653 2796
 
2654 2797
 	include_once($sourcedir . '/Subs-Post.php');
2655 2798
 
@@ -2680,8 +2823,9 @@  discard block
 block discarded – undo
2680 2823
 	$smcFunc['db_free_result']($request);
2681 2824
 
2682 2825
 	$context['sub_template'] = 'quotefast';
2683
-	if (!empty($row))
2684
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2826
+	if (!empty($row)) {
2827
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2828
+	}
2685 2829
 
2686 2830
 	if (!empty($can_view_post))
2687 2831
 	{
@@ -2714,8 +2858,9 @@  discard block
 block discarded – undo
2714 2858
 		}
2715 2859
 
2716 2860
 		// Remove any nested quotes.
2717
-		if (!empty($modSettings['removeNestedQuotes']))
2718
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2861
+		if (!empty($modSettings['removeNestedQuotes'])) {
2862
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2863
+		}
2719 2864
 
2720 2865
 		$lb = "\n";
2721 2866
 
@@ -2741,14 +2886,14 @@  discard block
 block discarded – undo
2741 2886
 				'time' => '',
2742 2887
 			),
2743 2888
 		);
2744
-	}
2745
-	else
2746
-		$context['quote'] = array(
2889
+	} else {
2890
+			$context['quote'] = array(
2747 2891
 			'xml' => '',
2748 2892
 			'mozilla' => '',
2749 2893
 			'text' => '',
2750 2894
 		);
2751
-}
2895
+	}
2896
+	}
2752 2897
 
2753 2898
 /**
2754 2899
  * Used to edit the body or subject of a message inline
@@ -2760,8 +2905,9 @@  discard block
 block discarded – undo
2760 2905
 	global $user_info, $context, $smcFunc, $language, $board_info;
2761 2906
 
2762 2907
 	// We have to have a topic!
2763
-	if (empty($topic))
2764
-		obExit(false);
2908
+	if (empty($topic)) {
2909
+			obExit(false);
2910
+	}
2765 2911
 
2766 2912
 	checkSession('get');
2767 2913
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2787,31 +2933,35 @@  discard block
 block discarded – undo
2787 2933
 			'guest_id' => 0,
2788 2934
 		)
2789 2935
 	);
2790
-	if ($smcFunc['db_num_rows']($request) == 0)
2791
-		fatal_lang_error('no_board', false);
2936
+	if ($smcFunc['db_num_rows']($request) == 0) {
2937
+			fatal_lang_error('no_board', false);
2938
+	}
2792 2939
 	$row = $smcFunc['db_fetch_assoc']($request);
2793 2940
 	$smcFunc['db_free_result']($request);
2794 2941
 
2795 2942
 	// Change either body or subject requires permissions to modify messages.
2796 2943
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2797 2944
 	{
2798
-		if (!empty($row['locked']))
2799
-			isAllowedTo('moderate_board');
2945
+		if (!empty($row['locked'])) {
2946
+					isAllowedTo('moderate_board');
2947
+		}
2800 2948
 
2801 2949
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2802 2950
 		{
2803
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2804
-				fatal_lang_error('modify_post_time_passed', false);
2805
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2806
-				isAllowedTo('modify_replies');
2807
-			else
2808
-				isAllowedTo('modify_own');
2951
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
2952
+							fatal_lang_error('modify_post_time_passed', false);
2953
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
2954
+							isAllowedTo('modify_replies');
2955
+			} else {
2956
+							isAllowedTo('modify_own');
2957
+			}
2809 2958
 		}
2810 2959
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2811
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2812
-			isAllowedTo('modify_replies');
2813
-		else
2814
-			isAllowedTo('modify_any');
2960
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
2961
+					isAllowedTo('modify_replies');
2962
+		} else {
2963
+					isAllowedTo('modify_any');
2964
+		}
2815 2965
 
2816 2966
 		// Only log this action if it wasn't your message.
2817 2967
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2823,10 +2973,10 @@  discard block
 block discarded – undo
2823 2973
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2824 2974
 
2825 2975
 		// Maximum number of characters.
2826
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2827
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2828
-	}
2829
-	elseif (isset($_POST['subject']))
2976
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
2977
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2978
+		}
2979
+	} elseif (isset($_POST['subject']))
2830 2980
 	{
2831 2981
 		$post_errors[] = 'no_subject';
2832 2982
 		unset($_POST['subject']);
@@ -2838,13 +2988,11 @@  discard block
 block discarded – undo
2838 2988
 		{
2839 2989
 			$post_errors[] = 'no_message';
2840 2990
 			unset($_POST['message']);
2841
-		}
2842
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2991
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2843 2992
 		{
2844 2993
 			$post_errors[] = 'long_message';
2845 2994
 			unset($_POST['message']);
2846
-		}
2847
-		else
2995
+		} else
2848 2996
 		{
2849 2997
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2850 2998
 
@@ -2860,31 +3008,34 @@  discard block
 block discarded – undo
2860 3008
 
2861 3009
 	if (isset($_POST['lock']))
2862 3010
 	{
2863
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2864
-			unset($_POST['lock']);
2865
-		elseif (!allowedTo('lock_any'))
3011
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
3012
+					unset($_POST['lock']);
3013
+		} elseif (!allowedTo('lock_any'))
2866 3014
 		{
2867
-			if ($row['locked'] == 1)
2868
-				unset($_POST['lock']);
2869
-			else
2870
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3015
+			if ($row['locked'] == 1) {
3016
+							unset($_POST['lock']);
3017
+			} else {
3018
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3019
+			}
3020
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
3021
+					unset($_POST['lock']);
3022
+		} else {
3023
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2871 3024
 		}
2872
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2873
-			unset($_POST['lock']);
2874
-		else
2875
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2876 3025
 	}
2877 3026
 
2878
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2879
-		unset($_POST['sticky']);
3027
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
3028
+			unset($_POST['sticky']);
3029
+	}
2880 3030
 
2881 3031
 	if (isset($_POST['modify_reason']))
2882 3032
 	{
2883 3033
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2884 3034
 
2885 3035
 		// Maximum number of characters.
2886
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2887
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3036
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
3037
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3038
+		}
2888 3039
 	}
2889 3040
 
2890 3041
 	if (empty($post_errors))
@@ -2921,8 +3072,9 @@  discard block
 block discarded – undo
2921 3072
 			}
2922 3073
 		}
2923 3074
 		// If nothing was changed there's no need to add an entry to the moderation log.
2924
-		else
2925
-			$moderationAction = false;
3075
+		else {
3076
+					$moderationAction = false;
3077
+		}
2926 3078
 
2927 3079
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2928 3080
 
@@ -2940,9 +3092,9 @@  discard block
 block discarded – undo
2940 3092
 			// Get the proper (default language) response prefix first.
2941 3093
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2942 3094
 			{
2943
-				if ($language === $user_info['language'])
2944
-					$context['response_prefix'] = $txt['response_prefix'];
2945
-				else
3095
+				if ($language === $user_info['language']) {
3096
+									$context['response_prefix'] = $txt['response_prefix'];
3097
+				} else
2946 3098
 				{
2947 3099
 					loadLanguage('index', $language, false);
2948 3100
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -2964,8 +3116,9 @@  discard block
 block discarded – undo
2964 3116
 			);
2965 3117
 		}
2966 3118
 
2967
-		if (!empty($moderationAction))
2968
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3119
+		if (!empty($moderationAction)) {
3120
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3121
+		}
2969 3122
 	}
2970 3123
 
2971 3124
 	if (isset($_REQUEST['xml']))
@@ -3006,8 +3159,7 @@  discard block
 block discarded – undo
3006 3159
 			);
3007 3160
 
3008 3161
 			censorText($context['message']['subject']);
3009
-		}
3010
-		else
3162
+		} else
3011 3163
 		{
3012 3164
 			$context['message'] = array(
3013 3165
 				'id' => $row['id_msg'],
@@ -3019,15 +3171,16 @@  discard block
 block discarded – undo
3019 3171
 			loadLanguage('Errors');
3020 3172
 			foreach ($post_errors as $post_error)
3021 3173
 			{
3022
-				if ($post_error == 'long_message')
3023
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3024
-				else
3025
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3174
+				if ($post_error == 'long_message') {
3175
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3176
+				} else {
3177
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3178
+				}
3026 3179
 			}
3027 3180
 		}
3181
+	} else {
3182
+			obExit(false);
3183
+	}
3028 3184
 	}
3029
-	else
3030
-		obExit(false);
3031
-}
3032 3185
 
3033 3186
 ?>
3034 3187
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Post.php 1 patch
Braces   +531 added lines, -395 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Takes a message and parses it, returning nothing.
@@ -31,8 +32,9 @@  discard block
 block discarded – undo
31 32
 	global $user_info, $modSettings, $context, $sourcedir;
32 33
 
33 34
 	// This line makes all languages *theoretically* work even with the wrong charset ;).
34
-	if (empty($context['utf8']))
35
-		$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
35
+	if (empty($context['utf8'])) {
36
+			$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
37
+	}
36 38
 
37 39
 	// Clean up after nobbc ;).
38 40
 	$message = preg_replace_callback('~\[nobbc\](.+?)\[/nobbc\]~is', function($a)
@@ -47,17 +49,19 @@  discard block
 block discarded – undo
47 49
 	$message = preg_replace('~\.{100,}~', '...', $message);
48 50
 
49 51
 	// Trim off trailing quotes - these often happen by accident.
50
-	while (substr($message, -7) == '[quote]')
51
-		$message = substr($message, 0, -7);
52
-	while (substr($message, 0, 8) == '[/quote]')
53
-		$message = substr($message, 8);
52
+	while (substr($message, -7) == '[quote]') {
53
+			$message = substr($message, 0, -7);
54
+	}
55
+	while (substr($message, 0, 8) == '[/quote]') {
56
+			$message = substr($message, 8);
57
+	}
54 58
 
55 59
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
56 60
 	$in_tag = false;
57 61
 	$had_tag = false;
58 62
 	$codeopen = 0;
59
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
60
-		foreach ($matches[0] as $index => $dummy)
63
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
64
+			foreach ($matches[0] as $index => $dummy)
61 65
 		{
62 66
 			// Closing?
63 67
 			if (!empty($matches[2][$index]))
@@ -65,6 +69,7 @@  discard block
 block discarded – undo
65 69
 				// If it's closing and we're not in a tag we need to open it...
66 70
 				if (!$in_tag)
67 71
 					$codeopen = true;
72
+	}
68 73
 				// Either way we ain't in one any more.
69 74
 				$in_tag = false;
70 75
 			}
@@ -73,17 +78,20 @@  discard block
 block discarded – undo
73 78
 			{
74 79
 				$had_tag = true;
75 80
 				// If we're in a tag don't do nought!
76
-				if (!$in_tag)
77
-					$in_tag = true;
81
+				if (!$in_tag) {
82
+									$in_tag = true;
83
+				}
78 84
 			}
79 85
 		}
80 86
 
81 87
 	// If we have an open tag, close it.
82
-	if ($in_tag)
83
-		$message .= '[/code]';
88
+	if ($in_tag) {
89
+			$message .= '[/code]';
90
+	}
84 91
 	// Open any ones that need to be open, only if we've never had a tag.
85
-	if ($codeopen && !$had_tag)
86
-		$message = '[code]' . $message;
92
+	if ($codeopen && !$had_tag) {
93
+			$message = '[code]' . $message;
94
+	}
87 95
 
88 96
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
89 97
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -109,23 +117,26 @@  discard block
 block discarded – undo
109 117
 	fixTags($message);
110 118
 
111 119
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
112
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
113
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
114
-	else
115
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
120
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
121
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
122
+	} else {
123
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
124
+	}
116 125
 
117 126
 	if (!$previewing && strpos($message, '[html]') !== false)
118 127
 	{
119
-		if (allowedTo('admin_forum'))
120
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
128
+		if (allowedTo('admin_forum')) {
129
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
121 130
 				return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => '&#13;', '  ' => ' &#32;', '[' => '&#91;', ']' => '&#93;')) . '[/html]';
131
+		}
122 132
 			}, $message);
123 133
 
124 134
 		// We should edit them out, or else if an admin edits the message they will get shown...
125 135
 		else
126 136
 		{
127
-			while (strpos($message, '[html]') !== false)
128
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			while (strpos($message, '[html]') !== false) {
138
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
139
+			}
129 140
 		}
130 141
 	}
131 142
 
@@ -147,10 +158,12 @@  discard block
 block discarded – undo
147 158
 
148 159
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
149 160
 	$list_close = substr_count($message, '[/list]');
150
-	if ($list_close - $list_open > 0)
151
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
152
-	if ($list_open - $list_close > 0)
153
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
161
+	if ($list_close - $list_open > 0) {
162
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
163
+	}
164
+	if ($list_open - $list_close > 0) {
165
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
166
+	}
154 167
 
155 168
 	$mistake_fixes = array(
156 169
 		// Find [table]s not followed by [tr].
@@ -199,8 +212,9 @@  discard block
 block discarded – undo
199 212
 	);
200 213
 
201 214
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
202
-	for ($j = 0; $j < 3; $j++)
203
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	for ($j = 0; $j < 3; $j++) {
216
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
217
+	}
204 218
 
205 219
 	// Remove empty bbc from the sections outside the code tags
206 220
 	$allowedEmpty = array(
@@ -211,24 +225,28 @@  discard block
 block discarded – undo
211 225
 	require_once($sourcedir . '/Subs.php');
212 226
 
213 227
 	$alltags = array();
214
-	foreach (($codes = parse_bbc(false)) as $code)
215
-		if (!in_array($code['tag'], $allowedEmpty))
228
+	foreach (($codes = parse_bbc(false)) as $code) {
229
+			if (!in_array($code['tag'], $allowedEmpty))
216 230
 			$alltags[] = $code['tag'];
231
+	}
217 232
 
218 233
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
219 234
 
220
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
221
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
235
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
236
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
237
+	}
222 238
 
223 239
 	// Restore code blocks
224
-	if (!empty($code_tags))
225
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
240
+	if (!empty($code_tags)) {
241
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
242
+	}
226 243
 
227 244
 	// Restore white space entities
228
-	if (!$previewing)
229
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
230
-	else
231
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
245
+	if (!$previewing) {
246
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
247
+	} else {
248
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
249
+	}
232 250
 
233 251
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
234 252
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -271,8 +289,9 @@  discard block
 block discarded – undo
271 289
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
272 290
 	}, $message);
273 291
 
274
-	if (!empty($code_tags))
275
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
292
+	if (!empty($code_tags)) {
293
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
294
+	}
276 295
 
277 296
 	// Change breaks back to \n's and &nsbp; back to spaces.
278 297
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -353,8 +372,9 @@  discard block
 block discarded – undo
353 372
 	);
354 373
 
355 374
 	// Fix each type of tag.
356
-	foreach ($fixArray as $param)
357
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
375
+	foreach ($fixArray as $param) {
376
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
377
+	}
358 378
 
359 379
 	// Now fix possible security problems with images loading links automatically...
360 380
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -390,16 +410,19 @@  discard block
 block discarded – undo
390 410
 					$desired_height = $height;
391 411
 				}
392 412
 				// Scale it to the width...
393
-				elseif (empty($desired_width) && !empty($height))
394
-					$desired_width = (int) (($desired_height * $width) / $height);
413
+				elseif (empty($desired_width) && !empty($height)) {
414
+									$desired_width = (int) (($desired_height * $width) / $height);
415
+				}
395 416
 				// Scale if to the height.
396
-				elseif (!empty($width))
397
-					$desired_height = (int) (($desired_width * $height) / $width);
417
+				elseif (!empty($width)) {
418
+									$desired_height = (int) (($desired_width * $height) / $width);
419
+				}
398 420
 			}
399 421
 
400 422
 			// If the width and height are fine, just continue along...
401
-			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
402
-				continue;
423
+			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
424
+							continue;
425
+			}
403 426
 
404 427
 			// Too bad, it's too wide.  Make it as wide as the maximum.
405 428
 			if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
@@ -419,8 +442,9 @@  discard block
 block discarded – undo
419 442
 		}
420 443
 
421 444
 		// If any img tags were actually changed...
422
-		if (!empty($replaces))
423
-			$message = strtr($message, $replaces);
445
+		if (!empty($replaces)) {
446
+					$message = strtr($message, $replaces);
447
+		}
424 448
 	}
425 449
 }
426 450
 
@@ -439,10 +463,11 @@  discard block
 block discarded – undo
439 463
 {
440 464
 	global $boardurl, $scripturl;
441 465
 
442
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
443
-		$domain_url = $match[1];
444
-	else
445
-		$domain_url = $boardurl . '/';
466
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
467
+			$domain_url = $match[1];
468
+	} else {
469
+			$domain_url = $boardurl . '/';
470
+	}
446 471
 
447 472
 	$replaces = array();
448 473
 
@@ -450,11 +475,11 @@  discard block
 block discarded – undo
450 475
 	{
451 476
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
452 477
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
478
+	} elseif ($hasEqualSign) {
479
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
480
+	} else {
481
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
453 482
 	}
454
-	elseif ($hasEqualSign)
455
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
456
-	else
457
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
458 483
 
459 484
 	foreach ($matches[0] as $k => $dummy)
460 485
 	{
@@ -467,49 +492,53 @@  discard block
 block discarded – undo
467 492
 		foreach ($protocols as $protocol)
468 493
 		{
469 494
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
470
-			if ($found)
471
-				break;
495
+			if ($found) {
496
+							break;
497
+			}
472 498
 		}
473 499
 
474 500
 		if (!$found && $protocols[0] == 'http')
475 501
 		{
476
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
477
-				$replace = $domain_url . $replace;
478
-			elseif (substr($replace, 0, 1) == '?')
479
-				$replace = $scripturl . $replace;
480
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
502
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
503
+							$replace = $domain_url . $replace;
504
+			} elseif (substr($replace, 0, 1) == '?') {
505
+							$replace = $scripturl . $replace;
506
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
481 507
 			{
482 508
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
483 509
 				$this_tag = 'iurl';
484 510
 				$this_close = 'iurl';
511
+			} elseif (substr($replace, 0, 2) != '//') {
512
+							$replace = $protocols[0] . '://' . $replace;
485 513
 			}
486
-			elseif (substr($replace, 0, 2) != '//')
487
-				$replace = $protocols[0] . '://' . $replace;
488
-		}
489
-		elseif (!$found && $protocols[0] == 'ftp')
490
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
491
-		elseif (!$found)
492
-			$replace = $protocols[0] . '://' . $replace;
493
-
494
-		if ($hasEqualSign && $embeddedUrl)
495
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
496
-		elseif ($hasEqualSign)
497
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
498
-		elseif ($embeddedUrl)
499
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
500
-		else
501
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
514
+		} elseif (!$found && $protocols[0] == 'ftp') {
515
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
516
+		} elseif (!$found) {
517
+					$replace = $protocols[0] . '://' . $replace;
518
+		}
519
+
520
+		if ($hasEqualSign && $embeddedUrl) {
521
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
522
+		} elseif ($hasEqualSign) {
523
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
524
+		} elseif ($embeddedUrl) {
525
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
526
+		} else {
527
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
528
+		}
502 529
 	}
503 530
 
504 531
 	foreach ($replaces as $k => $v)
505 532
 	{
506
-		if ($k == $v)
507
-			unset($replaces[$k]);
533
+		if ($k == $v) {
534
+					unset($replaces[$k]);
535
+		}
508 536
 	}
509 537
 
510
-	if (!empty($replaces))
511
-		$message = strtr($message, $replaces);
512
-}
538
+	if (!empty($replaces)) {
539
+			$message = strtr($message, $replaces);
540
+	}
541
+	}
513 542
 
514 543
 /**
515 544
  * This function sends an email to the specified recipient(s).
@@ -553,8 +582,9 @@  discard block
 block discarded – undo
553 582
 	}
554 583
 
555 584
 	// Nothing left? Nothing else to do
556
-	if (empty($to_array))
557
-		return true;
585
+	if (empty($to_array)) {
586
+			return true;
587
+	}
558 588
 
559 589
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
560 590
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -571,15 +601,17 @@  discard block
 block discarded – undo
571 601
 		}
572 602
 
573 603
 		// Call this function recursively for the hotmail addresses.
574
-		if (!empty($hotmail_to))
575
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
604
+		if (!empty($hotmail_to)) {
605
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
606
+		}
576 607
 
577 608
 		// The remaining addresses no longer need the fix.
578 609
 		$hotmail_fix = false;
579 610
 
580 611
 		// No other addresses left? Return instantly.
581
-		if (empty($to_array))
582
-			return $mail_result;
612
+		if (empty($to_array)) {
613
+					return $mail_result;
614
+		}
583 615
 	}
584 616
 
585 617
 	// Get rid of entities.
@@ -604,13 +636,15 @@  discard block
 block discarded – undo
604 636
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
605 637
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
606 638
 
607
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
608
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
639
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
640
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
641
+	}
609 642
 	$headers .= 'X-Mailer: SMF' . $line_break;
610 643
 
611 644
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
612
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
613
-		return false;
645
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
646
+			return false;
647
+	}
614 648
 
615 649
 	// Save the original message...
616 650
 	$orig_message = $message;
@@ -659,17 +693,19 @@  discard block
 block discarded – undo
659 693
 	}
660 694
 
661 695
 	// Are we using the mail queue, if so this is where we butt in...
662
-	if ($priority != 0)
663
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
696
+	if ($priority != 0) {
697
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
698
+	}
664 699
 
665 700
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
666 701
 	elseif (!empty($modSettings['mail_limit']))
667 702
 	{
668 703
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
669
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
670
-			$new_queue_stat = time() . '|' . 1;
671
-		else
672
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
704
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
705
+					$new_queue_stat = time() . '|' . 1;
706
+		} else {
707
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
708
+		}
673 709
 
674 710
 		updateSettings(array('mail_recent' => $new_queue_stat));
675 711
 	}
@@ -694,12 +730,13 @@  discard block
 block discarded – undo
694 730
 
695 731
 			// Wait, wait, I'm still sending here!
696 732
 			@set_time_limit(300);
697
-			if (function_exists('apache_reset_timeout'))
698
-				@apache_reset_timeout();
733
+			if (function_exists('apache_reset_timeout')) {
734
+							@apache_reset_timeout();
735
+			}
699 736
 		}
737
+	} else {
738
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
700 739
 	}
701
-	else
702
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
703 740
 
704 741
 	// Everything go smoothly?
705 742
 	return $mail_result;
@@ -725,8 +762,9 @@  discard block
 block discarded – undo
725 762
 	static $cur_insert = array();
726 763
 	static $cur_insert_len = 0;
727 764
 
728
-	if ($cur_insert_len == 0)
729
-		$cur_insert = array();
765
+	if ($cur_insert_len == 0) {
766
+			$cur_insert = array();
767
+	}
730 768
 
731 769
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
732 770
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -801,8 +839,9 @@  discard block
 block discarded – undo
801 839
 	}
802 840
 
803 841
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
804
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
805
-		return AddMailQueue(true);
842
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
843
+			return AddMailQueue(true);
844
+	}
806 845
 
807 846
 	return true;
808 847
 }
@@ -833,23 +872,26 @@  discard block
 block discarded – undo
833 872
 		'sent' => array()
834 873
 	);
835 874
 
836
-	if ($from === null)
837
-		$from = array(
875
+	if ($from === null) {
876
+			$from = array(
838 877
 			'id' => $user_info['id'],
839 878
 			'name' => $user_info['name'],
840 879
 			'username' => $user_info['username']
841 880
 		);
881
+	}
842 882
 
843 883
 	// This is the one that will go in their inbox.
844 884
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
845 885
 	preparsecode($htmlmessage);
846 886
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
847
-	if ($smcFunc['strlen']($htmlsubject) > 100)
848
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
887
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
888
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
889
+	}
849 890
 
850 891
 	// Make sure is an array
851
-	if (!is_array($recipients))
852
-		$recipients = array($recipients);
892
+	if (!is_array($recipients)) {
893
+			$recipients = array($recipients);
894
+	}
853 895
 
854 896
 	// Integrated PMs
855 897
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -877,21 +919,23 @@  discard block
 block discarded – undo
877 919
 				'usernames' => array_keys($usernames),
878 920
 			)
879 921
 		);
880
-		while ($row = $smcFunc['db_fetch_assoc']($request))
881
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
922
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
923
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
882 924
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
925
+		}
883 926
 		$smcFunc['db_free_result']($request);
884 927
 
885 928
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
886
-		foreach ($recipients as $rec_type => $rec)
887
-			foreach ($rec as $id => $member)
929
+		foreach ($recipients as $rec_type => $rec) {
930
+					foreach ($rec as $id => $member)
888 931
 			{
889 932
 				if (is_numeric($recipients[$rec_type][$id]))
890 933
 					continue;
934
+		}
891 935
 
892
-				if (!empty($usernames[$member]))
893
-					$recipients[$rec_type][$id] = $usernames[$member];
894
-				else
936
+				if (!empty($usernames[$member])) {
937
+									$recipients[$rec_type][$id] = $usernames[$member];
938
+				} else
895 939
 				{
896 940
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
897 941
 					unset($recipients[$rec_type][$id]);
@@ -929,8 +973,9 @@  discard block
 block discarded – undo
929 973
 		$delete = false;
930 974
 		foreach ($criteria as $criterium)
931 975
 		{
932
-			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
933
-				$delete = true;
976
+			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) {
977
+							$delete = true;
978
+			}
934 979
 			// If we're adding and one criteria don't match then we stop!
935 980
 			elseif (!$row['is_or'])
936 981
 			{
@@ -938,8 +983,9 @@  discard block
 block discarded – undo
938 983
 				break;
939 984
 			}
940 985
 		}
941
-		if ($delete)
942
-			$deletes[$row['id_member']] = 1;
986
+		if ($delete) {
987
+					$deletes[$row['id_member']] = 1;
988
+		}
943 989
 	}
944 990
 	$smcFunc['db_free_result']($request);
945 991
 
@@ -954,8 +1000,9 @@  discard block
 block discarded – undo
954 1000
 			array(
955 1001
 			)
956 1002
 		);
957
-		while ($row = $smcFunc['db_fetch_assoc']($request))
958
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
1003
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1004
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
1005
+		}
959 1006
 		$smcFunc['db_free_result']($request);
960 1007
 	}
961 1008
 
@@ -963,8 +1010,9 @@  discard block
 block discarded – undo
963 1010
 	require_once($sourcedir . '/Subs-Members.php');
964 1011
 	$pmReadGroups = groupsAllowedTo('pm_read');
965 1012
 
966
-	if (empty($modSettings['permission_enable_deny']))
967
-		$pmReadGroups['denied'] = array();
1013
+	if (empty($modSettings['permission_enable_deny'])) {
1014
+			$pmReadGroups['denied'] = array();
1015
+	}
968 1016
 
969 1017
 	// Load their alert preferences
970 1018
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -996,8 +1044,9 @@  discard block
 block discarded – undo
996 1044
 	while ($row = $smcFunc['db_fetch_assoc']($request))
997 1045
 	{
998 1046
 		// Don't do anything for members to be deleted!
999
-		if (isset($deletes[$row['id_member']]))
1000
-			continue;
1047
+		if (isset($deletes[$row['id_member']])) {
1048
+					continue;
1049
+		}
1001 1050
 
1002 1051
 		// Load the preferences for this member (if any)
1003 1052
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -1018,8 +1067,9 @@  discard block
 block discarded – undo
1018 1067
 		{
1019 1068
 			foreach ($groups as $id)
1020 1069
 			{
1021
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
1022
-					$message_limit = $message_limit_cache[$id];
1070
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1071
+									$message_limit = $message_limit_cache[$id];
1072
+				}
1023 1073
 			}
1024 1074
 
1025 1075
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1067,8 +1117,9 @@  discard block
 block discarded – undo
1067 1117
 	$smcFunc['db_free_result']($request);
1068 1118
 
1069 1119
 	// Only 'send' the message if there are any recipients left.
1070
-	if (empty($all_to))
1071
-		return $log;
1120
+	if (empty($all_to)) {
1121
+			return $log;
1122
+	}
1072 1123
 
1073 1124
 	// Insert the message itself and then grab the last insert id.
1074 1125
 	$id_pm = $smcFunc['db_insert']('',
@@ -1089,8 +1140,8 @@  discard block
 block discarded – undo
1089 1140
 	if (!empty($id_pm))
1090 1141
 	{
1091 1142
 		// If this is new we need to set it part of it's own conversation.
1092
-		if (empty($pm_head))
1093
-			$smcFunc['db_query']('', '
1143
+		if (empty($pm_head)) {
1144
+					$smcFunc['db_query']('', '
1094 1145
 				UPDATE {db_prefix}personal_messages
1095 1146
 				SET id_pm_head = {int:id_pm_head}
1096 1147
 				WHERE id_pm = {int:id_pm_head}',
@@ -1098,6 +1149,7 @@  discard block
 block discarded – undo
1098 1149
 					'id_pm_head' => $id_pm,
1099 1150
 				)
1100 1151
 			);
1152
+		}
1101 1153
 
1102 1154
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1103 1155
 		$smcFunc['db_query']('', '
@@ -1113,8 +1165,9 @@  discard block
 block discarded – undo
1113 1165
 		foreach ($all_to as $to)
1114 1166
 		{
1115 1167
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1116
-			if (!in_array($to, $recipients['bcc']))
1117
-				$to_list[] = $to;
1168
+			if (!in_array($to, $recipients['bcc'])) {
1169
+							$to_list[] = $to;
1170
+			}
1118 1171
 		}
1119 1172
 
1120 1173
 		$smcFunc['db_insert']('insert',
@@ -1132,9 +1185,9 @@  discard block
 block discarded – undo
1132 1185
 	{
1133 1186
 		censorText($message);
1134 1187
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1188
+	} else {
1189
+			$message = '';
1135 1190
 	}
1136
-	else
1137
-		$message = '';
1138 1191
 
1139 1192
 	$to_names = array();
1140 1193
 	if (count($to_list) > 1)
@@ -1147,8 +1200,9 @@  discard block
 block discarded – undo
1147 1200
 				'to_members' => $to_list,
1148 1201
 			)
1149 1202
 		);
1150
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1151
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1203
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1204
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1205
+		}
1152 1206
 		$smcFunc['db_free_result']($request);
1153 1207
 	}
1154 1208
 	$replacements = array(
@@ -1176,11 +1230,13 @@  discard block
 block discarded – undo
1176 1230
 	loadLanguage('index+PersonalMessage');
1177 1231
 
1178 1232
 	// Add one to their unread and read message counts.
1179
-	foreach ($all_to as $k => $id)
1180
-		if (isset($deletes[$id]))
1233
+	foreach ($all_to as $k => $id) {
1234
+			if (isset($deletes[$id]))
1181 1235
 			unset($all_to[$k]);
1182
-	if (!empty($all_to))
1183
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1236
+	}
1237
+	if (!empty($all_to)) {
1238
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1239
+	}
1184 1240
 
1185 1241
 	return $log;
1186 1242
 }
@@ -1210,15 +1266,17 @@  discard block
 block discarded – undo
1210 1266
 		// Let's, for now, assume there are only &#021;'ish characters.
1211 1267
 		$simple = true;
1212 1268
 
1213
-		foreach ($matches[1] as $entity)
1214
-			if ($entity > 128)
1269
+		foreach ($matches[1] as $entity) {
1270
+					if ($entity > 128)
1215 1271
 				$simple = false;
1272
+		}
1216 1273
 		unset($matches);
1217 1274
 
1218
-		if ($simple)
1219
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1275
+		if ($simple) {
1276
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1220 1277
 			{
1221 1278
 				return chr("$m[1]");
1279
+		}
1222 1280
 			}, $string);
1223 1281
 		else
1224 1282
 		{
@@ -1226,8 +1284,9 @@  discard block
 block discarded – undo
1226 1284
 			if (!$context['utf8'] && function_exists('iconv'))
1227 1285
 			{
1228 1286
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1229
-				if ($newstring)
1230
-					$string = $newstring;
1287
+				if ($newstring) {
1288
+									$string = $newstring;
1289
+				}
1231 1290
 			}
1232 1291
 
1233 1292
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1243,23 +1302,25 @@  discard block
 block discarded – undo
1243 1302
 		if (!$context['utf8'] && function_exists('iconv'))
1244 1303
 		{
1245 1304
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1246
-			if ($newstring)
1247
-				$string = $newstring;
1305
+			if ($newstring) {
1306
+							$string = $newstring;
1307
+			}
1248 1308
 		}
1249 1309
 
1250 1310
 		$entityConvert = function($m)
1251 1311
 		{
1252 1312
 			$c = $m[1];
1253
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1254
-				return $c;
1255
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1256
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1257
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1258
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1259
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1260
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1261
-			else
1262
-				return "";
1313
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1314
+							return $c;
1315
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1316
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1317
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1318
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1319
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1320
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1321
+			} else {
1322
+							return "";
1323
+			}
1263 1324
 		};
1264 1325
 
1265 1326
 		// Convert all 'special' characters to HTML entities.
@@ -1273,19 +1334,20 @@  discard block
 block discarded – undo
1273 1334
 		$string = base64_encode($string);
1274 1335
 
1275 1336
 		// Show the characterset and the transfer-encoding for header strings.
1276
-		if ($with_charset)
1277
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1337
+		if ($with_charset) {
1338
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1339
+		}
1278 1340
 
1279 1341
 		// Break it up in lines (mail body).
1280
-		else
1281
-			$string = chunk_split($string, 76, $line_break);
1342
+		else {
1343
+					$string = chunk_split($string, 76, $line_break);
1344
+		}
1282 1345
 
1283 1346
 		return array($charset, $string, 'base64');
1347
+	} else {
1348
+			return array($charset, $string, '7bit');
1349
+	}
1284 1350
 	}
1285
-
1286
-	else
1287
-		return array($charset, $string, '7bit');
1288
-}
1289 1351
 
1290 1352
 /**
1291 1353
  * Sends mail, like mail() but over SMTP.
@@ -1309,8 +1371,9 @@  discard block
 block discarded – undo
1309 1371
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1310 1372
 	{
1311 1373
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1312
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1313
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1374
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1375
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1376
+		}
1314 1377
 
1315 1378
 		if ($socket)
1316 1379
 		{
@@ -1331,8 +1394,9 @@  discard block
 block discarded – undo
1331 1394
 		// Maybe we can still save this?  The port might be wrong.
1332 1395
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1333 1396
 		{
1334
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1335
-				log_error($txt['smtp_port_ssl']);
1397
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1398
+							log_error($txt['smtp_port_ssl']);
1399
+			}
1336 1400
 		}
1337 1401
 
1338 1402
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1344,20 +1408,23 @@  discard block
 block discarded – undo
1344 1408
 	}
1345 1409
 
1346 1410
 	// Wait for a response of 220, without "-" continuer.
1347
-	if (!server_parse(null, $socket, '220'))
1348
-		return false;
1411
+	if (!server_parse(null, $socket, '220')) {
1412
+			return false;
1413
+	}
1349 1414
 
1350 1415
 	// Try and determine the servers name, fall back to the mail servers if not found
1351 1416
 	$helo = false;
1352
-	if (function_exists('gethostname') && gethostname() !== false)
1353
-		$helo = gethostname();
1354
-	elseif (function_exists('php_uname'))
1355
-		$helo = php_uname('n');
1356
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1357
-		$helo = $_SERVER['SERVER_NAME'];
1417
+	if (function_exists('gethostname') && gethostname() !== false) {
1418
+			$helo = gethostname();
1419
+	} elseif (function_exists('php_uname')) {
1420
+			$helo = php_uname('n');
1421
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1422
+			$helo = $_SERVER['SERVER_NAME'];
1423
+	}
1358 1424
 
1359
-	if (empty($helo))
1360
-		$helo = $modSettings['smtp_host'];
1425
+	if (empty($helo)) {
1426
+			$helo = $modSettings['smtp_host'];
1427
+	}
1361 1428
 
1362 1429
 	// SMTP = 1, SMTP - STARTTLS = 2
1363 1430
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1369,33 +1436,39 @@  discard block
 block discarded – undo
1369 1436
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1370 1437
 			{
1371 1438
 				// Send STARTTLS to enable encryption
1372
-				if (!server_parse('STARTTLS', $socket, '220'))
1373
-					return false;
1439
+				if (!server_parse('STARTTLS', $socket, '220')) {
1440
+									return false;
1441
+				}
1374 1442
 				// Enable the encryption
1375
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1376
-					return false;
1443
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1444
+									return false;
1445
+				}
1377 1446
 				// Send the EHLO command again
1378
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1379
-					return false;
1447
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1448
+									return false;
1449
+				}
1380 1450
 			}
1381 1451
 
1382
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1383
-				return false;
1452
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1453
+							return false;
1454
+			}
1384 1455
 			// Send the username and password, encoded.
1385
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1386
-				return false;
1456
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1457
+							return false;
1458
+			}
1387 1459
 			// The password is already encoded ;)
1388
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1389
-				return false;
1460
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1461
+							return false;
1462
+			}
1463
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1464
+					return false;
1390 1465
 		}
1391
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1392
-			return false;
1393
-	}
1394
-	else
1466
+	} else
1395 1467
 	{
1396 1468
 		// Just say "helo".
1397
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1398
-			return false;
1469
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1470
+					return false;
1471
+		}
1399 1472
 	}
1400 1473
 
1401 1474
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1408,31 +1481,38 @@  discard block
 block discarded – undo
1408 1481
 		// Reset the connection to send another email.
1409 1482
 		if ($i != 0)
1410 1483
 		{
1411
-			if (!server_parse('RSET', $socket, '250'))
1412
-				return false;
1484
+			if (!server_parse('RSET', $socket, '250')) {
1485
+							return false;
1486
+			}
1413 1487
 		}
1414 1488
 
1415 1489
 		// From, to, and then start the data...
1416
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1417
-			return false;
1418
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1419
-			return false;
1420
-		if (!server_parse('DATA', $socket, '354'))
1421
-			return false;
1490
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1491
+					return false;
1492
+		}
1493
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1494
+					return false;
1495
+		}
1496
+		if (!server_parse('DATA', $socket, '354')) {
1497
+					return false;
1498
+		}
1422 1499
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1423
-		if (strlen($mail_to) > 0)
1424
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1500
+		if (strlen($mail_to) > 0) {
1501
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1502
+		}
1425 1503
 		fputs($socket, $headers . "\r\n\r\n");
1426 1504
 		fputs($socket, $message . "\r\n");
1427 1505
 
1428 1506
 		// Send a ., or in other words "end of data".
1429
-		if (!server_parse('.', $socket, '250'))
1430
-			return false;
1507
+		if (!server_parse('.', $socket, '250')) {
1508
+					return false;
1509
+		}
1431 1510
 
1432 1511
 		// Almost done, almost done... don't stop me just yet!
1433 1512
 		@set_time_limit(300);
1434
-		if (function_exists('apache_reset_timeout'))
1435
-			@apache_reset_timeout();
1513
+		if (function_exists('apache_reset_timeout')) {
1514
+					@apache_reset_timeout();
1515
+		}
1436 1516
 	}
1437 1517
 	fputs($socket, 'QUIT' . "\r\n");
1438 1518
 	fclose($socket);
@@ -1456,8 +1536,9 @@  discard block
 block discarded – undo
1456 1536
 {
1457 1537
 	global $txt;
1458 1538
 
1459
-	if ($message !== null)
1460
-		fputs($socket, $message . "\r\n");
1539
+	if ($message !== null) {
1540
+			fputs($socket, $message . "\r\n");
1541
+	}
1461 1542
 
1462 1543
 	// No response yet.
1463 1544
 	$server_response = '';
@@ -1473,8 +1554,9 @@  discard block
 block discarded – undo
1473 1554
 		$response .= $server_response;
1474 1555
 	}
1475 1556
 
1476
-	if ($code === null)
1477
-		return substr($server_response, 0, 3);
1557
+	if ($code === null) {
1558
+			return substr($server_response, 0, 3);
1559
+	}
1478 1560
 
1479 1561
 	if (substr($server_response, 0, 3) != $code)
1480 1562
 	{
@@ -1504,8 +1586,9 @@  discard block
 block discarded – undo
1504 1586
 	// Create a pspell or enchant dictionary resource
1505 1587
 	$dict = spell_init();
1506 1588
 
1507
-	if (!isset($_POST['spellstring']) || !$dict)
1508
-		die;
1589
+	if (!isset($_POST['spellstring']) || !$dict) {
1590
+			die;
1591
+	}
1509 1592
 
1510 1593
 	// Construct a bit of Javascript code.
1511 1594
 	$context['spell_js'] = '
@@ -1523,8 +1606,9 @@  discard block
 block discarded – undo
1523 1606
 		$check_word = explode('|', $alphas[$i]);
1524 1607
 
1525 1608
 		// If the word is a known word, or spelled right...
1526
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1527
-			continue;
1609
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1610
+					continue;
1611
+		}
1528 1612
 
1529 1613
 		// Find the word, and move up the "last occurrence" to here.
1530 1614
 		$found_words = true;
@@ -1538,20 +1622,23 @@  discard block
 block discarded – undo
1538 1622
 		if (!empty($suggestions))
1539 1623
 		{
1540 1624
 			// But first check they aren't going to be censored - no naughty words!
1541
-			foreach ($suggestions as $k => $word)
1542
-				if ($suggestions[$k] != censorText($word))
1625
+			foreach ($suggestions as $k => $word) {
1626
+							if ($suggestions[$k] != censorText($word))
1543 1627
 					unset($suggestions[$k]);
1628
+			}
1544 1629
 
1545
-			if (!empty($suggestions))
1546
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1630
+			if (!empty($suggestions)) {
1631
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1632
+			}
1547 1633
 		}
1548 1634
 
1549 1635
 		$context['spell_js'] .= ']),';
1550 1636
 	}
1551 1637
 
1552 1638
 	// If words were found, take off the last comma.
1553
-	if ($found_words)
1554
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1639
+	if ($found_words) {
1640
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1641
+	}
1555 1642
 
1556 1643
 	$context['spell_js'] .= '
1557 1644
 		);';
@@ -1586,11 +1673,13 @@  discard block
 block discarded – undo
1586 1673
 	global $user_info, $smcFunc;
1587 1674
 
1588 1675
 	// Can't do it if there's no topics.
1589
-	if (empty($topics))
1590
-		return;
1676
+	if (empty($topics)) {
1677
+			return;
1678
+	}
1591 1679
 	// It must be an array - it must!
1592
-	if (!is_array($topics))
1593
-		$topics = array($topics);
1680
+	if (!is_array($topics)) {
1681
+			$topics = array($topics);
1682
+	}
1594 1683
 
1595 1684
 	// Get the subject and body...
1596 1685
 	$result = $smcFunc['db_query']('', '
@@ -1638,14 +1727,15 @@  discard block
 block discarded – undo
1638 1727
 	}
1639 1728
 	$smcFunc['db_free_result']($result);
1640 1729
 
1641
-	if (!empty($task_rows))
1642
-		$smcFunc['db_insert']('',
1730
+	if (!empty($task_rows)) {
1731
+			$smcFunc['db_insert']('',
1643 1732
 			'{db_prefix}background_tasks',
1644 1733
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1645 1734
 			$task_rows,
1646 1735
 			array('id_task')
1647 1736
 		);
1648
-}
1737
+	}
1738
+	}
1649 1739
 
1650 1740
 /**
1651 1741
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1683,9 +1773,9 @@  discard block
 block discarded – undo
1683 1773
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1684 1774
 
1685 1775
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1686
-	if (!$modSettings['postmod_active'])
1687
-		$topicOptions['is_approved'] = true;
1688
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1776
+	if (!$modSettings['postmod_active']) {
1777
+			$topicOptions['is_approved'] = true;
1778
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1689 1779
 	{
1690 1780
 		$request = $smcFunc['db_query']('', '
1691 1781
 			SELECT approved
@@ -1708,8 +1798,7 @@  discard block
 block discarded – undo
1708 1798
 			$posterOptions['id'] = 0;
1709 1799
 			$posterOptions['name'] = $txt['guest_title'];
1710 1800
 			$posterOptions['email'] = '';
1711
-		}
1712
-		elseif ($posterOptions['id'] != $user_info['id'])
1801
+		} elseif ($posterOptions['id'] != $user_info['id'])
1713 1802
 		{
1714 1803
 			$request = $smcFunc['db_query']('', '
1715 1804
 				SELECT member_name, email_address
@@ -1727,12 +1816,11 @@  discard block
 block discarded – undo
1727 1816
 				$posterOptions['id'] = 0;
1728 1817
 				$posterOptions['name'] = $txt['guest_title'];
1729 1818
 				$posterOptions['email'] = '';
1819
+			} else {
1820
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1730 1821
 			}
1731
-			else
1732
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1733 1822
 			$smcFunc['db_free_result']($request);
1734
-		}
1735
-		else
1823
+		} else
1736 1824
 		{
1737 1825
 			$posterOptions['name'] = $user_info['name'];
1738 1826
 			$posterOptions['email'] = $user_info['email'];
@@ -1742,8 +1830,9 @@  discard block
 block discarded – undo
1742 1830
 	if (!empty($modSettings['enable_mentions']))
1743 1831
 	{
1744 1832
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1745
-		if (!empty($msgOptions['mentioned_members']))
1746
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1833
+		if (!empty($msgOptions['mentioned_members'])) {
1834
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1835
+		}
1747 1836
 	}
1748 1837
 
1749 1838
 	// It's do or die time: forget any user aborts!
@@ -1776,12 +1865,13 @@  discard block
 block discarded – undo
1776 1865
 	);
1777 1866
 
1778 1867
 	// Something went wrong creating the message...
1779
-	if (empty($msgOptions['id']))
1780
-		return false;
1868
+	if (empty($msgOptions['id'])) {
1869
+			return false;
1870
+	}
1781 1871
 
1782 1872
 	// Fix the attachments.
1783
-	if (!empty($msgOptions['attachments']))
1784
-		$smcFunc['db_query']('', '
1873
+	if (!empty($msgOptions['attachments'])) {
1874
+			$smcFunc['db_query']('', '
1785 1875
 			UPDATE {db_prefix}attachments
1786 1876
 			SET id_msg = {int:id_msg}
1787 1877
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1790,6 +1880,7 @@  discard block
 block discarded – undo
1790 1880
 				'id_msg' => $msgOptions['id'],
1791 1881
 			)
1792 1882
 		);
1883
+	}
1793 1884
 
1794 1885
 	// What if we want to export new posts out to a CMS?
1795 1886
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1866,20 +1957,23 @@  discard block
 block discarded – undo
1866 1957
 			'id_topic' => $topicOptions['id'],
1867 1958
 			'counter_increment' => 1,
1868 1959
 		);
1869
-		if ($msgOptions['approved'])
1870
-			$topics_columns = array(
1960
+		if ($msgOptions['approved']) {
1961
+					$topics_columns = array(
1871 1962
 				'id_member_updated = {int:poster_id}',
1872 1963
 				'id_last_msg = {int:id_msg}',
1873 1964
 				'num_replies = num_replies + {int:counter_increment}',
1874 1965
 			);
1875
-		else
1876
-			$topics_columns = array(
1966
+		} else {
1967
+					$topics_columns = array(
1877 1968
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1878 1969
 			);
1879
-		if ($topicOptions['lock_mode'] !== null)
1880
-			$topics_columns[] = 'locked = {int:locked}';
1881
-		if ($topicOptions['sticky_mode'] !== null)
1882
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1970
+		}
1971
+		if ($topicOptions['lock_mode'] !== null) {
1972
+					$topics_columns[] = 'locked = {int:locked}';
1973
+		}
1974
+		if ($topicOptions['sticky_mode'] !== null) {
1975
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1976
+		}
1883 1977
 
1884 1978
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1885 1979
 
@@ -1908,8 +2002,8 @@  discard block
 block discarded – undo
1908 2002
 	);
1909 2003
 
1910 2004
 	// Increase the number of posts and topics on the board.
1911
-	if ($msgOptions['approved'])
1912
-		$smcFunc['db_query']('', '
2005
+	if ($msgOptions['approved']) {
2006
+			$smcFunc['db_query']('', '
1913 2007
 			UPDATE {db_prefix}boards
1914 2008
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1915 2009
 			WHERE id_board = {int:id_board}',
@@ -1917,7 +2011,7 @@  discard block
 block discarded – undo
1917 2011
 				'id_board' => $topicOptions['board'],
1918 2012
 			)
1919 2013
 		);
1920
-	else
2014
+	} else
1921 2015
 	{
1922 2016
 		$smcFunc['db_query']('', '
1923 2017
 			UPDATE {db_prefix}boards
@@ -1987,8 +2081,8 @@  discard block
 block discarded – undo
1987 2081
 		}
1988 2082
 	}
1989 2083
 
1990
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1991
-		$smcFunc['db_insert']('',
2084
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2085
+			$smcFunc['db_insert']('',
1992 2086
 			'{db_prefix}background_tasks',
1993 2087
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1994 2088
 			array(
@@ -2000,19 +2094,22 @@  discard block
 block discarded – undo
2000 2094
 			),
2001 2095
 			array('id_task')
2002 2096
 		);
2097
+	}
2003 2098
 
2004 2099
 	// If there's a custom search index, it may need updating...
2005 2100
 	require_once($sourcedir . '/Search.php');
2006 2101
 	$searchAPI = findSearchAPI();
2007
-	if (is_callable(array($searchAPI, 'postCreated')))
2008
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2102
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2103
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2104
+	}
2009 2105
 
2010 2106
 	// Increase the post counter for the user that created the post.
2011 2107
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
2012 2108
 	{
2013 2109
 		// Are you the one that happened to create this post?
2014
-		if ($user_info['id'] == $posterOptions['id'])
2015
-			$user_info['posts']++;
2110
+		if ($user_info['id'] == $posterOptions['id']) {
2111
+					$user_info['posts']++;
2112
+		}
2016 2113
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
2017 2114
 	}
2018 2115
 
@@ -2020,19 +2117,21 @@  discard block
 block discarded – undo
2020 2117
 	$_SESSION['last_read_topic'] = 0;
2021 2118
 
2022 2119
 	// Better safe than sorry.
2023
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
2024
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2120
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2121
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2122
+	}
2025 2123
 
2026 2124
 	// Update all the stats so everyone knows about this new topic and message.
2027 2125
 	updateStats('message', true, $msgOptions['id']);
2028 2126
 
2029 2127
 	// Update the last message on the board assuming it's approved AND the topic is.
2030
-	if ($msgOptions['approved'])
2031
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2128
+	if ($msgOptions['approved']) {
2129
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2130
+	}
2032 2131
 
2033 2132
 	// Queue createPost background notification
2034
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
2035
-		$smcFunc['db_insert']('',
2133
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2134
+			$smcFunc['db_insert']('',
2036 2135
 			'{db_prefix}background_tasks',
2037 2136
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2038 2137
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
@@ -2043,6 +2142,7 @@  discard block
 block discarded – undo
2043 2142
 			)), 0),
2044 2143
 			array('id_task')
2045 2144
 		);
2145
+	}
2046 2146
 
2047 2147
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2048 2148
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2069,14 +2169,18 @@  discard block
 block discarded – undo
2069 2169
 
2070 2170
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2071 2171
 	$messages_columns = array();
2072
-	if (isset($posterOptions['name']))
2073
-		$messages_columns['poster_name'] = $posterOptions['name'];
2074
-	if (isset($posterOptions['email']))
2075
-		$messages_columns['poster_email'] = $posterOptions['email'];
2076
-	if (isset($msgOptions['icon']))
2077
-		$messages_columns['icon'] = $msgOptions['icon'];
2078
-	if (isset($msgOptions['subject']))
2079
-		$messages_columns['subject'] = $msgOptions['subject'];
2172
+	if (isset($posterOptions['name'])) {
2173
+			$messages_columns['poster_name'] = $posterOptions['name'];
2174
+	}
2175
+	if (isset($posterOptions['email'])) {
2176
+			$messages_columns['poster_email'] = $posterOptions['email'];
2177
+	}
2178
+	if (isset($msgOptions['icon'])) {
2179
+			$messages_columns['icon'] = $msgOptions['icon'];
2180
+	}
2181
+	if (isset($msgOptions['subject'])) {
2182
+			$messages_columns['subject'] = $msgOptions['subject'];
2183
+	}
2080 2184
 	if (isset($msgOptions['body']))
2081 2185
 	{
2082 2186
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2103,8 +2207,9 @@  discard block
 block discarded – undo
2103 2207
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2104 2208
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2105 2209
 	}
2106
-	if (isset($msgOptions['smileys_enabled']))
2107
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2210
+	if (isset($msgOptions['smileys_enabled'])) {
2211
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2212
+	}
2108 2213
 
2109 2214
 	// Which columns need to be ints?
2110 2215
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2122,23 +2227,27 @@  discard block
 block discarded – undo
2122 2227
 		{
2123 2228
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2124 2229
 
2125
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2126
-				foreach ($match[1] as $i => $oldID)
2230
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2231
+							foreach ($match[1] as $i => $oldID)
2127 2232
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2233
+			}
2128 2234
 
2129
-			if (empty($modSettings['search_custom_index_config']))
2130
-				unset($msgOptions['old_body']);
2235
+			if (empty($modSettings['search_custom_index_config'])) {
2236
+							unset($msgOptions['old_body']);
2237
+			}
2131 2238
 		}
2132 2239
 
2133 2240
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2134 2241
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2135 2242
 
2136 2243
 		// Remove the poster.
2137
-		if (isset($mentions[$user_info['id']]))
2138
-			unset($mentions[$user_info['id']]);
2244
+		if (isset($mentions[$user_info['id']])) {
2245
+					unset($mentions[$user_info['id']]);
2246
+		}
2139 2247
 
2140
-		if (isset($oldmentions[$user_info['id']]))
2141
-			unset($oldmentions[$user_info['id']]);
2248
+		if (isset($oldmentions[$user_info['id']])) {
2249
+					unset($oldmentions[$user_info['id']]);
2250
+		}
2142 2251
 
2143 2252
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2144 2253
 		{
@@ -2168,8 +2277,9 @@  discard block
 block discarded – undo
2168 2277
 	}
2169 2278
 
2170 2279
 	// Nothing to do?
2171
-	if (empty($messages_columns))
2172
-		return true;
2280
+	if (empty($messages_columns)) {
2281
+			return true;
2282
+	}
2173 2283
 
2174 2284
 	// Change the post.
2175 2285
 	$smcFunc['db_query']('', '
@@ -2230,8 +2340,9 @@  discard block
 block discarded – undo
2230 2340
 	// If there's a custom search index, it needs to be modified...
2231 2341
 	require_once($sourcedir . '/Search.php');
2232 2342
 	$searchAPI = findSearchAPI();
2233
-	if (is_callable(array($searchAPI, 'postModified')))
2234
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2343
+	if (is_callable(array($searchAPI, 'postModified'))) {
2344
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2345
+	}
2235 2346
 
2236 2347
 	if (isset($msgOptions['subject']))
2237 2348
 	{
@@ -2245,14 +2356,16 @@  discard block
 block discarded – undo
2245 2356
 				'id_first_msg' => $msgOptions['id'],
2246 2357
 			)
2247 2358
 		);
2248
-		if ($smcFunc['db_num_rows']($request) == 1)
2249
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2359
+		if ($smcFunc['db_num_rows']($request) == 1) {
2360
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2361
+		}
2250 2362
 		$smcFunc['db_free_result']($request);
2251 2363
 	}
2252 2364
 
2253 2365
 	// Finally, if we are setting the approved state we need to do much more work :(
2254
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2255
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2366
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2367
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2368
+	}
2256 2369
 
2257 2370
 	return true;
2258 2371
 }
@@ -2269,11 +2382,13 @@  discard block
 block discarded – undo
2269 2382
 {
2270 2383
 	global $smcFunc;
2271 2384
 
2272
-	if (!is_array($msgs))
2273
-		$msgs = array($msgs);
2385
+	if (!is_array($msgs)) {
2386
+			$msgs = array($msgs);
2387
+	}
2274 2388
 
2275
-	if (empty($msgs))
2276
-		return false;
2389
+	if (empty($msgs)) {
2390
+			return false;
2391
+	}
2277 2392
 
2278 2393
 	// May as well start at the beginning, working out *what* we need to change.
2279 2394
 	$request = $smcFunc['db_query']('', '
@@ -2305,20 +2420,22 @@  discard block
 block discarded – undo
2305 2420
 		$topics[] = $row['id_topic'];
2306 2421
 
2307 2422
 		// Ensure our change array exists already.
2308
-		if (!isset($topic_changes[$row['id_topic']]))
2309
-			$topic_changes[$row['id_topic']] = array(
2423
+		if (!isset($topic_changes[$row['id_topic']])) {
2424
+					$topic_changes[$row['id_topic']] = array(
2310 2425
 				'id_last_msg' => $row['id_last_msg'],
2311 2426
 				'approved' => $row['topic_approved'],
2312 2427
 				'replies' => 0,
2313 2428
 				'unapproved_posts' => 0,
2314 2429
 			);
2315
-		if (!isset($board_changes[$row['id_board']]))
2316
-			$board_changes[$row['id_board']] = array(
2430
+		}
2431
+		if (!isset($board_changes[$row['id_board']])) {
2432
+					$board_changes[$row['id_board']] = array(
2317 2433
 				'posts' => 0,
2318 2434
 				'topics' => 0,
2319 2435
 				'unapproved_posts' => 0,
2320 2436
 				'unapproved_topics' => 0,
2321 2437
 			);
2438
+		}
2322 2439
 
2323 2440
 		// If it's the first message then the topic state changes!
2324 2441
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2339,14 +2456,13 @@  discard block
 block discarded – undo
2339 2456
 				'poster' => $row['id_member'],
2340 2457
 				'new_topic' => true,
2341 2458
 			);
2342
-		}
2343
-		else
2459
+		} else
2344 2460
 		{
2345 2461
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2346 2462
 
2347 2463
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2348
-			if ($row['id_msg'] > $row['id_last_msg'])
2349
-				$notification_posts[$row['id_topic']] = array(
2464
+			if ($row['id_msg'] > $row['id_last_msg']) {
2465
+							$notification_posts[$row['id_topic']] = array(
2350 2466
 					'id' => $row['id_msg'],
2351 2467
 					'body' => $row['body'],
2352 2468
 					'subject' => $row['subject'],
@@ -2357,28 +2473,33 @@  discard block
 block discarded – undo
2357 2473
 					'new_topic' => false,
2358 2474
 					'msg' => $row['id_msg'],
2359 2475
 				);
2476
+			}
2360 2477
 		}
2361 2478
 
2362 2479
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2363
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2364
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2480
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2481
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2482
+		}
2365 2483
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2366
-		elseif (!$approve)
2367
-			// Default to the first message and then we'll override in a bit ;)
2484
+		elseif (!$approve) {
2485
+					// Default to the first message and then we'll override in a bit ;)
2368 2486
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2487
+		}
2369 2488
 
2370 2489
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2371 2490
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2372 2491
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2373 2492
 
2374 2493
 		// Post count for the user?
2375
-		if ($row['id_member'] && empty($row['count_posts']))
2376
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2494
+		if ($row['id_member'] && empty($row['count_posts'])) {
2495
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2496
+		}
2377 2497
 	}
2378 2498
 	$smcFunc['db_free_result']($request);
2379 2499
 
2380
-	if (empty($msgs))
2381
-		return;
2500
+	if (empty($msgs)) {
2501
+			return;
2502
+	}
2382 2503
 
2383 2504
 	// Now we have the differences make the changes, first the easy one.
2384 2505
 	$smcFunc['db_query']('', '
@@ -2405,14 +2526,15 @@  discard block
 block discarded – undo
2405 2526
 				'approved' => 1,
2406 2527
 			)
2407 2528
 		);
2408
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2409
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2529
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2530
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2531
+		}
2410 2532
 		$smcFunc['db_free_result']($request);
2411 2533
 	}
2412 2534
 
2413 2535
 	// ... next the topics...
2414
-	foreach ($topic_changes as $id => $changes)
2415
-		$smcFunc['db_query']('', '
2536
+	foreach ($topic_changes as $id => $changes) {
2537
+			$smcFunc['db_query']('', '
2416 2538
 			UPDATE {db_prefix}topics
2417 2539
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2418 2540
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2425,10 +2547,11 @@  discard block
 block discarded – undo
2425 2547
 				'id_topic' => $id,
2426 2548
 			)
2427 2549
 		);
2550
+	}
2428 2551
 
2429 2552
 	// ... finally the boards...
2430
-	foreach ($board_changes as $id => $changes)
2431
-		$smcFunc['db_query']('', '
2553
+	foreach ($board_changes as $id => $changes) {
2554
+			$smcFunc['db_query']('', '
2432 2555
 			UPDATE {db_prefix}boards
2433 2556
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2434 2557
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2441,13 +2564,14 @@  discard block
 block discarded – undo
2441 2564
 				'id_board' => $id,
2442 2565
 			)
2443 2566
 		);
2567
+	}
2444 2568
 
2445 2569
 	// Finally, least importantly, notifications!
2446 2570
 	if ($approve)
2447 2571
 	{
2448 2572
 		$task_rows = array();
2449
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2450
-			$task_rows[] = array(
2573
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2574
+					$task_rows[] = array(
2451 2575
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
2452 2576
 					'msgOptions' => array(
2453 2577
 						'id' => $topic['msg'],
@@ -2465,14 +2589,16 @@  discard block
 block discarded – undo
2465 2589
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2466 2590
 				)), 0
2467 2591
 			);
2592
+		}
2468 2593
 
2469
-		if ($notify)
2470
-			$smcFunc['db_insert']('',
2594
+		if ($notify) {
2595
+					$smcFunc['db_insert']('',
2471 2596
 				'{db_prefix}background_tasks',
2472 2597
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2473 2598
 				$task_rows,
2474 2599
 				array('id_task')
2475 2600
 			);
2601
+		}
2476 2602
 
2477 2603
 		$smcFunc['db_query']('', '
2478 2604
 			DELETE FROM {db_prefix}approval_queue
@@ -2488,8 +2614,9 @@  discard block
 block discarded – undo
2488 2614
 	else
2489 2615
 	{
2490 2616
 		$msgInserts = array();
2491
-		foreach ($msgs as $msg)
2492
-			$msgInserts[] = array($msg);
2617
+		foreach ($msgs as $msg) {
2618
+					$msgInserts[] = array($msg);
2619
+		}
2493 2620
 
2494 2621
 		$smcFunc['db_insert']('ignore',
2495 2622
 			'{db_prefix}approval_queue',
@@ -2503,9 +2630,10 @@  discard block
 block discarded – undo
2503 2630
 	updateLastMessages(array_keys($board_changes));
2504 2631
 
2505 2632
 	// Post count for the members?
2506
-	if (!empty($member_post_changes))
2507
-		foreach ($member_post_changes as $id_member => $count_change)
2633
+	if (!empty($member_post_changes)) {
2634
+			foreach ($member_post_changes as $id_member => $count_change)
2508 2635
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2636
+	}
2509 2637
 
2510 2638
 	return true;
2511 2639
 }
@@ -2522,11 +2650,13 @@  discard block
 block discarded – undo
2522 2650
 {
2523 2651
 	global $smcFunc;
2524 2652
 
2525
-	if (!is_array($topics))
2526
-		$topics = array($topics);
2653
+	if (!is_array($topics)) {
2654
+			$topics = array($topics);
2655
+	}
2527 2656
 
2528
-	if (empty($topics))
2529
-		return false;
2657
+	if (empty($topics)) {
2658
+			return false;
2659
+	}
2530 2660
 
2531 2661
 	$approve_type = $approve ? 0 : 1;
2532 2662
 
@@ -2542,8 +2672,9 @@  discard block
 block discarded – undo
2542 2672
 		)
2543 2673
 	);
2544 2674
 	$msgs = array();
2545
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2546
-		$msgs[] = $row['id_msg'];
2675
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2676
+			$msgs[] = $row['id_msg'];
2677
+	}
2547 2678
 	$smcFunc['db_free_result']($request);
2548 2679
 
2549 2680
 	return approvePosts($msgs, $approve);
@@ -2566,11 +2697,13 @@  discard block
 block discarded – undo
2566 2697
 	global $board_info, $board, $smcFunc;
2567 2698
 
2568 2699
 	// Please - let's be sane.
2569
-	if (empty($setboards))
2570
-		return false;
2700
+	if (empty($setboards)) {
2701
+			return false;
2702
+	}
2571 2703
 
2572
-	if (!is_array($setboards))
2573
-		$setboards = array($setboards);
2704
+	if (!is_array($setboards)) {
2705
+			$setboards = array($setboards);
2706
+	}
2574 2707
 
2575 2708
 	// If we don't know the id_msg we need to find it.
2576 2709
 	if (!$id_msg)
@@ -2588,15 +2721,16 @@  discard block
 block discarded – undo
2588 2721
 			)
2589 2722
 		);
2590 2723
 		$lastMsg = array();
2591
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2592
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2724
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2725
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2726
+		}
2593 2727
 		$smcFunc['db_free_result']($request);
2594
-	}
2595
-	else
2728
+	} else
2596 2729
 	{
2597 2730
 		// Just to note - there should only be one board passed if we are doing this.
2598
-		foreach ($setboards as $id_board)
2599
-			$lastMsg[$id_board] = $id_msg;
2731
+		foreach ($setboards as $id_board) {
2732
+					$lastMsg[$id_board] = $id_msg;
2733
+		}
2600 2734
 	}
2601 2735
 
2602 2736
 	$parent_boards = array();
@@ -2611,10 +2745,11 @@  discard block
 block discarded – undo
2611 2745
 			$lastModified[$id_board] = 0;
2612 2746
 		}
2613 2747
 
2614
-		if (!empty($board) && $id_board == $board)
2615
-			$parents = $board_info['parent_boards'];
2616
-		else
2617
-			$parents = getBoardParents($id_board);
2748
+		if (!empty($board) && $id_board == $board) {
2749
+					$parents = $board_info['parent_boards'];
2750
+		} else {
2751
+					$parents = getBoardParents($id_board);
2752
+		}
2618 2753
 
2619 2754
 		// Ignore any parents on the top child level.
2620 2755
 		// @todo Why?
@@ -2623,10 +2758,11 @@  discard block
 block discarded – undo
2623 2758
 			if ($parent['level'] != 0)
2624 2759
 			{
2625 2760
 				// If we're already doing this one as a board, is this a higher last modified?
2626
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2627
-					$lastModified[$id] = $lastModified[$id_board];
2628
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2629
-					$parent_boards[$id] = $lastModified[$id_board];
2761
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2762
+									$lastModified[$id] = $lastModified[$id_board];
2763
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2764
+									$parent_boards[$id] = $lastModified[$id_board];
2765
+				}
2630 2766
 			}
2631 2767
 		}
2632 2768
 	}
@@ -2639,23 +2775,24 @@  discard block
 block discarded – undo
2639 2775
 	// Finally, to save on queries make the changes...
2640 2776
 	foreach ($parent_boards as $id => $msg)
2641 2777
 	{
2642
-		if (!isset($parent_updates[$msg]))
2643
-			$parent_updates[$msg] = array($id);
2644
-		else
2645
-			$parent_updates[$msg][] = $id;
2778
+		if (!isset($parent_updates[$msg])) {
2779
+					$parent_updates[$msg] = array($id);
2780
+		} else {
2781
+					$parent_updates[$msg][] = $id;
2782
+		}
2646 2783
 	}
2647 2784
 
2648 2785
 	foreach ($lastMsg as $id => $msg)
2649 2786
 	{
2650
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2651
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2787
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2788
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2652 2789
 				'id' => $msg,
2653 2790
 				'updated' => $lastModified[$id],
2654 2791
 				'boards' => array($id)
2655 2792
 			);
2656
-
2657
-		else
2658
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2793
+		} else {
2794
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2795
+		}
2659 2796
 	}
2660 2797
 
2661 2798
 	// Now commit the changes!
@@ -2747,11 +2884,13 @@  discard block
 block discarded – undo
2747 2884
 	global $txt, $mbname, $scripturl, $settings;
2748 2885
 
2749 2886
 	// First things first, load up the email templates language file, if we need to.
2750
-	if ($loadLang)
2751
-		loadLanguage('EmailTemplates', $lang);
2887
+	if ($loadLang) {
2888
+			loadLanguage('EmailTemplates', $lang);
2889
+	}
2752 2890
 
2753
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2754
-		fatal_lang_error('email_no_template', 'template', array($template));
2891
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2892
+			fatal_lang_error('email_no_template', 'template', array($template));
2893
+	}
2755 2894
 
2756 2895
 	$ret = array(
2757 2896
 		'subject' => $txt[$template . '_subject'],
@@ -2801,17 +2940,18 @@  discard block
 block discarded – undo
2801 2940
 function user_info_callback($matches)
2802 2941
 {
2803 2942
 	global $user_info;
2804
-	if (empty($matches[1]))
2805
-		return '';
2943
+	if (empty($matches[1])) {
2944
+			return '';
2945
+	}
2806 2946
 
2807 2947
 	$use_ref = true;
2808 2948
 	$ref = &$user_info;
2809 2949
 
2810 2950
 	foreach (explode('.', $matches[1]) as $index)
2811 2951
 	{
2812
-		if ($use_ref && isset($ref[$index]))
2813
-			$ref = &$ref[$index];
2814
-		else
2952
+		if ($use_ref && isset($ref[$index])) {
2953
+					$ref = &$ref[$index];
2954
+		} else
2815 2955
 		{
2816 2956
 			$use_ref = false;
2817 2957
 			break;
@@ -2848,8 +2988,7 @@  discard block
 block discarded – undo
2848 2988
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2849 2989
 		{
2850 2990
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2851
-		}
2852
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2991
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2853 2992
 		{
2854 2993
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2855 2994
 		}
@@ -2859,8 +2998,7 @@  discard block
 block discarded – undo
2859 2998
 		{
2860 2999
 			$context['provider'] = 'enchant';
2861 3000
 			return $enchant_link;
2862
-		}
2863
-		else
3001
+		} else
2864 3002
 		{
2865 3003
 			// Free up any resources used...
2866 3004
 			@enchant_broker_free($context['enchant_broker']);
@@ -2881,8 +3019,9 @@  discard block
 block discarded – undo
2881 3019
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2882 3020
 
2883 3021
 		// Most people don't have anything but English installed... So we use English as a last resort.
2884
-		if (!$pspell_link)
2885
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3022
+		if (!$pspell_link) {
3023
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3024
+		}
2886 3025
 
2887 3026
 		error_reporting($old);
2888 3027
 		ob_end_clean();
@@ -2922,8 +3061,7 @@  discard block
 block discarded – undo
2922 3061
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2923 3062
 		}
2924 3063
 		return enchant_dict_check($dict, $word);
2925
-	}
2926
-	elseif ($context['provider'] == 'pspell')
3064
+	} elseif ($context['provider'] == 'pspell')
2927 3065
 	{
2928 3066
 		return pspell_check($dict, $word);
2929 3067
 	}
@@ -2959,13 +3097,11 @@  discard block
 block discarded – undo
2959 3097
 			}
2960 3098
 
2961 3099
 			return $suggestions;
2962
-		}
2963
-		else
3100
+		} else
2964 3101
 		{
2965 3102
 			return enchant_dict_suggest($dict, $word);
2966 3103
 		}
2967
-	}
2968
-	elseif ($context['provider'] == 'pspell')
3104
+	} elseif ($context['provider'] == 'pspell')
2969 3105
 	{
2970 3106
 		return pspell_suggest($dict, $word);
2971 3107
 	}
Please login to merge, or discard this patch.
Sources/Register.php 1 patch
Braces   +177 added lines, -128 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Begin the registration process.
@@ -29,19 +30,23 @@  discard block
 block discarded – undo
29 30
 	global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile;
30 31
 
31 32
 	// Is this an incoming AJAX check?
32
-	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck')
33
-		return RegisterCheckUsername();
33
+	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') {
34
+			return RegisterCheckUsername();
35
+	}
34 36
 
35 37
 	// Check if the administrator has it disabled.
36
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3')
37
-		fatal_lang_error('registration_disabled', false);
38
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') {
39
+			fatal_lang_error('registration_disabled', false);
40
+	}
38 41
 
39 42
 	// If this user is an admin - redirect them to the admin registration page.
40
-	if (allowedTo('moderate_forum') && !$user_info['is_guest'])
41
-		redirectexit('action=admin;area=regcenter;sa=register');
43
+	if (allowedTo('moderate_forum') && !$user_info['is_guest']) {
44
+			redirectexit('action=admin;area=regcenter;sa=register');
45
+	}
42 46
 	// You are not a guest, so you are a member - and members don't get to register twice!
43
-	elseif (empty($user_info['is_guest']))
44
-		redirectexit();
47
+	elseif (empty($user_info['is_guest'])) {
48
+			redirectexit();
49
+	}
45 50
 
46 51
 	loadLanguage('Login');
47 52
 	loadTemplate('Register');
@@ -82,16 +87,18 @@  discard block
 block discarded – undo
82 87
 		}
83 88
 	}
84 89
 	// Make sure they don't squeeze through without agreeing.
85
-	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement'])
86
-		$current_step = 1;
90
+	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) {
91
+			$current_step = 1;
92
+	}
87 93
 
88 94
 	// Show the user the right form.
89 95
 	$context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form';
90 96
 	$context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form'];
91 97
 
92 98
 	// Kinda need this.
93
-	if ($context['sub_template'] == 'registration_form')
94
-		loadJavaScriptFile('register.js', array('defer' => false), 'smf_register');
99
+	if ($context['sub_template'] == 'registration_form') {
100
+			loadJavaScriptFile('register.js', array('defer' => false), 'smf_register');
101
+	}
95 102
 
96 103
 	// Add the register chain to the link tree.
97 104
 	$context['linktree'][] = array(
@@ -100,24 +107,26 @@  discard block
 block discarded – undo
100 107
 	);
101 108
 
102 109
 	// Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one.
103
-	if (!isset($_SESSION['register']))
104
-		$_SESSION['register'] = array(
110
+	if (!isset($_SESSION['register'])) {
111
+			$_SESSION['register'] = array(
105 112
 			'timenow' => time(),
106 113
 			'limit' => 10, // minimum number of seconds required on this page for registration
107 114
 		);
108
-	else
109
-		$_SESSION['register']['timenow'] = time();
115
+	} else {
116
+			$_SESSION['register']['timenow'] = time();
117
+	}
110 118
 
111 119
 	// If you have to agree to the agreement, it needs to be fetched from the file.
112 120
 	if ($context['require_agreement'])
113 121
 	{
114 122
 		// Have we got a localized one?
115
-		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt'))
116
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
117
-		elseif (file_exists($boarddir . '/agreement.txt'))
118
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
119
-		else
120
-			$context['agreement'] = '';
123
+		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) {
124
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
125
+		} elseif (file_exists($boarddir . '/agreement.txt')) {
126
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
127
+		} else {
128
+					$context['agreement'] = '';
129
+		}
121 130
 
122 131
 		// Nothing to show, lets disable registration and inform the admin of this error
123 132
 		if (empty($context['agreement']))
@@ -133,8 +142,9 @@  discard block
 block discarded – undo
133 142
 		$selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language'];
134 143
 
135 144
 		// Do we have any languages?
136
-		if (empty($context['languages']))
137
-			getLanguages();
145
+		if (empty($context['languages'])) {
146
+					getLanguages();
147
+		}
138 148
 
139 149
 		// Try to find our selected language.
140 150
 		foreach ($context['languages'] as $key => $lang)
@@ -142,8 +152,9 @@  discard block
 block discarded – undo
142 152
 			$context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => ''));
143 153
 
144 154
 			// Found it!
145
-			if ($selectedLanguage == $lang['filename'])
146
-				$context['languages'][$key]['selected'] = true;
155
+			if ($selectedLanguage == $lang['filename']) {
156
+							$context['languages'][$key]['selected'] = true;
157
+			}
147 158
 		}
148 159
 	}
149 160
 
@@ -170,16 +181,19 @@  discard block
 block discarded – undo
170 181
 		if (in_array('website', $reg_fields))
171 182
 		{
172 183
 			unset($reg_fields['website']);
173
-			if (isset($_POST['website_title']))
174
-				$cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']);
175
-			if (isset($_POST['website_url']))
176
-				$cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']);
184
+			if (isset($_POST['website_title'])) {
185
+							$cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']);
186
+			}
187
+			if (isset($_POST['website_url'])) {
188
+							$cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']);
189
+			}
177 190
 		}
178 191
 				
179 192
 		// We might have had some submissions on this front - go check.
180
-		foreach ($reg_fields as $field)
181
-			if (isset($_POST[$field]))
193
+		foreach ($reg_fields as $field) {
194
+					if (isset($_POST[$field]))
182 195
 				$cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]);
196
+		}
183 197
 
184 198
 		// Load all the fields in question.
185 199
 		setupProfileContext($reg_fields);
@@ -196,8 +210,9 @@  discard block
 block discarded – undo
196 210
 		$context['visual_verification_id'] = $verificationOptions['id'];
197 211
 	}
198 212
 	// Otherwise we have nothing to show.
199
-	else
200
-		$context['visual_verification'] = false;
213
+	else {
214
+			$context['visual_verification'] = false;
215
+	}
201 216
 
202 217
 
203 218
 	$context += array(
@@ -208,8 +223,9 @@  discard block
 block discarded – undo
208 223
 
209 224
 	// Were there any errors?
210 225
 	$context['registration_errors'] = array();
211
-	if (!empty($reg_errors))
212
-		$context['registration_errors'] = $reg_errors;
226
+	if (!empty($reg_errors)) {
227
+			$context['registration_errors'] = $reg_errors;
228
+	}
213 229
 
214 230
 	createToken('register');
215 231
 }
@@ -226,27 +242,32 @@  discard block
 block discarded – undo
226 242
 	validateToken('register');
227 243
 
228 244
 	// Check to ensure we're forcing SSL for authentication
229
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
230
-		fatal_lang_error('register_ssl_required');
245
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
246
+			fatal_lang_error('register_ssl_required');
247
+	}
231 248
 
232 249
 	// Start collecting together any errors.
233 250
 	$reg_errors = array();
234 251
 
235 252
 	// You can't register if it's disabled.
236
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3)
237
-		fatal_lang_error('registration_disabled', false);
253
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) {
254
+			fatal_lang_error('registration_disabled', false);
255
+	}
238 256
 
239 257
 	// Well, if you don't agree, you can't register.
240
-	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed']))
241
-		redirectexit();
258
+	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) {
259
+			redirectexit();
260
+	}
242 261
 
243 262
 	// Make sure they came from *somewhere*, have a session.
244
-	if (!isset($_SESSION['old_url']))
245
-		redirectexit('action=signup');
263
+	if (!isset($_SESSION['old_url'])) {
264
+			redirectexit('action=signup');
265
+	}
246 266
 
247 267
 	// If we don't require an agreement, we need a extra check for coppa.
248
-	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge']))
249
-		$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
268
+	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) {
269
+			$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
270
+	}
250 271
 	// Are they under age, and under age users are banned?
251 272
 	if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa']))
252 273
 	{
@@ -255,8 +276,9 @@  discard block
 block discarded – undo
255 276
 	}
256 277
 
257 278
 	// Check the time gate for miscreants. First make sure they came from somewhere that actually set it up.
258
-	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit']))
259
-		redirectexit('action=signup');
279
+	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) {
280
+			redirectexit('action=signup');
281
+	}
260 282
 	// Failing that, check the time on it.
261 283
 	if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit'])
262 284
 	{
@@ -276,15 +298,17 @@  discard block
 block discarded – undo
276 298
 		if (is_array($context['visual_verification']))
277 299
 		{
278 300
 			loadLanguage('Errors');
279
-			foreach ($context['visual_verification'] as $error)
280
-				$reg_errors[] = $txt['error_' . $error];
301
+			foreach ($context['visual_verification'] as $error) {
302
+							$reg_errors[] = $txt['error_' . $error];
303
+			}
281 304
 		}
282 305
 	}
283 306
 
284 307
 	foreach ($_POST as $key => $value)
285 308
 	{
286
-		if (!is_array($_POST[$key]))
287
-			$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
309
+		if (!is_array($_POST[$key])) {
310
+					$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
311
+		}
288 312
 	}
289 313
 
290 314
 	// Collect all extra registration fields someone might have filled in.
@@ -314,12 +338,14 @@  discard block
 block discarded – undo
314 338
 		$reg_fields = explode(',', $modSettings['registration_fields']);
315 339
 
316 340
 		// Website is a little different
317
-		if (in_array('website', $reg_fields))
318
-			$possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings);
341
+		if (in_array('website', $reg_fields)) {
342
+					$possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings);
343
+		}
319 344
 	}
320 345
 
321
-	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '')
322
-		$_POST['secret_answer'] = md5($_POST['secret_answer']);
346
+	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') {
347
+			$_POST['secret_answer'] = md5($_POST['secret_answer']);
348
+	}
323 349
 
324 350
 	// Needed for isReservedName() and registerMember().
325 351
 	require_once($sourcedir . '/Subs-Members.php');
@@ -328,8 +354,9 @@  discard block
 block discarded – undo
328 354
 	if (isset($_POST['real_name']))
329 355
 	{
330 356
 		// Are you already allowed to edit the displayed name?
331
-		if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum'))
332
-			$canEditDisplayName = true;
357
+		if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) {
358
+					$canEditDisplayName = true;
359
+		}
333 360
 
334 361
 		// If you are a guest, will you be allowed to once you register?
335 362
 		else
@@ -353,33 +380,38 @@  discard block
 block discarded – undo
353 380
 			$_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name']));
354 381
 
355 382
 			// Only set it if we are sure it is good
356
-			if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60)
357
-				$possible_strings[] = 'real_name';
383
+			if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) {
384
+							$possible_strings[] = 'real_name';
385
+			}
358 386
 		}
359 387
 	}
360 388
 
361 389
 	// Handle a string as a birthdate...
362
-	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '')
363
-		$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
390
+	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') {
391
+			$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
392
+	}
364 393
 	// Or birthdate parts...
365
-	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2']))
366
-		$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
394
+	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) {
395
+			$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
396
+	}
367 397
 
368 398
 	// Validate the passed language file.
369 399
 	if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage']))
370 400
 	{
371 401
 		// Do we have any languages?
372
-		if (empty($context['languages']))
373
-			getLanguages();
402
+		if (empty($context['languages'])) {
403
+					getLanguages();
404
+		}
374 405
 
375 406
 		// Did we find it?
376
-		if (isset($context['languages'][$_POST['lngfile']]))
377
-			$_SESSION['language'] = $_POST['lngfile'];
378
-		else
407
+		if (isset($context['languages'][$_POST['lngfile']])) {
408
+					$_SESSION['language'] = $_POST['lngfile'];
409
+		} else {
410
+					unset($_POST['lngfile']);
411
+		}
412
+	} else {
379 413
 			unset($_POST['lngfile']);
380 414
 	}
381
-	else
382
-		unset($_POST['lngfile']);
383 415
 
384 416
 	// Set the options needed for registration.
385 417
 	$regOptions = array(
@@ -399,22 +431,27 @@  discard block
 block discarded – undo
399 431
 	);
400 432
 
401 433
 	// Include the additional options that might have been filled in.
402
-	foreach ($possible_strings as $var)
403
-		if (isset($_POST[$var]))
434
+	foreach ($possible_strings as $var) {
435
+			if (isset($_POST[$var]))
404 436
 			$regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES);
405
-	foreach ($possible_ints as $var)
406
-		if (isset($_POST[$var]))
437
+	}
438
+	foreach ($possible_ints as $var) {
439
+			if (isset($_POST[$var]))
407 440
 			$regOptions['extra_register_vars'][$var] = (int) $_POST[$var];
408
-	foreach ($possible_floats as $var)
409
-		if (isset($_POST[$var]))
441
+	}
442
+	foreach ($possible_floats as $var) {
443
+			if (isset($_POST[$var]))
410 444
 			$regOptions['extra_register_vars'][$var] = (float) $_POST[$var];
411
-	foreach ($possible_bools as $var)
412
-		if (isset($_POST[$var]))
445
+	}
446
+	foreach ($possible_bools as $var) {
447
+			if (isset($_POST[$var]))
413 448
 			$regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1;
449
+	}
414 450
 
415 451
 	// Registration options are always default options...
416
-	if (isset($_POST['default_options']))
417
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
452
+	if (isset($_POST['default_options'])) {
453
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
454
+	}
418 455
 	$regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array();
419 456
 
420 457
 	// Make sure they are clean, dammit!
@@ -434,12 +471,14 @@  discard block
 block discarded – undo
434 471
 	while ($row = $smcFunc['db_fetch_assoc']($request))
435 472
 	{
436 473
 		// Don't allow overriding of the theme variables.
437
-		if (isset($regOptions['theme_vars'][$row['col_name']]))
438
-			unset($regOptions['theme_vars'][$row['col_name']]);
474
+		if (isset($regOptions['theme_vars'][$row['col_name']])) {
475
+					unset($regOptions['theme_vars'][$row['col_name']]);
476
+		}
439 477
 
440 478
 		// Not actually showing it then?
441
-		if (!$row['show_reg'])
442
-			continue;
479
+		if (!$row['show_reg']) {
480
+					continue;
481
+		}
443 482
 
444 483
 		// Prepare the value!
445 484
 		$value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : '';
@@ -448,24 +487,27 @@  discard block
 block discarded – undo
448 487
 		if (!in_array($row['field_type'], array('check', 'select', 'radio')))
449 488
 		{
450 489
 			// Is it too long?
451
-			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value))
452
-				$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
490
+			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) {
491
+							$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
492
+			}
453 493
 
454 494
 			// Any masks to apply?
455 495
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
456 496
 			{
457
-				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
458
-					$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
459
-				elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value))
460
-					$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
461
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
462
-					$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
497
+				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) {
498
+									$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
499
+				} elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) {
500
+									$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
501
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) {
502
+									$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
503
+				}
463 504
 			}
464 505
 		}
465 506
 
466 507
 		// Is this required but not there?
467
-		if (trim($value) == '' && $row['show_reg'] > 1)
468
-			$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
508
+		if (trim($value) == '' && $row['show_reg'] > 1) {
509
+					$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
510
+		}
469 511
 	}
470 512
 	$smcFunc['db_free_result']($request);
471 513
 
@@ -473,8 +515,9 @@  discard block
 block discarded – undo
473 515
 	if (!empty($custom_field_errors))
474 516
 	{
475 517
 		loadLanguage('Errors');
476
-		foreach ($custom_field_errors as $error)
477
-			$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
518
+		foreach ($custom_field_errors as $error) {
519
+					$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
520
+		}
478 521
 	}
479 522
 
480 523
 	// Lets check for other errors before trying to register the member.
@@ -519,8 +562,9 @@  discard block
 block discarded – undo
519 562
 	}
520 563
 
521 564
 	// If COPPA has been selected then things get complicated, setup the template.
522
-	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa']))
523
-		redirectexit('action=coppa;member=' . $memberID);
565
+	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) {
566
+			redirectexit('action=coppa;member=' . $memberID);
567
+	}
524 568
 	// Basic template variable setup.
525 569
 	elseif (!empty($modSettings['registration_method']))
526 570
 	{
@@ -532,8 +576,7 @@  discard block
 block discarded – undo
532 576
 			'sub_template' => 'after',
533 577
 			'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration']
534 578
 		);
535
-	}
536
-	else
579
+	} else
537 580
 	{
538 581
 		call_integration_hook('integrate_activate', array($regOptions['username']));
539 582
 
@@ -553,16 +596,18 @@  discard block
 block discarded – undo
553 596
 	global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info;
554 597
 
555 598
 	// Logged in users should not bother to activate their accounts
556
-	if (!empty($user_info['id']))
557
-		redirectexit();
599
+	if (!empty($user_info['id'])) {
600
+			redirectexit();
601
+	}
558 602
 
559 603
 	loadLanguage('Login');
560 604
 	loadTemplate('Login');
561 605
 
562 606
 	if (empty($_REQUEST['u']) && empty($_POST['user']))
563 607
 	{
564
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3')
565
-			fatal_lang_error('no_access', false);
608
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') {
609
+					fatal_lang_error('no_access', false);
610
+		}
566 611
 
567 612
 		$context['member_id'] = 0;
568 613
 		$context['sub_template'] = 'resend';
@@ -602,11 +647,13 @@  discard block
 block discarded – undo
602 647
 	// Change their email address? (they probably tried a fake one first :P.)
603 648
 	if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2))
604 649
 	{
605
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3)
606
-			fatal_lang_error('no_access', false);
650
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) {
651
+					fatal_lang_error('no_access', false);
652
+		}
607 653
 
608
-		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL))
609
-			fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
654
+		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) {
655
+					fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
656
+		}
610 657
 
611 658
 		// Make sure their email isn't banned.
612 659
 		isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']);
@@ -622,8 +669,9 @@  discard block
 block discarded – undo
622 669
 			)
623 670
 		);
624 671
 
625
-		if ($smcFunc['db_num_rows']($request) != 0)
626
-			fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
672
+		if ($smcFunc['db_num_rows']($request) != 0) {
673
+					fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
674
+		}
627 675
 		$smcFunc['db_free_result']($request);
628 676
 
629 677
 		updateMemberData($row['id_member'], array('email_address' => $_POST['new_email']));
@@ -661,9 +709,9 @@  discard block
 block discarded – undo
661 709
 	// Quit if this code is not right.
662 710
 	if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code'])
663 711
 	{
664
-		if (!empty($row['is_activated']))
665
-			fatal_lang_error('already_activated', false);
666
-		elseif ($row['validation_code'] == '')
712
+		if (!empty($row['is_activated'])) {
713
+					fatal_lang_error('already_activated', false);
714
+		} elseif ($row['validation_code'] == '')
667 715
 		{
668 716
 			loadLanguage('Profile');
669 717
 			fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false);
@@ -713,8 +761,9 @@  discard block
 block discarded – undo
713 761
 	loadTemplate('Register');
714 762
 
715 763
 	// No User ID??
716
-	if (!isset($_GET['member']))
717
-		fatal_lang_error('no_access', false);
764
+	if (!isset($_GET['member'])) {
765
+			fatal_lang_error('no_access', false);
766
+	}
718 767
 
719 768
 	// Get the user details...
720 769
 	$request = $smcFunc['db_query']('', '
@@ -727,8 +776,9 @@  discard block
 block discarded – undo
727 776
 			'is_coppa' => 5,
728 777
 		)
729 778
 	);
730
-	if ($smcFunc['db_num_rows']($request) == 0)
731
-		fatal_lang_error('no_access', false);
779
+	if ($smcFunc['db_num_rows']($request) == 0) {
780
+			fatal_lang_error('no_access', false);
781
+	}
732 782
 	list ($username) = $smcFunc['db_fetch_row']($request);
733 783
 	$smcFunc['db_free_result']($request);
734 784
 
@@ -766,8 +816,7 @@  discard block
 block discarded – undo
766 816
 			echo $data;
767 817
 			obExit(false);
768 818
 		}
769
-	}
770
-	else
819
+	} else
771 820
 	{
772 821
 		$context += array(
773 822
 			'page_title' => $txt['coppa_title'],
@@ -820,8 +869,9 @@  discard block
 block discarded – undo
820 869
 	{
821 870
 		require_once($sourcedir . '/Subs-Graphics.php');
822 871
 
823
-		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code))
824
-			header('HTTP/1.1 400 Bad Request');
872
+		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) {
873
+					header('HTTP/1.1 400 Bad Request');
874
+		}
825 875
 
826 876
 		// Otherwise just show a pre-defined letter.
827 877
 		elseif (isset($_REQUEST['letter']))
@@ -839,14 +889,13 @@  discard block
 block discarded – undo
839 889
 			header('Content-Type: image/gif');
840 890
 			die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
841 891
 		}
842
-	}
843
-
844
-	elseif ($_REQUEST['format'] === '.wav')
892
+	} elseif ($_REQUEST['format'] === '.wav')
845 893
 	{
846 894
 		require_once($sourcedir . '/Subs-Sound.php');
847 895
 
848
-		if (!createWaveFile($code))
849
-			header('HTTP/1.1 400 Bad Request');
896
+		if (!createWaveFile($code)) {
897
+					header('HTTP/1.1 400 Bad Request');
898
+		}
850 899
 	}
851 900
 
852 901
 	// We all die one day...
Please login to merge, or discard this patch.
Sources/Logging.php 1 patch
Braces   +149 added lines, -107 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Truncate the GET array to a specified length
@@ -26,24 +27,28 @@  discard block
 block discarded – undo
26 27
 function truncateArray($arr, $max_length=1900)
27 28
 {
28 29
 	$curr_length = 0;
29
-	foreach ($arr as $key => $value)
30
-		if (is_array($value))
30
+	foreach ($arr as $key => $value) {
31
+			if (is_array($value))
31 32
 			foreach ($value as $key2 => $value2)
32 33
 				$curr_length += strlen ($value2);
33
-		else
34
-			$curr_length += strlen ($value);
35
-	if ($curr_length <= $max_length)
36
-		return $arr;
37
-	else
34
+	}
35
+		else {
36
+					$curr_length += strlen ($value);
37
+		}
38
+	if ($curr_length <= $max_length) {
39
+			return $arr;
40
+	} else
38 41
 	{
39 42
 		// Truncate each element's value to a reasonable length
40 43
 		$param_max = floor($max_length/count($arr));
41
-		foreach ($arr as $key => &$value)
42
-			if (is_array($value))
44
+		foreach ($arr as $key => &$value) {
45
+					if (is_array($value))
43 46
 				foreach ($value as $key2 => &$value2)
44 47
 					$value2 = substr($value2, 0, $param_max - strlen($key) - 5);
45
-			else
46
-				$value = substr($value, 0, $param_max - strlen($key) - 5);
48
+		}
49
+			else {
50
+							$value = substr($value, 0, $param_max - strlen($key) - 5);
51
+			}
47 52
 		return $arr;
48 53
 	}
49 54
 }
@@ -65,8 +70,9 @@  discard block
 block discarded – undo
65 70
 		// Don't update for every page - this isn't wholly accurate but who cares.
66 71
 		if ($topic)
67 72
 		{
68
-			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic)
69
-				$force = false;
73
+			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) {
74
+							$force = false;
75
+			}
70 76
 			$_SESSION['last_topic_id'] = $topic;
71 77
 		}
72 78
 	}
@@ -79,22 +85,24 @@  discard block
 block discarded – undo
79 85
 	}
80 86
 
81 87
 	// Don't mark them as online more than every so often.
82
-	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force)
83
-		return;
88
+	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) {
89
+			return;
90
+	}
84 91
 
85 92
 	if (!empty($modSettings['who_enabled']))
86 93
 	{
87 94
 		$encoded_get = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
88 95
 
89 96
 		// In the case of a dlattach action, session_var may not be set.
90
-		if (!isset($context['session_var']))
91
-			$context['session_var'] = $_SESSION['session_var'];
97
+		if (!isset($context['session_var'])) {
98
+					$context['session_var'] = $_SESSION['session_var'];
99
+		}
92 100
 
93 101
 		unset($encoded_get['sesc'], $encoded_get[$context['session_var']]);
94 102
 		$encoded_get = $smcFunc['json_encode']($encoded_get);
103
+	} else {
104
+			$encoded_get = '';
95 105
 	}
96
-	else
97
-		$encoded_get = '';
98 106
 
99 107
 	// Guests use 0, members use their session ID.
100 108
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
@@ -134,17 +142,18 @@  discard block
 block discarded – undo
134 142
 		);
135 143
 
136 144
 		// Guess it got deleted.
137
-		if ($smcFunc['db_affected_rows']() == 0)
145
+		if ($smcFunc['db_affected_rows']() == 0) {
146
+					$_SESSION['log_time'] = 0;
147
+		}
148
+	} else {
138 149
 			$_SESSION['log_time'] = 0;
139 150
 	}
140
-	else
141
-		$_SESSION['log_time'] = 0;
142 151
 
143 152
 	// Otherwise, we have to delete and insert.
144 153
 	if (empty($_SESSION['log_time']))
145 154
 	{
146
-		if ($do_delete || !empty($user_info['id']))
147
-			$smcFunc['db_query']('', '
155
+		if ($do_delete || !empty($user_info['id'])) {
156
+					$smcFunc['db_query']('', '
148 157
 				DELETE FROM {db_prefix}log_online
149 158
 				WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'),
150 159
 				array(
@@ -152,6 +161,7 @@  discard block
 block discarded – undo
152 161
 					'log_time' => time() - $modSettings['lastActive'] * 60,
153 162
 				)
154 163
 			);
164
+		}
155 165
 
156 166
 		$smcFunc['db_insert']($do_delete ? 'ignore' : 'replace',
157 167
 			'{db_prefix}log_online',
@@ -165,21 +175,24 @@  discard block
 block discarded – undo
165 175
 	$_SESSION['log_time'] = time();
166 176
 
167 177
 	// Well, they are online now.
168
-	if (empty($_SESSION['timeOnlineUpdated']))
169
-		$_SESSION['timeOnlineUpdated'] = time();
178
+	if (empty($_SESSION['timeOnlineUpdated'])) {
179
+			$_SESSION['timeOnlineUpdated'] = time();
180
+	}
170 181
 
171 182
 	// Set their login time, if not already done within the last minute.
172 183
 	if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa'))))
173 184
 	{
174 185
 		// Don't count longer than 15 minutes.
175
-		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15)
176
-			$_SESSION['timeOnlineUpdated'] = time();
186
+		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) {
187
+					$_SESSION['timeOnlineUpdated'] = time();
188
+		}
177 189
 
178 190
 		$user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
179 191
 		updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in']));
180 192
 
181
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
182
-			cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
193
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
194
+					cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
195
+		}
183 196
 
184 197
 		$user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
185 198
 		$_SESSION['timeOnlineUpdated'] = time();
@@ -216,8 +229,7 @@  discard block
 block discarded – undo
216 229
 			// Oops. maybe we have no more disk space left, or some other troubles, troubles...
217 230
 			// Copy the file back and run for your life!
218 231
 			@copy($cachedir . '/db_last_error_bak.php', $cachedir . '/db_last_error.php');
219
-		}
220
-		else
232
+		} else
221 233
 		{
222 234
 			@touch($boarddir . '/' . 'Settings.php');
223 235
 			return true;
@@ -237,22 +249,27 @@  discard block
 block discarded – undo
237 249
 	global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt;
238 250
 
239 251
 	// Add to Settings.php if you want to show the debugging information.
240
-	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery'))
241
-		return;
252
+	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) {
253
+			return;
254
+	}
242 255
 
243
-	if (empty($_SESSION['view_queries']))
244
-		$_SESSION['view_queries'] = 0;
245
-	if (empty($context['debug']['language_files']))
246
-		$context['debug']['language_files'] = array();
247
-	if (empty($context['debug']['sheets']))
248
-		$context['debug']['sheets'] = array();
256
+	if (empty($_SESSION['view_queries'])) {
257
+			$_SESSION['view_queries'] = 0;
258
+	}
259
+	if (empty($context['debug']['language_files'])) {
260
+			$context['debug']['language_files'] = array();
261
+	}
262
+	if (empty($context['debug']['sheets'])) {
263
+			$context['debug']['sheets'] = array();
264
+	}
249 265
 
250 266
 	$files = get_included_files();
251 267
 	$total_size = 0;
252 268
 	for ($i = 0, $n = count($files); $i < $n; $i++)
253 269
 	{
254
-		if (file_exists($files[$i]))
255
-			$total_size += filesize($files[$i]);
270
+		if (file_exists($files[$i])) {
271
+					$total_size += filesize($files[$i]);
272
+		}
256 273
 		$files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)'));
257 274
 	}
258 275
 
@@ -261,8 +278,9 @@  discard block
 block discarded – undo
261 278
 	{
262 279
 		foreach ($db_cache as $q => $query_data)
263 280
 		{
264
-			if (!empty($query_data['w']))
265
-				$warnings += count($query_data['w']);
281
+			if (!empty($query_data['w'])) {
282
+							$warnings += count($query_data['w']);
283
+			}
266 284
 		}
267 285
 
268 286
 		$_SESSION['debug'] = &$db_cache;
@@ -283,12 +301,14 @@  discard block
 block discarded – undo
283 301
 	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),'
284 302
 	', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>';
285 303
 
286
-	if (function_exists('memory_get_peak_usage'))
287
-		echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
304
+	if (function_exists('memory_get_peak_usage')) {
305
+			echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
306
+	}
288 307
 
289 308
 	// What tokens are active?
290
-	if (isset($_SESSION['token']))
291
-		echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
309
+	if (isset($_SESSION['token'])) {
310
+			echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
311
+	}
292 312
 
293 313
 	if (!empty($modSettings['cache_enable']) && !empty($cache_hits))
294 314
 	{
@@ -302,10 +322,12 @@  discard block
 block discarded – undo
302 322
 			$total_t += $cache_hit['t'];
303 323
 			$total_s += $cache_hit['s'];
304 324
 		}
305
-		if (!isset($cache_misses))
306
-			$cache_misses = array();
307
-		foreach ($cache_misses as $missed)
308
-			$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
325
+		if (!isset($cache_misses)) {
326
+					$cache_misses = array();
327
+		}
328
+		foreach ($cache_misses as $missed) {
329
+					$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
330
+		}
309 331
 
310 332
 		echo '
311 333
 	', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br>
@@ -316,38 +338,44 @@  discard block
 block discarded – undo
316 338
 	<a href="', $scripturl, '?action=viewquery" target="_blank" rel="noopener">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br>
317 339
 	<br>';
318 340
 
319
-	if ($_SESSION['view_queries'] == 1 && !empty($db_cache))
320
-		foreach ($db_cache as $q => $query_data)
341
+	if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) {
342
+			foreach ($db_cache as $q => $query_data)
321 343
 		{
322 344
 			$is_select = strpos(trim($query_data['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($query_data['q'])) != 0;
345
+	}
323 346
 			// Temporary tables created in earlier queries are not explainable.
324 347
 			if ($is_select)
325 348
 			{
326
-				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp)
327
-					if (strpos(trim($query_data['q']), $tmp) !== false)
349
+				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) {
350
+									if (strpos(trim($query_data['q']), $tmp) !== false)
328 351
 					{
329 352
 						$is_select = false;
353
+				}
330 354
 						break;
331 355
 					}
332 356
 			}
333 357
 			// But actual creation of the temporary tables are.
334
-			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0)
335
-				$is_select = true;
358
+			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0) {
359
+							$is_select = true;
360
+			}
336 361
 
337 362
 			// Make the filenames look a bit better.
338
-			if (isset($query_data['f']))
339
-				$query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']);
363
+			if (isset($query_data['f'])) {
364
+							$query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']);
365
+			}
340 366
 
341 367
 			echo '
342 368
 	<strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" rel="noopener" style="text-decoration: none;">' : '', nl2br(str_replace("\t", '&nbsp;&nbsp;&nbsp;', $smcFunc['htmlspecialchars'](ltrim($query_data['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br>
343 369
 	&nbsp;&nbsp;&nbsp;';
344
-			if (!empty($query_data['f']) && !empty($query_data['l']))
345
-				echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']);
370
+			if (!empty($query_data['f']) && !empty($query_data['l'])) {
371
+							echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']);
372
+			}
346 373
 
347
-			if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at']))
348
-				echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>';
349
-			elseif (isset($query_data['t']))
350
-				echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>';
374
+			if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) {
375
+							echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>';
376
+			} elseif (isset($query_data['t'])) {
377
+							echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>';
378
+			}
351 379
 			echo '
352 380
 	<br>';
353 381
 		}
@@ -372,12 +400,14 @@  discard block
 block discarded – undo
372 400
 	global $modSettings, $smcFunc;
373 401
 	static $cache_stats = array();
374 402
 
375
-	if (empty($modSettings['trackStats']))
376
-		return false;
377
-	if (!empty($stats))
378
-		return $cache_stats = array_merge($cache_stats, $stats);
379
-	elseif (empty($cache_stats))
380
-		return false;
403
+	if (empty($modSettings['trackStats'])) {
404
+			return false;
405
+	}
406
+	if (!empty($stats)) {
407
+			return $cache_stats = array_merge($cache_stats, $stats);
408
+	} elseif (empty($cache_stats)) {
409
+			return false;
410
+	}
381 411
 
382 412
 	$setStringUpdate = '';
383 413
 	$insert_keys = array();
@@ -390,10 +420,11 @@  discard block
 block discarded – undo
390 420
 		$setStringUpdate .= '
391 421
 			' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ',';
392 422
 
393
-		if ($change === '+')
394
-			$cache_stats[$field] = 1;
395
-		else
396
-			$update_parameters[$field] = $change;
423
+		if ($change === '+') {
424
+					$cache_stats[$field] = 1;
425
+		} else {
426
+					$update_parameters[$field] = $change;
427
+		}
397 428
 		$insert_keys[$field] = 'int';
398 429
 	}
399 430
 
@@ -457,43 +488,50 @@  discard block
 block discarded – undo
457 488
 	);
458 489
 
459 490
 	// Make sure this particular log is enabled first...
460
-	if (empty($modSettings['modlog_enabled']))
461
-		unset ($log_types['moderate']);
462
-	if (empty($modSettings['userlog_enabled']))
463
-		unset ($log_types['user']);
464
-	if (empty($modSettings['adminlog_enabled']))
465
-		unset ($log_types['admin']);
491
+	if (empty($modSettings['modlog_enabled'])) {
492
+			unset ($log_types['moderate']);
493
+	}
494
+	if (empty($modSettings['userlog_enabled'])) {
495
+			unset ($log_types['user']);
496
+	}
497
+	if (empty($modSettings['adminlog_enabled'])) {
498
+			unset ($log_types['admin']);
499
+	}
466 500
 
467 501
 	call_integration_hook('integrate_log_types', array(&$log_types));
468 502
 
469 503
 	foreach ($logs as $log)
470 504
 	{
471
-		if (!isset($log_types[$log['log_type']]))
472
-			return false;
505
+		if (!isset($log_types[$log['log_type']])) {
506
+					return false;
507
+		}
473 508
 
474
-		if (!is_array($log['extra']))
475
-			trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
509
+		if (!is_array($log['extra'])) {
510
+					trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
511
+		}
476 512
 
477 513
 		// Pull out the parts we want to store separately, but also make sure that the data is proper
478 514
 		if (isset($log['extra']['topic']))
479 515
 		{
480
-			if (!is_numeric($log['extra']['topic']))
481
-				trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
516
+			if (!is_numeric($log['extra']['topic'])) {
517
+							trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
518
+			}
482 519
 			$topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic'];
483 520
 			unset($log['extra']['topic']);
521
+		} else {
522
+					$topic_id = 0;
484 523
 		}
485
-		else
486
-			$topic_id = 0;
487 524
 
488 525
 		if (isset($log['extra']['message']))
489 526
 		{
490
-			if (!is_numeric($log['extra']['message']))
491
-				trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
527
+			if (!is_numeric($log['extra']['message'])) {
528
+							trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
529
+			}
492 530
 			$msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message'];
493 531
 			unset($log['extra']['message']);
532
+		} else {
533
+					$msg_id = 0;
494 534
 		}
495
-		else
496
-			$msg_id = 0;
497 535
 
498 536
 		// @todo cache this?
499 537
 		// Is there an associated report on this?
@@ -520,23 +558,26 @@  discard block
 block discarded – undo
520 558
 			$smcFunc['db_free_result']($request);
521 559
 		}
522 560
 
523
-		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member']))
524
-			trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
561
+		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) {
562
+					trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
563
+		}
525 564
 
526 565
 		if (isset($log['extra']['board']))
527 566
 		{
528
-			if (!is_numeric($log['extra']['board']))
529
-				trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
567
+			if (!is_numeric($log['extra']['board'])) {
568
+							trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
569
+			}
530 570
 			$board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board'];
531 571
 			unset($log['extra']['board']);
572
+		} else {
573
+					$board_id = 0;
532 574
 		}
533
-		else
534
-			$board_id = 0;
535 575
 
536 576
 		if (isset($log['extra']['board_to']))
537 577
 		{
538
-			if (!is_numeric($log['extra']['board_to']))
539
-				trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
578
+			if (!is_numeric($log['extra']['board_to'])) {
579
+							trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
580
+			}
540 581
 			if (empty($board_id))
541 582
 			{
542 583
 				$board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to'];
@@ -544,10 +585,11 @@  discard block
 block discarded – undo
544 585
 			}
545 586
 		}
546 587
 
547
-		if (isset($log['extra']['member_affected']))
548
-			$memID = $log['extra']['member_affected'];
549
-		else
550
-			$memID = $user_info['id'];
588
+		if (isset($log['extra']['member_affected'])) {
589
+					$memID = $log['extra']['member_affected'];
590
+		} else {
591
+					$memID = $user_info['id'];
592
+		}
551 593
 
552 594
 		$inserts[] = array(
553 595
 			time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'],
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +796 added lines, -601 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -392,9 +409,9 @@  discard block
 block discarded – undo
392 409
 				break;
393 410
 			}
394 411
 		}
412
+	} else {
413
+			$id_member = 0;
395 414
 	}
396
-	else
397
-		$id_member = 0;
398 415
 
399 416
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
400 417
 	{
@@ -402,8 +419,9 @@  discard block
 block discarded – undo
402 419
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
403 420
 
404 421
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
405
-		if (empty($cookie_data))
406
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
422
+		if (empty($cookie_data)) {
423
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
424
+		}
407 425
 
408 426
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
409 427
 
@@ -411,16 +429,17 @@  discard block
 block discarded – undo
411 429
 
412 430
 		// Make sure the cookie is set to the correct domain and path
413 431
 		require_once($sourcedir . '/Subs-Auth.php');
414
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
415
-			setLoginCookie((int) $login_span - time(), $id_member);
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
432
+		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) {
433
+					setLoginCookie((int) $login_span - time(), $id_member);
434
+		}
435
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
418 436
 	{
419 437
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 438
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
421 439
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
440
+		if (empty($cookie_data)) {
441
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		}
424 443
 
425 444
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
426 445
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -445,30 +464,34 @@  discard block
 block discarded – undo
445 464
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 465
 			$smcFunc['db_free_result']($request);
447 466
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
449
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
467
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
468
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
469
+			}
450 470
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
471
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
472
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			}
453 474
 		}
454 475
 
455 476
 		// Did we find 'im?  If not, junk it.
456 477
 		if (!empty($user_settings))
457 478
 		{
458 479
 			// As much as the password should be right, we can assume the integration set things up.
459
-			if (!empty($already_verified) && $already_verified === true)
460
-				$check = true;
480
+			if (!empty($already_verified) && $already_verified === true) {
481
+							$check = true;
482
+			}
461 483
 			// SHA-512 hash should be 128 characters long.
462
-			elseif (strlen($password) == 128)
463
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
-			else
465
-				$check = false;
484
+			elseif (strlen($password) == 128) {
485
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
486
+			} else {
487
+							$check = false;
488
+			}
466 489
 
467 490
 			// Wrong password or not activated - either way, you're going nowhere.
468 491
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
492
+		} else {
493
+					$id_member = 0;
469 494
 		}
470
-		else
471
-			$id_member = 0;
472 495
 
473 496
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 497
 		if (!$id_member)
@@ -497,8 +520,9 @@  discard block
 block discarded – undo
497 520
 
498 521
 					list ($tfamember, $tfasecret) = $tfa_data;
499 522
 
500
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
501
-						$tfasecret = null;
523
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
524
+											$tfasecret = null;
525
+					}
502 526
 				}
503 527
 
504 528
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -518,10 +542,12 @@  discard block
 block discarded – undo
518 542
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
519 543
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
520 544
 		{
521
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
545
+			if ($modSettings['tfa_mode'] == 2) {
546
+				//only do this if we are just forcing SOME membergroups
522 547
 			{
523 548
 				//Build an array of ALL user membergroups.
524 549
 				$full_groups = array($user_settings['id_group']);
550
+			}
525 551
 				if (!empty($user_settings['additional_groups']))
526 552
 				{
527 553
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -541,15 +567,17 @@  discard block
 block discarded – undo
541 567
 				);
542 568
 				$row = $smcFunc['db_fetch_assoc']($request);
543 569
 				$smcFunc['db_free_result']($request);
570
+			} else {
571
+							$row['total'] = 1;
544 572
 			}
545
-			else
546
-				$row['total'] = 1; //simplifies logics in the next "if"
573
+			//simplifies logics in the next "if"
547 574
 
548 575
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
549 576
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
550 577
 
551
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
552
-				redirectexit('action=profile;area=tfasetup;forced');
578
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
579
+							redirectexit('action=profile;area=tfasetup;forced');
580
+			}
553 581
 		}
554 582
 	}
555 583
 
@@ -586,33 +614,37 @@  discard block
 block discarded – undo
586 614
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
587 615
 				$user_settings['last_login'] = time();
588 616
 
589
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
590
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
617
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
618
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
619
+				}
591 620
 
592
-				if (!empty($modSettings['cache_enable']))
593
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
621
+				if (!empty($modSettings['cache_enable'])) {
622
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
623
+				}
594 624
 			}
625
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
626
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
595 627
 		}
596
-		elseif (empty($_SESSION['id_msg_last_visit']))
597
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
598 628
 
599 629
 		$username = $user_settings['member_name'];
600 630
 
601
-		if (empty($user_settings['additional_groups']))
602
-			$user_info = array(
631
+		if (empty($user_settings['additional_groups'])) {
632
+					$user_info = array(
603 633
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
604 634
 			);
605
-		else
606
-			$user_info = array(
635
+		} else {
636
+					$user_info = array(
607 637
 				'groups' => array_merge(
608 638
 					array($user_settings['id_group'], $user_settings['id_post_group']),
609 639
 					explode(',', $user_settings['additional_groups'])
610 640
 				)
611 641
 			);
642
+		}
612 643
 
613 644
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
614
-		foreach ($user_info['groups'] as $k => $v)
615
-			$user_info['groups'][$k] = (int) $v;
645
+		foreach ($user_info['groups'] as $k => $v) {
646
+					$user_info['groups'][$k] = (int) $v;
647
+		}
616 648
 
617 649
 		// This is a logged in user, so definitely not a spider.
618 650
 		$user_info['possibly_robot'] = false;
@@ -626,8 +658,7 @@  discard block
 block discarded – undo
626 658
 			$time_system = new DateTime('now', $tz_system);
627 659
 			$time_user = new DateTime('now', $tz_user);
628 660
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
629
-		}
630
-		else
661
+		} else
631 662
 		{
632 663
 			// !!! Compatibility.
633 664
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -641,8 +672,9 @@  discard block
 block discarded – undo
641 672
 		$user_info = array('groups' => array(-1));
642 673
 		$user_settings = array();
643 674
 
644
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
645
-			$_COOKIE[$cookiename] = '';
675
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
676
+					$_COOKIE[$cookiename] = '';
677
+		}
646 678
 
647 679
 		// Expire the 2FA cookie
648 680
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -659,19 +691,20 @@  discard block
 block discarded – undo
659 691
 		}
660 692
 
661 693
 		// Create a login token if it doesn't exist yet.
662
-		if (!isset($_SESSION['token']['post-login']))
663
-			createToken('login');
664
-		else
665
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
694
+		if (!isset($_SESSION['token']['post-login'])) {
695
+					createToken('login');
696
+		} else {
697
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
698
+		}
666 699
 
667 700
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
668 701
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
669 702
 		{
670 703
 			require_once($sourcedir . '/ManageSearchEngines.php');
671 704
 			$user_info['possibly_robot'] = SpiderCheck();
705
+		} elseif (!empty($modSettings['spider_mode'])) {
706
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
672 707
 		}
673
-		elseif (!empty($modSettings['spider_mode']))
674
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
675 708
 		// If we haven't turned on proper spider hunts then have a guess!
676 709
 		else
677 710
 		{
@@ -719,8 +752,9 @@  discard block
 block discarded – undo
719 752
 	$user_info['groups'] = array_unique($user_info['groups']);
720 753
 
721 754
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
722
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
723
-		unset($user_info['ignoreboards'][$tmp]);
755
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
756
+			unset($user_info['ignoreboards'][$tmp]);
757
+	}
724 758
 
725 759
 	// Allow the user to change their language.
726 760
 	if (!empty($modSettings['userLanguage']))
@@ -733,13 +767,14 @@  discard block
 block discarded – undo
733 767
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
734 768
 
735 769
 			// Make it permanent for members.
736
-			if (!empty($user_info['id']))
737
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
738
-			else
739
-				$_SESSION['language'] = $user_info['language'];
770
+			if (!empty($user_info['id'])) {
771
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
772
+			} else {
773
+							$_SESSION['language'] = $user_info['language'];
774
+			}
775
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
776
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
740 777
 		}
741
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
742
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
743 778
 	}
744 779
 
745 780
 	$temp = build_query_board($user_info['id']);
@@ -802,9 +837,9 @@  discard block
 block discarded – undo
802 837
 		}
803 838
 
804 839
 		// Remember redirection is the key to avoiding fallout from your bosses.
805
-		if (!empty($topic))
806
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
807
-		else
840
+		if (!empty($topic)) {
841
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
842
+		} else
808 843
 		{
809 844
 			loadPermissions();
810 845
 			loadTheme();
@@ -822,10 +857,11 @@  discard block
 block discarded – undo
822 857
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
823 858
 	{
824 859
 		// @todo SLOW?
825
-		if (!empty($topic))
826
-			$temp = cache_get_data('topic_board-' . $topic, 120);
827
-		else
828
-			$temp = cache_get_data('board-' . $board, 120);
860
+		if (!empty($topic)) {
861
+					$temp = cache_get_data('topic_board-' . $topic, 120);
862
+		} else {
863
+					$temp = cache_get_data('board-' . $board, 120);
864
+		}
829 865
 
830 866
 		if (!empty($temp))
831 867
 		{
@@ -863,8 +899,9 @@  discard block
 block discarded – undo
863 899
 			$row = $smcFunc['db_fetch_assoc']($request);
864 900
 
865 901
 			// Set the current board.
866
-			if (!empty($row['id_board']))
867
-				$board = $row['id_board'];
902
+			if (!empty($row['id_board'])) {
903
+							$board = $row['id_board'];
904
+			}
868 905
 
869 906
 			// Basic operating information. (globals... :/)
870 907
 			$board_info = array(
@@ -900,21 +937,23 @@  discard block
 block discarded – undo
900 937
 
901 938
 			do
902 939
 			{
903
-				if (!empty($row['id_moderator']))
904
-					$board_info['moderators'][$row['id_moderator']] = array(
940
+				if (!empty($row['id_moderator'])) {
941
+									$board_info['moderators'][$row['id_moderator']] = array(
905 942
 						'id' => $row['id_moderator'],
906 943
 						'name' => $row['real_name'],
907 944
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
908 945
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
909 946
 					);
947
+				}
910 948
 
911
-				if (!empty($row['id_moderator_group']))
912
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
949
+				if (!empty($row['id_moderator_group'])) {
950
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
913 951
 						'id' => $row['id_moderator_group'],
914 952
 						'name' => $row['group_name'],
915 953
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
916 954
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
917 955
 					);
956
+				}
918 957
 			}
919 958
 			while ($row = $smcFunc['db_fetch_assoc']($request));
920 959
 
@@ -946,12 +985,12 @@  discard block
 block discarded – undo
946 985
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
947 986
 			{
948 987
 				// @todo SLOW?
949
-				if (!empty($topic))
950
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
988
+				if (!empty($topic)) {
989
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
990
+				}
951 991
 				cache_put_data('board-' . $board, $board_info, 120);
952 992
 			}
953
-		}
954
-		else
993
+		} else
955 994
 		{
956 995
 			// Otherwise the topic is invalid, there are no moderators, etc.
957 996
 			$board_info = array(
@@ -965,8 +1004,9 @@  discard block
 block discarded – undo
965 1004
 		$smcFunc['db_free_result']($request);
966 1005
 	}
967 1006
 
968
-	if (!empty($topic))
969
-		$_GET['board'] = (int) $board;
1007
+	if (!empty($topic)) {
1008
+			$_GET['board'] = (int) $board;
1009
+	}
970 1010
 
971 1011
 	if (!empty($board))
972 1012
 	{
@@ -976,10 +1016,12 @@  discard block
 block discarded – undo
976 1016
 		// Now check if the user is a moderator.
977 1017
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
978 1018
 
979
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
980
-			$board_info['error'] = 'access';
981
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
982
-			$board_info['error'] = 'access';
1019
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1020
+					$board_info['error'] = 'access';
1021
+		}
1022
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1023
+					$board_info['error'] = 'access';
1024
+		}
983 1025
 
984 1026
 		// Build up the linktree.
985 1027
 		$context['linktree'] = array_merge(
@@ -1002,8 +1044,9 @@  discard block
 block discarded – undo
1002 1044
 	$context['current_board'] = $board;
1003 1045
 
1004 1046
 	// No posting in redirection boards!
1005
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1006
-		$board_info['error'] == 'post_in_redirect';
1047
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1048
+			$board_info['error'] == 'post_in_redirect';
1049
+	}
1007 1050
 
1008 1051
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1009 1052
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1029,24 +1072,23 @@  discard block
 block discarded – undo
1029 1072
 			ob_end_clean();
1030 1073
 			header('HTTP/1.1 403 Forbidden');
1031 1074
 			die;
1032
-		}
1033
-		elseif ($board_info['error'] == 'post_in_redirect')
1075
+		} elseif ($board_info['error'] == 'post_in_redirect')
1034 1076
 		{
1035 1077
 			// Slightly different error message here...
1036 1078
 			fatal_lang_error('cannot_post_redirect', false);
1037
-		}
1038
-		elseif ($user_info['is_guest'])
1079
+		} elseif ($user_info['is_guest'])
1039 1080
 		{
1040 1081
 			loadLanguage('Errors');
1041 1082
 			is_not_guest($txt['topic_gone']);
1083
+		} else {
1084
+					fatal_lang_error('topic_gone', false);
1042 1085
 		}
1043
-		else
1044
-			fatal_lang_error('topic_gone', false);
1045 1086
 	}
1046 1087
 
1047
-	if ($user_info['is_mod'])
1048
-		$user_info['groups'][] = 3;
1049
-}
1088
+	if ($user_info['is_mod']) {
1089
+			$user_info['groups'][] = 3;
1090
+	}
1091
+	}
1050 1092
 
1051 1093
 /**
1052 1094
  * Load this user's permissions.
@@ -1067,8 +1109,9 @@  discard block
 block discarded – undo
1067 1109
 		asort($cache_groups);
1068 1110
 		$cache_groups = implode(',', $cache_groups);
1069 1111
 		// If it's a spider then cache it different.
1070
-		if ($user_info['possibly_robot'])
1071
-			$cache_groups .= '-spider';
1112
+		if ($user_info['possibly_robot']) {
1113
+					$cache_groups .= '-spider';
1114
+		}
1072 1115
 
1073 1116
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1074 1117
 		{
@@ -1076,9 +1119,9 @@  discard block
 block discarded – undo
1076 1119
 			banPermissions();
1077 1120
 
1078 1121
 			return;
1122
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1123
+					list ($user_info['permissions'], $removals) = $temp;
1079 1124
 		}
1080
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1081
-			list ($user_info['permissions'], $removals) = $temp;
1082 1125
 	}
1083 1126
 
1084 1127
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1100,23 +1143,26 @@  discard block
 block discarded – undo
1100 1143
 		$removals = array();
1101 1144
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1102 1145
 		{
1103
-			if (empty($row['add_deny']))
1104
-				$removals[] = $row['permission'];
1105
-			else
1106
-				$user_info['permissions'][] = $row['permission'];
1146
+			if (empty($row['add_deny'])) {
1147
+							$removals[] = $row['permission'];
1148
+			} else {
1149
+							$user_info['permissions'][] = $row['permission'];
1150
+			}
1107 1151
 		}
1108 1152
 		$smcFunc['db_free_result']($request);
1109 1153
 
1110
-		if (isset($cache_groups))
1111
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1154
+		if (isset($cache_groups)) {
1155
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1156
+		}
1112 1157
 	}
1113 1158
 
1114 1159
 	// Get the board permissions.
1115 1160
 	if (!empty($board))
1116 1161
 	{
1117 1162
 		// Make sure the board (if any) has been loaded by loadBoard().
1118
-		if (!isset($board_info['profile']))
1119
-			fatal_lang_error('no_board');
1163
+		if (!isset($board_info['profile'])) {
1164
+					fatal_lang_error('no_board');
1165
+		}
1120 1166
 
1121 1167
 		$request = $smcFunc['db_query']('', '
1122 1168
 			SELECT permission, add_deny
@@ -1132,20 +1178,23 @@  discard block
 block discarded – undo
1132 1178
 		);
1133 1179
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1134 1180
 		{
1135
-			if (empty($row['add_deny']))
1136
-				$removals[] = $row['permission'];
1137
-			else
1138
-				$user_info['permissions'][] = $row['permission'];
1181
+			if (empty($row['add_deny'])) {
1182
+							$removals[] = $row['permission'];
1183
+			} else {
1184
+							$user_info['permissions'][] = $row['permission'];
1185
+			}
1139 1186
 		}
1140 1187
 		$smcFunc['db_free_result']($request);
1141 1188
 	}
1142 1189
 
1143 1190
 	// Remove all the permissions they shouldn't have ;).
1144
-	if (!empty($modSettings['permission_enable_deny']))
1145
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1191
+	if (!empty($modSettings['permission_enable_deny'])) {
1192
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1193
+	}
1146 1194
 
1147
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1148
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1195
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1196
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1197
+	}
1149 1198
 
1150 1199
 	// Banned?  Watch, don't touch..
1151 1200
 	banPermissions();
@@ -1157,17 +1206,18 @@  discard block
 block discarded – undo
1157 1206
 		{
1158 1207
 			require_once($sourcedir . '/Subs-Auth.php');
1159 1208
 			rebuildModCache();
1209
+		} else {
1210
+					$user_info['mod_cache'] = $_SESSION['mc'];
1160 1211
 		}
1161
-		else
1162
-			$user_info['mod_cache'] = $_SESSION['mc'];
1163 1212
 
1164 1213
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1165 1214
 		// For example this drastically simplifies certain changes to the profile area.
1166 1215
 		$user_info['permissions'][] = 'is_not_guest';
1167 1216
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1168 1217
 		$user_info['permissions'][] = 'profile_view_own';
1169
-		if (in_array('profile_view', $user_info['permissions']))
1170
-			$user_info['permissions'][] = 'profile_view_any';
1218
+		if (in_array('profile_view', $user_info['permissions'])) {
1219
+					$user_info['permissions'][] = 'profile_view_any';
1220
+		}
1171 1221
 	}
1172 1222
 }
1173 1223
 
@@ -1185,8 +1235,9 @@  discard block
 block discarded – undo
1185 1235
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl, $user_info;
1186 1236
 
1187 1237
 	// Can't just look for no users :P.
1188
-	if (empty($users))
1189
-		return array();
1238
+	if (empty($users)) {
1239
+			return array();
1240
+	}
1190 1241
 
1191 1242
 	// Pass the set value
1192 1243
 	$context['loadMemberContext_set'] = $set;
@@ -1201,8 +1252,9 @@  discard block
 block discarded – undo
1201 1252
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1202 1253
 		{
1203 1254
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1204
-			if ($data == null)
1205
-				continue;
1255
+			if ($data == null) {
1256
+							continue;
1257
+			}
1206 1258
 
1207 1259
 			$loaded_ids[] = $data['id_member'];
1208 1260
 			$user_profile[$data['id_member']] = $data;
@@ -1269,16 +1321,19 @@  discard block
 block discarded – undo
1269 1321
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1270 1322
 
1271 1323
 			// Take care of proxying avatar if required, do this here for maximum reach
1272
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1273
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1324
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1325
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1326
+			}
1274 1327
 
1275 1328
 			// Keep track of the member's normal member group
1276 1329
 			$row['primary_group'] = $row['member_group'];
1277 1330
 
1278
-			if (isset($row['member_ip']))
1279
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1280
-			if (isset($row['member_ip2']))
1281
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1331
+			if (isset($row['member_ip'])) {
1332
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1333
+			}
1334
+			if (isset($row['member_ip2'])) {
1335
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1336
+			}
1282 1337
 			$new_loaded_ids[] = $row['id_member'];
1283 1338
 			$loaded_ids[] = $row['id_member'];
1284 1339
 			$row['options'] = array();
@@ -1297,8 +1352,9 @@  discard block
 block discarded – undo
1297 1352
 				'loaded_ids' => $new_loaded_ids,
1298 1353
 			)
1299 1354
 		);
1300
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1301
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1355
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1356
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1357
+		}
1302 1358
 		$smcFunc['db_free_result']($request);
1303 1359
 	}
1304 1360
 
@@ -1309,10 +1365,11 @@  discard block
 block discarded – undo
1309 1365
 	{
1310 1366
 		foreach ($loaded_ids as $a_member)
1311 1367
 		{
1312
-			if (!empty($user_profile[$a_member]['additional_groups']))
1313
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1314
-			else
1315
-				$groups = array($user_profile[$a_member]['id_group']);
1368
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1369
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1370
+			} else {
1371
+							$groups = array($user_profile[$a_member]['id_group']);
1372
+			}
1316 1373
 
1317 1374
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1318 1375
 
@@ -1325,8 +1382,9 @@  discard block
 block discarded – undo
1325 1382
 
1326 1383
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1327 1384
 	{
1328
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1329
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1385
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1386
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1387
+		}
1330 1388
 	}
1331 1389
 
1332 1390
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1352,14 +1410,17 @@  discard block
 block discarded – undo
1352 1410
 		foreach ($temp_mods as $id)
1353 1411
 		{
1354 1412
 			// By popular demand, don't show admins or global moderators as moderators.
1355
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1356
-				$user_profile[$id]['member_group'] = $row['member_group'];
1413
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1414
+							$user_profile[$id]['member_group'] = $row['member_group'];
1415
+			}
1357 1416
 
1358 1417
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1359
-			if (!empty($row['icons']))
1360
-				$user_profile[$id]['icons'] = $row['icons'];
1361
-			if (!empty($row['member_group_color']))
1362
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1418
+			if (!empty($row['icons'])) {
1419
+							$user_profile[$id]['icons'] = $row['icons'];
1420
+			}
1421
+			if (!empty($row['member_group_color'])) {
1422
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1423
+			}
1363 1424
 		}
1364 1425
 	}
1365 1426
 
@@ -1381,12 +1442,14 @@  discard block
 block discarded – undo
1381 1442
 	static $loadedLanguages = array();
1382 1443
 
1383 1444
 	// If this person's data is already loaded, skip it.
1384
-	if (isset($dataLoaded[$user]))
1385
-		return true;
1445
+	if (isset($dataLoaded[$user])) {
1446
+			return true;
1447
+	}
1386 1448
 
1387 1449
 	// We can't load guests or members not loaded by loadMemberData()!
1388
-	if ($user == 0)
1389
-		return false;
1450
+	if ($user == 0) {
1451
+			return false;
1452
+	}
1390 1453
 	if (!isset($user_profile[$user]))
1391 1454
 	{
1392 1455
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1412,12 +1475,16 @@  discard block
 block discarded – undo
1412 1475
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1413 1476
 
1414 1477
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1415
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1478
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1479
+		//icon is set and exists
1416 1480
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1417
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1481
+	} elseif (isset($profile['icons'][1])) {
1482
+		//icon is set and doesn't exist, fallback to default
1418 1483
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1419
-	else //not set, bye bye
1484
+	} else {
1485
+		//not set, bye bye
1420 1486
 		$group_icon_url = '';
1487
+	}
1421 1488
 
1422 1489
 	// These minimal values are always loaded
1423 1490
 	$memberContext[$user] = array(
@@ -1436,8 +1503,9 @@  discard block
 block discarded – undo
1436 1503
 	if ($context['loadMemberContext_set'] != 'minimal')
1437 1504
 	{
1438 1505
 		// Go the extra mile and load the user's native language name.
1439
-		if (empty($loadedLanguages))
1440
-			$loadedLanguages = getLanguages();
1506
+		if (empty($loadedLanguages)) {
1507
+					$loadedLanguages = getLanguages();
1508
+		}
1441 1509
 
1442 1510
 		$memberContext[$user] += array(
1443 1511
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1492,31 +1560,33 @@  discard block
 block discarded – undo
1492 1560
 	{
1493 1561
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1494 1562
 		{
1495
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1496
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1497
-			else
1498
-				$image = get_gravatar_url($profile['email_address']);
1499
-		}
1500
-		else
1563
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1564
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1565
+			} else {
1566
+							$image = get_gravatar_url($profile['email_address']);
1567
+			}
1568
+		} else
1501 1569
 		{
1502 1570
 			// So it's stored in the member table?
1503 1571
 			if (!empty($profile['avatar']))
1504 1572
 			{
1505 1573
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1574
+			} elseif (!empty($profile['filename'])) {
1575
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1506 1576
 			}
1507
-			elseif (!empty($profile['filename']))
1508
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1509 1577
 			// Right... no avatar...use the default one
1510
-			else
1511
-				$image = $modSettings['avatar_url'] . '/default.png';
1578
+			else {
1579
+							$image = $modSettings['avatar_url'] . '/default.png';
1580
+			}
1512 1581
 		}
1513
-		if (!empty($image))
1514
-			$memberContext[$user]['avatar'] = array(
1582
+		if (!empty($image)) {
1583
+					$memberContext[$user]['avatar'] = array(
1515 1584
 				'name' => $profile['avatar'],
1516 1585
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1517 1586
 				'href' => $image,
1518 1587
 				'url' => $image,
1519 1588
 			);
1589
+		}
1520 1590
 	}
1521 1591
 
1522 1592
 	// Are we also loading the members custom fields into context?
@@ -1524,13 +1594,15 @@  discard block
 block discarded – undo
1524 1594
 	{
1525 1595
 		$memberContext[$user]['custom_fields'] = array();
1526 1596
 
1527
-		if (!isset($context['display_fields']))
1528
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1597
+		if (!isset($context['display_fields'])) {
1598
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1599
+		}
1529 1600
 
1530 1601
 		foreach ($context['display_fields'] as $custom)
1531 1602
 		{
1532
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1533
-				continue;
1603
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1604
+							continue;
1605
+			}
1534 1606
 
1535 1607
 			$value = $profile['options'][$custom['col_name']];
1536 1608
 
@@ -1538,31 +1610,36 @@  discard block
 block discarded – undo
1538 1610
 			$currentKey = 0;
1539 1611
 
1540 1612
 			// Create a key => value array for multiple options fields
1541
-			if (!empty($custom['options']))
1542
-				foreach ($custom['options'] as $k => $v)
1613
+			if (!empty($custom['options'])) {
1614
+							foreach ($custom['options'] as $k => $v)
1543 1615
 				{
1544 1616
 					$fieldOptions[] = $v;
1545
-					if (empty($currentKey))
1546
-						$currentKey = $v == $value ? $k : 0;
1617
+			}
1618
+					if (empty($currentKey)) {
1619
+											$currentKey = $v == $value ? $k : 0;
1620
+					}
1547 1621
 				}
1548 1622
 
1549 1623
 			// BBC?
1550
-			if ($custom['bbc'])
1551
-				$value = parse_bbc($value);
1624
+			if ($custom['bbc']) {
1625
+							$value = parse_bbc($value);
1626
+			}
1552 1627
 
1553 1628
 			// ... or checkbox?
1554
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1555
-				$value = $value ? $txt['yes'] : $txt['no'];
1629
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1630
+							$value = $value ? $txt['yes'] : $txt['no'];
1631
+			}
1556 1632
 
1557 1633
 			// Enclosing the user input within some other text?
1558
-			if (!empty($custom['enclose']))
1559
-				$value = strtr($custom['enclose'], array(
1634
+			if (!empty($custom['enclose'])) {
1635
+							$value = strtr($custom['enclose'], array(
1560 1636
 					'{SCRIPTURL}' => $scripturl,
1561 1637
 					'{IMAGES_URL}' => $settings['images_url'],
1562 1638
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1563 1639
 					'{INPUT}' => $value,
1564 1640
 					'{KEY}' => $currentKey,
1565 1641
 				));
1642
+			}
1566 1643
 
1567 1644
 			$memberContext[$user]['custom_fields'][] = array(
1568 1645
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1589,8 +1666,9 @@  discard block
 block discarded – undo
1589 1666
 	global $smcFunc, $txt, $scripturl, $settings;
1590 1667
 
1591 1668
 	// Do not waste my time...
1592
-	if (empty($users) || empty($params))
1593
-		return false;
1669
+	if (empty($users) || empty($params)) {
1670
+			return false;
1671
+	}
1594 1672
 
1595 1673
 	// Make sure it's an array.
1596 1674
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1617,41 +1695,48 @@  discard block
 block discarded – undo
1617 1695
 		$currentKey = 0;
1618 1696
 
1619 1697
 		// Create a key => value array for multiple options fields
1620
-		if (!empty($row['field_options']))
1621
-			foreach (explode(',', $row['field_options']) as $k => $v)
1698
+		if (!empty($row['field_options'])) {
1699
+					foreach (explode(',', $row['field_options']) as $k => $v)
1622 1700
 			{
1623 1701
 				$fieldOptions[] = $v;
1624
-				if (empty($currentKey))
1625
-					$currentKey = $v == $row['value'] ? $k : 0;
1702
+		}
1703
+				if (empty($currentKey)) {
1704
+									$currentKey = $v == $row['value'] ? $k : 0;
1705
+				}
1626 1706
 			}
1627 1707
 
1628 1708
 		// BBC?
1629
-		if (!empty($row['bbc']))
1630
-			$row['value'] = parse_bbc($row['value']);
1709
+		if (!empty($row['bbc'])) {
1710
+					$row['value'] = parse_bbc($row['value']);
1711
+		}
1631 1712
 
1632 1713
 		// ... or checkbox?
1633
-		elseif (isset($row['type']) && $row['type'] == 'check')
1634
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1714
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1715
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1716
+		}
1635 1717
 
1636 1718
 		// Enclosing the user input within some other text?
1637
-		if (!empty($row['enclose']))
1638
-			$row['value'] = strtr($row['enclose'], array(
1719
+		if (!empty($row['enclose'])) {
1720
+					$row['value'] = strtr($row['enclose'], array(
1639 1721
 				'{SCRIPTURL}' => $scripturl,
1640 1722
 				'{IMAGES_URL}' => $settings['images_url'],
1641 1723
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1642 1724
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1643 1725
 				'{KEY}' => $currentKey,
1644 1726
 			));
1727
+		}
1645 1728
 
1646 1729
 		// Send a simple array if there is just 1 param
1647
-		if (count($params) == 1)
1648
-			$return[$row['id_member']] = $row;
1730
+		if (count($params) == 1) {
1731
+					$return[$row['id_member']] = $row;
1732
+		}
1649 1733
 
1650 1734
 		// More than 1? knock yourself out...
1651 1735
 		else
1652 1736
 		{
1653
-			if (!isset($return[$row['id_member']]))
1654
-				$return[$row['id_member']] = array();
1737
+			if (!isset($return[$row['id_member']])) {
1738
+							$return[$row['id_member']] = array();
1739
+			}
1655 1740
 
1656 1741
 			$return[$row['id_member']][$row['variable']] = $row;
1657 1742
 		}
@@ -1685,8 +1770,9 @@  discard block
 block discarded – undo
1685 1770
 	global $context;
1686 1771
 
1687 1772
 	// Don't know any browser!
1688
-	if (empty($context['browser']))
1689
-		detectBrowser();
1773
+	if (empty($context['browser'])) {
1774
+			detectBrowser();
1775
+	}
1690 1776
 
1691 1777
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1692 1778
 }
@@ -1704,8 +1790,9 @@  discard block
 block discarded – undo
1704 1790
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1705 1791
 
1706 1792
 	// The theme was specified by parameter.
1707
-	if (!empty($id_theme))
1708
-		$id_theme = (int) $id_theme;
1793
+	if (!empty($id_theme)) {
1794
+			$id_theme = (int) $id_theme;
1795
+	}
1709 1796
 	// The theme was specified by REQUEST.
1710 1797
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1711 1798
 	{
@@ -1713,54 +1800,61 @@  discard block
 block discarded – undo
1713 1800
 		$_SESSION['id_theme'] = $id_theme;
1714 1801
 	}
1715 1802
 	// The theme was specified by REQUEST... previously.
1716
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1717
-		$id_theme = (int) $_SESSION['id_theme'];
1803
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1804
+			$id_theme = (int) $_SESSION['id_theme'];
1805
+	}
1718 1806
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1719
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1720
-		$id_theme = $user_info['theme'];
1807
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1808
+			$id_theme = $user_info['theme'];
1809
+	}
1721 1810
 	// The theme was specified by the board.
1722
-	elseif (!empty($board_info['theme']))
1723
-		$id_theme = $board_info['theme'];
1811
+	elseif (!empty($board_info['theme'])) {
1812
+			$id_theme = $board_info['theme'];
1813
+	}
1724 1814
 	// The theme is the forum's default.
1725
-	else
1726
-		$id_theme = $modSettings['theme_guests'];
1815
+	else {
1816
+			$id_theme = $modSettings['theme_guests'];
1817
+	}
1727 1818
 
1728 1819
 	// We already load the basic stuff?
1729 1820
 	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1730 1821
 	{
1731 1822
 		// Verify the id_theme... no foul play.
1732 1823
 		// Always allow the board specific theme, if they are overriding.
1733
-		if (!empty($board_info['theme']) && $board_info['override_theme'])
1734
-			$id_theme = $board_info['theme'];
1824
+		if (!empty($board_info['theme']) && $board_info['override_theme']) {
1825
+					$id_theme = $board_info['theme'];
1826
+		}
1735 1827
 		// If they have specified a particular theme to use with SSI allow it to be used.
1736
-		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1737
-			$id_theme = (int) $id_theme;
1738
-		elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1828
+		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1829
+					$id_theme = (int) $id_theme;
1830
+		} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1739 1831
 		{
1740 1832
 			$themes = explode(',', $modSettings['enableThemes']);
1741
-			if (!in_array($id_theme, $themes))
1742
-				$id_theme = $modSettings['theme_guests'];
1743
-			else
1744
-				$id_theme = (int) $id_theme;
1833
+			if (!in_array($id_theme, $themes)) {
1834
+							$id_theme = $modSettings['theme_guests'];
1835
+			} else {
1836
+							$id_theme = (int) $id_theme;
1837
+			}
1838
+		} else {
1839
+					$id_theme = (int) $id_theme;
1745 1840
 		}
1746
-		else
1747
-			$id_theme = (int) $id_theme;
1748 1841
 
1749 1842
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1750 1843
 
1751 1844
 		// Disable image proxy if we don't have SSL enabled
1752
-		if (empty($modSettings['force_ssl']))
1753
-			$image_proxy_enabled = false;
1845
+		if (empty($modSettings['force_ssl'])) {
1846
+					$image_proxy_enabled = false;
1847
+		}
1754 1848
 
1755 1849
 		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1756 1850
 		{
1757 1851
 			$themeData = $temp;
1758 1852
 			$flag = true;
1853
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1854
+					$themeData = $temp + array($member => array());
1855
+		} else {
1856
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1759 1857
 		}
1760
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1761
-			$themeData = $temp + array($member => array());
1762
-		else
1763
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1764 1858
 
1765 1859
 		if (empty($flag))
1766 1860
 		{
@@ -1779,31 +1873,37 @@  discard block
 block discarded – undo
1779 1873
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1780 1874
 			{
1781 1875
 				// There are just things we shouldn't be able to change as members.
1782
-				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1783
-					continue;
1876
+				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1877
+									continue;
1878
+				}
1784 1879
 
1785 1880
 				// If this is the theme_dir of the default theme, store it.
1786
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1787
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1881
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1882
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1883
+				}
1788 1884
 
1789 1885
 				// If this isn't set yet, is a theme option, or is not the default theme..
1790
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1791
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1886
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1887
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1888
+				}
1792 1889
 			}
1793 1890
 			$smcFunc['db_free_result']($result);
1794 1891
 
1795
-			if (!empty($themeData[-1]))
1796
-				foreach ($themeData[-1] as $k => $v)
1892
+			if (!empty($themeData[-1])) {
1893
+							foreach ($themeData[-1] as $k => $v)
1797 1894
 				{
1798 1895
 					if (!isset($themeData[$member][$k]))
1799 1896
 						$themeData[$member][$k] = $v;
1897
+			}
1800 1898
 				}
1801 1899
 
1802
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1803
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1900
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1901
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1902
+			}
1804 1903
 			// Only if we didn't already load that part of the cache...
1805
-			elseif (!isset($temp))
1806
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1904
+			elseif (!isset($temp)) {
1905
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1906
+			}
1807 1907
 		}
1808 1908
 
1809 1909
 		$settings = $themeData[0];
@@ -1820,17 +1920,20 @@  discard block
 block discarded – undo
1820 1920
 		$settings['template_dirs'][] = $settings['theme_dir'];
1821 1921
 
1822 1922
 		// Based on theme (if there is one).
1823
-		if (!empty($settings['base_theme_dir']))
1824
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1923
+		if (!empty($settings['base_theme_dir'])) {
1924
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1925
+		}
1825 1926
 
1826 1927
 		// Lastly the default theme.
1827
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1828
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1928
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1929
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1930
+		}
1829 1931
 	}
1830 1932
 
1831 1933
 
1832
-	if (!$initialize)
1833
-		return;
1934
+	if (!$initialize) {
1935
+			return;
1936
+	}
1834 1937
 
1835 1938
 	// Check to see if we're forcing SSL
1836 1939
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1851,8 +1954,9 @@  discard block
 block discarded – undo
1851 1954
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1852 1955
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1853 1956
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1854
-		if ($temp != '/')
1855
-			$detected_url .= $temp;
1957
+		if ($temp != '/') {
1958
+					$detected_url .= $temp;
1959
+		}
1856 1960
 	}
1857 1961
 	if (isset($detected_url) && $detected_url != $boardurl)
1858 1962
 	{
@@ -1864,8 +1968,9 @@  discard block
 block discarded – undo
1864 1968
 			foreach ($aliases as $alias)
1865 1969
 			{
1866 1970
 				// Rip off all the boring parts, spaces, etc.
1867
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1868
-					$do_fix = true;
1971
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1972
+									$do_fix = true;
1973
+				}
1869 1974
 			}
1870 1975
 		}
1871 1976
 
@@ -1873,21 +1978,23 @@  discard block
 block discarded – undo
1873 1978
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1874 1979
 		{
1875 1980
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1876
-			if (empty($_GET))
1877
-				redirectexit('wwwRedirect');
1878
-			else
1981
+			if (empty($_GET)) {
1982
+							redirectexit('wwwRedirect');
1983
+			} else
1879 1984
 			{
1880 1985
 				$k = key($_GET);
1881 1986
 				$v = current($_GET);
1882 1987
 
1883
-				if ($k != 'wwwRedirect')
1884
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1988
+				if ($k != 'wwwRedirect') {
1989
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1990
+				}
1885 1991
 			}
1886 1992
 		}
1887 1993
 
1888 1994
 		// #3 is just a check for SSL...
1889
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1890
-			$do_fix = true;
1995
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1996
+					$do_fix = true;
1997
+		}
1891 1998
 
1892 1999
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1893 2000
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1922,8 +2029,9 @@  discard block
 block discarded – undo
1922 2029
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1923 2030
 				}
1924 2031
 			}
1925
-			foreach ($context['linktree'] as $k => $dummy)
1926
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2032
+			foreach ($context['linktree'] as $k => $dummy) {
2033
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2034
+			}
1927 2035
 		}
1928 2036
 	}
1929 2037
 	// Set up the contextual user array.
@@ -1942,16 +2050,16 @@  discard block
 block discarded – undo
1942 2050
 			'email' => $user_info['email'],
1943 2051
 			'ignoreusers' => $user_info['ignoreusers'],
1944 2052
 		);
1945
-		if (!$context['user']['is_guest'])
1946
-			$context['user']['name'] = $user_info['name'];
1947
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1948
-			$context['user']['name'] = $txt['guest_title'];
2053
+		if (!$context['user']['is_guest']) {
2054
+					$context['user']['name'] = $user_info['name'];
2055
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2056
+					$context['user']['name'] = $txt['guest_title'];
2057
+		}
1949 2058
 
1950 2059
 		// Determine the current smiley set.
1951 2060
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1952 2061
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1953
-	}
1954
-	else
2062
+	} else
1955 2063
 	{
1956 2064
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1957 2065
 		$context['user'] = array(
@@ -1985,18 +2093,24 @@  discard block
 block discarded – undo
1985 2093
 	}
1986 2094
 
1987 2095
 	// Some basic information...
1988
-	if (!isset($context['html_headers']))
1989
-		$context['html_headers'] = '';
1990
-	if (!isset($context['javascript_files']))
1991
-		$context['javascript_files'] = array();
1992
-	if (!isset($context['css_files']))
1993
-		$context['css_files'] = array();
1994
-	if (!isset($context['css_header']))
1995
-		$context['css_header'] = array();
1996
-	if (!isset($context['javascript_inline']))
1997
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1998
-	if (!isset($context['javascript_vars']))
1999
-		$context['javascript_vars'] = array();
2096
+	if (!isset($context['html_headers'])) {
2097
+			$context['html_headers'] = '';
2098
+	}
2099
+	if (!isset($context['javascript_files'])) {
2100
+			$context['javascript_files'] = array();
2101
+	}
2102
+	if (!isset($context['css_files'])) {
2103
+			$context['css_files'] = array();
2104
+	}
2105
+	if (!isset($context['css_header'])) {
2106
+			$context['css_header'] = array();
2107
+	}
2108
+	if (!isset($context['javascript_inline'])) {
2109
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2110
+	}
2111
+	if (!isset($context['javascript_vars'])) {
2112
+			$context['javascript_vars'] = array();
2113
+	}
2000 2114
 
2001 2115
 	$context['login_url'] =  $scripturl . '?action=login2';
2002 2116
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2008,16 +2122,18 @@  discard block
 block discarded – undo
2008 2122
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2009 2123
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2010 2124
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2011
-	if (isset($modSettings['load_average']))
2012
-		$context['load_average'] = $modSettings['load_average'];
2125
+	if (isset($modSettings['load_average'])) {
2126
+			$context['load_average'] = $modSettings['load_average'];
2127
+	}
2013 2128
 
2014 2129
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2015 2130
 	detectBrowser();
2016 2131
 
2017 2132
 	// Set the top level linktree up.
2018 2133
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2019
-	if (empty($context['linktree']))
2020
-		$context['linktree'] = array();
2134
+	if (empty($context['linktree'])) {
2135
+			$context['linktree'] = array();
2136
+	}
2021 2137
 	array_unshift($context['linktree'], array(
2022 2138
 		'url' => $scripturl,
2023 2139
 		'name' => $context['forum_name_html_safe']
@@ -2026,8 +2142,9 @@  discard block
 block discarded – undo
2026 2142
 	// This allows sticking some HTML on the page output - useful for controls.
2027 2143
 	$context['insert_after_template'] = '';
2028 2144
 
2029
-	if (!isset($txt))
2030
-		$txt = array();
2145
+	if (!isset($txt)) {
2146
+			$txt = array();
2147
+	}
2031 2148
 
2032 2149
 	$simpleActions = array(
2033 2150
 		'findmember',
@@ -2073,9 +2190,10 @@  discard block
 block discarded – undo
2073 2190
 
2074 2191
 	// See if theres any extra param to check.
2075 2192
 	$requiresXML = false;
2076
-	foreach ($extraParams as $key => $extra)
2077
-		if (isset($_REQUEST[$extra]))
2193
+	foreach ($extraParams as $key => $extra) {
2194
+			if (isset($_REQUEST[$extra]))
2078 2195
 			$requiresXML = true;
2196
+	}
2079 2197
 
2080 2198
 	// Output is fully XML, so no need for the index template.
2081 2199
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2090,37 +2208,39 @@  discard block
 block discarded – undo
2090 2208
 	{
2091 2209
 		loadLanguage('index+Modifications');
2092 2210
 		$context['template_layers'] = array();
2093
-	}
2094
-
2095
-	else
2211
+	} else
2096 2212
 	{
2097 2213
 		// Custom templates to load, or just default?
2098
-		if (isset($settings['theme_templates']))
2099
-			$templates = explode(',', $settings['theme_templates']);
2100
-		else
2101
-			$templates = array('index');
2214
+		if (isset($settings['theme_templates'])) {
2215
+					$templates = explode(',', $settings['theme_templates']);
2216
+		} else {
2217
+					$templates = array('index');
2218
+		}
2102 2219
 
2103 2220
 		// Load each template...
2104
-		foreach ($templates as $template)
2105
-			loadTemplate($template);
2221
+		foreach ($templates as $template) {
2222
+					loadTemplate($template);
2223
+		}
2106 2224
 
2107 2225
 		// ...and attempt to load their associated language files.
2108 2226
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2109 2227
 		loadLanguage($required_files, '', false);
2110 2228
 
2111 2229
 		// Custom template layers?
2112
-		if (isset($settings['theme_layers']))
2113
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2114
-		else
2115
-			$context['template_layers'] = array('html', 'body');
2230
+		if (isset($settings['theme_layers'])) {
2231
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2232
+		} else {
2233
+					$context['template_layers'] = array('html', 'body');
2234
+		}
2116 2235
 	}
2117 2236
 
2118 2237
 	// Initialize the theme.
2119 2238
 	loadSubTemplate('init', 'ignore');
2120 2239
 
2121 2240
 	// Allow overriding the board wide time/number formats.
2122
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2123
-		$user_info['time_format'] = $txt['time_format'];
2241
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2242
+			$user_info['time_format'] = $txt['time_format'];
2243
+	}
2124 2244
 
2125 2245
 	// Set the character set from the template.
2126 2246
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2128,12 +2248,14 @@  discard block
 block discarded – undo
2128 2248
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2129 2249
 
2130 2250
 	// Guests may still need a name.
2131
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2132
-		$context['user']['name'] = $txt['guest_title'];
2251
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2252
+			$context['user']['name'] = $txt['guest_title'];
2253
+	}
2133 2254
 
2134 2255
 	// Any theme-related strings that need to be loaded?
2135
-	if (!empty($settings['require_theme_strings']))
2136
-		loadLanguage('ThemeStrings', '', false);
2256
+	if (!empty($settings['require_theme_strings'])) {
2257
+			loadLanguage('ThemeStrings', '', false);
2258
+	}
2137 2259
 
2138 2260
 	// Make a special URL for the language.
2139 2261
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2144,8 +2266,9 @@  discard block
 block discarded – undo
2144 2266
 	// Here is my luvly Responsive CSS
2145 2267
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2146 2268
 
2147
-	if ($context['right_to_left'])
2148
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2269
+	if ($context['right_to_left']) {
2270
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2271
+	}
2149 2272
 
2150 2273
 	// We allow theme variants, because we're cool.
2151 2274
 	$context['theme_variant'] = '';
@@ -2153,14 +2276,17 @@  discard block
 block discarded – undo
2153 2276
 	if (!empty($settings['theme_variants']))
2154 2277
 	{
2155 2278
 		// Overriding - for previews and that ilk.
2156
-		if (!empty($_REQUEST['variant']))
2157
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2279
+		if (!empty($_REQUEST['variant'])) {
2280
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2281
+		}
2158 2282
 		// User selection?
2159
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2160
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2283
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2284
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2285
+		}
2161 2286
 		// If not a user variant, select the default.
2162
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2163
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2287
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2288
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2289
+		}
2164 2290
 
2165 2291
 		// Do this to keep things easier in the templates.
2166 2292
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2169,20 +2295,23 @@  discard block
 block discarded – undo
2169 2295
 		if (!empty($context['theme_variant']))
2170 2296
 		{
2171 2297
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2172
-			if ($context['right_to_left'])
2173
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2298
+			if ($context['right_to_left']) {
2299
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2300
+			}
2174 2301
 		}
2175 2302
 	}
2176 2303
 
2177 2304
 	// Let's be compatible with old themes!
2178
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2179
-		$context['template_layers'] = array('main');
2305
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2306
+			$context['template_layers'] = array('main');
2307
+	}
2180 2308
 
2181 2309
 	$context['tabindex'] = 1;
2182 2310
 
2183 2311
 	// Compatibility.
2184
-	if (!isset($settings['theme_version']))
2185
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2312
+	if (!isset($settings['theme_version'])) {
2313
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2314
+	}
2186 2315
 
2187 2316
 	// Default JS variables for use in every theme
2188 2317
 	$context['javascript_vars'] = array(
@@ -2201,18 +2330,18 @@  discard block
 block discarded – undo
2201 2330
 	);
2202 2331
 
2203 2332
 	// Add the JQuery library to the list of files to load.
2204
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2205
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2206
-
2207
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2208
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2209
-
2210
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2211
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2333
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2334
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2335
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2336
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2337
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2338
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2339
+	}
2212 2340
 
2213 2341
 	// Auto loading? template_javascript() will take care of the local half of this.
2214
-	else
2215
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2342
+	else {
2343
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2344
+	}
2216 2345
 
2217 2346
 	// Queue our JQuery plugins!
2218 2347
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2235,12 +2364,12 @@  discard block
 block discarded – undo
2235 2364
 			require_once($sourcedir . '/ScheduledTasks.php');
2236 2365
 
2237 2366
 			// What to do, what to do?!
2238
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2239
-				AutoTask();
2240
-			else
2241
-				ReduceMailQueue();
2242
-		}
2243
-		else
2367
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2368
+							AutoTask();
2369
+			} else {
2370
+							ReduceMailQueue();
2371
+			}
2372
+		} else
2244 2373
 		{
2245 2374
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2246 2375
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2291,8 +2420,9 @@  discard block
 block discarded – undo
2291 2420
 		foreach ($theme_includes as $include)
2292 2421
 		{
2293 2422
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2294
-			if (file_exists($include))
2295
-				require_once($include);
2423
+			if (file_exists($include)) {
2424
+							require_once($include);
2425
+			}
2296 2426
 		}
2297 2427
 	}
2298 2428
 
@@ -2322,16 +2452,19 @@  discard block
 block discarded – undo
2322 2452
 	// Do any style sheets first, cause we're easy with those.
2323 2453
 	if (!empty($style_sheets))
2324 2454
 	{
2325
-		if (!is_array($style_sheets))
2326
-			$style_sheets = array($style_sheets);
2455
+		if (!is_array($style_sheets)) {
2456
+					$style_sheets = array($style_sheets);
2457
+		}
2327 2458
 
2328
-		foreach ($style_sheets as $sheet)
2329
-			loadCSSFile($sheet . '.css', array(), $sheet);
2459
+		foreach ($style_sheets as $sheet) {
2460
+					loadCSSFile($sheet . '.css', array(), $sheet);
2461
+		}
2330 2462
 	}
2331 2463
 
2332 2464
 	// No template to load?
2333
-	if ($template_name === false)
2334
-		return true;
2465
+	if ($template_name === false) {
2466
+			return true;
2467
+	}
2335 2468
 
2336 2469
 	$loaded = false;
2337 2470
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2346,12 +2479,14 @@  discard block
 block discarded – undo
2346 2479
 
2347 2480
 	if ($loaded)
2348 2481
 	{
2349
-		if ($db_show_debug === true)
2350
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2482
+		if ($db_show_debug === true) {
2483
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2484
+		}
2351 2485
 
2352 2486
 		// If they have specified an initialization function for this template, go ahead and call it now.
2353
-		if (function_exists('template_' . $template_name . '_init'))
2354
-			call_user_func('template_' . $template_name . '_init');
2487
+		if (function_exists('template_' . $template_name . '_init')) {
2488
+					call_user_func('template_' . $template_name . '_init');
2489
+		}
2355 2490
 	}
2356 2491
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2357 2492
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2371,13 +2506,14 @@  discard block
 block discarded – undo
2371 2506
 		loadTemplate($template_name);
2372 2507
 	}
2373 2508
 	// Cause an error otherwise.
2374
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2375
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2376
-	elseif ($fatal)
2377
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2378
-	else
2379
-		return false;
2380
-}
2509
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2510
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2511
+	} elseif ($fatal) {
2512
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2513
+	} else {
2514
+			return false;
2515
+	}
2516
+	}
2381 2517
 
2382 2518
 /**
2383 2519
  * Load a sub-template.
@@ -2395,17 +2531,19 @@  discard block
 block discarded – undo
2395 2531
 {
2396 2532
 	global $context, $txt, $db_show_debug;
2397 2533
 
2398
-	if ($db_show_debug === true)
2399
-		$context['debug']['sub_templates'][] = $sub_template_name;
2534
+	if ($db_show_debug === true) {
2535
+			$context['debug']['sub_templates'][] = $sub_template_name;
2536
+	}
2400 2537
 
2401 2538
 	// Figure out what the template function is named.
2402 2539
 	$theme_function = 'template_' . $sub_template_name;
2403
-	if (function_exists($theme_function))
2404
-		$theme_function();
2405
-	elseif ($fatal === false)
2406
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2407
-	elseif ($fatal !== 'ignore')
2408
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2540
+	if (function_exists($theme_function)) {
2541
+			$theme_function();
2542
+	} elseif ($fatal === false) {
2543
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2544
+	} elseif ($fatal !== 'ignore') {
2545
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2546
+	}
2409 2547
 
2410 2548
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2411 2549
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2435,8 +2573,9 @@  discard block
 block discarded – undo
2435 2573
 {
2436 2574
 	global $settings, $context, $modSettings;
2437 2575
 	
2438
-	if (empty($context['css_files_order'])) 
2439
-		$context['css_files_order'] = array();
2576
+	if (empty($context['css_files_order'])) {
2577
+			$context['css_files_order'] = array();
2578
+	}
2440 2579
 
2441 2580
 	$params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : '');
2442 2581
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2447,8 +2586,9 @@  discard block
 block discarded – undo
2447 2586
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2448 2587
 
2449 2588
 	// If this is an external file, automatically set this to false.
2450
-	if (!empty($params['external']))
2451
-		$params['minimize'] = false;
2589
+	if (!empty($params['external'])) {
2590
+			$params['minimize'] = false;
2591
+	}
2452 2592
 
2453 2593
 	// Account for shorthand like admin.css?alp21 filenames
2454 2594
 	$has_seed = strpos($fileName, '.css?');
@@ -2465,13 +2605,10 @@  discard block
 block discarded – undo
2465 2605
 			{
2466 2606
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2467 2607
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2608
+			} else {
2609
+							$fileUrl = false;
2468 2610
 			}
2469
-
2470
-			else
2471
-				$fileUrl = false;
2472
-		}
2473
-
2474
-		else
2611
+		} else
2475 2612
 		{
2476 2613
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2477 2614
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2489,16 +2626,18 @@  discard block
 block discarded – undo
2489 2626
 	if (!empty($fileName))
2490 2627
 	{
2491 2628
 		// find a free number/position
2492
-		while (isset($context['css_files_order'][$params['order_pos']]))
2493
-			$params['order_pos']++;
2629
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2630
+					$params['order_pos']++;
2631
+		}
2494 2632
 		$context['css_files_order'][$params['order_pos']] = $id;
2495 2633
 
2496 2634
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2497 2635
 	}
2498 2636
 
2499
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2500
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2501
-}
2637
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2638
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2639
+	}
2640
+	}
2502 2641
 
2503 2642
 /**
2504 2643
  * Add a block of inline css code to be executed later
@@ -2515,8 +2654,9 @@  discard block
 block discarded – undo
2515 2654
 	global $context;
2516 2655
 
2517 2656
 	// Gotta add something...
2518
-	if (empty($css))
2519
-		return false;
2657
+	if (empty($css)) {
2658
+			return false;
2659
+	}
2520 2660
 
2521 2661
 	$context['css_header'][] = $css;
2522 2662
 }
@@ -2551,8 +2691,9 @@  discard block
 block discarded – undo
2551 2691
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2552 2692
 
2553 2693
 	// If this is an external file, automatically set this to false.
2554
-	if (!empty($params['external']))
2555
-		$params['minimize'] = false;
2694
+	if (!empty($params['external'])) {
2695
+			$params['minimize'] = false;
2696
+	}
2556 2697
 
2557 2698
 	// Account for shorthand like admin.js?alp21 filenames
2558 2699
 	$has_seed = strpos($fileName, '.js?');
@@ -2569,16 +2710,12 @@  discard block
 block discarded – undo
2569 2710
 			{
2570 2711
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2571 2712
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2572
-			}
2573
-
2574
-			else
2713
+			} else
2575 2714
 			{
2576 2715
 				$fileUrl = false;
2577 2716
 				$filePath = false;
2578 2717
 			}
2579
-		}
2580
-
2581
-		else
2718
+		} else
2582 2719
 		{
2583 2720
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2584 2721
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2593,9 +2730,10 @@  discard block
 block discarded – undo
2593 2730
 	}
2594 2731
 
2595 2732
 	// Add it to the array for use in the template
2596
-	if (!empty($fileName))
2597
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2598
-}
2733
+	if (!empty($fileName)) {
2734
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2735
+	}
2736
+	}
2599 2737
 
2600 2738
 /**
2601 2739
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2609,9 +2747,10 @@  discard block
 block discarded – undo
2609 2747
 {
2610 2748
 	global $context;
2611 2749
 
2612
-	if (!empty($key) && (!empty($value) || $value === '0'))
2613
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2614
-}
2750
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2751
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2752
+	}
2753
+	}
2615 2754
 
2616 2755
 /**
2617 2756
  * Add a block of inline Javascript code to be executed later
@@ -2628,8 +2767,9 @@  discard block
 block discarded – undo
2628 2767
 {
2629 2768
 	global $context;
2630 2769
 
2631
-	if (empty($javascript))
2632
-		return false;
2770
+	if (empty($javascript)) {
2771
+			return false;
2772
+	}
2633 2773
 
2634 2774
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2635 2775
 }
@@ -2650,15 +2790,18 @@  discard block
 block discarded – undo
2650 2790
 	static $already_loaded = array();
2651 2791
 
2652 2792
 	// Default to the user's language.
2653
-	if ($lang == '')
2654
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2793
+	if ($lang == '') {
2794
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2795
+	}
2655 2796
 
2656 2797
 	// Do we want the English version of language file as fallback?
2657
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2658
-		loadLanguage($template_name, 'english', false);
2798
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2799
+			loadLanguage($template_name, 'english', false);
2800
+	}
2659 2801
 
2660
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2661
-		return $lang;
2802
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2803
+			return $lang;
2804
+	}
2662 2805
 
2663 2806
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2664 2807
 	if (empty($settings['default_theme_dir']))
@@ -2669,8 +2812,9 @@  discard block
 block discarded – undo
2669 2812
 
2670 2813
 	// What theme are we in?
2671 2814
 	$theme_name = basename($settings['theme_url']);
2672
-	if (empty($theme_name))
2673
-		$theme_name = 'unknown';
2815
+	if (empty($theme_name)) {
2816
+			$theme_name = 'unknown';
2817
+	}
2674 2818
 
2675 2819
 	// For each file open it up and write it out!
2676 2820
 	foreach (explode('+', $template_name) as $template)
@@ -2712,8 +2856,9 @@  discard block
 block discarded – undo
2712 2856
 				$found = true;
2713 2857
 
2714 2858
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2715
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2716
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2859
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2860
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2861
+				}
2717 2862
 
2718 2863
 				break;
2719 2864
 			}
@@ -2753,8 +2898,9 @@  discard block
 block discarded – undo
2753 2898
 	}
2754 2899
 
2755 2900
 	// Keep track of what we're up to soldier.
2756
-	if ($db_show_debug === true)
2757
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2901
+	if ($db_show_debug === true) {
2902
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2903
+	}
2758 2904
 
2759 2905
 	// Remember what we have loaded, and in which language.
2760 2906
 	$already_loaded[$template_name] = $lang;
@@ -2800,8 +2946,9 @@  discard block
 block discarded – undo
2800 2946
 				)
2801 2947
 			);
2802 2948
 			// In the EXTREMELY unlikely event this happens, give an error message.
2803
-			if ($smcFunc['db_num_rows']($result) == 0)
2804
-				fatal_lang_error('parent_not_found', 'critical');
2949
+			if ($smcFunc['db_num_rows']($result) == 0) {
2950
+							fatal_lang_error('parent_not_found', 'critical');
2951
+			}
2805 2952
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2806 2953
 			{
2807 2954
 				if (!isset($boards[$row['id_board']]))
@@ -2818,8 +2965,8 @@  discard block
 block discarded – undo
2818 2965
 					);
2819 2966
 				}
2820 2967
 				// If a moderator exists for this board, add that moderator for all children too.
2821
-				if (!empty($row['id_moderator']))
2822
-					foreach ($boards as $id => $dummy)
2968
+				if (!empty($row['id_moderator'])) {
2969
+									foreach ($boards as $id => $dummy)
2823 2970
 					{
2824 2971
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2825 2972
 							'id' => $row['id_moderator'],
@@ -2827,11 +2974,12 @@  discard block
 block discarded – undo
2827 2974
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2828 2975
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2829 2976
 						);
2977
+				}
2830 2978
 					}
2831 2979
 
2832 2980
 				// If a moderator group exists for this board, add that moderator group for all children too
2833
-				if (!empty($row['id_moderator_group']))
2834
-					foreach ($boards as $id => $dummy)
2981
+				if (!empty($row['id_moderator_group'])) {
2982
+									foreach ($boards as $id => $dummy)
2835 2983
 					{
2836 2984
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2837 2985
 							'id' => $row['id_moderator_group'],
@@ -2839,6 +2987,7 @@  discard block
 block discarded – undo
2839 2987
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2840 2988
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2841 2989
 						);
2990
+				}
2842 2991
 					}
2843 2992
 			}
2844 2993
 			$smcFunc['db_free_result']($result);
@@ -2865,23 +3014,27 @@  discard block
 block discarded – undo
2865 3014
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2866 3015
 	{
2867 3016
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2868
-		if (empty($smcFunc['ucwords']))
2869
-			reloadSettings();
3017
+		if (empty($smcFunc['ucwords'])) {
3018
+					reloadSettings();
3019
+		}
2870 3020
 
2871 3021
 		// If we don't have our theme information yet, let's get it.
2872
-		if (empty($settings['default_theme_dir']))
2873
-			loadTheme(0, false);
3022
+		if (empty($settings['default_theme_dir'])) {
3023
+					loadTheme(0, false);
3024
+		}
2874 3025
 
2875 3026
 		// Default language directories to try.
2876 3027
 		$language_directories = array(
2877 3028
 			$settings['default_theme_dir'] . '/languages',
2878 3029
 		);
2879
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2880
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3030
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3031
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3032
+		}
2881 3033
 
2882 3034
 		// We possibly have a base theme directory.
2883
-		if (!empty($settings['base_theme_dir']))
2884
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3035
+		if (!empty($settings['base_theme_dir'])) {
3036
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3037
+		}
2885 3038
 
2886 3039
 		// Remove any duplicates.
2887 3040
 		$language_directories = array_unique($language_directories);
@@ -2895,20 +3048,21 @@  discard block
 block discarded – undo
2895 3048
 		foreach ($language_directories as $language_dir)
2896 3049
 		{
2897 3050
 			// Can't look in here... doesn't exist!
2898
-			if (!file_exists($language_dir))
2899
-				continue;
3051
+			if (!file_exists($language_dir)) {
3052
+							continue;
3053
+			}
2900 3054
 
2901 3055
 			$dir = dir($language_dir);
2902 3056
 			while ($entry = $dir->read())
2903 3057
 			{
2904 3058
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2905
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2906
-					continue;
2907
-
2908
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2909
-					$langName = $langList[$matches[1]];
3059
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3060
+									continue;
3061
+				}
2910 3062
 
2911
-				else
3063
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3064
+									$langName = $langList[$matches[1]];
3065
+				} else
2912 3066
 				{
2913 3067
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2914 3068
 
@@ -2949,12 +3103,14 @@  discard block
 block discarded – undo
2949 3103
 		}
2950 3104
 
2951 3105
 		// Do we need to store the lang list?
2952
-		if (empty($langList))
2953
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3106
+		if (empty($langList)) {
3107
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3108
+		}
2954 3109
 
2955 3110
 		// Let's cash in on this deal.
2956
-		if (!empty($modSettings['cache_enable']))
2957
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3111
+		if (!empty($modSettings['cache_enable'])) {
3112
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3113
+		}
2958 3114
 	}
2959 3115
 
2960 3116
 	return $context['languages'];
@@ -2977,8 +3133,9 @@  discard block
 block discarded – undo
2977 3133
 	global $modSettings, $options, $txt;
2978 3134
 	static $censor_vulgar = null, $censor_proper;
2979 3135
 
2980
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2981
-		return $text;
3136
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3137
+			return $text;
3138
+	}
2982 3139
 
2983 3140
 	// If they haven't yet been loaded, load them.
2984 3141
 	if ($censor_vulgar == null)
@@ -3009,9 +3166,9 @@  discard block
 block discarded – undo
3009 3166
 	{
3010 3167
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3011 3168
 		$text = $func($censor_vulgar, $censor_proper, $text);
3169
+	} else {
3170
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3012 3171
 	}
3013
-	else
3014
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3015 3172
 
3016 3173
 	return $text;
3017 3174
 }
@@ -3037,38 +3194,42 @@  discard block
 block discarded – undo
3037 3194
 	@ini_set('track_errors', '1');
3038 3195
 
3039 3196
 	// Don't include the file more than once, if $once is true.
3040
-	if ($once && in_array($filename, $templates))
3041
-		return;
3197
+	if ($once && in_array($filename, $templates)) {
3198
+			return;
3199
+	}
3042 3200
 	// Add this file to the include list, whether $once is true or not.
3043
-	else
3044
-		$templates[] = $filename;
3201
+	else {
3202
+			$templates[] = $filename;
3203
+	}
3045 3204
 
3046 3205
 	// Are we going to use eval?
3047 3206
 	if (empty($modSettings['disableTemplateEval']))
3048 3207
 	{
3049 3208
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
3050 3209
 		$settings['current_include_filename'] = $filename;
3051
-	}
3052
-	else
3210
+	} else
3053 3211
 	{
3054 3212
 		$file_found = file_exists($filename);
3055 3213
 
3056
-		if ($once && $file_found)
3057
-			require_once($filename);
3058
-		elseif ($file_found)
3059
-			require($filename);
3214
+		if ($once && $file_found) {
3215
+					require_once($filename);
3216
+		} elseif ($file_found) {
3217
+					require($filename);
3218
+		}
3060 3219
 	}
3061 3220
 
3062 3221
 	if ($file_found !== true)
3063 3222
 	{
3064 3223
 		ob_end_clean();
3065
-		if (!empty($modSettings['enableCompressedOutput']))
3066
-			@ob_start('ob_gzhandler');
3067
-		else
3068
-			ob_start();
3224
+		if (!empty($modSettings['enableCompressedOutput'])) {
3225
+					@ob_start('ob_gzhandler');
3226
+		} else {
3227
+					ob_start();
3228
+		}
3069 3229
 
3070
-		if (isset($_GET['debug']))
3071
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3230
+		if (isset($_GET['debug'])) {
3231
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3232
+		}
3072 3233
 
3073 3234
 		// Don't cache error pages!!
3074 3235
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3087,12 +3248,13 @@  discard block
 block discarded – undo
3087 3248
 		echo '<!DOCTYPE html>
3088 3249
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3089 3250
 	<head>';
3090
-		if (isset($context['character_set']))
3091
-			echo '
3251
+		if (isset($context['character_set'])) {
3252
+					echo '
3092 3253
 		<meta charset="', $context['character_set'], '">';
3254
+		}
3093 3255
 
3094
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3095
-			echo '
3256
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3257
+					echo '
3096 3258
 		<title>', $mtitle, '</title>
3097 3259
 	</head>
3098 3260
 	<body>
@@ -3100,8 +3262,8 @@  discard block
 block discarded – undo
3100 3262
 		', $mmessage, '
3101 3263
 	</body>
3102 3264
 </html>';
3103
-		elseif (!allowedTo('admin_forum'))
3104
-			echo '
3265
+		} elseif (!allowedTo('admin_forum')) {
3266
+					echo '
3105 3267
 		<title>', $txt['template_parse_error'], '</title>
3106 3268
 	</head>
3107 3269
 	<body>
@@ -3109,16 +3271,18 @@  discard block
 block discarded – undo
3109 3271
 		', $txt['template_parse_error_message'], '
3110 3272
 	</body>
3111 3273
 </html>';
3112
-		else
3274
+		} else
3113 3275
 		{
3114 3276
 			require_once($sourcedir . '/Subs-Package.php');
3115 3277
 
3116 3278
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3117 3279
 			$error_array = error_get_last();
3118
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3119
-				$error = $error_array['message'];
3120
-			if (empty($error))
3121
-				$error = $txt['template_parse_errmsg'];
3280
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3281
+							$error = $error_array['message'];
3282
+			}
3283
+			if (empty($error)) {
3284
+							$error = $txt['template_parse_errmsg'];
3285
+			}
3122 3286
 
3123 3287
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3124 3288
 
@@ -3129,11 +3293,12 @@  discard block
 block discarded – undo
3129 3293
 		<h3>', $txt['template_parse_error'], '</h3>
3130 3294
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3131 3295
 
3132
-			if (!empty($error))
3133
-				echo '
3296
+			if (!empty($error)) {
3297
+							echo '
3134 3298
 		<hr>
3135 3299
 
3136 3300
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3301
+			}
3137 3302
 
3138 3303
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3139 3304
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3143,10 +3308,11 @@  discard block
 block discarded – undo
3143 3308
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3144 3309
 
3145 3310
 				// Fix the PHP code stuff...
3146
-				if (!isBrowser('gecko'))
3147
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3148
-				else
3149
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3311
+				if (!isBrowser('gecko')) {
3312
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3313
+				} else {
3314
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3315
+				}
3150 3316
 
3151 3317
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3152 3318
 				$j = -1;
@@ -3154,8 +3320,9 @@  discard block
 block discarded – undo
3154 3320
 				{
3155 3321
 					$j++;
3156 3322
 
3157
-					if (substr_count($line, '<br>') == 0)
3158
-						continue;
3323
+					if (substr_count($line, '<br>') == 0) {
3324
+											continue;
3325
+					}
3159 3326
 
3160 3327
 					$n = substr_count($line, '<br>');
3161 3328
 					for ($i = 0; $i < $n; $i++)
@@ -3174,38 +3341,42 @@  discard block
 block discarded – undo
3174 3341
 				// Figure out what the color coding was before...
3175 3342
 				$line = max($match[1] - 9, 1);
3176 3343
 				$last_line = '';
3177
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3178
-					if (strpos($data2[$line2], '<') !== false)
3344
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3345
+									if (strpos($data2[$line2], '<') !== false)
3179 3346
 					{
3180 3347
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3181 3348
 							$last_line = $color_match[1];
3349
+				}
3182 3350
 						break;
3183 3351
 					}
3184 3352
 
3185 3353
 				// Show the relevant lines...
3186 3354
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3187 3355
 				{
3188
-					if ($line == $match[1])
3189
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3356
+					if ($line == $match[1]) {
3357
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3358
+					}
3190 3359
 
3191 3360
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3192
-					if (isset($data2[$line]) && $data2[$line] != '')
3193
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3361
+					if (isset($data2[$line]) && $data2[$line] != '') {
3362
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3363
+					}
3194 3364
 
3195 3365
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3196 3366
 					{
3197 3367
 						$last_line = $color_match[1];
3198 3368
 						echo '</', substr($last_line, 1, 4), '>';
3369
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3370
+											$last_line = '';
3371
+					} elseif ($last_line != '' && $data2[$line] != '') {
3372
+											echo '</', substr($last_line, 1, 4), '>';
3199 3373
 					}
3200
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3201
-						$last_line = '';
3202
-					elseif ($last_line != '' && $data2[$line] != '')
3203
-						echo '</', substr($last_line, 1, 4), '>';
3204 3374
 
3205
-					if ($line == $match[1])
3206
-						echo '</pre></div><pre style="margin: 0;">';
3207
-					else
3208
-						echo "\n";
3375
+					if ($line == $match[1]) {
3376
+											echo '</pre></div><pre style="margin: 0;">';
3377
+					} else {
3378
+											echo "\n";
3379
+					}
3209 3380
 				}
3210 3381
 
3211 3382
 				echo '</pre></div>';
@@ -3229,8 +3400,9 @@  discard block
 block discarded – undo
3229 3400
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3230 3401
 
3231 3402
 	// Figure out what type of database we are using.
3232
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3233
-		$db_type = 'mysql';
3403
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3404
+			$db_type = 'mysql';
3405
+	}
3234 3406
 
3235 3407
 	// Load the file for the database.
3236 3408
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3238,8 +3410,9 @@  discard block
 block discarded – undo
3238 3410
 	$db_options = array();
3239 3411
 
3240 3412
 	// Add in the port if needed
3241
-	if (!empty($db_port))
3242
-		$db_options['port'] = $db_port;
3413
+	if (!empty($db_port)) {
3414
+			$db_options['port'] = $db_port;
3415
+	}
3243 3416
 
3244 3417
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3245 3418
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3258,13 +3431,15 @@  discard block
 block discarded – undo
3258 3431
 	}
3259 3432
 
3260 3433
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3261
-	if (!$db_connection)
3262
-		display_db_error();
3434
+	if (!$db_connection) {
3435
+			display_db_error();
3436
+	}
3263 3437
 
3264 3438
 	// If in SSI mode fix up the prefix.
3265
-	if (SMF == 'SSI')
3266
-		db_fix_prefix($db_prefix, $db_name);
3267
-}
3439
+	if (SMF == 'SSI') {
3440
+			db_fix_prefix($db_prefix, $db_name);
3441
+	}
3442
+	}
3268 3443
 
3269 3444
 /**
3270 3445
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3278,10 +3453,11 @@  discard block
 block discarded – undo
3278 3453
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3279 3454
 
3280 3455
 	// Not overriding this and we have a cacheAPI, send it back.
3281
-	if (empty($overrideCache) && is_object($cacheAPI))
3282
-		return $cacheAPI;
3283
-	elseif (is_null($cacheAPI))
3284
-		$cacheAPI = false;
3456
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3457
+			return $cacheAPI;
3458
+	} elseif (is_null($cacheAPI)) {
3459
+			$cacheAPI = false;
3460
+	}
3285 3461
 
3286 3462
 	// Make sure our class is in session.
3287 3463
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3302,8 +3478,9 @@  discard block
 block discarded – undo
3302 3478
 		if (!$testAPI->isSupported())
3303 3479
 		{
3304 3480
 			// Can we save ourselves?
3305
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3306
-				return loadCacheAccelerator(null, false);
3481
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3482
+							return loadCacheAccelerator(null, false);
3483
+			}
3307 3484
 			return false;
3308 3485
 		}
3309 3486
 
@@ -3315,9 +3492,9 @@  discard block
 block discarded – undo
3315 3492
 		{
3316 3493
 			$cacheAPI = $testAPI;
3317 3494
 			return $cacheAPI;
3495
+		} else {
3496
+					return $testAPI;
3318 3497
 		}
3319
-		else
3320
-			return $testAPI;
3321 3498
 	}
3322 3499
 }
3323 3500
 
@@ -3337,8 +3514,9 @@  discard block
 block discarded – undo
3337 3514
 
3338 3515
 	// @todo Why are we doing this if caching is disabled?
3339 3516
 
3340
-	if (function_exists('call_integration_hook'))
3341
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3517
+	if (function_exists('call_integration_hook')) {
3518
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3519
+	}
3342 3520
 
3343 3521
 	/* Refresh the cache if either:
3344 3522
 		1. Caching is disabled.
@@ -3352,16 +3530,19 @@  discard block
 block discarded – undo
3352 3530
 		require_once($sourcedir . '/' . $file);
3353 3531
 		$cache_block = call_user_func_array($function, $params);
3354 3532
 
3355
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3356
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3533
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3534
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3535
+		}
3357 3536
 	}
3358 3537
 
3359 3538
 	// Some cached data may need a freshening up after retrieval.
3360
-	if (!empty($cache_block['post_retri_eval']))
3361
-		eval($cache_block['post_retri_eval']);
3539
+	if (!empty($cache_block['post_retri_eval'])) {
3540
+			eval($cache_block['post_retri_eval']);
3541
+	}
3362 3542
 
3363
-	if (function_exists('call_integration_hook'))
3364
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3543
+	if (function_exists('call_integration_hook')) {
3544
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3545
+	}
3365 3546
 
3366 3547
 	return $cache_block['data'];
3367 3548
 }
@@ -3388,8 +3569,9 @@  discard block
 block discarded – undo
3388 3569
 	global $smcFunc, $cache_enable, $cacheAPI;
3389 3570
 	global $cache_hits, $cache_count, $db_show_debug;
3390 3571
 
3391
-	if (empty($cache_enable) || empty($cacheAPI))
3392
-		return;
3572
+	if (empty($cache_enable) || empty($cacheAPI)) {
3573
+			return;
3574
+	}
3393 3575
 
3394 3576
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3395 3577
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3402,12 +3584,14 @@  discard block
 block discarded – undo
3402 3584
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3403 3585
 	$cacheAPI->putData($key, $value, $ttl);
3404 3586
 
3405
-	if (function_exists('call_integration_hook'))
3406
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3587
+	if (function_exists('call_integration_hook')) {
3588
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3589
+	}
3407 3590
 
3408
-	if (isset($db_show_debug) && $db_show_debug === true)
3409
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3410
-}
3591
+	if (isset($db_show_debug) && $db_show_debug === true) {
3592
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3593
+	}
3594
+	}
3411 3595
 
3412 3596
 /**
3413 3597
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3423,8 +3607,9 @@  discard block
 block discarded – undo
3423 3607
 	global $smcFunc, $cache_enable, $cacheAPI;
3424 3608
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3425 3609
 
3426
-	if (empty($cache_enable) || empty($cacheAPI))
3427
-		return;
3610
+	if (empty($cache_enable) || empty($cacheAPI)) {
3611
+			return;
3612
+	}
3428 3613
 
3429 3614
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3430 3615
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3444,16 +3629,18 @@  discard block
 block discarded – undo
3444 3629
 
3445 3630
 		if (empty($value))
3446 3631
 		{
3447
-			if (!is_array($cache_misses))
3448
-				$cache_misses = array();
3632
+			if (!is_array($cache_misses)) {
3633
+							$cache_misses = array();
3634
+			}
3449 3635
 
3450 3636
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3451 3637
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3452 3638
 		}
3453 3639
 	}
3454 3640
 
3455
-	if (function_exists('call_integration_hook') && isset($value))
3456
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3641
+	if (function_exists('call_integration_hook') && isset($value)) {
3642
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3643
+	}
3457 3644
 
3458 3645
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3459 3646
 }
@@ -3475,8 +3662,9 @@  discard block
 block discarded – undo
3475 3662
 	global $cacheAPI;
3476 3663
 
3477 3664
 	// If we can't get to the API, can't do this.
3478
-	if (empty($cacheAPI))
3479
-		return;
3665
+	if (empty($cacheAPI)) {
3666
+			return;
3667
+	}
3480 3668
 
3481 3669
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3482 3670
 	$cacheAPI->cleanCache($type);
@@ -3501,8 +3689,9 @@  discard block
 block discarded – undo
3501 3689
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret, $user_info;
3502 3690
 
3503 3691
 	// Come on!
3504
-	if (empty($data))
3505
-		return array();
3692
+	if (empty($data)) {
3693
+			return array();
3694
+	}
3506 3695
 
3507 3696
 	// Set a nice default var.
3508 3697
 	$image = '';
@@ -3510,11 +3699,11 @@  discard block
 block discarded – undo
3510 3699
 	// Gravatar has been set as mandatory!
3511 3700
 	if (!empty($modSettings['gravatarOverride']))
3512 3701
 	{
3513
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3514
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3515
-
3516
-		else if (!empty($data['email']))
3517
-			$image = get_gravatar_url($data['email']);
3702
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3703
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3704
+		} else if (!empty($data['email'])) {
3705
+					$image = get_gravatar_url($data['email']);
3706
+		}
3518 3707
 	}
3519 3708
 
3520 3709
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3526,54 +3715,60 @@  discard block
 block discarded – undo
3526 3715
 			// Gravatar.
3527 3716
 			if (stristr($data['avatar'], 'gravatar://'))
3528 3717
 			{
3529
-				if ($data['avatar'] == 'gravatar://')
3530
-					$image = get_gravatar_url($data['email']);
3531
-
3532
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3533
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3718
+				if ($data['avatar'] == 'gravatar://') {
3719
+									$image = get_gravatar_url($data['email']);
3720
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3721
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3722
+				}
3534 3723
 			}
3535 3724
 
3536 3725
 			// External url.
3537 3726
 			else
3538 3727
 			{
3539 3728
 				// Using ssl?
3540
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3541
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3729
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3730
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3731
+				}
3542 3732
 
3543 3733
 				// Just a plain external url.
3544
-				else
3545
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3734
+				else {
3735
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3736
+				}
3546 3737
 			}
3547 3738
 		}
3548 3739
 
3549 3740
 		// Perhaps this user has an attachment as avatar...
3550
-		else if (!empty($data['filename']))
3551
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3741
+		else if (!empty($data['filename'])) {
3742
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3743
+		}
3552 3744
 
3553 3745
 		// Right... no avatar... use our default image.
3554
-		else
3555
-			$image = $modSettings['avatar_url'] . '/default.png';
3746
+		else {
3747
+					$image = $modSettings['avatar_url'] . '/default.png';
3748
+		}
3556 3749
 	}
3557 3750
 
3558 3751
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3559 3752
 
3560 3753
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3561
-	if (!empty($image))
3562
-		return array(
3754
+	if (!empty($image)) {
3755
+			return array(
3563 3756
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3564 3757
 			'image' => '<img class="avatar" src="' . $image . '" />',
3565 3758
 			'href' => $image,
3566 3759
 			'url' => $image,
3567 3760
 		);
3761
+	}
3568 3762
 
3569 3763
 	// Fallback to make life easier for everyone...
3570
-	else
3571
-		return array(
3764
+	else {
3765
+			return array(
3572 3766
 			'name' => '',
3573 3767
 			'image' => '',
3574 3768
 			'href' => '',
3575 3769
 			'url' => '',
3576 3770
 		);
3577
-}
3771
+	}
3772
+	}
3578 3773
 
3579 3774
 ?>
3580 3775
\ No newline at end of file
Please login to merge, or discard this patch.