Completed
Pull Request — release-2.1 (#4090)
by Rick
08:07
created
Sources/ReCaptcha/RequestMethod/Curl.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -32,43 +32,43 @@
 block discarded – undo
32 32
 class Curl
33 33
 {
34 34
 
35
-    /**
36
-     * @see https://php.net/curl_init
37
-     * @param string $url
38
-     * @return resource cURL handle
39
-     */
40
-    public function init($url = null)
41
-    {
42
-        return curl_init($url);
43
-    }
35
+	/**
36
+	 * @see https://php.net/curl_init
37
+	 * @param string $url
38
+	 * @return resource cURL handle
39
+	 */
40
+	public function init($url = null)
41
+	{
42
+		return curl_init($url);
43
+	}
44 44
 
45
-    /**
46
-     * @see https://php.net/curl_setopt_array
47
-     * @param resource $ch
48
-     * @param array $options
49
-     * @return bool
50
-     */
51
-    public function setoptArray($ch, array $options)
52
-    {
53
-        return curl_setopt_array($ch, $options);
54
-    }
45
+	/**
46
+	 * @see https://php.net/curl_setopt_array
47
+	 * @param resource $ch
48
+	 * @param array $options
49
+	 * @return bool
50
+	 */
51
+	public function setoptArray($ch, array $options)
52
+	{
53
+		return curl_setopt_array($ch, $options);
54
+	}
55 55
 
56
-    /**
57
-     * @see https://php.net/curl_exec
58
-     * @param resource $ch
59
-     * @return mixed
60
-     */
61
-    public function exec($ch)
62
-    {
63
-        return curl_exec($ch);
64
-    }
56
+	/**
57
+	 * @see https://php.net/curl_exec
58
+	 * @param resource $ch
59
+	 * @return mixed
60
+	 */
61
+	public function exec($ch)
62
+	{
63
+		return curl_exec($ch);
64
+	}
65 65
 
66
-    /**
67
-     * @see https://php.net/curl_close
68
-     * @param resource $ch
69
-     */
70
-    public function close($ch)
71
-    {
72
-        curl_close($ch);
73
-    }
66
+	/**
67
+	 * @see https://php.net/curl_close
68
+	 * @param resource $ch
69
+	 */
70
+	public function close($ch)
71
+	{
72
+		curl_close($ch);
73
+	}
74 74
 }
Please login to merge, or discard this patch.
Sources/ReCaptcha/RequestMethod/Socket.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -32,74 +32,74 @@
 block discarded – undo
32 32
  */
33 33
 class Socket
34 34
 {
35
-    private $handle = null;
35
+	private $handle = null;
36 36
 
37
-    /**
38
-     * fsockopen
39
-     * 
40
-     * @see https://php.net/fsockopen
41
-     * @param string $hostname
42
-     * @param int $port
43
-     * @param int $errno
44
-     * @param string $errstr
45
-     * @param float $timeout
46
-     * @return resource
47
-     */
48
-    public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null)
49
-    {
50
-        $this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout));
37
+	/**
38
+	 * fsockopen
39
+	 * 
40
+	 * @see https://php.net/fsockopen
41
+	 * @param string $hostname
42
+	 * @param int $port
43
+	 * @param int $errno
44
+	 * @param string $errstr
45
+	 * @param float $timeout
46
+	 * @return resource
47
+	 */
48
+	public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null)
49
+	{
50
+		$this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout));
51 51
 
52
-        if ($this->handle != false && $errno === 0 && $errstr === '') {
53
-            return $this->handle;
54
-        } else {
55
-            return false;
56
-        }
57
-    }
52
+		if ($this->handle != false && $errno === 0 && $errstr === '') {
53
+			return $this->handle;
54
+		} else {
55
+			return false;
56
+		}
57
+	}
58 58
 
59
-    /**
60
-     * fwrite
61
-     * 
62
-     * @see https://php.net/fwrite
63
-     * @param string $string
64
-     * @param int $length
65
-     * @return int | bool
66
-     */
67
-    public function fwrite($string, $length = null)
68
-    {
69
-        return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length));
70
-    }
59
+	/**
60
+	 * fwrite
61
+	 * 
62
+	 * @see https://php.net/fwrite
63
+	 * @param string $string
64
+	 * @param int $length
65
+	 * @return int | bool
66
+	 */
67
+	public function fwrite($string, $length = null)
68
+	{
69
+		return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length));
70
+	}
71 71
 
72
-    /**
73
-     * fgets
74
-     * 
75
-     * @see https://php.net/fgets
76
-     * @param int $length
77
-     * @return string
78
-     */
79
-    public function fgets($length = null)
80
-    {
81
-        return fgets($this->handle, $length);
82
-    }
72
+	/**
73
+	 * fgets
74
+	 * 
75
+	 * @see https://php.net/fgets
76
+	 * @param int $length
77
+	 * @return string
78
+	 */
79
+	public function fgets($length = null)
80
+	{
81
+		return fgets($this->handle, $length);
82
+	}
83 83
 
84
-    /**
85
-     * feof
86
-     * 
87
-     * @see https://php.net/feof
88
-     * @return bool
89
-     */
90
-    public function feof()
91
-    {
92
-        return feof($this->handle);
93
-    }
84
+	/**
85
+	 * feof
86
+	 * 
87
+	 * @see https://php.net/feof
88
+	 * @return bool
89
+	 */
90
+	public function feof()
91
+	{
92
+		return feof($this->handle);
93
+	}
94 94
 
95
-    /**
96
-     * fclose
97
-     * 
98
-     * @see https://php.net/fclose
99
-     * @return bool
100
-     */
101
-    public function fclose()
102
-    {
103
-        return fclose($this->handle);
104
-    }
95
+	/**
96
+	 * fclose
97
+	 * 
98
+	 * @see https://php.net/fclose
99
+	 * @return bool
100
+	 */
101
+	public function fclose()
102
+	{
103
+		return fclose($this->handle);
104
+	}
105 105
 }
Please login to merge, or discard this patch.
Themes/default/Post.template.php 2 patches
Braces   +89 added lines, -61 removed lines patch added patch discarded remove patch
@@ -22,22 +22,24 @@  discard block
 block discarded – undo
22 22
 		<script>';
23 23
 
24 24
 	// When using Go Back due to fatal_error, allow the form to be re-submitted with changes.
25
-	if (isBrowser('is_firefox'))
26
-		echo '
25
+	if (isBrowser('is_firefox')) {
26
+			echo '
27 27
 			window.addEventListener("pageshow", reActivate, false);';
28
+	}
28 29
 
29 30
 	// Start with message icons - and any missing from this theme.
30 31
 	echo '
31 32
 			var icon_urls = {';
32
-	foreach ($context['icons'] as $icon)
33
-		echo '
33
+	foreach ($context['icons'] as $icon) {
34
+			echo '
34 35
 				\'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ',';
36
+	}
35 37
 	echo '
36 38
 			};';
37 39
 
38 40
 	// If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations.
39
-	if ($context['make_poll'])
40
-		echo '
41
+	if ($context['make_poll']) {
42
+			echo '
41 43
 			var pollOptionNum = 0, pollTabIndex;
42 44
 			var pollOptionId = ', $context['last_choice_id'], ';
43 45
 			function addPollOption()
@@ -56,11 +58,13 @@  discard block
 block discarded – undo
56 58
 
57 59
 				setOuterHTML(document.getElementById(\'pollMoreOptions\'), ', JavaScriptEscape('<dt><label for="options-'), ' + pollOptionId + ', JavaScriptEscape('">' . $txt['option'] . ' '), ' + pollOptionNum + ', JavaScriptEscape('</label>:</dt><dd><input type="text" name="options['), ' + pollOptionId + ', JavaScriptEscape(']" id="options-'), ' + pollOptionId + ', JavaScriptEscape('" value="" size="80" maxlength="255" tabindex="'), ' + pollTabIndex + ', JavaScriptEscape('" class="input_text"></dd><p id="pollMoreOptions"></p>'), ');
58 60
 			}';
61
+	}
59 62
 
60 63
 	// If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here.
61
-	if ($context['make_event'])
62
-		echo '
64
+	if ($context['make_event']) {
65
+			echo '
63 66
 			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];';
67
+	}
64 68
 
65 69
 	// End of the javascript, start the form and display the link tree.
66 70
 	echo '
@@ -80,9 +84,10 @@  discard block
 block discarded – undo
80 84
 				</div>
81 85
 			</div><br>';
82 86
 
83
-	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board'])))
84
-		echo '
87
+	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board']))) {
88
+			echo '
85 89
 			<input type="hidden" name="eventid" value="', $context['event']['id'], '">';
90
+	}
86 91
 
87 92
 	// Start the main table.
88 93
 	echo '
@@ -117,18 +122,20 @@  discard block
 block discarded – undo
117 122
 	}
118 123
 
119 124
 	// If it's locked, show a message to warn the replier.
120
-	if (!empty($context['locked']))
121
-	echo '
125
+	if (!empty($context['locked'])) {
126
+		echo '
122 127
 					<p class="errorbox">
123 128
 						', $txt['topic_locked_no_reply'], '
124 129
 					</p>';
130
+	}
125 131
 
126
-	if (!empty($modSettings['drafts_post_enabled']))
127
-		echo '
132
+	if (!empty($modSettings['drafts_post_enabled'])) {
133
+			echo '
128 134
 					<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
129 135
 						sprintf($txt['draft_saved'], $scripturl . '?action=profile;u=' . $context['user']['id'] . ';area=showdrafts'), '
130 136
 						', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
131 137
 					</div>';
138
+	}
132 139
 
133 140
 	// The post header... important stuff
134 141
 	echo '
@@ -180,9 +187,10 @@  discard block
 block discarded – undo
180 187
 				{
181 188
 					echo '
182 189
 										<optgroup label="', $category['name'], '">';
183
-					foreach ($category['boards'] as $board)
184
-						echo '
190
+					foreach ($category['boards'] as $board) {
191
+											echo '
185 192
 											<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
193
+					}
186 194
 					echo '
187 195
 										</optgroup>';
188 196
 				}
@@ -218,9 +226,10 @@  discard block
 block discarded – undo
218 226
 									<span class="label">', $txt['calendar_timezone'], '</span>
219 227
 									<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
220 228
 
221
-			foreach ($context['all_timezones'] as $tz => $tzname)
222
-				echo '
229
+			foreach ($context['all_timezones'] as $tz => $tzname) {
230
+							echo '
223 231
 										<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
232
+			}
224 233
 
225 234
 			echo '
226 235
 									</select>
@@ -286,14 +295,15 @@  discard block
 block discarded – undo
286 295
 									<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked' : '', ' class="input_check">
287 296
 								</dd>';
288 297
 
289
-		if ($context['poll_options']['guest_vote_enabled'])
290
-			echo '
298
+		if ($context['poll_options']['guest_vote_enabled']) {
299
+					echo '
291 300
 								<dt>
292 301
 									<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
293 302
 								</dt>
294 303
 								<dd>
295 304
 									<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked' : '', ' class="input_check">
296 305
 								</dd>';
306
+		}
297 307
 
298 308
 		echo '
299 309
 								<dt>
@@ -314,8 +324,8 @@  discard block
 block discarded – undo
314 324
 					', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
315 325
 
316 326
 	// If we're editing and displaying edit details, show a box where they can say why
317
-	if (isset($context['editing']) && $modSettings['show_modify'])
318
-		echo '
327
+	if (isset($context['editing']) && $modSettings['show_modify']) {
328
+			echo '
319 329
 					<dl>
320 330
 						<dt class="clear">
321 331
 							<span id="caption_edit_reason">', $txt['reason_for_edit'], ':</span>
@@ -324,20 +334,23 @@  discard block
 block discarded – undo
324 334
 							<input type="text" name="modify_reason"', isset($context['last_modified_reason']) ? ' value="' . $context['last_modified_reason'] . '"' : '', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text">
325 335
 						</dd>
326 336
 					</dl>';
337
+	}
327 338
 
328 339
 	// If this message has been edited in the past - display when it was.
329
-	if (isset($context['last_modified']))
330
-		echo '
340
+	if (isset($context['last_modified'])) {
341
+			echo '
331 342
 					<div class="padding smalltext">
332 343
 						', $context['last_modified_text'], '
333 344
 					</div>';
345
+	}
334 346
 
335 347
 	// If the admin has enabled the hiding of the additional options - show a link and image for it.
336
-	if (!empty($modSettings['additional_options_collapsable']))
337
-		echo '
348
+	if (!empty($modSettings['additional_options_collapsable'])) {
349
+			echo '
338 350
 					<div id="postAdditionalOptionsHeader">
339 351
 						<strong><a href="#" id="postMoreExpandLink"> ', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong>
340 352
 					</div>';
353
+	}
341 354
 
342 355
 	echo '
343 356
 					<div id="postAdditionalOptions">';
@@ -369,19 +382,21 @@  discard block
 block discarded – undo
369 382
 								<input type="hidden" name="attach_del[]" value="0">
370 383
 								', $txt['uncheck_unwatchd_attach'], ':
371 384
 							</dd>';
372
-		foreach ($context['current_attachments'] as $attachment)
373
-			echo '
385
+		foreach ($context['current_attachments'] as $attachment) {
386
+					echo '
374 387
 							<dd class="smalltext">
375 388
 								<label for="attachment_', $attachment['attachID'], '"><input type="checkbox" id="attachment_', $attachment['attachID'], '" name="attach_del[]" value="', $attachment['attachID'], '"', empty($attachment['unchecked']) ? ' checked' : '', ' class="input_check"> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''),
376 389
 								!empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1028) / 1028), 0)) : '', '</label>
377 390
 							</dd>';
391
+		}
378 392
 
379 393
 		echo '
380 394
 						</dl>';
381 395
 
382
-		if (!empty($context['files_in_session_warning']))
383
-			echo '
396
+		if (!empty($context['files_in_session_warning'])) {
397
+					echo '
384 398
 						<div class="smalltext">', $context['files_in_session_warning'], '</div>';
399
+		}
385 400
 	}
386 401
 
387 402
 	// Is the user allowed to post any additional ones? If so give them the boxes to do it!
@@ -434,8 +449,8 @@  discard block
 block discarded – undo
434 449
 								', empty($modSettings['attachmentSizeLimit']) ? '' : ('<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1028 . '">');
435 450
 
436 451
 		// Show more boxes if they aren't approaching that limit.
437
-		if ($context['num_allowed_attachments'] > 1)
438
-			echo '
452
+		if ($context['num_allowed_attachments'] > 1) {
453
+					echo '
439 454
 										<script>
440 455
 											var allowed_attachments = ', $context['num_allowed_attachments'], ';
441 456
 											var current_attachment = 1;
@@ -456,9 +471,10 @@  discard block
 block discarded – undo
456 471
 									</div>
457 472
 								</div>
458 473
 							</dd>';
459
-		else
460
-			echo '
474
+		} else {
475
+					echo '
461 476
 							</dd>';
477
+		}
462 478
 
463 479
 		// Add any template changes for an alternative upload system here.
464 480
 		call_integration_hook('integrate_upload_template');
@@ -467,21 +483,25 @@  discard block
 block discarded – undo
467 483
 							<dd class="smalltext">';
468 484
 
469 485
 		// Show some useful information such as allowed extensions, maximum size and amount of attachments allowed.
470
-		if (!empty($modSettings['attachmentCheckExtensions']))
471
-			echo '
486
+		if (!empty($modSettings['attachmentCheckExtensions'])) {
487
+					echo '
472 488
 								', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br>';
489
+		}
473 490
 
474
-		if (!empty($context['attachment_restrictions']))
475
-			echo '
491
+		if (!empty($context['attachment_restrictions'])) {
492
+					echo '
476 493
 								', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br>';
494
+		}
477 495
 
478
-		if ($context['num_allowed_attachments'] == 0)
479
-			echo '
496
+		if ($context['num_allowed_attachments'] == 0) {
497
+					echo '
480 498
 								', $txt['attach_limit_nag'], '<br>';
499
+		}
481 500
 
482
-		if (!$context['can_post_attachment_unapproved'])
483
-			echo '
501
+		if (!$context['can_post_attachment_unapproved']) {
502
+					echo '
484 503
 								<span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br>';
504
+		}
485 505
 
486 506
 		echo '
487 507
 							</dd>
@@ -504,10 +524,11 @@  discard block
 block discarded – undo
504 524
 							<dt><strong>', $txt['subject'], '</strong></dt>
505 525
 							<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
506 526
 
507
-		foreach ($context['drafts'] as $draft)
508
-			echo '
527
+		foreach ($context['drafts'] as $draft) {
528
+					echo '
509 529
 							<dt>', $draft['link'], '</dt>
510 530
 							<dd>', $draft['poster_time'], '</dd>';
531
+		}
511 532
 		echo '
512 533
 						</dl>
513 534
 					</div>';
@@ -532,9 +553,10 @@  discard block
 block discarded – undo
532 553
 						', template_control_richedit_buttons($context['post_box_name']);
533 554
 
534 555
 	// Option to delete an event if user is editing one.
535
-	if ($context['make_event'] && !$context['event']['new'])
536
-		echo '
556
+	if ($context['make_event'] && !$context['event']['new']) {
557
+			echo '
537 558
 						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button_submit you_sure">';
559
+	}
538 560
 
539 561
 	echo '
540 562
 					</span>
@@ -543,9 +565,10 @@  discard block
 block discarded – undo
543 565
 			<br class="clear">';
544 566
 
545 567
 	// Assuming this isn't a new topic pass across the last message id.
546
-	if (isset($context['topic_last_message']))
547
-		echo '
568
+	if (isset($context['topic_last_message'])) {
569
+			echo '
548 570
 			<input type="hidden" name="last_msg" value="', $context['topic_last_message'], '">';
571
+	}
549 572
 
550 573
 	echo '
551 574
 			<input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '">
@@ -687,9 +710,10 @@  discard block
 block discarded – undo
687 710
 
688 711
 						newPostsHTML += \'<div class="windowbg\' + (++reply_counter % 2 == 0 ? \'2\' : \'\') + \'"><div id="msg\' + newPosts[i].getAttribute("id") + \'"><div class="floatleft"><h5>', $txt['posted_by'], ': \' + newPosts[i].getElementsByTagName("poster")[0].firstChild.nodeValue + \'</h5><span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> \' + newPosts[i].getElementsByTagName("time")[0].firstChild.nodeValue + \'&nbsp;&#187;</span> <span class="new_posts" id="image_new_\' + newPosts[i].getAttribute("id") + \'">', $txt['new'], '</span></div>\';';
689 712
 
690
-	if ($context['can_quote'])
691
-		echo '
713
+	if ($context['can_quote']) {
714
+			echo '
692 715
 						newPostsHTML += \'<ul class="quickbuttons" id="msg_\' + newPosts[i].getAttribute("id") + \'_quote"><li><a href="#postmodify" onclick="return insertQuoteFast(\\\'\' + newPosts[i].getAttribute("id") + \'\\\');" class="quote_button"><span>', $txt['quote'], '</span><\' + \'/a></li></ul>\';';
716
+	}
693 717
 
694 718
 	echo '
695 719
 						newPostsHTML += \'<br class="clear">\';
@@ -732,8 +756,8 @@  discard block
 block discarded – undo
732 756
 			}';
733 757
 
734 758
 	// Code for showing and hiding additional options.
735
-	if (!empty($modSettings['additional_options_collapsable']))
736
-		echo '
759
+	if (!empty($modSettings['additional_options_collapsable'])) {
760
+			echo '
737 761
 			var oSwapAdditionalOptions = new smc_Toggle({
738 762
 				bToggleEnabled: true,
739 763
 				bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ',
@@ -761,10 +785,11 @@  discard block
 block discarded – undo
761 785
 					}
762 786
 				]
763 787
 			});';
788
+	}
764 789
 
765 790
 	// Code for showing and hiding drafts
766
-	if (!empty($context['drafts']))
767
-		echo '
791
+	if (!empty($context['drafts'])) {
792
+			echo '
768 793
 			var oSwapDraftOptions = new smc_Toggle({
769 794
 				bToggleEnabled: true,
770 795
 				bCurrentlyCollapsed: true,
@@ -786,6 +811,7 @@  discard block
 block discarded – undo
786 811
 					}
787 812
 				]
788 813
 			});';
814
+	}
789 815
 
790 816
 	echo '
791 817
 			var oEditorID = "', $context['post_box_name'] ,'";
@@ -806,8 +832,9 @@  discard block
 block discarded – undo
806 832
 		foreach ($context['previous_posts'] as $post)
807 833
 		{
808 834
 			$ignoring = false;
809
-			if (!empty($post['is_ignored']))
810
-				$ignored_posts[] = $ignoring = $post['id'];
835
+			if (!empty($post['is_ignored'])) {
836
+							$ignored_posts[] = $ignoring = $post['id'];
837
+			}
811 838
 
812 839
 			echo '
813 840
 			<div class="windowbg">
@@ -990,10 +1017,10 @@  discard block
 block discarded – undo
990 1017
 		<div id="temporary_posting_area" style="display: none;"></div>
991 1018
 		<script>';
992 1019
 
993
-	if ($context['close_window'])
994
-		echo '
1020
+	if ($context['close_window']) {
1021
+			echo '
995 1022
 			window.close();';
996
-	else
1023
+	} else
997 1024
 	{
998 1025
 		// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;).
999 1026
 		echo '
@@ -1047,11 +1074,12 @@  discard block
 block discarded – undo
1047 1074
 				</p>
1048 1075
 				<ul>';
1049 1076
 
1050
-	foreach ($context['groups'] as $group)
1051
-		echo '
1077
+	foreach ($context['groups'] as $group) {
1078
+			echo '
1052 1079
 					<li>
1053 1080
 						<label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked class="input_check"> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em>
1054 1081
 					</li>';
1082
+	}
1055 1083
 
1056 1084
 	echo '
1057 1085
 					<li>
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
 									</div>
417 417
 									<div class="progressBar" role="progressBar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><span></span></div>
418 418
 									<div class="attach-ui">
419
-										<a data-dz-remove class="button_submit cancel">', $txt['modify_cancel'] ,'</a>
420
-										<a class="button_submit upload">', $txt['upload'] ,'</a>
419
+										<a data-dz-remove class="button_submit cancel">', $txt['modify_cancel'], '</a>
420
+										<a class="button_submit upload">', $txt['upload'], '</a>
421 421
 									</div>
422 422
 								</div>
423 423
 							</div>
@@ -435,10 +435,10 @@  discard block
 block discarded – undo
435 435
 							</dt>
436 436
 							<dd class="smalltext fallback">
437 437
 								<div id="attachUpload" class="descbox">
438
-									<h5>', $txt['attach_drop_zone'] ,'</h5>
439
-									<a class="button_submit" id="attach-cancelAll">', $txt['attached_cancelAll'] ,'</a>
440
-									<a class="button_submit" id="attach-uploadAll">', $txt['attached_uploadAll'] ,'</a>
441
-									<a class="button_submit fileinput-button">', $txt['attach_add'] ,'</a>
438
+									<h5>', $txt['attach_drop_zone'], '</h5>
439
+									<a class="button_submit" id="attach-cancelAll">', $txt['attached_cancelAll'], '</a>
440
+									<a class="button_submit" id="attach-uploadAll">', $txt['attached_uploadAll'], '</a>
441
+									<a class="button_submit fileinput-button">', $txt['attach_add'], '</a>
442 442
 									<div id="total-progress" class="progressBar" role="progressBar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><span></span></div>
443 443
 									<div class="fallback">
444 444
 										<input type="file" multiple="multiple" name="attachment[]" id="attachment1" class="input_file fallback"> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment1\');">', $txt['clean_attach'], '</a>)
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 	// Option to delete an event if user is editing one.
546 546
 	if ($context['make_event'] && !$context['event']['new'])
547 547
 		echo '
548
-						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button_submit you_sure">';
548
+						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'], '" class="button_submit you_sure">';
549 549
 
550 550
 	echo '
551 551
 					</span>
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
 			});';
800 800
 
801 801
 	echo '
802
-			var oEditorID = "', $context['post_box_name'] ,'";
802
+			var oEditorID = "', $context['post_box_name'], '";
803 803
 			var oEditorObject = oEditorHandle_', $context['post_box_name'], ';
804 804
 		</script>';
805 805
 
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 			{
832 832
 				echo '
833 833
 					<ul class="quickbuttons" id="msg_', $post['id'], '_quote">
834
-						<li style="display:none;" id="quoteSelected_', $post['id'], '" data-msgid="', $post['id'], '"><a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'] ,'</a></li>
834
+						<li style="display:none;" id="quoteSelected_', $post['id'], '" data-msgid="', $post['id'], '"><a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'], '</a></li>
835 835
 						<li id="post_modify"><a href="#postmodify" onclick="return insertQuoteFast(', $post['id'], ');"><span class="generic_icons quote"></span>', $txt['quote'], '</a></li>
836 836
 					</ul>';
837 837
 			}
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
 	<head>
919 919
 		<meta charset="', $context['character_set'], '">
920 920
 		<title>', $txt['spell_check'], '</title>
921
-		<link rel="stylesheet" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css', $modSettings['browser_cache'] ,'">
921
+		<link rel="stylesheet" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css', $modSettings['browser_cache'], '">
922 922
 		<style>
923 923
 			body, td
924 924
 			{
@@ -951,8 +951,8 @@  discard block
 block discarded – undo
951 951
 			var spell_formname = window.opener.spell_formname;
952 952
 			var spell_fieldname = window.opener.spell_fieldname;
953 953
 		</script>
954
-		<script src="', $settings['default_theme_url'], '/scripts/spellcheck.js', $modSettings['browser_cache'] ,'"></script>
955
-		<script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'] ,'"></script>
954
+		<script src="', $settings['default_theme_url'], '/scripts/spellcheck.js', $modSettings['browser_cache'], '"></script>
955
+		<script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'], '"></script>
956 956
 		<script>
957 957
 			', $context['spell_js'], '
958 958
 		</script>
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
 	<head>
995 995
 		<meta charset="', $context['character_set'], '">
996 996
 		<title>', $txt['retrieving_quote'], '</title>
997
-		<script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'] ,'"></script>
997
+		<script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'], '"></script>
998 998
 	</head>
999 999
 	<body>
1000 1000
 		', $txt['retrieving_quote'], '
Please login to merge, or discard this patch.
Sources/Subs-Editor.php 1 patch
Braces   +402 added lines, -303 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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
  * !!!Compatibility!!!
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 {
31 32
 	global $modSettings;
32 33
 
33
-	if (!$compat_mode)
34
-		return $text;
34
+	if (!$compat_mode) {
35
+			return $text;
36
+	}
35 37
 
36 38
 	// Turn line breaks back into br's.
37 39
 	$text = strtr($text, array("\r" => '', "\n" => '<br>'));
@@ -48,8 +50,9 @@  discard block
 block discarded – undo
48 50
 			for ($i = 0, $n = count($parts); $i < $n; $i++)
49 51
 			{
50 52
 				// Value of 2 means we're inside the tag.
51
-				if ($i % 4 == 2)
52
-					$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
53
+				if ($i % 4 == 2) {
54
+									$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
55
+				}
53 56
 			}
54 57
 			// Put our humpty dumpty message back together again.
55 58
 			$text = implode('', $parts);
@@ -107,8 +110,9 @@  discard block
 block discarded – undo
107 110
 	$text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text);
108 111
 
109 112
 	// Safari/webkit wraps lines in Wysiwyg in <div>'s.
110
-	if (isBrowser('webkit'))
111
-		$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
113
+	if (isBrowser('webkit')) {
114
+			$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
115
+	}
112 116
 
113 117
 	// If there's a trailing break get rid of it - Firefox tends to add one.
114 118
 	$text = preg_replace('~<br\s?/?' . '>$~i', '', $text);
@@ -123,8 +127,9 @@  discard block
 block discarded – undo
123 127
 		for ($i = 0, $n = count($parts); $i < $n; $i++)
124 128
 		{
125 129
 			// Value of 2 means we're inside the tag.
126
-			if ($i % 4 == 2)
127
-				$parts[$i] = strip_tags($parts[$i]);
130
+			if ($i % 4 == 2) {
131
+							$parts[$i] = strip_tags($parts[$i]);
132
+			}
128 133
 		}
129 134
 
130 135
 		$text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>'));
@@ -150,18 +155,19 @@  discard block
 block discarded – undo
150 155
 			{
151 156
 				$found = array_search($file, $smileysto);
152 157
 				// Note the weirdness here is to stop double spaces between smileys.
153
-				if ($found)
154
-					$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
155
-				else
156
-					$matches[1][$k] = '';
158
+				if ($found) {
159
+									$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
160
+				} else {
161
+									$matches[1][$k] = '';
162
+				}
157 163
 			}
158
-		}
159
-		else
164
+		} else
160 165
 		{
161 166
 			// Load all the smileys.
162 167
 			$names = array();
163
-			foreach ($matches[1] as $file)
164
-				$names[] = $file;
168
+			foreach ($matches[1] as $file) {
169
+							$names[] = $file;
170
+			}
165 171
 			$names = array_unique($names);
166 172
 
167 173
 			if (!empty($names))
@@ -175,13 +181,15 @@  discard block
 block discarded – undo
175 181
 					)
176 182
 				);
177 183
 				$mappings = array();
178
-				while ($row = $smcFunc['db_fetch_assoc']($request))
179
-					$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
184
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+									$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
186
+				}
180 187
 				$smcFunc['db_free_result']($request);
181 188
 
182
-				foreach ($matches[1] as $k => $file)
183
-					if (isset($mappings[$file]))
189
+				foreach ($matches[1] as $k => $file) {
190
+									if (isset($mappings[$file]))
184 191
 						$matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#';
192
+				}
185 193
 			}
186 194
 		}
187 195
 
