Completed
Push — release-2.1 ( 9df441...754615 )
by Mathias
15s
created
Themes/default/GenericControls.template.php 1 patch
Braces   +79 added lines, -60 removed lines patch added patch discarded remove patch
@@ -53,14 +53,15 @@  discard block
 block discarded – undo
53 53
 			foreach ($context['smileys'] as $location => $smileyRows)
54 54
 			{
55 55
 				$countLocations--;
56
-				if ($location == 'postform')
57
-					echo '
56
+				if ($location == 'postform') {
57
+									echo '
58 58
 						dropdown:
59 59
 						{';
60
-				elseif ($location == 'popup')
61
-					echo '
60
+				} elseif ($location == 'popup') {
61
+									echo '
62 62
 						popup:
63 63
 						{';
64
+				}
64 65
 
65 66
 				$numRows = count($smileyRows);
66 67
 
@@ -68,25 +69,27 @@  discard block
 block discarded – undo
68 69
 				$emptyPlaceholder = 0;
69 70
 				foreach ($smileyRows as $smileyRow)
70 71
 				{
71
-					foreach ($smileyRow['smileys'] as $smiley)
72
-						echo '
72
+					foreach ($smileyRow['smileys'] as $smiley) {
73
+											echo '
73 74
 							', JavaScriptEscape($smiley['code']), ': ', JavaScriptEscape($settings['smileys_url'] . '/' . $smiley['filename']), empty($smiley['isLast']) ? ',' : '';
75
+					}
74 76
 
75
-					if (empty($smileyRow['isLast']) && $numRows != 1)
76
-						echo ',
77
+					if (empty($smileyRow['isLast']) && $numRows != 1) {
78
+											echo ',
77 79
 						\'-', $emptyPlaceholder++, '\': \'\',';
80
+					}
78 81
 				}
79 82
 				echo '
80 83
 						}', $countLocations != 0 ? ',' : '';
81 84
 			}
82 85
 			echo '
83 86
 					}';
84
-		}
85
-		else
86
-			echo ',
87
+		} else {
88
+					echo ',
87 89
 					emoticons:
88 90
 					{},
89 91
 					emoticonsEnabled:false';
92
+		}
90 93
 
91 94
 		if ($context['show_bbc'] && $bbcContainer !== null)
92 95
 		{
@@ -100,15 +103,16 @@  discard block
 block discarded – undo
100 103
 
101 104
 				$count_tags--;
102 105
 
103
-				if (!empty($count_tags))
104
-					echo '||';
106
+				if (!empty($count_tags)) {
107
+									echo '||';
108
+				}
105 109
 			}
106 110
 
107 111
 			echo '",';
108
-		}
109
-		else
110
-			echo ',
112
+		} else {
113
+					echo ',
111 114
 					toolbar: "",';
115
+		}
112 116
 
113 117
 		echo '
114 118
 				});
@@ -150,42 +154,47 @@  discard block
 block discarded – undo
150 154
 
151 155
 	$tempTab = $context['tabindex'];
152 156
 
153
-	if (!empty($context['drafts_pm_save']))
154
-		$tempTab++;
155
-	elseif (!empty($context['drafts_save']))
156
-		$tempTab++;
157
-	elseif ($editor_context['preview_type'])
158
-		$tempTab++;
159
-	elseif ($context['show_spellchecking'])
160
-		$tempTab++;
157
+	if (!empty($context['drafts_pm_save'])) {
158
+			$tempTab++;
159
+	} elseif (!empty($context['drafts_save'])) {
160
+			$tempTab++;
161
+	} elseif ($editor_context['preview_type']) {
162
+			$tempTab++;
163
+	} elseif ($context['show_spellchecking']) {
164
+			$tempTab++;
165
+	}
161 166
 
162 167
 	$tempTab++;
163 168
 	$context['tabindex'] = $tempTab;
164 169
 
165
-	if (!empty($context['drafts_pm_save']))
166
-		echo '
170
+	if (!empty($context['drafts_pm_save'])) {
171
+			echo '
167 172
 		<input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="submitThisOnce(this);" accesskey="d" class="button">
168 173
 		<input type="hidden" id="id_pm_draft" name="id_pm_draft" value="', empty($context['id_pm_draft']) ? 0 : $context['id_pm_draft'], '">';
174
+	}
169 175
 
170
-	if (!empty($context['drafts_save']))
171
-		echo '
176
+	if (!empty($context['drafts_save'])) {
177
+			echo '
172 178
 		<input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="return confirm(' . JavaScriptEscape($txt['draft_save_note']) . ') && submitThisOnce(this);" accesskey="d" class="button">
173 179
 		<input type="hidden" id="id_draft" name="id_draft" value="', empty($context['id_draft']) ? 0 : $context['id_draft'], '">';
180
+	}
174 181
 
175
-	if ($context['show_spellchecking'])
176
-		echo '
182
+	if ($context['show_spellchecking']) {
183
+			echo '
177 184
 		<input type="button" value="', $txt['spell_check'], '" tabindex="', --$tempTab, '" onclick="oEditorHandle_', $editor_id, '.spellCheckStart();" class="button">';
185
+	}
178 186
 
179
-	if ($editor_context['preview_type'])
180
-		echo '
187
+	if ($editor_context['preview_type']) {
188
+			echo '
181 189
 		<input type="submit" name="preview" value="', isset($editor_context['labels']['preview_button']) ? $editor_context['labels']['preview_button'] : $txt['preview'], '" tabindex="', --$tempTab, '" onclick="', $editor_context['preview_type'] == 2 ? 'return event.ctrlKey || previewPost();' : 'return submitThisOnce(this);', '" accesskey="p" class="button">';
190
+	}
182 191
 
183 192
 	echo '
184 193
 		<input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['post'], '" name="post" tabindex="', --$tempTab, '" onclick="return submitThisOnce(this);" accesskey="s" class="button">';
185 194
 
186 195
 	// Load in the PM autosaver if it's enabled
187
-	if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave']))
188
-		echo '
196
+	if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave'])) {
197
+			echo '
189 198
 		<span class="righttext padding" style="display: block">
190 199
 			<span id="throbber" style="display:none"><img src="' . $settings['images_url'] . '/loading_sm.gif" alt="" class="centericon"></span>
191 200
 			<span id="draft_lastautosave" ></span>
@@ -203,10 +212,11 @@  discard block
 block discarded – undo
203 212
 				iFreq: ', (empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000), '
204 213
 			});
205 214
 		</script>';
215
+	}
206 216
 
207 217
 	// Start an instance of the auto saver if its enabled
208
-	if (!empty($context['drafts_save']) && !empty($context['drafts_autosave']))
209
-		echo '
218
+	if (!empty($context['drafts_save']) && !empty($context['drafts_autosave'])) {
219
+			echo '
210 220
 		<span class="righttext padding" style="display: block">
211 221
 			<span id="throbber" style="display:none"><img src="', $settings['images_url'], '/loading_sm.gif" alt="" class="centericon"></span>
212 222
 			<span id="draft_lastautosave" ></span>
@@ -223,7 +233,8 @@  discard block
 block discarded – undo
223 233
 				iFreq: ', $context['drafts_autosave_frequency'], '
224 234
 			});
225 235
 		</script>';
226
-}
236
+	}
237
+	}
227 238
 
228 239
 /**
229 240
  * This template displays a verification form
@@ -240,51 +251,57 @@  discard block
 block discarded – undo
240 251
 	$verify_context = &$context['controls']['verification'][$verify_id];
241 252
 
242 253
 	// Keep track of where we are.
243
-	if (empty($verify_context['tracking']) || $reset)
244
-		$verify_context['tracking'] = 0;
254
+	if (empty($verify_context['tracking']) || $reset) {
255
+			$verify_context['tracking'] = 0;
256
+	}
245 257
 
246 258
 	// How many items are there to display in total.
247 259
 	$total_items = count($verify_context['questions']) + ($verify_context['show_visual'] || $verify_context['can_recaptcha'] ? 1 : 0);
248 260
 
249 261
 	// If we've gone too far, stop.
250
-	if ($verify_context['tracking'] > $total_items)
251
-		return false;
262
+	if ($verify_context['tracking'] > $total_items) {
263
+			return false;
264
+	}
252 265
 
253 266
 	// Loop through each item to show them.
254 267
 	for ($i = 0; $i < $total_items; $i++)
255 268
 	{
256 269
 		// If we're after a single item only show it if we're in the right place.
257
-		if ($display_type == 'single' && $verify_context['tracking'] != $i)
258
-			continue;
270
+		if ($display_type == 'single' && $verify_context['tracking'] != $i) {
271
+					continue;
272
+		}
259 273
 
260
-		if ($display_type != 'single')
261
-			echo '
274
+		if ($display_type != 'single') {
275
+					echo '
262 276
 			<div id="verification_control_', $i, '" class="verification_control">';
277
+		}
263 278
 
264 279
 		// Display empty field, but only if we have one, and it's the first time.
265
-		if ($verify_context['empty_field'] && empty($i))
266
-			echo '
280
+		if ($verify_context['empty_field'] && empty($i)) {
281
+					echo '
267 282
 				<div class="smalltext vv_special">
268 283
 					', $txt['visual_verification_hidden'], ':
269 284
 					<input type="text" name="', $_SESSION[$verify_id . '_vv']['empty_field'], '" autocomplete="off" size="30" value="">
270 285
 				</div>';
286
+		}
271 287
 
272 288
 		// Do the actual stuff
273 289
 		if ($i == 0 && ($verify_context['show_visual'] || $verify_context['can_recaptcha']))
274 290
 		{
275 291
 			if ($verify_context['show_visual'])
276 292
 			{
277
-				if ($context['use_graphic_library'])
278
-					echo '
293
+				if ($context['use_graphic_library']) {
294
+									echo '
279 295
 				<img src="', $verify_context['image_href'], '" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '">';
280
-				else
281
-					echo '
296
+				} else {
297
+									echo '
282 298
 				<img src="', $verify_context['image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_1">
283 299
 				<img src="', $verify_context['image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_2">
284 300
 				<img src="', $verify_context['image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_3">
285 301
 				<img src="', $verify_context['image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_4">
286 302
 				<img src="', $verify_context['image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_5">
287 303
 				<img src="', $verify_context['image_href'], ';letter=6" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_6">';
304
+				}
288 305
 
289 306
 				echo '
290 307
 				<div class="smalltext" style="margin: 4px 0 8px 0;">
@@ -302,8 +319,7 @@  discard block
 block discarded – undo
302 319
 				<br>
303 320
 				<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl='.$lang.'"></script>';
304 321
 			}
305
-		}
306
-		else
322
+		} else
307 323
 		{
308 324
 			// Where in the question array is this question?
309 325
 			$qIndex = $verify_context['show_visual'] ? $i - 1 : $i;
@@ -315,21 +331,24 @@  discard block
 block discarded – undo
315 331
 				</div>';
316 332
 		}
317 333
 
318
-		if ($display_type != 'single')
319
-			echo '
334
+		if ($display_type != 'single') {
335
+					echo '
320 336
 			</div><!-- #verification_control_[i] -->';
337
+		}
321 338
 
322 339
 		// If we were displaying just one and we did it, break.
323
-		if ($display_type == 'single' && $verify_context['tracking'] == $i)
324
-			break;
340
+		if ($display_type == 'single' && $verify_context['tracking'] == $i) {
341
+					break;
342
+		}
325 343
 	}
326 344
 
327 345
 	// Assume we found something, always.
328 346
 	$verify_context['tracking']++;
329 347
 
330 348
 	// Tell something displaying piecemeal to keep going.
331
-	if ($display_type == 'single')
332
-		return true;
333
-}
349
+	if ($display_type == 'single') {
350
+			return true;
351
+	}
352
+	}
334 353
 
335 354
 ?>
336 355
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Profile-View.php 1 patch
Braces   +302 added lines, -221 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * View a summary.
@@ -23,8 +24,9 @@  discard block
 block discarded – undo
23 24
 	global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;
24 25
 
25 26
 	// Attempt to load the member's profile data.
26
-	if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
27
-		fatal_lang_error('not_a_user', false, 404);
27
+	if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
28
+			fatal_lang_error('not_a_user', false, 404);
29
+	}
28 30
 
29 31
 	// Set up the stuff and load the user.
30 32
 	$context += array(
@@ -49,19 +51,21 @@  discard block
 block discarded – undo
49 51
 
50 52
 	// See if they have broken any warning levels...
51 53
 	list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
52
-	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
53
-		$context['warning_status'] = $txt['profile_warning_is_muted'];
54
-	elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
55
-		$context['warning_status'] = $txt['profile_warning_is_moderation'];
56
-	elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
57
-		$context['warning_status'] = $txt['profile_warning_is_watch'];
54
+	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) {
55
+			$context['warning_status'] = $txt['profile_warning_is_muted'];
56
+	} elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) {
57
+			$context['warning_status'] = $txt['profile_warning_is_moderation'];
58
+	} elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) {
59
+			$context['warning_status'] = $txt['profile_warning_is_watch'];
60
+	}
58 61
 
59 62
 	// They haven't even been registered for a full day!?
60 63
 	$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
61
-	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
62
-		$context['member']['posts_per_day'] = $txt['not_applicable'];
63
-	else
64
-		$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
64
+	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) {
65
+			$context['member']['posts_per_day'] = $txt['not_applicable'];
66
+	} else {
67
+			$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
68
+	}
65 69
 
66 70
 	// Set the age...
67 71
 	if (empty($context['member']['birth_date']) || substr($context['member']['birth_date'], 0, 4) < 1002)
@@ -70,8 +74,7 @@  discard block
 block discarded – undo
70 74
 			'age' => $txt['not_applicable'],
71 75
 			'today_is_birthday' => false
72 76
 		);
73
-	}
74
-	else
77
+	} else
75 78
 	{
76 79
 		list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
77 80
 		$datearray = getdate(forum_time());
@@ -84,15 +87,16 @@  discard block
 block discarded – undo
84 87
 	if (allowedTo('moderate_forum'))
85 88
 	{
86 89
 		// Make sure it's a valid ip address; otherwise, don't bother...
87
-		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
88
-			$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
89
-		else
90
-			$context['member']['hostname'] = '';
90
+		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
91
+					$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
92
+		} else {
93
+					$context['member']['hostname'] = '';
94
+		}
91 95
 
92 96
 		$context['can_see_ip'] = true;
97
+	} else {
98
+			$context['can_see_ip'] = false;
93 99
 	}
94
-	else
95
-		$context['can_see_ip'] = false;
96 100
 
97 101
 	// Are they hidden?
98 102
 	$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
@@ -103,8 +107,9 @@  discard block
 block discarded – undo
103 107
 		include_once($sourcedir . '/Who.php');
104 108
 		$action = determineActions($user_profile[$memID]['url']);
105 109
 
106
-		if ($action !== false)
107
-			$context['member']['action'] = $action;
110
+		if ($action !== false) {
111
+					$context['member']['action'] = $action;
112
+		}
108 113
 	}
109 114
 
110 115
 	// If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
@@ -167,13 +172,15 @@  discard block
 block discarded – undo
167 172
 		{
168 173
 			// Work out what restrictions we actually have.
169 174
 			$ban_restrictions = array();
170
-			foreach (array('access', 'login', 'post') as $type)
171
-				if ($row['cannot_' . $type])
175
+			foreach (array('access', 'login', 'post') as $type) {
176
+							if ($row['cannot_' . $type])
172 177
 					$ban_restrictions[] = $txt['ban_type_' . $type];
178
+			}
173 179
 
174 180
 			// No actual ban in place?
175
-			if (empty($ban_restrictions))
176
-				continue;
181
+			if (empty($ban_restrictions)) {
182
+							continue;
183
+			}
177 184
 
178 185
 			// Prepare the link for context.
179 186
 			$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
@@ -195,9 +202,10 @@  discard block
 block discarded – undo
195 202
 	$context['print_custom_fields'] = array();
196 203
 
197 204
 	// Any custom profile fields?
198
-	if (!empty($context['custom_fields']))
199
-		foreach ($context['custom_fields'] as $custom)
205
+	if (!empty($context['custom_fields'])) {
206
+			foreach ($context['custom_fields'] as $custom)
200 207
 			$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
208
+	}
201 209
 
202 210
 }
203 211
 
@@ -245,16 +253,18 @@  discard block
 block discarded – undo
245 253
 		$row['extra'] = !empty($row['extra']) ? $smcFunc['json_decode']($row['extra'], true) : array();
246 254
 		$alerts[$id_alert] = $row;
247 255
 
248
-		if (!empty($row['sender_id']))
249
-			$senders[] = $row['sender_id'];
256
+		if (!empty($row['sender_id'])) {
257
+					$senders[] = $row['sender_id'];
258
+		}
250 259
 	}
251 260
 	$smcFunc['db_free_result']($request);
252 261
 
253 262
 	if($withSender)
254 263
 	{
255 264
 		$senders = loadMemberData($senders);
256
-		foreach ($senders as $member)
257
-			loadMemberContext($member);
265
+		foreach ($senders as $member) {
266
+					loadMemberContext($member);
267
+		}
258 268
 	}
259 269
 
260 270
 	// Now go through and actually make with the text.
@@ -269,12 +279,15 @@  discard block
 block discarded – undo
269 279
 	$msgs = array();
270 280
 	foreach ($alerts as $id_alert => $alert)
271 281
 	{
272
-		if (isset($alert['extra']['board']))
273
-			$boards[$alert['extra']['board']] = $txt['board_na'];
274
-		if (isset($alert['extra']['topic']))
275
-			$topics[$alert['extra']['topic']] = $txt['topic_na'];
276
-		if ($alert['content_type'] == 'msg')
277
-			$msgs[$alert['content_id']] = $txt['topic_na'];
282
+		if (isset($alert['extra']['board'])) {
283
+					$boards[$alert['extra']['board']] = $txt['board_na'];
284
+		}
285
+		if (isset($alert['extra']['topic'])) {
286
+					$topics[$alert['extra']['topic']] = $txt['topic_na'];
287
+		}
288
+		if ($alert['content_type'] == 'msg') {
289
+					$msgs[$alert['content_id']] = $txt['topic_na'];
290
+		}
278 291
 	}
279 292
 
280 293
 	// Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up.
@@ -289,8 +302,9 @@  discard block
 block discarded – undo
289 302
 				'boards' => array_keys($boards),
290 303
 			)
291 304
 		);
292
-		while ($row = $smcFunc['db_fetch_assoc']($request))
293
-			$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
305
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
306
+					$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
307
+		}
294 308
 	}
295 309
 	if (!empty($topics))
296 310
 	{
@@ -305,8 +319,9 @@  discard block
 block discarded – undo
305 319
 				'topics' => array_keys($topics),
306 320
 			)
307 321
 		);
308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
309
-			$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
322
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
323
+					$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
324
+		}
310 325
 	}
311 326
 	if (!empty($msgs))
312 327
 	{
@@ -321,44 +336,51 @@  discard block
 block discarded – undo
321 336
 				'msgs' => array_keys($msgs),
322 337
 			)
323 338
 		);
324
-		while ($row = $smcFunc['db_fetch_assoc']($request))
325
-			$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
339
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
340
+					$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
341
+		}
326 342
 	}
327 343
 
328 344
 	// Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
329 345
 	foreach ($alerts as $id_alert => $alert)
330 346
 	{
331
-		if (!empty($alert['text']))
332
-			continue;
333
-		if (isset($alert['extra']['board']))
334
-			if ($boards[$alert['extra']['board']] == $txt['board_na'])
347
+		if (!empty($alert['text'])) {
348
+					continue;
349
+		}
350
+		if (isset($alert['extra']['board'])) {
351
+					if ($boards[$alert['extra']['board']] == $txt['board_na'])
335 352
 			{
336 353
 				unset($alerts[$id_alert]);
354
+		}
337 355
 				continue;
356
+			} else {
357
+							$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
338 358
 			}
339
-			else
340
-				$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
341
-		if (isset($alert['extra']['topic']))
342
-			if ($alert['extra']['topic'] == $txt['topic_na'])
359
+		if (isset($alert['extra']['topic'])) {
360
+					if ($alert['extra']['topic'] == $txt['topic_na'])
343 361
 			{
344 362
 				unset($alerts[$id_alert]);
363
+		}
345 364
 				continue;
365
+			} else {
366
+							$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
346 367
 			}
347
-			else
348
-				$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
349
-		if ($alert['content_type'] == 'msg')
350
-			if ($msgs[$alert['content_id']] == $txt['topic_na'])
368
+		if ($alert['content_type'] == 'msg') {
369
+					if ($msgs[$alert['content_id']] == $txt['topic_na'])
351 370
 			{
352 371
 				unset($alerts[$id_alert]);
372
+		}
353 373
 				continue;
374
+			} else {
375
+							$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
354 376
 			}
355
-			else
356
-				$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
357
-		if ($alert['content_type'] == 'profile')
358
-			$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
377
+		if ($alert['content_type'] == 'profile') {
378
+					$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
379
+		}
359 380
 
360
-		if (!empty($memberContext[$alert['sender_id']]))
361
-			$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
381
+		if (!empty($memberContext[$alert['sender_id']])) {
382
+					$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
383
+		}
362 384
 
363 385
 		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
364 386
 		if (isset($txt[$string]))
@@ -446,11 +468,11 @@  discard block
 block discarded – undo
446 468
 		checkSession('request');
447 469
 
448 470
 		// Call it!
449
-		if ($action == 'remove')
450
-			alert_delete($toMark, $memID);
451
-
452
-		else
453
-			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
471
+		if ($action == 'remove') {
472
+					alert_delete($toMark, $memID);
473
+		} else {
474
+					alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
475
+		}
454 476
 
455 477
 		// Set a nice update message.
456 478
 		$_SESSION['update_message'] = true;
@@ -500,23 +522,27 @@  discard block
 block discarded – undo
500 522
 	);
501 523
 
502 524
 	// Set the page title
503
-	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
504
-		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
505
-	else
506
-		$context['page_title'] = $txt['showPosts'];
525
+	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) {
526
+			$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
527
+	} else {
528
+			$context['page_title'] = $txt['showPosts'];
529
+	}
507 530
 
508 531
 	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
509 532
 
510 533
 	// Is the load average too high to allow searching just now?
511
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
512
-		fatal_lang_error('loadavg_show_posts_disabled', false);
534
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) {
535
+			fatal_lang_error('loadavg_show_posts_disabled', false);
536
+	}
513 537
 
514 538
 	// If we're specifically dealing with attachments use that function!
515
-	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
516
-		return showAttachments($memID);
539
+	if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
540
+			return showAttachments($memID);
541
+	}
517 542
 	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
518
-	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
519
-		return showUnwatched($memID);
543
+	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') {
544
+			return showUnwatched($memID);
545
+	}
520 546
 
521 547
 	// Are we just viewing topics?
522 548
 	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
@@ -539,27 +565,30 @@  discard block
 block discarded – undo
539 565
 		$smcFunc['db_free_result']($request);
540 566
 
541 567
 		// Trying to remove a message that doesn't exist.
542
-		if (empty($info))
543
-			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
568
+		if (empty($info)) {
569
+					redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
570
+		}
544 571
 
545 572
 		// We can be lazy, since removeMessage() will check the permissions for us.
546 573
 		require_once($sourcedir . '/RemoveTopic.php');
547 574
 		removeMessage((int) $_GET['delete']);
548 575
 
549 576
 		// Add it to the mod log.
550
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
551
-			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
577
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
578
+					logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
579
+		}
552 580
 
553 581
 		// Back to... where we are now ;).
554 582
 		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
555 583
 	}
556 584
 
557 585
 	// Default to 10.
558
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
559
-		$_REQUEST['viewscount'] = '10';
586
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
587
+			$_REQUEST['viewscount'] = '10';
588
+	}
560 589
 
561
-	if ($context['is_topics'])
562
-		$request = $smcFunc['db_query']('', '
590
+	if ($context['is_topics']) {
591
+			$request = $smcFunc['db_query']('', '
563 592
 			SELECT COUNT(*)
564 593
 			FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
565 594
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
@@ -572,8 +601,8 @@  discard block
 block discarded – undo
572 601
 				'board' => $board,
573 602
 			)
574 603
 		);
575
-	else
576
-		$request = $smcFunc['db_query']('', '
604
+	} else {
605
+			$request = $smcFunc['db_query']('', '
577 606
 			SELECT COUNT(*)
578 607
 			FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
579 608
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
@@ -586,6 +615,7 @@  discard block
 block discarded – undo
586 615
 				'board' => $board,
587 616
 			)
588 617
 		);
618
+	}
589 619
 	list ($msgCount) = $smcFunc['db_fetch_row']($request);
590 620
 	$smcFunc['db_free_result']($request);
591 621
 
@@ -606,10 +636,11 @@  discard block
 block discarded – undo
606 636
 
607 637
 	$range_limit = '';
608 638
 
609
-	if ($context['is_topics'])
610
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
611
-	else
612
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
639
+	if ($context['is_topics']) {
640
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
641
+	} else {
642
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
643
+	}
613 644
 
614 645
 	$maxIndex = $maxPerPage;
615 646
 
@@ -635,9 +666,9 @@  discard block
 block discarded – undo
635 666
 		{
636 667
 			$margin *= 5;
637 668
 			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
669
+		} else {
670
+					$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
638 671
 		}
639
-		else
640
-			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
641 672
 	}
642 673
 
643 674
 	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
@@ -669,8 +700,7 @@  discard block
 block discarded – undo
669 700
 					'max' => $maxIndex,
670 701
 				)
671 702
 			);
672
-		}
673
-		else
703
+		} else
674 704
 		{
675 705
 			$request = $smcFunc['db_query']('', '
676 706
 				SELECT
@@ -699,8 +729,9 @@  discard block
 block discarded – undo
699 729
 		}
700 730
 
701 731
 		// Make sure we quit this loop.
702
-		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '')
703
-			break;
732
+		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '') {
733
+					break;
734
+		}
704 735
 		$looped = true;
705 736
 		$range_limit = '';
706 737
 	}
@@ -744,19 +775,21 @@  discard block
 block discarded – undo
744 775
 			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
745 776
 		);
746 777
 
747
-		if ($user_info['id'] == $row['id_member_started'])
748
-			$board_ids['own'][$row['id_board']][] = $counter;
778
+		if ($user_info['id'] == $row['id_member_started']) {
779
+					$board_ids['own'][$row['id_board']][] = $counter;
780
+		}
749 781
 		$board_ids['any'][$row['id_board']][] = $counter;
750 782
 	}
751 783
 	$smcFunc['db_free_result']($request);
752 784
 
753 785
 	// All posts were retrieved in reverse order, get them right again.
754
-	if ($reverse)
755
-		$context['posts'] = array_reverse($context['posts'], true);
786
+	if ($reverse) {
787
+			$context['posts'] = array_reverse($context['posts'], true);
788
+	}
756 789
 
757 790
 	// These are all the permissions that are different from board to board..
758
-	if ($context['is_topics'])
759
-		$permissions = array(
791
+	if ($context['is_topics']) {
792
+			$permissions = array(
760 793
 			'own' => array(
761 794
 				'post_reply_own' => 'can_reply',
762 795
 			),
@@ -764,8 +797,8 @@  discard block
 block discarded – undo
764 797
 				'post_reply_any' => 'can_reply',
765 798
 			)
766 799
 		);
767
-	else
768
-		$permissions = array(
800
+	} else {
801
+			$permissions = array(
769 802
 			'own' => array(
770 803
 				'post_reply_own' => 'can_reply',
771 804
 				'delete_own' => 'can_delete',
@@ -775,6 +808,7 @@  discard block
 block discarded – undo
775 808
 				'delete_any' => 'can_delete',
776 809
 			)
777 810
 		);
811
+	}
778 812
 
779 813
 	// For every permission in the own/any lists...
780 814
 	foreach ($permissions as $type => $list)
@@ -785,19 +819,22 @@  discard block
 block discarded – undo
785 819
 			$boards = boardsAllowedTo($permission);
786 820
 
787 821
 			// Hmm, they can do it on all boards, can they?
788
-			if (!empty($boards) && $boards[0] == 0)
789
-				$boards = array_keys($board_ids[$type]);
822
+			if (!empty($boards) && $boards[0] == 0) {
823
+							$boards = array_keys($board_ids[$type]);
824
+			}
790 825
 
791 826
 			// Now go through each board they can do the permission on.
792 827
 			foreach ($boards as $board_id)
793 828
 			{
794 829
 				// There aren't any posts displayed from this board.
795
-				if (!isset($board_ids[$type][$board_id]))
796
-					continue;
830
+				if (!isset($board_ids[$type][$board_id])) {
831
+									continue;
832
+				}
797 833
 
798 834
 				// Set the permission to true ;).
799
-				foreach ($board_ids[$type][$board_id] as $counter)
800
-					$context['posts'][$counter][$allowed] = true;
835
+				foreach ($board_ids[$type][$board_id] as $counter) {
836
+									$context['posts'][$counter][$allowed] = true;
837
+				}
801 838
 			}
802 839
 		}
803 840
 	}
@@ -828,8 +865,9 @@  discard block
 block discarded – undo
828 865
 	$boardsAllowed = boardsAllowedTo('view_attachments');
829 866
 
830 867
 	// Make sure we can't actually see anything...
831
-	if (empty($boardsAllowed))
832
-		$boardsAllowed = array(-1);
868
+	if (empty($boardsAllowed)) {
869
+			$boardsAllowed = array(-1);
870
+	}
833 871
 
834 872
 	require_once($sourcedir . '/Subs-List.php');
835 873
 
@@ -980,8 +1018,8 @@  discard block
 block discarded – undo
980 1018
 		)
981 1019
 	);
982 1020
 	$attachments = array();
983
-	while ($row = $smcFunc['db_fetch_assoc']($request))
984
-		$attachments[] = array(
1021
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1022
+			$attachments[] = array(
985 1023
 			'id' => $row['id_attach'],
986 1024
 			'filename' => $row['filename'],
987 1025
 			'downloads' => $row['downloads'],
@@ -993,6 +1031,7 @@  discard block
 block discarded – undo
993 1031
 			'board_name' => $row['name'],
994 1032
 			'approved' => $row['approved'],
995 1033
 		);
1034
+	}
996 1035
 
997 1036
 	$smcFunc['db_free_result']($request);
998 1037
 
@@ -1047,8 +1086,9 @@  discard block
 block discarded – undo
1047 1086
 	global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir;
1048 1087
 
1049 1088
 	// Only the owner can see the list (if the function is enabled of course)
1050
-	if ($user_info['id'] != $memID)
1051
-		return;
1089
+	if ($user_info['id'] != $memID) {
1090
+			return;
1091
+	}
1052 1092
 
1053 1093
 	require_once($sourcedir . '/Subs-List.php');
1054 1094
 
@@ -1194,8 +1234,9 @@  discard block
 block discarded – undo
1194 1234
 	);
1195 1235
 
1196 1236
 	$topics = array();
1197
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1198
-		$topics[] = $row['id_topic'];
1237
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1238
+			$topics[] = $row['id_topic'];
1239
+	}
1199 1240
 
1200 1241
 	$smcFunc['db_free_result']($request);
1201 1242
 
@@ -1215,8 +1256,9 @@  discard block
 block discarded – undo
1215 1256
 				'topics' => $topics,
1216 1257
 			)
1217 1258
 		);
1218
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1219
-			$topicsInfo[] = $row;
1259
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1260
+					$topicsInfo[] = $row;
1261
+		}
1220 1262
 		$smcFunc['db_free_result']($request);
1221 1263
 	}
1222 1264
 
@@ -1264,8 +1306,9 @@  discard block
 block discarded – undo
1264 1306
 	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1265 1307
 
1266 1308
 	// Is the load average too high to allow searching just now?
1267
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1268
-		fatal_lang_error('loadavg_userstats_disabled', false);
1309
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) {
1310
+			fatal_lang_error('loadavg_userstats_disabled', false);
1311
+	}
1269 1312
 
1270 1313
 	// General user statistics.
1271 1314
 	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
@@ -1408,11 +1451,13 @@  discard block
 block discarded – undo
1408 1451
 	}
1409 1452
 	$smcFunc['db_free_result']($result);
1410 1453
 
1411
-	if ($maxPosts > 0)
1412
-		for ($hour = 0; $hour < 24; $hour++)
1454
+	if ($maxPosts > 0) {
1455
+			for ($hour = 0;
1456
+	}
1457
+	$hour < 24; $hour++)
1413 1458
 		{
1414
-			if (!isset($context['posts_by_time'][$hour]))
1415
-				$context['posts_by_time'][$hour] = array(
1459
+			if (!isset($context['posts_by_time'][$hour])) {
1460
+							$context['posts_by_time'][$hour] = array(
1416 1461
 					'hour' => $hour,
1417 1462
 					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1418 1463
 					'posts' => 0,
@@ -1420,7 +1465,7 @@  discard block
 block discarded – undo
1420 1465
 					'relative_percent' => 0,
1421 1466
 					'is_last' => $hour == 23,
1422 1467
 				);
1423
-			else
1468
+			} else
1424 1469
 			{
1425 1470
 				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1426 1471
 				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
@@ -1453,8 +1498,9 @@  discard block
 block discarded – undo
1453 1498
 
1454 1499
 	foreach ($subActions as $sa => $action)
1455 1500
 	{
1456
-		if (!allowedTo($action[2]))
1457
-			unset($subActions[$sa]);
1501
+		if (!allowedTo($action[2])) {
1502
+					unset($subActions[$sa]);
1503
+		}
1458 1504
 	}
1459 1505
 
1460 1506
 	// Create the tabs for the template.
@@ -1472,15 +1518,18 @@  discard block
 block discarded – undo
1472 1518
 	);
1473 1519
 
1474 1520
 	// Moderation must be on to track edits.
1475
-	if (empty($modSettings['userlog_enabled']))
1476
-		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1521
+	if (empty($modSettings['userlog_enabled'])) {
1522
+			unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1523
+	}
1477 1524
 
1478 1525
 	// Group requests must be active to show it...
1479
-	if (empty($modSettings['show_group_membership']))
1480
-		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1526
+	if (empty($modSettings['show_group_membership'])) {
1527
+			unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1528
+	}
1481 1529
 
1482
-	if (empty($subActions))
1483
-		fatal_lang_error('no_access', false);
1530
+	if (empty($subActions)) {
1531
+			fatal_lang_error('no_access', false);
1532
+	}
1484 1533
 
1485 1534
 	$keys = array_keys($subActions);
1486 1535
 	$default = array_shift($keys);
@@ -1493,9 +1542,10 @@  discard block
 block discarded – undo
1493 1542
 	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1494 1543
 	$call = call_helper($subActions[$context['tracking_area']][0], true);
1495 1544
 
1496
-	if (!empty($call))
1497
-		call_user_func($call, $memID);
1498
-}
1545
+	if (!empty($call)) {
1546
+			call_user_func($call, $memID);
1547
+	}
1548
+	}
1499 1549
 
1500 1550
 /**
1501 1551
  * Handles tracking a user's activity
@@ -1511,8 +1561,9 @@  discard block
 block discarded – undo
1511 1561
 	isAllowedTo('moderate_forum');
1512 1562
 
1513 1563
 	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1514
-	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1515
-		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1564
+	if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) {
1565
+			$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1566
+	}
1516 1567
 	$context['member']['name'] = $user_profile[$memID]['real_name'];
1517 1568
 
1518 1569
 	// Set the options for the list component.
@@ -1679,8 +1730,9 @@  discard block
 block discarded – undo
1679 1730
 			)
1680 1731
 		);
1681 1732
 		$message_members = array();
1682
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1683
-			$message_members[] = $row['id_member'];
1733
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1734
+					$message_members[] = $row['id_member'];
1735
+		}
1684 1736
 		$smcFunc['db_free_result']($request);
1685 1737
 
1686 1738
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1695,8 +1747,9 @@  discard block
 block discarded – undo
1695 1747
 					'ip_list' => $ips,
1696 1748
 				)
1697 1749
 			);
1698
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1699
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1750
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1751
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1752
+			}
1700 1753
 			$smcFunc['db_free_result']($request);
1701 1754
 		}
1702 1755
 
@@ -1710,8 +1763,9 @@  discard block
 block discarded – undo
1710 1763
 				'ip_list' => $ips,
1711 1764
 			)
1712 1765
 		);
1713
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1714
-			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1766
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1767
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1768
+		}
1715 1769
 		$smcFunc['db_free_result']($request);
1716 1770
 	}
1717 1771
 }
@@ -1771,8 +1825,8 @@  discard block
 block discarded – undo
1771 1825
 		))
1772 1826
 	);
1773 1827
 	$error_messages = array();
1774
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1775
-		$error_messages[] = array(
1828
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1829
+			$error_messages[] = array(
1776 1830
 			'ip' => inet_dtop($row['ip']),
1777 1831
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1778 1832
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1780,6 +1834,7 @@  discard block
 block discarded – undo
1780 1834
 			'time' => timeformat($row['log_time']),
1781 1835
 			'timestamp' => forum_time(true, $row['log_time']),
1782 1836
 		);
1837
+	}
1783 1838
 	$smcFunc['db_free_result']($request);
1784 1839
 
1785 1840
 	return $error_messages;
@@ -1842,8 +1897,8 @@  discard block
 block discarded – undo
1842 1897
 		))
1843 1898
 	);
1844 1899
 	$messages = array();
1845
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1846
-		$messages[] = array(
1900
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1901
+			$messages[] = array(
1847 1902
 			'ip' => inet_dtop($row['poster_ip']),
1848 1903
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1849 1904
 			'board' => array(
@@ -1856,6 +1911,7 @@  discard block
 block discarded – undo
1856 1911
 			'time' => timeformat($row['poster_time']),
1857 1912
 			'timestamp' => forum_time(true, $row['poster_time'])
1858 1913
 		);
1914
+	}
1859 1915
 	$smcFunc['db_free_result']($request);
1860 1916
 
1861 1917
 	return $messages;
@@ -1882,19 +1938,20 @@  discard block
 block discarded – undo
1882 1938
 		$context['sub_template'] = 'trackIP';
1883 1939
 		$context['page_title'] = $txt['profile'];
1884 1940
 		$context['base_url'] = $scripturl . '?action=trackip';
1885
-	}
1886
-	else
1941
+	} else
1887 1942
 	{
1888 1943
 		$context['ip'] = $user_profile[$memID]['member_ip'];
1889 1944
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1890 1945
 	}
1891 1946
 
1892 1947
 	// Searching?
1893
-	if (isset($_REQUEST['searchip']))
1894
-		$context['ip'] = trim($_REQUEST['searchip']);
1948
+	if (isset($_REQUEST['searchip'])) {
1949
+			$context['ip'] = trim($_REQUEST['searchip']);
1950
+	}
1895 1951
 
1896
-	if (isValidIP($context['ip']) === false)
1897
-		fatal_lang_error('invalid_tracking_ip', false);
1952
+	if (isValidIP($context['ip']) === false) {
1953
+			fatal_lang_error('invalid_tracking_ip', false);
1954
+	}
1898 1955
 
1899 1956
 	//mysql didn't support like search with varbinary
1900 1957
 	//$ip_var = str_replace('*', '%', $context['ip']);
@@ -1902,8 +1959,9 @@  discard block
 block discarded – undo
1902 1959
 	$ip_var = $context['ip'];
1903 1960
 	$ip_string = '= {inet:ip_address}';
1904 1961
 
1905
-	if (empty($context['tracking_area']))
1906
-		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1962
+	if (empty($context['tracking_area'])) {
1963
+			$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1964
+	}
1907 1965
 
1908 1966
 	$request = $smcFunc['db_query']('', '
1909 1967
 		SELECT id_member, real_name AS display_name, member_ip
@@ -1914,8 +1972,9 @@  discard block
 block discarded – undo
1914 1972
 		)
1915 1973
 	);
1916 1974
 	$context['ips'] = array();
1917
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1918
-		$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1975
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1976
+			$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1977
+	}
1919 1978
 	$smcFunc['db_free_result']($request);
1920 1979
 
1921 1980
 	ksort($context['ips']);
@@ -2144,8 +2203,9 @@  discard block
 block discarded – undo
2144 2203
 		foreach ($context['whois_servers'] as $whois)
2145 2204
 		{
2146 2205
 			// Strip off the "decimal point" and anything following...
2147
-			if (in_array((int) $context['ip'], $whois['range']))
2148
-				$context['auto_whois_server'] = $whois;
2206
+			if (in_array((int) $context['ip'], $whois['range'])) {
2207
+							$context['auto_whois_server'] = $whois;
2208
+			}
2149 2209
 		}
2150 2210
 	}
2151 2211
 }
@@ -2162,10 +2222,11 @@  discard block
 block discarded – undo
2162 2222
 	// Gonna want this for the list.
2163 2223
 	require_once($sourcedir . '/Subs-List.php');
2164 2224
 
2165
-	if ($memID == 0)
2166
-		$context['base_url'] = $scripturl . '?action=trackip';
2167
-	else
2168
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2225
+	if ($memID == 0) {
2226
+			$context['base_url'] = $scripturl . '?action=trackip';
2227
+	} else {
2228
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2229
+	}
2169 2230
 
2170 2231
 	// Start with the user messages.
2171 2232
 	$listOptions = array(
@@ -2275,12 +2336,13 @@  discard block
 block discarded – undo
2275 2336
 		)
2276 2337
 	);
2277 2338
 	$logins = array();
2278
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2279
-		$logins[] = array(
2339
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2340
+			$logins[] = array(
2280 2341
 			'time' => timeformat($row['time']),
2281 2342
 			'ip' => inet_dtop($row['ip']),
2282 2343
 			'ip2' => inet_dtop($row['ip2']),
2283 2344
 		);
2345
+	}
2284 2346
 	$smcFunc['db_free_result']($request);
2285 2347
 
2286 2348
 	return $logins;
@@ -2305,11 +2367,12 @@  discard block
 block discarded – undo
2305 2367
 		)
2306 2368
 	);
2307 2369
 	$context['custom_field_titles'] = array();
2308
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2309
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2370
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2371
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2310 2372
 			'title' => $row['field_name'],
2311 2373
 			'parse_bbc' => $row['bbc'],
2312 2374
 		);
2375
+	}
2313 2376
 	$smcFunc['db_free_result']($request);
2314 2377
 
2315 2378
 	// Set the options for the error lists.
@@ -2448,19 +2511,22 @@  discard block
 block discarded – undo
2448 2511
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2449 2512
 	{
2450 2513
 		$extra = $smcFunc['json_decode']($row['extra'], true);
2451
-		if (!empty($extra['applicator']))
2452
-			$members[] = $extra['applicator'];
2514
+		if (!empty($extra['applicator'])) {
2515
+					$members[] = $extra['applicator'];
2516
+		}
2453 2517
 
2454 2518
 		// Work out what the name of the action is.
2455
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2456
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2457
-		elseif (isset($txt[$row['action']]))
2458
-			$action_text = $txt[$row['action']];
2519
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2520
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2521
+		} elseif (isset($txt[$row['action']])) {
2522
+					$action_text = $txt[$row['action']];
2523
+		}
2459 2524
 		// Custom field?
2460
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2461
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2462
-		else
2463
-			$action_text = $row['action'];
2525
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2526
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2527
+		} else {
2528
+					$action_text = $row['action'];
2529
+		}
2464 2530
 
2465 2531
 		// Parse BBC?
2466 2532
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2492,13 +2558,15 @@  discard block
 block discarded – undo
2492 2558
 			)
2493 2559
 		);
2494 2560
 		$members = array();
2495
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2496
-			$members[$row['id_member']] = $row['real_name'];
2561
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2562
+					$members[$row['id_member']] = $row['real_name'];
2563
+		}
2497 2564
 		$smcFunc['db_free_result']($request);
2498 2565
 
2499
-		foreach ($edits as $key => $value)
2500
-			if (isset($members[$value['id_member']]))
2566
+		foreach ($edits as $key => $value) {
2567
+					if (isset($members[$value['id_member']]))
2501 2568
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2569
+		}
2502 2570
 	}
2503 2571
 
2504 2572
 	return $edits;
@@ -2699,10 +2767,11 @@  discard block
 block discarded – undo
2699 2767
 	$context['board'] = $board;
2700 2768
 
2701 2769
 	// Determine which groups this user is in.
2702
-	if (empty($user_profile[$memID]['additional_groups']))
2703
-		$curGroups = array();
2704
-	else
2705
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2770
+	if (empty($user_profile[$memID]['additional_groups'])) {
2771
+			$curGroups = array();
2772
+	} else {
2773
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2774
+	}
2706 2775
 	$curGroups[] = $user_profile[$memID]['id_group'];
2707 2776
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2708 2777
 
@@ -2722,28 +2791,30 @@  discard block
 block discarded – undo
2722 2791
 	$context['no_access_boards'] = array();
2723 2792
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2724 2793
 	{
2725
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2726
-			$context['no_access_boards'][] = array(
2794
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2795
+					$context['no_access_boards'][] = array(
2727 2796
 				'id' => $row['id_board'],
2728 2797
 				'name' => $row['name'],
2729 2798
 				'is_last' => false,
2730 2799
 			);
2731
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2732
-			$context['boards'][$row['id_board']] = array(
2800
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2801
+					$context['boards'][$row['id_board']] = array(
2733 2802
 				'id' => $row['id_board'],
2734 2803
 				'name' => $row['name'],
2735 2804
 				'selected' => $board == $row['id_board'],
2736 2805
 				'profile' => $row['id_profile'],
2737 2806
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2738 2807
 			);
2808
+		}
2739 2809
 	}
2740 2810
 	$smcFunc['db_free_result']($request);
2741 2811
 
2742 2812
 	require_once($sourcedir . '/Subs-Boards.php');
2743 2813
 	sortBoards($context['boards']);
2744 2814
 
2745
-	if (!empty($context['no_access_boards']))
2746
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2815
+	if (!empty($context['no_access_boards'])) {
2816
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2817
+	}
2747 2818
 
2748 2819
 	$context['member']['permissions'] = array(
2749 2820
 		'general' => array(),
@@ -2752,8 +2823,9 @@  discard block
 block discarded – undo
2752 2823
 
2753 2824
 	// If you're an admin we know you can do everything, we might as well leave.
2754 2825
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2755
-	if ($context['member']['has_all_permissions'])
2756
-		return;
2826
+	if ($context['member']['has_all_permissions']) {
2827
+			return;
2828
+	}
2757 2829
 
2758 2830
 	$denied = array();
2759 2831
 
@@ -2772,21 +2844,24 @@  discard block
 block discarded – undo
2772 2844
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2773 2845
 	{
2774 2846
 		// We don't know about this permission, it doesn't exist :P.
2775
-		if (!isset($txt['permissionname_' . $row['permission']]))
2776
-			continue;
2847
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2848
+					continue;
2849
+		}
2777 2850
 
2778
-		if (empty($row['add_deny']))
2779
-			$denied[] = $row['permission'];
2851
+		if (empty($row['add_deny'])) {
2852
+					$denied[] = $row['permission'];
2853
+		}
2780 2854
 
2781 2855
 		// Permissions that end with _own or _any consist of two parts.
2782
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2783
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2784
-		else
2785
-			$name = $txt['permissionname_' . $row['permission']];
2856
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2857
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2858
+		} else {
2859
+					$name = $txt['permissionname_' . $row['permission']];
2860
+		}
2786 2861
 
2787 2862
 		// Add this permission if it doesn't exist yet.
2788
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2789
-			$context['member']['permissions']['general'][$row['permission']] = array(
2863
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2864
+					$context['member']['permissions']['general'][$row['permission']] = array(
2790 2865
 				'id' => $row['permission'],
2791 2866
 				'groups' => array(
2792 2867
 					'allowed' => array(),
@@ -2796,6 +2871,7 @@  discard block
 block discarded – undo
2796 2871
 				'is_denied' => false,
2797 2872
 				'is_global' => true,
2798 2873
 			);
2874
+		}
2799 2875
 
2800 2876
 		// Add the membergroup to either the denied or the allowed groups.
2801 2877
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2829,18 +2905,20 @@  discard block
 block discarded – undo
2829 2905
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2830 2906
 	{
2831 2907
 		// We don't know about this permission, it doesn't exist :P.
2832
-		if (!isset($txt['permissionname_' . $row['permission']]))
2833
-			continue;
2908
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2909
+					continue;
2910
+		}
2834 2911
 
2835 2912
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2836
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2837
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2838
-		else
2839
-			$name = $txt['permissionname_' . $row['permission']];
2913
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2914
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2915
+		} else {
2916
+					$name = $txt['permissionname_' . $row['permission']];
2917
+		}
2840 2918
 
2841 2919
 		// Create the structure for this permission.
2842
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2843
-			$context['member']['permissions']['board'][$row['permission']] = array(
2920
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2921
+					$context['member']['permissions']['board'][$row['permission']] = array(
2844 2922
 				'id' => $row['permission'],
2845 2923
 				'groups' => array(
2846 2924
 					'allowed' => array(),
@@ -2850,6 +2928,7 @@  discard block
 block discarded – undo
2850 2928
 				'is_denied' => false,
2851 2929
 				'is_global' => empty($board),
2852 2930
 			);
2931
+		}
2853 2932
 
2854 2933
 		$context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
2855 2934
 
@@ -2868,8 +2947,9 @@  discard block
 block discarded – undo
2868 2947
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2869 2948
 
2870 2949
 	// Firstly, can we actually even be here?
2871
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2872
-		fatal_lang_error('no_access', false);
2950
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2951
+			fatal_lang_error('no_access', false);
2952
+	}
2873 2953
 
2874 2954
 	// Make sure things which are disabled stay disabled.
2875 2955
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2956,9 +3036,10 @@  discard block
 block discarded – undo
2956 3036
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2957 3037
 	);
2958 3038
 	$context['current_level'] = 0;
2959
-	foreach ($context['level_effects'] as $limit => $dummy)
2960
-		if ($context['member']['warning'] >= $limit)
3039
+	foreach ($context['level_effects'] as $limit => $dummy) {
3040
+			if ($context['member']['warning'] >= $limit)
2961 3041
 			$context['current_level'] = $limit;
2962
-}
3042
+	}
3043
+	}
2963 3044
 
2964 3045
 ?>
2965 3046
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/DbPackages-postgresql.php 1 patch
Braces   +122 added lines, -95 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Add the file functions to the $smcFunc array.
@@ -53,8 +54,9 @@  discard block
 block discarded – undo
53 54
 		'messages', 'moderator_groups', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages',
54 55
 		'pm_labeled_messages', 'pm_labels', 'pm_recipients', 'pm_rules', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys',
55 56
 		'spiders', 'subscriptions', 'themes', 'topics', 'user_alerts', 'user_alerts_prefs', 'user_drafts', 'user_likes');
56
-	foreach ($reservedTables as $k => $table_name)
57
-		$reservedTables[$k] = strtolower($db_prefix . $table_name);
57
+	foreach ($reservedTables as $k => $table_name) {
58
+			$reservedTables[$k] = strtolower($db_prefix . $table_name);
59
+	}
58 60
 
59 61
 	// We in turn may need the extra stuff.
60 62
 	db_extend('extra');
@@ -107,8 +109,9 @@  discard block
 block discarded – undo
107 109
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
108 110
 
109 111
 	// First - no way do we touch SMF tables.
110
-	if (in_array(strtolower($table_name), $reservedTables))
111
-		return false;
112
+	if (in_array(strtolower($table_name), $reservedTables)) {
113
+			return false;
114
+	}
112 115
 
113 116
 	// Log that we'll want to remove this on uninstall.
114 117
 	$db_package_log[] = array('remove_table', $table_name);
@@ -118,9 +121,9 @@  discard block
 block discarded – undo
118 121
 	if (in_array($full_table_name, $tables))
119 122
 	{
120 123
 		// This is a sad day... drop the table? If not, return false (error) by default.
121
-		if ($if_exists == 'overwrite')
122
-			$smcFunc['db_drop_table']($table_name);
123
-		else if ($if_exists == 'update')
124
+		if ($if_exists == 'overwrite') {
125
+					$smcFunc['db_drop_table']($table_name);
126
+		} else if ($if_exists == 'update')
124 127
 		{
125 128
 			$smcFunc['db_drop_table']($table_name.'_old');
126 129
 			$smcFunc['db_transaction']('begin');
@@ -132,47 +135,51 @@  discard block
 block discarded – undo
132 135
 				)
133 136
 			);
134 137
 			$old_table_exists = true;
138
+		} else {
139
+					return $if_exists == 'ignore';
135 140
 		}
136
-		else
137
-			return $if_exists == 'ignore';
138 141
 	}
139 142
 
140 143
 	// If we've got this far - good news - no table exists. We can build our own!
141
-	if (!$db_trans)
142
-		$smcFunc['db_transaction']('begin');
144
+	if (!$db_trans) {
145
+			$smcFunc['db_transaction']('begin');
146
+	}
143 147
 	$table_query = 'CREATE TABLE ' . $table_name . "\n" . '(';
144 148
 	foreach ($columns as $column)
145 149
 	{
146 150
 		// If we have an auto increment do it!
147 151
 		if (!empty($column['auto']))
148 152
 		{
149
-			if (!$old_table_exists)
150
-				$smcFunc['db_query']('', '
153
+			if (!$old_table_exists) {
154
+							$smcFunc['db_query']('', '
151 155
 					DROP SEQUENCE IF EXISTS ' . $table_name . '_seq',
152 156
 					array(
153 157
 						'security_override' => true,
154 158
 					)
155 159
 				);
160
+			}
156 161
 
157
-			if (!$old_table_exists)
158
-				$smcFunc['db_query']('', '
162
+			if (!$old_table_exists) {
163
+							$smcFunc['db_query']('', '
159 164
 					CREATE SEQUENCE ' . $table_name . '_seq',
160 165
 					array(
161 166
 						'security_override' => true,
162 167
 					)
163 168
 				);
169
+			}
164 170
 			$default = 'default nextval(\'' . $table_name . '_seq\')';
171
+		} elseif (isset($column['default']) && $column['default'] !== null) {
172
+					$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
173
+		} else {
174
+					$default = '';
165 175
 		}
166
-		elseif (isset($column['default']) && $column['default'] !== null)
167
-			$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
168
-		else
169
-			$default = '';
170 176
 
171 177
 		// Sort out the size...
172 178
 		$column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
173 179
 		list ($type, $size) = $smcFunc['db_calculate_type']($column['type'], $column['size']);
174
-		if ($size !== null)
175
-			$type = $type . '(' . $size . ')';
180
+		if ($size !== null) {
181
+					$type = $type . '(' . $size . ')';
182
+		}
176 183
 
177 184
 		// Now just put it together!
178 185
 		$table_query .= "\n\t\"" . $column['name'] . '" ' . $type . ' ' . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default . ',';
@@ -185,19 +192,21 @@  discard block
 block discarded – undo
185 192
 		$columns = implode(',', $index['columns']);
186 193
 
187 194
 		// Primary goes in the table...
188
-		if (isset($index['type']) && $index['type'] == 'primary')
189
-			$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
190
-		else
195
+		if (isset($index['type']) && $index['type'] == 'primary') {
196
+					$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
197
+		} else
191 198
 		{
192
-			if (empty($index['name']))
193
-				$index['name'] = implode('_', $index['columns']);
199
+			if (empty($index['name'])) {
200
+							$index['name'] = implode('_', $index['columns']);
201
+			}
194 202
 			$index_queries[] = 'CREATE ' . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $table_name . '_' . $index['name'] . ' ON ' . $table_name . ' (' . $columns . ')';
195 203
 		}
196 204
 	}
197 205
 
198 206
 	// No trailing commas!
199
-	if (substr($table_query, -1) == ',')
200
-		$table_query = substr($table_query, 0, -1);
207
+	if (substr($table_query, -1) == ',') {
208
+			$table_query = substr($table_query, 0, -1);
209
+	}
201 210
 
202 211
 	$table_query .= ')';
203 212
 
@@ -242,18 +251,20 @@  discard block
 block discarded – undo
242 251
 	}
243 252
 
244 253
 	// And the indexes...
245
-	foreach ($index_queries as $query)
246
-		$smcFunc['db_query']('', $query,
254
+	foreach ($index_queries as $query) {
255
+			$smcFunc['db_query']('', $query,
247 256
 		array(
248 257
 			'security_override' => true,
249 258
 		)
250 259
 	);
260
+	}
251 261
 
252 262
 	// Go, go power rangers!
253 263
 	$smcFunc['db_transaction']('commit');
254 264
 
255
-	if ($old_table_exists)
256
-		$smcFunc['db_drop_table']($table_name . '_old');
265
+	if ($old_table_exists) {
266
+			$smcFunc['db_drop_table']($table_name . '_old');
267
+	}
257 268
 
258 269
 	return true;
259 270
 }
@@ -278,8 +289,9 @@  discard block
 block discarded – undo
278 289
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
279 290
 
280 291
 	// God no - dropping one of these = bad.
281
-	if (in_array(strtolower($table_name), $reservedTables))
282
-		return false;
292
+	if (in_array(strtolower($table_name), $reservedTables)) {
293
+			return false;
294
+	}
283 295
 
284 296
 	// Does it exist?
285 297
 	if (in_array($full_table_name, $smcFunc['db_list_tables']()))
@@ -337,21 +349,24 @@  discard block
 block discarded – undo
337 349
 
338 350
 	// Does it exist - if so don't add it again!
339 351
 	$columns = $smcFunc['db_list_columns']($table_name, false);
340
-	foreach ($columns as $column)
341
-		if ($column == $column_info['name'])
352
+	foreach ($columns as $column) {
353
+			if ($column == $column_info['name'])
342 354
 		{
343 355
 			// If we're going to overwrite then use change column.
344 356
 			if ($if_exists == 'update')
345 357
 				return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
346
-			else
347
-				return false;
358
+	}
359
+			else {
360
+							return false;
361
+			}
348 362
 		}
349 363
 
350 364
 	// Get the specifics...
351 365
 	$column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null;
352 366
 	list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
353
-	if ($size !== null)
354
-		$type = $type . '(' . $size . ')';
367
+	if ($size !== null) {
368
+			$type = $type . '(' . $size . ')';
369
+	}
355 370
 
356 371
 	// Now add the thing!
357 372
 	$query = '
@@ -366,11 +381,12 @@  discard block
 block discarded – undo
366 381
 	// If there's more attributes they need to be done via a change on PostgreSQL.
367 382
 	unset($column_info['type'], $column_info['size']);
368 383
 
369
-	if (count($column_info) != 1)
370
-		return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
371
-	else
372
-		return true;
373
-}
384
+	if (count($column_info) != 1) {
385
+			return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
386
+	} else {
387
+			return true;
388
+	}
389
+	}
374 390
 
375 391
 /**
376 392
  * Removes a column.
@@ -389,8 +405,8 @@  discard block
 block discarded – undo
389 405
 
390 406
 	// Does it exist?
391 407
 	$columns = $smcFunc['db_list_columns']($table_name, true);
392
-	foreach ($columns as $column)
393
-		if ($column['name'] == $column_name)
408
+	foreach ($columns as $column) {
409
+			if ($column['name'] == $column_name)
394 410
 		{
395 411
 			// If there is an auto we need remove it!
396 412
 			if ($column['auto'])
@@ -400,6 +416,7 @@  discard block
 block discarded – undo
400 416
 						'security_override' => true,
401 417
 					)
402 418
 				);
419
+	}
403 420
 
404 421
 			$smcFunc['db_query']('', '
405 422
 				ALTER TABLE ' . $table_name . '
@@ -433,13 +450,15 @@  discard block
 block discarded – undo
433 450
 	// Check it does exist!
434 451
 	$columns = $smcFunc['db_list_columns']($table_name, true);
435 452
 	$old_info = null;
436
-	foreach ($columns as $column)
437
-		if ($column['name'] == $old_column)
453
+	foreach ($columns as $column) {
454
+			if ($column['name'] == $old_column)
438 455
 			$old_info = $column;
456
+	}
439 457
 
440 458
 	// Nothing?
441
-	if ($old_info == null)
442
-		return false;
459
+	if ($old_info == null) {
460
+			return false;
461
+	}
443 462
 
444 463
 	// Now we check each bit individually and ALTER as required.
445 464
 	if (isset($column_info['name']) && $column_info['name'] != $old_column)
@@ -496,8 +515,9 @@  discard block
 block discarded – undo
496 515
 	{
497 516
 		$column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null;
498 517
 		list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
499
-		if ($size !== null)
500
-			$type = $type . '(' . $size . ')';
518
+		if ($size !== null) {
519
+					$type = $type . '(' . $size . ')';
520
+		}
501 521
 
502 522
 		// The alter is a pain.
503 523
 		$smcFunc['db_transaction']('begin');
@@ -598,21 +618,23 @@  discard block
 block discarded – undo
598 618
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
599 619
 
600 620
 	// No columns = no index.
601
-	if (empty($index_info['columns']))
602
-		return false;
621
+	if (empty($index_info['columns'])) {
622
+			return false;
623
+	}
603 624
 	$columns = implode(',', $index_info['columns']);
604 625
 
605 626
 	// No name - make it up!
606 627
 	if (empty($index_info['name']))
607 628
 	{
608 629
 		// No need for primary.
609
-		if (isset($index_info['type']) && $index_info['type'] == 'primary')
610
-			$index_info['name'] = '';
611
-		else
612
-			$index_info['name'] = $table_name . implode('_', $index_info['columns']);
630
+		if (isset($index_info['type']) && $index_info['type'] == 'primary') {
631
+					$index_info['name'] = '';
632
+		} else {
633
+					$index_info['name'] = $table_name . implode('_', $index_info['columns']);
634
+		}
635
+	} else {
636
+			$index_info['name'] = $table_name . $index_info['name'];
613 637
 	}
614
-	else
615
-		$index_info['name'] = $table_name . $index_info['name'];
616 638
 
617 639
 	// Log that we are going to want to remove this!
618 640
 	$db_package_log[] = array('remove_index', $table_name, $index_info['name']);
@@ -625,10 +647,11 @@  discard block
 block discarded – undo
625 647
 		if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary'))
626 648
 		{
627 649
 			// If we want to overwrite simply remove the current one then continue.
628
-			if ($if_exists != 'update' || $index['type'] == 'primary')
629
-				return false;
630
-			else
631
-				$smcFunc['db_remove_index']($table_name, $index_info['name']);
650
+			if ($if_exists != 'update' || $index['type'] == 'primary') {
651
+							return false;
652
+			} else {
653
+							$smcFunc['db_remove_index']($table_name, $index_info['name']);
654
+			}
632 655
 		}
633 656
 	}
634 657
 
@@ -642,8 +665,7 @@  discard block
 block discarded – undo
642 665
 				'security_override' => true,
643 666
 			)
644 667
 		);
645
-	}
646
-	else
668
+	} else
647 669
 	{
648 670
 		$smcFunc['db_query']('', '
649 671
 			CREATE ' . (isset($index_info['type']) && $index_info['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $index_info['name'] . ' ON ' . $table_name . ' (' . $columns . ')',
@@ -671,8 +693,9 @@  discard block
 block discarded – undo
671 693
 
672 694
 	// Better exist!
673 695
 	$indexes = $smcFunc['db_list_indexes']($table_name, true);
674
-	if ($index_name != 'primary')
675
-		$index_name = $table_name . '_' . $index_name;
696
+	if ($index_name != 'primary') {
697
+			$index_name = $table_name . '_' . $index_name;
698
+	}
676 699
 
677 700
 	foreach ($indexes as $index)
678 701
 	{
@@ -736,8 +759,7 @@  discard block
 block discarded – undo
736 759
 			'datetime' => 'timestamp without time zone',
737 760
 			'timestamp' => 'timestamp without time zone',
738 761
 		);
739
-	}
740
-	else
762
+	} else
741 763
 	{
742 764
 		$types = array(
743 765
 			'character varying' => 'varchar',
@@ -753,14 +775,16 @@  discard block
 block discarded – undo
753 775
 	// Got it? Change it!
754 776
 	if (isset($types[$type_name]))
755 777
 	{
756
-		if ($type_name == 'tinytext')
757
-			$type_size = 255;
778
+		if ($type_name == 'tinytext') {
779
+					$type_size = 255;
780
+		}
758 781
 		$type_name = $types[$type_name];
759 782
 	}
760 783
 
761 784
 	// Only char fields got size
762
-	if (strpos($type_name, 'char') === false)
763
-			$type_size = null;
785
+	if (strpos($type_name, 'char') === false) {
786
+				$type_size = null;
787
+	}
764 788
 
765 789
 
766 790
 	return array($type_name, $type_size);
@@ -816,8 +840,7 @@  discard block
 block discarded – undo
816 840
 		if (!$detail)
817 841
 		{
818 842
 			$columns[] = $row['column_name'];
819
-		}
820
-		else
843
+		} else
821 844
 		{
822 845
 			$auto = false;
823 846
 			// What is the default?
@@ -825,11 +848,11 @@  discard block
 block discarded – undo
825 848
 			{
826 849
 				$default = null;
827 850
 				$auto = true;
851
+			} elseif (trim($row['column_default']) != '') {
852
+							$default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::'));
853
+			} else {
854
+							$default = null;
828 855
 			}
829
-			elseif (trim($row['column_default']) != '')
830
-				$default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::'));
831
-			else
832
-				$default = null;
833 856
 
834 857
 			// Make the type generic.
835 858
 			list ($type, $size) = $smcFunc['db_calculate_type']($row['data_type'], $row['character_maximum_length'], true);
@@ -880,26 +903,30 @@  discard block
 block discarded – undo
880 903
 	while ($row = $smcFunc['db_fetch_assoc']($result))
881 904
 	{
882 905
 		// Try get the columns that make it up.
883
-		if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0)
884
-			continue;
906
+		if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) {
907
+					continue;
908
+		}
885 909
 
886 910
 		$columns = explode(',', $matches[1]);
887 911
 
888
-		if (empty($columns))
889
-			continue;
912
+		if (empty($columns)) {
913
+					continue;
914
+		}
890 915
 
891
-		foreach ($columns as $k => $v)
892
-			$columns[$k] = trim($v);
916
+		foreach ($columns as $k => $v) {
917
+					$columns[$k] = trim($v);
918
+		}
893 919
 
894 920
 		// Fix up the name to be consistent cross databases
895
-		if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1)
896
-			$row['name'] = 'PRIMARY';
897
-		else
898
-			$row['name'] = str_replace($table_name . '_', '', $row['name']);
921
+		if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) {
922
+					$row['name'] = 'PRIMARY';
923
+		} else {
924
+					$row['name'] = str_replace($table_name . '_', '', $row['name']);
925
+		}
899 926
 
900
-		if (!$detail)
901
-			$indexes[] = $row['name'];
902
-		else
927
+		if (!$detail) {
928
+					$indexes[] = $row['name'];
929
+		} else
903 930
 		{
904 931
 			$indexes[$row['name']] = array(
905 932
 				'name' => $row['name'],
Please login to merge, or discard this patch.
Themes/default/Login.template.php 1 patch
Braces   +35 added lines, -24 removed lines patch added patch discarded remove patch
@@ -28,15 +28,17 @@  discard block
 block discarded – undo
28 28
 				<form class="login" action="', $context['login_url'], '" name="frmLogin" id="frmLogin" method="post" accept-charset="', $context['character_set'], '">';
29 29
 
30 30
 	// Did they make a mistake last time?
31
-	if (!empty($context['login_errors']))
32
-		echo '
31
+	if (!empty($context['login_errors'])) {
32
+			echo '
33 33
 					<div class="errorbox">', implode('<br>', $context['login_errors']), '</div>
34 34
 					<br>';
35
+	}
35 36
 
36 37
 	// Or perhaps there's some special description for this time?
37
-	if (isset($context['description']))
38
-		echo '
38
+	if (isset($context['description'])) {
39
+			echo '
39 40
 					<div class="information">', $context['description'], '</div>';
41
+	}
40 42
 
41 43
 	// Now just get the basic information - username, password, etc.
42 44
 	echo '
@@ -61,10 +63,11 @@  discard block
 block discarded – undo
61 63
 						</dd>';
62 64
 
63 65
 	// If they have deleted their account, give them a chance to change their mind.
64
-	if (isset($context['login_show_undelete']))
65
-		echo '
66
+	if (isset($context['login_show_undelete'])) {
67
+			echo '
66 68
 						<dt class="alert">', $txt['undelete_account'], ':</dt>
67 69
 						<dd><input type="checkbox" name="undelete"></dd>';
70
+	}
68 71
 
69 72
 	echo '
70 73
 					</dl>
@@ -82,8 +85,8 @@  discard block
 block discarded – undo
82 85
 							document.getElementById("', !empty($context['from_ajax']) ? 'ajax_' : '', isset($context['default_username']) && $context['default_username'] != '' ? 'loginpass' : 'loginuser', '").focus();
83 86
 						}, 150);';
84 87
 
85
-	if (!empty($context['from_ajax']))
86
-		echo '
88
+	if (!empty($context['from_ajax'])) {
89
+			echo '
87 90
 						form = $("#frmLogin");
88 91
 						form.submit(function(e) {
89 92
 							e.preventDefault();
@@ -116,16 +119,18 @@  discard block
 block discarded – undo
116 119
 
117 120
 							return false;
118 121
 						});';
122
+	}
119 123
 
120 124
 	echo '
121 125
 					</script>
122 126
 				</form>';
123 127
 
124 128
 	// It is a long story as to why we have this when we're clearly not going to use it.
125
-	if (!empty($context['from_ajax']))
126
-		echo '
129
+	if (!empty($context['from_ajax'])) {
130
+			echo '
127 131
 				<br>
128 132
 				<a href="javascript:self.close();"></a>';
133
+	}
129 134
 
130 135
 	echo '
131 136
 			</div><!-- .roundframe -->
@@ -148,11 +153,12 @@  discard block
 block discarded – undo
148 153
 			</div>
149 154
 			<div class="roundframe noup">';
150 155
 
151
-	if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error']))
152
-		echo '
156
+	if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error'])) {
157
+			echo '
153 158
 				<div class="error">
154 159
 					', $txt['tfa_' . (!empty($context['tfa_error']) ? 'code_' : 'backup_') . 'invalid'], '
155 160
 				</div>';
161
+	}
156 162
 
157 163
 	echo '
158 164
 				<form action="', $context['tfa_url'], '" method="post" id="frmTfa">
@@ -181,8 +187,8 @@  discard block
 block discarded – undo
181 187
 				<script>
182 188
 					form = $("#frmTfa");';
183 189
 
184
-	if (!empty($context['from_ajax']))
185
-		echo '
190
+	if (!empty($context['from_ajax'])) {
191
+			echo '
186 192
 					form.submit(function(e) {
187 193
 						// If we are submitting backup code, let normal workflow follow since it redirects a couple times into a different page
188 194
 						if (form.find("input[name=tfa_backup]:first").val().length > 0)
@@ -201,6 +207,7 @@  discard block
 block discarded – undo
201 207
 
202 208
 						return false;
203 209
 					});';
210
+	}
204 211
 
205 212
 	echo '
206 213
 					form.find("input[name=backup]").click(function(e) {
@@ -232,10 +239,11 @@  discard block
 block discarded – undo
232 239
 			<p class="information centertext">
233 240
 				', empty($context['kick_message']) ? $txt['only_members_can_access'] : $context['kick_message'], '<br>';
234 241
 
235
-	if ($context['can_register'])
236
-		echo sprintf($txt['login_below_or_register'], $scripturl . '?action=signup', $context['forum_name_html_safe']);
237
-	else
238
-		echo $txt['login_below'];
242
+	if ($context['can_register']) {
243
+			echo sprintf($txt['login_below_or_register'], $scripturl . '?action=signup', $context['forum_name_html_safe']);
244
+	} else {
245
+			echo $txt['login_below'];
246
+	}
239 247
 
240 248
 	// And now the login information.
241 249
 	echo '
@@ -335,9 +343,10 @@  discard block
 block discarded – undo
335 343
 			</div>
336 344
 			<div class="roundframe centertext noup">';
337 345
 
338
-	if (!empty($context['incorrect_password']))
339
-		echo '
346
+	if (!empty($context['incorrect_password'])) {
347
+			echo '
340 348
 				<div class="error">', $txt['admin_incorrect_password'], '</div>';
349
+	}
341 350
 
342 351
 	echo '
343 352
 				<strong>', $txt['password'], ':</strong>
@@ -378,10 +387,11 @@  discard block
 block discarded – undo
378 387
 				<dl>';
379 388
 
380 389
 	// You didn't even have an ID?
381
-	if (empty($context['member_id']))
382
-		echo '
390
+	if (empty($context['member_id'])) {
391
+			echo '
383 392
 					<dt>', $txt['invalid_activation_username'], ':</dt>
384 393
 					<dd><input type="text" name="user" size="30"></dd>';
394
+	}
385 395
 
386 396
 	echo '
387 397
 					<dt>', $txt['invalid_activation_retry'], ':</dt>
@@ -418,13 +428,14 @@  discard block
 block discarded – undo
418 428
 					<dd><input type="password" name="passwd" size="30"></dd>
419 429
 				</dl>';
420 430
 
421
-	if ($context['can_activate'])
422
-		echo '
431
+	if ($context['can_activate']) {
432
+			echo '
423 433
 				<p>', $txt['invalid_activation_known'], '</p>
424 434
 				<dl>
425 435
 					<dt>', $txt['invalid_activation_retry'], ':</dt>
426 436
 					<dd><input type="text" name="code" size="30"></dd>
427 437
 				</dl>';
438
+	}
428 439
 
429 440
 	echo '
430 441
 				<p><input type="submit" value="', $txt['invalid_activation_resend'], '" class="button"></p>
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +154 added lines, -121 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -98,23 +102,26 @@  discard block
 block discarded – undo
98 102
 	if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest'])
99 103
 	{
100 104
 		// First check for 2.1 json-format cookie in $_COOKIE
101
-		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1)
102
-			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
105
+		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) {
106
+					list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
107
+		}
103 108
 
104 109
 		// Try checking for 2.1 json-format cookie in $_SESSION
105
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1)
106
-			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
110
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) {
111
+					list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
112
+		}
107 113
 
108 114
 		// Next, try checking for 2.0 serialized string cookie in $_COOKIE
109
-		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1)
110
-			list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
115
+		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) {
116
+					list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
117
+		}
111 118
 
112 119
 		// Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION
113
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1)
114
-			list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
115
-
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
120
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) {
121
+					list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
122
+		} else {
123
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
124
+		}
118 125
 
119 126
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 127
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -134,24 +141,23 @@  discard block
 block discarded – undo
134 141
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
135 142
 	{
136 143
 		// Strike!  You're outta there!
137
-		if ($_GET['member'] != $user_info['id'])
138
-			fatal_lang_error('login_cookie_error', false);
144
+		if ($_GET['member'] != $user_info['id']) {
145
+					fatal_lang_error('login_cookie_error', false);
146
+		}
139 147
 
140 148
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
141 149
 
142 150
 		// Some whitelisting for login_url...
143
-		if (empty($_SESSION['login_url']))
144
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
145
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
151
+		if (empty($_SESSION['login_url'])) {
152
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
153
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
146 154
 		{
147 155
 			unset ($_SESSION['login_url']);
148 156
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
149
-		}
150
-		elseif (!empty($user_settings['tfa_secret']))
157
+		} elseif (!empty($user_settings['tfa_secret']))
151 158
 		{
152 159
 			redirectexit('action=logintfa');
153
-		}
154
-		else
160
+		} else
155 161
 		{
156 162
 			// Best not to clutter the session data too much...
157 163
 			$temp = $_SESSION['login_url'];
@@ -162,8 +168,9 @@  discard block
 block discarded – undo
162 168
 	}
163 169
 
164 170
 	// Beyond this point you are assumed to be a guest trying to login.
165
-	if (!$user_info['is_guest'])
166
-		redirectexit();
171
+	if (!$user_info['is_guest']) {
172
+			redirectexit();
173
+	}
167 174
 
168 175
 	// Are you guessing with a script?
169 176
 	checkSession();
@@ -171,18 +178,21 @@  discard block
 block discarded – undo
171 178
 	spamProtection('login');
172 179
 
173 180
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
174
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
175
-		$_SESSION['login_url'] = $_SESSION['old_url'];
181
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
182
+			$_SESSION['login_url'] = $_SESSION['old_url'];
183
+	}
176 184
 
177 185
 	// Been guessing a lot, haven't we?
178
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
179
-		fatal_lang_error('login_threshold_fail', 'login');
186
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
187
+			fatal_lang_error('login_threshold_fail', 'login');
188
+	}
180 189
 
181 190
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
182
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
183
-		$modSettings['cookieTime'] = 3153600;
184
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
185
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
191
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
192
+			$modSettings['cookieTime'] = 3153600;
193
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
194
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
195
+	}
186 196
 
187 197
 	loadLanguage('Login');
188 198
 	// Load the template stuff.
@@ -302,8 +312,9 @@  discard block
 block discarded – undo
302 312
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
303 313
 
304 314
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
305
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
306
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
315
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
316
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
317
+			}
307 318
 
308 319
 			// phpBB3 users new hashing.  We now support it as well ;).
309 320
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -323,27 +334,29 @@  discard block
 block discarded – undo
323 334
 			// Some common md5 ones.
324 335
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
325 336
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
326
-		}
327
-		elseif (strlen($user_settings['passwd']) == 40)
337
+		} elseif (strlen($user_settings['passwd']) == 40)
328 338
 		{
329 339
 			// Maybe they are using a hash from before the password fix.
330 340
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
331 341
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
332 342
 
333 343
 			// BurningBoard3 style of hashing.
334
-			if (!empty($modSettings['enable_password_conversion']))
335
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
344
+			if (!empty($modSettings['enable_password_conversion'])) {
345
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
346
+			}
336 347
 
337 348
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
338 349
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
339 350
 			{
340 351
 				// Try iconv first, for no particular reason.
341
-				if (function_exists('iconv'))
342
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
352
+				if (function_exists('iconv')) {
353
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
354
+				}
343 355
 
344 356
 				// Say it aint so, iconv failed!
345
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
346
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
357
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
358
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
359
+				}
347 360
 			}
348 361
 		}
349 362
 
@@ -373,8 +386,9 @@  discard block
 block discarded – undo
373 386
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
374 387
 
375 388
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
376
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
377
-				redirectexit('action=reminder');
389
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
390
+							redirectexit('action=reminder');
391
+			}
378 392
 			// We'll give you another chance...
379 393
 			else
380 394
 			{
@@ -385,8 +399,7 @@  discard block
 block discarded – undo
385 399
 				return;
386 400
 			}
387 401
 		}
388
-	}
389
-	elseif (!empty($user_settings['passwd_flood']))
402
+	} elseif (!empty($user_settings['passwd_flood']))
390 403
 	{
391 404
 		// Let's be sure they weren't a little hacker.
392 405
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -403,8 +416,9 @@  discard block
 block discarded – undo
403 416
 	}
404 417
 
405 418
 	// Check their activation status.
406
-	if (!checkActivation())
407
-		return;
419
+	if (!checkActivation()) {
420
+			return;
421
+	}
408 422
 
409 423
 	DoLogin();
410 424
 }
@@ -416,8 +430,9 @@  discard block
 block discarded – undo
416 430
 {
417 431
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
418 432
 
419
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
420
-		fatal_lang_error('no_access', false);
433
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
434
+			fatal_lang_error('no_access', false);
435
+	}
421 436
 
422 437
 	loadLanguage('Profile');
423 438
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -425,8 +440,9 @@  discard block
 block discarded – undo
425 440
 	$member = $context['tfa_member'];
426 441
 
427 442
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
428
-	if (time() - $member['last_login'] < 120)
429
-		fatal_lang_error('tfa_wait', false);
443
+	if (time() - $member['last_login'] < 120) {
444
+			fatal_lang_error('tfa_wait', false);
445
+	}
430 446
 
431 447
 	$totp = new \TOTP\Auth($member['tfa_secret']);
432 448
 	$totp->setRange(1);
@@ -440,8 +456,9 @@  discard block
 block discarded – undo
440 456
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
441 457
 	{
442 458
 		// Check to ensure we're forcing SSL for authentication
443
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
444
-			fatal_lang_error('login_ssl_required');
459
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
460
+					fatal_lang_error('login_ssl_required');
461
+		}
445 462
 
446 463
 		$code = $_POST['tfa_code'];
447 464
 
@@ -451,20 +468,19 @@  discard block
 block discarded – undo
451 468
 
452 469
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
453 470
 			redirectexit();
454
-		}
455
-		else
471
+		} else
456 472
 		{
457 473
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
458 474
 
459 475
 			$context['tfa_error'] = true;
460 476
 			$context['tfa_value'] = $_POST['tfa_code'];
461 477
 		}
462
-	}
463
-	elseif (!empty($_POST['tfa_backup']))
478
+	} elseif (!empty($_POST['tfa_backup']))
464 479
 	{
465 480
 		// Check to ensure we're forcing SSL for authentication
466
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
467
-			fatal_lang_error('login_ssl_required');
481
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
482
+					fatal_lang_error('login_ssl_required');
483
+		}
468 484
 
469 485
 		$backup = $_POST['tfa_backup'];
470 486
 
@@ -478,8 +494,7 @@  discard block
 block discarded – undo
478 494
 			));
479 495
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
480 496
 			redirectexit('action=profile;area=tfasetup;backup');
481
-		}
482
-		else
497
+		} else
483 498
 		{
484 499
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
485 500
 
@@ -502,8 +517,9 @@  discard block
 block discarded – undo
502 517
 {
503 518
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
504 519
 
505
-	if (!isset($context['login_errors']))
506
-		$context['login_errors'] = array();
520
+	if (!isset($context['login_errors'])) {
521
+			$context['login_errors'] = array();
522
+	}
507 523
 
508 524
 	// What is the true activation status of this account?
509 525
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -515,8 +531,9 @@  discard block
 block discarded – undo
515 531
 		return false;
516 532
 	}
517 533
 	// Awaiting approval still?
518
-	elseif ($activation_status == 3)
519
-		fatal_lang_error('still_awaiting_approval', 'user');
534
+	elseif ($activation_status == 3) {
535
+			fatal_lang_error('still_awaiting_approval', 'user');
536
+	}
520 537
 	// Awaiting deletion, changed their mind?
521 538
 	elseif ($activation_status == 4)
522 539
 	{
@@ -524,8 +541,7 @@  discard block
 block discarded – undo
524 541
 		{
525 542
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
526 543
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
527
-		}
528
-		else
544
+		} else
529 545
 		{
530 546
 			$context['disable_login_hashing'] = true;
531 547
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -565,8 +581,9 @@  discard block
 block discarded – undo
565 581
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
566 582
 
567 583
 	// Reset the login threshold.
568
-	if (isset($_SESSION['failed_login']))
569
-		unset($_SESSION['failed_login']);
584
+	if (isset($_SESSION['failed_login'])) {
585
+			unset($_SESSION['failed_login']);
586
+	}
570 587
 
571 588
 	$user_info['is_guest'] = false;
572 589
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -588,16 +605,18 @@  discard block
 block discarded – undo
588 605
 			'id_member' => $user_info['id'],
589 606
 		)
590 607
 	);
591
-	if ($smcFunc['db_num_rows']($request) == 1)
592
-		$_SESSION['first_login'] = true;
593
-	else
594
-		unset($_SESSION['first_login']);
608
+	if ($smcFunc['db_num_rows']($request) == 1) {
609
+			$_SESSION['first_login'] = true;
610
+	} else {
611
+			unset($_SESSION['first_login']);
612
+	}
595 613
 	$smcFunc['db_free_result']($request);
596 614
 
597 615
 	// You've logged in, haven't you?
598 616
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
599
-	if (empty($user_settings['tfa_secret']))
600
-		$update['last_login'] = time();
617
+	if (empty($user_settings['tfa_secret'])) {
618
+			$update['last_login'] = time();
619
+	}
601 620
 	updateMemberData($user_info['id'], $update);
602 621
 
603 622
 	// Get rid of the online entry for that old guest....
@@ -611,8 +630,8 @@  discard block
 block discarded – undo
611 630
 	$_SESSION['log_time'] = 0;
612 631
 
613 632
 	// Log this entry, only if we have it enabled.
614
-	if (!empty($modSettings['loginHistoryDays']))
615
-		$smcFunc['db_insert']('insert',
633
+	if (!empty($modSettings['loginHistoryDays'])) {
634
+			$smcFunc['db_insert']('insert',
616 635
 			'{db_prefix}member_logins',
617 636
 			array(
618 637
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -624,13 +643,15 @@  discard block
 block discarded – undo
624 643
 				'id_member', 'time'
625 644
 			)
626 645
 		);
646
+	}
627 647
 
628 648
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
629
-	if (empty($maintenance) || allowedTo('admin_forum'))
630
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
631
-	else
632
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
633
-}
649
+	if (empty($maintenance) || allowedTo('admin_forum')) {
650
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
651
+	} else {
652
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
653
+	}
654
+	}
634 655
 
635 656
 /**
636 657
  * Logs the current user out of their account.
@@ -646,13 +667,15 @@  discard block
 block discarded – undo
646 667
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
647 668
 
648 669
 	// Make sure they aren't being auto-logged out.
649
-	if (!$internal)
650
-		checkSession('get');
670
+	if (!$internal) {
671
+			checkSession('get');
672
+	}
651 673
 
652 674
 	require_once($sourcedir . '/Subs-Auth.php');
653 675
 
654
-	if (isset($_SESSION['pack_ftp']))
655
-		$_SESSION['pack_ftp'] = null;
676
+	if (isset($_SESSION['pack_ftp'])) {
677
+			$_SESSION['pack_ftp'] = null;
678
+	}
656 679
 
657 680
 	// It won't be first login anymore.
658 681
 	unset($_SESSION['first_login']);
@@ -680,8 +703,9 @@  discard block
 block discarded – undo
680 703
 
681 704
 	// And some other housekeeping while we're at it.
682 705
 	$salt = substr(md5(mt_rand()), 0, 4);
683
-	if (!empty($user_info['id']))
684
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
706
+	if (!empty($user_info['id'])) {
707
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
708
+	}
685 709
 
686 710
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
687 711
 	{
@@ -694,14 +718,13 @@  discard block
 block discarded – undo
694 718
 	// Off to the merry board index we go!
695 719
 	if ($redirect)
696 720
 	{
697
-		if (empty($_SESSION['logout_url']))
698
-			redirectexit('', $context['server']['needs_login_fix']);
699
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
721
+		if (empty($_SESSION['logout_url'])) {
722
+					redirectexit('', $context['server']['needs_login_fix']);
723
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
700 724
 		{
701 725
 			unset ($_SESSION['logout_url']);
702 726
 			redirectexit();
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			$temp = $_SESSION['logout_url'];
707 730
 			unset($_SESSION['logout_url']);
@@ -734,8 +757,9 @@  discard block
 block discarded – undo
734 757
 function phpBB3_password_check($passwd, $passwd_hash)
735 758
 {
736 759
 	// Too long or too short?
737
-	if (strlen($passwd_hash) != 34)
738
-		return;
760
+	if (strlen($passwd_hash) != 34) {
761
+			return;
762
+	}
739 763
 
740 764
 	// Range of characters allowed.
741 765
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -746,8 +770,9 @@  discard block
 block discarded – undo
746 770
 	$salt = substr($passwd_hash, 4, 8);
747 771
 
748 772
 	$hash = md5($salt . $passwd, true);
749
-	for (; $count != 0; --$count)
750
-		$hash = md5($hash . $passwd, true);
773
+	for (; $count != 0; --$count) {
774
+			$hash = md5($hash . $passwd, true);
775
+	}
751 776
 
752 777
 	$output = substr($passwd_hash, 0, 12);
753 778
 	$i = 0;
@@ -756,21 +781,25 @@  discard block
 block discarded – undo
756 781
 		$value = ord($hash[$i++]);
757 782
 		$output .= $range[$value & 0x3f];
758 783
 
759
-		if ($i < 16)
760
-			$value |= ord($hash[$i]) << 8;
784
+		if ($i < 16) {
785
+					$value |= ord($hash[$i]) << 8;
786
+		}
761 787
 
762 788
 		$output .= $range[($value >> 6) & 0x3f];
763 789
 
764
-		if ($i++ >= 16)
765
-			break;
790
+		if ($i++ >= 16) {
791
+					break;
792
+		}
766 793
 
767
-		if ($i < 16)
768
-			$value |= ord($hash[$i]) << 16;
794
+		if ($i < 16) {
795
+					$value |= ord($hash[$i]) << 16;
796
+		}
769 797
 
770 798
 		$output .= $range[($value >> 12) & 0x3f];
771 799
 
772
-		if ($i++ >= 16)
773
-			break;
800
+		if ($i++ >= 16) {
801
+					break;
802
+		}
774 803
 
775 804
 		$output .= $range[($value >> 18) & 0x3f];
776 805
 	}
@@ -802,8 +831,9 @@  discard block
 block discarded – undo
802 831
 		require_once($sourcedir . '/Subs-Auth.php');
803 832
 		setLoginCookie(-3600, 0);
804 833
 
805
-		if (isset($_SESSION['login_' . $cookiename]))
806
-			unset($_SESSION['login_' . $cookiename]);
834
+		if (isset($_SESSION['login_' . $cookiename])) {
835
+					unset($_SESSION['login_' . $cookiename]);
836
+		}
807 837
 	}
808 838
 
809 839
 	// We need a member!
@@ -817,8 +847,9 @@  discard block
 block discarded – undo
817 847
 	}
818 848
 
819 849
 	// Right, have we got a flood value?
820
-	if ($password_flood_value !== false)
821
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
850
+	if ($password_flood_value !== false) {
851
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
852
+	}
822 853
 
823 854
 	// Timestamp or number of tries invalid?
824 855
 	if (empty($number_tries) || empty($time_stamp))
@@ -834,15 +865,17 @@  discard block
 block discarded – undo
834 865
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
835 866
 
836 867
 		// They are trying too fast, make them wait longer
837
-		if ($time_stamp < time() - 10)
838
-			$time_stamp = time();
868
+		if ($time_stamp < time() - 10) {
869
+					$time_stamp = time();
870
+		}
839 871
 	}
840 872
 
841 873
 	$number_tries++;
842 874
 
843 875
 	// Broken the law?
844
-	if ($number_tries > 5)
845
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
876
+	if ($number_tries > 5) {
877
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
878
+	}
846 879
 
847 880
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
848 881
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/Display.php 1 patch
Braces   +292 added lines, -214 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * 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.
@@ -679,8 +696,9 @@  discard block
 block discarded – undo
679 696
 		$smcFunc['db_free_result']($request);
680 697
 
681 698
 		// Got we multi choice?
682
-		if ($pollinfo['max_votes'] > 1)
683
-			$realtotal = $pollinfo['total'];
699
+		if ($pollinfo['max_votes'] > 1) {
700
+					$realtotal = $pollinfo['total'];
701
+		}
684 702
 
685 703
 		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
686 704
 		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
@@ -693,20 +711,21 @@  discard block
 block discarded – undo
693 711
 				foreach ($guestinfo as $i => $guestvoted)
694 712
 				{
695 713
 					$guestvoted = explode(',', $guestvoted);
696
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
697
-						break;
714
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
715
+											break;
716
+					}
698 717
 				}
699 718
 				// Has the poll been reset since guest voted?
700 719
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
701 720
 				{
702 721
 					// Remove the poll info from the cookie to allow guest to vote again
703 722
 					unset($guestinfo[$i]);
704
-					if (!empty($guestinfo))
705
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
706
-					else
707
-						unset($_COOKIE['guest_poll_vote']);
708
-				}
709
-				else
723
+					if (!empty($guestinfo)) {
724
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
725
+					} else {
726
+											unset($_COOKIE['guest_poll_vote']);
727
+					}
728
+				} else
710 729
 				{
711 730
 					// What did they vote for?
712 731
 					unset($guestvoted[0], $guestvoted[1]);
@@ -820,23 +839,29 @@  discard block
 block discarded – undo
820 839
 		// Build the poll moderation button array.
821 840
 		$context['poll_buttons'] = array();
822 841
 
823
-		if ($context['allow_return_vote'])
824
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
842
+		if ($context['allow_return_vote']) {
843
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
844
+		}
825 845
 
826
-		if ($context['show_view_results_button'])
827
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
846
+		if ($context['show_view_results_button']) {
847
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
848
+		}
828 849
 
829
-		if ($context['allow_change_vote'])
830
-			$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']);
850
+		if ($context['allow_change_vote']) {
851
+					$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']);
852
+		}
831 853
 
832
-		if ($context['allow_lock_poll'])
833
-			$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']);
854
+		if ($context['allow_lock_poll']) {
855
+					$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']);
856
+		}
834 857
 
835
-		if ($context['allow_edit_poll'])
836
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
858
+		if ($context['allow_edit_poll']) {
859
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
860
+		}
837 861
 
838
-		if ($context['can_remove_poll'])
839
-			$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']);
862
+		if ($context['can_remove_poll']) {
863
+					$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']);
864
+		}
840 865
 
841 866
 		// Allow mods to add additional buttons here
842 867
 		call_integration_hook('integrate_poll_buttons');
@@ -872,9 +897,9 @@  discard block
 block discarded – undo
872 897
 	{
873 898
 		$start_char = 'C';
874 899
 		$page_id = $ascending ? $context['topicinfo']['id_first_msg'] : $context['topicinfo']['id_last_msg'];
900
+	} else {
901
+			$start_char = null;
875 902
 	}
876
-	else
877
-		$start_char = null;
878 903
 
879 904
 	$limit = $context['messages_per_page'];
880 905
 
@@ -889,17 +914,17 @@  discard block
 block discarded – undo
889 914
 		{
890 915
 			$ascending_seek = true;
891 916
 			$page_operator = $ascending ? '>=' : '<=';
892
-		}
893
-		else
917
+		} else
894 918
 		{
895 919
 			$ascending_seek = false;
896 920
 			$page_operator = $ascending ? '<=' : '>=';
897 921
 		}
898 922
 
899
-		if ($start_char === 'C')
900
-			$limit_seek = $limit;
901
-		else
902
-			$limit_seek  = $limit + 1;
923
+		if ($start_char === 'C') {
924
+					$limit_seek = $limit;
925
+		} else {
926
+					$limit_seek  = $limit + 1;
927
+		}
903 928
 
904 929
 		$request = $smcFunc['db_query']('', '
905 930
 			SELECT id_msg, id_member, approved
@@ -922,21 +947,23 @@  discard block
 block discarded – undo
922 947
 		$found_msg = false;
923 948
 
924 949
 		// Fallback
925
-		if ($smcFunc['db_num_rows']($request) < 1)
926
-			unset($start_char);
927
-		else
950
+		if ($smcFunc['db_num_rows']($request) < 1) {
951
+					unset($start_char);
952
+		} else
928 953
 		{
929 954
 			while ($row = $smcFunc['db_fetch_assoc']($request))
930 955
 			{
931 956
 				// Check if the start msg is in our result
932
-				if ($row['id_msg'] == $page_id)
933
-					$found_msg = true;
957
+				if ($row['id_msg'] == $page_id) {
958
+									$found_msg = true;
959
+				}
934 960
 
935 961
 				// Skip the the start msg if we not in mode C
936 962
 				if ($start_char === 'C' || $row['id_msg'] != $page_id)
937 963
 				{
938
-					if (!empty($row['id_member']))
939
-						$all_posters[$row['id_msg']] = $row['id_member'];
964
+					if (!empty($row['id_member'])) {
965
+											$all_posters[$row['id_msg']] = $row['id_member'];
966
+					}
940 967
 
941 968
 					$messages[] = $row['id_msg'];
942 969
 				}
@@ -952,8 +979,9 @@  discard block
 block discarded – undo
952 979
 		}
953 980
 
954 981
 		// Before Page bring in the right order
955
-		if (!empty($start_char) && $start_char === 'L')
956
-			krsort($messages);
982
+		if (!empty($start_char) && $start_char === 'L') {
983
+					krsort($messages);
984
+		}
957 985
 	}
958 986
 
959 987
 	// Jump to page
@@ -989,14 +1017,16 @@  discard block
 block discarded – undo
989 1017
 
990 1018
 		while ($row = $smcFunc['db_fetch_assoc']($request))
991 1019
 		{
992
-			if (!empty($row['id_member']))
993
-				$all_posters[$row['id_msg']] = $row['id_member'];
1020
+			if (!empty($row['id_member'])) {
1021
+							$all_posters[$row['id_msg']] = $row['id_member'];
1022
+			}
994 1023
 			$messages[] = $row['id_msg'];
995 1024
 		}
996 1025
 
997 1026
 		// Sort the messages into the correct display order
998
-		if (!$ascending)
999
-			sort($messages);
1027
+		if (!$ascending) {
1028
+					sort($messages);
1029
+		}
1000 1030
 	}
1001 1031
 
1002 1032
 	// Remember the paging data for next time
@@ -1016,8 +1046,9 @@  discard block
 block discarded – undo
1016 1046
 	if (!$user_info['is_guest'] && !empty($messages))
1017 1047
 	{
1018 1048
 		$mark_at_msg = max($messages);
1019
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
1020
-			$mark_at_msg = $modSettings['maxMsgID'];
1049
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
1050
+					$mark_at_msg = $modSettings['maxMsgID'];
1051
+		}
1021 1052
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
1022 1053
 		{
1023 1054
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -1049,8 +1080,9 @@  discard block
 block discarded – undo
1049 1080
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1050 1081
 		{
1051 1082
 			// Find if this topic is marked for notification...
1052
-			if (!empty($row['id_topic']))
1053
-				$context['is_marked_notify'] = true;
1083
+			if (!empty($row['id_topic'])) {
1084
+							$context['is_marked_notify'] = true;
1085
+			}
1054 1086
 
1055 1087
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
1056 1088
 			if (!empty($row['sent']) && $do_once)
@@ -1072,8 +1104,9 @@  discard block
 block discarded – undo
1072 1104
 		}
1073 1105
 
1074 1106
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
1075
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
1076
-			$_SESSION['topicseen_cache'][$board]--;
1107
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
1108
+					$_SESSION['topicseen_cache'][$board]--;
1109
+		}
1077 1110
 		// Mark board as seen if this is the only new topic.
1078 1111
 		elseif (isset($_REQUEST['topicseen']))
1079 1112
 		{
@@ -1097,14 +1130,16 @@  discard block
 block discarded – undo
1097 1130
 			$smcFunc['db_free_result']($request);
1098 1131
 
1099 1132
 			// If there're no real new topics in this board, mark the board as seen.
1100
-			if (empty($numNewTopics))
1101
-				$_REQUEST['boardseen'] = true;
1102
-			else
1103
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1133
+			if (empty($numNewTopics)) {
1134
+							$_REQUEST['boardseen'] = true;
1135
+			} else {
1136
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1137
+			}
1104 1138
 		}
1105 1139
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
1106
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
1107
-			$_SESSION['topicseen_cache'][$board]--;
1140
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1141
+					$_SESSION['topicseen_cache'][$board]--;
1142
+		}
1108 1143
 
1109 1144
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
1110 1145
 		if (isset($_REQUEST['boardseen']))
@@ -1161,23 +1196,26 @@  discard block
 block discarded – undo
1161 1196
 			$temp = array();
1162 1197
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1163 1198
 			{
1164
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1165
-					continue;
1199
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1200
+									continue;
1201
+				}
1166 1202
 
1167 1203
 				$temp[$row['id_attach']] = $row;
1168 1204
 				$temp[$row['id_attach']]['topic'] = $topic;
1169 1205
 				$temp[$row['id_attach']]['board'] = $board;
1170 1206
 
1171
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1172
-					$context['loaded_attachments'][$row['id_msg']] = array();
1207
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1208
+									$context['loaded_attachments'][$row['id_msg']] = array();
1209
+				}
1173 1210
 			}
1174 1211
 			$smcFunc['db_free_result']($request);
1175 1212
 
1176 1213
 			// This is better than sorting it with the query...
1177 1214
 			ksort($temp);
1178 1215
 
1179
-			foreach ($temp as $row)
1180
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1216
+			foreach ($temp as $row) {
1217
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1218
+			}
1181 1219
 		}
1182 1220
 
1183 1221
 		$msg_parameters = array(
@@ -1204,21 +1242,23 @@  discard block
 block discarded – undo
1204 1242
 		);
1205 1243
 
1206 1244
 		// And the likes
1207
-		if (!empty($modSettings['enable_likes']))
1208
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1245
+		if (!empty($modSettings['enable_likes'])) {
1246
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1247
+		}
1209 1248
 
1210 1249
 		// Go to the last message if the given time is beyond the time of the last message.
1211
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1212
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1250
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1251
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1252
+		}
1213 1253
 
1214 1254
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1215 1255
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1216
-		if (empty($options['view_newest_first']))
1217
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1218
-		else
1219
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1220
-	}
1221
-	else
1256
+		if (empty($options['view_newest_first'])) {
1257
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1258
+		} else {
1259
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1260
+		}
1261
+	} else
1222 1262
 	{
1223 1263
 		$messages_request = false;
1224 1264
 		$context['first_message'] = 0;
@@ -1253,8 +1293,9 @@  discard block
 block discarded – undo
1253 1293
 		'can_restore_msg' => 'move_any',
1254 1294
 		'can_like' => 'likes_like',
1255 1295
 	);
1256
-	foreach ($common_permissions as $contextual => $perm)
1257
-		$context[$contextual] = allowedTo($perm);
1296
+	foreach ($common_permissions as $contextual => $perm) {
1297
+			$context[$contextual] = allowedTo($perm);
1298
+	}
1258 1299
 
1259 1300
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1260 1301
 	$anyown_permissions = array(
@@ -1267,8 +1308,9 @@  discard block
 block discarded – undo
1267 1308
 		'can_reply_unapproved' => 'post_unapproved_replies',
1268 1309
 		'can_view_warning' => 'profile_warning',
1269 1310
 	);
1270
-	foreach ($anyown_permissions as $contextual => $perm)
1271
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1311
+	foreach ($anyown_permissions as $contextual => $perm) {
1312
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1313
+	}
1272 1314
 
1273 1315
 	if (!$user_info['is_admin'] && $context['can_move'] && !$modSettings['topic_move_any'])
1274 1316
 	{
@@ -1314,8 +1356,9 @@  discard block
 block discarded – undo
1314 1356
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1315 1357
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1316 1358
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1317
-	if (!empty($context['drafts_save']))
1318
-		loadLanguage('Drafts');
1359
+	if (!empty($context['drafts_save'])) {
1360
+			loadLanguage('Drafts');
1361
+	}
1319 1362
 
1320 1363
 	// When was the last time this topic was replied to?  Should we warn them about it?
1321 1364
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1376,26 +1419,31 @@  discard block
 block discarded – undo
1376 1419
 	// Message icons - customized icons are off?
1377 1420
 	$context['icons'] = getMessageIcons($board);
1378 1421
 
1379
-	if (!empty($context['icons']))
1380
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1422
+	if (!empty($context['icons'])) {
1423
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1424
+	}
1381 1425
 
1382 1426
 	// Build the normal button array.
1383 1427
 	$context['normal_buttons'] = array();
1384 1428
 
1385
-	if ($context['can_reply'])
1386
-		$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);
1429
+	if ($context['can_reply']) {
1430
+			$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);
1431
+	}
1387 1432
 
1388
-	if ($context['can_add_poll'])
1389
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1433
+	if ($context['can_add_poll']) {
1434
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1435
+	}
1390 1436
 
1391
-	if ($context['can_mark_unread'])
1392
-		$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']);
1437
+	if ($context['can_mark_unread']) {
1438
+			$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']);
1439
+	}
1393 1440
 
1394
-	if ($context['can_print'])
1395
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1441
+	if ($context['can_print']) {
1442
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1443
+	}
1396 1444
 
1397
-	if ($context['can_set_notify'])
1398
-		$context['normal_buttons']['notify'] = array(
1445
+	if ($context['can_set_notify']) {
1446
+			$context['normal_buttons']['notify'] = array(
1399 1447
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1400 1448
 			'sub_buttons' => array(
1401 1449
 				array(
@@ -1417,38 +1465,47 @@  discard block
 block discarded – undo
1417 1465
 				),
1418 1466
 			),
1419 1467
 		);
1468
+	}
1420 1469
 
1421 1470
 	// Build the mod button array
1422 1471
 	$context['mod_buttons'] = array();
1423 1472
 
1424
-	if ($context['can_move'])
1425
-		$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');
1473
+	if ($context['can_move']) {
1474
+			$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');
1475
+	}
1426 1476
 
1427
-	if ($context['can_delete'])
1428
-		$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']);
1477
+	if ($context['can_delete']) {
1478
+			$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']);
1479
+	}
1429 1480
 
1430
-	if ($context['can_lock'])
1431
-		$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']);
1481
+	if ($context['can_lock']) {
1482
+			$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']);
1483
+	}
1432 1484
 
1433
-	if ($context['can_sticky'])
1434
-		$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']);
1485
+	if ($context['can_sticky']) {
1486
+			$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']);
1487
+	}
1435 1488
 
1436
-	if ($context['can_merge'])
1437
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1489
+	if ($context['can_merge']) {
1490
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1491
+	}
1438 1492
 
1439
-	if ($context['calendar_post'])
1440
-		$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');
1493
+	if ($context['calendar_post']) {
1494
+			$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');
1495
+	}
1441 1496
 
1442 1497
 	// Restore topic. eh?  No monkey business.
1443
-	if ($context['can_restore_topic'])
1444
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1498
+	if ($context['can_restore_topic']) {
1499
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1500
+	}
1445 1501
 
1446 1502
 	// Show a message in case a recently posted message became unapproved.
1447 1503
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1448 1504
 
1449 1505
 	// Don't want to show this forever...
1450
-	if ($context['becomesUnapproved'])
1451
-		unset($_SESSION['becomesUnapproved']);
1506
+	if ($context['becomesUnapproved']) {
1507
+			unset($_SESSION['becomesUnapproved']);
1508
+	}
1452 1509
 
1453 1510
 	// Allow adding new mod buttons easily.
1454 1511
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1457,12 +1514,14 @@  discard block
 block discarded – undo
1457 1514
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1458 1515
 
1459 1516
 	// Load the drafts js file
1460
-	if ($context['drafts_autosave'])
1461
-		loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1517
+	if ($context['drafts_autosave']) {
1518
+			loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1519
+	}
1462 1520
 
1463 1521
 	// Spellcheck
1464
-	if ($context['show_spellchecking'])
1465
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1522
+	if ($context['show_spellchecking']) {
1523
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1524
+	}
1466 1525
 
1467 1526
 	// topic.js
1468 1527
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -1496,16 +1555,19 @@  discard block
 block discarded – undo
1496 1555
 	static $counter = null;
1497 1556
 
1498 1557
 	// If the query returned false, bail.
1499
-	if ($messages_request == false)
1500
-		return false;
1558
+	if ($messages_request == false) {
1559
+			return false;
1560
+	}
1501 1561
 
1502 1562
 	// Remember which message this is.  (ie. reply #83)
1503
-	if ($counter === null || $reset)
1504
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1563
+	if ($counter === null || $reset) {
1564
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1565
+	}
1505 1566
 
1506 1567
 	// Start from the beginning...
1507
-	if ($reset)
1508
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1568
+	if ($reset) {
1569
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1570
+	}
1509 1571
 
1510 1572
 	// Attempt to get the next message.
1511 1573
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1519,19 +1581,21 @@  discard block
 block discarded – undo
1519 1581
 	if (empty($context['icon_sources']))
1520 1582
 	{
1521 1583
 		$context['icon_sources'] = array();
1522
-		foreach ($context['stable_icons'] as $icon)
1523
-			$context['icon_sources'][$icon] = 'images_url';
1584
+		foreach ($context['stable_icons'] as $icon) {
1585
+					$context['icon_sources'][$icon] = 'images_url';
1586
+		}
1524 1587
 	}
1525 1588
 
1526 1589
 	// Message Icon Management... check the images exist.
1527 1590
 	if (empty($modSettings['messageIconChecks_disable']))
1528 1591
 	{
1529 1592
 		// If the current icon isn't known, then we need to do something...
1530
-		if (!isset($context['icon_sources'][$message['icon']]))
1531
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1593
+		if (!isset($context['icon_sources'][$message['icon']])) {
1594
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1595
+		}
1596
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1597
+			$context['icon_sources'][$message['icon']] = 'images_url';
1532 1598
 	}
1533
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1534
-		$context['icon_sources'][$message['icon']] = 'images_url';
1535 1599
 
1536 1600
 	// If you're a lazy bum, you probably didn't give a subject...
1537 1601
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1556,8 +1620,7 @@  discard block
 block discarded – undo
1556 1620
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1557 1621
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1558 1622
 		$memberContext[$message['id_member']]['is_guest'] = true;
1559
-	}
1560
-	else
1623
+	} else
1561 1624
 	{
1562 1625
 		// Define this here to make things a bit more readable
1563 1626
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1580,8 +1643,9 @@  discard block
 block discarded – undo
1580 1643
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1581 1644
 
1582 1645
 	// If it's in the recycle bin we need to override whatever icon we did have.
1583
-	if (!empty($board_info['recycle']))
1584
-		$message['icon'] = 'recycled';
1646
+	if (!empty($board_info['recycle'])) {
1647
+			$message['icon'] = 'recycled';
1648
+	}
1585 1649
 
1586 1650
 	require_once($sourcedir . '/Subs-Attachments.php');
1587 1651
 
@@ -1625,32 +1689,36 @@  discard block
 block discarded – undo
1625 1689
 	}
1626 1690
 
1627 1691
 	// Are likes enable?
1628
-	if (!empty($modSettings['enable_likes']))
1629
-		$output['likes'] = array(
1692
+	if (!empty($modSettings['enable_likes'])) {
1693
+			$output['likes'] = array(
1630 1694
 			'count' => $message['likes'],
1631 1695
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1632 1696
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1633 1697
 		);
1698
+	}
1634 1699
 
1635 1700
 	// Is this user the message author?
1636 1701
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1637
-	if (!empty($output['modified']['name']))
1638
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1702
+	if (!empty($output['modified']['name'])) {
1703
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1704
+	}
1639 1705
 
1640 1706
 	// Did they give a reason for editing?
1641
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1642
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1707
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1708
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1709
+	}
1643 1710
 
1644 1711
 	// Any custom profile fields?
1645
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1646
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1712
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1713
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1647 1714
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1715
+	}
1648 1716
 
1649
-	if (empty($options['view_newest_first']))
1650
-		$counter++;
1651
-
1652
-	else
1653
-		$counter--;
1717
+	if (empty($options['view_newest_first'])) {
1718
+			$counter++;
1719
+	} else {
1720
+			$counter--;
1721
+	}
1654 1722
 
1655 1723
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1656 1724
 
@@ -1676,8 +1744,9 @@  discard block
 block discarded – undo
1676 1744
  */