@@ -193,8 +201,9 @@  discard block
 block discarded – undo
193 201
 	}
194 202
 
195 203
 	// Only try to buy more time if the client didn't quit.
196
-	if (connection_aborted() && $context['server']['is_apache'])
197
-		@apache_reset_timeout();
204
+	if (connection_aborted() && $context['server']['is_apache']) {
205
+			@apache_reset_timeout();
206
+	}
198 207
 
199 208
 	$parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
200 209
 	$replacement = '';
@@ -205,9 +214,9 @@  discard block
 block discarded – undo
205 214
 		if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1)
206 215
 		{
207 216
 			// If it's being closed instantly, we can't deal with it...yet.
208
-			if ($matches[5] === '/')
209
-				continue;
210
-			else
217
+			if ($matches[5] === '/') {
218
+							continue;
219
+			} else
211 220
 			{
212 221
 				// Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.)
213 222
 				$styles = explode(';', strtr($matches[3], array('&quot;' => '')));
@@ -223,8 +232,9 @@  discard block
 block discarded – undo
223 232
 					$clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':'));
224 233
 
225 234
 					// Something like 'font-weight: bold' is expected here.
226
-					if (strpos($clean_type_value_pair, ':') === false)
227
-						continue;
235
+					if (strpos($clean_type_value_pair, ':') === false) {
236
+											continue;
237
+					}
228 238
 
229 239
 					// Capture the elements of a single style item (e.g. 'font-weight' and 'bold').
230 240
 					list ($style_type, $style_value) = explode(':', $type_value_pair);
@@ -246,8 +256,7 @@  discard block
 block discarded – undo
246 256
 							{
247 257
 								$curCloseTags .= '[/u]';
248 258
 								$replacement .= '[u]';
249
-							}
250
-							elseif ($style_value == 'line-through')
259
+							} elseif ($style_value == 'line-through')
251 260
 							{
252 261
 								$curCloseTags .= '[/s]';
253 262
 								$replacement .= '[s]';
@@ -259,13 +268,11 @@  discard block
 block discarded – undo
259 268
 							{
260 269
 								$curCloseTags .= '[/left]';
261 270
 								$replacement .= '[left]';
262
-							}
263
-							elseif ($style_value == 'center')
271
+							} elseif ($style_value == 'center')
264 272
 							{
265 273
 								$curCloseTags .= '[/center]';
266 274
 								$replacement .= '[center]';
267
-							}
268
-							elseif ($style_value == 'right')
275
+							} elseif ($style_value == 'right')
269 276
 							{
270 277
 								$curCloseTags .= '[/right]';
271 278
 								$replacement .= '[right]';
@@ -287,8 +294,9 @@  discard block
 block discarded – undo
287 294
 
288 295
 						case 'font-size':
289 296
 							// Sometimes people put decimals where decimals should not be.
290
-							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1)
291
-								$style_value = $dec_matches[1] . $dec_matches[2];
297
+							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) {
298
+															$style_value = $dec_matches[1] . $dec_matches[2];
299
+							}
292 300
 
293 301
 							$curCloseTags .= '[/size]';
294 302
 							$replacement .= '[size=' . $style_value . ']';
@@ -296,8 +304,9 @@  discard block
 block discarded – undo
296 304
 
297 305
 						case 'font-family':
298 306
 							// Only get the first freaking font if there's a list!
299
-							if (strpos($style_value, ',') !== false)
300
-								$style_value = substr($style_value, 0, strpos($style_value, ','));
307
+							if (strpos($style_value, ',') !== false) {
308
+															$style_value = substr($style_value, 0, strpos($style_value, ','));
309
+							}
301 310
 
302 311
 							$curCloseTags .= '[/font]';
303 312
 							$replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']';
@@ -306,13 +315,15 @@  discard block
 block discarded – undo
306 315
 						// This is a hack for images with dimensions embedded.
307 316
 						case 'width':
308 317
 						case 'height':
309
-							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1)
310
-								$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
318
+							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
319
+															$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
320
+							}
311 321
 						break;
312 322
 
313 323
 						case 'list-style-type':
314
-							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1)
315
-								$extra_attr .= ' listtype="' . $listType[0] . '"';
324
+							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) {
325
+															$extra_attr .= ' listtype="' . $listType[0] . '"';
326
+							}
316 327
 						break;
317 328
 					}
318 329
 				}
@@ -325,18 +336,17 @@  discard block
 block discarded – undo
325 336
 				}
326 337
 
327 338
 				// If there's something that still needs closing, push it to the stack.
328
-				if (!empty($curCloseTags))
329
-					array_push($stack, array(
339
+				if (!empty($curCloseTags)) {
340
+									array_push($stack, array(
330 341
 							'element' => strtolower($curElement),
331 342
 							'closeTags' => $curCloseTags
332 343
 						)
333 344
 					);
334
-				elseif (!empty($extra_attr))
335
-					$replacement .= $precedingStyle . $extra_attr . $afterStyle;
345
+				} elseif (!empty($extra_attr)) {
346
+									$replacement .= $precedingStyle . $extra_attr . $afterStyle;
347
+				}
336 348
 			}
337
-		}
338
-
339
-		elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
349
+		} elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
340 350
 		{
341 351
 			// Is this the element that we've been waiting for to be closed?
342 352
 			if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element'])
@@ -346,28 +356,32 @@  discard block
 block discarded – undo
346 356
 			}
347 357
 
348 358
 			// Must've been something else.
349
-			else
350
-				$replacement .= $part;
359
+			else {
360
+							$replacement .= $part;
361
+			}
351 362
 		}
352 363
 		// In all other cases, just add the part to the replacement.
353
-		else
354
-			$replacement .= $part;
364
+		else {
365
+					$replacement .= $part;
366
+		}
355 367
 	}
356 368
 
357 369
 	// Now put back the replacement in the text.
358 370
 	$text = $replacement;
359 371
 
360 372
 	// We are not finished yet, request more time.
361
-	if (connection_aborted() && $context['server']['is_apache'])
362
-		@apache_reset_timeout();
373
+	if (connection_aborted() && $context['server']['is_apache']) {
374
+			@apache_reset_timeout();
375
+	}
363 376
 
364 377
 	// Let's pull out any legacy alignments.
365 378
 	while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1)
366 379
 	{
367 380
 		// Find the position in the text of this tag over again.
368 381
 		$start_pos = strpos($text, $matches[0]);
369
-		if ($start_pos === false)
370
-			break;
382
+		if ($start_pos === false) {
383
+					break;
384
+		}
371 385
 
372 386
 		// End tag?
373 387
 		if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false)
@@ -382,8 +396,7 @@  discard block
 block discarded – undo
382 396
 
383 397
 			// Put the tags back into the body.
384 398
 			$text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos);
385
-		}
386
-		else
399
+		} else
387 400
 		{
388 401
 			// Just get rid of this evil tag.
389 402
 			$text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0]));
@@ -396,8 +409,9 @@  discard block
 block discarded – undo
396 409
 		// Find the position of this again.
397 410
 		$start_pos = strpos($text, $matches[0]);
398 411
 		$end_pos = false;
399
-		if ($start_pos === false)
400
-			break;
412
+		if ($start_pos === false) {
413
+					break;
414
+		}
401 415
 
402 416
 		// This must have an end tag - and we must find the right one.
403 417
 		$lower_text = strtolower($text);
@@ -430,8 +444,9 @@  discard block
 block discarded – undo
430 444
 				break;
431 445
 			}
432 446
 		}
433
-		if ($end_pos === false)
434
-			break;
447
+		if ($end_pos === false) {
448
+					break;
449
+		}
435 450
 
436 451
 		// Now work out what the attributes are.
437 452
 		$attribs = fetchTagAttributes($matches[1]);
@@ -445,11 +460,11 @@  discard block
 block discarded – undo
445 460
 				$v = (int) trim($v);
446 461
 				$v = empty($v) ? 1 : $v;
447 462
 				$tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]');
463
+			} elseif ($s == 'face') {
464
+							$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
465
+			} elseif ($s == 'color') {
466
+							$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
448 467
 			}
449
-			elseif ($s == 'face')
450
-				$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
451
-			elseif ($s == 'color')
452
-				$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
453 468
 		}
454 469
 
455 470
 		// As before add in our tags.
@@ -457,8 +472,9 @@  discard block
 block discarded – undo
457 472
 		foreach ($tags as $tag)
458 473
 		{
459 474
 			$before .= $tag[0];
460
-			if (isset($tag[1]))
461
-				$after = $tag[1] . $after;
475
+			if (isset($tag[1])) {
476
+							$after = $tag[1] . $after;
477
+			}
462 478
 		}
463 479
 
464 480
 		// Remove the tag so it's never checked again.
@@ -469,8 +485,9 @@  discard block
 block discarded – undo
469 485
 	}
470 486
 
471 487
 	// Almost there, just a little more time.
472
-	if (connection_aborted() && $context['server']['is_apache'])
473
-		@apache_reset_timeout();
488
+	if (connection_aborted() && $context['server']['is_apache']) {
489
+			@apache_reset_timeout();
490
+	}
474 491
 
475 492
 	if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1)
476 493
 	{
@@ -526,12 +543,13 @@  discard block
 block discarded – undo
526 543
 						{
527 544
 							$inList = true;
528 545
 
529
-							if ($tag === 'ol')
530
-								$listType = 'decimal';
531
-							elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1)
532
-								$listType = $listTypeMapping[$match[1]];
533
-							else
534
-								$listType = null;
546
+							if ($tag === 'ol') {
547
+															$listType = 'decimal';
548
+							} elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) {
549
+															$listType = $listTypeMapping[$match[1]];
550
+							} else {
551
+															$listType = null;
552
+							}
535 553
 
536 554
 							$listDepth++;
537 555
 
@@ -595,9 +613,7 @@  discard block
 block discarded – undo
595 613
 							$parts[$i + 1] = '';
596 614
 							$parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]';
597 615
 							$parts[$i + 3] = '';
598
-						}
599
-
600
-						else
616
+						} else
601 617
 						{
602 618
 							// We're in a list item.
603 619
 							if ($listDepth > 0)
@@ -634,9 +650,7 @@  discard block
 block discarded – undo
634 650
 							$parts[$i + 1] = '';
635 651
 							$parts[$i + 2] = '';
636 652
 							$parts[$i + 3] = '';
637
-						}
638
-
639
-						else
653
+						} else
640 654
 						{
641 655
 							// Remove the trailing breaks from the list item.
642 656
 							$parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]);
@@ -674,8 +688,9 @@  discard block
 block discarded – undo
674 688
 			$text .= str_repeat("\t", $listDepth) . '[/list]';
675 689
 		}
676 690
 
677
-		for ($i = $listDepth; $i > 0; $i--)
678
-			$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
691
+		for ($i = $listDepth; $i > 0; $i--) {
692
+					$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
693
+		}
679 694
 
680 695
 	}
681 696
 
@@ -684,8 +699,9 @@  discard block
 block discarded – undo
684 699
 	{
685 700
 		// Find the position of the image.
686 701
 		$start_pos = strpos($text, $matches[0]);
687
-		if ($start_pos === false)
688
-			break;
702
+		if ($start_pos === false) {
703
+					break;
704
+		}
689 705
 		$end_pos = $start_pos + strlen($matches[0]);
690 706
 
691 707
 		$params = '';
@@ -694,12 +710,13 @@  discard block
 block discarded – undo
694 710
 		$attrs = fetchTagAttributes($matches[1]);
695 711
 		foreach ($attrs as $attrib => $value)
696 712
 		{
697
-			if (in_array($attrib, array('width', 'height')))
698
-				$params .= ' ' . $attrib . '=' . (int) $value;
699
-			elseif ($attrib == 'alt' && trim($value) != '')
700
-				$params .= ' alt=' . trim($value);
701
-			elseif ($attrib == 'src')
702
-				$src = trim($value);
713
+			if (in_array($attrib, array('width', 'height'))) {
714
+							$params .= ' ' . $attrib . '=' . (int) $value;
715
+			} elseif ($attrib == 'alt' && trim($value) != '') {
716
+							$params .= ' alt=' . trim($value);
717
+			} elseif ($attrib == 'src') {
718
+							$src = trim($value);
719
+			}
703 720
 		}
704 721
 
705 722
 		$tag = '';
@@ -710,10 +727,11 @@  discard block
 block discarded – undo
710 727
 			{
711 728
 				$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
712 729
 
713
-				if (substr($src, 0, 1) === '/')
714
-					$src = $baseURL . $src;
715
-				else
716
-					$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
730
+				if (substr($src, 0, 1) === '/') {
731
+									$src = $baseURL . $src;
732
+				} else {
733
+									$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
734
+				}
717 735
 			}
718 736
 
719 737
 			$tag = '[img' . $params . ']' . $src . '[/img]';
@@ -891,20 +909,23 @@  discard block
 block discarded – undo
891 909
 		},
892 910
 	);
893 911
 
894
-	foreach ($tags as $tag => $replace)
895
-		$text = preg_replace_callback($tag, $replace, $text);
912
+	foreach ($tags as $tag => $replace) {
913
+			$text = preg_replace_callback($tag, $replace, $text);
914
+	}
896 915
 
897 916
 	// Please give us just a little more time.
898
-	if (connection_aborted() && $context['server']['is_apache'])
899
-		@apache_reset_timeout();
917
+	if (connection_aborted() && $context['server']['is_apache']) {
918
+			@apache_reset_timeout();
919
+	}
900 920
 
901 921
 	// What about URL's - the pain in the ass of the tag world.
902 922
 	while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1)
903 923
 	{
904 924
 		// Find the position of the URL.
905 925
 		$start_pos = strpos($text, $matches[0]);
906
-		if ($start_pos === false)
907
-			break;
926
+		if ($start_pos === false) {
927
+					break;
928
+		}
908 929
 		$end_pos = $start_pos + strlen($matches[0]);
909 930
 
910 931
 		$tag_type = 'url';
@@ -918,8 +939,9 @@  discard block
 block discarded – undo
918 939
 				$href = trim($value);
919 940
 
920 941
 				// Are we dealing with an FTP link?
921
-				if (preg_match('~^ftps?://~', $href) === 1)
922
-					$tag_type = 'ftp';
942
+				if (preg_match('~^ftps?://~', $href) === 1) {
943
+									$tag_type = 'ftp';
944
+				}
923 945
 
924 946
 				// Or is this a link to an email address?
925 947
 				elseif (substr($href, 0, 7) == 'mailto:')
@@ -933,28 +955,31 @@  discard block
 block discarded – undo
933 955
 				{
934 956
 					$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
935 957
 
936
-					if (substr($href, 0, 1) === '/')
937
-						$href = $baseURL . $href;
938
-					else
939
-						$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
958
+					if (substr($href, 0, 1) === '/') {
959
+											$href = $baseURL . $href;
960
+					} else {
961
+											$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
962
+					}
940 963
 				}
941 964
 			}
942 965
 
943 966
 			// External URL?
944 967
 			if ($attrib == 'target' && $tag_type == 'url')
945 968
 			{
946
-				if (trim($value) == '_blank')
947
-					$tag_type == 'iurl';
969
+				if (trim($value) == '_blank') {
970
+									$tag_type == 'iurl';
971
+				}
948 972
 			}
949 973
 		}
950 974
 
951 975
 		$tag = '';
952 976
 		if ($href != '')
953 977
 		{
954
-			if ($matches[2] == $href)
955
-				$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
956
-			else
957
-				$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
978
+			if ($matches[2] == $href) {
979
+							$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
980
+			} else {
981
+							$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
982
+			}
958 983
 		}
959 984
 
960 985
 		// Replace the tag
@@ -993,17 +1018,18 @@  discard block
 block discarded – undo
993 1018
 		// We're either moving from the key to the attribute or we're in a string and this is fine.
994 1019
 		if ($text[$i] == '=')
995 1020
 		{
996
-			if ($tag_state == 0)
997
-				$tag_state = 1;
998
-			elseif ($tag_state == 2)
999
-				$value .= '=';
1021
+			if ($tag_state == 0) {
1022
+							$tag_state = 1;
1023
+			} elseif ($tag_state == 2) {
1024
+							$value .= '=';
1025
+			}
1000 1026
 		}
1001 1027
 		// A space is either moving from an attribute back to a potential key or in a string is fine.
1002 1028
 		elseif ($text[$i] == ' ')
1003 1029
 		{
1004
-			if ($tag_state == 2)
1005
-				$value .= ' ';
1006
-			elseif ($tag_state == 1)
1030
+			if ($tag_state == 2) {
1031
+							$value .= ' ';
1032
+			} elseif ($tag_state == 1)
1007 1033
 			{
1008 1034
 				$attribs[$key] = $value;
1009 1035
 				$key = $value = '';
@@ -1014,24 +1040,27 @@  discard block
 block discarded – undo
1014 1040
 		elseif ($text[$i] == '"')
1015 1041
 		{
1016 1042
 			// Must be either going into or out of a string.
1017
-			if ($tag_state == 1)
1018
-				$tag_state = 2;
1019
-			else
1020
-				$tag_state = 1;
1043
+			if ($tag_state == 1) {
1044
+							$tag_state = 2;
1045
+			} else {
1046
+							$tag_state = 1;
1047
+			}
1021 1048
 		}
1022 1049
 		// Otherwise it's fine.
1023 1050
 		else
1024 1051
 		{
1025
-			if ($tag_state == 0)
1026
-				$key .= $text[$i];
1027
-			else
1028
-				$value .= $text[$i];
1052
+			if ($tag_state == 0) {
1053
+							$key .= $text[$i];
1054
+			} else {
1055
+							$value .= $text[$i];
1056
+			}
1029 1057
 		}
1030 1058
 	}
1031 1059
 
1032 1060
 	// Anything left?
1033
-	if ($key != '' && $value != '')
1034
-		$attribs[$key] = $value;
1061
+	if ($key != '' && $value != '') {
1062
+			$attribs[$key] = $value;
1063
+	}
1035 1064
 
1036 1065
 	return $attribs;
1037 1066
 }
@@ -1047,15 +1076,17 @@  discard block
 block discarded – undo
1047 1076
 	global $modSettings;
1048 1077
 
1049 1078
 	// Don't care about the texts that are too short.
1050
-	if (strlen($text) < 3)
1051
-		return $text;
1079
+	if (strlen($text) < 3) {
1080
+			return $text;
1081
+	}
1052 1082
 
1053 1083
 	// A list of tags that's disabled by the admin.
1054 1084
 	$disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC'])));
1055 1085
 
1056 1086
 	// Add flash if it's disabled as embedded tag.
1057
-	if (empty($modSettings['enableEmbeddedFlash']))
1058
-		$disabled['flash'] = true;
1087
+	if (empty($modSettings['enableEmbeddedFlash'])) {
1088
+			$disabled['flash'] = true;
1089
+	}
1059 1090
 
1060 1091
 	// Get a list of all the tags that are not disabled.
1061 1092
 	$all_tags = parse_bbc(false);
@@ -1063,10 +1094,12 @@  discard block
 block discarded – undo
1063 1094
 	$self_closing_tags = array();
1064 1095
 	foreach ($all_tags as $tag)
1065 1096
 	{
1066
-		if (!isset($disabled[$tag['tag']]))
1067
-			$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1068
-		if (isset($tag['type']) && $tag['type'] == 'closed')
1069
-			$self_closing_tags[] = $tag['tag'];
1097
+		if (!isset($disabled[$tag['tag']])) {
1098
+					$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1099
+		}
1100
+		if (isset($tag['type']) && $tag['type'] == 'closed') {
1101
+					$self_closing_tags[] = $tag['tag'];
1102
+		}
1070 1103
 	}
1071 1104
 
1072 1105
 	// Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid!
@@ -1093,16 +1126,19 @@  discard block
 block discarded – undo
1093 1126
 				$tagName = substr($match, $isClosingTag ? 2 : 1, -1);
1094 1127
 
1095 1128
 				// We're closing the exact same tag that we opened.
1096
-				if ($isClosingTag && $insideTag === $tagName)
1097
-					$insideTag = null;
1129
+				if ($isClosingTag && $insideTag === $tagName) {
1130
+									$insideTag = null;
1131
+				}
1098 1132
 
1099 1133
 				// We're opening a tag and we're not yet inside one either
1100
-				elseif (!$isClosingTag && $insideTag === null)
1101
-					$insideTag = $tagName;
1134
+				elseif (!$isClosingTag && $insideTag === null) {
1135
+									$insideTag = $tagName;
1136
+				}
1102 1137
 
1103 1138
 				// In all other cases, this tag must be invalid
1104
-				else
1105
-					unset($matches[$i]);
1139
+				else {
1140
+									unset($matches[$i]);
1141
+				}
1106 1142
 			}
1107 1143
 
1108 1144
 			// The next one is gonna be the other one.
@@ -1110,8 +1146,9 @@  discard block
 block discarded – undo
1110 1146
 		}
1111 1147
 
1112 1148
 		// We're still inside a tag and had no chance for closure?
1113
-		if ($insideTag !== null)
1114
-			$matches[] = '[/' . $insideTag . ']';
1149
+		if ($insideTag !== null) {
1150
+					$matches[] = '[/' . $insideTag . ']';
1151
+		}
1115 1152
 
1116 1153
 		// And a complete text string again.
1117 1154
 		$text = implode('', $matches);
@@ -1120,8 +1157,9 @@  discard block
 block discarded – undo
1120 1157
 	// Quickly remove any tags which are back to back.
1121 1158
 	$backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~';
1122 1159
 	$lastlen = 0;
1123
-	while (strlen($text) !== $lastlen)
1124
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1160
+	while (strlen($text) !== $lastlen) {
1161
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1162
+	}
1125 1163
 
1126 1164
 	// Need to sort the tags my name length.
1127 1165
 	uksort($valid_tags, 'sort_array_length');
@@ -1158,8 +1196,9 @@  discard block
 block discarded – undo
1158 1196
 			$isCompetingTag = in_array($tag, $competing_tags);
1159 1197
 
1160 1198
 			// Check if this might be one of those cleaned out tags.
1161
-			if ($tag === '')
1162
-				continue;
1199
+			if ($tag === '') {
1200
+							continue;
1201
+			}
1163 1202
 
1164 1203
 			// Special case: inside [code] blocks any code is left untouched.
1165 1204
 			elseif ($tag === 'code')
@@ -1170,8 +1209,9 @@  discard block
 block discarded – undo
1170 1209
 					$inCode = false;
1171 1210
 
1172 1211
 					// Reopen tags that were closed before the code block.
1173
-					if (!empty($inlineElements))
1174
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1212
+					if (!empty($inlineElements)) {
1213
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1214
+					}
1175 1215
 				}
1176 1216
 
1177 1217
 				// We're outside a coding and nobbc block and opening it.
@@ -1200,8 +1240,9 @@  discard block
 block discarded – undo
1200 1240
 					$inNoBbc = false;
1201 1241
 
1202 1242
 					// Some inline elements might've been closed that need reopening.
1203
-					if (!empty($inlineElements))
1204
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1243
+					if (!empty($inlineElements)) {
1244
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1245
+					}
1205 1246
 				}
1206 1247
 
1207 1248
 				// We're outside a nobbc and coding block and opening it.
@@ -1221,8 +1262,9 @@  discard block
 block discarded – undo
1221 1262
 			}
1222 1263
 
1223 1264
 			// So, we're inside one of the special blocks: ignore any tag.
1224
-			elseif ($inCode || $inNoBbc)
1225
-				continue;
1265
+			elseif ($inCode || $inNoBbc) {
1266
+							continue;
1267
+			}
1226 1268
 
1227 1269
 			// We're dealing with an opening tag.
1228 1270
 			if ($isOpeningTag)
@@ -1263,8 +1305,9 @@  discard block
 block discarded – undo
1263 1305
 							if ($parts[$j + 3] === $tag)
1264 1306
 							{
1265 1307
 								// If it's an opening tag, increase the level.
1266
-								if ($parts[$j + 2] === '')
1267
-									$curLevel++;
1308
+								if ($parts[$j + 2] === '') {
1309
+																	$curLevel++;
1310
+								}
1268 1311
 
1269 1312
 								// A closing tag, decrease the level.
1270 1313
 								else
@@ -1287,13 +1330,15 @@  discard block
 block discarded – undo
1287 1330
 					{
1288 1331
 						if ($isCompetingTag)
1289 1332
 						{
1290
-							if (!isset($competingElements[$tag]))
1291
-								$competingElements[$tag] = array();
1333
+							if (!isset($competingElements[$tag])) {
1334
+															$competingElements[$tag] = array();
1335
+							}
1292 1336
 
1293 1337
 							$competingElements[$tag][] = $parts[$i + 4];
1294 1338
 
1295
-							if (count($competingElements[$tag]) > 1)
1296
-								$parts[$i] .= '[/' . $tag . ']';
1339
+							if (count($competingElements[$tag]) > 1) {
1340
+															$parts[$i] .= '[/' . $tag . ']';
1341
+							}
1297 1342
 						}
1298 1343
 
1299 1344
 						$inlineElements[$elementContent] = $tag;
@@ -1314,15 +1359,17 @@  discard block
 block discarded – undo
1314 1359
 						$addClosingTags = array();
1315 1360
 						while ($element = array_pop($blockElements))
1316 1361
 						{
1317
-							if ($element === $tag)
1318
-								break;
1362
+							if ($element === $tag) {
1363
+															break;
1364
+							}
1319 1365
 
1320 1366
 							// Still a block tag was open not equal to this tag.
1321 1367
 							$addClosingTags[] = $element['type'];
1322 1368
 						}
1323 1369
 
1324
-						if (!empty($addClosingTags))
1325
-							$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1370
+						if (!empty($addClosingTags)) {
1371
+													$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1372
+						}
1326 1373
 
1327 1374
 						// Apparently the closing tag was not found on the stack.
1328 1375
 						if (!is_string($element) || $element !== $tag)
@@ -1332,8 +1379,7 @@  discard block
 block discarded – undo
1332 1379
 							$parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1333 1380
 							continue;
1334 1381
 						}
1335
-					}
1336
-					else
1382
+					} else
1337 1383
 					{
1338 1384
 						// Get rid of this closing tag!
1339 1385
 						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
@@ -1362,53 +1408,62 @@  discard block
 block discarded – undo
1362 1408
 							unset($inlineElements[$tagContentToBeClosed]);
1363 1409
 
1364 1410
 							// Was this the tag we were looking for?
1365
-							if ($tagToBeClosed === $tag)
1366
-								break;
1411
+							if ($tagToBeClosed === $tag) {
1412
+															break;
1413
+							}
1367 1414
 
1368 1415
 							// Nope, close it and look further!
1369
-							else
1370
-								$parts[$i] .= '[/' . $tagToBeClosed . ']';
1416
+							else {
1417
+															$parts[$i] .= '[/' . $tagToBeClosed . ']';
1418
+							}
1371 1419
 						}
1372 1420
 
1373 1421
 						if ($isCompetingTag && !empty($competingElements[$tag]))
1374 1422
 						{
1375 1423
 							array_pop($competingElements[$tag]);
1376 1424
 
1377
-							if (count($competingElements[$tag]) > 0)
1378
-								$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1425
+							if (count($competingElements[$tag]) > 0) {
1426
+															$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1427
+							}
1379 1428
 						}
1380 1429
 					}
1381 1430
 
1382 1431
 					// Unexpected closing tag, ex-ter-mi-nate.
1383
-					else
1384
-						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1432
+					else {
1433
+											$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1434
+					}
1385 1435
 				}
1386 1436
 			}
1387 1437
 		}
1388 1438
 
1389 1439
 		// Close the code tags.
1390
-		if ($inCode)
1391
-			$parts[$i] .= '[/code]';
1440
+		if ($inCode) {
1441
+					$parts[$i] .= '[/code]';
1442
+		}
1392 1443
 
1393 1444
 		// The same for nobbc tags.
1394
-		elseif ($inNoBbc)
1395
-			$parts[$i] .= '[/nobbc]';
1445
+		elseif ($inNoBbc) {
1446
+					$parts[$i] .= '[/nobbc]';
1447
+		}
1396 1448
 
1397 1449
 		// Still inline tags left unclosed? Close them now, better late than never.
1398
-		elseif (!empty($inlineElements))
1399
-			$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1450
+		elseif (!empty($inlineElements)) {
1451
+					$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1452
+		}
1400 1453
 
1401 1454
 		// Now close the block elements.
1402
-		if (!empty($blockElements))
1403
-			$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1455
+		if (!empty($blockElements)) {
1456
+					$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1457
+		}
1404 1458
 
1405 1459
 		$text = implode('', $parts);
1406 1460
 	}
1407 1461
 
1408 1462
 	// Final clean up of back to back tags.
1409 1463
 	$lastlen = 0;
1410
-	while (strlen($text) !== $lastlen)
1411
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1464
+	while (strlen($text) !== $lastlen) {
1465
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1466
+	}
1412 1467
 
1413 1468
 	return $text;
1414 1469
 }
@@ -1437,22 +1492,25 @@  discard block
 block discarded – undo
1437 1492
 	$context['template_layers'] = array();
1438 1493
 	// Lets make sure we aren't going to output anything nasty.
1439 1494
 	@ob_end_clean();
1440
-	if (!empty($modSettings['enableCompressedOutput']))
1441
-		@ob_start('ob_gzhandler');
1442
-	else
1443
-		@ob_start();
1495
+	if (!empty($modSettings['enableCompressedOutput'])) {
1496
+			@ob_start('ob_gzhandler');
1497
+	} else {
1498
+			@ob_start();
1499
+	}
1444 1500
 
1445 1501
 	// If we don't have any locale better avoid broken js
1446
-	if (empty($txt['lang_locale']))
1447
-		die();
1502
+	if (empty($txt['lang_locale'])) {
1503
+			die();
1504
+	}
1448 1505
 