1677 1745
 function approved_attach_sort($a, $b)
1678 1746
 {
1679
-	if ($a['is_approved'] == $b['is_approved'])
1680
-		return 0;
1747
+	if ($a['is_approved'] == $b['is_approved']) {
1748
+			return 0;
1749
+	}
1681 1750
 
1682 1751
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1683 1752
 }
@@ -1694,16 +1763,19 @@  discard block
 block discarded – undo
1694 1763
 
1695 1764
 	require_once($sourcedir . '/RemoveTopic.php');
1696 1765
 
1697
-	if (empty($_REQUEST['msgs']))
1698
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1766
+	if (empty($_REQUEST['msgs'])) {
1767
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1768
+	}
1699 1769
 
1700 1770
 	$messages = array();
1701
-	foreach ($_REQUEST['msgs'] as $dummy)
1702
-		$messages[] = (int) $dummy;
1771
+	foreach ($_REQUEST['msgs'] as $dummy) {
1772
+			$messages[] = (int) $dummy;
1773
+	}
1703 1774
 
1704 1775
 	// We are restoring messages. We handle this in another place.
1705
-	if (isset($_REQUEST['restore_selected']))
1706
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1776
+	if (isset($_REQUEST['restore_selected'])) {
1777
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1778
+	}
1707 1779
 	if (isset($_REQUEST['split_selection']))