1449 1506
 	$file_data = '(function ($) {
1450 1507
 	\'use strict\';
1451 1508
 
1452 1509
 	$.sceditor.locale[' . javaScriptEscape($txt['lang_locale']) . '] = {';
1453
-	foreach ($editortxt as $key => $val)
1454
-		$file_data .= '
1510
+	foreach ($editortxt as $key => $val) {
1511
+			$file_data .= '
1455 1512
 		' . javaScriptEscape($key) . ': ' . javaScriptEscape($val) . ',';
1513
+	}
1456 1514
 
1457 1515
 	$file_data .= '
1458 1516
 		dateFormat: "day.month.year"
@@ -1520,8 +1578,9 @@  discard block
 block discarded – undo
1520 1578
 				)
1521 1579
 			);
1522 1580
 			$icon_data = array();
1523
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1524
-				$icon_data[] = $row;
1581
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1582
+							$icon_data[] = $row;
1583
+			}
1525 1584
 			$smcFunc['db_free_result']($request);
1526 1585
 
1527 1586
 			$icons = array();
@@ -1536,9 +1595,9 @@  discard block
 block discarded – undo
1536 1595
 			}
1537 1596
 
1538 1597
 			cache_put_data('posting_icons-' . $board_id, $icons, 480);
1598
+		} else {
1599
+					$icons = $temp;
1539 1600
 		}
1540
-		else
1541
-			$icons = $temp;
1542 1601
 	}
1543 1602
 	call_integration_hook('integrate_load_message_icons', array(&$icons));
1544 1603
 
@@ -1579,8 +1638,9 @@  discard block
 block discarded – undo
1579 1638
 	{
1580 1639
 		// Some general stuff.
1581 1640
 		$settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
1582
-		if (!empty($context['drafts_autosave']))
1583
-			$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1641
+		if (!empty($context['drafts_autosave'])) {
1642
+					$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1643
+		}
1584 1644
 
1585 1645
 		// This really has some WYSIWYG stuff.
1586 1646
 		loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor');
@@ -1596,8 +1656,9 @@  discard block
 block discarded – undo
1596 1656
 		var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\';
1597 1657
 		var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';');
1598 1658
 		// editor language file
1599
-		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US')
1600
-			loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1659
+		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') {
1660
+					loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1661
+		}
1601 1662
 
1602 1663
 		$context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))];
1603 1664
 		$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
@@ -1606,11 +1667,12 @@  discard block
 block discarded – undo
1606 1667
 			loadJavaScriptFile('spellcheck.js', array(), 'smf_spellcheck');
1607 1668
 
1608 1669
 			// Some hidden information is needed in order to make the spell checking work.
1609
-			if (!isset($_REQUEST['xml']))
1610
-				$context['insert_after_template'] .= '
1670
+			if (!isset($_REQUEST['xml'])) {
1671
+							$context['insert_after_template'] .= '
1611 1672
 		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
1612 1673
 			<input type="hidden" name="spellstring" value="">
1613 1674
 		</form>';
1675
+			}
1614 1676
 		}
1615 1677
 	}
1616 1678
 
@@ -1776,10 +1838,12 @@  discard block
 block discarded – undo
1776 1838
 
1777 1839
 		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
1778 1840
 		$disabled_tags = array();
1779
-		if (!empty($modSettings['disabledBBC']))
1780
-			$disabled_tags = explode(',', $modSettings['disabledBBC']);
1781
-		if (empty($modSettings['enableEmbeddedFlash']))
1782
-			$disabled_tags[] = 'flash';
1841
+		if (!empty($modSettings['disabledBBC'])) {
1842
+					$disabled_tags = explode(',', $modSettings['disabledBBC']);
1843
+		}
1844
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1845
+					$disabled_tags[] = 'flash';
1846
+		}
1783 1847
 
1784 1848
 		foreach ($disabled_tags as $tag)
1785 1849
 		{
@@ -1789,9 +1853,10 @@  discard block
 block discarded – undo
1789 1853
 				$context['disabled_tags']['orderedlist'] = true;
1790 1854
 			}
1791 1855
 
1792
-			foreach ($editor_tag_map as $thisTag => $tagNameBBC)
1793
-				if ($tag === $thisTag)
1856
+			foreach ($editor_tag_map as $thisTag => $tagNameBBC) {
1857
+							if ($tag === $thisTag)
1794 1858
 					$context['disabled_tags'][$tagNameBBC] = true;
1859
+			}
1795 1860
 
1796 1861
 			$context['disabled_tags'][trim($tag)] = true;
1797 1862
 		}
@@ -1801,19 +1866,21 @@  discard block
 block discarded – undo
1801 1866
 		$context['bbc_toolbar'] = array();
1802 1867
 		foreach ($context['bbc_tags'] as $row => $tagRow)
1803 1868
 		{
1804
-			if (!isset($context['bbc_toolbar'][$row]))
1805
-				$context['bbc_toolbar'][$row] = array();
1869
+			if (!isset($context['bbc_toolbar'][$row])) {
1870
+							$context['bbc_toolbar'][$row] = array();
1871
+			}
1806 1872
 			$tagsRow = array();
1807 1873
 			foreach ($tagRow as $tag)
1808 1874
 			{
1809 1875
 				if ((!empty($tag['code'])) && empty($context['disabled_tags'][$tag['code']]))
1810 1876
 				{
1811 1877
 					$tagsRow[] = $tag['code'];
1812
-					if (isset($tag['image']))
1813
-						$bbcodes_styles .= '
1878
+					if (isset($tag['image'])) {
1879
+											$bbcodes_styles .= '
1814 1880
 			.sceditor-button-' . $tag['code'] . ' div {
1815 1881
 				background: url(\'' . $settings['default_theme_url'] . '/images/bbc/' . $tag['image'] . '.png\');
1816 1882
 			}';
1883
+					}
1817 1884
 					if (isset($tag['before']))
1818 1885
 					{
1819 1886
 						$context['bbcodes_handlers'] .= '
@@ -1827,8 +1894,7 @@  discard block
 block discarded – undo
1827 1894
 				});';
1828 1895
 					}
1829 1896
 
1830
-				}
1831
-				else
1897
+				} else
1832 1898
 				{
1833 1899
 					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1834 1900
 					$tagsRow = array();
@@ -1839,14 +1905,16 @@  discard block
 block discarded – undo
1839 1905
 			{
1840 1906
 				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1841 1907
 				$tagsRow = array();
1842
-				if (!isset($context['disabled_tags']['font']))
1843
-					$tagsRow[] = 'font';
1844
-				if (!isset($context['disabled_tags']['size']))
1845
-					$tagsRow[] = 'size';
1846
-				if (!isset($context['disabled_tags']['color']))
1847
-					$tagsRow[] = 'color';
1848
-			}
1849
-			elseif ($row == 1 && empty($modSettings['disable_wysiwyg']))
1908
+				if (!isset($context['disabled_tags']['font'])) {
1909
+									$tagsRow[] = 'font';
1910
+				}
1911
+				if (!isset($context['disabled_tags']['size'])) {
1912
+									$tagsRow[] = 'size';
1913
+				}
1914
+				if (!isset($context['disabled_tags']['color'])) {
1915
+									$tagsRow[] = 'color';
1916
+				}
1917
+			} elseif ($row == 1 && empty($modSettings['disable_wysiwyg']))
1850 1918
 			{
1851 1919
 				$tmp = array();
1852 1920
 				$tagsRow[] = 'removeformat';
@@ -1857,13 +1925,15 @@  discard block
 block discarded – undo
1857 1925
 				}
1858 1926
 			}
1859 1927
 
1860
-			if (!empty($tagsRow))
1861
-				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1928
+			if (!empty($tagsRow)) {
1929
+							$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1930
+			}
1862 1931
 		}
1863
-		if (!empty($bbcodes_styles))
1864
-			$context['html_headers'] .= '
1932
+		if (!empty($bbcodes_styles)) {
1933
+					$context['html_headers'] .= '
1865 1934
 		<style>' . $bbcodes_styles . '
1866 1935
 		</style>';
1936
+		}
1867 1937
 	}
1868 1938
 
1869 1939
 	// Initialize smiley array... if not loaded before.
@@ -1875,8 +1945,8 @@  discard block
 block discarded – undo
1875 1945
 		);
1876 1946
 
1877 1947
 		// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
1878
-		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none')
1879
-			$context['smileys']['postform'][] = array(
1948
+		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
1949
+					$context['smileys']['postform'][] = array(
1880 1950
 				'smileys' => array(
1881 1951
 					array(
1882 1952
 						'code' => ':)',
@@ -1962,7 +2032,7 @@  discard block
 block discarded – undo
1962 2032
 				),
1963 2033
 				'isLast' => true,
1964 2034
 			);
1965
-		elseif ($user_info['smiley_set'] != 'none')
2035
+		} elseif ($user_info['smiley_set'] != 'none')
1966 2036
 		{
1967 2037
 			if (($temp = cache_get_data('posting_smileys', 480)) == null)
1968 2038
 			{
@@ -1985,17 +2055,19 @@  discard block
 block discarded – undo
1985 2055
 
1986 2056
 				foreach ($context['smileys'] as $section => $smileyRows)
1987 2057
 				{
1988
-					foreach ($smileyRows as $rowIndex => $smileys)
1989
-						$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2058
+					foreach ($smileyRows as $rowIndex => $smileys) {
2059
+											$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2060
+					}
1990 2061
 
1991
-					if (!empty($smileyRows))
1992
-						$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2062
+					if (!empty($smileyRows)) {
2063
+											$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2064
+					}
1993 2065
 				}
1994 2066
 
1995 2067
 				cache_put_data('posting_smileys', $context['smileys'], 480);
2068
+			} else {
2069
+							$context['smileys'] = $temp;
1996 2070
 			}
1997
-			else
1998
-				$context['smileys'] = $temp;
1999 2071
 		}
2000 2072
 	}
2001 2073
 
@@ -2021,8 +2093,9 @@  discard block
 block discarded – undo
2021 2093
 		loadTemplate('GenericControls');
2022 2094
 
2023 2095
 		// Some javascript ma'am?
2024
-		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])))
2025
-			loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2096
+		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) {
2097
+					loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2098
+		}
2026 2099
 
2027 2100
 		$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
2028 2101
 
@@ -2035,8 +2108,8 @@  discard block
 block discarded – undo
2035 2108
 	$isNew = !isset($context['controls']['verification'][$verificationOptions['id']]);
2036 2109
 
2037 2110
 	// Log this into our collection.
2038
-	if ($isNew)
2039
-		$context['controls']['verification'][$verificationOptions['id']] = array(
2111
+	if ($isNew) {
2112
+			$context['controls']['verification'][$verificationOptions['id']] = array(
2040 2113
 			'id' => $verificationOptions['id'],
2041 2114
 			'empty_field' => empty($verificationOptions['no_empty_field']),
2042 2115
 			'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])),
@@ -2047,13 +2120,15 @@  discard block
 block discarded – undo
2047 2120
 			'questions' => array(),
2048 2121
 			'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']),
2049 2122
 		);
2123
+	}
2050 2124
 	$thisVerification = &$context['controls']['verification'][$verificationOptions['id']];
2051 2125
 
2052 2126
 	// Is there actually going to be anything?
2053
-	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha']))
2054
-		return false;
2055
-	elseif (!$isNew && !$do_test)
2056
-		return true;
2127
+	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) {
2128
+			return false;
2129
+	} elseif (!$isNew && !$do_test) {
2130
+			return true;
2131
+	}
2057 2132
 
2058 2133
 	// Sanitize reCAPTCHA fields?
2059 2134
 	if ($thisVerification['can_recaptcha'])
@@ -2066,11 +2141,12 @@  discard block
 block discarded – undo
2066 2141
 	}
2067 2142
 
2068 2143
 	// Add javascript for the object.
2069
-	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual'])
2070
-		$context['insert_after_template'] .= '
2144
+	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) {
2145
+			$context['insert_after_template'] .= '
2071 2146
 			<script>
2072 2147
 				var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . ');
2073 2148
 			</script>';
2149
+	}
2074 2150
 
2075 2151
 	// If we want questions do we have a cache of all the IDs?
2076 2152
 	if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache']))
@@ -2093,8 +2169,9 @@  discard block
 block discarded – undo
2093 2169
 				unset ($row['id_question']);
2094 2170
 				// Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh?
2095 2171
 				$row['answers'] = smf_json_decode($row['answers'], true);
2096
-				foreach ($row['answers'] as $k => $v)
2097
-					$row['answers'][$k] = $smcFunc['strtolower']($v);
2172
+				foreach ($row['answers'] as $k => $v) {
2173
+									$row['answers'][$k] = $smcFunc['strtolower']($v);
2174
+				}
2098 2175
 
2099 2176
 				$modSettings['question_id_cache']['questions'][$id_question] = $row;
2100 2177
 				$modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question;
@@ -2105,35 +2182,42 @@  discard block
 block discarded – undo
2105 2182
 		}
2106 2183
 	}
2107 2184
 
2108
-	if (!isset($_SESSION[$verificationOptions['id'] . '_vv']))
2109
-		$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2185
+	if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) {
2186
+			$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2187
+	}
2110 2188
 
2111 2189
 	// Do we need to refresh the verification?
2112
-	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh']))
2113
-		$force_refresh = true;
2114
-	else
2115
-		$force_refresh = false;
2190
+	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) {
2191
+			$force_refresh = true;
2192
+	} else {
2193
+			$force_refresh = false;
2194
+	}
2116 2195
 
2117 2196
 	// This can also force a fresh, although unlikely.
2118
-	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q'])))
2119
-		$force_refresh = true;
2197
+	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) {
2198
+			$force_refresh = true;
2199
+	}
2120 2200
 
2121 2201
 	$verification_errors = array();
2122 2202
 	// Start with any testing.
2123 2203
 	if ($do_test)
2124 2204
 	{
2125 2205
 		// This cannot happen!
2126
-		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count']))
2127
-			fatal_lang_error('no_access', false);
2206
+		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) {
2207
+					fatal_lang_error('no_access', false);
2208
+		}
2128 2209
 		// ... nor this!
2129
-		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'])))
2130
-			fatal_lang_error('no_access', false);
2210
+		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) {
2211
+					fatal_lang_error('no_access', false);
2212
+		}
2131 2213
 		// Hmm, it's requested but not actually declared. This shouldn't happen.
2132
-		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2133
-			fatal_lang_error('no_access', false);
2214
+		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) {
2215
+					fatal_lang_error('no_access', false);
2216
+		}
2134 2217
 		// While we're here, did the user do something bad?
2135
-		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']]))
2136
-			$verification_errors[] = 'wrong_verification_answer';
2218
+		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) {
2219
+					$verification_errors[] = 'wrong_verification_answer';
2220
+		}
2137 2221
 
2138 2222
 		if ($thisVerification['can_recaptcha'])
2139 2223
 		{
@@ -2144,22 +2228,25 @@  discard block
 block discarded – undo
2144 2228
 			{
2145 2229
 				$resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']);
2146 2230
 
2147
-				if (!$resp->isSuccess())
2148
-					$verification_errors[] = 'wrong_verification_code';
2231
+				if (!$resp->isSuccess()) {
2232
+									$verification_errors[] = 'wrong_verification_code';
2233
+				}
2234
+			} else {
2235
+							$verification_errors[] = 'wrong_verification_code';
2149 2236
 			}
2150
-			else
2151
-				$verification_errors[] = 'wrong_verification_code';
2152 2237
 		}
2153
-		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code']))
2154
-			$verification_errors[] = 'wrong_verification_code';
2238
+		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) {
2239
+					$verification_errors[] = 'wrong_verification_code';
2240
+		}
2155 2241
 		if ($thisVerification['number_questions'])
2156 2242
 		{
2157 2243
 			$incorrectQuestions = array();
2158 2244
 			foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q)
2159 2245
 			{
2160 2246
 				// We don't have this question any more, thus no answers.
2161
-				if (!isset($modSettings['question_id_cache']['questions'][$q]))
2162
-					continue;
2247
+				if (!isset($modSettings['question_id_cache']['questions'][$q])) {
2248
+									continue;
2249
+				}
2163 2250
 				// This is quite complex. We have our question but it might have multiple answers.
2164 2251
 				// First, did they actually answer this question?
2165 2252
 				if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '')
@@ -2171,24 +2258,28 @@  discard block
 block discarded – undo
2171 2258
 				else
2172 2259
 				{
2173 2260
 					$given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q])));
2174
-					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers']))
2175
-						$incorrectQuestions[] = $q;
2261
+					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) {
2262
+											$incorrectQuestions[] = $q;
2263
+					}
2176 2264
 				}
2177 2265
 			}
2178 2266
 
2179
-			if (!empty($incorrectQuestions))
2180
-				$verification_errors[] = 'wrong_verification_answer';
2267
+			if (!empty($incorrectQuestions)) {
2268
+							$verification_errors[] = 'wrong_verification_answer';
2269
+			}
2181 2270
 		}
2182 2271
 	}
2183 2272
 
2184 2273
 	// Any errors means we refresh potentially.
2185 2274
 	if (!empty($verification_errors))
2186 2275
 	{
2187
-		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors']))
2188
-			$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2276
+		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) {
2277
+					$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2278
+		}
2189 2279
 		// Too many errors?
2190
-		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors'])
2191
-			$force_refresh = true;
2280
+		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) {
2281
+					$force_refresh = true;
2282
+		}
2192 2283
 
2193 2284
 		// Keep a track of these.
2194 2285
 		$_SESSION[$verificationOptions['id'] . '_vv']['errors']++;
@@ -2221,8 +2312,9 @@  discard block
 block discarded – undo
2221 2312
 			// Are we overriding the range?
2222 2313
 			$character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range'];
2223 2314
 
2224
-			for ($i = 0; $i < 6; $i++)
2225
-				$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2315
+			for ($i = 0; $i < 6; $i++) {
2316
+							$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2317
+			}
2226 2318
 		}
2227 2319
 
2228 2320
 		// Getting some new questions?
@@ -2230,8 +2322,9 @@  discard block
 block discarded – undo
2230 2322
 		{
2231 2323
 			// Attempt to try the current page's language, followed by the user's preference, followed by the site default.
2232 2324
 			$possible_langs = array();
2233
-			if (isset($_SESSION['language']))
2234
-				$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2325
+			if (isset($_SESSION['language'])) {
2326
+							$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2327
+			}
2235 2328
 			if (!empty($user_info['language']));
2236 2329
 			$possible_langs[] = $user_info['language'];
2237 2330
 			$possible_langs[] = $language;
@@ -2250,8 +2343,7 @@  discard block
 block discarded – undo
2250 2343
 				}
2251 2344
 			}
2252 2345
 		}
2253
-	}
2254
-	else
2346
+	} else
2255 2347
 	{
2256 2348
 		// Same questions as before.
2257 2349
 		$questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array();
@@ -2261,8 +2353,9 @@  discard block
 block discarded – undo
2261 2353
 	// If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway.
2262 2354
 	if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2263 2355
 	{
2264
-		if (!isset($context['html_headers']))
2265
-			$context['html_headers'] = '';
2356
+		if (!isset($context['html_headers'])) {
2357
+					$context['html_headers'] = '';
2358
+		}
2266 2359
 		$context['html_headers'] .= '<style>.vv_special { display:none; }</style>';
2267 2360
 	}
2268 2361
 
@@ -2288,11 +2381,13 @@  discard block
 block discarded – undo
2288 2381
 	$_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1;
2289 2382
 
2290 2383
 	// Return errors if we have them.
2291
-	if (!empty($verification_errors))
2292
-		return $verification_errors;
2384
+	if (!empty($verification_errors)) {
2385
+			return $verification_errors;
2386
+	}
2293 2387
 	// If we had a test that one, make a note.
2294
-	elseif ($do_test)
2295
-		$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2388
+	elseif ($do_test) {
2389
+			$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2390
+	}
2296 2391
 
2297 2392
 	// Say that everything went well chaps.
2298 2393
 	return true;
@@ -2317,8 +2412,9 @@  discard block
 block discarded – undo
2317 2412
 	call_integration_hook('integrate_autosuggest', array(&$searchTypes));
2318 2413
 
2319 2414
 	// If we're just checking the callback function is registered return true or false.
2320
-	if ($checkRegistered != null)
2321
-		return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2415
+	if ($checkRegistered != null) {
2416
+			return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2417
+	}
2322 2418
 
2323 2419
 	checkSession('get');
2324 2420
 	loadTemplate('Xml');
@@ -2469,24 +2565,27 @@  discard block
 block discarded – undo
2469 2565
 		foreach ($possible_versions as $ver)
2470 2566
 		{
2471 2567
 			$ver = trim($ver);
2472
-			if (strpos($ver, 'SMF') === 0)
2473
-				$versions[] = $ver;
2568
+			if (strpos($ver, 'SMF') === 0) {
2569
+							$versions[] = $ver;
2570
+			}
2474 2571
 		}
2475 2572
 	}
2476 2573
 	$smcFunc['db_free_result']($request);
2477 2574
 
2478 2575
 	// Just in case we don't have ANYthing.
2479
-	if (empty($versions))
2480
-		$versions = array('SMF 2.0');
2576
+	if (empty($versions)) {
2577
+			$versions = array('SMF 2.0');
2578
+	}
2481 2579
 
2482
-	foreach ($versions as $id => $version)
2483
-		if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2580
+	foreach ($versions as $id => $version) {
2581
+			if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2484 2582
 			$xml_data['items']['children'][] = array(
2485 2583
 				'attributes' => array(
2486 2584
 					'id' => $id,
2487 2585
 				),
2488 2586
 				'value' => $version,
2489 2587
 			);
2588
+	}
2490 2589
 
2491 2590
 	return $xml_data;
2492 2591
 }
Please login to merge, or discard this patch.
Sources/Packages.php 1 patch
Braces   +599 added lines, -484 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * This is the notoriously defunct package manager..... :/.
@@ -57,10 +58,11 @@  discard block
 block discarded – undo
57 58
 	);
58 59
 
59 60
 	// Work out exactly who it is we are calling.
60
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
61
-		$context['sub_action'] = $_REQUEST['sa'];
62
-	else
63
-		$context['sub_action'] = 'browse';
61
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
62
+			$context['sub_action'] = $_REQUEST['sa'];
63
+	} else {
64
+			$context['sub_action'] = 'browse';
65
+	}
64 66
 
65 67
 	// Set up some tabs...
66 68
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -82,8 +84,9 @@  discard block
 block discarded – undo
82 84
 		),
83 85
 	);
84 86
 
85
-	if ($context['sub_action'] == 'browse')
86
-		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
87
+	if ($context['sub_action'] == 'browse') {
88
+			loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
89
+	}
87 90
 
88 91
 	call_integration_hook('integrate_manage_packages', array(&$subActions));
89 92
 
@@ -99,8 +102,9 @@  discard block
 block discarded – undo
99 102
 	global $boarddir, $txt, $context, $scripturl, $sourcedir, $packagesdir, $modSettings, $smcFunc, $settings;
100 103
 
101 104
 	// You have to specify a file!!
102
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
103
-		redirectexit('action=admin;area=packages');
105
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
106
+			redirectexit('action=admin;area=packages');
107
+	}
104 108
 	$context['filename'] = preg_replace('~[\.]+~', '.', $_REQUEST['package']);
105 109
 
106 110
 	// Do we have an existing id, for uninstalls and the like.
@@ -112,8 +116,9 @@  discard block
 block discarded – undo
112 116
 	create_chmod_control();
113 117
 
114 118
 	// Make sure temp directory exists and is empty.
115
-	if (file_exists($packagesdir . '/temp'))
116
-		deltree($packagesdir . '/temp', false);
119
+	if (file_exists($packagesdir . '/temp')) {
120
+			deltree($packagesdir . '/temp', false);
121
+	}
117 122
 
118 123
 	if (!mktree($packagesdir . '/temp', 0755))
119 124
 	{
@@ -124,8 +129,9 @@  discard block
 block discarded – undo
124 129
 			create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'], 'crash_on_error' => true));
125 130
 
126 131
 			deltree($packagesdir . '/temp', false);
127
-			if (!mktree($packagesdir . '/temp', 0777))
128
-				fatal_lang_error('package_cant_download', false);
132
+			if (!mktree($packagesdir . '/temp', 0777)) {
133
+							fatal_lang_error('package_cant_download', false);
134
+			}
129 135
 		}
130 136
 	}
131 137
 
@@ -151,25 +157,26 @@  discard block
 block discarded – undo
151 157
 	{
152 158
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
153 159
 
154
-		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml'))
155
-			foreach ($context['extracted_files'] as $file)
160
+		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) {
161
+					foreach ($context['extracted_files'] as $file)
156 162
 				if (basename($file['filename']) == 'package-info.xml')
157 163
 				{
158 164
 					$context['base_path'] = dirname($file['filename']) . '/';
165
+		}
159 166
 					break;
160 167
 				}
161 168
 
162
-		if (!isset($context['base_path']))
163
-			$context['base_path'] = '';
164
-	}
165
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
169
+		if (!isset($context['base_path'])) {
170
+					$context['base_path'] = '';
171
+		}
172
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
166 173
 	{
167 174
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
168 175
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
169 176
 		$context['base_path'] = '';
177
+	} else {
178
+			fatal_lang_error('no_access', false);
170 179
 	}
171
-	else
172
-		fatal_lang_error('no_access', false);
173 180
 
174 181
 	// Load up any custom themes we may want to install into...
175 182
 	$request = $smcFunc['db_query']('', '
@@ -185,15 +192,17 @@  discard block
 block discarded – undo
185 192
 		)
186 193
 	);
187 194
 	$theme_paths = array();
188
-	while ($row = $smcFunc['db_fetch_assoc']($request))
189
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
195
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
196
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
197
+	}
190 198
 	$smcFunc['db_free_result']($request);
191 199
 
192 200
 	// Get the package info...
193 201
 	$packageInfo = getPackageInfo($context['filename']);
194 202
 
195
-	if (!is_array($packageInfo))
196
-		fatal_lang_error($packageInfo);
203
+	if (!is_array($packageInfo)) {
204
+			fatal_lang_error($packageInfo);
205
+	}
197 206
 
198 207
 	$packageInfo['filename'] = $context['filename'];
199 208
 	$context['package_name'] = isset($packageInfo['name']) ? $packageInfo['name'] : $context['filename'];
@@ -227,18 +236,19 @@  discard block
 block discarded – undo
227 236
 	$smcFunc['db_free_result']($request);
228 237
 
229 238
 	$context['database_changes'] = array();
230
-	if (isset($packageInfo['uninstall']['database']))
231
-		$context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
232
-	elseif (!empty($db_changes))
239
+	if (isset($packageInfo['uninstall']['database'])) {
240
+			$context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
241
+	} elseif (!empty($db_changes))
233 242
 	{
234 243
 		foreach ($db_changes as $change)
235 244
 		{
236
-			if (isset($change[2]) && isset($txt['package_db_' . $change[0]]))
237
-				$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
238
-			elseif (isset($txt['package_db_' . $change[0]]))
239
-				$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
240
-			else
241
-				$context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
245
+			if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) {
246
+							$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
247
+			} elseif (isset($txt['package_db_' . $change[0]])) {
248
+							$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
249
+			} else {
250
+							$context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
251
+			}
242 252
 		}
243 253
 	}
244 254
 
@@ -265,31 +275,33 @@  discard block
 block discarded – undo
265 275
 		$context['themes_locked'] = true;
266 276
 
267 277
 		// Only let them uninstall themes it was installed into.
268
-		foreach ($theme_paths as $id => $data)
269
-			if ($id != 1 && !in_array($id, $old_themes))
278
+		foreach ($theme_paths as $id => $data) {
279
+					if ($id != 1 && !in_array($id, $old_themes))
270 280
 				unset($theme_paths[$id]);
271
-	}
272
-	elseif (isset($old_version) && $old_version != $packageInfo['version'])
281
+		}
282
+	} elseif (isset($old_version) && $old_version != $packageInfo['version'])
273 283
 	{
274 284
 		// Look for an upgrade...
275 285
 		$actions = parsePackageInfo($packageInfo['xml'], true, 'upgrade', $old_version);
276 286
 
277 287
 		// There was no upgrade....
278
-		if (empty($actions))
279
-			$context['is_installed'] = true;
280
-		else
288
+		if (empty($actions)) {
289
+					$context['is_installed'] = true;
290
+		} else
281 291
 		{
282 292
 			// Otherwise they can only upgrade themes from the first time around.
283
-			foreach ($theme_paths as $id => $data)
284
-				if ($id != 1 && !in_array($id, $old_themes))
293
+			foreach ($theme_paths as $id => $data) {
294
+							if ($id != 1 && !in_array($id, $old_themes))
285 295
 					unset($theme_paths[$id]);
296
+			}
286 297
 		}
298
+	} elseif (isset($old_version) && $old_version == $packageInfo['version']) {
299
+			$context['is_installed'] = true;
287 300
 	}
288
-	elseif (isset($old_version) && $old_version == $packageInfo['version'])
289
-		$context['is_installed'] = true;
290 301
 
291
-	if (!isset($old_version) || $context['is_installed'])
292
-		$actions = parsePackageInfo($packageInfo['xml'], true, 'install');
302
+	if (!isset($old_version) || $context['is_installed']) {
303
+			$actions = parsePackageInfo($packageInfo['xml'], true, 'install');
304
+	}
293 305
 
294 306
 	$context['actions'] = array();
295 307
 	$context['ftp_needed'] = false;
@@ -297,8 +309,9 @@  discard block
 block discarded – undo
297 309
 	$chmod_files = array();
298 310
 
299 311
 	// no actions found, return so we can display an error
300
-	if (empty($actions))
301
-		return;
312
+	if (empty($actions)) {
313
+			return;
314
+	}
302 315
 
303 316
 	// This will hold data about anything that can be installed in other themes.
304 317
 	$themeFinds = array(
@@ -317,14 +330,14 @@  discard block
 block discarded – undo
317 330
 		{
318 331
 			$chmod_files[] = $action['filename'];
319 332
 			continue;
320
-		}
321
-		elseif ($action['type'] == 'readme' || $action['type'] == 'license')
333
+		} elseif ($action['type'] == 'readme' || $action['type'] == 'license')
322 334
 		{
323 335
 			$type = 'package_' . $action['type'];
324
-			if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
325
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r"));
326
-			elseif (file_exists($action['filename']))
327
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
336
+			if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
337
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r"));
338
+			} elseif (file_exists($action['filename'])) {
339
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
340
+			}
328 341
 
329 342
 			if (!empty($action['parse_bbc']))
330 343
 			{
@@ -332,24 +345,24 @@  discard block
 block discarded – undo
332 345
 				$context[$type] = preg_replace('~\[[/]?html\]~i', '', $context[$type]);
333 346
 				preparsecode($context[$type]);
334 347
 				$context[$type] = parse_bbc($context[$type]);
348
+			} else {
349
+							$context[$type] = nl2br($context[$type]);
335 350
 			}
336
-			else
337
-				$context[$type] = nl2br($context[$type]);
338 351
 
339 352
 			continue;
340 353
 		}
341 354
 		// Don't show redirects.
342
-		elseif ($action['type'] == 'redirect')
343
-			continue;
344
-		elseif ($action['type'] == 'error')
355
+		elseif ($action['type'] == 'redirect') {
356
+					continue;
357
+		} elseif ($action['type'] == 'error')
345 358
 		{
346 359
 			$context['has_failure'] = true;
347
-			if (isset($action['error_msg']) && isset($action['error_var']))
348
-				$context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']);
349
-			elseif (isset($action['error_msg']))
350
-				$context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg'];
351
-		}
352
-		elseif ($action['type'] == 'modification')
360
+			if (isset($action['error_msg']) && isset($action['error_var'])) {
361
+							$context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']);
362
+			} elseif (isset($action['error_msg'])) {
363
+							$context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg'];
364
+			}
365
+		} elseif ($action['type'] == 'modification')
353 366
 		{
354 367
 			if (!file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
355 368
 			{
@@ -361,52 +374,54 @@  discard block
 block discarded – undo
361 374
 					'description' => $txt['package_action_missing'],
362 375
 					'failed' => true,
363 376
 				);
364
-			}
365
-			else
377
+			} else
366 378
 			{
367 379
 
368
-				if ($action['boardmod'])
369
-					$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
370
-				else
371
-					$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
380
+				if ($action['boardmod']) {
381
+									$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
382
+				} else {
383
+									$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
384
+				}
372 385
 
373
-				if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-')
374
-					$mod_actions[0]['filename'] = $action['filename'];
386
+				if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') {
387
+									$mod_actions[0]['filename'] = $action['filename'];
388
+				}
375 389
 
376 390
 				foreach ($mod_actions as $key => $mod_action)
377 391
 				{
378 392
 					// Lets get the last section of the file name.
379
-					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php')
380
-						$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
381
-					elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches))
382
-						$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
383
-					else
384
-						$actual_filename = $key;
385
-
386
-					if ($mod_action['type'] == 'opened')
387
-						$failed = false;
388
-					elseif ($mod_action['type'] == 'failure')
393
+					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
394
+											$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
395
+					} elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) {
396
+											$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
397
+					} else {
398
+											$actual_filename = $key;
399
+					}
400
+
401
+					if ($mod_action['type'] == 'opened') {
402
+											$failed = false;
403
+					} elseif ($mod_action['type'] == 'failure')
389 404
 					{
390
-						if (empty($mod_action['is_custom']))
391
-							$context['has_failure'] = true;
405
+						if (empty($mod_action['is_custom'])) {
406
+													$context['has_failure'] = true;
407
+						}
392 408
 						$failed = true;
393
-					}
394
-					elseif ($mod_action['type'] == 'chmod')
409
+					} elseif ($mod_action['type'] == 'chmod')
395 410
 					{
396 411
 						$chmod_files[] = $mod_action['filename'];
397
-					}
398
-					elseif ($mod_action['type'] == 'saved')
412
+					} elseif ($mod_action['type'] == 'saved')
399 413
 					{
400 414
 						if (!empty($mod_action['is_custom']))
401 415
 						{
402
-							if (!isset($context['theme_actions'][$mod_action['is_custom']]))
403
-								$context['theme_actions'][$mod_action['is_custom']] = array(
416
+							if (!isset($context['theme_actions'][$mod_action['is_custom']])) {
417
+															$context['theme_actions'][$mod_action['is_custom']] = array(
404 418
 									'name' => $theme_paths[$mod_action['is_custom']]['name'],
405 419
 									'actions' => array(),
406 420
 									'has_failure' => $failed,
407 421
 								);
408
-							else
409
-								$context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
422
+							} else {
423
+															$context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
424
+							}
410 425
 
411 426
 							$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename] = array(
412 427
 								'type' => $txt['execute_modification'],
@@ -414,8 +429,7 @@  discard block
 block discarded – undo
414 429
 								'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'],
415 430
 								'failed' => $failed,
416 431
 							);
417
-						}
418
-						elseif (!isset($context['actions'][$actual_filename]))
432
+						} elseif (!isset($context['actions'][$actual_filename]))
419 433
 						{
420 434
 							$context['actions'][$actual_filename] = array(
421 435
 								'type' => $txt['execute_modification'],
@@ -423,22 +437,19 @@  discard block
 block discarded – undo
423 437
 								'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'],
424 438
 								'failed' => $failed,
425 439
 							);
426
-						}
427
-						else
440
+						} else
428 441
 						{
429 442
 								$context['actions'][$actual_filename]['failed'] |= $failed;
430 443
 								$context['actions'][$actual_filename]['description'] = $context['actions'][$actual_filename]['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'];
431 444
 						}
432
-					}
433
-					elseif ($mod_action['type'] == 'skipping')
445
+					} elseif ($mod_action['type'] == 'skipping')
434 446
 					{
435 447
 						$context['actions'][$actual_filename] = array(
436 448
 							'type' => $txt['execute_modification'],
437 449
 							'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
438 450
 							'description' => $txt['package_action_skipping']
439 451
 						);
440
-					}
441
-					elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom']))
452
+					} elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom']))
442 453
 					{
443 454
 						$context['has_failure'] = true;
444 455
 						$context['actions'][$actual_filename] = array(
@@ -447,32 +458,33 @@  discard block
 block discarded – undo
447 458
 							'description' => $txt['package_action_missing'],
448 459
 							'failed' => true,
449 460
 						);
450
-					}
451
-					elseif ($mod_action['type'] == 'error')
452
-						$context['actions'][$actual_filename] = array(
461
+					} elseif ($mod_action['type'] == 'error') {
462
+											$context['actions'][$actual_filename] = array(
453 463
 							'type' => $txt['execute_modification'],
454 464
 							'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
455 465
 							'description' => $txt['package_action_error'],
456 466
 							'failed' => true,
457 467
 						);
468
+					}
458 469
 				}
459 470
 
460 471
 				// We need to loop again just to get the operations down correctly.
461 472
 				foreach ($mod_actions as $operation_key => $mod_action)
462 473
 				{
463 474
 					// Lets get the last section of the file name.
464
-					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php')
465
-						$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
466
-					elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches))
467
-						$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
468
-					else
469
-						$actual_filename = $key;
475
+					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
476
+											$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
477
+					} elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) {
478
+											$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
479
+					} else {
480
+											$actual_filename = $key;
481
+					}
470 482
 
471 483
 					// We just need it for actual parse changes.
472 484
 					if (!in_array($mod_action['type'], array('error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod')))
473 485
 					{
474
-						if (empty($mod_action['is_custom']))
475
-							$context['actions'][$actual_filename]['operations'][] = array(
486
+						if (empty($mod_action['is_custom'])) {
487
+													$context['actions'][$actual_filename]['operations'][] = array(
476 488
 								'type' => $txt['execute_modification'],
477 489
 								'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
478 490
 								'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'],
@@ -483,10 +495,11 @@  discard block
 block discarded – undo
483 495
 								'failed' => $mod_action['failed'],
484 496
 								'ignore_failure' => !empty($mod_action['ignore_failure']),
485 497
 							);
498
+						}
486 499
 
487 500
 						// Themes are under the saved type.
488
-						if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']]))
489
-							$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array(
501
+						if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) {
502
+													$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array(
490 503
 								'type' => $txt['execute_modification'],
491 504
 								'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
492 505
 								'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'],
@@ -497,59 +510,55 @@  discard block
 block discarded – undo
497 510
 								'failed' => $mod_action['failed'],
498 511
 								'ignore_failure' => !empty($mod_action['ignore_failure']),
499 512
 							);
513
+						}
500 514
 					}
501 515
 				}
502 516
 			}
503
-		}
504
-		elseif ($action['type'] == 'code')
517
+		} elseif ($action['type'] == 'code')
505 518
 		{
506 519
 			$thisAction = array(
507 520
 				'type' => $txt['execute_code'],
508 521
 				'action' => $smcFunc['htmlspecialchars']($action['filename']),
509 522
 			);
510
-		}
511
-		elseif ($action['type'] == 'database')
523
+		} elseif ($action['type'] == 'database')
512 524
 		{
513 525
 			$thisAction = array(
514 526
 				'type' => $txt['execute_database_changes'],
515 527
 				'action' => $smcFunc['htmlspecialchars']($action['filename']),
516 528
 			);
517
-		}
518
-		elseif (in_array($action['type'], array('create-dir', 'create-file')))
529
+		} elseif (in_array($action['type'], array('create-dir', 'create-file')))
519 530
 		{
520 531
 			$thisAction = array(
521 532
 				'type' => $txt['package_create'] . ' ' . ($action['type'] == 'create-dir' ? $txt['package_tree'] : $txt['package_file']),
522 533
 				'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.')))
523 534
 			);
524
-		}
525
-		elseif ($action['type'] == 'hook')
535
+		} elseif ($action['type'] == 'hook')
526 536
 		{
527 537
 			$action['description'] = !isset($action['hook'], $action['function']) ? $txt['package_action_failure'] : $txt['package_action_success'];
528 538
 
529
-			if (!isset($action['hook'], $action['function']))
530
-				$context['has_failure'] = true;
539
+			if (!isset($action['hook'], $action['function'])) {
540
+							$context['has_failure'] = true;
541
+			}
531 542
 
532 543
 			$thisAction = array(
533 544
 				'type' => $action['reverse'] ? $txt['execute_hook_remove'] : $txt['execute_hook_add'],
534 545
 				'action' => sprintf($txt['execute_hook_action' . ($action['reverse'] ? '_inverse' : '')], $smcFunc['htmlspecialchars']($action['hook'])),
535 546
 			);
536
-		}
537
-		elseif ($action['type'] == 'credits')
547
+		} elseif ($action['type'] == 'credits')
538 548
 		{
539 549
 			$thisAction = array(
540 550
 				'type' => $txt['execute_credits_add'],
541 551
 				'action' => sprintf($txt['execute_credits_action'], $smcFunc['htmlspecialchars']($action['title'])),
542 552
 			);
543
-		}
544
-		elseif ($action['type'] == 'requires')
553
+		} elseif ($action['type'] == 'requires')
545 554
 		{
546 555
 			$installed = false;
547 556
 			$version = true;
548 557
 
549 558
 			// package missing required values?
550
-			if (!isset($action['id']))
551
-				$context['has_failure'] = true;
552
-			else
559
+			if (!isset($action['id'])) {
560
+							$context['has_failure'] = true;
561
+			} else
553 562
 			{
554 563
 				// See if this dependancy is installed
555 564
 				$request = $smcFunc['db_query']('', '
@@ -565,8 +574,9 @@  discard block
 block discarded – undo
565 574
 					)
566 575
 				);
567 576
 				$installed = ($smcFunc['db_num_rows']($request) !== 0);
568
-				if ($installed)
569
-					list ($version) = $smcFunc['db_fetch_row']($request);
577
+				if ($installed) {
578
+									list ($version) = $smcFunc['db_fetch_row']($request);
579
+				}
570 580
 				$smcFunc['db_free_result']($request);
571 581
 
572 582
 				// do a version level check (if requested) in the most basic way
@@ -581,8 +591,7 @@  discard block
 block discarded – undo
581 591
 				'type' => $txt['package_requires'],
582 592
 				'action' => $txt['package_check_for'] . ' ' . $action['id'] . (isset($action['version']) ? (' / ' . ($version ? $action['version'] : '<span class="error">' . $action['version'] . '</span>')) : ''),
583 593
 			);
584
-		}
585
-		elseif (in_array($action['type'], array('require-dir', 'require-file')))
594
+		} elseif (in_array($action['type'], array('require-dir', 'require-file')))
586 595
 		{
587 596
 			// Do this one...
588 597
 			$thisAction = array(
@@ -596,26 +605,29 @@  discard block
 block discarded – undo
596 605
 				// Is the action already stated?
597 606
 				$theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto';
598 607
 				// If it's not auto do we think we have something we can act upon?
599
-				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir')))
600
-					$theme_action = '';
608
+				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
609
+									$theme_action = '';
610
+				}
601 611
 				// ... or if it's auto do we even want to do anything?
602
-				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir')
603
-					$theme_action = '';
612
+				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
613
+									$theme_action = '';
614
+				}
604 615
 
605 616
 				// So, we still want to do something?
606
-				if ($theme_action != '')
607
-					$themeFinds['candidates'][] = $action;
617
+				if ($theme_action != '') {
618
+									$themeFinds['candidates'][] = $action;
619
+				}
608 620
 				// Otherwise is this is going into another theme record it.
609
-				elseif ($matches[1] == 'themes_dir')
610
-					$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
621
+				elseif ($matches[1] == 'themes_dir') {
622
+									$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
623
+				}
611 624
 			}
612
-		}
613
-		elseif (in_array($action['type'], array('move-dir', 'move-file')))
614
-			$thisAction = array(
625
+		} elseif (in_array($action['type'], array('move-dir', 'move-file'))) {
626
+					$thisAction = array(
615 627
 				'type' => $txt['package_move'] . ' ' . ($action['type'] == 'move-dir' ? $txt['package_tree'] : $txt['package_file']),
616 628
 				'action' => $smcFunc['htmlspecialchars'](strtr($action['source'], array($boarddir => '.'))) . ' => ' . $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.')))
617 629
 			);
618
-		elseif (in_array($action['type'], array('remove-dir', 'remove-file')))
630
+		} elseif (in_array($action['type'], array('remove-dir', 'remove-file')))
619 631
 		{
620 632
 			$thisAction = array(
621 633
 				'type' => $txt['package_delete'] . ' ' . ($action['type'] == 'remove-dir' ? $txt['package_tree'] : $txt['package_file']),
@@ -631,30 +643,36 @@  discard block
 block discarded – undo
631 643
 				$action['unparsed_destination'] = $action['unparsed_filename'];
632 644
 
633 645
 				// If it's not auto do we think we have something we can act upon?
634
-				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir')))
635
-					$theme_action = '';
646
+				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
647
+									$theme_action = '';
648
+				}
636 649
 				// ... or if it's auto do we even want to do anything?
637
-				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir')
638
-					$theme_action = '';
650
+				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
651
+									$theme_action = '';
652
+				}
639 653
 
640 654
 				// So, we still want to do something?
641
-				if ($theme_action != '')
642
-					$themeFinds['candidates'][] = $action;
655
+				if ($theme_action != '') {
656
+									$themeFinds['candidates'][] = $action;
657
+				}
643 658
 				// Otherwise is this is going into another theme record it.
644
-				elseif ($matches[1] == 'themes_dir')
645
-					$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
659
+				elseif ($matches[1] == 'themes_dir') {
660
+									$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
661
+				}
646 662
 			}
647 663
 		}
648 664
 
649
-		if (empty($thisAction))
650
-			continue;
665
+		if (empty($thisAction)) {
666
+					continue;
667
+		}
651 668
 
652 669
 		if (!in_array($action['type'], array('hook', 'credits')))
653 670
 		{
654
-			if ($context['uninstalling'])
655
-				$file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
656
-			else
657
-				$file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
671
+			if ($context['uninstalling']) {
672
+							$file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
673
+			} else {
674
+							$file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
675
+			}
658 676
 		}
659 677
 
660 678
 		// Don't fail if a file/directory we're trying to create doesn't exist...
@@ -669,8 +687,9 @@  discard block
 block discarded – undo
669 687
 		}
670 688
 
671 689
 		// @todo None given?
672
-		if (empty($thisAction['description']))
673
-			$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
690
+		if (empty($thisAction['description'])) {
691
+					$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
692
+		}
674 693
 
675 694
 		$context['actions'][] = $thisAction;
676 695
 	}
@@ -683,18 +702,21 @@  discard block
 block discarded – undo
683 702
 			// Get the part of the file we'll be dealing with.
684 703
 			preg_match('~^\$(languagedir|languages_dir|imagesdir|themedir)(\\|/)*(.+)*~i', $action_data['unparsed_destination'], $matches);
685 704
 
686
-			if ($matches[1] == 'imagesdir')
687
-				$path = '/' . basename($settings['default_images_url']);
688
-			elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir')
689
-				$path = '/languages';
690
-			else
691
-				$path = '';
705
+			if ($matches[1] == 'imagesdir') {
706
+							$path = '/' . basename($settings['default_images_url']);
707
+			} elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') {
708
+							$path = '/languages';
709
+			} else {
710
+							$path = '';
711
+			}
692 712
 
693
-			if (!empty($matches[3]))
694
-				$path .= $matches[3];
713
+			if (!empty($matches[3])) {
714
+							$path .= $matches[3];
715
+			}
695 716
 
696
-			if (!$context['uninstalling'])
697
-				$path .= '/' . basename($action_data['filename']);
717
+			if (!$context['uninstalling']) {
718
+							$path .= '/' . basename($action_data['filename']);
719
+			}
698 720
 
699 721
 			// Loop through each custom theme to note it's candidacy!
700 722
 			foreach ($theme_paths as $id => $theme_data)
@@ -710,36 +732,40 @@  discard block
 block discarded – undo
710 732
 						if (!mktree(dirname($real_path), false))
711 733
 						{
712 734
 							$temp = dirname($real_path);
713
-							while (!file_exists($temp) && strlen($temp) > 1)
714
-								$temp = dirname($temp);
735
+							while (!file_exists($temp) && strlen($temp) > 1) {
736
+															$temp = dirname($temp);
737
+							}
715 738
 							$chmod_files[] = $temp;
716 739
 						}
717 740
 
718
-						if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path))))
719
-							$chmod_files[] = $real_path;
741
+						if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) {
742
+													$chmod_files[] = $real_path;
743
+						}
720 744
 
721
-						if (!isset($context['theme_actions'][$id]))
722
-							$context['theme_actions'][$id] = array(
745
+						if (!isset($context['theme_actions'][$id])) {
746
+													$context['theme_actions'][$id] = array(
723 747
 								'name' => $theme_data['name'],
724 748
 								'actions' => array(),
725 749
 							);
750
+						}
726 751
 
727
-						if ($context['uninstalling'])
728
-							$context['theme_actions'][$id]['actions'][] = array(
752
+						if ($context['uninstalling']) {
753
+													$context['theme_actions'][$id]['actions'][] = array(
729 754
 								'type' => $txt['package_delete'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']),
730 755
 								'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')),
731 756
 								'description' => '',
732 757
 								'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['filename'], 'future' => $real_path, 'id' => $id))),
733 758
 								'not_mod' => true,
734 759
 							);
735
-						else
736
-							$context['theme_actions'][$id]['actions'][] = array(
760
+						} else {
761
+													$context['theme_actions'][$id]['actions'][] = array(
737 762
 								'type' => $txt['package_extract'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']),
738 763
 								'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')),
739 764
 								'description' => '',
740 765
 								'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['destination'], 'future' => $real_path, 'id' => $id))),
741 766
 								'not_mod' => true,
742 767
 							);
768
+						}
743 769
 					}
744 770
 				}
745 771
 			}
@@ -749,8 +775,9 @@  discard block
 block discarded – undo
749 775
 	// Trash the cache... which will also check permissions for us!
750 776
 	package_flush_cache(true);
751 777
 
752
-	if (file_exists($packagesdir . '/temp'))
753
-		deltree($packagesdir . '/temp');
778
+	if (file_exists($packagesdir . '/temp')) {
779
+			deltree($packagesdir . '/temp');
780
+	}
754 781
 
755 782
 	if (!empty($chmod_files))
756 783
 	{
@@ -775,8 +802,9 @@  discard block
 block discarded – undo
775 802
 	checkSession();
776 803
 
777 804
 	// If there's no file, what are we installing?
778
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
779
-		redirectexit('action=admin;area=packages');
805
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
806
+			redirectexit('action=admin;area=packages');
807
+	}
780 808
 	$context['filename'] = $_REQUEST['package'];
781 809
 
782 810
 	// If this is an uninstall, we'll have an id.
@@ -797,51 +825,55 @@  discard block
 block discarded – undo
797 825
 
798 826
 	$context['sub_template'] = 'extract_package';
799 827
 
800
-	if (!file_exists($packagesdir . '/' . $context['filename']))
801
-		fatal_lang_error('package_no_file', false);
828
+	if (!file_exists($packagesdir . '/' . $context['filename'])) {
829
+			fatal_lang_error('package_no_file', false);
830
+	}
802 831
 
803 832
 	// Load up the package FTP information?
804 833
 	create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package']));
805 834
 
806 835
 	// Make sure temp directory exists and is empty!
807
-	if (file_exists($packagesdir . '/temp'))
808
-		deltree($packagesdir . '/temp', false);
809
-	else
810
-		mktree($packagesdir . '/temp', 0777);
836
+	if (file_exists($packagesdir . '/temp')) {
837
+			deltree($packagesdir . '/temp', false);
838
+	} else {
839
+			mktree($packagesdir . '/temp', 0777);
840
+	}
811 841
 
812 842
 	// Let the unpacker do the work.
813 843
 	if (is_file($packagesdir . '/' . $context['filename']))
814 844
 	{
815 845
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
816 846
 
817
-		if (!file_exists($packagesdir . '/temp/package-info.xml'))
818
-			foreach ($context['extracted_files'] as $file)
847
+		if (!file_exists($packagesdir . '/temp/package-info.xml')) {
848
+					foreach ($context['extracted_files'] as $file)
819 849
 				if (basename($file['filename']) == 'package-info.xml')
820 850
 				{
821 851
 					$context['base_path'] = dirname($file['filename']) . '/';
852
+		}
822 853
 					break;
823 854
 				}
824 855
 
825
-		if (!isset($context['base_path']))
826
-			$context['base_path'] = '';
827
-	}
828
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
856
+		if (!isset($context['base_path'])) {
857
+					$context['base_path'] = '';
858
+		}
859
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
829 860
 	{
830 861
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
831 862
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
832 863
 		$context['base_path'] = '';
864
+	} else {
865
+			fatal_lang_error('no_access', false);
833 866
 	}
834
-	else
835
-		fatal_lang_error('no_access', false);
836 867
 
837 868
 	// Are we installing this into any custom themes?
838 869
 	$custom_themes = array(1);
839 870
 	$known_themes = explode(',', $modSettings['knownThemes']);
840 871
 	if (!empty($_POST['custom_theme']))
841 872
 	{
842
-		foreach ($_POST['custom_theme'] as $tid)
843
-			if (in_array($tid, $known_themes))
873
+		foreach ($_POST['custom_theme'] as $tid) {
874
+					if (in_array($tid, $known_themes))
844 875
 				$custom_themes[] = (int) $tid;
876
+		}
845 877
 	}
846 878
 
847 879
 	// Now load up the paths of the themes that we need to know about.
@@ -858,8 +890,9 @@  discard block
 block discarded – undo
858 890
 	);
859 891
 	$theme_paths = array();
860 892
 	$themes_installed = array(1);
861
-	while ($row = $smcFunc['db_fetch_assoc']($request))
862
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
893
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
894
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
895
+	}
863 896
 	$smcFunc['db_free_result']($request);
864 897
 
865 898
 	// Are there any theme copying that we want to take place?
@@ -871,11 +904,13 @@  discard block
 block discarded – undo
871 904
 	{
872 905
 		foreach ($_POST['theme_changes'] as $change)
873 906
 		{
874
-			if (empty($change))
875
-				continue;
907
+			if (empty($change)) {
908
+							continue;
909
+			}
876 910
 			$theme_data = smf_json_decode(base64_decode($change), true);
877
-			if (empty($theme_data['type']))
878
-				continue;
911
+			if (empty($theme_data['type'])) {
912
+							continue;
913
+			}
879 914
 
880 915
 			$themes_installed[] = $theme_data['id'];
881 916
 			$context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future'];
@@ -884,8 +919,9 @@  discard block
 block discarded – undo
884 919
 
885 920
 	// Get the package info...
886 921
 	$packageInfo = getPackageInfo($context['filename']);
887
-	if (!is_array($packageInfo))
888
-		fatal_lang_error($packageInfo);
922
+	if (!is_array($packageInfo)) {
923
+			fatal_lang_error($packageInfo);
924
+	}
889 925
 
890 926
 	$packageInfo['filename'] = $context['filename'];
891 927
 
@@ -897,8 +933,9 @@  discard block
 block discarded – undo
897 933
 	{
898 934
 		$_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$');
899 935
 		$result = package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.'));
900
-		if (!$result)
901
-			fatal_lang_error('could_not_package_backup', false);
936
+		if (!$result) {
937
+					fatal_lang_error('could_not_package_backup', false);
938
+		}
902 939
 	}
903 940
 
904 941
 	// The mod isn't installed.... unless proven otherwise.
@@ -938,35 +975,38 @@  discard block
 block discarded – undo
938 975
 		$install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall');
939 976
 
940 977
 		// Gadzooks!  There's no uninstaller at all!?
941
-		if (empty($install_log))
942
-			fatal_lang_error('package_uninstall_cannot', false);
978
+		if (empty($install_log)) {
979
+					fatal_lang_error('package_uninstall_cannot', false);
980
+		}
943 981
 
944 982
 		// They can only uninstall from what it was originally installed into.
945
-		foreach ($theme_paths as $id => $data)
946
-			if ($id != 1 && !in_array($id, $old_themes))
983
+		foreach ($theme_paths as $id => $data) {
984
+					if ($id != 1 && !in_array($id, $old_themes))
947 985
 				unset($theme_paths[$id]);
948
-	}
949
-	elseif (isset($old_version) && $old_version != $packageInfo['version'])
986
+		}
987
+	} elseif (isset($old_version) && $old_version != $packageInfo['version'])
950 988
 	{
951 989
 		// Look for an upgrade...
952 990
 		$install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $old_version);
953 991
 
954 992
 		// There was no upgrade....
955
-		if (empty($install_log))
956
-			$context['is_installed'] = true;
957
-		else
993
+		if (empty($install_log)) {
994
+					$context['is_installed'] = true;
995
+		} else
958 996
 		{
959 997
 			// Upgrade previous themes only!
960
-			foreach ($theme_paths as $id => $data)
961
-				if ($id != 1 && !in_array($id, $old_themes))
998
+			foreach ($theme_paths as $id => $data) {
999
+							if ($id != 1 && !in_array($id, $old_themes))
962 1000
 					unset($theme_paths[$id]);
1001
+			}
963 1002
 		}
1003
+	} elseif (isset($old_version) && $old_version == $packageInfo['version']) {
1004
+			$context['is_installed'] = true;
964 1005
 	}
965
-	elseif (isset($old_version) && $old_version == $packageInfo['version'])
966
-		$context['is_installed'] = true;
967 1006
 
968
-	if (!isset($old_version) || $context['is_installed'])
969
-		$install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
1007
+	if (!isset($old_version) || $context['is_installed']) {
1008
+			$install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
1009
+	}
970 1010
 
971 1011
 	$context['install_finished'] = false;
972 1012
 
@@ -983,37 +1023,39 @@  discard block
 block discarded – undo
983 1023
 
984 1024
 			if ($action['type'] == 'modification' && !empty($action['filename']))
985 1025
 			{
986
-				if ($action['boardmod'])
987
-					$mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
988
-				else
989
-					$mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1026
+				if ($action['boardmod']) {
1027
+									$mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1028
+				} else {
1029
+									$mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1030
+				}
990 1031
 
991 1032
 				// Any errors worth noting?
992 1033
 				foreach ($mod_actions as $key => $modAction)
993 1034
 				{
994
-					if ($modAction['type'] == 'failure')
995
-						$failed_steps[] = array(
1035
+					if ($modAction['type'] == 'failure') {
1036
+											$failed_steps[] = array(
996 1037
 							'file' => $modAction['filename'],
997 1038
 							'large_step' => $failed_count,
998 1039
 							'sub_step' => $key,
999 1040
 							'theme' => 1,
1000 1041
 						);
1042
+					}
1001 1043
 
1002 1044
 					// Gather the themes we installed into.
1003
-					if (!empty($modAction['is_custom']))
1004
-						$themes_installed[] = $modAction['is_custom'];
1045
+					if (!empty($modAction['is_custom'])) {
1046
+											$themes_installed[] = $modAction['is_custom'];
1047
+					}
1005 1048
 				}
1006
-			}
1007
-			elseif ($action['type'] == 'code' && !empty($action['filename']))
1049
+			} elseif ($action['type'] == 'code' && !empty($action['filename']))
1008 1050
 			{
1009 1051
 				// This is just here as reference for what is available.
1010 1052
 				global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc;
1011 1053
 
1012 1054
 				// Now include the file and be done with it ;).
1013
-				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
1014
-					require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1015
-			}
1016
-			elseif ($action['type'] == 'credits')
1055
+				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
1056
+									require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1057
+				}
1058
+			} elseif ($action['type'] == 'credits')
1017 1059
 			{
1018 1060
 				// Time to build the billboard
1019 1061
 				$credits_tag = array(
@@ -1023,13 +1065,13 @@  discard block
 block discarded – undo
1023 1065
 					'copyright' => $action['copyright'],
1024 1066
 					'title' => $action['title'],
1025 1067
 				);
1026
-			}
1027
-			elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function']))
1068
+			} elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function']))
1028 1069
 			{
1029
-				if ($action['reverse'])
1030
-					remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1031
-				else
1032
-					add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1070
+				if ($action['reverse']) {
1071
+									remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1072
+				} else {
1073
+									add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1074
+				}
1033 1075
 			}