1708 1780
 	{
1709 1781
 		$request = $smcFunc['db_query']('', '
@@ -1722,8 +1794,9 @@  discard block
 block discarded – undo
1722 1794
 	}
1723 1795
 
1724 1796
 	// Allowed to delete any message?
1725
-	if (allowedTo('delete_any'))
1726
-		$allowed_all = true;
1797
+	if (allowedTo('delete_any')) {
1798
+			$allowed_all = true;
1799
+	}
1727 1800
 	// Allowed to delete replies to their messages?
1728 1801
 	elseif (allowedTo('delete_replies'))
1729 1802
 	{
@@ -1740,13 +1813,14 @@  discard block
 block discarded – undo
1740 1813
 		$smcFunc['db_free_result']($request);
1741 1814
 
1742 1815
 		$allowed_all = $starter == $user_info['id'];
1816
+	} else {
1817
+			$allowed_all = false;
1743 1818
 	}
1744
-	else
1745
-		$allowed_all = false;
1746 1819
 
1747 1820
 	// Make sure they're allowed to delete their own messages, if not any.
1748
-	if (!$allowed_all)
1749
-		isAllowedTo('delete_own');
1821
+	if (!$allowed_all) {
1822
+			isAllowedTo('delete_own');
1823
+	}
1750 1824
 
1751 1825
 	// Allowed to remove which messages?
1752 1826
 	$request = $smcFunc['db_query']('', '
@@ -1766,8 +1840,9 @@  discard block
 block discarded – undo
1766 1840
 	$messages = array();
1767 1841
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1768 1842
 	{
1769
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1770
-			continue;
1843
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1844
+					continue;
1845
+		}
1771 1846
 
1772 1847
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1773 1848
 	}
@@ -1790,17 +1865,20 @@  discard block
 block discarded – undo
1790 1865
 	foreach ($messages as $message => $info)
1791 1866
 	{
1792 1867
 		// Just skip the first message - if it's not the last.
1793
-		if ($message == $first_message && $message != $last_message)
1794
-			continue;
1868
+		if ($message == $first_message && $message != $last_message) {
1869
+					continue;
1870
+		}
1795 1871
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1796
-		elseif ($message == $first_message)
1797
-			$topicGone = true;
1872
+		elseif ($message == $first_message) {
1873
+					$topicGone = true;
1874
+		}
1798 1875
 
1799 1876
 		removeMessage($message);
1800 1877
 
1801 1878
 		// Log this moderation action ;).
1802
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1803
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1879
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
1880
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1881
+		}
1804 1882
 	}
1805 1883
 
1806 1884
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Smileys/alienine/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Errors.template.php 1 patch
Braces   +24 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 {
24 24
 	global $context, $txt;
25 25
 
26
-	if (!empty($context['simple_action']))
27
-		echo '
26
+	if (!empty($context['simple_action'])) {
27
+			echo '
28 28
 	<strong>
29 29
 		', $context['error_title'], '
30 30
 	</strong><br>
31 31
 	<div ', $context['error_code'], 'class="padding">
32 32
 		', $context['error_message'], '
33 33
 	</div>';
34
-	else
34
+	} else
35 35
 	{
36 36
 		echo '
37 37
 	<div id="fatal_error">
@@ -85,21 +85,23 @@  discard block
 block discarded – undo
85 85
 
86 86
 	$error_types = array();
87 87
 
88
-	foreach ($context['error_types'] as $type => $details)
89
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
88
+	foreach ($context['error_types'] as $type => $details) {
89
+			$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
90
+	}
90 91
 
91 92
 	echo '
92 93
 						', implode(' | ', $error_types), '
93 94
 					</td>
94 95
 				</tr>';
95 96
 
96
-	if ($context['has_filter'])
97
-		echo '
97
+	if ($context['has_filter']) {
98
+			echo '
98 99
 				<tr>
99 100
 					<td colspan="3" class="windowbg">
100 101
 						<strong>', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], ' [<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
101 102
 					</td>
102 103
 				</tr>';
104
+	}
103 105
 
104 106
 	echo '
105 107
 				<tr>
@@ -110,11 +112,12 @@  discard block
 block discarded – undo
110 112
 				</tr>';
111 113
 
112 114
 	// No errors, then show a message
113
-	if (count($context['errors']) == 0)
114
-		echo '
115
+	if (count($context['errors']) == 0) {
116
+			echo '
115 117
 				<tr class="windowbg">
116 118
 					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
117 119
 				</tr>';
120
+	}
118 121
 
119 122
 	// We have some errors, must be some mods installed :P
120 123
 	foreach ($context['errors'] as $error)
@@ -128,16 +131,18 @@  discard block
 block discarded – undo
128 131
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a>
129 132
 							', $error['time'], '<br>';
130 133
 
131
-		if (!empty($error['member']['ip']))
132
-			echo '
134
+		if (!empty($error['member']['ip'])) {
135
+					echo '
133 136
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><span class="generic_icons filter centericon"></span></a>
134 137
 							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>';
138
+		}
135 139
 		
136
-		if ($error['member']['session'] != '')
137
-			echo '
140
+		if ($error['member']['session'] != '') {
141
+					echo '
138 142
 							<br>
139 143
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><span class="generic_icons filter centericon"></span></a>
140 144
 							', $error['member']['session'], '<br>';
145
+		}
141 146
 
142 147
 		echo '
143 148
 						</div>
@@ -152,12 +157,13 @@  discard block
 block discarded – undo
152 157
 							<a href="', $error['url']['html'], '">', $error['url']['html'], '</a>
153 158
 ';
154 159
 
155
-		if (!empty($error['file']))
156
-			echo '
160
+		if (!empty($error['file'])) {
161
+					echo '
157 162
 							<div>
158 163
 								<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '">'
159 164
 				. '					<span class="generic_icons filter"></span></a> ', $error['file']['link'], ' (', $txt['line'], ' ', $error['file']['line'], ')
160 165
 							</div>';
166
+		}
161 167
 
162 168
 		echo '
163 169
 						</div>
@@ -186,9 +192,10 @@  discard block
 block discarded – undo
186 192
 				</div>
187 193
 			</div>';
188 194
 
189
-	if ($context['sort_direction'] == 'down')
190
-		echo '
195
+	if ($context['sort_direction'] == 'down') {
196
+			echo '
191 197
 			<input type="hidden" name="desc" value="1">';
198
+	}
192 199
 
193 200
 	echo '
194 201
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
Please login to merge, or discard this patch.
Sources/Themes.php 1 patch
Braces   +348 added lines, -271 removed lines patch added patch discarded remove patch
@@ -30,8 +30,9 @@  discard block
 block discarded – undo
30 30
  * @version 2.1 Beta 4
31 31
  */
32 32
 
33
-if (!defined('SMF'))
33
+if (!defined('SMF')) {
34 34
 	die('No direct access...');
35
+}
35 36
 
36 37
 /**
37 38
  * Subaction handler - manages the action and delegates control to the proper
@@ -103,12 +104,12 @@  discard block
 block discarded – undo
103 104
 	cache_put_data('minimized_css', null);
104 105
 
105 106
 	// Follow the sa or just go to administration.
106
-	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']]))
107
-		call_helper($subActions[$_GET['sa']]);
108
-
109
-	else
110
-		call_helper($subActions['admin']);
111
-}
107
+	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) {
108
+			call_helper($subActions[$_GET['sa']]);
109
+	} else {
110
+			call_helper($subActions['admin']);
111
+	}
112
+	}
112 113
 
113 114
 /**
114 115
  * This function allows administration of themes and their settings,
@@ -130,15 +131,16 @@  discard block
 block discarded – undo
130 131
 		checkSession();
131 132
 		validateToken('admin-tm');
132 133
 
133
-		if (isset($_POST['options']['known_themes']))
134
-			foreach ($_POST['options']['known_themes'] as $key => $id)
134
+		if (isset($_POST['options']['known_themes'])) {
135
+					foreach ($_POST['options']['known_themes'] as $key => $id)
135 136
 				$_POST['options']['known_themes'][$key] = (int) $id;
137
+		} else {
138
+					fatal_lang_error('themes_none_selectable', false);
139
+		}
136 140
 
137
-		else
138
-			fatal_lang_error('themes_none_selectable', false);
139
-
140
-		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes']))
141
-			fatal_lang_error('themes_default_selectable', false);
141
+		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) {
142
+					fatal_lang_error('themes_default_selectable', false);
143
+		}
142 144
 
143 145
 		// Commit the new settings.
144 146
 		updateSettings(array(
@@ -146,8 +148,9 @@  discard block
 block discarded – undo
146 148
 			'theme_guests' => $_POST['options']['theme_guests'],
147 149
 			'knownThemes' => implode(',', $_POST['options']['known_themes']),
148 150
 		));
149
-		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes']))
150
-			updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
151
+		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) {
152
+					updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
153
+		}
151 154
 
152 155
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=admin');
153 156
 	}
@@ -166,8 +169,9 @@  discard block
 block discarded – undo
166 169
 	// Look for a non existent theme directory. (ie theme87.)
167 170
 	$theme_dir = $boarddir . '/Themes/theme';
168 171
 	$i = 1;
169
-	while (file_exists($theme_dir . $i))
170
-		$i++;
172
+	while (file_exists($theme_dir . $i)) {
173
+			$i++;
174
+	}
171 175
 
172 176
 	$context['new_theme_name'] = 'theme' . $i;
173 177
 
@@ -189,8 +193,9 @@  discard block
 block discarded – undo
189 193
 	loadLanguage('Admin');
190 194
 	isAllowedTo('admin_forum');
191 195
 
192
-	if (isset($_REQUEST['th']))
193
-		return SetThemeSettings();
196
+	if (isset($_REQUEST['th'])) {
197
+			return SetThemeSettings();
198
+	}
194 199
 
195 200
 	if (isset($_POST['save']))
196 201
 	{
@@ -274,12 +279,13 @@  discard block
 block discarded – undo
274 279
 		$context['themes'] = array();
275 280
 		while ($row = $smcFunc['db_fetch_assoc']($request))
276 281
 		{
277
-			if (!isset($context['themes'][$row['id_theme']]))
278
-				$context['themes'][$row['id_theme']] = array(
282
+			if (!isset($context['themes'][$row['id_theme']])) {
283
+							$context['themes'][$row['id_theme']] = array(
279 284
 					'id' => $row['id_theme'],
280 285
 					'num_default_options' => 0,
281 286
 					'num_members' => 0,
282 287
 				);
288
+			}
283 289
 			$context['themes'][$row['id_theme']][$row['variable']] = $row['value'];
284 290
 		}
285 291
 		$smcFunc['db_free_result']($request);
@@ -293,8 +299,9 @@  discard block
 block discarded – undo
293 299
 				'guest_member' => -1,
294 300
 			)
295 301
 		);
296
-		while ($row = $smcFunc['db_fetch_assoc']($request))
297
-			$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
302
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
303
+					$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
304
+		}
298 305
 		$smcFunc['db_free_result']($request);
299 306
 
300 307
 		// Need to make sure we don't do custom fields.
@@ -305,8 +312,9 @@  discard block
 block discarded – undo
305 312
 			)
306 313
 		);
307 314
 		$customFields = array();
308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
309
-			$customFields[] = $row['col_name'];
315
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
316
+					$customFields[] = $row['col_name'];
317
+		}
310 318
 		$smcFunc['db_free_result']($request);
311 319
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
312 320
 
@@ -321,14 +329,16 @@  discard block
 block discarded – undo
321 329
 				'custom_fields' => empty($customFields) ? array() : $customFields,
322 330
 			)
323 331
 		);
324
-		while ($row = $smcFunc['db_fetch_assoc']($request))
325
-			$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
332
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
333
+					$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
334
+		}
326 335
 		$smcFunc['db_free_result']($request);
327 336
 
328 337
 		// There has to be a Settings template!
329
-		foreach ($context['themes'] as $k => $v)
330
-			if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
338
+		foreach ($context['themes'] as $k => $v) {
339
+					if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
331 340
 				unset($context['themes'][$k]);
341
+		}
332 342
 
333 343
 		loadTemplate('Themes');
334 344
 		$context['sub_template'] = 'reset_list';
@@ -343,16 +353,19 @@  discard block
 block discarded – undo
343 353
 		checkSession();
344 354
 		validateToken('admin-sto');
345 355
 
346
-		if (empty($_POST['options']))
347
-			$_POST['options'] = array();
348
-		if (empty($_POST['default_options']))
349
-			$_POST['default_options'] = array();
356
+		if (empty($_POST['options'])) {
357
+					$_POST['options'] = array();
358
+		}
359
+		if (empty($_POST['default_options'])) {
360
+					$_POST['default_options'] = array();
361
+		}
350 362
 
351 363
 		// Set up the sql query.
352 364
 		$setValues = array();
353 365
 
354
-		foreach ($_POST['options'] as $opt => $val)
355
-			$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
366
+		foreach ($_POST['options'] as $opt => $val) {
367
+					$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
368
+		}
356 369
 
357 370
 		$old_settings = array();
358 371
 		foreach ($_POST['default_options'] as $opt => $val)
@@ -366,8 +379,8 @@  discard block
 block discarded – undo
366 379
 		if (!empty($setValues))
367 380
 		{
368 381
 			// Are there options in non-default themes set that should be cleared?
369
-			if (!empty($old_settings))
370
-				$smcFunc['db_query']('', '
382
+			if (!empty($old_settings)) {
383
+							$smcFunc['db_query']('', '
371 384
 					DELETE FROM {db_prefix}themes
372 385
 					WHERE id_theme != {int:default_theme}
373 386
 						AND id_member = {int:guest_member}
@@ -378,6 +391,7 @@  discard block
 block discarded – undo
378 391
 						'old_settings' => $old_settings,
379 392
 					)
380 393
 				);
394
+			}
381 395
 
382 396
 			$smcFunc['db_insert']('replace',
383 397
 				'{db_prefix}themes',
@@ -391,8 +405,7 @@  discard block
 block discarded – undo
391 405
 		cache_put_data('theme_settings-1', null, 90);
392 406
 
393 407
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
394
-	}
395
-	elseif (isset($_POST['submit']) && $_POST['who'] == 1)
408
+	} elseif (isset($_POST['submit']) && $_POST['who'] == 1)
396 409
 	{
397 410
 		checkSession();
398 411
 		validateToken('admin-sto');
@@ -405,9 +418,9 @@  discard block
 block discarded – undo
405 418
 		$old_settings = array();
406 419
 		foreach ($_POST['default_options'] as $opt => $val)
407 420
 		{
408
-			if ($_POST['default_options_master'][$opt] == 0)
409
-				continue;
410
-			elseif ($_POST['default_options_master'][$opt] == 1)
421
+			if ($_POST['default_options_master'][$opt] == 0) {
422
+							continue;
423
+			} elseif ($_POST['default_options_master'][$opt] == 1)
411 424
 			{
412 425
 				// Delete then insert for ease of database compatibility!
413 426
 				$smcFunc['db_query']('substring', '
@@ -433,8 +446,7 @@  discard block
 block discarded – undo
433 446
 				);
434 447
 
435 448
 				$old_settings[] = $opt;
436
-			}
437
-			elseif ($_POST['default_options_master'][$opt] == 2)
449
+			} elseif ($_POST['default_options_master'][$opt] == 2)
438 450
 			{
439 451
 				$smcFunc['db_query']('', '
440 452
 					DELETE FROM {db_prefix}themes
@@ -449,8 +461,8 @@  discard block
 block discarded – undo
449 461
 		}
450 462
 
451 463
 		// Delete options from other themes.
452
-		if (!empty($old_settings))
453
-			$smcFunc['db_query']('', '
464
+		if (!empty($old_settings)) {
465
+					$smcFunc['db_query']('', '
454 466
 				DELETE FROM {db_prefix}themes
455 467
 				WHERE id_theme != {int:default_theme}
456 468
 					AND id_member > {int:no_member}
@@ -461,12 +473,13 @@  discard block
 block discarded – undo
461 473
 					'old_settings' => $old_settings,
462 474
 				)
463 475
 			);
476
+		}
464 477
 
465 478
 		foreach ($_POST['options'] as $opt => $val)
466 479
 		{
467
-			if ($_POST['options_master'][$opt] == 0)
468
-				continue;
469
-			elseif ($_POST['options_master'][$opt] == 1)
480
+			if ($_POST['options_master'][$opt] == 0) {
481
+							continue;
482
+			} elseif ($_POST['options_master'][$opt] == 1)
470 483
 			{
471 484
 				// Delete then insert for ease of database compatibility - again!
472 485
 				$smcFunc['db_query']('substring', '
@@ -491,8 +504,7 @@  discard block
 block discarded – undo
491 504
 						'value' => (is_array($val) ? implode(',', $val) : $val),
492 505
 					)
493 506
 				);
494
-			}
495
-			elseif ($_POST['options_master'][$opt] == 2)
507
+			} elseif ($_POST['options_master'][$opt] == 2)
496 508
 			{
497 509
 				$smcFunc['db_query']('', '
498 510
 					DELETE FROM {db_prefix}themes
@@ -509,8 +521,7 @@  discard block
 block discarded – undo
509 521
 		}
510 522
 
511 523
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
512
-	}
513
-	elseif (!empty($_GET['who']) && $_GET['who'] == 2)
524
+	} elseif (!empty($_GET['who']) && $_GET['who'] == 2)
514 525
 	{
515 526
 		checkSession('get');
516 527
 		validateToken('admin-stor', 'request');
@@ -525,8 +536,9 @@  discard block
 block discarded – undo
525 536
 				)
526 537
 			);
527 538
 			$customFields = array();
528
-			while ($row = $smcFunc['db_fetch_assoc']($request))
529
-				$customFields[] = $row['col_name'];
539
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
540
+							$customFields[] = $row['col_name'];
541
+			}
530 542
 			$smcFunc['db_free_result']($request);
531 543
 		}
532 544
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
@@ -581,13 +593,13 @@  discard block
 block discarded – undo
581 593
 			)
582 594
 		);
583 595
 		$context['theme_options'] = array();
584
-		while ($row = $smcFunc['db_fetch_assoc']($request))
585
-			$context['theme_options'][$row['variable']] = $row['value'];
596
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
597
+					$context['theme_options'][$row['variable']] = $row['value'];
598
+		}
586 599
 		$smcFunc['db_free_result']($request);
587 600
 
588 601
 		$context['theme_options_reset'] = false;
589
-	}
590
-	else
602
+	} else
591 603
 	{
592 604
 		$context['theme_options'] = array();
593 605
 		$context['theme_options_reset'] = true;
@@ -596,30 +608,32 @@  discard block
 block discarded – undo
596 608
 	foreach ($context['options'] as $i => $setting)
597 609
 	{
598 610
 		// Just skip separators
599
-		if (!is_array($setting))
600
-			continue;
611
+		if (!is_array($setting)) {
612
+					continue;
613
+		}
601 614
 
602 615
 		// Is this disabled?
603 616
 		if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled']))
604 617
 		{
605 618
 			unset($context['options'][$i]);
606 619
 			continue;
607
-		}
608
-		elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
620
+		} elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage']))
609 621
 		{
610 622
 			unset($context['options'][$i]);
611 623
 			continue;
612 624
 		}
613 625
 
614
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
615
-			$context['options'][$i]['type'] = 'checkbox';
616
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
617
-			$context['options'][$i]['type'] = 'number';
618
-		elseif ($setting['type'] == 'string')
619
-			$context['options'][$i]['type'] = 'text';
626
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
627
+					$context['options'][$i]['type'] = 'checkbox';
628
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
629
+					$context['options'][$i]['type'] = 'number';
630
+		} elseif ($setting['type'] == 'string') {
631
+					$context['options'][$i]['type'] = 'text';
632
+		}
620 633
 
621
-		if (isset($setting['options']))
622
-			$context['options'][$i]['type'] = 'list';
634
+		if (isset($setting['options'])) {
635
+					$context['options'][$i]['type'] = 'list';
636
+		}
623 637
 
624 638
 		$context['options'][$i]['value'] = !isset($context['theme_options'][$setting['id']]) ? '' : $context['theme_options'][$setting['id']];
625 639
 	}
@@ -644,8 +658,9 @@  discard block
 block discarded – undo
644 658
 {
645 659
 	global $txt, $context, $settings, $modSettings, $smcFunc;
646 660
 
647
-	if (empty($_GET['th']) && empty($_GET['id']))
648
-		return ThemeAdmin();
661
+	if (empty($_GET['th']) && empty($_GET['id'])) {
662
+			return ThemeAdmin();
663
+	}
649 664
 
650 665
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
651 666
 
@@ -656,8 +671,9 @@  discard block
 block discarded – undo
656 671
 	isAllowedTo('admin_forum');
657 672
 
658 673
 	// Validate inputs/user.
659
-	if (empty($_GET['th']))
660
-		fatal_lang_error('no_theme', false);
674
+	if (empty($_GET['th'])) {
675
+			fatal_lang_error('no_theme', false);
676
+	}
661 677
 
662 678
 	// Fetch the smiley sets...
663 679
 	$sets = explode(',', 'none,' . $modSettings['smiley_sets_known']);
@@ -665,8 +681,9 @@  discard block
 block discarded – undo
665 681
 	$context['smiley_sets'] = array(
666 682
 		'' => $txt['smileys_no_default']
667 683
 	);
668
-	foreach ($sets as $i => $set)
669
-		$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
684
+	foreach ($sets as $i => $set) {
685
+			$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
686
+	}
670 687
 
671 688
 	$old_id = $settings['theme_id'];
672 689
 	$old_settings = $settings;
@@ -691,8 +708,9 @@  discard block
 block discarded – undo
691 708
 	if (file_exists($settings['theme_dir'] . '/index.template.php'))
692 709
 	{
693 710
 		$file_contents = implode('', file($settings['theme_dir'] . '/index.template.php'));
694
-		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches))
695
-				eval('global $settings;' . $matches[0]);
711
+		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) {
712
+						eval('global $settings;' . $matches[0]);
713
+		}
696 714
 	}
697 715
 
698 716
 	// Let mods hook into the theme settings.
@@ -704,37 +722,45 @@  discard block
 block discarded – undo
704 722
 		checkSession();
705 723
 		validateToken('admin-sts');
706 724
 
707
-		if (empty($_POST['options']))
708
-			$_POST['options'] = array();
709
-		if (empty($_POST['default_options']))
710
-			$_POST['default_options'] = array();
725
+		if (empty($_POST['options'])) {
726
+					$_POST['options'] = array();
727
+		}
728
+		if (empty($_POST['default_options'])) {
729
+					$_POST['default_options'] = array();
730
+		}
711 731
 
712 732
 		// Make sure items are cast correctly.
713 733
 		foreach ($context['theme_settings'] as $item)
714 734
 		{
715 735
 			// Disregard this item if this is just a separator.
716
-			if (!is_array($item))
717
-				continue;
736
+			if (!is_array($item)) {
737
+							continue;
738
+			}
718 739
 
719 740
 			foreach (array('options', 'default_options') as $option)
720 741
 			{
721
-				if (!isset($_POST[$option][$item['id']]))
722
-					continue;
742
+				if (!isset($_POST[$option][$item['id']])) {
743
+									continue;
744
+				}
723 745
 				// Checkbox.
724
-				elseif (empty($item['type']))
725
-					$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
746
+				elseif (empty($item['type'])) {
747
+									$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
748
+				}
726 749
 				// Number
727
-				elseif ($item['type'] == 'number')
728
-					$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
750
+				elseif ($item['type'] == 'number') {
751
+									$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
752
+				}
729 753
 			}
730 754
 		}
731 755
 
732 756
 		// Set up the sql query.
733 757
 		$inserts = array();
734
-		foreach ($_POST['options'] as $opt => $val)
735
-			$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
736
-		foreach ($_POST['default_options'] as $opt => $val)
737
-			$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
758
+		foreach ($_POST['options'] as $opt => $val) {
759
+					$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
760
+		}
761
+		foreach ($_POST['default_options'] as $opt => $val) {
762
+					$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
763
+		}
738 764
 		// If we're actually inserting something..
739 765
 		if (!empty($inserts))
740 766
 		{
@@ -760,8 +786,9 @@  discard block
 block discarded – undo
760 786
 
761 787
 	foreach ($settings as $setting => $dummy)
762 788
 	{
763
-		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs')))
764
-			$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
789
+		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) {
790
+					$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
791
+		}
765 792
 	}
766 793
 
767 794
 	$context['settings'] = $context['theme_settings'];
@@ -770,18 +797,21 @@  discard block
 block discarded – undo
770 797
 	foreach ($context['settings'] as $i => $setting)
771 798
 	{
772 799
 		// Separators are dummies, so leave them alone.
773
-		if (!is_array($setting))
774
-			continue;
800
+		if (!is_array($setting)) {
801
+					continue;
802
+		}
775 803
 
776
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
777
-			$context['settings'][$i]['type'] = 'checkbox';
778
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
779
-			$context['settings'][$i]['type'] = 'number';
780
-		elseif ($setting['type'] == 'string')
781
-			$context['settings'][$i]['type'] = 'text';
804
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
805
+					$context['settings'][$i]['type'] = 'checkbox';
806
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
807
+					$context['settings'][$i]['type'] = 'number';
808
+		} elseif ($setting['type'] == 'string') {
809
+					$context['settings'][$i]['type'] = 'text';
810
+		}
782 811
 
783
-		if (isset($setting['options']))
784
-			$context['settings'][$i]['type'] = 'list';
812
+		if (isset($setting['options'])) {
813
+					$context['settings'][$i]['type'] = 'list';
814
+		}
785 815
 
786 816
 		$context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']];
787 817
 	}
@@ -834,8 +864,9 @@  discard block
 block discarded – undo
834 864
 	$themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
835 865
 
836 866
 	// You can't delete the default theme!
837
-	if ($themeID == 1)
838
-		fatal_lang_error('no_access', false);
867
+	if ($themeID == 1) {
868
+			fatal_lang_error('no_access', false);
869
+	}
839 870
 
840 871
 	$theme_info = get_single_theme($themeID);
841 872
 
@@ -843,8 +874,9 @@  discard block
 block discarded – undo
843 874
 	remove_theme($themeID);
844 875
 
845 876
 	// And remove all its files and folders too.
846
-	if (!empty($theme_info) && !empty($theme_info['theme_dir']))
847
-		remove_dir($theme_info['theme_dir']);
877
+	if (!empty($theme_info) && !empty($theme_info['theme_dir'])) {
878
+			remove_dir($theme_info['theme_dir']);
879
+	}
848 880
 
849 881
 	// Go back to the list page.
850 882
 	redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id'] . ';done=removing');
@@ -869,12 +901,14 @@  discard block
 block discarded – undo
869 901
 	$enableThemes = explode(',', $modSettings['enableThemes']);
870 902
 
871 903
 	// Are we disabling it?
872
-	if (isset($_GET['disabled']))
873
-		$enableThemes = array_diff($enableThemes, array($themeID));
904
+	if (isset($_GET['disabled'])) {
905
+			$enableThemes = array_diff($enableThemes, array($themeID));
906
+	}
874 907
 
875 908
 	// Nope? then enable it!
876
-	else
877
-		$enableThemes[] = (string) $themeID;
909
+	else {
910
+			$enableThemes[] = (string) $themeID;
911
+	}
878 912
 
879 913
 	// Update the setting.
880 914
 	$enableThemes = strtr(implode(',', $enableThemes), array(',,' => ','));
@@ -909,18 +943,21 @@  discard block
 block discarded – undo
909 943
 
910 944
 	$_SESSION['id_theme'] = 0;
911 945
 
912
-	if (isset($_GET['id']))
913
-		$_GET['th'] = $_GET['id'];
946
+	if (isset($_GET['id'])) {
947
+			$_GET['th'] = $_GET['id'];
948
+	}
914 949
 
915 950
 	// Saving a variant cause JS doesn't work - pretend it did ;)
916 951
 	if (isset($_POST['save']))
917 952
 	{
918 953
 		// Which theme?
919
-		foreach ($_POST['save'] as $k => $v)
920
-			$_GET['th'] = (int) $k;
954
+		foreach ($_POST['save'] as $k => $v) {
955
+					$_GET['th'] = (int) $k;
956
+		}
921 957
 
922
-		if (isset($_POST['vrt'][$k]))
923
-			$_GET['vrt'] = $_POST['vrt'][$k];
958
+		if (isset($_POST['vrt'][$k])) {
959
+					$_GET['vrt'] = $_POST['vrt'][$k];
960
+		}
924 961
 	}
925 962
 
926 963
 	// Have we made a decision, or are we just browsing?
@@ -998,8 +1035,9 @@  discard block
 block discarded – undo
998 1035
 		else
999 1036
 		{
1000 1037
 			// The forum's default theme is always 0 and we
1001
-			if (isset($_GET['th']) && $_GET['th'] == 0)
1002
-					$_GET['th'] = $modSettings['theme_guests'];
1038
+			if (isset($_GET['th']) && $_GET['th'] == 0) {
1039
+								$_GET['th'] = $modSettings['theme_guests'];
1040
+			}
1003 1041
 
1004 1042
 			updateMemberData((int) $_REQUEST['u'], array('id_theme' => (int) $_GET['th']));
1005 1043
 
@@ -1013,8 +1051,9 @@  discard block
 block discarded – undo
1013 1051
 				);
1014 1052
 				cache_put_data('theme_settings-' . $_GET['th'] . ':' . (int) $_REQUEST['u'], null, 90);
1015 1053
 
1016
-				if ($user_info['id'] == $_REQUEST['u'])
1017
-					$_SESSION['id_variant'] = 0;
1054
+				if ($user_info['id'] == $_REQUEST['u']) {
1055
+									$_SESSION['id_variant'] = 0;
1056
+				}
1018 1057
 			}
1019 1058
 
1020 1059
 			redirectexit('action=profile;u=' . (int) $_REQUEST['u'] . ';area=theme');
@@ -1083,12 +1122,13 @@  discard block
 block discarded – undo
1083 1122
 		);
1084 1123
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1085 1124
 		{
1086
-			if (!isset($context['available_themes'][$row['id_theme']]))
1087
-				$context['available_themes'][$row['id_theme']] = array(
1125
+			if (!isset($context['available_themes'][$row['id_theme']])) {
1126
+							$context['available_themes'][$row['id_theme']] = array(
1088 1127
 					'id' => $row['id_theme'],
1089 1128
 					'selected' => $context['current_theme'] == $row['id_theme'],
1090 1129
 					'num_users' => 0
1091 1130
 				);
1131
+			}
1092 1132
 			$context['available_themes'][$row['id_theme']][$row['variable']] = $row['value'];
1093 1133
 		}
1094 1134
 		$smcFunc['db_free_result']($request);
@@ -1101,9 +1141,9 @@  discard block
 block discarded – undo
1101 1141
 			'num_users' => 0
1102 1142
 		);
1103 1143
 		$guest_theme = 0;
1144
+	} else {
1145
+			$guest_theme = $modSettings['theme_guests'];
1104 1146
 	}
1105
-	else
1106
-		$guest_theme = $modSettings['theme_guests'];
1107 1147
 
1108 1148
 	$request = $smcFunc['db_query']('', '
1109 1149
 		SELECT id_theme, COUNT(*) AS the_count
@@ -1116,15 +1156,17 @@  discard block
 block discarded – undo
1116 1156
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1117 1157
 	{
1118 1158
 		// Figure out which theme it is they are REALLY using.
1119
-		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes'])))
1120
-			$row['id_theme'] = $guest_theme;
1121
-		elseif (empty($modSettings['theme_allow']))
1122
-			$row['id_theme'] = $guest_theme;
1159
+		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) {
1160
+					$row['id_theme'] = $guest_theme;
1161
+		} elseif (empty($modSettings['theme_allow'])) {
1162
+					$row['id_theme'] = $guest_theme;
1163
+		}
1123 1164
 
1124
-		if (isset($context['available_themes'][$row['id_theme']]))
1125
-			$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1126
-		else
1127
-			$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1165
+		if (isset($context['available_themes'][$row['id_theme']])) {
1166
+					$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1167
+		} else {
1168
+					$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1169
+		}
1128 1170
 	}
1129 1171
 	$smcFunc['db_free_result']($request);
1130 1172
 
@@ -1143,8 +1185,9 @@  discard block
 block discarded – undo
1143 1185
 				'id_member' => isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? array(-1, $context['current_member']) : array(-1),
1144 1186
 			)
1145 1187
 		);
1146
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1147
-			$variant_preferences[$row['id_theme']] = $row['value'];
1188
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1189
+					$variant_preferences[$row['id_theme']] = $row['value'];
1190
+		}
1148 1191
 		$smcFunc['db_free_result']($request);
1149 1192
 	}
1150 1193
 
@@ -1155,17 +1198,18 @@  discard block
 block discarded – undo
1155 1198
 	foreach ($context['available_themes'] as $id_theme => $theme_data)
1156 1199
 	{
1157 1200
 		// Don't try to load the forum or board default theme's data... it doesn't have any!
1158
-		if ($id_theme == 0)
1159
-			continue;
1201
+		if ($id_theme == 0) {
1202
+					continue;
1203
+		}
1160 1204
 
1161 1205
 		// The thumbnail needs the correct path.
1162 1206
 		$settings['images_url'] = &$theme_data['images_url'];
1163 1207
 
1164
-		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'))
1165
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1166
-		elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'))
1167
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1168
-		else
1208
+		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) {
1209
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1210
+		} elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) {
1211
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1212
+		} else
1169 1213
 		{
1170 1214
 			$txt['theme_thumbnail_href'] = $theme_data['images_url'] . '/thumbnail.png';
1171 1215
 			$txt['theme_description'] = '';
@@ -1190,15 +1234,17 @@  discard block
 block discarded – undo
1190 1234
 					loadLanguage('Settings');
1191 1235
 
1192 1236
 					$context['available_themes'][$id_theme]['variants'] = array();
1193
-					foreach ($settings['theme_variants'] as $variant)
1194
-						$context['available_themes'][$id_theme]['variants'][$variant] = array(
1237
+					foreach ($settings['theme_variants'] as $variant) {
1238
+											$context['available_themes'][$id_theme]['variants'][$variant] = array(
1195 1239
 							'label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant,
1196 1240
 							'thumbnail' => !file_exists($theme_data['theme_dir'] . '/images/thumbnail.png') || file_exists($theme_data['theme_dir'] . '/images/thumbnail_' . $variant . '.png') ? $theme_data['images_url'] . '/thumbnail_' . $variant . '.png' : ($theme_data['images_url'] . '/thumbnail.png'),
1197 1241
 						);
1242
+					}
1198 1243
 
1199 1244
 					$context['available_themes'][$id_theme]['selected_variant'] = isset($_GET['vrt']) ? $_GET['vrt'] : (!empty($variant_preferences[$id_theme]) ? $variant_preferences[$id_theme] : (!empty($settings['default_variant']) ? $settings['default_variant'] : $settings['theme_variants'][0]));
1200
-					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail']))
1201
-						$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1245
+					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) {
1246
+											$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1247
+					}
1202 1248
 
1203 1249
 					$context['available_themes'][$id_theme]['thumbnail_href'] = $context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'];
1204 1250
 					// Allow themes to override the text.
@@ -1214,8 +1260,9 @@  discard block
 block discarded – undo
1214 1260
 	// As long as we're not doing the default theme...
1215 1261
 	if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0)
1216 1262
 	{
1217
-		if ($guest_theme != 0)
1218
-			$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1263
+		if ($guest_theme != 0) {
1264
+					$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1265
+		}
1219 1266
 
1220 1267
 		$context['available_themes'][0]['id'] = 0;
1221 1268
 		$context['available_themes'][0]['name'] = $txt['theme_forum_default'];
@@ -1264,14 +1311,16 @@  discard block
 block discarded – undo
1264 1311
 		$action = $smcFunc['htmlspecialchars'](trim($_GET['do']));
1265 1312
 
1266 1313
 		// Got any info from the specific form?
1267
-		if (!isset($_POST['save_' . $action]))
1268
-			fatal_lang_error('theme_install_no_action', false);
1314
+		if (!isset($_POST['save_' . $action])) {
1315
+					fatal_lang_error('theme_install_no_action', false);
1316
+		}
1269 1317
 
1270 1318
 		validateToken('admin-t-' . $action);
1271 1319
 
1272 1320
 		// Hopefully the themes directory is writable, or we might have a problem.
1273
-		if (!is_writable($themedir))
1274
-			fatal_lang_error('theme_install_write_error', 'critical');
1321
+		if (!is_writable($themedir)) {
1322
+					fatal_lang_error('theme_install_write_error', 'critical');
1323
+		}
1275 1324
 
1276 1325
 		// Call the function and handle the result.
1277 1326
 		$result = $subActions[$action]();
@@ -1286,9 +1335,10 @@  discard block
 block discarded – undo
1286 1335
 	}
1287 1336
 
1288 1337
 	// Nope, show a nice error.
1289
-	else
1290
-		fatal_lang_error('theme_install_no_action', false);
1291
-}
1338
+	else {
1339
+			fatal_lang_error('theme_install_no_action', false);
1340
+	}
1341
+	}
1292 1342
 
1293 1343
 /**
1294 1344
  * Installs a theme from a theme package.
@@ -1304,8 +1354,9 @@  discard block
 block discarded – undo
1304 1354
 	$dirtemp = $themedir . '/temp';
1305 1355
 
1306 1356
 	// Make sure the temp dir doesn't already exist
1307
-	if (file_exists($dirtemp))
1308
-		remove_dir($dirtemp);
1357
+	if (file_exists($dirtemp)) {
1358
+			remove_dir($dirtemp);
1359
+	}
1309 1360
 
1310 1361
 	// Create the temp dir.
1311 1362
 	mkdir($dirtemp, 0777);
@@ -1317,17 +1368,20 @@  discard block
 block discarded – undo
1317 1368
 		smf_chmod($dirtemp, '0755');
1318 1369
 
1319 1370
 		// How about now?
1320
-		if (!is_writable($dirtemp))
1321
-			fatal_lang_error('theme_install_write_error', 'critical');
1371
+		if (!is_writable($dirtemp)) {
1372
+					fatal_lang_error('theme_install_write_error', 'critical');
1373
+		}
1322 1374
 	}
1323 1375
 
1324 1376
 	// This happens when the admin session is gone and the user has to login again.
1325
-	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz']))
1326
-		redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1377
+	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) {
1378
+			redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1379
+	}
1327 1380
 
1328 1381
 	// Another error check layer, something went wrong with the upload.
1329
-	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0)
1330
-		fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1382
+	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) {
1383
+			fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1384
+	}
1331 1385
 
1332 1386
 	// Get the theme's name.
1333 1387
 	$name = pathinfo($_FILES['theme_gz']['name'], PATHINFO_FILENAME);
@@ -1358,11 +1412,10 @@  discard block
 block discarded – undo
1358 1412
 
1359 1413
 		// return all the info.
1360 1414
 		return $context['to_install'];
1415
+	} else {
1416
+			fatal_lang_error('theme_install_error_title', false);
1417
+	}
1361 1418
 	}
1362
-
1363
-	else
1364
-		fatal_lang_error('theme_install_error_title', false);
1365
-}
1366 1419
 
1367 1420
 /**
1368 1421
  * Makes a copy from the default theme, assigns a name for it and installs it.
@@ -1376,15 +1429,17 @@  discard block
 block discarded – undo
1376 1429
 	global $forum_version;
1377 1430
 
1378 1431
 	// There's gotta be something to work with.
1379
-	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy']))
1380
-		fatal_lang_error('theme_install_error_title', false);
1432
+	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) {
1433
+			fatal_lang_error('theme_install_error_title', false);
1434
+	}
1381 1435
 
1382 1436
 	// Get a cleaner version.
1383 1437
 	$name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']);
1384 1438
 
1385 1439
 	// Is there a theme already named like this?
1386
-	if (file_exists($themedir . '/' . $name))
1387
-		fatal_lang_error('theme_install_already_dir', false);
1440
+	if (file_exists($themedir . '/' . $name)) {
1441
+			fatal_lang_error('theme_install_already_dir', false);
1442
+	}
1388 1443
 
1389 1444
 	// This is a brand new theme so set all possible values.
1390 1445
 	$context['to_install'] = array(
@@ -1404,8 +1459,9 @@  discard block
 block discarded – undo
1404 1459
 
1405 1460
 	// Buy some time.
1406 1461
 	@set_time_limit(600);
1407
-	if (function_exists('apache_reset_timeout'))
1408
-		@apache_reset_timeout();
1462
+	if (function_exists('apache_reset_timeout')) {
1463
+			@apache_reset_timeout();
1464
+	}
1409 1465
 
1410 1466
 	// Create subdirectories for css and javascript files.
1411 1467
 	mkdir($context['to_install']['theme_dir'] . '/css', 0777);
@@ -1441,12 +1497,13 @@  discard block
 block discarded – undo
1441 1497
 
1442 1498
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1443 1499
 	{
1444
-		if ($row['variable'] == 'theme_templates')
1445
-			$theme_templates = $row['value'];
1446
-		elseif ($row['variable'] == 'theme_layers')
1447
-			$theme_layers = $row['value'];
1448
-		else
1449
-			continue;
1500
+		if ($row['variable'] == 'theme_templates') {
1501
+					$theme_templates = $row['value'];
1502
+		} elseif ($row['variable'] == 'theme_layers') {
1503
+					$theme_layers = $row['value'];
1504
+		} else {
1505
+					continue;
1506
+		}
1450 1507
 	}
1451 1508
 
1452 1509
 	$smcFunc['db_free_result']($request);
@@ -1505,12 +1562,14 @@  discard block
 block discarded – undo
1505 1562
 	global $themedir, $themeurl, $context;
1506 1563
 
1507 1564
 	// Cannot use the theme dir as a theme dir.
1508
-	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir))
1509
-		fatal_lang_error('theme_install_invalid_dir', false);
1565
+	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) {
1566
+			fatal_lang_error('theme_install_invalid_dir', false);
1567
+	}
1510 1568
 
1511 1569
 	// Check is there is "something" on the dir.
1512
-	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml'))
1513
-		fatal_lang_error('theme_install_error', false);
1570
+	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) {
1571
+			fatal_lang_error('theme_install_error', false);
1572
+	}
1514 1573
 
1515 1574
 	$name = basename($_REQUEST['theme_dir']);
1516 1575
 	$name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);
@@ -1554,24 +1613,27 @@  discard block
 block discarded – undo
1554 1613
 	}
1555 1614
 
1556 1615
 	// Any special layers?
1557
-	if (isset($settings['catch_action']['layers']))
1558
-		$context['template_layers'] = $settings['catch_action']['layers'];
1616
+	if (isset($settings['catch_action']['layers'])) {
1617
+			$context['template_layers'] = $settings['catch_action']['layers'];
1618
+	}
1559 1619
 
1560 1620
 	// Any function to call?
1561 1621
 	if (isset($settings['catch_action']['function']))
1562 1622
 	{
1563 1623
 		$hook = $settings['catch_action']['function'];
1564 1624
 
1565
-		if (!isset($settings['catch_action']['filename']))
1566
-			$settings['catch_action']['filename'] = '';
1625
+		if (!isset($settings['catch_action']['filename'])) {
1626
+					$settings['catch_action']['filename'] = '';
1627
+		}
1567 1628
 
1568 1629
 		add_integration_function('integrate_wrap_action', $hook, false, $settings['catch_action']['filename'], false);
1569 1630
 		call_integration_hook('integrate_wrap_action');
1570 1631
 	}
1571 1632
 	// And finally, the main sub template ;).
1572
-	if (isset($settings['catch_action']['sub_template']))
1573
-		$context['sub_template'] = $settings['catch_action']['sub_template'];
1574
-}
1633
+	if (isset($settings['catch_action']['sub_template'])) {
1634
+			$context['sub_template'] = $settings['catch_action']['sub_template'];
1635
+	}
1636
+	}
1575 1637
 
1576 1638
 /**
1577 1639
  * Set an option via javascript.
@@ -1590,12 +1652,14 @@  discard block
 block discarded – undo
1590 1652
 	checkSession('get');
1591 1653
 
1592 1654
 	// This good-for-nothing pixel is being used to keep the session alive.
1593
-	if (empty($_GET['var']) || !isset($_GET['val']))
1594
-		redirectexit($settings['images_url'] . '/blank.png');
1655
+	if (empty($_GET['var']) || !isset($_GET['val'])) {
1656
+			redirectexit($settings['images_url'] . '/blank.png');
1657
+	}
1595 1658
 
1596 1659
 	// Sorry, guests can't go any further than this.
1597
-	if ($user_info['is_guest'] || $user_info['id'] == 0)
1598
-		obExit(false);
1660
+	if ($user_info['is_guest'] || $user_info['id'] == 0) {
1661
+			obExit(false);
1662
+	}
1599 1663
 
1600 1664
 	$reservedVars = array(
1601 1665
 		'actual_theme_url',
@@ -1618,8 +1682,9 @@  discard block
 block discarded – undo
1618 1682
 	);
1619 1683
 
1620 1684
 	// Can't change reserved vars.
1621
-	if (in_array(strtolower($_GET['var']), $reservedVars))
1622
-		redirectexit($settings['images_url'] . '/blank.png');
1685
+	if (in_array(strtolower($_GET['var']), $reservedVars)) {
1686
+			redirectexit($settings['images_url'] . '/blank.png');
1687
+	}
1623 1688
 
1624 1689
 	// Use a specific theme?
1625 1690
 	if (isset($_GET['th']) || isset($_GET['id']))
@@ -1635,8 +1700,9 @@  discard block
 block discarded – undo
1635 1700
 	{
1636 1701
 		$options['admin_preferences'] = !empty($options['admin_preferences']) ? $smcFunc['json_decode']($options['admin_preferences'], true) : array();
1637 1702
 		// New thingy...
1638
-		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5)
1639
-			$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1703
+		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) {
1704
+					$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1705
+		}
1640 1706
 
1641 1707
 		// Change the value to be something nice,
1642 1708
 		$_GET['val'] = $smcFunc['json_encode']($options['admin_preferences']);
@@ -1666,8 +1732,9 @@  discard block
 block discarded – undo
1666 1732
 	global $context, $scripturl, $boarddir, $smcFunc, $txt;
1667 1733
 
1668 1734
 	// @todo Should this be removed?
1669
-	if (isset($_REQUEST['preview']))
1670
-		die('die() with fire');
1735
+	if (isset($_REQUEST['preview'])) {
1736
+			die('die() with fire');
1737
+	}
1671 1738
 
1672 1739
 	isAllowedTo('admin_forum');
1673 1740
 	loadTemplate('Themes');
@@ -1681,11 +1748,11 @@  discard block
 block discarded – undo
1681 1748
 		foreach ($context['themes'] as $key => $theme)
1682 1749
 		{
1683 1750
 			// There has to be a Settings template!
1684
-			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css'))
1685
-				unset($context['themes'][$key]);
1686
-
1687
-			else
1688
-				$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1751
+			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) {
1752
+							unset($context['themes'][$key]);
1753
+			} else {
1754
+							$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1755
+			}
1689 1756
 		}
1690 1757
 
1691 1758
 		$context['sub_template'] = 'edit_list';
@@ -1700,22 +1767,24 @@  discard block
 block discarded – undo
1700 1767
 	$context['theme_id'] = $currentTheme['id'];
1701 1768
 	$context['browse_title'] = sprintf($txt['themeadmin_browsing_theme'], $currentTheme['name']);
1702 1769
 
1703
-	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css'))
1704
-		fatal_lang_error('theme_edit_missing', false);
1770
+	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) {
1771
+			fatal_lang_error('theme_edit_missing', false);
1772
+	}
1705 1773
 
1706 1774
 	if (!isset($_REQUEST['filename']))
1707 1775
 	{
1708 1776
 		if (isset($_GET['directory']))
1709 1777
 		{
1710
-			if (substr($_GET['directory'], 0, 1) == '.')
1711
-				$_GET['directory'] = '';
1712
-			else
1778
+			if (substr($_GET['directory'], 0, 1) == '.') {
1779
+							$_GET['directory'] = '';
1780
+			} else
1713 1781
 			{
1714 1782
 				$_GET['directory'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_GET['directory']);
1715 1783
 
1716 1784
 				$temp = realpath($currentTheme['theme_dir'] . '/' . $_GET['directory']);
1717
-				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1718
-					$_GET['directory'] = '';
1785
+				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1786
+									$_GET['directory'] = '';
1787
+				}
1719 1788
 			}
1720 1789
 		}
1721 1790
 
@@ -1734,37 +1803,39 @@  discard block
 block discarded – undo
1734 1803
 				'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $temp,
1735 1804
 				'size' => '',
1736 1805
 			));
1806
+		} else {
1807
+					$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1737 1808
 		}
1738
-		else
1739
-			$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1740 1809
 
1741 1810
 		$context['sub_template'] = 'edit_browse';
1742 1811
 
1743 1812
 		return;
1744
-	}
1745
-	else
1813
+	} else
1746 1814
 	{
1747
-		if (substr($_REQUEST['filename'], 0, 1) == '.')
1748
-			$_REQUEST['filename'] = '';
1749
-		else
1815
+		if (substr($_REQUEST['filename'], 0, 1) == '.') {
1816
+					$_REQUEST['filename'] = '';
1817
+		} else
1750 1818
 		{
1751 1819
 			$_REQUEST['filename'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_REQUEST['filename']);
1752 1820
 
1753 1821
 			$temp = realpath($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1754
-			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1755
-				$_REQUEST['filename'] = '';
1822
+			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1823
+							$_REQUEST['filename'] = '';
1824
+			}
1756 1825
 		}
1757 1826
 
1758
-		if (empty($_REQUEST['filename']))
1759
-			fatal_lang_error('theme_edit_missing', false);
1827
+		if (empty($_REQUEST['filename'])) {
1828
+					fatal_lang_error('theme_edit_missing', false);
1829
+		}
1760 1830
 	}
1761 1831
 
1762 1832
 	if (isset($_POST['save']))
1763 1833
 	{
1764 1834
 		if (checkSession('post', '', false) == '' && validateToken('admin-te-' . md5($_GET['th'] . '-' . $_REQUEST['filename']), 'post', false) == true)
1765 1835
 		{
1766
-			if (is_array($_POST['entire_file']))
1767
-				$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1836
+			if (is_array($_POST['entire_file'])) {
1837
+							$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1838
+			}
1768 1839
 
1769 1840
 			$_POST['entire_file'] = rtrim(strtr($_POST['entire_file'], array("\r" => '', '   ' => "\t")));
1770 1841
 
@@ -1776,10 +1847,11 @@  discard block
 block discarded – undo
1776 1847
 				fclose($fp);
1777 1848
 
1778 1849
 				$error = @file_get_contents($currentTheme['theme_url'] . '/tmp_' . session_id() . '.php');
1779
-				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0)
1780
-					$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1781
-				else
1782
-					unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1850
+				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) {
1851
+									$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1852
+				} else {
1853
+									unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1854
+				}
1783 1855
 			}
1784 1856
 
1785 1857
 			if (!isset($error_file))
@@ -1800,10 +1872,11 @@  discard block
 block discarded – undo
1800 1872
 			$context['sub_template'] = 'edit_file';
1801 1873
 
1802 1874
 			// Recycle the submitted data.
1803
-			if (is_array($_POST['entire_file']))
1804
-				$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1805
-			else
1806
-				$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1875
+			if (is_array($_POST['entire_file'])) {
1876
+							$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1877
+			} else {
1878
+							$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1879
+			}
1807 1880
 
1808 1881
 			$context['edit_filename'] = $smcFunc['htmlspecialchars']($_POST['filename']);
1809 1882
 
@@ -1826,17 +1899,17 @@  discard block
 block discarded – undo
1826 1899
 		$context['sub_template'] = 'edit_style';
1827 1900
 
1828 1901
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(file_get_contents($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']), array("\t" => '   ')));
1829
-	}
1830
-	elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1902
+	} elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1831 1903
 	{
1832 1904
 		$context['sub_template'] = 'edit_template';
1833 1905
 
1834
-		if (!isset($error_file))
1835
-			$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1836
-		else
1906
+		if (!isset($error_file)) {
1907
+					$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1908
+		} else
1837 1909
 		{
1838
-			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0)
1839
-				$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1910
+			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) {
1911
+							$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1912
+			}
1840 1913
 			$file_data = file($error_file);
1841 1914
 			unlink($error_file);
1842 1915
 		}
@@ -1850,8 +1923,9 @@  discard block
 block discarded – undo
1850 1923
 				// Try to format the functions a little nicer...
1851 1924
 				$context['file_parts'][$j]['data'] = trim($context['file_parts'][$j]['data']) . "\n";
1852 1925
 
1853
-				if (empty($context['file_parts'][$j]['lines']))
1854
-					unset($context['file_parts'][$j]);
1926
+				if (empty($context['file_parts'][$j]['lines'])) {
1927
+									unset($context['file_parts'][$j]);
1928
+				}
1855 1929
 				$context['file_parts'][++$j] = array('lines' => 0, 'line' => $i + 1, 'data' => '');
1856 1930
 			}
1857 1931
 
@@ -1860,8 +1934,7 @@  discard block
 block discarded – undo
1860 1934
 		}
1861 1935
 
1862 1936
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(implode('', $file_data), array("\t" => '   ')));
1863
-	}
1864
-	else
1937
+	} else
1865 1938
 	{
1866 1939
 		$context['sub_template'] = 'edit_file';
1867 1940
 
@@ -1887,8 +1960,9 @@  discard block
 block discarded – undo
1887 1960
 
1888 1961
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
1889 1962
 
1890
-	if (empty($_GET['th']))
1891
-		fatal_lang_error('theme_install_invalid_id');
1963
+	if (empty($_GET['th'])) {
1964
+			fatal_lang_error('theme_install_invalid_id');
1965
+	}
1892 1966
 
1893 1967
 	// Get the theme info.
1894 1968
 	$theme = get_single_theme($_GET['th']);
@@ -1896,25 +1970,24 @@  discard block
 block discarded – undo
1896 1970
 
1897 1971
 	if (isset($_REQUEST['template']) && preg_match('~[\./\\\\:\0]~', $_REQUEST['template']) == 0)
1898 1972
 	{
1899
-		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'))
1900
-			$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1901
-
1902
-		else
1903
-			fatal_lang_error('no_access', false);
1973
+		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) {
1974
+					$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1975
+		} else {
1976
+					fatal_lang_error('no_access', false);
1977
+		}
1904 1978
 
1905 1979
 		$fp = fopen($theme['theme_dir'] . '/' . $_REQUEST['template'] . '.template.php', 'w');
1906 1980
 		fwrite($fp, file_get_contents($filename));
1907 1981
 		fclose($fp);
1908 1982
 
1909 1983
 		redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy');
1910
-	}
1911
-	elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1984
+	} elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1912 1985
 	{
1913
-		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'))
1914
-			$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1915
-
1916
-		else
1917
-			fatal_lang_error('no_access', false);
1986
+		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) {
1987
+					$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1988
+		} else {
1989
+					fatal_lang_error('no_access', false);
1990
+		}
1918 1991
 
1919 1992
 		$fp = fopen($theme['theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php', 'w');
1920 1993
 		fwrite($fp, file_get_contents($filename));
@@ -1929,16 +2002,18 @@  discard block
 block discarded – undo
1929 2002
 	$dir = dir($settings['default_theme_dir']);
1930 2003
 	while ($entry = $dir->read())
1931 2004
 	{
1932
-		if (substr($entry, -13) == '.template.php')
1933
-			$templates[] = substr($entry, 0, -13);
2005
+		if (substr($entry, -13) == '.template.php') {
2006
+					$templates[] = substr($entry, 0, -13);
2007
+		}
1934 2008
 	}
1935 2009
 	$dir->close();
1936 2010
 
1937 2011
 	$dir = dir($settings['default_theme_dir'] . '/languages');
1938 2012
 	while ($entry = $dir->read())
1939 2013
 	{
1940
-		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches))
1941
-			$lang_files[] = $matches[1];
2014
+		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) {
2015
+					$lang_files[] = $matches[1];
2016
+		}
1942 2017
 	}
1943 2018
 	$dir->close();
1944 2019
 
@@ -1946,21 +2021,23 @@  discard block
 block discarded – undo
1946 2021
 	natcasesort($lang_files);
1947 2022
 
1948 2023
 	$context['available_templates'] = array();
1949
-	foreach ($templates as $template)
1950
-		$context['available_templates'][$template] = array(
2024
+	foreach ($templates as $template) {
2025
+			$context['available_templates'][$template] = array(
1951 2026
 			'filename' => $template . '.template.php',
1952 2027
 			'value' => $template,
1953 2028
 			'already_exists' => false,
1954 2029
 			'can_copy' => is_writable($theme['theme_dir']),
1955 2030
 		);
2031
+	}
1956 2032
 	$context['available_language_files'] = array();
1957
-	foreach ($lang_files as $file)
1958
-		$context['available_language_files'][$file] = array(
2033
+	foreach ($lang_files as $file) {
2034
+			$context['available_language_files'][$file] = array(
1959 2035
 			'filename' => $file . '.php',
1960 2036
 			'value' => $file,
1961 2037
 			'already_exists' => false,
1962 2038
 			'can_copy' => file_exists($theme['theme_dir'] . '/languages') ? is_writable($theme['theme_dir'] . '/languages') : is_writable($theme['theme_dir']),
1963 2039
 		);
2040
+	}
1964 2041
 
1965 2042
 	$dir = dir($theme['theme_dir']);
1966 2043
 	while ($entry = $dir->read())
Please login to merge, or discard this patch.