1034 1076
 			// Only do the database changes on uninstall if requested.
1035 1077
 			elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes'])))
@@ -1042,8 +1084,9 @@  discard block
 block discarded – undo
1042 1084
 				db_extend('packages');
1043 1085
 
1044 1086
 				// Let the file work its magic ;)
1045
-				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
1046
-					require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1087
+				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
1088
+									require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1089
+				}
1047 1090
 			}
1048 1091
 			// Handle a redirect...
1049 1092
 			elseif ($action['type'] == 'redirect' && !empty($action['redirect_url']))
@@ -1125,8 +1168,9 @@  discard block
 block discarded – undo
1125 1168
 			reloadSettings();
1126 1169
 
1127 1170
 			// Any db changes from older version?
1128
-			if (!empty($old_db_changes))
1129
-				$db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log);
1171
+			if (!empty($old_db_changes)) {
1172
+							$db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log);
1173
+			}
1130 1174
 
1131 1175
 			// If there are some database changes we might want to remove then filter them out.
1132 1176
 			if (!empty($db_package_log))
@@ -1142,22 +1186,24 @@  discard block
 block discarded – undo
1142 1186
 				 */
1143 1187
 				function sort_table_first($a, $b)
1144 1188
 				{
1145
-					if ($a[0] == $b[0])
1146
-						return 0;
1189
+					if ($a[0] == $b[0]) {
1190
+											return 0;
1191
+					}
1147 1192
 					return $a[0] == 'remove_table' ? -1 : 1;
1148 1193
 				}
1149 1194
 				usort($db_package_log, 'sort_table_first');
1150 1195
 				foreach ($db_package_log as $k => $log)
1151 1196
 				{
1152
-					if ($log[0] == 'remove_table')
1153
-						$tables[] = $log[1];
1154
-					elseif (in_array($log[1], $tables))
1155
-						unset($db_package_log[$k]);
1197
+					if ($log[0] == 'remove_table') {
1198
+											$tables[] = $log[1];
1199
+					} elseif (in_array($log[1], $tables)) {
1200
+											unset($db_package_log[$k]);
1201
+					}
1156 1202
 				}
1157 1203
 				$db_changes = json_encode($db_package_log);
1204
+			} else {
1205
+							$db_changes = '';
1158 1206
 			}
1159
-			else
1160
-				$db_changes = '';
1161 1207
 
1162 1208
 			// What themes did we actually install?
1163 1209
 			$themes_installed = array_unique($themes_installed);
@@ -1206,18 +1252,20 @@  discard block
 block discarded – undo
1206 1252
 
1207 1253
 		foreach ($db_changes as $change)
1208 1254
 		{
1209
-			if ($change[0] == 'remove_table' && isset($change[1]))
1210
-				$smcFunc['db_drop_table']($change[1]);
1211
-			elseif ($change[0] == 'remove_column' && isset($change[2]))
1212
-				$smcFunc['db_remove_column']($change[1], $change[2]);
1213
-			elseif ($change[0] == 'remove_index' && isset($change[2]))
1214
-				$smcFunc['db_remove_index']($change[1], $change[2]);
1255
+			if ($change[0] == 'remove_table' && isset($change[1])) {
1256
+							$smcFunc['db_drop_table']($change[1]);
1257
+			} elseif ($change[0] == 'remove_column' && isset($change[2])) {
1258
+							$smcFunc['db_remove_column']($change[1], $change[2]);
1259
+			} elseif ($change[0] == 'remove_index' && isset($change[2])) {
1260
+							$smcFunc['db_remove_index']($change[1], $change[2]);
1261
+			}
1215 1262
 		}
1216 1263
 	}
1217 1264
 
1218 1265
 	// Clean house... get rid of the evidence ;).
1219
-	if (file_exists($packagesdir . '/temp'))
1220
-		deltree($packagesdir . '/temp');
1266
+	if (file_exists($packagesdir . '/temp')) {
1267
+			deltree($packagesdir . '/temp');
1268
+	}
1221 1269
 
1222 1270
 	// Log what we just did.
1223 1271
 	logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => $smcFunc['htmlspecialchars']($packageInfo['name']), 'version' => $smcFunc['htmlspecialchars']($packageInfo['version'])), 'admin');
@@ -1239,8 +1287,9 @@  discard block
 block discarded – undo
1239 1287
 	require_once($sourcedir . '/Subs-Package.php');
1240 1288
 
1241 1289
 	// No package?  Show him or her the door.
1242
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
1243
-		redirectexit('action=admin;area=packages');
1290
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
1291
+			redirectexit('action=admin;area=packages');
1292
+	}
1244 1293
 
1245 1294
 	$context['linktree'][] = array(
1246 1295
 		'url' => $scripturl . '?action=admin;area=packages;sa=list;package=' . $_REQUEST['package'],
@@ -1253,11 +1302,12 @@  discard block
 block discarded – undo
1253 1302
 	$context['filename'] = $_REQUEST['package'];
1254 1303
 
1255 1304
 	// Let the unpacker do the work.
1256
-	if (is_file($packagesdir . '/' . $context['filename']))
1257
-		$context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null);
1258
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
1259
-		$context['files'] = listtree($packagesdir . '/' . $context['filename']);
1260
-}
1305
+	if (is_file($packagesdir . '/' . $context['filename'])) {
1306
+			$context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null);
1307
+	} elseif (is_dir($packagesdir . '/' . $context['filename'])) {
1308
+			$context['files'] = listtree($packagesdir . '/' . $context['filename']);
1309
+	}
1310
+	}
1261 1311
 
1262 1312
 /**
1263 1313
  * Display one of the files in a package.
@@ -1269,22 +1319,25 @@  discard block
 block discarded – undo
1269 1319
 	require_once($sourcedir . '/Subs-Package.php');
1270 1320
 
1271 1321
 	// No package?  Show him or her the door.
1272
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
1273
-		redirectexit('action=admin;area=packages');
1322
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
1323
+			redirectexit('action=admin;area=packages');
1324
+	}
1274 1325
 
1275 1326
 	// No file?  Show him or her the door.
1276
-	if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '')
1277
-		redirectexit('action=admin;area=packages');
1327
+	if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') {
1328
+			redirectexit('action=admin;area=packages');
1329
+	}
1278 1330
 
1279 1331
 	$_REQUEST['package'] = preg_replace('~[\.]+~', '.', strtr($_REQUEST['package'], array('/' => '_', '\\' => '_')));
1280 1332
 	$_REQUEST['file'] = preg_replace('~[\.]+~', '.', $_REQUEST['file']);
1281 1333
 
1282 1334
 	if (isset($_REQUEST['raw']))
1283 1335
 	{
1284
-		if (is_file($packagesdir . '/' . $_REQUEST['package']))
1285
-			echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true);
1286
-		elseif (is_dir($packagesdir . '/' . $_REQUEST['package']))
1287
-			echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']);
1336
+		if (is_file($packagesdir . '/' . $_REQUEST['package'])) {
1337
+					echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true);
1338
+		} elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) {
1339
+					echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']);
1340
+		}
1288 1341
 
1289 1342
 		obExit(false);
1290 1343
 	}
@@ -1301,17 +1354,19 @@  discard block
 block discarded – undo
1301 1354
 	$context['filename'] = $_REQUEST['file'];
1302 1355
 
1303 1356
 	// Let the unpacker do the work.... but make sure we handle images properly.
1304
-	if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png')))
1305
-		$context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">';
1306
-	else
1357
+	if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) {
1358
+			$context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">';
1359
+	} else
1307 1360
 	{
1308
-		if (is_file($packagesdir . '/' . $_REQUEST['package']))
1309
-			$context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true));
1310
-		elseif (is_dir($packagesdir . '/' . $_REQUEST['package']))
1311
-			$context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']));
1361
+		if (is_file($packagesdir . '/' . $_REQUEST['package'])) {
1362
+					$context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true));
1363
+		} elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) {
1364
+					$context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']));
1365
+		}
1312 1366
 
1313
-		if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php')
1314
-			$context['filedata'] = highlight_php_code($context['filedata']);
1367
+		if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') {
1368
+					$context['filedata'] = highlight_php_code($context['filedata']);
1369
+		}
1315 1370
 	}
1316 1371
 }
1317 1372
 
@@ -1326,8 +1381,9 @@  discard block
 block discarded – undo
1326 1381
 	checkSession('get');
1327 1382
 
1328 1383
 	// Ack, don't allow deletion of arbitrary files here, could become a security hole somehow!
1329
-	if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups')
1330
-		redirectexit('action=admin;area=packages;sa=browse');
1384
+	if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') {
1385
+			redirectexit('action=admin;area=packages;sa=browse');
1386
+	}
1331 1387
 	$_GET['package'] = preg_replace('~[\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_')));
1332 1388
 
1333 1389
 	// Can't delete what's not there.
@@ -1335,9 +1391,9 @@  discard block
 block discarded – undo
1335 1391
 	{
1336 1392
 		create_chmod_control(array($packagesdir . '/' . $_GET['package']), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=remove;package=' . $_GET['package'], 'crash_on_error' => true));
1337 1393
 
1338
-		if (is_dir($packagesdir . '/' . $_GET['package']))
1339
-			deltree($packagesdir . '/' . $_GET['package']);
1340
-		else
1394
+		if (is_dir($packagesdir . '/' . $_GET['package'])) {
1395
+					deltree($packagesdir . '/' . $_GET['package']);
1396
+		} else
1341 1397
 		{
1342 1398
 			smf_chmod($packagesdir . '/' . $_GET['package'], 0777);
1343 1399
 			unlink($packagesdir . '/' . $_GET['package']);
@@ -1385,8 +1441,9 @@  discard block
 block discarded – undo
1385 1441
 					'data' => array(
1386 1442
 						'function' => function($package_md5) use ($type, &$context)
1387 1443
 						{
1388
-							if (isset($context['available_' . $type . ''][$package_md5]))
1389
-								return $context['available_' . $type . ''][$package_md5]['sort_id'];
1444
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1445
+															return $context['available_' . $type . ''][$package_md5]['sort_id'];
1446
+							}
1390 1447
 						},
1391 1448
 					),
1392 1449
 					'sort' => array(
@@ -1402,8 +1459,9 @@  discard block
 block discarded – undo
1402 1459
 					'data' => array(
1403 1460
 						'function' => function($package_md5) use ($type, &$context)
1404 1461
 						{
1405
-							if (isset($context['available_' . $type . ''][$package_md5]))
1406
-								return $context['available_' . $type . ''][$package_md5]['name'];
1462
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1463
+															return $context['available_' . $type . ''][$package_md5]['name'];
1464
+							}
1407 1465
 						},
1408 1466
 					),
1409 1467
 					'sort' => array(
@@ -1418,8 +1476,9 @@  discard block
 block discarded – undo
1418 1476
 					'data' => array(
1419 1477
 						'function' => function($package_md5) use ($type, &$context)
1420 1478
 						{
1421
-							if (isset($context['available_' . $type . ''][$package_md5]))
1422
-								return $context['available_' . $type . ''][$package_md5]['version'];
1479
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1480
+															return $context['available_' . $type . ''][$package_md5]['version'];
1481
+							}
1423 1482
 						},
1424 1483
 					),
1425 1484
 					'sort' => array(
@@ -1434,8 +1493,9 @@  discard block
 block discarded – undo
1434 1493
 					'data' => array(
1435 1494
 						'function' => function($package_md5) use ($type, $txt, &$context)
1436 1495
 						{
1437
-							if (isset($context['available_' . $type . ''][$package_md5]))
1438
-								return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable'];
1496
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1497
+															return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable'];
1498
+							}
1439 1499
 						},
1440 1500
 						'class' => 'smalltext',
1441 1501
 					),
@@ -1451,28 +1511,30 @@  discard block
 block discarded – undo
1451 1511
 					'data' => array(
1452 1512
 						'function' => function($package_md5) use ($type, &$context, $scripturl, $txt)
1453 1513
 						{
1454
-							if (!isset($context['available_' . $type . ''][$package_md5]))
1455
-								return '';
1514
+							if (!isset($context['available_' . $type . ''][$package_md5])) {
1515
+															return '';
1516
+							}
1456 1517
 
1457 1518
 							// Rewrite shortcut
1458 1519
 							$package = $context['available_' . $type . ''][$package_md5];
1459 1520
 							$return = '';
1460 1521
 
1461
-							if ($package['can_uninstall'])
1462
-								$return = '
1522
+							if ($package['can_uninstall']) {
1523
+															$return = '
1463 1524
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['uninstall'] . '</a>';
1464
-							elseif ($package['can_emulate_uninstall'])
1465
-								$return = '
1525
+							} elseif ($package['can_emulate_uninstall']) {
1526
+															$return = '
1466 1527
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;ve=' . $package['can_emulate_uninstall'] . ';package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['package_emulate_uninstall'] . ' ' . $package['can_emulate_uninstall'] . '</a>';
1467
-							elseif ($package['can_upgrade'])
1468
-								$return = '
1528
+							} elseif ($package['can_upgrade']) {
1529
+															$return = '
1469 1530
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['package_upgrade'] . '</a>';
1470
-							elseif ($package['can_install'])
1471
-								$return = '
1531
+							} elseif ($package['can_install']) {
1532
+															$return = '
1472 1533
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['install_mod'] . '</a>';
1473
-							elseif ($package['can_emulate_install'])
1474
-								$return = '
1534
+							} elseif ($package['can_emulate_install']) {
1535
+															$return = '
1475 1536
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;ve=' . $package['can_emulate_install'] . ';package=' . $package['filename'] . '" class="button">' . $txt['package_emulate_install'] . ' ' . $package['can_emulate_install'] . '</a>';
1537
+							}
1476 1538
 
1477 1539
 							return $return . '
1478 1540
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=list;package=' . $package['filename'] . '" class="button">' . $txt['list_files'] . '</a>
@@ -1537,12 +1599,14 @@  discard block
 block discarded – undo
1537 1599
 	static $packages, $installed_mods;
1538 1600
 
1539 1601
 	// Start things up
1540
-	if (!isset($packages[$params]))
1541
-		$packages[$params] = array();
1602
+	if (!isset($packages[$params])) {
1603
+			$packages[$params] = array();
1604
+	}
1542 1605
 
1543 1606
 	// We need the packages directory to be writable for this.
1544
-	if (!@is_writable($packagesdir))
1545
-		create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true));
1607
+	if (!@is_writable($packagesdir)) {
1608
+			create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true));
1609
+	}
1546 1610
 
1547 1611
 	$the_version = strtr($forum_version, array('SMF ' => ''));
1548 1612
 
@@ -1550,41 +1614,44 @@  discard block
 block discarded – undo
1550 1614
 	if (isset($_GET['version_emulate']) && strtr($_GET['version_emulate'], array('SMF ' => '')) == $the_version)
1551 1615
 	{
1552 1616
 		unset($_SESSION['version_emulate']);
1553
-	}
1554
-	elseif (isset($_GET['version_emulate']))
1617
+	} elseif (isset($_GET['version_emulate']))
1555 1618
 	{
1556
-		if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate']))
1557
-			unset($_SESSION['version_emulate']);
1558
-		elseif ($_GET['version_emulate'] !== 0)
1559
-			$_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => ''));
1619
+		if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) {
1620
+					unset($_SESSION['version_emulate']);
1621
+		} elseif ($_GET['version_emulate'] !== 0) {
1622
+					$_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => ''));
1623
+		}
1560 1624
 	}
1561 1625
 	if (!empty($_SESSION['version_emulate']))
1562 1626
 	{
1563 1627
 		$context['forum_version'] = 'SMF ' . $_SESSION['version_emulate'];
1564 1628
 		$the_version = $_SESSION['version_emulate'];
1565 1629
 	}
1566
-	if (isset($_SESSION['single_version_emulate']))
1567
-		unset($_SESSION['single_version_emulate']);
1630
+	if (isset($_SESSION['single_version_emulate'])) {
1631
+			unset($_SESSION['single_version_emulate']);
1632
+	}
1568 1633
 
1569 1634
 	if (empty($installed_mods))
1570 1635
 	{
1571 1636
 		$instmods = loadInstalledPackages();
1572 1637
 		$installed_mods = array();
1573 1638
 		// Look through the list of installed mods...
1574
-		foreach ($instmods as $installed_mod)
1575
-			$installed_mods[$installed_mod['package_id']] = array(
1639
+		foreach ($instmods as $installed_mod) {
1640
+					$installed_mods[$installed_mod['package_id']] = array(
1576 1641
 				'id' => $installed_mod['id'],
1577 1642
 				'version' => $installed_mod['version'],
1578 1643
 				'time_installed' => $installed_mod['time_installed'],
1579 1644
 			);
1645
+		}
1580 1646
 
1581 1647
 		// Get a list of all the ids installed, so the latest packages won't include already installed ones.
1582 1648
 		$context['installed_mods'] = array_keys($installed_mods);
1583 1649
 	}
1584 1650
 
1585
-	if (empty($packages))
1586
-		foreach ($context['modification_types'] as $type)
1651
+	if (empty($packages)) {
1652
+			foreach ($context['modification_types'] as $type)
1587 1653
 			$packages[$type] = array();
1654
+	}
1588 1655
 
1589 1656
 	if ($dir = @opendir($packagesdir))
1590 1657
 	{
@@ -1600,50 +1667,56 @@  discard block
 block discarded – undo
1600 1667
 
1601 1668
 		while ($package = readdir($dir))
1602 1669
 		{
1603
-			if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip'))
1604
-				continue;
1670
+			if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) {
1671
+							continue;
1672
+			}
1605 1673
 
1606 1674
 			$skip = false;
1607
-			foreach ($context['modification_types'] as $type)
1608
-				if (isset($context['available_' . $type][md5($package)]))
1675
+			foreach ($context['modification_types'] as $type) {
1676
+							if (isset($context['available_' . $type][md5($package)]))
1609 1677
 					$skip = true;
1678
+			}
1610 1679
 
1611
-			if ($skip)
1612
-				continue;
1680
+			if ($skip) {
1681
+							continue;
1682
+			}
1613 1683
 
1614 1684
 			// Skip directories or files that are named the same.
1615 1685
 			if (is_dir($packagesdir . '/' . $package))
1616 1686
 			{
1617
-				if (in_array($package, $dirs))
1618
-					continue;
1687
+				if (in_array($package, $dirs)) {
1688
+									continue;
1689
+				}
1619 1690
 				$dirs[] = $package;
1620
-			}
1621
-			elseif (substr(strtolower($package), -7) == '.tar.gz')
1691
+			} elseif (substr(strtolower($package), -7) == '.tar.gz')
1622 1692
 			{
1623
-				if (in_array(substr($package, 0, -7), $dirs))
1624
-					continue;
1693
+				if (in_array(substr($package, 0, -7), $dirs)) {
1694
+									continue;
1695
+				}
1625 1696
 				$dirs[] = substr($package, 0, -7);
1626
-			}
1627
-			elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz')
1697
+			} elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz')
1628 1698
 			{
1629
-				if (in_array(substr($package, 0, -4), $dirs))
1630
-					continue;
1699
+				if (in_array(substr($package, 0, -4), $dirs)) {
1700
+									continue;
1701
+				}
1631 1702
 				$dirs[] = substr($package, 0, -4);
1632 1703
 			}
1633 1704
 
1634 1705
 			$packageInfo = getPackageInfo($package);
1635
-			if (!is_array($packageInfo))
1636
-				continue;
1706
+			if (!is_array($packageInfo)) {
1707
+							continue;
1708
+			}
1637 1709
 
1638 1710
 			if (!empty($packageInfo))
1639 1711
 			{
1640 1712
 				$packageInfo['installed_id'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['id'] : 0;
1641 1713
 				$packageInfo['time_installed'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['time_installed'] : 0;
1642 1714
 
1643
-				if (!isset($sort_id[$packageInfo['type']]))
1644
-					$packageInfo['sort_id'] = $sort_id['unknown'];
1645
-				else
1646
-					$packageInfo['sort_id'] = $sort_id[$packageInfo['type']];
1715
+				if (!isset($sort_id[$packageInfo['type']])) {
1716
+									$packageInfo['sort_id'] = $sort_id['unknown'];
1717
+				} else {
1718
+									$packageInfo['sort_id'] = $sort_id[$packageInfo['type']];
1719
+				}
1647 1720
 
1648 1721
 				$packageInfo['is_installed'] = isset($installed_mods[$packageInfo['id']]);
1649 1722
 				$packageInfo['is_current'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] == $packageInfo['version']);
@@ -1692,10 +1765,11 @@  discard block
 block discarded – undo
1692 1765
 					foreach ($upgrades as $upgrade)
1693 1766
 					{
1694 1767
 						// Even if it is for this SMF, is it for the installed version of the mod?
1695
-						if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for')))
1696
-							if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from')))
1768
+						if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) {
1769
+													if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from')))
1697 1770
 							{
1698 1771
 								$packageInfo['can_upgrade'] = true;
1772
+						}
1699 1773
 								break;
1700 1774
 							}
1701 1775
 					}
@@ -1772,10 +1846,11 @@  discard block
 block discarded – undo
1772 1846
 
1773 1847
 	if (isset($_GET['type']) && $_GET['type'] == $params)
1774 1848
 	{
1775
-		if (isset($_GET['desc']))
1776
-			krsort($packages[$params]);
1777
-		else
1778
-			ksort($packages[$params]);
1849
+		if (isset($_GET['desc'])) {
1850
+					krsort($packages[$params]);
1851
+		} else {
1852
+					ksort($packages[$params]);
1853
+		}
1779 1854
 	}
1780 1855
 
1781 1856
 	return $packages[$params];
@@ -1804,10 +1879,11 @@  discard block
 block discarded – undo
1804 1879
 		redirectexit('action=admin;area=packages;sa=options');
1805 1880
 	}
1806 1881
 
1807
-	if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
1808
-		$default_username = $match[1];
1809
-	else
1810
-		$default_username = '';
1882
+	if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) {
1883
+			$default_username = $match[1];
1884
+	} else {
1885
+			$default_username = '';
1886
+	}
1811 1887
 
1812 1888
 	$context['page_title'] = $txt['package_settings'];
1813 1889
 	$context['sub_template'] = 'install_options';
@@ -1836,8 +1912,9 @@  discard block
 block discarded – undo
1836 1912
 	isAllowedTo('admin_forum');
1837 1913
 
1838 1914
 	// We need to know the operation key for the search and replace, mod file looking at, is it a board mod?
1839
-	if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key']))
1840
-		fatal_lang_error('operation_invalid', 'general');
1915
+	if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) {
1916
+			fatal_lang_error('operation_invalid', 'general');
1917
+	}
1841 1918
 
1842 1919
 	// Load the required file.
1843 1920
 	require_once($sourcedir . '/Subs-Package.php');
@@ -1853,18 +1930,19 @@  discard block
 block discarded – undo
1853 1930
 	{
1854 1931
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
1855 1932
 
1856
-		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml'))
1857
-			foreach ($context['extracted_files'] as $file)
1933
+		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) {
1934
+					foreach ($context['extracted_files'] as $file)
1858 1935
 				if (basename($file['filename']) == 'package-info.xml')
1859 1936
 				{
1860 1937
 					$context['base_path'] = dirname($file['filename']) . '/';
1938
+		}
1861 1939
 					break;
1862 1940
 				}
1863 1941
 
1864
-		if (!isset($context['base_path']))
1865
-			$context['base_path'] = '';
1866
-	}
1867
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
1942
+		if (!isset($context['base_path'])) {
1943
+					$context['base_path'] = '';
1944
+		}
1945
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
1868 1946
 	{
1869 1947
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
1870 1948
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
@@ -1885,8 +1963,9 @@  discard block
 block discarded – undo
1885 1963
 		)
1886 1964
 	);
1887 1965
 	$theme_paths = array();
1888
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1889
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1966
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1967
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1968
+	}
1890 1969
 	$smcFunc['db_free_result']($request);
1891 1970
 
1892 1971
 	// If we're viewing uninstall operations, only consider themes that
@@ -1911,19 +1990,21 @@  discard block
 block discarded – undo
1911 1990
 				list ($old_themes) = $smcFunc['db_fetch_row']($request);
1912 1991
 				$old_themes = explode(',', $old_themes);
1913 1992
 
1914
-				foreach ($theme_paths as $id => $data)
1915
-					if ($id != 1 && !in_array($id, $old_themes))
1993
+				foreach ($theme_paths as $id => $data) {
1994
+									if ($id != 1 && !in_array($id, $old_themes))
1916 1995
 						unset($theme_paths[$id]);
1996
+				}
1917 1997
 			}
1918 1998
 			$smcFunc['db_free_result']($request);
1919 1999
 		}
1920 2000
 	}
1921 2001
 
1922 2002
 	// Boardmod?
1923
-	if (isset($_REQUEST['boardmod']))
1924
-		$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
1925
-	else
1926
-		$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2003
+	if (isset($_REQUEST['boardmod'])) {
2004
+			$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2005
+	} else {
2006
+			$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2007
+	}
1927 2008
 
1928 2009
 	// Ok lets get the content of the file.
1929 2010
 	$context['operations'] = array(
@@ -1979,9 +2060,9 @@  discard block
 block discarded – undo
1979 2060
 			'path' => $detect_path,
1980 2061
 			'form_elements_only' => true,
1981 2062
 		);
2063
+	} else {
2064
+			$context['ftp_connected'] = true;
1982 2065
 	}
1983
-	else
1984
-		$context['ftp_connected'] = true;
1985 2066
 
1986 2067
 	// Define the template.
1987 2068
 	$context['page_title'] = $txt['package_file_perms'];
@@ -2094,18 +2175,19 @@  discard block
 block discarded – undo
2094 2175
 	{
2095 2176
 		unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']);
2096 2177
 
2097
-		if (!is_array($modSettings['attachmentUploadDir']))
2098
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
2178
+		if (!is_array($modSettings['attachmentUploadDir'])) {
2179
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
2180
+		}
2099 2181
 
2100 2182
 		// @todo Should we suggest non-current directories be read only?
2101
-		foreach ($modSettings['attachmentUploadDir'] as $dir)
2102
-			$context['file_tree'][strtr($dir, array('\\' => '/'))] = array(
2183
+		foreach ($modSettings['attachmentUploadDir'] as $dir) {
2184
+					$context['file_tree'][strtr($dir, array('\\' => '/'))] = array(
2103 2185
 			'type' => 'dir',
2104 2186
 			'writable_on' => 'restrictive',
2105 2187
 		);
2188
+		}
2106 2189
 
2107
-	}
2108
-	elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir)
2190
+	} elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir)
2109 2191
 	{
2110 2192
 		unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']);
2111 2193
 		$context['file_tree'][strtr($modSettings['attachmentUploadDir'], array('\\' => '/'))] = array(
@@ -2155,8 +2237,8 @@  discard block
 block discarded – undo
2155 2237
 	);
2156 2238
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2157 2239
 	{
2158
-		if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes'))
2159
-			$context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array(
2240
+		if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) {
2241
+					$context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array(
2160 2242
 				'type' => 'dir_recursive',
2161 2243
 				'list_contents' => true,
2162 2244
 				'contents' => array(
@@ -2166,7 +2248,7 @@  discard block
 block discarded – undo
2166 2248
 					),
2167 2249
 				),
2168 2250
 			);
2169
-		else
2251
+		} else
2170 2252
 		{
2171 2253
 			$context['file_tree'][strtr($row['value'], array('\\' => '/'))] = array(
2172 2254
 				'type' => 'dir_recursive',
@@ -2183,28 +2265,33 @@  discard block
 block discarded – undo
2183 2265
 	$smcFunc['db_free_result']($request);
2184 2266
 
2185 2267
 	// If we're submitting then let's move on to another function to keep things cleaner..
2186
-	if (isset($_POST['action_changes']))
2187
-		return PackagePermissionsAction();
2268
+	if (isset($_POST['action_changes'])) {
2269
+			return PackagePermissionsAction();
2270
+	}
2188 2271
 
2189 2272
 	$context['look_for'] = array();
2190 2273
 	// Are we looking for a particular tree - normally an expansion?
2191
-	if (!empty($_REQUEST['find']))
2192
-		$context['look_for'][] = base64_decode($_REQUEST['find']);
2274
+	if (!empty($_REQUEST['find'])) {
2275
+			$context['look_for'][] = base64_decode($_REQUEST['find']);
2276
+	}
2193 2277
 	// Only that tree?
2194 2278
 	$context['only_find'] = isset($_GET['xml']) && !empty($_REQUEST['onlyfind']) ? $_REQUEST['onlyfind'] : '';
2195
-	if ($context['only_find'])
2196
-		$context['look_for'][] = $context['only_find'];
2279
+	if ($context['only_find']) {
2280
+			$context['look_for'][] = $context['only_find'];
2281
+	}
2197 2282
 
2198 2283
 	// Have we got a load of back-catalogue trees to expand from a submit etc?
2199 2284
 	if (!empty($_GET['back_look']))
2200 2285
 	{
2201 2286
 		$potententialTrees = smf_json_decode(base64_decode($_GET['back_look']), true);
2202
-		foreach ($potententialTrees as $tree)
2203
-			$context['look_for'][] = $tree;
2287
+		foreach ($potententialTrees as $tree) {
2288
+					$context['look_for'][] = $tree;
2289
+		}
2204 2290
 	}
2205 2291
 	// ... maybe posted?
2206
-	if (!empty($_POST['back_look']))
2207
-		$context['only_find'] = array_merge($context['only_find'], $_POST['back_look']);
2292
+	if (!empty($_POST['back_look'])) {
2293
+			$context['only_find'] = array_merge($context['only_find'], $_POST['back_look']);
2294
+	}
2208 2295
 
2209 2296
 	$context['back_look_data'] = base64_encode(json_encode(array_slice($context['look_for'], 0, 15)));
2210 2297
 
@@ -2243,9 +2330,9 @@  discard block
 block discarded – undo
2243 2330
 				'chmod' => @is_writable($path),
2244 2331
 				'perms' => @fileperms($path),
2245 2332
 			);
2333
+		} else {
2334
+					unset($context['file_tree'][$path]);
2246 2335
 		}
2247
-		else
2248
-			unset($context['file_tree'][$path]);
2249 2336
 	}
2250 2337
 
2251 2338
 	// Is this actually xml?
@@ -2269,22 +2356,25 @@  discard block
 block discarded – undo
2269 2356
 	global $context;
2270 2357
 
2271 2358
 	$isLikelyPath = false;
2272
-	foreach ($context['look_for'] as $possiblePath)
2273
-		if (substr($possiblePath, 0, strlen($path)) == $path)
2359
+	foreach ($context['look_for'] as $possiblePath) {
2360
+			if (substr($possiblePath, 0, strlen($path)) == $path)
2274 2361
 			$isLikelyPath = true;
2362
+	}
2275 2363
 
2276 2364
 	// Is this where we stop?
2277
-	if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath)
2278
-		return;
2279
-	elseif ($level > $context['default_level'] && !$isLikelyPath)
2280
-		return;
2365
+	if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) {
2366
+			return;
2367
+	} elseif ($level > $context['default_level'] && !$isLikelyPath) {
2368
+			return;
2369
+	}
2281 2370
 
2282 2371
 	// Are we actually interested in saving this data?
2283 2372
 	$save_data = empty($context['only_find']) || $context['only_find'] == $path;
2284 2373
 
2285 2374
 	// @todo Shouldn't happen - but better error message?
2286
-	if (!is_dir($path))
2287
-		fatal_lang_error('no_access', false);
2375
+	if (!is_dir($path)) {
2376
+			fatal_lang_error('no_access', false);
2377
+	}
2288 2378
 
2289 2379
 	// This is where we put stuff we've found for sorting.
2290 2380
 	$foundData = array(
@@ -2299,11 +2389,13 @@  discard block
 block discarded – undo
2299 2389
 		if (is_file($path . '/' . $entry))
2300 2390
 		{
2301 2391
 			// Are we listing PHP files in this directory?
2302
-			if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php')
2303
-				$foundData['files'][$entry] = true;
2392
+			if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') {
2393
+							$foundData['files'][$entry] = true;
2394
+			}
2304 2395
 			// A file we were looking for.
2305
-			elseif ($save_data && isset($data['contents'][$entry]))
2306
-				$foundData['files'][$entry] = true;
2396
+			elseif ($save_data && isset($data['contents'][$entry])) {
2397
+							$foundData['files'][$entry] = true;
2398
+			}
2307 2399
 		}
2308 2400
 		// It's a directory - we're interested one way or another, probably...
2309 2401
 		elseif ($entry != '.' && $entry != '..')
@@ -2311,32 +2403,36 @@  discard block
 block discarded – undo
2311 2403
 			// Going further?
2312 2404
 			if ((!empty($data['type']) && $data['type'] == 'dir_recursive') || (isset($data['contents'][$entry]) && (!empty($data['contents'][$entry]['list_contents']) || (!empty($data['contents'][$entry]['type']) && $data['contents'][$entry]['type'] == 'dir_recursive'))))
2313 2405
 			{
2314
-				if (!isset($data['contents'][$entry]))
2315
-					$foundData['folders'][$entry] = 'dir_recursive';
2316
-				else
2317
-					$foundData['folders'][$entry] = true;
2406
+				if (!isset($data['contents'][$entry])) {
2407
+									$foundData['folders'][$entry] = 'dir_recursive';
2408
+				} else {
2409
+									$foundData['folders'][$entry] = true;
2410
+				}
2318 2411
 
2319 2412
 				// If this wasn't expected inherit the recusiveness...
2320
-				if (!isset($data['contents'][$entry]))
2321
-					// We need to do this as we will be going all recursive.
2413
+				if (!isset($data['contents'][$entry])) {
2414
+									// We need to do this as we will be going all recursive.
2322 2415
 					$data['contents'][$entry] = array(
2323 2416
 						'type' => 'dir_recursive',
2324 2417
 					);
2418
+				}
2325 2419
 
2326 2420
 				// Actually do the recursive stuff...
2327 2421
 				fetchPerms__recursive($path . '/' . $entry, $data['contents'][$entry], $level + 1);
2328 2422
 			}
2329 2423
 			// Maybe it is a folder we are not descending into.
2330
-			elseif (isset($data['contents'][$entry]))
2331
-				$foundData['folders'][$entry] = true;
2424
+			elseif (isset($data['contents'][$entry])) {
2425
+							$foundData['folders'][$entry] = true;
2426
+			}
2332 2427
 			// Otherwise we stop here.
2333 2428
 		}
2334 2429
 	}
2335 2430
 	closedir($dh);
2336 2431
 
2337 2432
 	// Nothing to see here?
2338
-	if (!$save_data)
2339
-		return;
2433
+	if (!$save_data) {
2434
+			return;
2435
+	}
2340 2436
 
2341 2437
 	// Now actually add the data, starting with the folders.
2342 2438
 	ksort($foundData['folders']);
@@ -2348,8 +2444,9 @@  discard block
 block discarded – undo
2348 2444
 				'perms' => @fileperms($path . '/' . $folder),
2349 2445
 			),
2350 2446
 		);
2351
-		if ($type !== true)
2352
-			$additional_data['type'] = $type;
2447
+		if ($type !== true) {
2448
+					$additional_data['type'] = $type;
2449
+		}
2353 2450
 
2354 2451
 		// If there's an offset ignore any folders in XML mode.
2355 2452
 		if (isset($_GET['xml']) && $context['file_offset'] == 0)
@@ -2368,13 +2465,13 @@  discard block
 block discarded – undo
2368 2465
 				),
2369 2466
 				'value' => $folder,
2370 2467
 			);
2371
-		}
2372
-		elseif (!isset($_GET['xml']))
2468
+		} elseif (!isset($_GET['xml']))
2373 2469
 		{
2374
-			if (isset($data['contents'][$folder]))
2375
-				$data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data);
2376
-			else
2377
-				$data['contents'][$folder] = $additional_data;
2470
+			if (isset($data['contents'][$folder])) {
2471
+							$data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data);
2472
+			} else {
2473
+							$data['contents'][$folder] = $additional_data;
2474
+			}
2378 2475
 		}
2379 2476
 	}
2380 2477
 
@@ -2386,11 +2483,13 @@  discard block
 block discarded – undo
2386 2483
 		$counter++;
2387 2484
 
2388 2485
 		// Have we reached our offset?
2389
-		if ($context['file_offset'] > $counter)
2390
-			continue;
2486
+		if ($context['file_offset'] > $counter) {
2487
+					continue;
2488
+		}
2391 2489
 		// Gone too far?
2392
-		if ($counter > ($context['file_offset'] + $context['file_limit']))
2393
-			continue;
2490
+		if ($counter > ($context['file_offset'] + $context['file_limit'])) {
2491
+					continue;
2492
+		}
2394 2493
 
2395 2494
 		$additional_data = array(
2396 2495
 			'perms' => array(
@@ -2416,13 +2515,13 @@  discard block
 block discarded – undo
2416 2515
 				),
2417 2516
 				'value' => $file,
2418 2517
 			);
2419
-		}
2420
-		elseif ($counter != ($context['file_offset'] + $context['file_limit']))
2518
+		} elseif ($counter != ($context['file_offset'] + $context['file_limit']))
2421 2519
 		{
2422
-			if (isset($data['contents'][$file]))
2423
-				$data['contents'][$file] = array_merge($data['contents'][$file], $additional_data);
2424
-			else
2425
-				$data['contents'][$file] = $additional_data;
2520
+			if (isset($data['contents'][$file])) {
2521
+							$data['contents'][$file] = array_merge($data['contents'][$file], $additional_data);
2522
+			} else {
2523
+							$data['contents'][$file] = $additional_data;
2524
+			}
2426 2525
 		}
2427 2526
 	}
2428 2527
 }
@@ -2444,8 +2543,9 @@  discard block
 block discarded – undo
2444 2543
 	$context['back_look_data'] = isset($_POST['back_look']) ? $_POST['back_look'] : array();
2445 2544
 
2446 2545
 	// Skipping use of FTP?
2447
-	if (empty($package_ftp))
2448
-		$context['skip_ftp'] = true;
2546
+	if (empty($package_ftp)) {
2547
+			$context['skip_ftp'] = true;
2548
+	}
2449 2549
 
2450 2550
 	// We'll start off in a good place, security. Make sure that if we're dealing with individual files that they seem in the right place.
2451 2551
 	if ($context['method'] == 'individual')
@@ -2455,8 +2555,9 @@  discard block
 block discarded – undo
2455 2555
 		$context['custom_value'] = (int) $_POST['custom_value'];
2456 2556
 
2457 2557
 		// Continuing?
2458
-		if (isset($_POST['toProcess']))
2459
-			$_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true);
2558
+		if (isset($_POST['toProcess'])) {
2559
+					$_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true);
2560
+		}
2460 2561
 
2461 2562
 		if (isset($_POST['permStatus']))
2462 2563
 		{
@@ -2465,22 +2566,27 @@  discard block
 block discarded – undo
2465 2566
 			foreach ($_POST['permStatus'] as $path => $status)
2466 2567
 			{
2467 2568
 				// Nothing to see here?
2468
-				if ($status == 'no_change')
2469
-					continue;
2569
+				if ($status == 'no_change') {
2570
+									continue;
2571
+				}
2470 2572
 				$legal = false;
2471
-				foreach ($legal_roots as $root)
2472
-					if (substr($path, 0, strlen($root)) == $root)
2573
+				foreach ($legal_roots as $root) {
2574
+									if (substr($path, 0, strlen($root)) == $root)
2473 2575
 						$legal = true;
2576
+				}
2474 2577
 
2475
-				if (!$legal)
2476
-					continue;
2578
+				if (!$legal) {
2579
+									continue;
2580
+				}
2477 2581
 
2478 2582
 				// Check it exists.
2479
-				if (!file_exists($path))
2480
-					continue;
2583
+				if (!file_exists($path)) {
2584
+									continue;
2585
+				}
2481 2586
 
2482
-				if ($status == 'custom')
2483
-					$validate_custom = true;
2587
+				if ($status == 'custom') {
2588
+									$validate_custom = true;
2589
+				}
2484 2590
 
2485 2591
 				// Now add it.
2486 2592
 				$context['to_process'][$path] = $status;
@@ -2490,17 +2596,20 @@  discard block
 block discarded – undo
2490 2596
 			// Make sure the chmod status is valid?
2491 2597
 			if ($validate_custom)
2492 2598
 			{
2493
-				if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false)
2494
-					fatal_error($txt['chmod_value_invalid']);
2599
+				if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) {
2600
+									fatal_error($txt['chmod_value_invalid']);
2601
+				}
2495 2602
 			}
2496 2603
 
2497 2604
 			// Nothing to do?
2498
-			if (empty($context['to_process']))
2499
-				redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']);
2605
+			if (empty($context['to_process'])) {
2606
+							redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']);
2607
+			}
2500 2608
 		}
2501 2609
 		// Should never get here,
2502
-		else
2503
-			fatal_lang_error('no_access', false);
2610
+		else {
2611
+					fatal_lang_error('no_access', false);
2612
+		}
2504 2613
 
2505 2614
 		// Setup the custom value.
2506 2615
 		$custom_value = octdec('0' . $context['custom_value']);
@@ -2508,26 +2617,27 @@  discard block
 block discarded – undo
2508 2617
 		// Start processing items.
2509 2618
 		foreach ($context['to_process'] as $path => $status)
2510 2619
 		{
2511
-			if (in_array($status, array('execute', 'writable', 'read')))
2512
-				package_chmod($path, $status);
2513
-			elseif ($status == 'custom' && !empty($custom_value))
2620
+			if (in_array($status, array('execute', 'writable', 'read'))) {
2621
+							package_chmod($path, $status);
2622
+			} elseif ($status == 'custom' && !empty($custom_value))
2514 2623
 			{
2515 2624
 				// Use FTP if we have it.
2516 2625
 				if (!empty($package_ftp) && !empty($_SESSION['pack_ftp']))
2517 2626
 				{
2518 2627
 					$ftp_file = strtr($path, array($_SESSION['pack_ftp']['root'] => ''));
2519 2628
 					$package_ftp->chmod($ftp_file, $custom_value);
2629
+				} else {
2630
+									smf_chmod($path, $custom_value);
2520 2631
 				}
2521
-				else
2522
-					smf_chmod($path, $custom_value);
2523 2632
 			}
2524 2633
 
2525 2634
 			// This fish is fried...
2526 2635
 			unset($context['to_process'][$path]);
2527 2636
 
2528 2637
 			// See if we're out of time?
2529
-			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit)
2530
-				return false;
2638
+			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) {
2639
+							return false;
2640
+			}
2531 2641
 		}
2532 2642
 	}
2533 2643
 	// If predefined this is a little different.
@@ -2595,23 +2705,27 @@  discard block
 block discarded – undo
2595 2705
 			{
2596 2706
 				global $context;
2597 2707
 
2598
-				if (!empty($data['writable_on']))
2599
-					if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive')
2708
+				if (!empty($data['writable_on'])) {
2709
+									if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive')
2600 2710
 						$context['special_files'][$path] = 1;
2711
+				}
2601 2712
 
2602
-				if (!empty($data['contents']))
2603
-					foreach ($data['contents'] as $name => $contents)
2713
+				if (!empty($data['contents'])) {
2714
+									foreach ($data['contents'] as $name => $contents)
2604 2715
 						build_special_files__recursive($path . '/' . $name, $contents);
2716
+				}
2605 2717
 			}
2606 2718
 
2607
-			foreach ($context['file_tree'] as $path => $data)
2608
-				build_special_files__recursive($path, $data);
2719
+			foreach ($context['file_tree'] as $path => $data) {
2720
+							build_special_files__recursive($path, $data);
2721
+			}
2609 2722
 		}
2610 2723
 		// Free doesn't need special files.
2611
-		elseif ($context['predefined_type'] == 'free')
2612
-			$context['special_files'] = array();
2613
-		else
2614
-			$context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true);
2724
+		elseif ($context['predefined_type'] == 'free') {
2725
+					$context['special_files'] = array();
2726
+		} else {
2727
+					$context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true);
2728
+		}
2615 2729
 
2616 2730
 		// Now we definitely know where we are, we need to go through again doing the chmod!
2617 2731
 		foreach ($context['directory_list'] as $path => $dummy)
@@ -2656,8 +2770,9 @@  discard block
 block discarded – undo
2656 2770
 			unset($context['directory_list'][$path]);
2657 2771
 
2658 2772
 			// See if we're out of time?
2659
-			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit)
2660
-				return false;
2773
+			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) {
2774
+							return false;
2775
+			}
2661 2776
 		}
2662 2777
 	}
2663 2778
 
Please login to merge, or discard this patch.
Sources/ReCaptcha/ReCaptcha.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -31,67 +31,67 @@
 block discarded – undo
31 31
  */
32 32
 class ReCaptcha
33 33
 {
34
-    /**
35
-     * Version of this client library.
36
-     * @const string
37
-     */
38
-    const VERSION = 'php_1.1.2';
34
+	/**
35
+	 * Version of this client library.
36
+	 * @const string
37
+	 */
38
+	const VERSION = 'php_1.1.2';
39 39
 
40
-    /**
41
-     * Shared secret for the site.
42
-     * @var string
43
-     */
44
-    private $secret;
40
+	/**
41
+	 * Shared secret for the site.
42
+	 * @var string
43
+	 */
44
+	private $secret;
45 45
 
46
-    /**
47
-     * Method used to communicate  with service. Defaults to POST request.
48
-     * @var RequestMethod
49
-     */
50
-    private $requestMethod;
46
+	/**
47
+	 * Method used to communicate  with service. Defaults to POST request.
48
+	 * @var RequestMethod
49
+	 */
50
+	private $requestMethod;
51 51
 
52
-    /**
53
-     * Create a configured instance to use the reCAPTCHA service.
54
-     *
55
-     * @param string $secret shared secret between site and reCAPTCHA server.
56
-     * @param RequestMethod $requestMethod method used to send the request. Defaults to POST.
57
-     */
58
-    public function __construct($secret, RequestMethod $requestMethod = null)
59
-    {
60
-        if (empty($secret)) {
61
-            throw new \RuntimeException('No secret provided');
62
-        }
52
+	/**
53
+	 * Create a configured instance to use the reCAPTCHA service.
54
+	 *
55
+	 * @param string $secret shared secret between site and reCAPTCHA server.
56
+	 * @param RequestMethod $requestMethod method used to send the request. Defaults to POST.
57
+	 */
58
+	public function __construct($secret, RequestMethod $requestMethod = null)
59
+	{
60
+		if (empty($secret)) {
61
+			throw new \RuntimeException('No secret provided');
62
+		}
63 63
 
64
-        if (!is_string($secret)) {
65
-            throw new \RuntimeException('The provided secret must be a string');
66
-        }
64
+		if (!is_string($secret)) {
65
+			throw new \RuntimeException('The provided secret must be a string');
66
+		}
67 67
 
68
-        $this->secret = $secret;
68
+		$this->secret = $secret;
69 69
 
70
-        if (!is_null($requestMethod)) {
71
-            $this->requestMethod = $requestMethod;
72
-        } else {
73
-            $this->requestMethod = new RequestMethod\Post();
74
-        }
75
-    }
70
+		if (!is_null($requestMethod)) {
71
+			$this->requestMethod = $requestMethod;
72
+		} else {
73
+			$this->requestMethod = new RequestMethod\Post();
74
+		}
75
+	}
76 76
 
77
-    /**
78
-     * Calls the reCAPTCHA siteverify API to verify whether the user passes
79
-     * CAPTCHA test.
80
-     *
81
-     * @param string $response The value of 'g-recaptcha-response' in the submitted form.
82
-     * @param string $remoteIp The end user's IP address.
83
-     * @return Response Response from the service.
84
-     */
85
-    public function verify($response, $remoteIp = null)
86
-    {
87
-        // Discard empty solution submissions
88
-        if (empty($response)) {
89
-            $recaptchaResponse = new Response(false, array('missing-input-response'));
90
-            return $recaptchaResponse;
91
-        }
77
+	/**
78
+	 * Calls the reCAPTCHA siteverify API to verify whether the user passes
79
+	 * CAPTCHA test.
80
+	 *
81
+	 * @param string $response The value of 'g-recaptcha-response' in the submitted form.
82
+	 * @param string $remoteIp The end user's IP address.
83
+	 * @return Response Response from the service.
84
+	 */
85
+	public function verify($response, $remoteIp = null)
86
+	{
87
+		// Discard empty solution submissions
88
+		if (empty($response)) {
89
+			$recaptchaResponse = new Response(false, array('missing-input-response'));
90
+			return $recaptchaResponse;
91
+		}
92 92
 
93
-        $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION);
94
-        $rawResponse = $this->requestMethod->submit($params);
95
-        return Response::fromJson($rawResponse);
96
-    }
93
+		$params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION);
94
+		$rawResponse = $this->requestMethod->submit($params);
95
+		return Response::fromJson($rawResponse);
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Sources/Display.php 1 patch
Braces   +333 added lines, -249 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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
  * The central part of the board - topic display.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	global $messages_request, $language, $smcFunc;
35 36
 
36 37
 	// What are you gonna display if these are empty?!
37
-	if (empty($topic))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($topic)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// Load the proper template.
41 43
 	loadTemplate('Display');
@@ -52,15 +54,17 @@  discard block
 block discarded – undo
52 54
 	$context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
53 55
 
54 56
 	// Let's do some work on what to search index.
55
-	if (count($_GET) > 2)
56
-		foreach ($_GET as $k => $v)
57
+	if (count($_GET) > 2) {
58
+			foreach ($_GET as $k => $v)
57 59
 		{
58 60
 			if (!in_array($k, array('topic', 'board', 'start', session_name())))
59 61
 				$context['robot_no_index'] = true;
62
+	}
60 63
 		}
61 64
 
62
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
63
-		$context['robot_no_index'] = true;
65
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
66
+			$context['robot_no_index'] = true;
67
+	}
64 68
 
65 69
 	// Find the previous or next topic.  Make a fuss if there are no more.
66 70
 	if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
@@ -172,8 +176,9 @@  discard block
 block discarded – undo
172 176
 			$topic_parameters
173 177
 	);
174 178
 
175
-	if ($smcFunc['db_num_rows']($request) == 0)
176
-		fatal_lang_error('not_a_topic', false, 404);
179
+	if ($smcFunc['db_num_rows']($request) == 0) {
180
+			fatal_lang_error('not_a_topic', false, 404);
181
+	}
177 182
 	$context['topicinfo'] = $smcFunc['db_fetch_assoc']($request);
178 183
 	$smcFunc['db_free_result']($request);
179 184
 
@@ -210,8 +215,9 @@  discard block
 block discarded – undo
210 215
 	$context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0;
211 216
 
212 217
 	// Add up unapproved replies to get real number of replies...
213
-	if ($modSettings['postmod_active'] && $approve_posts)
214
-		$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
218
+	if ($modSettings['postmod_active'] && $approve_posts) {
219
+			$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
220
+	}
215 221
 
216 222
 	// If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
217 223
 	if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts)
@@ -231,11 +237,11 @@  discard block
 block discarded – undo
231 237
 		$smcFunc['db_free_result']($request);
232 238
 
233 239
 		$context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0);
240
+	} elseif ($user_info['is_guest']) {
241
+			$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
242
+	} else {
243
+			$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
234 244
 	}
235
-	elseif ($user_info['is_guest'])
236
-		$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
237
-	else
238
-		$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
239 245
 
240 246
 	// The start isn't a number; it's information about what to do, where to go.
241 247
 	if (!is_numeric($_REQUEST['start']))
@@ -248,8 +254,7 @@  discard block
 block discarded – undo
248 254
 			{
249 255
 				$context['start_from'] = $context['total_visible_posts'] - 1;
250 256
 				$_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
251
-			}
252
-			else
257
+			} else
253 258
 			{
254 259
 				// Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
255 260
 				$request = $smcFunc['db_query']('', '
@@ -277,9 +282,9 @@  discard block
 block discarded – undo
277 282
 		if (substr($_REQUEST['start'], 0, 4) == 'from')
278 283
 		{
279 284
 			$timestamp = (int) substr($_REQUEST['start'], 4);
280
-			if ($timestamp === 0)
281
-				$_REQUEST['start'] = 0;
282
-			else
285
+			if ($timestamp === 0) {
286
+							$_REQUEST['start'] = 0;
287
+			} else
283 288
 			{
284 289
 				// Find the number of messages posted before said time...
285 290
 				$request = $smcFunc['db_query']('', '
@@ -307,11 +312,11 @@  discard block
 block discarded – undo
307 312
 		elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
308 313
 		{
309 314
 			$virtual_msg = (int) substr($_REQUEST['start'], 3);
310
-			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg'])
311
-				$context['start_from'] = $context['total_visible_posts'] - 1;
312
-			elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg'])
313
-				$context['start_from'] = 0;
314
-			else
315
+			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) {
316
+							$context['start_from'] = $context['total_visible_posts'] - 1;
317
+			} elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) {
318
+							$context['start_from'] = 0;
319
+			} else
315 320
 			{
316 321
 				// Find the start value for that message......
317 322
 				$request = $smcFunc['db_query']('', '
@@ -394,21 +399,25 @@  discard block
 block discarded – undo
394 399
 		);
395 400
 		while ($row = $smcFunc['db_fetch_assoc']($request))
396 401
 		{
397
-			if (empty($row['id_member']))
398
-				continue;
402
+			if (empty($row['id_member'])) {
403
+							continue;
404
+			}
399 405
 
400
-			if (!empty($row['online_color']))
401
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
402
-			else
403
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
406
+			if (!empty($row['online_color'])) {
407
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
408
+			} else {
409
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
410
+			}
404 411
 
405 412
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
406
-			if ($is_buddy)
407
-				$link = '<strong>' . $link . '</strong>';
413
+			if ($is_buddy) {
414
+							$link = '<strong>' . $link . '</strong>';
415
+			}
408 416
 
409 417
 			// Add them both to the list and to the more detailed list.
410
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
411
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
418
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
419
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
420
+			}
412 421
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
413 422
 				'id' => $row['id_member'],
414 423
 				'username' => $row['member_name'],
@@ -420,8 +429,9 @@  discard block
 block discarded – undo
420 429
 				'hidden' => empty($row['show_online']),
421 430
 			);
422 431
 
423
-			if (empty($row['show_online']))
424
-				$context['view_num_hidden']++;
432
+			if (empty($row['show_online'])) {
433
+							$context['view_num_hidden']++;
434
+			}
425 435
 		}
426 436
 
427 437
 		// The number of guests is equal to the rows minus the ones we actually used ;).
@@ -435,11 +445,13 @@  discard block
 block discarded – undo
435 445
 
436 446
 	// If all is set, but not allowed... just unset it.
437 447
 	$can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
438
-	if (isset($_REQUEST['all']) && !$can_show_all)
439
-		unset($_REQUEST['all']);
448
+	if (isset($_REQUEST['all']) && !$can_show_all) {
449
+			unset($_REQUEST['all']);
450
+	}
440 451
 	// Otherwise, it must be allowed... so pretend start was -1.
441
-	elseif (isset($_REQUEST['all']))
442
-		$_REQUEST['start'] = -1;
452
+	elseif (isset($_REQUEST['all'])) {
453
+			$_REQUEST['start'] = -1;
454
+	}
443 455
 
444 456
 	// Construct the page index, allowing for the .START method...
445 457
 	$context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true);
@@ -476,8 +488,9 @@  discard block
 block discarded – undo
476 488
 			$_REQUEST['start'] = 0;
477 489
 		}
478 490
 		// They aren't using it, but the *option* is there, at least.
479
-		else
480
-			$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
491
+		else {
492
+					$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
493
+		}
481 494
 	}
482 495
 
483 496
 	// Build the link tree.
@@ -493,14 +506,16 @@  discard block
 block discarded – undo
493 506
 	if (!empty($board_info['moderators']))
494 507
 	{
495 508
 		// Add a link for each moderator...
496
-		foreach ($board_info['moderators'] as $mod)
497
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
509
+		foreach ($board_info['moderators'] as $mod) {
510
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
511
+		}
498 512
 	}
499 513
 	if (!empty($board_info['moderator_groups']))
500 514
 	{
501 515
 		// Add a link for each moderator group as well...
502
-		foreach ($board_info['moderator_groups'] as $mod_group)
503
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
516
+		foreach ($board_info['moderator_groups'] as $mod_group) {
517
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
518
+		}
504 519
 	}
505 520
 
506 521
 	if (!empty($context['link_moderators']))
@@ -531,9 +546,9 @@  discard block
 block discarded – undo
531 546
 	// For quick reply we need a response prefix in the default forum language.
532 547
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
533 548
 	{
534
-		if ($language === $user_info['language'])
535
-			$context['response_prefix'] = $txt['response_prefix'];
536
-		else
549
+		if ($language === $user_info['language']) {
550
+					$context['response_prefix'] = $txt['response_prefix'];
551
+		} else
537 552
 		{
538 553
 			loadLanguage('index', $language, false);
539 554
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -565,8 +580,9 @@  discard block
 block discarded – undo
565 580
 			list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
566 581
 
567 582
 			// Sanity check
568
-			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
569
-				continue;
583
+			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
584
+							continue;
585
+			}
570 586
 
571 587
 			$linked_calendar_event = array(
572 588
 				'id' => $row['id_event'],
@@ -615,8 +631,9 @@  discard block
 block discarded – undo
615 631
 		}
616 632
 		$smcFunc['db_free_result']($request);
617 633
 
618
-		if (!empty($context['linked_calendar_events']))
619
-			$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
634
+		if (!empty($context['linked_calendar_events'])) {
635
+					$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
636
+		}
620 637
 	}
621 638
 
622 639
 	// Create the poll info if it exists.
@@ -689,20 +706,21 @@  discard block
 block discarded – undo
689 706
 				foreach ($guestinfo as $i => $guestvoted)
690 707
 				{
691 708
 					$guestvoted = explode(',', $guestvoted);
692
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
693
-						break;
709
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
710
+											break;
711
+					}
694 712
 				}
695 713
 				// Has the poll been reset since guest voted?
696 714
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
697 715
 				{
698 716
 					// Remove the poll info from the cookie to allow guest to vote again
699 717
 					unset($guestinfo[$i]);
700
-					if (!empty($guestinfo))
701
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
702
-					else
703
-						unset($_COOKIE['guest_poll_vote']);
704
-				}
705
-				else
718
+					if (!empty($guestinfo)) {
719
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
720
+					} else {
721
+											unset($_COOKIE['guest_poll_vote']);
722
+					}
723
+				} else
706 724
 				{
707 725
 					// What did they vote for?
708 726
 					unset($guestvoted[0], $guestvoted[1]);
@@ -816,23 +834,29 @@  discard block
 block discarded – undo
816 834
 		// Build the poll moderation button array.
817 835
 		$context['poll_buttons'] = array();
818 836
 
819
-		if ($context['allow_return_vote'])
820
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
837
+		if ($context['allow_return_vote']) {
838
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
839
+		}
821 840
 
822
-		if ($context['show_view_results_button'])
823
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
841
+		if ($context['show_view_results_button']) {
842
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
843
+		}
824 844
 
825
-		if ($context['allow_change_vote'])
826
-			$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
845
+		if ($context['allow_change_vote']) {
846
+					$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
847
+		}
827 848
 
828
-		if ($context['allow_lock_poll'])
829
-			$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
849
+		if ($context['allow_lock_poll']) {
850
+					$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
851
+		}
830 852
 
831
-		if ($context['allow_edit_poll'])
832
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
853
+		if ($context['allow_edit_poll']) {
854
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
855
+		}
833 856
 
834
-		if ($context['can_remove_poll'])
835
-			$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
857
+		if ($context['can_remove_poll']) {
858
+					$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
859
+		}
836 860
 
837 861
 		// Allow mods to add additional buttons here
838 862
 		call_integration_hook('integrate_poll_buttons');
@@ -873,8 +897,9 @@  discard block
 block discarded – undo
873 897
 	$all_posters = array();
874 898
 	while ($row = $smcFunc['db_fetch_assoc']($request))
875 899
 	{
876
-		if (!empty($row['id_member']))
877
-			$all_posters[$row['id_msg']] = $row['id_member'];
900
+		if (!empty($row['id_member'])) {
901
+					$all_posters[$row['id_msg']] = $row['id_member'];
902
+		}
878 903
 		$messages[] = $row['id_msg'];
879 904
 	}
880 905
 	$smcFunc['db_free_result']($request);
@@ -886,8 +911,9 @@  discard block
 block discarded – undo
886 911
 	if (!$user_info['is_guest'] && !empty($messages))
887 912
 	{
888 913
 		$mark_at_msg = max($messages);
889
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
890
-			$mark_at_msg = $modSettings['maxMsgID'];
914
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
915
+					$mark_at_msg = $modSettings['maxMsgID'];
916
+		}
891 917
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
892 918
 		{
893 919
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -919,8 +945,9 @@  discard block
 block discarded – undo
919 945
 		while ($row = $smcFunc['db_fetch_assoc']($request))
920 946
 		{
921 947
 			// Find if this topic is marked for notification...
922
-			if (!empty($row['id_topic']))
923
-				$context['is_marked_notify'] = true;
948
+			if (!empty($row['id_topic'])) {
949
+							$context['is_marked_notify'] = true;
950
+			}
924 951
 
925 952
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
926 953
 			if (!empty($row['sent']) && $do_once)
@@ -942,8 +969,9 @@  discard block
 block discarded – undo
942 969
 		}
943 970
 
944 971
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
945
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
946
-			$_SESSION['topicseen_cache'][$board]--;
972
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
973
+					$_SESSION['topicseen_cache'][$board]--;
974
+		}
947 975
 		// Mark board as seen if this is the only new topic.
948 976
 		elseif (isset($_REQUEST['topicseen']))
949 977
 		{
@@ -967,14 +995,16 @@  discard block
 block discarded – undo
967 995
 			$smcFunc['db_free_result']($request);
968 996
 
969 997
 			// If there're no real new topics in this board, mark the board as seen.
970
-			if (empty($numNewTopics))
971
-				$_REQUEST['boardseen'] = true;
972
-			else
973
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
998
+			if (empty($numNewTopics)) {
999
+							$_REQUEST['boardseen'] = true;
1000
+			} else {
1001
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1002
+			}
974 1003
 		}
975 1004
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
976
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
977
-			$_SESSION['topicseen_cache'][$board]--;
1005
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1006
+					$_SESSION['topicseen_cache'][$board]--;
1007
+		}
978 1008
 
979 1009
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
980 1010
 		if (isset($_REQUEST['boardseen']))
@@ -1031,23 +1061,26 @@  discard block
 block discarded – undo
1031 1061
 			$temp = array();
1032 1062
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1033 1063
 			{
1034
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1035
-					continue;
1064
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1065
+									continue;
1066
+				}
1036 1067
 
1037 1068
 				$temp[$row['id_attach']] = $row;
1038 1069
 				$temp[$row['id_attach']]['topic'] = $topic;
1039 1070
 				$temp[$row['id_attach']]['board'] = $board;
1040 1071
 
1041
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1042
-					$context['loaded_attachments'][$row['id_msg']] = array();
1072
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1073
+									$context['loaded_attachments'][$row['id_msg']] = array();
1074
+				}
1043 1075
 			}
1044 1076
 			$smcFunc['db_free_result']($request);
1045 1077
 
1046 1078
 			// This is better than sorting it with the query...
1047 1079
 			ksort($temp);
1048 1080
 
1049
-			foreach ($temp as $row)
1050
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1081
+			foreach ($temp as $row) {
1082
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1083
+			}
1051 1084
 		}
1052 1085
 
1053 1086
 		$msg_parameters = array(
@@ -1074,21 +1107,23 @@  discard block
 block discarded – undo
1074 1107
 		);
1075 1108
 
1076 1109
 		// And the likes
1077
-		if (!empty($modSettings['enable_likes']))
1078
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1110
+		if (!empty($modSettings['enable_likes'])) {
1111
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1112
+		}
1079 1113
 
1080 1114
 		// Go to the last message if the given time is beyond the time of the last message.
1081
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1082
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1115
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1116
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1117
+		}
1083 1118
 
1084 1119
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1085 1120
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1086
-		if (empty($options['view_newest_first']))
1087
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1088
-		else
1089
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1090
-	}
1091
-	else
1121
+		if (empty($options['view_newest_first'])) {
1122
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1123
+		} else {
1124
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1125
+		}
1126
+	} else
1092 1127
 	{
1093 1128
 		$messages_request = false;
1094 1129
 		$context['first_message'] = 0;
@@ -1124,8 +1159,9 @@  discard block
 block discarded – undo
1124 1159
 		'can_see_likes' => 'likes_view',
1125 1160
 		'can_like' => 'likes_like',
1126 1161
 	);
1127
-	foreach ($common_permissions as $contextual => $perm)
1128
-		$context[$contextual] = allowedTo($perm);
1162
+	foreach ($common_permissions as $contextual => $perm) {
1163
+			$context[$contextual] = allowedTo($perm);
1164
+	}
1129 1165
 
1130 1166
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1131 1167
 	$anyown_permissions = array(
@@ -1138,8 +1174,9 @@  discard block
 block discarded – undo
1138 1174
 		'can_reply_unapproved' => 'post_unapproved_replies',
1139 1175
 		'can_view_warning' => 'profile_warning',
1140 1176
 	);
1141
-	foreach ($anyown_permissions as $contextual => $perm)
1142
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1177
+	foreach ($anyown_permissions as $contextual => $perm) {
1178
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1179
+	}
1143 1180
 
1144 1181
 	if (!$user_info['is_admin'] && !$modSettings['topic_move_any'])
1145 1182
 	{
@@ -1185,8 +1222,9 @@  discard block
 block discarded – undo
1185 1222
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1186 1223
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1187 1224
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1188
-	if (!empty($context['drafts_save']))
1189
-		loadLanguage('Drafts');
1225
+	if (!empty($context['drafts_save'])) {
1226
+			loadLanguage('Drafts');
1227
+	}
1190 1228
 
1191 1229
 	// When was the last time this topic was replied to?  Should we warn them about it?
1192 1230
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1247,26 +1285,31 @@  discard block
 block discarded – undo
1247 1285
 	// Message icons - customized icons are off?
1248 1286
 	$context['icons'] = getMessageIcons($board);
1249 1287
 
1250
-	if (!empty($context['icons']))
1251
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1288
+	if (!empty($context['icons'])) {
1289
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1290
+	}
1252 1291
 
1253 1292
 	// Build the normal button array.
1254 1293
 	$context['normal_buttons'] = array();
1255 1294
 
1256
-	if ($context['can_reply'])
1257
-		$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1295
+	if ($context['can_reply']) {
1296
+			$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1297
+	}
1258 1298
 
1259
-	if ($context['can_add_poll'])
1260
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1299
+	if ($context['can_add_poll']) {
1300
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1301
+	}
1261 1302
 
1262
-	if ($context['can_mark_unread'])
1263
-		$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1303
+	if ($context['can_mark_unread']) {
1304
+			$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1305
+	}
1264 1306
 
1265
-	if ($context['can_print'])
1266
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1307
+	if ($context['can_print']) {
1308
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1309
+	}
1267 1310
 
1268
-	if ($context['can_set_notify'])
1269
-		$context['normal_buttons']['notify'] = array(
1311
+	if ($context['can_set_notify']) {
1312
+			$context['normal_buttons']['notify'] = array(
1270 1313
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1271 1314
 			'sub_buttons' => array(
1272 1315
 				array(
@@ -1288,38 +1331,47 @@  discard block
 block discarded – undo
1288 1331
 				),
1289 1332
 			),
1290 1333
 		);
1334
+	}
1291 1335
 
1292 1336
 	// Build the mod button array
1293 1337
 	$context['mod_buttons'] = array();
1294 1338
 
1295
-	if ($context['can_move'])
1296
-		$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1339
+	if ($context['can_move']) {
1340
+			$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1341
+	}
1297 1342
 
1298
-	if ($context['can_delete'])
1299
-		$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1343
+	if ($context['can_delete']) {
1344
+			$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1345
+	}
1300 1346
 
1301
-	if ($context['can_lock'])
1302
-		$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1347
+	if ($context['can_lock']) {
1348
+			$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1349
+	}
1303 1350
 
1304
-	if ($context['can_sticky'])
1305
-		$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1351
+	if ($context['can_sticky']) {
1352
+			$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1353
+	}
1306 1354
 
1307
-	if ($context['can_merge'])
1308
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1355
+	if ($context['can_merge']) {
1356
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1357
+	}
1309 1358
 
1310
-	if ($context['calendar_post'])
1311
-		$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1359
+	if ($context['calendar_post']) {
1360
+			$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1361
+	}
1312 1362
 
1313 1363
 	// Restore topic. eh?  No monkey business.
1314
-	if ($context['can_restore_topic'])
1315
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1364
+	if ($context['can_restore_topic']) {
1365
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1366
+	}
1316 1367
 
1317 1368
 	// Show a message in case a recently posted message became unapproved.
1318 1369
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1319 1370
 
1320 1371
 	// Don't want to show this forever...
1321
-	if ($context['becomesUnapproved'])
1322
-		unset($_SESSION['becomesUnapproved']);
1372
+	if ($context['becomesUnapproved']) {
1373
+			unset($_SESSION['becomesUnapproved']);
1374
+	}
1323 1375
 
1324 1376
 	// Allow adding new mod buttons easily.
1325 1377
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1328,12 +1380,14 @@  discard block
 block discarded – undo
1328 1380
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1329 1381
 
1330 1382
 	// Load the drafts js file
1331
-	if ($context['drafts_autosave'])
1332
-		loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1383
+	if ($context['drafts_autosave']) {
1384
+			loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1385
+	}
1333 1386
 
1334 1387
 	// Spellcheck
1335
-	if ($context['show_spellchecking'])
1336
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1388
+	if ($context['show_spellchecking']) {
1389
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1390
+	}
1337 1391
 
1338 1392
 	// topic.js
1339 1393
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -1367,16 +1421,19 @@  discard block
 block discarded – undo
1367 1421
 	static $counter = null;
1368 1422
 
1369 1423
 	// If the query returned false, bail.
1370
-	if ($messages_request == false)
1371
-		return false;
1424
+	if ($messages_request == false) {
1425
+			return false;
1426
+	}
1372 1427
 
1373 1428
 	// Remember which message this is.  (ie. reply #83)
1374
-	if ($counter === null || $reset)
1375
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1429
+	if ($counter === null || $reset) {
1430
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1431
+	}
1376 1432
 
1377 1433
 	// Start from the beginning...
1378
-	if ($reset)
1379
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1434
+	if ($reset) {
1435
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1436
+	}
1380 1437
 
1381 1438
 	// Attempt to get the next message.
1382 1439
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1390,19 +1447,21 @@  discard block
 block discarded – undo
1390 1447
 	if (empty($context['icon_sources']))
1391 1448
 	{
1392 1449
 		$context['icon_sources'] = array();
1393
-		foreach ($context['stable_icons'] as $icon)
1394
-			$context['icon_sources'][$icon] = 'images_url';
1450
+		foreach ($context['stable_icons'] as $icon) {
1451
+					$context['icon_sources'][$icon] = 'images_url';
1452
+		}
1395 1453
 	}
1396 1454
 
1397 1455
 	// Message Icon Management... check the images exist.
1398 1456
 	if (empty($modSettings['messageIconChecks_disable']))
1399 1457
 	{
1400 1458
 		// If the current icon isn't known, then we need to do something...
1401
-		if (!isset($context['icon_sources'][$message['icon']]))
1402
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1459
+		if (!isset($context['icon_sources'][$message['icon']])) {
1460
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1461
+		}
1462
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1463
+			$context['icon_sources'][$message['icon']] = 'images_url';
1403 1464
 	}
1404
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1405
-		$context['icon_sources'][$message['icon']] = 'images_url';
1406 1465
 
1407 1466
 	// If you're a lazy bum, you probably didn't give a subject...
1408 1467
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1427,8 +1486,7 @@  discard block
 block discarded – undo
1427 1486
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1428 1487
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1429 1488
 		$memberContext[$message['id_member']]['is_guest'] = true;
1430
-	}
1431
-	else
1489
+	} else
1432 1490
 	{
1433 1491
 		// Define this here to make things a bit more readable
1434 1492
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1451,8 +1509,9 @@  discard block
 block discarded – undo
1451 1509
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1452 1510
 
1453 1511
 	// If it's in the recycle bin we need to override whatever icon we did have.
1454
-	if (!empty($board_info['recycle']))
1455
-		$message['icon'] = 'recycled';
1512
+	if (!empty($board_info['recycle'])) {
1513
+			$message['icon'] = 'recycled';
1514
+	}
1456 1515
 
1457 1516
 	require_once($sourcedir . '/Subs-Attachments.php');
1458 1517
 
@@ -1496,32 +1555,36 @@  discard block
 block discarded – undo
1496 1555
 	}
1497 1556
 
1498 1557
 	// Are likes enable?
1499
-	if (!empty($modSettings['enable_likes']))
1500
-		$output['likes'] = array(
1558
+	if (!empty($modSettings['enable_likes'])) {
1559
+			$output['likes'] = array(
1501 1560
 			'count' => $message['likes'],
1502 1561
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1503 1562
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1504 1563
 		);
1564
+	}
1505 1565
 
1506 1566
 	// Is this user the message author?
1507 1567
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1508
-	if (!empty($output['modified']['name']))
1509
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1568
+	if (!empty($output['modified']['name'])) {
1569
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1570
+	}
1510 1571
 
1511 1572
 	// Did they give a reason for editing?
1512
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1513
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1573
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1574
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1575
+	}
1514 1576
 
1515 1577
 	// Any custom profile fields?
1516
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1517
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1578
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1579
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1518 1580
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1581
+	}
1519 1582
 
1520
-	if (empty($options['view_newest_first']))
1521
-		$counter++;
1522
-
1523
-	else
1524
-		$counter--;
1583
+	if (empty($options['view_newest_first'])) {
1584
+			$counter++;
1585
+	} else {
1586
+			$counter--;
1587
+	}
1525 1588
 
1526 1589
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1527 1590
 
@@ -1547,21 +1610,23 @@  discard block
 block discarded – undo
1547 1610
 	$context['no_last_modified'] = true;
1548 1611
 
1549 1612
 	// Prevent a preview image from being displayed twice.
1550
-	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview'))
1551
-		return;
1613
+	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) {
1614
+			return;
1615
+	}
1552 1616
 
1553 1617
 	// Make sure some attachment was requested!
1554
-	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id']))
1555
-		fatal_lang_error('no_access', false);
1618
+	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) {
1619
+			fatal_lang_error('no_access', false);
1620
+	}
1556 1621
 
1557 1622
 	$_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id'];
1558 1623
 
1559 1624
 	// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
1560 1625
 	$attachRequest = null;
1561 1626
 	call_integration_hook('integrate_download_request', array(&$attachRequest));
1562
-	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
1563
-		$request = $attachRequest;
1564
-	else
1627
+	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
1628
+			$request = $attachRequest;
1629
+	} else
1565 1630
 	{
1566 1631
 		// This checks only the current board for $board/$topic's permissions.
1567 1632
 		isAllowedTo('view_attachments');
@@ -1582,19 +1647,21 @@  discard block
 block discarded – undo
1582 1647
 		);
1583 1648
 	}
1584 1649
 
1585
-	if ($smcFunc['db_num_rows']($request) == 0)
1586
-		fatal_lang_error('no_access', false);
1650
+	if ($smcFunc['db_num_rows']($request) == 0) {
1651
+			fatal_lang_error('no_access', false);
1652
+	}
1587 1653
 
1588 1654
 	list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request);
1589 1655
 	$smcFunc['db_free_result']($request);
1590 1656
 
1591 1657
 	// If it isn't yet approved, do they have permission to view it?
1592
-	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3))
1593
-		isAllowedTo('approve_posts');
1658
+	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) {
1659
+			isAllowedTo('approve_posts');
1660
+	}
1594 1661
 
1595 1662
 	// Update the download counter (unless it's a thumbnail).
1596
-	if ($attachment_type != 3)
1597
-		$smcFunc['db_query']('attach_download_increase', '
1663
+	if ($attachment_type != 3) {
1664
+			$smcFunc['db_query']('attach_download_increase', '
1598 1665
 			UPDATE LOW_PRIORITY {db_prefix}attachments
1599 1666
 			SET downloads = downloads + 1
1600 1667
 			WHERE id_attach = {int:id_attach}',
@@ -1602,15 +1669,15 @@  discard block
 block discarded – undo
1602 1669
 				'id_attach' => $id_attach,
1603 1670
 			)
1604 1671
 		);
1672
+	}
1605 1673
 
1606 1674
 	$filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash);
1607 1675
 
1608 1676
 	// This is done to clear any output that was made before now.
1609 1677
 	ob_end_clean();
1610
-	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java')))
1611
-		@ob_start('ob_gzhandler');
1612
-
1613
-	else
1678
+	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) {
1679
+			@ob_start('ob_gzhandler');
1680
+	} else
1614 1681
 	{
1615 1682
 		ob_start();
1616 1683
 		header('Content-Encoding: none');
@@ -1653,8 +1720,9 @@  discard block
 block discarded – undo
1653 1720
 	// Send the attachment headers.
1654 1721
 	header('Pragma: ');
1655 1722
 
1656
-	if (!isBrowser('gecko'))
1657
-		header('Content-Transfer-Encoding: binary');
1723
+	if (!isBrowser('gecko')) {
1724
+			header('Content-Transfer-Encoding: binary');
1725
+	}
1658 1726
 
1659 1727
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
1660 1728
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT');
@@ -1663,18 +1731,19 @@  discard block
 block discarded – undo
1663 1731
 	header('ETag: ' . $eTag);
1664 1732
 
1665 1733
 	// Make sure the mime type warrants an inline display.
1666
-	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0)
1667
-		unset($_REQUEST['image']);
1734
+	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) {
1735
+			unset($_REQUEST['image']);
1736
+	}
1668 1737
 
1669 1738
 	// Does this have a mime type?
1670
-	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
1671
-		header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1672
-
1673
-	else
1739
+	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
1740
+			header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1741
+	} else
1674 1742
 	{
1675 1743
 		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
1676
-		if (isset($_REQUEST['image']))
1677
-			unset($_REQUEST['image']);
1744
+		if (isset($_REQUEST['image'])) {
1745
+					unset($_REQUEST['image']);
1746
+		}
1678 1747
 	}
1679 1748
 
1680 1749
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -1682,23 +1751,22 @@  discard block
 block discarded – undo
1682 1751
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
1683 1752
 
1684 1753
 	// Different browsers like different standards...
1685
-	if (isBrowser('firefox'))
1686
-		header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1687
-
1688
-	elseif (isBrowser('opera'))
1689
-		header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1690
-
1691
-	elseif (isBrowser('ie'))
1692
-		header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1693
-
1694
-	else
1695
-		header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1754
+	if (isBrowser('firefox')) {
1755
+			header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1756
+	} elseif (isBrowser('opera')) {
1757
+			header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1758
+	} elseif (isBrowser('ie')) {
1759
+			header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1760
+	} else {
1761
+			header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1762
+	}
1696 1763
 
1697 1764
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
1698
-	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
1699
-		header('Cache-Control: no-cache');
1700
-	else
1701
-		header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1765
+	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
1766
+			header('Cache-Control: no-cache');
1767
+	} else {
1768
+			header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1769
+	}
1702 1770
 
1703 1771
 	header('Content-Length: ' . filesize($filename));
1704 1772
 
@@ -1708,20 +1776,23 @@  discard block
 block discarded – undo
1708 1776
 	// Recode line endings for text files, if enabled.
1709 1777
 	if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml')))
1710 1778
 	{
1711
-		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false)
1712
-			$callback = function($buffer)
1779
+		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) {
1780
+					$callback = function($buffer)
1713 1781
 			{
1714 1782
 				return preg_replace('~[\r]?\n~', "\r\n", $buffer);
1783
+		}
1715 1784
 			};
1716
-		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false)
1717
-			$callback = function($buffer)
1785
+		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) {
1786
+					$callback = function($buffer)
1718 1787
 			{
1719 1788
 				return preg_replace('~[\r]?\n~', "\r", $buffer);
1789
+		}
1720 1790
 			};
1721
-		else
1722
-			$callback = function($buffer)
1791
+		else {
1792
+					$callback = function($buffer)
1723 1793
 			{
1724 1794
 				return preg_replace('~[\r]?\n~', "\n", $buffer);
1795
+		}
1725 1796
 			};
1726 1797
 	}
1727 1798
 
@@ -1729,23 +1800,26 @@  discard block
 block discarded – undo
1729 1800
 	if (filesize($filename) > 4194304)
1730 1801
 	{
1731 1802
 		// Forcibly end any output buffering going on.
1732
-		while (@ob_get_level() > 0)
1733
-			@ob_end_clean();
1803
+		while (@ob_get_level() > 0) {
1804
+					@ob_end_clean();
1805
+		}
1734 1806
 
1735 1807
 		$fp = fopen($filename, 'rb');
1736 1808
 		while (!feof($fp))
1737 1809
 		{
1738
-			if (isset($callback))
1739
-				echo $callback(fread($fp, 8192));
1740
-			else
1741
-				echo fread($fp, 8192);
1810
+			if (isset($callback)) {
1811
+							echo $callback(fread($fp, 8192));
1812
+			} else {
1813
+							echo fread($fp, 8192);
1814
+			}
1742 1815
 			flush();
1743 1816
 		}
1744 1817
 		fclose($fp);
1745 1818
 	}
1746 1819
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
1747
-	elseif (isset($callback) || @readfile($filename) === null)
1748
-		echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1820
+	elseif (isset($callback) || @readfile($filename) === null) {
1821
+			echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1822
+	}
1749 1823
 
1750 1824
 	obExit(false);
1751 1825
 }
@@ -1758,8 +1832,9 @@  discard block
 block discarded – undo
1758 1832
  */
1759 1833
 function approved_attach_sort($a, $b)
1760 1834
 {
1761
-	if ($a['is_approved'] == $b['is_approved'])
1762
-		return 0;
1835
+	if ($a['is_approved'] == $b['is_approved']) {
1836
+			return 0;
1837
+	}
1763 1838
 
1764 1839
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1765 1840
 }
@@ -1776,16 +1851,19 @@  discard block
 block discarded – undo
1776 1851
 
1777 1852
 	require_once($sourcedir . '/RemoveTopic.php');
1778 1853
 
1779
-	if (empty($_REQUEST['msgs']))
1780
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1854
+	if (empty($_REQUEST['msgs'])) {
1855
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1856
+	}
1781 1857
 
1782 1858
 	$messages = array();
1783
-	foreach ($_REQUEST['msgs'] as $dummy)
1784
-		$messages[] = (int) $dummy;
1859
+	foreach ($_REQUEST['msgs'] as $dummy) {
1860
+			$messages[] = (int) $dummy;
1861
+	}
1785 1862
 
1786 1863
 	// We are restoring messages. We handle this in another place.
1787
-	if (isset($_REQUEST['restore_selected']))
1788
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1864
+	if (isset($_REQUEST['restore_selected'])) {
1865
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1866
+	}
1789 1867
 	if (isset($_REQUEST['split_selection']))
1790 1868
 	{
1791 1869
 		$request = $smcFunc['db_query']('', '
@@ -1804,8 +1882,9 @@  discard block
 block discarded – undo
1804 1882
 	}
1805 1883
 
1806 1884
 	// Allowed to delete any message?
1807
-	if (allowedTo('delete_any'))
1808
-		$allowed_all = true;
1885
+	if (allowedTo('delete_any')) {
1886
+			$allowed_all = true;
1887
+	}
1809 1888
 	// Allowed to delete replies to their messages?
1810 1889
 	elseif (allowedTo('delete_replies'))
1811 1890
 	{
@@ -1822,13 +1901,14 @@  discard block
 block discarded – undo
1822 1901
 		$smcFunc['db_free_result']($request);
1823 1902
 
1824 1903
 		$allowed_all = $starter == $user_info['id'];
1904
+	} else {
1905
+			$allowed_all = false;
1825 1906
 	}
1826
-	else
1827
-		$allowed_all = false;
1828 1907
 
1829 1908
 	// Make sure they're allowed to delete their own messages, if not any.
1830
-	if (!$allowed_all)
1831
-		isAllowedTo('delete_own');
1909
+	if (!$allowed_all) {
1910
+			isAllowedTo('delete_own');
1911
+	}
1832 1912
 
1833 1913
 	// Allowed to remove which messages?
1834 1914
 	$request = $smcFunc['db_query']('', '
@@ -1848,8 +1928,9 @@  discard block
 block discarded – undo
1848 1928
 	$messages = array();
1849 1929
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1850 1930
 	{
1851
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1852
-			continue;
1931
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1932
+					continue;
1933
+		}
1853 1934
 
1854 1935
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1855 1936
 	}
@@ -1872,17 +1953,20 @@  discard block
 block discarded – undo
1872 1953
 	foreach ($messages as $message => $info)
1873 1954
 	{
1874 1955
 		// Just skip the first message - if it's not the last.
1875
-		if ($message == $first_message && $message != $last_message)
1876
-			continue;
1956
+		if ($message == $first_message && $message != $last_message) {
1957
+					continue;
1958
+		}
1877 1959
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1878
-		elseif ($message == $first_message)
1879
-			$topicGone = true;
1960
+		elseif ($message == $first_message) {
1961
+					$topicGone = true;
1962
+		}
1880 1963
 
1881 1964
 		removeMessage($message);
1882 1965
 
1883 1966
 		// Log this moderation action ;).
1884
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1885
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1967
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
1968
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1969
+		}
1886 1970
 	}
1887 1971
 
1888 1972
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Sources/CacheAPI-zend.php 1 patch
Braces   +15 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * Our Cache API class
@@ -27,8 +28,9 @@  discard block
 block discarded – undo
27 28
 	{
28 29
 		$supported = function_exists('zend_shm_cache_fetch') || function_exists('output_cache_get');
29 30
 
30
-		if ($test)
31
-			return $supported;
31
+		if ($test) {
32
+					return $supported;
33
+		}
32 34
 		return parent::isSupported() && $supported;
33 35
 	}
34 36
 
@@ -40,10 +42,11 @@  discard block
 block discarded – undo
40 42
 		$key = $this->prefix . strtr($key, ':/', '-_');
41 43
 
42 44
 		// Zend's pricey stuff.
43
-		if (function_exists('zend_shm_cache_fetch'))
44
-			return zend_shm_cache_fetch('SMF::' . $key);
45
-		elseif (function_exists('output_cache_get'))
46
-			return output_cache_get($key, $ttl);
45
+		if (function_exists('zend_shm_cache_fetch')) {
46
+					return zend_shm_cache_fetch('SMF::' . $key);
47
+		} elseif (function_exists('output_cache_get')) {
48
+					return output_cache_get($key, $ttl);
49
+		}
47 50
 	}
48 51
 
49 52
 	/**
@@ -53,10 +56,11 @@  discard block
 block discarded – undo
53 56
 	{
54 57
 		$key = $this->prefix . strtr($key, ':/', '-_');
55 58
 
56
-		if (function_exists('zend_shm_cache_store'))
57
-			return zend_shm_cache_store('SMF::' . $key, $value, $ttl);
58
-		elseif (function_exists('output_cache_put'))
59
-			return output_cache_put($key, $value);
59
+		if (function_exists('zend_shm_cache_store')) {
60
+					return zend_shm_cache_store('SMF::' . $key, $value, $ttl);
61
+		} elseif (function_exists('output_cache_put')) {
62
+					return output_cache_put($key, $value);
63
+		}
60 64
 	}
61 65
 
62 66
 	/**
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 1 patch
Braces   +297 added lines, -224 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -54,21 +57,25 @@  discard block
 block discarded – undo
54 57
 
55 58
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
56 59
 	{
57
-			if (!is_array($modSettings['attachment_basedirectories']))
58
-				$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
60
+			if (!is_array($modSettings['attachment_basedirectories'])) {
61
+							$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
62
+			}
59 63
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
64
+	} else {
65
+			$base_dir = 0;
60 66
 	}
61
-	else
62
-		$base_dir = 0;
63 67
 
64 68
 	if ($modSettings['automanage_attachments'] == 1)
65 69
 	{
66
-		if (!isset($modSettings['last_attachments_directory']))
67
-			$modSettings['last_attachments_directory'] = array();
68
-		if (!is_array($modSettings['last_attachments_directory']))
69
-			$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
70
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
71
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
70
+		if (!isset($modSettings['last_attachments_directory'])) {
71
+					$modSettings['last_attachments_directory'] = array();
72
+		}
73
+		if (!is_array($modSettings['last_attachments_directory'])) {
74
+					$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
75
+		}
76
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
77
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
78
+		}
72 79
 	}
73 80
 
74 81
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -97,12 +104,14 @@  discard block
 block discarded – undo
97 104
 			$updir = '';
98 105
 	}
99 106
 
100
-	if (!is_array($modSettings['attachmentUploadDir']))
101
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
102
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
103
-		$outputCreation = automanage_attachments_create_directory($updir);
104
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
105
-		$outputCreation = true;
107
+	if (!is_array($modSettings['attachmentUploadDir'])) {
108
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
109
+	}
110
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
111
+			$outputCreation = automanage_attachments_create_directory($updir);
112
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
113
+			$outputCreation = true;
114
+	}
106 115
 
107 116
 	if ($outputCreation)
108 117
 	{
@@ -139,8 +148,9 @@  discard block
 block discarded – undo
139 148
 		$count = count($tree);
140 149
 
141 150
 		$directory = attachments_init_dir($tree, $count);
142
-		if ($directory === false)
143
-			return false;
151
+		if ($directory === false) {
152
+					return false;
153
+		}
144 154
 	}
145 155
 
146 156
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -168,8 +178,9 @@  discard block
 block discarded – undo
168 178
 	}
169 179
 
170 180
 	// Everything seems fine...let's create the .htaccess
171
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
172
-		secureDirectory($updir, true);
181
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
182
+			secureDirectory($updir, true);
183
+	}
173 184
 
174 185
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
175 186
 	$updir = rtrim($updir, $sep);
@@ -201,8 +212,9 @@  discard block
 block discarded – undo
201 212
 {
202 213
 	global $modSettings, $boarddir;
203 214
 
204
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
205
-		return;
215
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
216
+			return;
217
+	}
206 218
 
207 219
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
208 220
 	// Just to be sure: I don't want directory separators at the end
@@ -214,13 +226,14 @@  discard block
 block discarded – undo
214 226
 	{
215 227
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
216 228
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
229
+	} else {
230
+			$base_dir = 0;
217 231
 	}
218
-	else
219
-		$base_dir = 0;
220 232
 
221 233
 	// Get the last attachment directory for that base directory
222
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
223
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
234
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
235
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
236
+	}
224 237
 	// And increment it.
225 238
 	$modSettings['last_attachments_directory'][$base_dir]++;
226 239
 
@@ -235,10 +248,10 @@  discard block
 block discarded – undo
235 248
 		$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
236 249
 
237 250
 		return true;
251
+	} else {
252
+			return false;
253
+	}
238 254
 	}
239
-	else
240
-		return false;
241
-}
242 255
 
243 256
 /**
244 257
  * Split a path into a list of all directories and subdirectories
@@ -256,12 +269,13 @@  discard block
 block discarded – undo
256 269
 			* in Windows we need to explode for both \ and /
257 270
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
258 271
 	*/
259
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
260
-		$tree = preg_split('#[\\\/]#', $directory);
261
-	else
272
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
273
+			$tree = preg_split('#[\\\/]#', $directory);
274
+	} else
262 275
 	{
263
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
264
-			return false;
276
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
277
+					return false;
278
+		}
265 279
 
266 280
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
267 281
 	}
@@ -285,10 +299,11 @@  discard block
 block discarded – undo
285 299
 		 //Better be sure that the first part of the path is actually a drive letter...
286 300
 		 //...even if, I should check this in the admin page...isn't it?
287 301
 		 //...NHAAA Let's leave space for users' complains! :P
288
-		if (preg_match('/^[a-z]:$/i', $tree[0]))
289
-			$directory = array_shift($tree);
290
-		else
291
-			return false;
302
+		if (preg_match('/^[a-z]:$/i', $tree[0])) {
303
+					$directory = array_shift($tree);
304
+		} else {
305
+					return false;
306
+		}
292 307
 
293 308
 		$count--;
294 309
 	}
@@ -303,18 +318,20 @@  discard block
 block discarded – undo
303 318
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
304 319
 
305 320
 	// Make sure we're uploading to the right place.
306
-	if (!empty($modSettings['automanage_attachments']))
307
-		automanage_attachments_check_directory();
321
+	if (!empty($modSettings['automanage_attachments'])) {
322
+			automanage_attachments_check_directory();
323
+	}
308 324
 
309
-	if (!is_array($modSettings['attachmentUploadDir']))
310
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
325
+	if (!is_array($modSettings['attachmentUploadDir'])) {
326
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
327
+	}
311 328
 
312 329
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
313 330
 
314 331
 	// Is the attachments folder actualy there?
315
-	if (!empty($context['dir_creation_error']))
316
-		$initial_error = $context['dir_creation_error'];
317
-	elseif (!is_dir($context['attach_dir']))
332
+	if (!empty($context['dir_creation_error'])) {
333
+			$initial_error = $context['dir_creation_error'];
334
+	} elseif (!is_dir($context['attach_dir']))
318 335
 	{
319 336
 		$initial_error = 'attach_folder_warning';
320 337
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -337,12 +354,12 @@  discard block
 block discarded – undo
337 354
 			);
338 355
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
339 356
 			$smcFunc['db_free_result']($request);
340
-		}
341
-		else
342
-			$context['attachments'] = array(
357
+		} else {
358
+					$context['attachments'] = array(
343 359
 				'quantity' => 0,
344 360
 				'total_size' => 0,
345 361
 			);
362
+		}
346 363
 	}
347 364
 
348 365
 	// Hmm. There are still files in session.
@@ -352,39 +369,44 @@  discard block
 block discarded – undo
352 369
 		// Let's try to keep them. But...
353 370
 		$ignore_temp = true;
354 371
 		// If new files are being added. We can't ignore those
355
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
356
-			if (!empty($dummy))
372
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
373
+					if (!empty($dummy))
357 374
 			{
358 375
 				$ignore_temp = false;
376
+		}
359 377
 				break;
360 378
 			}
361 379
 
362 380
 		// Need to make space for the new files. So, bye bye.
363 381
 		if (!$ignore_temp)
364 382
 		{
365
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
366
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
383
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
384
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
367 385
 					unlink($attachment['tmp_name']);
386
+			}
368 387
 
369 388
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
370 389
 			$_SESSION['temp_attachments'] = array();
371 390
 		}
372 391
 	}
373 392
 
374
-	if (!isset($_FILES['attachment']['name']))
375
-		$_FILES['attachment']['tmp_name'] = array();
393
+	if (!isset($_FILES['attachment']['name'])) {
394
+			$_FILES['attachment']['tmp_name'] = array();
395
+	}
376 396
 
377
-	if (!isset($_SESSION['temp_attachments']))
378
-		$_SESSION['temp_attachments'] = array();
397
+	if (!isset($_SESSION['temp_attachments'])) {
398
+			$_SESSION['temp_attachments'] = array();
399
+	}
379 400
 
380 401
 	// Remember where we are at. If it's anywhere at all.
381
-	if (!$ignore_temp)
382
-		$_SESSION['temp_attachments']['post'] = array(
402
+	if (!$ignore_temp) {
403
+			$_SESSION['temp_attachments']['post'] = array(
383 404
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
384 405
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
385 406
 			'topic' => !empty($topic) ? $topic : 0,
386 407
 			'board' => !empty($board) ? $board : 0,
387 408
 		);
409
+	}
388 410
 
389 411
 	// If we have an initial error, lets just display it.
390 412
 	if (!empty($initial_error))
@@ -392,9 +414,10 @@  discard block
 block discarded – undo
392 414
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
393 415
 
394 416
 		// And delete the files 'cos they ain't going nowhere.
395
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
396
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
417
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
418
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
397 419
 				unlink($_FILES['attachment']['tmp_name'][$n]);
420
+		}
398 421
 
399 422
 		$_FILES['attachment']['tmp_name'] = array();
400 423
 	}
@@ -402,21 +425,24 @@  discard block
 block discarded – undo
402 425
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
403 426
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
404 427
 	{
405
-		if ($_FILES['attachment']['name'][$n] == '')
406
-			continue;
428
+		if ($_FILES['attachment']['name'][$n] == '') {
429
+					continue;
430
+		}
407 431
 
408 432
 		// First, let's first check for PHP upload errors.
409 433
 		$errors = array();
410 434
 		if (!empty($_FILES['attachment']['error'][$n]))
411 435
 		{
412
-			if ($_FILES['attachment']['error'][$n] == 2)
413
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
414
-			elseif ($_FILES['attachment']['error'][$n] == 6)
415
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
416
-			else
417
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
418
-			if (empty($errors))
419
-				$errors[] = 'attach_php_error';
436
+			if ($_FILES['attachment']['error'][$n] == 2) {
437
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
438
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
439
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
440
+			} else {
441
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
442
+			}
443
+			if (empty($errors)) {
444
+							$errors[] = 'attach_php_error';
445
+			}
420 446
 		}
421 447
 
422 448
 		// Try to move and rename the file before doing any more checks on it.
@@ -426,8 +452,9 @@  discard block
 block discarded – undo
426 452
 		{
427 453
 			// The reported MIME type of the attachment might not be reliable.
428 454
 			// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
429
-			if (function_exists('mime_content_type'))
430
-				$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
455
+			if (function_exists('mime_content_type')) {
456
+							$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
457
+			}
431 458
 
432 459
 			$_SESSION['temp_attachments'][$attachID] = array(
433 460
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -439,16 +466,16 @@  discard block
 block discarded – undo
439 466
 			);
440 467
 
441 468
 			// Move the file to the attachments folder with a temp name for now.
442
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
443
-				smf_chmod($destName, 0644);
444
-			else
469
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
470
+							smf_chmod($destName, 0644);
471
+			} else
445 472
 			{
446 473
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
447
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
448
-					unlink($_FILES['attachment']['tmp_name'][$n]);
474
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
475
+									unlink($_FILES['attachment']['tmp_name'][$n]);
476
+				}
449 477
 			}
450
-		}
451
-		else
478
+		} else
452 479
 		{
453 480
 			$_SESSION['temp_attachments'][$attachID] = array(
454 481
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -456,12 +483,14 @@  discard block
 block discarded – undo
456 483
 				'errors' => $errors,
457 484
 			);
458 485
 
459
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
460
-				unlink($_FILES['attachment']['tmp_name'][$n]);
486
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
487
+							unlink($_FILES['attachment']['tmp_name'][$n]);
488
+			}
461 489
 		}
462 490
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
463
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
464
-			attachmentChecks($attachID);
491
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
492
+					attachmentChecks($attachID);
493
+		}
465 494
 	}
466 495
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
467 496
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -488,21 +517,20 @@  discard block
 block discarded – undo
488 517
 	global $modSettings, $context, $sourcedir, $smcFunc;
489 518
 
490 519
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
491
-	if (empty($_SESSION['temp_attachments'][$attachID]))
492
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
493
-
494
-	elseif (empty($attachID))
495
-		$error = '$attachID';
496
-
497
-	elseif (empty($context['attachments']))
498
-		$error = '$context[\'attachments\']';
499
-
500
-	elseif (empty($context['attach_dir']))
501
-		$error = '$context[\'attach_dir\']';
520
+	if (empty($_SESSION['temp_attachments'][$attachID])) {
521
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
522
+	} elseif (empty($attachID)) {
523
+			$error = '$attachID';
524
+	} elseif (empty($context['attachments'])) {
525
+			$error = '$context[\'attachments\']';
526
+	} elseif (empty($context['attach_dir'])) {
527
+			$error = '$context[\'attach_dir\']';
528
+	}
502 529
 
503 530
 	// Let's get their attention.
504
-	if (!empty($error))
505
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
531
+	if (!empty($error)) {
532
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
533
+	}
506 534
 
507 535
 	// Just in case this slipped by the first checks, we stop it here and now
508 536
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -531,8 +559,9 @@  discard block
 block discarded – undo
531 559
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
532 560
 			if (!(empty($size)) && ($size[2] != $old_format))
533 561
 			{
534
-				if (isset($context['validImageTypes'][$size[2]]))
535
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
562
+				if (isset($context['validImageTypes'][$size[2]])) {
563
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
564
+				}
536 565
 			}
537 566
 		}
538 567
 	}
@@ -586,42 +615,48 @@  discard block
 block discarded – undo
586 615
 				// Or, let the user know that it ain't gonna happen.
587 616
 				else
588 617
 				{
589
-					if (isset($context['dir_creation_error']))
590
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
591
-					else
592
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
618
+					if (isset($context['dir_creation_error'])) {
619
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
620
+					} else {
621
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
622
+					}
593 623
 				}
624
+			} else {
625
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
594 626
 			}
595
-			else
596
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
597 627
 		}
598 628
 	}
599 629
 
600 630
 	// Is the file too big?
601 631
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
602
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
632
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
634
+	}
604 635
 
605 636
 	// Check the total upload size for this post...
606
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
607
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
637
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
638
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
639
+	}
608 640
 
609 641
 	// Have we reached the maximum number of files we are allowed?
610 642
 	$context['attachments']['quantity']++;
611 643
 
612 644
 	// Set a max limit if none exists
613
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
614
-		$modSettings['attachmentNumPerPostLimit'] = 50;
645
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
646
+			$modSettings['attachmentNumPerPostLimit'] = 50;
647
+	}
615 648
 
616
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
617
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
649
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
650
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
651
+	}
618 652
 
619 653
 	// File extension check
620 654
 	if (!empty($modSettings['attachmentCheckExtensions']))
621 655
 	{
622 656
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
623
-		foreach ($allowed as $k => $dummy)
624
-			$allowed[$k] = trim($dummy);
657
+		foreach ($allowed as $k => $dummy) {
658
+					$allowed[$k] = trim($dummy);
659
+		}
625 660
 
626 661
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
627 662
 		{
@@ -633,10 +668,12 @@  discard block
 block discarded – undo
633 668
 	// Undo the math if there's an error
634 669
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
635 670
 	{
636
-		if (isset($context['dir_size']))
637
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
638
-		if (isset($context['dir_files']))
639
-			$context['dir_files']--;
671
+		if (isset($context['dir_size'])) {
672
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
673
+		}
674
+		if (isset($context['dir_files'])) {
675
+					$context['dir_files']--;
676
+		}
640 677
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
641 678
 		$context['attachments']['quantity']--;
642 679
 		return false;
@@ -668,12 +705,14 @@  discard block
 block discarded – undo
668 705
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
669 706
 	{
670 707
 		// Got a proper mime type?
671
-		if (!empty($size['mime']))
672
-			$attachmentOptions['mime_type'] = $size['mime'];
708
+		if (!empty($size['mime'])) {
709
+					$attachmentOptions['mime_type'] = $size['mime'];
710
+		}
673 711
 
674 712
 		// Otherwise a valid one?
675
-		elseif (isset($context['validImageTypes'][$size[2]]))
676
-			$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
713
+		elseif (isset($context['validImageTypes'][$size[2]])) {
714
+					$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
715
+		}
677 716
 	}
678 717
 
679 718
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -685,15 +724,17 @@  discard block
 block discarded – undo
685 724
 	}
686 725
 
687 726
 	// Get the hash if no hash has been given yet.
688
-	if (empty($attachmentOptions['file_hash']))
689
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
727
+	if (empty($attachmentOptions['file_hash'])) {
728
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
729
+	}
690 730
 
691 731
 	// Assuming no-one set the extension let's take a look at it.
692 732
 	if (empty($attachmentOptions['fileext']))
693 733
 	{
694 734
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
695
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
696
-			$attachmentOptions['fileext'] = '';
735
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
736
+					$attachmentOptions['fileext'] = '';
737
+		}
697 738
 	}
698 739
 
699 740
 	// Last chance to change stuff!
@@ -702,8 +743,9 @@  discard block
 block discarded – undo
702 743
 	// Make sure the folder is valid...
703 744
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true);
704 745
 	$folders = array_keys($tmp);
705
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
706
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
746
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
747
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
748
+	}
707 749
 
708 750
 	$attachmentOptions['id'] = $smcFunc['db_insert']('',
709 751
 		'{db_prefix}attachments',
@@ -734,8 +776,8 @@  discard block
 block discarded – undo
734 776
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
735 777
 
736 778
 	// If it's not approved then add to the approval queue.
737
-	if (!$attachmentOptions['approved'])
738
-		$smcFunc['db_insert']('',
779
+	if (!$attachmentOptions['approved']) {
780
+			$smcFunc['db_insert']('',
739 781
 			'{db_prefix}approval_queue',
740 782
 			array(
741 783
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -745,9 +787,11 @@  discard block
 block discarded – undo
745 787
 			),
746 788
 			array()
747 789
 		);
790
+	}
748 791
 
749
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
750
-		return true;
792
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
793
+			return true;
794
+	}
751 795
 
752 796
 	// Like thumbnails, do we?
753 797
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -758,13 +802,15 @@  discard block
 block discarded – undo
758 802
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
759 803
 			list ($thumb_width, $thumb_height) = $size;
760 804
 
761
-			if (!empty($size['mime']))
762
-				$thumb_mime = $size['mime'];
763
-			elseif (isset($context['validImageTypes'][$size[2]]))
764
-				$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
805
+			if (!empty($size['mime'])) {
806
+							$thumb_mime = $size['mime'];
807
+			} elseif (isset($context['validImageTypes'][$size[2]])) {
808
+							$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
809
+			}
765 810
 			// Lord only knows how this happened...
766
-			else
767
-				$thumb_mime = '';
811
+			else {
812
+							$thumb_mime = '';
813
+			}
768 814
 
769 815
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
770 816
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -844,15 +890,17 @@  discard block
 block discarded – undo
844 890
 	global $smcFunc;
845 891
 
846 892
 	// Oh, come on!
847
-	if (empty($attachIDs) || empty($msgID))
848
-		return false;
893
+	if (empty($attachIDs) || empty($msgID)) {
894
+			return false;
895
+	}
849 896
 
850 897
 	// "I see what is right and approve, but I do what is wrong."
851 898
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
852 899
 
853 900
 	// One last check
854
-	if (empty($attachIDs))
855
-		return false;
901
+	if (empty($attachIDs)) {
902
+			return false;
903
+	}
856 904
 
857 905
 	// Perform.
858 906
 	$smcFunc['db_query']('', '
@@ -880,8 +928,9 @@  discard block
 block discarded – undo
880 928
 	global $board, $modSettings, $context, $scripturl, $smcFunc;
881 929
 
882 930
 	// Meh...
883
-	if (empty($attachID))
884
-		return 'attachments_no_data_loaded';
931
+	if (empty($attachID)) {
932
+			return 'attachments_no_data_loaded';
933
+	}
885 934
 
886 935
 	// Make it easy.
887 936
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -890,20 +939,23 @@  discard block
 block discarded – undo
890 939
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
891 940
 
892 941
 	// "I am innocent of the blood of this just person: see ye to it."
893
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
894
-		return $externalParse;
942
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
943
+			return $externalParse;
944
+	}
895 945
 
896 946
 	//Are attachments enable?
897
-	if (empty($modSettings['attachmentEnable']))
898
-		return 'attachments_not_enable';
947
+	if (empty($modSettings['attachmentEnable'])) {
948
+			return 'attachments_not_enable';
949
+	}
899 950
 
900 951
 	// Previewing much? no msg ID has been set yet.
901 952
 	if (!empty($context['preview_message']))
902 953
 	{
903 954
 		$allAttachments = getAttachsByMsg(0);
904 955
 
905
-		if (empty($allAttachments[0][$attachID]))
906
-			return 'attachments_no_data_loaded';
956
+		if (empty($allAttachments[0][$attachID])) {
957
+					return 'attachments_no_data_loaded';
958
+		}
907 959
 
908 960
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
909 961
 
@@ -915,57 +967,66 @@  discard block
 block discarded – undo
915 967
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
916 968
 
917 969
 		// Fix the thumbnail too, if the image has one.
918
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
919
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
970
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
971
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		}
920 973
 
921 974
 		return $attachContext;
922 975
 	}
923 976
 
924 977
 	// There is always the chance someone else has already done our dirty work...
925 978
 	// If so, all pertinent checks were already done. Hopefully...
926
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
927
-		return $context['current_attachments'][$attachID];
979
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
980
+			return $context['current_attachments'][$attachID];
981
+	}
928 982
 
929 983
 	// If we are lucky enough to be in $board's scope then check it!
930
-	if (!empty($board) && !allowedTo('view_attachments', $board))
931
-		return 'attachments_not_allowed_to_see';
984
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
985
+			return 'attachments_not_allowed_to_see';
986
+	}
932 987
 
933 988
 	// Get the message info associated with this particular attach ID.
934 989
 	$attachInfo = getAttachMsgInfo($attachID);
935 990
 
936 991
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
937
-	if (empty($attachInfo) || empty($attachInfo['msg']))
938
-		return 'attachments_no_msg_associated';
992
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
993
+			return 'attachments_no_msg_associated';
994
+	}
939 995
 
940 996
 	// Hold it! got the info now check if you can see this attachment.
941
-	if (!allowedTo('view_attachments', $attachInfo['board']))
942
-		return 'attachments_not_allowed_to_see';
997
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
998
+			return 'attachments_not_allowed_to_see';
999
+	}
943 1000
 
944 1001
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
945 1002
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
946 1003
 
947 1004
 	// No point in keep going further.
948
-	if (!allowedTo('view_attachments', $attachContext['board']))
949
-		return 'attachments_not_allowed_to_see';
1005
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1006
+			return 'attachments_not_allowed_to_see';
1007
+	}
950 1008
 
951 1009
 	// Load this particular attach's context.
952
-	if (!empty($attachContext))
953
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1010
+	if (!empty($attachContext)) {
1011
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	}
954 1013
 
955 1014
 	// One last check, you know, gotta be paranoid...
956
-	else
957
-		return 'attachments_no_data_loaded';
1015
+	else {
1016
+			return 'attachments_no_data_loaded';
1017
+	}
958 1018
 
959 1019
 	// This is the last "if" I promise!
960
-	if (empty($attachLoaded))
961
-		return 'attachments_no_data_loaded';
962
-
963
-	else
964
-		$attachContext = $attachLoaded[$attachID];
1020
+	if (empty($attachLoaded)) {
1021
+			return 'attachments_no_data_loaded';
1022
+	} else {
1023
+			$attachContext = $attachLoaded[$attachID];
1024
+	}
965 1025
 
966 1026
 	// You may or may not want to show this under the post.
967
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
968
-		$context['show_attach_under_post'][$attachID] = $attachID;
1027
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1028
+			$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	}
969 1030
 
970 1031
 	// Last minute changes?
971 1032
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -985,8 +1046,9 @@  discard block
 block discarded – undo
985 1046
 {
986 1047
 	global $smcFunc, $modSettings;
987 1048
 
988
-	if (empty($attachIDs))
989
-		return array();
1049
+	if (empty($attachIDs)) {
1050
+			return array();
1051
+	}
990 1052
 
991 1053
 	$return = array();
992 1054
 
@@ -1002,11 +1064,12 @@  discard block
 block discarded – undo
1002 1064
 		)
1003 1065
 	);
1004 1066
 
1005
-	if ($smcFunc['db_num_rows']($request) != 1)
1006
-		return array();
1067
+	if ($smcFunc['db_num_rows']($request) != 1) {
1068
+			return array();
1069
+	}
1007 1070
 
1008
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1009
-		$return[$row['id_attach']] = array(
1071
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1072
+			$return[$row['id_attach']] = array(
1010 1073
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1011 1074
 			'size' => $row['size'],
1012 1075
 			'attachID' => $row['id_attach'],
@@ -1015,6 +1078,7 @@  discard block
 block discarded – undo
1015 1078
 			'mime_type' => $row['mime_type'],
1016 1079
 			'thumb' => $row['id_thumb'],
1017 1080
 		);
1081
+	}
1018 1082
 	$smcFunc['db_free_result']($request);
1019 1083
 
1020 1084
 	return $return;
@@ -1031,8 +1095,9 @@  discard block
 block discarded – undo
1031 1095
 {
1032 1096
 	global $smcFunc;
1033 1097
 
1034
-	if (empty($attachID))
1035
-		return array();
1098
+	if (empty($attachID)) {
1099
+			return array();
1100
+	}
1036 1101
 
1037 1102
 	$request = $smcFunc['db_query']('', '
1038 1103
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1045,8 +1110,9 @@  discard block
 block discarded – undo
1045 1110
 		)
1046 1111
 	);
1047 1112
 
1048
-	if ($smcFunc['db_num_rows']($request) != 1)
1049
-		return array();
1113
+	if ($smcFunc['db_num_rows']($request) != 1) {
1114
+			return array();
1115
+	}
1050 1116
 
1051 1117
 	$row = $smcFunc['db_fetch_assoc']($request);
1052 1118
 	$smcFunc['db_free_result']($request);
@@ -1087,8 +1153,9 @@  discard block
 block discarded – undo
1087 1153
 		$temp = array();
1088 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1089 1155
 		{
1090
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1091
-				continue;
1156
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1157
+							continue;
1158
+			}
1092 1159
 
1093 1160
 			$temp[$row['id_attach']] = $row;
1094 1161
 		}
@@ -1117,8 +1184,9 @@  discard block
 block discarded – undo
1117 1184
 {
1118 1185
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1119 1186
 
1120
-	if (empty($attachments) || empty($attachments[$id_msg]))
1121
-		return array();
1187
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1188
+			return array();
1189
+	}
1122 1190
 
1123 1191
 	// Set up the attachment info - based on code by Meriadoc.
1124 1192
 	$attachmentData = array();
@@ -1142,11 +1210,13 @@  discard block
 block discarded – undo
1142 1210
 			);
1143 1211
 
1144 1212
 			// If something is unapproved we'll note it so we can sort them.
1145
-			if (!$attachment['approved'])
1146
-				$have_unapproved = true;
1213
+			if (!$attachment['approved']) {
1214
+							$have_unapproved = true;
1215
+			}
1147 1216
 
1148
-			if (!$attachmentData[$i]['is_image'])
1149
-				continue;
1217
+			if (!$attachmentData[$i]['is_image']) {
1218
+							continue;
1219
+			}
1150 1220
 
1151 1221
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1152 1222
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1167,11 +1237,11 @@  discard block
 block discarded – undo
1167 1237
 						// So what folder are we putting this image in?
1168 1238
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1169 1239
 						{
1170
-							if (!is_array($modSettings['attachmentUploadDir']))
1171
-								$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1240
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1241
+															$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1242
+							}
1172 1243
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1173
-						}
1174
-						else
1244
+						} else
1175 1245
 						{
1176 1246
 							$id_folder_thumb = 1;
1177 1247
 						}
@@ -1185,10 +1255,11 @@  discard block
 block discarded – undo
1185 1255
 						$thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : '';
1186 1256
 
1187 1257
 						// Figure out the mime type.
1188
-						if (!empty($size['mime']))
1189
-							$thumb_mime = $size['mime'];
1190
-						else
1191
-							$thumb_mime = 'image/' . $thumb_ext;
1258
+						if (!empty($size['mime'])) {
1259
+													$thumb_mime = $size['mime'];
1260
+						} else {
1261
+													$thumb_mime = 'image/' . $thumb_ext;
1262
+						}
1192 1263
 
1193 1264
 						$thumb_filename = $attachment['filename'] . '_thumb';
1194 1265
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1235,11 +1306,12 @@  discard block
 block discarded – undo
1235 1306
 				}
1236 1307
 			}
1237 1308
 
1238
-			if (!empty($attachment['id_thumb']))
1239
-				$attachmentData[$i]['thumbnail'] = array(
1309
+			if (!empty($attachment['id_thumb'])) {
1310
+							$attachmentData[$i]['thumbnail'] = array(
1240 1311
 					'id' => $attachment['id_thumb'],
1241 1312
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1242 1313
 				);
1314
+			}
1243 1315
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1244 1316
 
1245 1317
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1249,30 +1321,31 @@  discard block
 block discarded – undo
1249 1321
 				{
1250 1322
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1251 1323
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1252
-				}
1253
-				elseif (!empty($modSettings['max_image_width']))
1324
+				} elseif (!empty($modSettings['max_image_width']))
1254 1325
 				{
1255 1326
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1256 1327
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1257 1328
 				}
1258
-			}
1259
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1329
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1260 1330
 			{
1261 1331
 				// If the image is too large to show inline, make it a popup.
1262
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1263
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1264
-				else
1265
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1332
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1333
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1334
+				} else {
1335
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1336
+				}
1266 1337
 			}
1267 1338
 
1268
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1269
-				$attachmentData[$i]['downloads']++;
1339
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1340
+							$attachmentData[$i]['downloads']++;
1341
+			}
1270 1342
 		}
1271 1343
 	}
1272 1344
 
1273 1345
 	// Do we need to instigate a sort?
1274
-	if ($have_unapproved)
1275
-		usort($attachmentData, 'approved_attach_sort');
1346
+	if ($have_unapproved) {
1347
+			usort($attachmentData, 'approved_attach_sort');
1348
+	}
1276 1349
 
1277 1350
 	return $attachmentData;
1278 1351
 }
Please login to merge, or discard this patch.