Completed
Push — release-2.1 ( 5ca5b8...e49a83 )
by Mathias
07:07
created
Sources/Printpage.php 1 patch
Braces   +30 added lines, -23 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Format a topic to be printer friendly.
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	global $board_info, $smcFunc, $modSettings;
33 34
 
34 35
 	// Redirect to the boardindex if no valid topic id is provided.
35
-	if (empty($topic))
36
-		redirectexit();
36
+	if (empty($topic)) {
37
+			redirectexit();
38
+	}
37 39
 
38 40
 	if (!empty($modSettings['disable_print_topic']))
39 41
 	{
@@ -59,8 +61,9 @@  discard block
 block discarded – undo
59 61
 		)
60 62
 	);
61 63
 	// Redirect to the boardindex if no valid topic id is provided.
62
-	if ($smcFunc['db_num_rows']($request) == 0)
63
-		redirectexit();
64
+	if ($smcFunc['db_num_rows']($request) == 0) {
65
+			redirectexit();
66
+	}
64 67
 	$row = $smcFunc['db_fetch_assoc']($request);
65 68
 	$smcFunc['db_free_result']($request);
66 69
 
@@ -134,20 +137,21 @@  discard block
 block discarded – undo
134 137
 				foreach ($guestinfo as $i => $guestvoted)
135 138
 				{
136 139
 					$guestvoted = explode(',', $guestvoted);
137
-					if ($guestvoted[0] == $row['id_poll'])
138
-						break;
140
+					if ($guestvoted[0] == $row['id_poll']) {
141
+											break;
142
+					}
139 143
 				}
140 144
 				// Has the poll been reset since guest voted?
141 145
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
142 146
 				{
143 147
 					// Remove the poll info from the cookie to allow guest to vote again
144 148
 					unset($guestinfo[$i]);
145
-					if (!empty($guestinfo))
146
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
147
-					else
148
-						unset($_COOKIE['guest_poll_vote']);
149
-				}
150
-				else
149
+					if (!empty($guestinfo)) {
150
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
151
+					} else {
152
+											unset($_COOKIE['guest_poll_vote']);
153
+					}
154
+				} else
151 155
 				{
152 156
 					// What did they vote for?
153 157
 					unset($guestvoted[0], $guestvoted[1]);
@@ -233,8 +237,9 @@  discard block
 block discarded – undo
233 237
 	$context['poster_name'] = $row['poster_name'];
234 238
 	$context['post_time'] = timeformat($row['poster_time'], false);
235 239
 	$context['parent_boards'] = array();
236
-	foreach ($board_info['parent_boards'] as $parent)
237
-		$context['parent_boards'][] = $parent['name'];
240
+	foreach ($board_info['parent_boards'] as $parent) {
241
+			$context['parent_boards'][] = $parent['name'];
242
+	}
238 243
 
239 244
 	// Split the topics up so we can print them.
240 245
 	$request = $smcFunc['db_query']('', '
@@ -266,8 +271,9 @@  discard block
 block discarded – undo
266 271
 			'id_msg' => $row['id_msg'],
267 272
 		);
268 273
 
269
-		if (!isset($context['topic_subject']))
270
-			$context['topic_subject'] = $row['subject'];
274
+		if (!isset($context['topic_subject'])) {
275
+					$context['topic_subject'] = $row['subject'];
276
+		}
271 277
 	}
272 278
 	$smcFunc['db_free_result']($request);
273 279
 
@@ -275,8 +281,9 @@  discard block
 block discarded – undo
275 281
 	if (isset($_REQUEST['images']) && !empty($modSettings['attachmentEnable']) && allowedTo('view_attachments'))
276 282
 	{
277 283
 		$messages = array();
278
-		foreach ($context['posts'] as $temp)
279
-			$messages[] = $temp['id_msg'];
284
+		foreach ($context['posts'] as $temp) {
285
+					$messages[] = $temp['id_msg'];
286
+		}
280 287
 
281 288
 		// build the request
282 289
 		$request = $smcFunc['db_query']('', '
@@ -295,8 +302,9 @@  discard block
 block discarded – undo
295 302
 		while ($row = $smcFunc['db_fetch_assoc']($request))
296 303
 		{
297 304
 			$temp[$row['id_attach']] = $row;
298
-			if (!isset($context['printattach'][$row['id_msg']]))
299
-				$context['printattach'][$row['id_msg']] = array();
305
+			if (!isset($context['printattach'][$row['id_msg']])) {
306
+							$context['printattach'][$row['id_msg']] = array();
307
+			}
300 308
 		}
301 309
 		$smcFunc['db_free_result']($request);
302 310
 		ksort($temp);
@@ -313,8 +321,7 @@  discard block
 block discarded – undo
313 321
 						$row['height'] = floor($row['height'] * ($modSettings['max_image_width'] / $row['width']));
314 322
 						$row['width'] = $modSettings['max_image_width'];
315 323
 					}
316
-				}
317
-				elseif (!empty($modSettings['max_image_width']))
324
+				} elseif (!empty($modSettings['max_image_width']))
318 325
 				{
319 326
 					if ($row['height'] > $modSettings['max_image_height'])
320 327
 					{
Please login to merge, or discard this patch.
Sources/Reminder.php 1 patch
Braces   +66 added lines, -46 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  * @version 2.1 Beta 3
13 13
  */
14 14
 
15
-if (!defined('SMF'))
15
+if (!defined('SMF')) {
16 16
 	die('No direct access...');
17
+}
17 18
 
18 19
 /**
19 20
  * This is the controlling delegator
@@ -38,13 +39,15 @@  discard block
 block discarded – undo
38 39
 	);
39 40
 
40 41
 	// Any subaction?  If none, fall through to the main template, which will ask for one.
41
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
42
-		call_helper($subActions[$_REQUEST['sa']]);
42
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
43
+			call_helper($subActions[$_REQUEST['sa']]);
44
+	}
43 45
 
44 46
 	// Creating a one time token.
45
-	else
46
-		createToken('remind');
47
-}
47
+	else {
48
+			createToken('remind');
49
+	}
50
+	}
48 51
 
49 52
 /**
50 53
  * Allows the user to pick how they wish to be reminded
@@ -62,8 +65,7 @@  discard block
 block discarded – undo
62 65
 	{
63 66
 		$where = 'id_member = {int:id_member}';
64 67
 		$where_params['id_member'] = (int) $_REQUEST['uid'];
65
-	}
66
-	elseif (isset($_POST['user']) && $_POST['user'] != '')
68
+	} elseif (isset($_POST['user']) && $_POST['user'] != '')
67 69
 	{
68 70
 		$where = 'member_name = {string:member_name}';
69 71
 		$where_params['member_name'] = $_POST['user'];
@@ -71,8 +73,9 @@  discard block
 block discarded – undo
71 73
 	}
72 74
 
73 75
 	// You must enter a username/email address.
74
-	if (empty($where))
75
-		fatal_lang_error('username_no_exist', false);
76
+	if (empty($where)) {
77
+			fatal_lang_error('username_no_exist', false);
78
+	}
76 79
 
77 80
 	// Make sure we are not being slammed
78 81
 	// Don't call this if you're coming from the "Choose a reminder type" page - otherwise you'll likely get an error
@@ -101,8 +104,9 @@  discard block
 block discarded – undo
101 104
 			LIMIT 1',
102 105
 			$where_params
103 106
 		);
104
-		if ($smcFunc['db_num_rows']($request) == 0)
105
-			fatal_lang_error('no_user_with_email', false);
107
+		if ($smcFunc['db_num_rows']($request) == 0) {
108
+					fatal_lang_error('no_user_with_email', false);
109
+		}
106 110
 	}
107 111
 
108 112
 	$row = $smcFunc['db_fetch_assoc']($request);
@@ -112,16 +116,18 @@  discard block
 block discarded – undo
112 116
 	if ($row['is_activated'] != 1)
113 117
 	{
114 118
 		// Awaiting approval...
115
-		if (trim($row['validation_code']) == '')
116
-			fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
117
-		else
118
-			fatal_error(sprintf($txt['registration_not_activated'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
119
+		if (trim($row['validation_code']) == '') {
120
+					fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
121
+		} else {
122
+					fatal_error(sprintf($txt['registration_not_activated'], $scripturl . '?action=activate;user=' . $_POST['user']), false);
123
+		}
119 124
 	}
120 125
 
121 126
 	// You can't get emailed if you have no email address.
122 127
 	$row['email_address'] = trim($row['email_address']);
123
-	if ($row['email_address'] == '')
124
-		fatal_error($txt['no_reminder_email'] . '<br>' . $txt['send_email'] . ' <a href="mailto:' . $webmaster_email . '">webmaster</a> ' . $txt['to_ask_password'] . '.');
128
+	if ($row['email_address'] == '') {
129
+			fatal_error($txt['no_reminder_email'] . '<br>' . $txt['send_email'] . ' <a href="mailto:' . $webmaster_email . '">webmaster</a> ' . $txt['to_ask_password'] . '.');
130
+	}
125 131
 
126 132
 	// If they have no secret question then they can only get emailed the item, or they are requesting the email, send them an email.
127 133
 	if (empty($row['secret_question']) || (isset($_POST['reminder_type']) && $_POST['reminder_type'] == 'email'))
@@ -176,8 +182,9 @@  discard block
 block discarded – undo
176 182
 	loadLanguage('Login');
177 183
 
178 184
 	// You need a code!
179
-	if (!isset($_REQUEST['code']))
180
-		fatal_lang_error('no_access', false);
185
+	if (!isset($_REQUEST['code'])) {
186
+			fatal_lang_error('no_access', false);
187
+	}
181 188
 
182 189
 	// Fill the context array.
183 190
 	$context += array(
@@ -203,16 +210,19 @@  discard block
 block discarded – undo
203 210
 	checkSession();
204 211
 	validateToken('remind-sp');
205 212
 
206
-	if (empty($_POST['u']) || !isset($_POST['passwrd1']) || !isset($_POST['passwrd2']))
207
-		fatal_lang_error('no_access', false);
213
+	if (empty($_POST['u']) || !isset($_POST['passwrd1']) || !isset($_POST['passwrd2'])) {
214
+			fatal_lang_error('no_access', false);
215
+	}
208 216
 
209 217
 	$_POST['u'] = (int) $_POST['u'];
210 218
 
211
-	if ($_POST['passwrd1'] != $_POST['passwrd2'])
212
-		fatal_lang_error('passwords_dont_match', false);
219
+	if ($_POST['passwrd1'] != $_POST['passwrd2']) {
220
+			fatal_lang_error('passwords_dont_match', false);
221
+	}
213 222
 
214
-	if ($_POST['passwrd1'] == '')
215
-		fatal_lang_error('no_password', false);
223
+	if ($_POST['passwrd1'] == '') {
224
+			fatal_lang_error('no_password', false);
225
+	}
216 226
 
217 227
 	loadLanguage('Login');
218 228
 
@@ -232,8 +242,9 @@  discard block
 block discarded – undo
232 242
 	);
233 243
 
234 244
 	// Does this user exist at all?
235
-	if ($smcFunc['db_num_rows']($request) == 0)
236
-		fatal_lang_error('invalid_userid', false);
245
+	if ($smcFunc['db_num_rows']($request) == 0) {
246
+			fatal_lang_error('invalid_userid', false);
247
+	}
237 248
 
238 249
 	list ($realCode, $username, $email, $flood_value) = $smcFunc['db_fetch_row']($request);
239 250
 	$smcFunc['db_free_result']($request);
@@ -243,8 +254,9 @@  discard block
 block discarded – undo
243 254
 	$passwordError = validatePassword($_POST['passwrd1'], $username, array($email));
244 255
 
245 256
 	// What - it's not?
246
-	if ($passwordError != null)
247
-		fatal_lang_error('profile_error_password_' . $passwordError, false);
257
+	if ($passwordError != null) {
258
+			fatal_lang_error('profile_error_password_' . $passwordError, false);
259
+	}
248 260
 
249 261
 	require_once($sourcedir . '/LogInOut.php');
250 262
 
@@ -291,8 +303,9 @@  discard block
 block discarded – undo
291 303
 	loadLanguage('Login');
292 304
 
293 305
 	// Check they entered something...
294
-	if (empty($_REQUEST['uid']))
295
-		fatal_lang_error('username_no_exist', false);
306
+	if (empty($_REQUEST['uid'])) {
307
+			fatal_lang_error('username_no_exist', false);
308
+	}
296 309
 
297 310
 	// Get the stuff....
298 311
 	$request = $smcFunc['db_query']('', '
@@ -304,15 +317,17 @@  discard block
 block discarded – undo
304 317
 			'id_member' => (int) $_REQUEST['uid'],
305 318
 		)
306 319
 	);
307
-	if ($smcFunc['db_num_rows']($request) == 0)
308
-		fatal_lang_error('username_no_exist', false);
320
+	if ($smcFunc['db_num_rows']($request) == 0) {
321
+			fatal_lang_error('username_no_exist', false);
322
+	}
309 323
 
310 324
 	$row = $smcFunc['db_fetch_assoc']($request);
311 325
 	$smcFunc['db_free_result']($request);
312 326
 
313 327
 	// If there is NO secret question - then throw an error.
314
-	if (trim($row['secret_question']) == '')
315
-		fatal_lang_error('registration_no_secret_question', false);
328
+	if (trim($row['secret_question']) == '') {
329
+			fatal_lang_error('registration_no_secret_question', false);
330
+	}
316 331
 
317 332
 	// Ask for the answer...
318 333
 	$context['remind_user'] = $row['id_member'];
@@ -335,8 +350,9 @@  discard block
 block discarded – undo
335 350
 	validateToken('remind-sai');
336 351
 
337 352
 	// Hacker?  How did you get this far without an email or username?
338
-	if (empty($_REQUEST['uid']))
339
-		fatal_lang_error('username_no_exist', false);
353
+	if (empty($_REQUEST['uid'])) {
354
+			fatal_lang_error('username_no_exist', false);
355
+	}
340 356
 
341 357
 	loadLanguage('Login');
342 358
 
@@ -350,8 +366,9 @@  discard block
 block discarded – undo
350 366
 			'id_member' => $_REQUEST['uid'],
351 367
 		)
352 368
 	);
353
-	if ($smcFunc['db_num_rows']($request) == 0)
354
-		fatal_lang_error('username_no_exist', false);
369
+	if ($smcFunc['db_num_rows']($request) == 0) {
370
+			fatal_lang_error('username_no_exist', false);
371
+	}
355 372
 
356 373
 	$row = $smcFunc['db_fetch_assoc']($request);
357 374
 	$smcFunc['db_free_result']($request);
@@ -364,20 +381,23 @@  discard block
 block discarded – undo
364 381
 	}
365 382
 
366 383
 	// You can't use a blank one!
367
-	if (strlen(trim($_POST['passwrd1'])) === 0)
368
-		fatal_lang_error('no_password', false);
384
+	if (strlen(trim($_POST['passwrd1'])) === 0) {
385
+			fatal_lang_error('no_password', false);
386
+	}
369 387
 
370 388
 	// They have to be the same too.
371
-	if ($_POST['passwrd1'] != $_POST['passwrd2'])
372
-		fatal_lang_error('passwords_dont_match', false);
389
+	if ($_POST['passwrd1'] != $_POST['passwrd2']) {
390
+			fatal_lang_error('passwords_dont_match', false);
391
+	}
373 392
 
374 393
 	// Make sure they have a strong enough password.
375 394
 	require_once($sourcedir . '/Subs-Auth.php');
376 395
 	$passwordError = validatePassword($_POST['passwrd1'], $row['member_name'], array($row['email_address']));
377 396
 
378 397
 	// Invalid?
379
-	if ($passwordError != null)
380
-		fatal_lang_error('profile_error_password_' . $passwordError, false);
398
+	if ($passwordError != null) {
399
+			fatal_lang_error('profile_error_password_' . $passwordError, false);
400
+	}
381 401
 
382 402
 	// Alright, so long as 'yer sure.
383 403
 	updateMemberData($row['id_member'], array('passwd' => hash_password($row['member_name'], $_POST['passwrd1'])));
Please login to merge, or discard this patch.
Sources/Subs-Categories.php 1 patch
Braces   +44 added lines, -29 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Edit the position and properties of a category.
@@ -42,8 +43,9 @@  discard block
 block discarded – undo
42 43
 		$cat_order = array();
43 44
 
44 45
 		// Setting 'move_after' to '0' moves the category to the top.
45
-		if ($catOptions['move_after'] == 0)
46
-			$cats[] = $category_id;
46
+		if ($catOptions['move_after'] == 0) {
47
+					$cats[] = $category_id;
48
+		}
47 49
 
48 50
 		// Grab the categories sorted by cat_order.
49 51
 		$request = $smcFunc['db_query']('', '
@@ -55,17 +57,19 @@  discard block
 block discarded – undo
55 57
 		);
56 58
 		while ($row = $smcFunc['db_fetch_assoc']($request))
57 59
 		{
58
-			if ($row['id_cat'] != $category_id)
59
-				$cats[] = $row['id_cat'];
60
-			if ($row['id_cat'] == $catOptions['move_after'])
61
-				$cats[] = $category_id;
60
+			if ($row['id_cat'] != $category_id) {
61
+							$cats[] = $row['id_cat'];
62
+			}
63
+			if ($row['id_cat'] == $catOptions['move_after']) {
64
+							$cats[] = $category_id;
65
+			}
62 66
 			$cat_order[$row['id_cat']] = $row['cat_order'];
63 67
 		}
64 68
 		$smcFunc['db_free_result']($request);
65 69
 
66 70
 		// Set the new order for the categories.
67
-		foreach ($cats as $index => $cat)
68
-			if ($index != $cat_order[$cat])
71
+		foreach ($cats as $index => $cat) {
72
+					if ($index != $cat_order[$cat])
69 73
 				$smcFunc['db_query']('', '
70 74
 					UPDATE {db_prefix}categories
71 75
 					SET cat_order = {int:new_order}
@@ -75,6 +79,7 @@  discard block
 block discarded – undo
75 79
 						'current_category' => $cat,
76 80
 					)
77 81
 				);
82
+		}
78 83
 
79 84
 		// If the category order changed, so did the board order.
80 85
 		require_once($sourcedir . '/Subs-Boards.php');
@@ -117,8 +122,9 @@  discard block
 block discarded – undo
117 122
 			))
118 123
 		);
119 124
 
120
-		if (empty($catOptions['dont_log']))
121
-			logAction('edit_cat', array('catname' => isset($catOptions['cat_name']) ? $catOptions['cat_name'] : $category_id), 'admin');
125
+		if (empty($catOptions['dont_log'])) {
126
+					logAction('edit_cat', array('catname' => isset($catOptions['cat_name']) ? $catOptions['cat_name'] : $category_id), 'admin');
127
+		}
122 128
 	}
123 129
 }
124 130
 
@@ -135,16 +141,20 @@  discard block
 block discarded – undo
135 141
 	global $smcFunc;
136 142
 
137 143
 	// Check required values.
138
-	if (!isset($catOptions['cat_name']) || trim($catOptions['cat_name']) == '')
139
-		trigger_error('createCategory(): A category name is required', E_USER_ERROR);
144
+	if (!isset($catOptions['cat_name']) || trim($catOptions['cat_name']) == '') {
145
+			trigger_error('createCategory(): A category name is required', E_USER_ERROR);
146
+	}
140 147
 
141 148
 	// Set default values.
142
-	if (!isset($catOptions['cat_desc']))
143
-		$catOptions['cat_desc'] = '';
144
-	if (!isset($catOptions['move_after']))
145
-		$catOptions['move_after'] = 0;
146
-	if (!isset($catOptions['is_collapsible']))
147
-		$catOptions['is_collapsible'] = true;
149
+	if (!isset($catOptions['cat_desc'])) {
150
+			$catOptions['cat_desc'] = '';
151
+	}
152
+	if (!isset($catOptions['move_after'])) {
153
+			$catOptions['move_after'] = 0;
154
+	}
155
+	if (!isset($catOptions['is_collapsible'])) {
156
+			$catOptions['is_collapsible'] = true;
157
+	}
148 158
 	// Don't log an edit right after.
149 159
 	$catOptions['dont_log'] = true;
150 160
 
@@ -212,21 +222,24 @@  discard block
 block discarded – undo
212 222
 			)
213 223
 		);
214 224
 		$boards_inside = array();
215
-		while ($row = $smcFunc['db_fetch_assoc']($request))
216
-			$boards_inside[] = $row['id_board'];
225
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
226
+					$boards_inside[] = $row['id_board'];
227
+		}
217 228
 		$smcFunc['db_free_result']($request);
218 229
 
219
-		if (!empty($boards_inside))
220
-			deleteBoards($boards_inside, null);
230
+		if (!empty($boards_inside)) {
231
+					deleteBoards($boards_inside, null);
232
+		}
221 233
 	}
222 234
 
223 235
 	// Make sure the safe category is really safe.
224
-	elseif (in_array($moveBoardsTo, $categories))
225
-		trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR);
236
+	elseif (in_array($moveBoardsTo, $categories)) {
237
+			trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR);
238
+	}
226 239
 
227 240
 	// Move the boards inside the categories to a safe category.
228
-	else
229
-		$smcFunc['db_query']('', '
241
+	else {
242
+			$smcFunc['db_query']('', '
230 243
 			UPDATE {db_prefix}boards
231 244
 			SET id_cat = {int:new_parent_cat}
232 245
 			WHERE id_cat IN ({array_int:category_list})',
@@ -235,6 +248,7 @@  discard block
 block discarded – undo
235 248
 				'new_parent_cat' => $moveBoardsTo,
236 249
 			)
237 250
 		);
251
+	}
238 252
 
239 253
 	// Do the deletion of the category itself
240 254
 	$smcFunc['db_query']('', '
@@ -246,8 +260,9 @@  discard block
 block discarded – undo
246 260
 	);
247 261
 
248 262
 	// Log what we've done.
249
-	foreach ($categories as $category)
250
-		logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin');
263
+	foreach ($categories as $category) {
264
+			logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin');
265
+	}
251 266
 
252 267
 	// Get all boards back into the right order.
253 268
 	reorderBoards();
Please login to merge, or discard this patch.
Sources/ManageServer.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 
248 248
 		saveSettings($config_vars);
249 249
 		$_SESSION['adm-save'] = true;
250
-		redirectexit('action=admin;area=serversettings;sa=database;' . $context['session_var'] . '=' . $context['session_id'] );
250
+		redirectexit('action=admin;area=serversettings;sa=database;' . $context['session_var'] . '=' . $context['session_id']);
251 251
 	}
252 252
 
253 253
 	// Fill the config array.
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 		array('localCookies', $txt['localCookies'], 'db', 'check', false, 'localCookies'),
273 273
 		array('globalCookies', $txt['globalCookies'], 'db', 'check', false, 'globalCookies'),
274 274
 		array('globalCookiesDomain', $txt['globalCookiesDomain'], 'db', 'text', false, 'globalCookiesDomain'),
275
-		array('secureCookies', $txt['secureCookies'], 'db', 'check', false, 'secureCookies',  'disabled' => !isset($_SERVER['HTTPS']) || !(strtolower($_SERVER['HTTPS']) == 'on' || strtolower($_SERVER['HTTPS']) == '1')),
275
+		array('secureCookies', $txt['secureCookies'], 'db', 'check', false, 'secureCookies', 'disabled' => !isset($_SERVER['HTTPS']) || !(strtolower($_SERVER['HTTPS']) == 'on' || strtolower($_SERVER['HTTPS']) == '1')),
276 276
 		array('httponlyCookies', $txt['httponlyCookies'], 'db', 'check', false, 'httponlyCookies'),
277 277
 		'',
278 278
 		// Sessions
Please login to merge, or discard this patch.
Braces   +253 added lines, -196 removed lines patch added patch discarded remove patch
@@ -59,8 +59,9 @@  discard block
 block discarded – undo
59 59
  * @version 2.1 Beta 3
60 60
  */
61 61
 
62
-if (!defined('SMF'))
62
+if (!defined('SMF')) {
63 63
 	die('No direct access...');
64
+}
64 65
 
65 66
 /**
66 67
  * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects
@@ -111,10 +112,11 @@  discard block
 block discarded – undo
111 112
 	$settings_not_writable = !is_writable($boarddir . '/Settings.php');
112 113
 	$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
113 114
 
114
-	if ($settings_not_writable)
115
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
116
-	elseif ($settings_backup_fail)
117
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
115
+	if ($settings_not_writable) {
116
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
117
+	} elseif ($settings_backup_fail) {
118
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
119
+	}
118 120
 
119 121
 	$context['settings_not_writable'] = $settings_not_writable;
120 122
 
@@ -166,8 +168,9 @@  discard block
 block discarded – undo
166 168
 
167 169
 	call_integration_hook('integrate_general_settings', array(&$config_vars));
168 170
 
169
-	if ($return_config)
170
-		return $config_vars;
171
+	if ($return_config) {
172
+			return $config_vars;
173
+	}
171 174
 
172 175
 	// Setup the template stuff.
173 176
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save';
@@ -232,8 +235,9 @@  discard block
 block discarded – undo
232 235
 
233 236
 	call_integration_hook('integrate_database_settings', array(&$config_vars));
234 237
 
235
-	if ($return_config)
236
-		return $config_vars;
238
+	if ($return_config) {
239
+			return $config_vars;
240
+	}
237 241
 
238 242
 	// Setup the template stuff.
239 243
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save';
@@ -308,13 +312,15 @@  discard block
 block discarded – undo
308 312
 		hideGlobalCookies();
309 313
 	});', true);
310 314
 
311
-	if (empty($user_settings['tfa_secret']))
312
-		addInlineJavaScript('');
315
+	if (empty($user_settings['tfa_secret'])) {
316
+			addInlineJavaScript('');
317
+	}
313 318
 
314 319
 	call_integration_hook('integrate_cookie_settings', array(&$config_vars));
315 320
 
316
-	if ($return_config)
317
-		return $config_vars;
321
+	if ($return_config) {
322
+			return $config_vars;
323
+	}
318 324
 
319 325
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save';
320 326
 	$context['settings_title'] = $txt['cookies_sessions_settings'];
@@ -325,11 +331,13 @@  discard block
 block discarded – undo
325 331
 		call_integration_hook('integrate_save_cookie_settings');
326 332
 
327 333
 		// Local and global do not play nicely together.
328
-		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
329
-			unset ($_POST['globalCookies']);
334
+		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) {
335
+					unset ($_POST['globalCookies']);
336
+		}
330 337
 
331
-		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false)
332
-			fatal_lang_error('invalid_cookie_domain', false);
338
+		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) {
339
+					fatal_lang_error('invalid_cookie_domain', false);
340
+		}
333 341
 
334 342
 		saveSettings($config_vars);
335 343
 
@@ -412,8 +420,9 @@  discard block
 block discarded – undo
412 420
 
413 421
 	call_integration_hook('integrate_general_security_settings', array(&$config_vars));
414 422
 
415
-	if ($return_config)
416
-		return $config_vars;
423
+	if ($return_config) {
424
+			return $config_vars;
425
+	}
417 426
 
418 427
 	// Saving?
419 428
 	if (isset($_GET['save']))
@@ -452,8 +461,7 @@  discard block
 block discarded – undo
452 461
 		$txt['cache_settings_message'] = $txt['detected_no_caching'];
453 462
 		$cache_level = array($txt['cache_off']);
454 463
 		$detected['none'] = $txt['cache_off'];
455
-	}
456
-	else
464
+	} else
457 465
 	{
458 466
 		$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
459 467
 		$cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']);
@@ -490,8 +498,9 @@  discard block
 block discarded – undo
490 498
 			}
491 499
 		}
492 500
 	}
493
-	if ($return_config)
494
-		return $config_vars;
501
+	if ($return_config) {
502
+			return $config_vars;
503
+	}
495 504
 
496 505
 	// Saving again?
497 506
 	if (isset($_GET['save']))
@@ -519,8 +528,9 @@  discard block
 block discarded – undo
519 528
 	$context['save_disabled'] = $context['settings_not_writable'];
520 529
 
521 530
 	// Decide what message to show.
522
-	if (!$context['save_disabled'])
523
-		$context['settings_message'] = $txt['caching_information'];
531
+	if (!$context['save_disabled']) {
532
+			$context['settings_message'] = $txt['caching_information'];
533
+	}
524 534
 
525 535
 	// Prepare the template.
526 536
 	prepareServerSettingsContext($config_vars);
@@ -543,24 +553,25 @@  discard block
 block discarded – undo
543 553
 	if (stripos(PHP_OS, 'win') === 0)
544 554
 	{
545 555
 		$context['settings_message'] = $txt['loadavg_disabled_windows'];
546
-		if (isset($_GET['save']))
547
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
548
-	}
549
-	elseif (stripos(PHP_OS, 'darwin') === 0)
556
+		if (isset($_GET['save'])) {
557
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
558
+		}
559
+	} elseif (stripos(PHP_OS, 'darwin') === 0)
550 560
 	{
551 561
 		$context['settings_message'] = $txt['loadavg_disabled_osx'];
552
-		if (isset($_GET['save']))
553
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
554
-	}
555
-	else
562
+		if (isset($_GET['save'])) {
563
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
564
+		}
565
+	} else
556 566
 	{
557 567
 		$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
558
-		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0)
559
-			$modSettings['load_average'] = (float) $matches[1];
560
-		elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0)
561
-			$modSettings['load_average'] = (float) $matches[1];
562
-		else
563
-			unset($modSettings['load_average']);
568
+		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) {
569
+					$modSettings['load_average'] = (float) $matches[1];
570
+		} elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) {
571
+					$modSettings['load_average'] = (float) $matches[1];
572
+		} else {
573
+					unset($modSettings['load_average']);
574
+		}
564 575
 
565 576
 		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
566 577
 		{
@@ -596,8 +607,9 @@  discard block
 block discarded – undo
596 607
 
597 608
 	call_integration_hook('integrate_loadavg_settings', array(&$config_vars));
598 609
 
599
-	if ($return_config)
600
-		return $config_vars;
610
+	if ($return_config) {
611
+			return $config_vars;
612
+	}
601 613
 
602 614
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save';
603 615
 	$context['settings_title'] = $txt['load_balancing_settings'];
@@ -608,24 +620,27 @@  discard block
 block discarded – undo
608 620
 		// Stupidity is not allowed.
609 621
 		foreach ($_POST as $key => $value)
610 622
 		{
611
-			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values)))
612
-				continue;
613
-			else
614
-				$_POST[$key] = (float) $value;
615
-
616
-			if ($key == 'loadavg_auto_opt' && $value <= 1)
617
-				$_POST['loadavg_auto_opt'] = 1.0;
618
-			elseif ($key == 'loadavg_forum' && $value < 10)
619
-				$_POST['loadavg_forum'] = 10.0;
620
-			elseif ($value < 2)
621
-				$_POST[$key] = 2.0;
623
+			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) {
624
+							continue;
625
+			} else {
626
+							$_POST[$key] = (float) $value;
627
+			}
628
+
629
+			if ($key == 'loadavg_auto_opt' && $value <= 1) {
630
+							$_POST['loadavg_auto_opt'] = 1.0;
631
+			} elseif ($key == 'loadavg_forum' && $value < 10) {
632
+							$_POST['loadavg_forum'] = 10.0;
633
+			} elseif ($value < 2) {
634
+							$_POST[$key] = 2.0;
635
+			}
622 636
 		}
623 637
 
624 638
 		call_integration_hook('integrate_save_loadavg_settings');
625 639
 
626 640
 		saveDBSettings($config_vars);
627
-		if (!isset($_SESSION['adm-save']))
628
-			$_SESSION['adm-save'] = true;
641
+		if (!isset($_SESSION['adm-save'])) {
642
+					$_SESSION['adm-save'] = true;
643
+		}
629 644
 		redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
630 645
 	}
631 646
 
@@ -661,10 +676,11 @@  discard block
 block discarded – undo
661 676
 
662 677
 	if (isset($_SESSION['adm-save']))
663 678
 	{
664
-		if ($_SESSION['adm-save'] === true)
665
-			$context['saved_successful'] = true;
666
-		else
667
-			$context['saved_failed'] = $_SESSION['adm-save'];
679
+		if ($_SESSION['adm-save'] === true) {
680
+					$context['saved_successful'] = true;
681
+		} else {
682
+					$context['saved_failed'] = $_SESSION['adm-save'];
683
+		}
668 684
 
669 685
 		unset($_SESSION['adm-save']);
670 686
 	}
@@ -672,9 +688,9 @@  discard block
 block discarded – undo
672 688
 	$context['config_vars'] = array();
673 689
 	foreach ($config_vars as $identifier => $config_var)
674 690
 	{
675
-		if (!is_array($config_var) || !isset($config_var[1]))
676
-			$context['config_vars'][] = $config_var;
677
-		else
691
+		if (!is_array($config_var) || !isset($config_var[1])) {
692
+					$context['config_vars'][] = $config_var;
693
+		} else
678 694
 		{
679 695
 			$varname = $config_var[0];
680 696
 			global $$varname;
@@ -709,16 +725,19 @@  discard block
 block discarded – undo
709 725
 			if ($config_var[3] == 'int' || $config_var[3] == 'float')
710 726
 			{
711 727
 				// Default to a min of 0 if one isn't set
712
-				if (isset($config_var['min']))
713
-					$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
714
-				else
715
-					$context['config_vars'][$config_var[0]]['min'] = 0;
728
+				if (isset($config_var['min'])) {
729
+									$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
730
+				} else {
731
+									$context['config_vars'][$config_var[0]]['min'] = 0;
732
+				}
716 733
 
717
-				if (isset($config_var['max']))
718
-					$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
734
+				if (isset($config_var['max'])) {
735
+									$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
736
+				}
719 737
 
720
-				if (isset($config_var['step']))
721
-					$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
738
+				if (isset($config_var['step'])) {
739
+									$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
740
+				}
722 741
 			}
723 742
 
724 743
 			// If this is a select box handle any data.
@@ -726,12 +745,13 @@  discard block
 block discarded – undo
726 745
 			{
727 746
 				// If it's associative
728 747
 				$config_values = array_values($config_var[4]);
729
-				if (isset($config_values[0]) && is_array($config_values[0]))
730
-					$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
731
-				else
748
+				if (isset($config_values[0]) && is_array($config_values[0])) {
749
+									$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
750
+				} else
732 751
 				{
733
-					foreach ($config_var[4] as $key => $item)
734
-						$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
752
+					foreach ($config_var[4] as $key => $item) {
753
+											$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
754
+					}
735 755
 				}
736 756
 			}
737 757
 		}
@@ -756,10 +776,11 @@  discard block
 block discarded – undo
756 776
 
757 777
 	if (isset($_SESSION['adm-save']))
758 778
 	{
759
-		if ($_SESSION['adm-save'] === true)
760
-			$context['saved_successful'] = true;
761
-		else
762
-			$context['saved_failed'] = $_SESSION['adm-save'];
779
+		if ($_SESSION['adm-save'] === true) {
780
+					$context['saved_successful'] = true;
781
+		} else {
782
+					$context['saved_failed'] = $_SESSION['adm-save'];
783
+		}
763 784
 
764 785
 		unset($_SESSION['adm-save']);
765 786
 	}
@@ -771,26 +792,30 @@  discard block
 block discarded – undo
771 792
 	foreach ($config_vars as $config_var)
772 793
 	{
773 794
 		// HR?
774
-		if (!is_array($config_var))
775
-			$context['config_vars'][] = $config_var;
776
-		else
795
+		if (!is_array($config_var)) {
796
+					$context['config_vars'][] = $config_var;
797
+		} else
777 798
 		{
778 799
 			// If it has no name it doesn't have any purpose!
779
-			if (empty($config_var[1]))
780
-				continue;
800
+			if (empty($config_var[1])) {
801
+							continue;
802
+			}
781 803
 
782 804
 			// Special case for inline permissions
783
-			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions'))
784
-				$inlinePermissions[] = $config_var[1];
785
-			elseif ($config_var[0] == 'permissions')
786
-				continue;
805
+			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) {
806
+							$inlinePermissions[] = $config_var[1];
807
+			} elseif ($config_var[0] == 'permissions') {
808
+							continue;
809
+			}
787 810
 
788
-			if ($config_var[0] == 'boards')
789
-				$board_list = true;
811
+			if ($config_var[0] == 'boards') {
812
+							$board_list = true;
813
+			}
790 814
 
791 815
 			// Are we showing the BBC selection box?
792
-			if ($config_var[0] == 'bbc')
793
-				$bbcChoice[] = $config_var[1];
816
+			if ($config_var[0] == 'bbc') {
817
+							$bbcChoice[] = $config_var[1];
818
+			}
794 819
 
795 820
 			// We need to do some parsing of the value before we pass it in.
796 821
 			if (isset($modSettings[$config_var[1]]))
@@ -809,8 +834,7 @@  discard block
 block discarded – undo
809 834
 					default:
810 835
 						$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
811 836
 				}
812
-			}
813
-			else
837
+			} else
814 838
 			{
815 839
 				// Darn, it's empty. What type is expected?
816 840
 				switch ($config_var[0])
@@ -850,16 +874,19 @@  discard block
 block discarded – undo
850 874
 			if ($config_var[0] == 'int' || $config_var[0] == 'float')
851 875
 			{
852 876
 				// Default to a min of 0 if one isn't set
853
-				if (isset($config_var['min']))
854
-					$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
855
-				else
856
-					$context['config_vars'][$config_var[1]]['min'] = 0;
877
+				if (isset($config_var['min'])) {
878
+									$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
879
+				} else {
880
+									$context['config_vars'][$config_var[1]]['min'] = 0;
881
+				}
857 882
 
858
-				if (isset($config_var['max']))
859
-					$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
883
+				if (isset($config_var['max'])) {
884
+									$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
885
+				}
860 886
 
861
-				if (isset($config_var['step']))
862
-					$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
887
+				if (isset($config_var['step'])) {
888
+									$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
889
+				}
863 890
 			}
864 891
 
865 892
 			// If this is a select box handle any data.
@@ -873,12 +900,13 @@  discard block
 block discarded – undo
873 900
 				}
874 901
 
875 902
 				// If it's associative
876
-				if (isset($config_var[2][0]) && is_array($config_var[2][0]))
877
-					$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
878
-				else
903
+				if (isset($config_var[2][0]) && is_array($config_var[2][0])) {
904
+									$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
905
+				} else
879 906
 				{
880
-					foreach ($config_var[2] as $key => $item)
881
-						$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
907
+					foreach ($config_var[2] as $key => $item) {
908
+											$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
909
+					}
882 910
 				}
883 911
 			}
884 912
 
@@ -887,17 +915,19 @@  discard block
 block discarded – undo
887 915
 			{
888 916
 				if (!is_numeric($k))
889 917
 				{
890
-					if (substr($k, 0, 2) == 'on')
891
-						$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
892
-					else
893
-						$context['config_vars'][$config_var[1]][$k] = $v;
918
+					if (substr($k, 0, 2) == 'on') {
919
+											$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
920
+					} else {
921
+											$context['config_vars'][$config_var[1]][$k] = $v;
922
+					}
894 923
 				}
895 924
 
896 925
 				// See if there are any other labels that might fit?
897
-				if (isset($txt['setting_' . $config_var[1]]))
898
-					$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
899
-				elseif (isset($txt['groups_' . $config_var[1]]))
900
-					$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
926
+				if (isset($txt['setting_' . $config_var[1]])) {
927
+									$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
928
+				} elseif (isset($txt['groups_' . $config_var[1]])) {
929
+									$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
930
+				}
901 931
 			}
902 932
 
903 933
 			// Set the subtext in case it's part of the label.
@@ -930,8 +960,9 @@  discard block
 block discarded – undo
930 960
 		// What are the options, eh?
931 961
 		$temp = parse_bbc(false);
932 962
 		$bbcTags = array();
933
-		foreach ($temp as $tag)
934
-			$bbcTags[] = $tag['tag'];
963
+		foreach ($temp as $tag) {
964
+					$bbcTags[] = $tag['tag'];
965
+		}
935 966
 
936 967
 		$bbcTags = array_unique($bbcTags);
937 968
 		$totalTags = count($bbcTags);
@@ -946,8 +977,9 @@  discard block
 block discarded – undo
946 977
 		$col = 0; $i = 0;
947 978
 		foreach ($bbcTags as $tag)
948 979
 		{
949
-			if ($i % $tagsPerColumn == 0 && $i != 0)
950
-				$col++;
980
+			if ($i % $tagsPerColumn == 0 && $i != 0) {
981
+							$col++;
982
+			}
951 983
 
952 984
 			$context['bbc_columns'][$col][] = array(
953 985
 				'tag' => $tag,
@@ -990,18 +1022,21 @@  discard block
 block discarded – undo
990 1022
 	validateToken('admin-ssc');
991 1023
 
992 1024
 	// Fix the darn stupid cookiename! (more may not be allowed, but these for sure!)
993
-	if (isset($_POST['cookiename']))
994
-		$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1025
+	if (isset($_POST['cookiename'])) {
1026
+			$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1027
+	}
995 1028
 
996 1029
 	// Fix the forum's URL if necessary.
997 1030
 	if (isset($_POST['boardurl']))
998 1031
 	{
999
-		if (substr($_POST['boardurl'], -10) == '/index.php')
1000
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1001
-		elseif (substr($_POST['boardurl'], -1) == '/')
1002
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1003
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
1004
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1032
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1033
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1034
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1035
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1036
+		}
1037
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1038
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1039
+		}
1005 1040
 	}
1006 1041
 
1007 1042
 	// Any passwords?
@@ -1036,21 +1071,21 @@  discard block
 block discarded – undo
1036 1071
 	// Figure out which config vars we're saving here...
1037 1072
 	foreach ($config_vars as $var)
1038 1073
 	{
1039
-		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]])))
1040
-			continue;
1074
+		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) {
1075
+					continue;
1076
+		}
1041 1077
 
1042 1078
 		$config_var = $var[0];
1043 1079
 
1044 1080
 		if (in_array($config_var, $config_passwords))
1045 1081
 		{
1046
-			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1])
1047
-				$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1048
-		}
1049
-		elseif (in_array($config_var, $config_strs))
1082
+			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) {
1083
+							$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1084
+			}
1085
+		} elseif (in_array($config_var, $config_strs))
1050 1086
 		{
1051 1087
 			$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\'';
1052
-		}
1053
-		elseif (in_array($config_var, $config_ints))
1088
+		} elseif (in_array($config_var, $config_ints))
1054 1089
 		{
1055 1090
 			$new_settings[$config_var] = (int) $_POST[$config_var];
1056 1091
 
@@ -1059,17 +1094,17 @@  discard block
 block discarded – undo
1059 1094
 			$new_settings[$config_var] = max($min, $new_settings[$config_var]);
1060 1095
 
1061 1096
 			// Is there a max value for this as well?
1062
-			if (isset($var['max']))
1063
-				$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1064
-		}
1065
-		elseif (in_array($config_var, $config_bools))
1097
+			if (isset($var['max'])) {
1098
+							$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1099
+			}
1100
+		} elseif (in_array($config_var, $config_bools))
1066 1101
 		{
1067
-			if (!empty($_POST[$config_var]))
1068
-				$new_settings[$config_var] = '1';
1069
-			else
1070
-				$new_settings[$config_var] = '0';
1071
-		}
1072
-		else
1102
+			if (!empty($_POST[$config_var])) {
1103
+							$new_settings[$config_var] = '1';
1104
+			} else {
1105
+							$new_settings[$config_var] = '0';
1106
+			}
1107
+		} else
1073 1108
 		{
1074 1109
 			// This shouldn't happen, but it might...
1075 1110
 			fatal_error('Unknown config_var \'' . $config_var . '\'');
@@ -1085,30 +1120,35 @@  discard block
 block discarded – undo
1085 1120
 	foreach ($config_vars as $config_var)
1086 1121
 	{
1087 1122
 		// We just saved the file-based settings, so skip their definitions.
1088
-		if (!is_array($config_var) || $config_var[2] == 'file')
1089
-			continue;
1123
+		if (!is_array($config_var) || $config_var[2] == 'file') {
1124
+					continue;
1125
+		}
1090 1126
 
1091 1127
 		$new_setting = array($config_var[3], $config_var[0]);
1092 1128
 
1093 1129
 		// Select options need carried over, too.
1094
-		if (isset($config_var[4]))
1095
-			$new_setting[] = $config_var[4];
1130
+		if (isset($config_var[4])) {
1131
+					$new_setting[] = $config_var[4];
1132
+		}
1096 1133
 
1097 1134
 		// Include min and max if necessary
1098
-		if (isset($config_var['min']))
1099
-			$new_setting['min'] = $config_var['min'];
1135
+		if (isset($config_var['min'])) {
1136
+					$new_setting['min'] = $config_var['min'];
1137
+		}
1100 1138
 
1101
-		if (isset($config_var['max']))
1102
-			$new_setting['max'] = $config_var['max'];
1139
+		if (isset($config_var['max'])) {
1140
+					$new_setting['max'] = $config_var['max'];
1141
+		}
1103 1142
 
1104 1143
 		// Rewrite the definition a bit.
1105 1144
 		$new_settings[] = $new_setting;
1106 1145
 	}
1107 1146
 
1108 1147
 	// Save the new database-based settings, if any.
1109
-	if (!empty($new_settings))
1110
-		saveDBSettings($new_settings);
1111
-}
1148
+	if (!empty($new_settings)) {
1149
+			saveDBSettings($new_settings);
1150
+	}
1151
+	}
1112 1152
 
1113 1153
 /**
1114 1154
  * Helper function for saving database settings.
@@ -1126,22 +1166,25 @@  discard block
 block discarded – undo
1126 1166
 	$inlinePermissions = array();
1127 1167
 	foreach ($config_vars as $var)
1128 1168
 	{
1129
-		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags']))))
1130
-			continue;
1169
+		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) {
1170
+					continue;
1171
+		}
1131 1172
 
1132 1173
 		// Checkboxes!
1133
-		elseif ($var[0] == 'check')
1134
-			$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1174
+		elseif ($var[0] == 'check') {
1175
+					$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1176
+		}
1135 1177
 		// Select boxes!
1136
-		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2])))
1137
-			$setArray[$var[1]] = $_POST[$var[1]];
1138
-		elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1178
+		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) {
1179
+					$setArray[$var[1]] = $_POST[$var[1]];
1180
+		} elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1139 1181
 		{
1140 1182
 			// For security purposes we validate this line by line.
1141 1183
 			$lOptions = array();
1142
-			foreach ($_POST[$var[1]] as $invar)
1143
-				if (in_array($invar, array_keys($var[2])))
1184
+			foreach ($_POST[$var[1]] as $invar) {
1185
+							if (in_array($invar, array_keys($var[2])))
1144 1186
 					$lOptions[] = $invar;
1187
+			}
1145 1188
 
1146 1189
 			$setArray[$var[1]] = json_encode($lOptions);
1147 1190
 		}
@@ -1155,18 +1198,20 @@  discard block
 block discarded – undo
1155 1198
 				$request = $smcFunc['db_query']('', '
1156 1199
 					SELECT id_board
1157 1200
 					FROM {db_prefix}boards');
1158
-				while ($row = $smcFunc['db_fetch_row']($request))
1159
-					$board_list[$row[0]] = true;
1201
+				while ($row = $smcFunc['db_fetch_row']($request)) {
1202
+									$board_list[$row[0]] = true;
1203
+				}
1160 1204
 
1161 1205
 				$smcFunc['db_free_result']($request);
1162 1206
 			}
1163 1207
 
1164 1208
 			$lOptions = array();
1165 1209
 
1166
-			if (!empty($_POST[$var[1]]))
1167
-				foreach ($_POST[$var[1]] as $invar => $dummy)
1210
+			if (!empty($_POST[$var[1]])) {
1211
+							foreach ($_POST[$var[1]] as $invar => $dummy)
1168 1212
 					if (isset($board_list[$invar]))
1169 1213
 						$lOptions[] = $invar;
1214
+			}
1170 1215
 
1171 1216
 			$setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : '';
1172 1217
 		}
@@ -1180,8 +1225,9 @@  discard block
 block discarded – undo
1180 1225
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1181 1226
 
1182 1227
 			// Do we have a max value for this as well?
1183
-			if (isset($var['max']))
1184
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1228
+			if (isset($var['max'])) {
1229
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1230
+			}
1185 1231
 		}
1186 1232
 		// Floating point!
1187 1233
 		elseif ($var[0] == 'float')
@@ -1193,40 +1239,47 @@  discard block
 block discarded – undo
1193 1239
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1194 1240
 
1195 1241
 			// Do we have a max value for this as well?
1196
-			if (isset($var['max']))
1197
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1242
+			if (isset($var['max'])) {
1243
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1244
+			}
1198 1245
 		}
1199 1246
 		// Text!
1200
-		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time')))
1201
-			$setArray[$var[1]] = $_POST[$var[1]];
1247
+		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) {
1248
+					$setArray[$var[1]] = $_POST[$var[1]];
1249
+		}
1202 1250
 		// Passwords!
1203 1251
 		elseif ($var[0] == 'password')
1204 1252
 		{
1205
-			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1])
1206
-				$setArray[$var[1]] = $_POST[$var[1]][0];
1253
+			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) {
1254
+							$setArray[$var[1]] = $_POST[$var[1]][0];
1255
+			}
1207 1256
 		}
1208 1257
 		// BBC.
1209 1258
 		elseif ($var[0] == 'bbc')
1210 1259
 		{
1211 1260
 
1212 1261
 			$bbcTags = array();
1213
-			foreach (parse_bbc(false) as $tag)
1214
-				$bbcTags[] = $tag['tag'];
1262
+			foreach (parse_bbc(false) as $tag) {
1263
+							$bbcTags[] = $tag['tag'];
1264
+			}
1215 1265
 
1216
-			if (!isset($_POST[$var[1] . '_enabledTags']))
1217
-				$_POST[$var[1] . '_enabledTags'] = array();
1218
-			elseif (!is_array($_POST[$var[1] . '_enabledTags']))
1219
-				$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1266
+			if (!isset($_POST[$var[1] . '_enabledTags'])) {
1267
+							$_POST[$var[1] . '_enabledTags'] = array();
1268
+			} elseif (!is_array($_POST[$var[1] . '_enabledTags'])) {
1269
+							$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1270
+			}
1220 1271
 
1221 1272
 			$setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags']));
1222 1273
 		}
1223 1274
 		// Permissions?
1224
-		elseif ($var[0] == 'permissions')
1225
-			$inlinePermissions[] = $var[1];
1275
+		elseif ($var[0] == 'permissions') {
1276
+					$inlinePermissions[] = $var[1];
1277
+		}
1226 1278
 	}
1227 1279
 
1228
-	if (!empty($setArray))
1229
-		updateSettings($setArray);
1280
+	if (!empty($setArray)) {
1281
+			updateSettings($setArray);
1282
+	}
1230 1283
 
1231 1284
 	// If we have inline permissions we need to save them.
1232 1285
 	if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
@@ -1264,18 +1317,21 @@  discard block
 block discarded – undo
1264 1317
 	// put all of it into an array
1265 1318
 	foreach ($info_lines as $line)
1266 1319
 	{
1267
-		if (preg_match('~(' . $remove . ')~', $line))
1268
-			continue;
1320
+		if (preg_match('~(' . $remove . ')~', $line)) {
1321
+					continue;
1322
+		}
1269 1323
 
1270 1324
 		// new category?
1271
-		if (strpos($line, '<h2>') !== false)
1272
-			$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1325
+		if (strpos($line, '<h2>') !== false) {
1326
+					$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1327
+		}
1273 1328
 
1274 1329
 		// load it as setting => value or the old setting local master
1275
-		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1276
-			$pinfo[$category][$val[1]] = $val[2];
1277
-		elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1278
-			$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1330
+		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1331
+					$pinfo[$category][$val[1]] = $val[2];
1332
+		} elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1333
+					$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1334
+		}
1279 1335
 	}
1280 1336
 
1281 1337
 	// load it in to context and display it
@@ -1310,8 +1366,9 @@  discard block
 block discarded – undo
1310 1366
 				$testAPI = new $cache_class_name();
1311 1367
 
1312 1368
 				// No Support?  NEXT!
1313
-				if (!$testAPI->isSupported(true))
1314
-					continue;
1369
+				if (!$testAPI->isSupported(true)) {
1370
+									continue;
1371
+				}
1315 1372
 
1316 1373
 				$apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache;
1317 1374
 			}
Please login to merge, or discard this patch.
Sources/Subs-Compat.php 1 patch
Braces   +27 added lines, -19 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
  * @version 2.1 Beta 3
17 17
  */
18 18
 
19
-if (!defined('SMF'))
19
+if (!defined('SMF')) {
20 20
 	die('No direct access...');
21
+}
21 22
 
22 23
 
23 24
 /**
@@ -28,14 +29,16 @@  discard block
 block discarded – undo
28 29
 function sha1_smf($str)
29 30
 {
30 31
 	// If we have mhash loaded in, use it instead!
31
-	if (function_exists('mhash') && defined('MHASH_SHA1'))
32
-		return bin2hex(mhash(MHASH_SHA1, $str));
32
+	if (function_exists('mhash') && defined('MHASH_SHA1')) {
33
+			return bin2hex(mhash(MHASH_SHA1, $str));
34
+	}
33 35
 
34 36
 	$nblk = (strlen($str) + 8 >> 6) + 1;
35 37
 	$blks = array_pad(array(), $nblk * 16, 0);
36 38
 
37
-	for ($i = 0; $i < strlen($str); $i++)
38
-		$blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8);
39
+	for ($i = 0; $i < strlen($str); $i++) {
40
+			$blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8);
41
+	}
39 42
 
40 43
 	$blks[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8);
41 44
 
@@ -70,10 +73,11 @@  discard block
 block discarded – undo
70 73
 
71 74
 		for ($j = 0; $j < 80; $j++)
72 75
 		{
73
-			if ($j < 16)
74
-				$w[$j] = isset($x[$i + $j]) ? $x[$i + $j] : 0;
75
-			else
76
-				$w[$j] = sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);
76
+			if ($j < 16) {
77
+							$w[$j] = isset($x[$i + $j]) ? $x[$i + $j] : 0;
78
+			} else {
79
+							$w[$j] = sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);
80
+			}
77 81
 
78 82
 			$t = sha1_rol($a, 5) + sha1_ft($j, $b, $c, $d) + $e + $w[$j] + sha1_kt($j);
79 83
 			$e = $d;
@@ -103,12 +107,15 @@  discard block
 block discarded – undo
103 107
  */
104 108
 function sha1_ft($t, $b, $c, $d)
105 109
 {
106
-	if ($t < 20)
107
-		return ($b & $c) | ((~$b) & $d);
108
-	if ($t < 40)
109
-		return $b ^ $c ^ $d;
110
-	if ($t < 60)
111
-		return ($b & $c) | ($b & $d) | ($c & $d);
110
+	if ($t < 20) {
111
+			return ($b & $c) | ((~$b) & $d);
112
+	}
113
+	if ($t < 40) {
114
+			return $b ^ $c ^ $d;
115
+	}
116
+	if ($t < 60) {
117
+			return ($b & $c) | ($b & $d) | ($c & $d);
118
+	}
112 119
 
113 120
 	return $b ^ $c ^ $d;
114 121
 }
@@ -132,10 +139,11 @@  discard block
 block discarded – undo
132 139
 function sha1_rol($num, $cnt)
133 140
 {
134 141
 	// Unfortunately, PHP uses unsigned 32-bit longs only.  So we have to kludge it a bit.
135
-	if ($num & 0x80000000)
136
-		$a = ($num >> 1 & 0x7fffffff) >> (31 - $cnt);
137
-	else
138
-		$a = $num >> (32 - $cnt);
142
+	if ($num & 0x80000000) {
143
+			$a = ($num >> 1 & 0x7fffffff) >> (31 - $cnt);
144
+	} else {
145
+			$a = $num >> (32 - $cnt);
146
+	}
139 147
 
140 148
 	return ($num << $cnt) | $a;
141 149
 }
Please login to merge, or discard this patch.
Sources/ShowAttachments.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 	}
72 72
 
73 73
 	// Use cache when possible.
74
-	if (($cache = cache_get_data('attachment_lookup_id-'. $attachId)) != null)
74
+	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null)
75 75
 		list($file, $thumbFile) = $cache;
76 76
 
77 77
 	// Get the info from the DB.
78
-	if(empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
78
+	if (empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
79 79
 	{
80 80
 		// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
81 81
 		$attachRequest = null;
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 		$file['filePath'] = getAttachmentFilename($file['filename'], $attachId, $file['id_folder'], false, $file['file_hash']);
145 145
 		// ensure variant attachment compatibility
146 146
 		$filePath = pathinfo($file['filePath']);
147
-		$file['filePath'] = !file_exists($file['filePath']) ? substr($file['filePath'], 0, -(strlen($filePath['extension'])+1)) : $file['filePath'];
148
-		$file['etag'] = '"'. md5_file($file['filePath']) .'"';
147
+		$file['filePath'] = !file_exists($file['filePath']) ? substr($file['filePath'], 0, -(strlen($filePath['extension']) + 1)) : $file['filePath'];
148
+		$file['etag'] = '"' . md5_file($file['filePath']) . '"';
149 149
 
150 150
 		// now get the thumbfile!
151 151
 		$thumbFile = array();
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
 
172 172
 				// set filePath and ETag time
173 173
 				$thumbFile['filePath'] = getAttachmentFilename($thumbFile['filename'], $attachId, $thumbFile['id_folder'], false, $thumbFile['file_hash']);
174
-				$thumbFile['etag'] = '"'. md5_file($thumbFile['filePath']) .'"';
174
+				$thumbFile['etag'] = '"' . md5_file($thumbFile['filePath']) . '"';
175 175
 			}
176 176
 		}
177 177
 
178 178
 		// Cache it.
179
-		if(!empty($file) || !empty($thumbFile))
180
-			cache_put_data('attachment_lookup_id-'. $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
179
+		if (!empty($file) || !empty($thumbFile))
180
+			cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
181 181
 	}
182 182
 
183 183
 	// Update the download counter (unless it's a thumbnail).
@@ -289,17 +289,17 @@  discard block
 block discarded – undo
289 289
 	if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file['fileext'], array('txt', 'css', 'htm', 'html', 'php', 'xml')))
290 290
 	{
291 291
 		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false)
292
-			$callback = function ($buffer)
292
+			$callback = function($buffer)
293 293
 			{
294 294
 				return preg_replace('~[\r]?\n~', "\r\n", $buffer);
295 295
 			};
296 296
 		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false)
297
-			$callback = function ($buffer)
297
+			$callback = function($buffer)
298 298
 			{
299 299
 				return preg_replace('~[\r]?\n~', "\r", $buffer);
300 300
 			};
301 301
 		else
302
-			$callback = function ($buffer)
302
+			$callback = function($buffer)
303 303
 			{
304 304
 				return preg_replace('~[\r]?\n~', "\n", $buffer);
305 305
 			};
Please login to merge, or discard this patch.
Braces   +63 added lines, -54 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Shows an avatar based on $_GET['attach']
@@ -35,11 +36,11 @@  discard block
 block discarded – undo
35 36
 
36 37
 	if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0)
37 38
 	{
38
-		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler')
39
-			$modSettings['enableCompressedOutput'] = 0;
40
-
41
-		else
42
-			ob_start('ob_gzhandler');
39
+		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') {
40
+					$modSettings['enableCompressedOutput'] = 0;
41
+		} else {
42
+					ob_start('ob_gzhandler');
43
+		}
43 44
 	}
44 45
 
45 46
 	if (empty($modSettings['enableCompressedOutput']))
@@ -71,8 +72,9 @@  discard block
 block discarded – undo
71 72
 	}
72 73
 
73 74
 	// Use cache when possible.
74
-	if (($cache = cache_get_data('attachment_lookup_id-'. $attachId)) != null)
75
-		list($file, $thumbFile) = $cache;
75
+	if (($cache = cache_get_data('attachment_lookup_id-'. $attachId)) != null) {
76
+			list($file, $thumbFile) = $cache;
77
+	}
76 78
 
77 79
 	// Get the info from the DB.
78 80
 	if(empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
@@ -80,10 +82,9 @@  discard block
 block discarded – undo
80 82
 		// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
81 83
 		$attachRequest = null;
82 84
 		call_integration_hook('integrate_download_request', array(&$attachRequest));
83
-		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
84
-			$request = $attachRequest;
85
-
86
-		else
85
+		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
86
+					$request = $attachRequest;
87
+		} else
87 88
 		{
88 89
 			// Make sure this attachment is on this board and load its info while we are at it.
89 90
 			$request = $smcFunc['db_query']('', '
@@ -176,13 +177,14 @@  discard block
 block discarded – undo
176 177
 		}
177 178
 
178 179
 		// Cache it.
179
-		if(!empty($file) || !empty($thumbFile))
180
-			cache_put_data('attachment_lookup_id-'. $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
180
+		if(!empty($file) || !empty($thumbFile)) {
181
+					cache_put_data('attachment_lookup_id-'. $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
182
+		}
181 183
 	}
182 184
 
183 185
 	// Update the download counter (unless it's a thumbnail).
184
-	if ($file['attachment_type'] != 3 && empty($showThumb))
185
-		$smcFunc['db_query']('attach_download_increase', '
186
+	if ($file['attachment_type'] != 3 && empty($showThumb)) {
187
+			$smcFunc['db_query']('attach_download_increase', '
186 188
 			UPDATE LOW_PRIORITY {db_prefix}attachments
187 189
 			SET downloads = downloads + 1
188 190
 			WHERE id_attach = {int:id_attach}',
@@ -190,10 +192,12 @@  discard block
 block discarded – undo
190 192
 				'id_attach' => $attachId,
191 193
 			)
192 194
 		);
195
+	}
193 196
 
194 197
 	// Replace the normal file with its thumbnail if it has one!
195
-	if (!empty($showThumb) && !empty($thumbFile))
196
-		$file = $thumbFile;
198
+	if (!empty($showThumb) && !empty($thumbFile)) {
199
+			$file = $thumbFile;
200
+	}
197 201
 
198 202
 	// No point in a nicer message, because this is supposed to be an attachment anyway...
199 203
 	if (!file_exists($file['filePath']))
@@ -232,8 +236,9 @@  discard block
 block discarded – undo
232 236
 	// Send the attachment headers.
233 237
 	header('Pragma: ');
234 238
 
235
-	if (!isBrowser('gecko'))
236
-		header('Content-Transfer-Encoding: binary');
239
+	if (!isBrowser('gecko')) {
240
+			header('Content-Transfer-Encoding: binary');
241
+	}
237 242
 
238 243
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
239 244
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT');
@@ -242,18 +247,19 @@  discard block
 block discarded – undo
242 247
 	header('ETag: ' . $eTag);
243 248
 
244 249
 	// Make sure the mime type warrants an inline display.
245
-	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0)
246
-		unset($_REQUEST['image']);
250
+	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) {
251
+			unset($_REQUEST['image']);
252
+	}
247 253
 
248 254
 	// Does this have a mime type?
249
-	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
250
-		header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
251
-
252
-	else
255
+	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
256
+			header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
257
+	} else
253 258
 	{
254 259
 		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
255
-		if (isset($_REQUEST['image']))
256
-			unset($_REQUEST['image']);
260
+		if (isset($_REQUEST['image'])) {
261
+					unset($_REQUEST['image']);
262
+		}
257 263
 	}
258 264
 
259 265
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -261,24 +267,22 @@  discard block
 block discarded – undo
261 267
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
262 268
 
263 269
 	// Different browsers like different standards...
264
-	if (isBrowser('firefox'))
265
-		header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
266
-
267
-	elseif (isBrowser('opera'))
268
-		header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
269
-
270
-	elseif (isBrowser('ie'))
271
-		header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
272
-
273
-	else
274
-		header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
270
+	if (isBrowser('firefox')) {
271
+			header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
272
+	} elseif (isBrowser('opera')) {
273
+			header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
274
+	} elseif (isBrowser('ie')) {
275
+			header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
276
+	} else {
277
+			header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
278
+	}
275 279
 
276 280
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
277
-	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
278
-		header('Cache-Control: no-cache');
279
-
280
-	else
281
-		header('Cache-Control: max-age=' . (525600 * 60) . ', private');
281
+	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
282
+			header('Cache-Control: no-cache');
283
+	} else {
284
+			header('Cache-Control: max-age=' . (525600 * 60) . ', private');
285
+	}
282 286
 
283 287
 	header('Content-Length: ' . filesize($file['filePath']));
284 288
 
@@ -288,20 +292,23 @@  discard block
 block discarded – undo
288 292
 	// Recode line endings for text files, if enabled.
289 293
 	if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file['fileext'], array('txt', 'css', 'htm', 'html', 'php', 'xml')))
290 294
 	{
291
-		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false)
292
-			$callback = function ($buffer)
295
+		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) {
296
+					$callback = function ($buffer)
293 297
 			{
294 298
 				return preg_replace('~[\r]?\n~', "\r\n", $buffer);
299
+		}
295 300
 			};
296
-		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false)
297
-			$callback = function ($buffer)
301
+		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) {
302
+					$callback = function ($buffer)
298 303
 			{
299 304
 				return preg_replace('~[\r]?\n~', "\r", $buffer);
305
+		}
300 306
 			};
301
-		else
302
-			$callback = function ($buffer)
307
+		else {
308
+					$callback = function ($buffer)
303 309
 			{
304 310
 				return preg_replace('~[\r]?\n~', "\n", $buffer);
311
+		}
305 312
 			};
306 313
 	}
307 314
 
@@ -309,8 +316,9 @@  discard block
 block discarded – undo
309 316
 	if (filesize($file['filePath']) > 4194304)
310 317
 	{
311 318
 		// Forcibly end any output buffering going on.
312
-		while (@ob_get_level() > 0)
313
-			@ob_end_clean();
319
+		while (@ob_get_level() > 0) {
320
+					@ob_end_clean();
321
+		}
314 322
 
315 323
 		$fp = fopen($file['filePath'], 'rb');
316 324
 		while (!feof($fp))
@@ -322,8 +330,9 @@  discard block
 block discarded – undo
322 330
 	}
323 331
 
324 332
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
325
-	elseif (@readfile($file['filePath']) === null)
326
-		echo file_get_contents($file['filePath']);
333
+	elseif (@readfile($file['filePath']) === null) {
334
+			echo file_get_contents($file['filePath']);
335
+	}
327 336
 
328 337
 	die();
329 338
 }
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	{
151 151
 		if (!@is_dir($directory))
152 152
 		{
153
-			if (!@mkdir($directory,0755))
153
+			if (!@mkdir($directory, 0755))
154 154
 			{
155 155
 				$context['dir_creation_error'] = 'attachments_no_create';
156 156
 				return false;
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
  *
249 249
  * @return array|bool An array of all the directories and subdirectories or false on failure
250 250
  */
251
-function get_directory_tree_elements ($directory)
251
+function get_directory_tree_elements($directory)
252 252
 {
253 253
 	/*
254 254
 		In Windows server both \ and / can be used as directory separators in paths
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
265 265
 			return false;
266 266
 
267
-		$tree = explode(DIRECTORY_SEPARATOR, trim($directory,DIRECTORY_SEPARATOR));
267
+		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
268 268
 	}
269 269
 	return $tree;
270 270
 }
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
  *
278 278
  * @return string|bool The first part of the path or false on error
279 279
  */
280
-function attachments_init_dir (&$tree, &$count)
280
+function attachments_init_dir(&$tree, &$count)
281 281
 {
282 282
 	$directory = '';
283 283
 	// If on Windows servers the first part of the path is the drive (e.g. "C:")
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 		 //Better be sure that the first part of the path is actually a drive letter...
287 287
 		 //...even if, I should check this in the admin page...isn't it?
288 288
 		 //...NHAAA Let's leave space for users' complains! :P
289
-		if (preg_match('/^[a-z]:$/i',$tree[0]))
289
+		if (preg_match('/^[a-z]:$/i', $tree[0]))
290 290
 			$directory = array_shift($tree);
291 291
 		else
292 292
 			return false;
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 	global $modSettings, $context, $sourcedir, $smcFunc;
485 485
 
486 486
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
487
-	if ( empty($_SESSION['temp_attachments'][$attachID]))
487
+	if (empty($_SESSION['temp_attachments'][$attachID]))
488 488
 		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
489 489
 
490 490
 	elseif (empty($attachID))
@@ -911,9 +911,9 @@  discard block
 block discarded – undo
911 911
 		$attachContext = $attachLoaded[$attachID];
912 912
 
913 913
 		// Fix the url to point out to showAvatar().
914
-		$attachContext['href'] = $scripturl . '?action=dlattach;attach=' . $attachID .';type=preview';
914
+		$attachContext['href'] = $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview';
915 915
 
916
-		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID .';type=preview'. (empty($attachContext['is_image']) ? ';file' : '') .'">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
916
+		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
917 917
 
918 918
 		// Fix the thumbnail too, if the image has one.
919 919
 		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
 				LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)') . '
1079 1079
 				LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
1080 1080
 			WHERE a.attachment_type = {int:attachment_type}
1081
-				'. (!empty($msgID) ? 'AND a.id_msg = {int:message_id}' : '') .'',
1081
+				'. (!empty($msgID) ? 'AND a.id_msg = {int:message_id}' : '') . '',
1082 1082
 			array(
1083 1083
 				'message_id' => $msgID,
1084 1084
 				'attachment_type' => 0,
Please login to merge, or discard this patch.
Braces   +294 added lines, -222 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -55,21 +58,25 @@  discard block
 block discarded – undo
55 58
 
56 59
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
57 60
 	{
58
-			if (!is_array($modSettings['attachment_basedirectories']))
59
-				$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
61
+			if (!is_array($modSettings['attachment_basedirectories'])) {
62
+							$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
63
+			}
60 64
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
65
+	} else {
66
+			$base_dir = 0;
61 67
 	}
62
-	else
63
-		$base_dir = 0;
64 68
 
65 69
 	if ($modSettings['automanage_attachments'] == 1)
66 70
 	{
67
-		if (!isset($modSettings['last_attachments_directory']))
68
-			$modSettings['last_attachments_directory'] = array();
69
-		if (!is_array($modSettings['last_attachments_directory']))
70
-			$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
71
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
72
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
71
+		if (!isset($modSettings['last_attachments_directory'])) {
72
+					$modSettings['last_attachments_directory'] = array();
73
+		}
74
+		if (!is_array($modSettings['last_attachments_directory'])) {
75
+					$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
76
+		}
77
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
78
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
79
+		}
73 80
 	}
74 81
 
75 82
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -98,12 +105,14 @@  discard block
 block discarded – undo
98 105
 			$updir = '';
99 106
 	}
100 107
 
101
-	if (!is_array($modSettings['attachmentUploadDir']))
102
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
103
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
104
-		$outputCreation = automanage_attachments_create_directory($updir);
105
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
106
-		$outputCreation = true;
108
+	if (!is_array($modSettings['attachmentUploadDir'])) {
109
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
110
+	}
111
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
112
+			$outputCreation = automanage_attachments_create_directory($updir);
113
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
114
+			$outputCreation = true;
115
+	}
107 116
 
108 117
 	if ($outputCreation)
109 118
 	{
@@ -140,8 +149,9 @@  discard block
 block discarded – undo
140 149
 		$count = count($tree);
141 150
 
142 151
 		$directory = attachments_init_dir($tree, $count);
143
-		if ($directory === false)
144
-			return false;
152
+		if ($directory === false) {
153
+					return false;
154
+		}
145 155
 	}
146 156
 
147 157
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -169,8 +179,9 @@  discard block
 block discarded – undo
169 179
 	}
170 180
 
171 181
 	// Everything seems fine...let's create the .htaccess
172
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
173
-		secureDirectory($updir, true);
182
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
183
+			secureDirectory($updir, true);
184
+	}
174 185
 
175 186
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
176 187
 	$updir = rtrim($updir, $sep);
@@ -202,8 +213,9 @@  discard block
 block discarded – undo
202 213
 {
203 214
 	global $modSettings, $boarddir;
204 215
 
205
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
206
-		return;
216
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
217
+			return;
218
+	}
207 219
 
208 220
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
209 221
 	// Just to be sure: I don't want directory separators at the end
@@ -215,13 +227,14 @@  discard block
 block discarded – undo
215 227
 	{
216 228
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
217 229
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
230
+	} else {
231
+			$base_dir = 0;
218 232
 	}
219
-	else
220
-		$base_dir = 0;
221 233
 
222 234
 	// Get the last attachment directory for that base directory
223
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
224
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
235
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
236
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
237
+	}
225 238
 	// And increment it.
226 239
 	$modSettings['last_attachments_directory'][$base_dir]++;
227 240
 
@@ -236,10 +249,10 @@  discard block
 block discarded – undo
236 249
 		$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
237 250
 
238 251
 		return true;
252
+	} else {
253
+			return false;
254
+	}
239 255
 	}
240
-	else
241
-		return false;
242
-}
243 256
 
244 257
 /**
245 258
  * Split a path into a list of all directories and subdirectories
@@ -257,12 +270,13 @@  discard block
 block discarded – undo
257 270
 			* in Windows we need to explode for both \ and /
258 271
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
259 272
 	*/
260
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
261
-		$tree = preg_split('#[\\\/]#', $directory);
262
-	else
273
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
274
+			$tree = preg_split('#[\\\/]#', $directory);
275
+	} else
263 276
 	{
264
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
265
-			return false;
277
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
278
+					return false;
279
+		}
266 280
 
267 281
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory,DIRECTORY_SEPARATOR));
268 282
 	}
@@ -286,10 +300,11 @@  discard block
 block discarded – undo
286 300
 		 //Better be sure that the first part of the path is actually a drive letter...
287 301
 		 //...even if, I should check this in the admin page...isn't it?
288 302
 		 //...NHAAA Let's leave space for users' complains! :P
289
-		if (preg_match('/^[a-z]:$/i',$tree[0]))
290
-			$directory = array_shift($tree);
291
-		else
292
-			return false;
303
+		if (preg_match('/^[a-z]:$/i',$tree[0])) {
304
+					$directory = array_shift($tree);
305
+		} else {
306
+					return false;
307
+		}
293 308
 
294 309
 		$count--;
295 310
 	}
@@ -304,18 +319,20 @@  discard block
 block discarded – undo
304 319
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
305 320
 
306 321
 	// Make sure we're uploading to the right place.
307
-	if (!empty($modSettings['automanage_attachments']))
308
-		automanage_attachments_check_directory();
322
+	if (!empty($modSettings['automanage_attachments'])) {
323
+			automanage_attachments_check_directory();
324
+	}
309 325
 
310
-	if (!is_array($modSettings['attachmentUploadDir']))
311
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
326
+	if (!is_array($modSettings['attachmentUploadDir'])) {
327
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
328
+	}
312 329
 
313 330
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
314 331
 
315 332
 	// Is the attachments folder actualy there?
316
-	if (!empty($context['dir_creation_error']))
317
-		$initial_error = $context['dir_creation_error'];
318
-	elseif (!is_dir($context['attach_dir']))
333
+	if (!empty($context['dir_creation_error'])) {
334
+			$initial_error = $context['dir_creation_error'];
335
+	} elseif (!is_dir($context['attach_dir']))
319 336
 	{
320 337
 		$initial_error = 'attach_folder_warning';
321 338
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -338,12 +355,12 @@  discard block
 block discarded – undo
338 355
 			);
339 356
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
340 357
 			$smcFunc['db_free_result']($request);
341
-		}
342
-		else
343
-			$context['attachments'] = array(
358
+		} else {
359
+					$context['attachments'] = array(
344 360
 				'quantity' => 0,
345 361
 				'total_size' => 0,
346 362
 			);
363
+		}
347 364
 	}
348 365
 
349 366
 	// Hmm. There are still files in session.
@@ -353,39 +370,44 @@  discard block
 block discarded – undo
353 370
 		// Let's try to keep them. But...
354 371
 		$ignore_temp = true;
355 372
 		// If new files are being added. We can't ignore those
356
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
357
-			if (!empty($dummy))
373
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
374
+					if (!empty($dummy))
358 375
 			{
359 376
 				$ignore_temp = false;
377
+		}
360 378
 				break;
361 379
 			}
362 380
 
363 381
 		// Need to make space for the new files. So, bye bye.
364 382
 		if (!$ignore_temp)
365 383
 		{
366
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
367
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
384
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
385
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
368 386
 					unlink($attachment['tmp_name']);
387
+			}
369 388
 
370 389
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
371 390
 			$_SESSION['temp_attachments'] = array();
372 391
 		}
373 392
 	}
374 393
 
375
-	if (!isset($_FILES['attachment']['name']))
376
-		$_FILES['attachment']['tmp_name'] = array();
394
+	if (!isset($_FILES['attachment']['name'])) {
395
+			$_FILES['attachment']['tmp_name'] = array();
396
+	}
377 397
 
378
-	if (!isset($_SESSION['temp_attachments']))
379
-		$_SESSION['temp_attachments'] = array();
398
+	if (!isset($_SESSION['temp_attachments'])) {
399
+			$_SESSION['temp_attachments'] = array();
400
+	}
380 401
 
381 402
 	// Remember where we are at. If it's anywhere at all.
382
-	if (!$ignore_temp)
383
-		$_SESSION['temp_attachments']['post'] = array(
403
+	if (!$ignore_temp) {
404
+			$_SESSION['temp_attachments']['post'] = array(
384 405
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
385 406
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
386 407
 			'topic' => !empty($topic) ? $topic : 0,
387 408
 			'board' => !empty($board) ? $board : 0,
388 409
 		);
410
+	}
389 411
 
390 412
 	// If we have an initial error, lets just display it.
391 413
 	if (!empty($initial_error))
@@ -393,9 +415,10 @@  discard block
 block discarded – undo
393 415
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
394 416
 
395 417
 		// And delete the files 'cos they ain't going nowhere.
396
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
397
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
418
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
419
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
398 420
 				unlink($_FILES['attachment']['tmp_name'][$n]);
421
+		}
399 422
 
400 423
 		$_FILES['attachment']['tmp_name'] = array();
401 424
 	}
@@ -403,21 +426,24 @@  discard block
 block discarded – undo
403 426
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
404 427
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
405 428
 	{
406
-		if ($_FILES['attachment']['name'][$n] == '')
407
-			continue;
429
+		if ($_FILES['attachment']['name'][$n] == '') {
430
+					continue;
431
+		}
408 432
 
409 433
 		// First, let's first check for PHP upload errors.
410 434
 		$errors = array();
411 435
 		if (!empty($_FILES['attachment']['error'][$n]))
412 436
 		{
413
-			if ($_FILES['attachment']['error'][$n] == 2)
414
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
415
-			elseif ($_FILES['attachment']['error'][$n] == 6)
416
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
417
-			else
418
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
419
-			if (empty($errors))
420
-				$errors[] = 'attach_php_error';
437
+			if ($_FILES['attachment']['error'][$n] == 2) {
438
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
439
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
440
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
441
+			} else {
442
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
443
+			}
444
+			if (empty($errors)) {
445
+							$errors[] = 'attach_php_error';
446
+			}
421 447
 		}
422 448
 
423 449
 		// Try to move and rename the file before doing any more checks on it.
@@ -435,16 +461,16 @@  discard block
 block discarded – undo
435 461
 			);
436 462
 
437 463
 			// Move the file to the attachments folder with a temp name for now.
438
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
439
-				smf_chmod($destName, 0644);
440
-			else
464
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
465
+							smf_chmod($destName, 0644);
466
+			} else
441 467
 			{
442 468
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
443
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
444
-					unlink($_FILES['attachment']['tmp_name'][$n]);
469
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
470
+									unlink($_FILES['attachment']['tmp_name'][$n]);
471
+				}
445 472
 			}
446
-		}
447
-		else
473
+		} else
448 474
 		{
449 475
 			$_SESSION['temp_attachments'][$attachID] = array(
450 476
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -452,12 +478,14 @@  discard block
 block discarded – undo
452 478
 				'errors' => $errors,
453 479
 			);
454 480
 
455
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
456
-				unlink($_FILES['attachment']['tmp_name'][$n]);
481
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
482
+							unlink($_FILES['attachment']['tmp_name'][$n]);
483
+			}
457 484
 		}
458 485
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
459
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
460
-			attachmentChecks($attachID);
486
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
487
+					attachmentChecks($attachID);
488
+		}
461 489
 	}
462 490
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
463 491
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -484,21 +512,20 @@  discard block
 block discarded – undo
484 512
 	global $modSettings, $context, $sourcedir, $smcFunc;
485 513
 
486 514
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
487
-	if ( empty($_SESSION['temp_attachments'][$attachID]))
488
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
489
-
490
-	elseif (empty($attachID))
491
-		$error = '$attachID';
492
-
493
-	elseif (empty($context['attachments']))
494
-		$error = '$context[\'attachments\']';
495
-
496
-	elseif (empty($context['attach_dir']))
497
-		$error = '$context[\'attach_dir\']';
515
+	if ( empty($_SESSION['temp_attachments'][$attachID])) {
516
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
517
+	} elseif (empty($attachID)) {
518
+			$error = '$attachID';
519
+	} elseif (empty($context['attachments'])) {
520
+			$error = '$context[\'attachments\']';
521
+	} elseif (empty($context['attach_dir'])) {
522
+			$error = '$context[\'attach_dir\']';
523
+	}
498 524
 
499 525
 	// Let's get their attention.
500
-	if (!empty($error))
501
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
526
+	if (!empty($error)) {
527
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
528
+	}
502 529
 
503 530
 	// Just in case this slipped by the first checks, we stop it here and now
504 531
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -527,8 +554,9 @@  discard block
 block discarded – undo
527 554
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
528 555
 			if (!(empty($size)) && ($size[2] != $old_format))
529 556
 			{
530
-				if (isset($context['validImageTypes'][$size[2]]))
531
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
557
+				if (isset($context['validImageTypes'][$size[2]])) {
558
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
559
+				}
532 560
 			}
533 561
 		}
534 562
 	}
@@ -582,42 +610,48 @@  discard block
 block discarded – undo
582 610
 				// Or, let the user know that it ain't gonna happen.
583 611
 				else
584 612
 				{
585
-					if (isset($context['dir_creation_error']))
586
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
587
-					else
588
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
613
+					if (isset($context['dir_creation_error'])) {
614
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
615
+					} else {
616
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
617
+					}
589 618
 				}
619
+			} else {
620
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
590 621
 			}
591
-			else
592
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
593 622
 		}
594 623
 	}
595 624
 
596 625
 	// Is the file too big?
597 626
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
598
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
599
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
627
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
628
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
629
+	}
600 630
 
601 631
 	// Check the total upload size for this post...
602
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
632
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
634
+	}
604 635
 
605 636
 	// Have we reached the maximum number of files we are allowed?
606 637
 	$context['attachments']['quantity']++;
607 638
 
608 639
 	// Set a max limit if none exists
609
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
610
-		$modSettings['attachmentNumPerPostLimit'] = 50;
640
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
641
+			$modSettings['attachmentNumPerPostLimit'] = 50;
642
+	}
611 643
 
612
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
613
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
644
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
645
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
646
+	}
614 647
 
615 648
 	// File extension check
616 649
 	if (!empty($modSettings['attachmentCheckExtensions']))
617 650
 	{
618 651
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
619
-		foreach ($allowed as $k => $dummy)
620
-			$allowed[$k] = trim($dummy);
652
+		foreach ($allowed as $k => $dummy) {
653
+					$allowed[$k] = trim($dummy);
654
+		}
621 655
 
622 656
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
623 657
 		{
@@ -629,10 +663,12 @@  discard block
 block discarded – undo
629 663
 	// Undo the math if there's an error
630 664
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
631 665
 	{
632
-		if (isset($context['dir_size']))
633
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
634
-		if (isset($context['dir_files']))
635
-			$context['dir_files']--;
666
+		if (isset($context['dir_size'])) {
667
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
668
+		}
669
+		if (isset($context['dir_files'])) {
670
+					$context['dir_files']--;
671
+		}
636 672
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
637 673
 		$context['attachments']['quantity']--;
638 674
 		return false;
@@ -664,12 +700,14 @@  discard block
 block discarded – undo
664 700
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
665 701
 	{
666 702
 		// Got a proper mime type?
667
-		if (!empty($size['mime']))
668
-			$attachmentOptions['mime_type'] = $size['mime'];
703
+		if (!empty($size['mime'])) {
704
+					$attachmentOptions['mime_type'] = $size['mime'];
705
+		}
669 706
 
670 707
 		// Otherwise a valid one?
671
-		elseif (isset($context['validImageTypes'][$size[2]]))
672
-			$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
708
+		elseif (isset($context['validImageTypes'][$size[2]])) {
709
+					$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
710
+		}
673 711
 	}
674 712
 
675 713
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -681,15 +719,17 @@  discard block
 block discarded – undo
681 719
 	}
682 720
 
683 721
 	// Get the hash if no hash has been given yet.
684
-	if (empty($attachmentOptions['file_hash']))
685
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
722
+	if (empty($attachmentOptions['file_hash'])) {
723
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
724
+	}
686 725
 
687 726
 	// Assuming no-one set the extension let's take a look at it.
688 727
 	if (empty($attachmentOptions['fileext']))
689 728
 	{
690 729
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
691
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
692
-			$attachmentOptions['fileext'] = '';
730
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
731
+					$attachmentOptions['fileext'] = '';
732
+		}
693 733
 	}
694 734
 
695 735
 	// Last chance to change stuff!
@@ -698,8 +738,9 @@  discard block
 block discarded – undo
698 738
 	// Make sure the folder is valid...
699 739
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true);
700 740
 	$folders = array_keys($tmp);
701
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
702
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
741
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
742
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
743
+	}
703 744
 
704 745
 	$smcFunc['db_insert']('',
705 746
 		'{db_prefix}attachments',
@@ -730,8 +771,8 @@  discard block
 block discarded – undo
730 771
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
731 772
 
732 773
 	// If it's not approved then add to the approval queue.
733
-	if (!$attachmentOptions['approved'])
734
-		$smcFunc['db_insert']('',
774
+	if (!$attachmentOptions['approved']) {
775
+			$smcFunc['db_insert']('',
735 776
 			'{db_prefix}approval_queue',
736 777
 			array(
737 778
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -741,9 +782,11 @@  discard block
 block discarded – undo
741 782
 			),
742 783
 			array()
743 784
 		);
785
+	}
744 786
 
745
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
746
-		return true;
787
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
788
+			return true;
789
+	}
747 790
 
748 791
 	// Like thumbnails, do we?
749 792
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -754,13 +797,15 @@  discard block
 block discarded – undo
754 797
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
755 798
 			list ($thumb_width, $thumb_height) = $size;
756 799
 
757
-			if (!empty($size['mime']))
758
-				$thumb_mime = $size['mime'];
759
-			elseif (isset($context['validImageTypes'][$size[2]]))
760
-				$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
800
+			if (!empty($size['mime'])) {
801
+							$thumb_mime = $size['mime'];
802
+			} elseif (isset($context['validImageTypes'][$size[2]])) {
803
+							$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
804
+			}
761 805
 			// Lord only knows how this happened...
762
-			else
763
-				$thumb_mime = '';
806
+			else {
807
+							$thumb_mime = '';
808
+			}
764 809
 
765 810
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
766 811
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -840,15 +885,17 @@  discard block
 block discarded – undo
840 885
 	global $smcFunc;
841 886
 
842 887
 	// Oh, come on!
843
-	if (empty($attachIDs) || empty($msgID))
844
-		return false;
888
+	if (empty($attachIDs) || empty($msgID)) {
889
+			return false;
890
+	}
845 891
 
846 892
 	// "I see what is right and approve, but I do what is wrong."
847 893
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
848 894
 
849 895
 	// One last check
850
-	if (empty($attachIDs))
851
-		return false;
896
+	if (empty($attachIDs)) {
897
+			return false;
898
+	}
852 899
 
853 900
 	// Perform.
854 901
 	$smcFunc['db_query']('', '
@@ -880,8 +927,9 @@  discard block
 block discarded – undo
880 927
 	$externalParse = false;
881 928
 
882 929
 	// Meh...
883
-	if (empty($attachID))
884
-		return 'attachments_no_data_loaded';
930
+	if (empty($attachID)) {
931
+			return 'attachments_no_data_loaded';
932
+	}
885 933
 
886 934
 	// Make it easy.
887 935
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -890,20 +938,23 @@  discard block
 block discarded – undo
890 938
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
891 939
 
892 940
 	// "I am innocent of the blood of this just person: see ye to it."
893
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
894
-		return $externalParse;
941
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
942
+			return $externalParse;
943
+	}
895 944
 
896 945
 	//Are attachments enable?
897
-	if (empty($modSettings['attachmentEnable']))
898
-		return 'attachments_not_enable';
946
+	if (empty($modSettings['attachmentEnable'])) {
947
+			return 'attachments_not_enable';
948
+	}
899 949
 
900 950
 	// Previewing much? no msg ID has been set yet.
901 951
 	if (!empty($context['preview_message']))
902 952
 	{
903 953
 		$allAttachments = getAttachsByMsg(0);
904 954
 
905
-		if (empty($allAttachments[0][$attachID]))
906
-			return 'attachments_no_data_loaded';
955
+		if (empty($allAttachments[0][$attachID])) {
956
+					return 'attachments_no_data_loaded';
957
+		}
907 958
 
908 959
 		$attachContext = $allAttachments[0][$attachID];
909 960
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
@@ -916,57 +967,66 @@  discard block
 block discarded – undo
916 967
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID .';type=preview'. (empty($attachContext['is_image']) ? ';file' : '') .'">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
917 968
 
918 969
 		// Fix the thumbnail too, if the image has one.
919
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
920
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
970
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
971
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		}
921 973
 
922 974
 		return $attachContext;
923 975
 	}
924 976
 
925 977
 	// There is always the chance someone else has already done our dirty work...
926 978
 	// If so, all pertinent checks were already done. Hopefully...
927
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
928
-		return $context['current_attachments'][$attachID];
979
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
980
+			return $context['current_attachments'][$attachID];
981
+	}
929 982
 
930 983
 	// If we are lucky enough to be in $board's scope then check it!
931
-	if (!empty($board) && !allowedTo('view_attachments', $board))
932
-		return 'attachments_not_allowed_to_see';
984
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
985
+			return 'attachments_not_allowed_to_see';
986
+	}
933 987
 
934 988
 	// Get the message info associated with this particular attach ID.
935 989
 	$attachInfo = getAttachMsgInfo($attachID);
936 990
 
937 991
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
938
-	if (empty($attachInfo) || empty($attachInfo['msg']))
939
-		return 'attachments_no_msg_associated';
992
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
993
+			return 'attachments_no_msg_associated';
994
+	}
940 995
 
941 996
 	// Hold it! got the info now check if you can see this attachment.
942
-	if (!allowedTo('view_attachments', $attachInfo['board']))
943
-		return 'attachments_not_allowed_to_see';
997
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
998
+			return 'attachments_not_allowed_to_see';
999
+	}
944 1000
 
945 1001
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
946 1002
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
947 1003
 
948 1004
 	// No point in keep going further.
949
-	if (!allowedTo('view_attachments', $attachContext['board']))
950
-		return 'attachments_not_allowed_to_see';
1005
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1006
+			return 'attachments_not_allowed_to_see';
1007
+	}
951 1008
 
952 1009
 	// Load this particular attach's context.
953
-	if (!empty($attachContext))
954
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1010
+	if (!empty($attachContext)) {
1011
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	}
955 1013
 
956 1014
 	// One last check, you know, gotta be paranoid...
957
-	else
958
-		return 'attachments_no_data_loaded';
1015
+	else {
1016
+			return 'attachments_no_data_loaded';
1017
+	}
959 1018
 
960 1019
 	// This is the last "if" I promise!
961
-	if (empty($attachLoaded))
962
-		return 'attachments_no_data_loaded';
963
-
964
-	else
965
-		$attachContext = $attachLoaded[$attachID];
1020
+	if (empty($attachLoaded)) {
1021
+			return 'attachments_no_data_loaded';
1022
+	} else {
1023
+			$attachContext = $attachLoaded[$attachID];
1024
+	}
966 1025
 
967 1026
 	// You may or may not want to show this under the post.
968
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
969
-		$context['show_attach_under_post'][$attachID] = $attachID;
1027
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1028
+			$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	}
970 1030
 
971 1031
 	// Last minute changes?
972 1032
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -986,8 +1046,9 @@  discard block
 block discarded – undo
986 1046
 {
987 1047
 	global $smcFunc, $modSettings;
988 1048
 
989
-	if (empty($attachIDs))
990
-		return array();
1049
+	if (empty($attachIDs)) {
1050
+			return array();
1051
+	}
991 1052
 
992 1053
 	$return = array();
993 1054
 
@@ -1003,11 +1064,12 @@  discard block
 block discarded – undo
1003 1064
 		)
1004 1065
 	);
1005 1066
 
1006
-	if ($smcFunc['db_num_rows']($request) != 1)
1007
-		return array();
1067
+	if ($smcFunc['db_num_rows']($request) != 1) {
1068
+			return array();
1069
+	}
1008 1070
 
1009
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1010
-		$return[$row['id_attach']] = array(
1071
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1072
+			$return[$row['id_attach']] = array(
1011 1073
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1012 1074
 			'size' => $row['size'],
1013 1075
 			'attachID' => $row['id_attach'],
@@ -1016,6 +1078,7 @@  discard block
 block discarded – undo
1016 1078
 			'mime_type' => $row['mime_type'],
1017 1079
 			'thumb' => $row['id_thumb'],
1018 1080
 		);
1081
+	}
1019 1082
 	$smcFunc['db_free_result']($request);
1020 1083
 
1021 1084
 	return $return;
@@ -1032,8 +1095,9 @@  discard block
 block discarded – undo
1032 1095
 {
1033 1096
 	global $smcFunc;
1034 1097
 
1035
-	if (empty($attachID))
1036
-		return array();
1098
+	if (empty($attachID)) {
1099
+			return array();
1100
+	}
1037 1101
 
1038 1102
 	$request = $smcFunc['db_query']('', '
1039 1103
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1046,8 +1110,9 @@  discard block
 block discarded – undo
1046 1110
 		)
1047 1111
 	);
1048 1112
 
1049
-	if ($smcFunc['db_num_rows']($request) != 1)
1050
-		return array();
1113
+	if ($smcFunc['db_num_rows']($request) != 1) {
1114
+			return array();
1115
+	}
1051 1116
 
1052 1117
 	$row = $smcFunc['db_fetch_assoc']($request);
1053 1118
 	$smcFunc['db_free_result']($request);
@@ -1088,8 +1153,9 @@  discard block
 block discarded – undo
1088 1153
 		$temp = array();
1089 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1090 1155
 		{
1091
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1092
-				continue;
1156
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1157
+							continue;
1158
+			}
1093 1159
 
1094 1160
 			$temp[$row['id_attach']] = $row;
1095 1161
 		}
@@ -1118,8 +1184,9 @@  discard block
 block discarded – undo
1118 1184
 {
1119 1185
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1120 1186
 
1121
-	if (empty($attachments) || empty($attachments[$id_msg]))
1122
-		return array();
1187
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1188
+			return array();
1189
+	}
1123 1190
 
1124 1191
 	// Set up the attachment info - based on code by Meriadoc.
1125 1192
 	$attachmentData = array();
@@ -1143,11 +1210,13 @@  discard block
 block discarded – undo
1143 1210
 			);
1144 1211
 
1145 1212
 			// If something is unapproved we'll note it so we can sort them.
1146
-			if (!$attachment['approved'])
1147
-				$have_unapproved = true;
1213
+			if (!$attachment['approved']) {
1214
+							$have_unapproved = true;
1215
+			}
1148 1216
 
1149
-			if (!$attachmentData[$i]['is_image'])
1150
-				continue;
1217
+			if (!$attachmentData[$i]['is_image']) {
1218
+							continue;
1219
+			}
1151 1220
 
1152 1221
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1153 1222
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1168,12 +1237,12 @@  discard block
 block discarded – undo
1168 1237
 						// So what folder are we putting this image in?
1169 1238
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1170 1239
 						{
1171
-							if (!is_array($modSettings['attachmentUploadDir']))
1172
-								$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1240
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1241
+															$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1242
+							}
1173 1243
 							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
1174 1244
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1175
-						}
1176
-						else
1245
+						} else
1177 1246
 						{
1178 1247
 							$path = $modSettings['attachmentUploadDir'];
1179 1248
 							$id_folder_thumb = 1;
@@ -1188,10 +1257,11 @@  discard block
 block discarded – undo
1188 1257
 						$thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : '';
1189 1258
 
1190 1259
 						// Figure out the mime type.
1191
-						if (!empty($size['mime']))
1192
-							$thumb_mime = $size['mime'];
1193
-						else
1194
-							$thumb_mime = 'image/' . $thumb_ext;
1260
+						if (!empty($size['mime'])) {
1261
+													$thumb_mime = $size['mime'];
1262
+						} else {
1263
+													$thumb_mime = 'image/' . $thumb_ext;
1264
+						}
1195 1265
 
1196 1266
 						$thumb_filename = $attachment['filename'] . '_thumb';
1197 1267
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1238,11 +1308,12 @@  discard block
 block discarded – undo
1238 1308
 				}
1239 1309
 			}
1240 1310
 
1241
-			if (!empty($attachment['id_thumb']))
1242
-				$attachmentData[$i]['thumbnail'] = array(
1311
+			if (!empty($attachment['id_thumb'])) {
1312
+							$attachmentData[$i]['thumbnail'] = array(
1243 1313
 					'id' => $attachment['id_thumb'],
1244 1314
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1245 1315
 				);
1316
+			}
1246 1317
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1247 1318
 
1248 1319
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1252,30 +1323,31 @@  discard block
 block discarded – undo
1252 1323
 				{
1253 1324
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1254 1325
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1255
-				}
1256
-				elseif (!empty($modSettings['max_image_width']))
1326
+				} elseif (!empty($modSettings['max_image_width']))
1257 1327
 				{
1258 1328
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1259 1329
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1260 1330
 				}
1261
-			}
1262
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1331
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1263 1332
 			{
1264 1333
 				// If the image is too large to show inline, make it a popup.
1265
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1266
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1267
-				else
1268
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1334
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1335
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1336
+				} else {
1337
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1338
+				}
1269 1339
 			}
1270 1340
 
1271
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1272
-				$attachmentData[$i]['downloads']++;
1341
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1342
+							$attachmentData[$i]['downloads']++;
1343
+			}
1273 1344
 		}
1274 1345
 	}
1275 1346
 
1276 1347
 	// Do we need to instigate a sort?
1277
-	if ($have_unapproved)
1278
-		usort($attachmentData, 'approved_attach_sort');
1348
+	if ($have_unapproved) {
1349
+			usort($attachmentData, 'approved_attach_sort');
1350
+	}
1279 1351
 
1280 1352
 	return $attachmentData;
1281 1353
 }
Please login to merge, or discard this patch.
Sources/ManageScheduledTasks.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -515,7 +515,7 @@
 block discarded – undo
515 515
 					'value' => $txt['scheduled_log_time_run'],
516 516
 				),
517 517
 				'data' => array(
518
-					'function' => function ($rowData)
518
+					'function' => function($rowData)
519 519
 					{
520 520
 						return timeformat($rowData['time_run'], true);
521 521
 					},
Please login to merge, or discard this patch.
Braces   +54 added lines, -38 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Scheduled tasks management dispatcher. This function checks permissions and delegates
@@ -40,10 +41,11 @@  discard block
 block discarded – undo
40 41
 	);
41 42
 
42 43
 	// We need to find what's the action.
43
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
44
-		$context['sub_action'] = $_REQUEST['sa'];
45
-	else
46
-		$context['sub_action'] = 'tasks';
44
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
45
+			$context['sub_action'] = $_REQUEST['sa'];
46
+	} else {
47
+			$context['sub_action'] = 'tasks';
48
+	}
47 49
 
48 50
 	// Now for the lovely tabs. That we all love.
49 51
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -90,9 +92,10 @@  discard block
 block discarded – undo
90 92
 
91 93
 		// Enable and disable as required.
92 94
 		$enablers = array(0);
93
-		foreach ($_POST['enable_task'] as $id => $enabled)
94
-			if ($enabled)
95
+		foreach ($_POST['enable_task'] as $id => $enabled) {
96
+					if ($enabled)
95 97
 				$enablers[] = (int) $id;
98
+		}
96 99
 
97 100
 		// Do the update!
98 101
 		$smcFunc['db_query']('', '
@@ -130,8 +133,9 @@  discard block
 block discarded – undo
130 133
 
131 134
 		// Lets figure out which ones they want to run.
132 135
 		$tasks = array();
133
-		foreach ($_POST['run_task'] as $task => $dummy)
134
-			$tasks[] = (int) $task;
136
+		foreach ($_POST['run_task'] as $task => $dummy) {
137
+					$tasks[] = (int) $task;
138
+		}
135 139
 
136 140
 		// Load up the tasks.
137 141
 		$request = $smcFunc['db_query']('', '
@@ -151,36 +155,41 @@  discard block
 block discarded – undo
151 155
 		while ($row = $smcFunc['db_fetch_assoc']($request))
152 156
 		{
153 157
 			// What kind of task are we handling?
154
-			if (!empty($row['callable']))
155
-				$task_string = $row['callable'];
158
+			if (!empty($row['callable'])) {
159
+							$task_string = $row['callable'];
160
+			}
156 161
 
157 162
 			// Default SMF task or old mods?
158
-			elseif (function_exists('scheduled_' . $row['task']))
159
-				$task_string = 'scheduled_' . $row['task'];
163
+			elseif (function_exists('scheduled_' . $row['task'])) {
164
+							$task_string = 'scheduled_' . $row['task'];
165
+			}
160 166
 
161 167
 			// One last resource, the task name.
162
-			elseif (!empty($row['task']))
163
-				$task_string = $row['task'];
168
+			elseif (!empty($row['task'])) {
169
+							$task_string = $row['task'];
170
+			}
164 171
 
165 172
 			$start_time = microtime();
166 173
 			// The functions got to exist for us to use it.
167
-			if (empty($task_string))
168
-				continue;
174
+			if (empty($task_string)) {
175
+							continue;
176
+			}
169 177
 
170 178
 			// Try to stop a timeout, this would be bad...
171 179
 			@set_time_limit(300);
172
-			if (function_exists('apache_reset_timeout'))
173
-				@apache_reset_timeout();
180
+			if (function_exists('apache_reset_timeout')) {
181
+							@apache_reset_timeout();
182
+			}
174 183
 
175 184
 			// Get the callable.
176 185
 			$callable_task = call_helper($task_string, true);
177 186
 
178 187
 			// Perform the task.
179
-			if (!empty($callable_task))
180
-				$completed = call_user_func($callable_task);
181
-
182
-			else
183
-				$completed = false;
188
+			if (!empty($callable_task)) {
189
+							$completed = call_user_func($callable_task);
190
+			} else {
191
+							$completed = false;
192
+			}
184 193
 
185 194
 			// Log that we did it ;)
186 195
 			if ($completed)
@@ -197,8 +206,9 @@  discard block
 block discarded – undo
197 206
 		$smcFunc['db_free_result']($request);
198 207
 
199 208
 		// If we had any errors, push them to session so we can pick them up next time to tell the user.
200
-		if (!empty($context['scheduled_errors']))
201
-			$_SESSION['st_error'] = $context['scheduled_errors'];
209
+		if (!empty($context['scheduled_errors'])) {
210
+					$_SESSION['st_error'] = $context['scheduled_errors'];
211
+		}
202 212
 
203 213
 		redirectexit('action=admin;area=scheduledtasks;done');
204 214
 	}
@@ -370,8 +380,9 @@  discard block
 block discarded – undo
370 380
 	$context['server_time'] = timeformat(time(), false, 'server');
371 381
 
372 382
 	// Cleaning...
373
-	if (!isset($_GET['tid']))
374
-		fatal_lang_error('no_access', false);
383
+	if (!isset($_GET['tid'])) {
384
+			fatal_lang_error('no_access', false);
385
+	}
375 386
 	$_GET['tid'] = (int) $_GET['tid'];
376 387
 
377 388
 	// Saving?
@@ -387,10 +398,12 @@  discard block
 block discarded – undo
387 398
 		preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches);
388 399
 
389 400
 		// If a half is empty then assume zero offset!
390
-		if (!isset($matches[2]) || $matches[2] > 59)
391
-			$matches[2] = 0;
392
-		if (!isset($matches[1]) || $matches[1] > 23)
393
-			$matches[1] = 0;
401
+		if (!isset($matches[2]) || $matches[2] > 59) {
402
+					$matches[2] = 0;
403
+		}
404
+		if (!isset($matches[1]) || $matches[1] > 23) {
405
+					$matches[1] = 0;
406
+		}
394 407
 
395 408
 		// Now the offset is easy; easy peasy - except we need to offset by a few hours...
396 409
 		$offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z');
@@ -400,8 +413,9 @@  discard block
 block discarded – undo
400 413
 		$unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd';
401 414
 
402 415
 		// Don't allow one minute intervals.
403
-		if ($interval == 1 && $unit == 'm')
404
-			$interval = 2;
416
+		if ($interval == 1 && $unit == 'm') {
417
+					$interval = 2;
418
+		}
405 419
 
406 420
 		// Is it disabled?
407 421
 		$disabled = !isset($_POST['enabled']) ? 1 : 0;
@@ -439,8 +453,9 @@  discard block
 block discarded – undo
439 453
 	);
440 454
 
441 455
 	// Should never, ever, happen!
442
-	if ($smcFunc['db_num_rows']($request) == 0)
443
-		fatal_lang_error('no_access', false);
456
+	if ($smcFunc['db_num_rows']($request) == 0) {
457
+			fatal_lang_error('no_access', false);
458
+	}
444 459
 
445 460
 	while ($row = $smcFunc['db_fetch_assoc']($request))
446 461
 	{
@@ -598,13 +613,14 @@  discard block
 block discarded – undo
598 613
 		)
599 614
 	);
600 615
 	$log_entries = array();
601
-	while ($row = $smcFunc['db_fetch_assoc']($request))
602
-		$log_entries[] = array(
616
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
617
+			$log_entries[] = array(
603 618
 			'id' => $row['id_log'],
604 619
 			'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'],
605 620
 			'time_run' => $row['time_run'],
606 621
 			'time_taken' => $row['time_taken'],
607 622
 		);
623
+	}
608 624
 	$smcFunc['db_free_result']($request);
609 625
 
610 626
 	return $log_entries;
Please login to merge, or discard this patch.
Sources/Subs-Editor.php 2 patches
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	// @todo Tie in with bbc permissions ?
41 41
 	foreach (array('code', 'php', 'nobbc') as $code)
42 42
 	{
43
-		if (strpos($text, '['. $code) !== false)
43
+		if (strpos($text, '[' . $code) !== false)
44 44
 		{
45 45
 			$parts = preg_split('~(\[/' . $code . '\]|\[' . $code . '(?:=[^\]]+)?\])~i', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
46 46
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	// Parse unique ID's and disable javascript into the smileys - using the double space.
78 78
 	$i = 1;
79 79
 	$text = preg_replace_callback('~(?:\s|&nbsp;)?<(img\ssrc="' . preg_quote($modSettings['smileys_url'], '~') . '/[^<>]+?/([^<>]+?)"\s*)[^<>]*?class="smiley">~',
80
-		function ($m) use (&$i)
80
+		function($m) use (&$i)
81 81
 		{
82 82
 			return '<' . stripslashes($m[1]) . 'alt="" title="" onresizestart="return false;" id="smiley_' . $i++ . '_' . $m[2] . '" style="padding: 0 3px 0 3px;">';
83 83
 		}, $text);
@@ -605,10 +605,10 @@  discard block
 block discarded – undo
605 605
 								// Inject closure for this list item first.
606 606
 								// The content of $parts[$i] is left as is!
607 607
 								array_splice($parts, $i + 1, 0, array(
608
-									'',				// $i + 1
609
-									'[/li]' . "\n",	// $i + 2
610
-									'',				// $i + 3
611
-									'',				// $i + 4
608
+									'', // $i + 1
609
+									'[/li]' . "\n", // $i + 2
610
+									'', // $i + 3
611
+									'', // $i + 4
612 612
 								));
613 613
 								$numParts = count($parts) - 1;
614 614
 
@@ -726,167 +726,167 @@  discard block
 block discarded – undo
726 726
 
727 727
 	// The final bits are the easy ones - tags which map to tags which map to tags - etc etc.
728 728
 	$tags = array(
729
-		'~<b(\s(.)*?)*?' . '>~i' => function ()
729
+		'~<b(\s(.)*?)*?' . '>~i' => function()
730 730
 		{
731 731
 			return '[b]';
732 732
 		},
733
-		'~</b>~i' => function ()
733
+		'~</b>~i' => function()
734 734
 		{
735 735
 			return '[/b]';
736 736
 		},
737
-		'~<i(\s(.)*?)*?' . '>~i' => function ()
737
+		'~<i(\s(.)*?)*?' . '>~i' => function()
738 738
 		{
739 739
 			return '[i]';
740 740
 		},
741
-		'~</i>~i' => function ()
741
+		'~</i>~i' => function()
742 742
 		{
743 743
 			return '[/i]';
744 744
 		},
745
-		'~<u(\s(.)*?)*?' . '>~i' => function ()
745
+		'~<u(\s(.)*?)*?' . '>~i' => function()
746 746
 		{
747 747
 			return '[u]';
748 748
 		},
749
-		'~</u>~i' => function ()
749
+		'~</u>~i' => function()
750 750
 		{
751 751
 			return '[/u]';
752 752
 		},
753
-		'~<strong(\s(.)*?)*?' . '>~i' => function ()
753
+		'~<strong(\s(.)*?)*?' . '>~i' => function()
754 754
 		{
755 755
 			return '[b]';
756 756
 		},
757
-		'~</strong>~i' => function ()
757
+		'~</strong>~i' => function()
758 758
 		{
759 759
 			return '[/b]';
760 760
 		},
761
-		'~<em(\s(.)*?)*?' . '>~i' => function ()
761
+		'~<em(\s(.)*?)*?' . '>~i' => function()
762 762
 		{
763 763
 			return '[i]';
764 764
 		},
765
-		'~</em>~i' => function ()
765
+		'~</em>~i' => function()
766 766
 		{
767 767
 			return '[i]';
768 768
 		},
769
-		'~<s(\s(.)*?)*?' . '>~i' => function ()
769
+		'~<s(\s(.)*?)*?' . '>~i' => function()
770 770
 		{
771 771
 			return "[s]";
772 772
 		},
773
-		'~</s>~i' => function ()
773
+		'~</s>~i' => function()
774 774
 		{
775 775
 			return "[/s]";
776 776
 		},
777
-		'~<strike(\s(.)*?)*?' . '>~i' => function ()
777
+		'~<strike(\s(.)*?)*?' . '>~i' => function()
778 778
 		{
779 779
 			return '[s]';
780 780
 		},
781
-		'~</strike>~i' => function ()
781
+		'~</strike>~i' => function()
782 782
 		{
783 783
 			return '[/s]';
784 784
 		},
785
-		'~<del(\s(.)*?)*?' . '>~i' => function ()
785
+		'~<del(\s(.)*?)*?' . '>~i' => function()
786 786
 		{
787 787
 			return '[s]';
788 788
 		},
789
-		'~</del>~i' => function ()
789
+		'~</del>~i' => function()
790 790
 		{
791 791
 			return '[/s]';
792 792
 		},
793
-		'~<center(\s(.)*?)*?' . '>~i' => function ()
793
+		'~<center(\s(.)*?)*?' . '>~i' => function()
794 794
 		{
795 795
 			return '[center]';
796 796
 		},
797
-		'~</center>~i' => function ()
797
+		'~</center>~i' => function()
798 798
 		{
799 799
 			return '[/center]';
800 800
 		},
801
-		'~<pre(\s(.)*?)*?' . '>~i' => function ()
801
+		'~<pre(\s(.)*?)*?' . '>~i' => function()
802 802
 		{
803 803
 			return '[pre]';
804 804
 		},
805
-		'~</pre>~i' => function ()
805
+		'~</pre>~i' => function()
806 806
 		{
807 807
 			return '[/pre]';
808 808
 		},
809
-		'~<sub(\s(.)*?)*?' . '>~i' => function ()
809
+		'~<sub(\s(.)*?)*?' . '>~i' => function()
810 810
 		{
811 811
 			return '[sub]';
812 812
 		},
813
-		'~</sub>~i' => function ()
813
+		'~</sub>~i' => function()
814 814
 		{
815 815
 			return '[/sub]';
816 816
 		},
817
-		'~<sup(\s(.)*?)*?' . '>~i' => function ()
817
+		'~<sup(\s(.)*?)*?' . '>~i' => function()
818 818
 		{
819 819
 			return '[sup]';
820 820
 		},
821
-		'~</sup>~i' => function ()
821
+		'~</sup>~i' => function()
822 822
 		{
823 823
 			return '[/sup]';
824 824
 		},
825
-		'~<tt(\s(.)*?)*?' . '>~i' => function ()
825
+		'~<tt(\s(.)*?)*?' . '>~i' => function()
826 826
 		{
827 827
 			return '[tt]';
828 828
 		},
829
-		'~</tt>~i' => function ()
829
+		'~</tt>~i' => function()
830 830
 		{
831 831
 			return '[/tt]';
832 832
 		},
833
-		'~<table(\s(.)*?)*?' . '>~i' => function ()
833
+		'~<table(\s(.)*?)*?' . '>~i' => function()
834 834
 		{
835 835
 			return '[table]';
836 836
 		},
837
-		'~</table>~i' => function ()
837
+		'~</table>~i' => function()
838 838
 		{
839 839
 			return '[/table]';
840 840
 		},
841
-		'~<tr(\s(.)*?)*?' . '>~i' => function ()
841
+		'~<tr(\s(.)*?)*?' . '>~i' => function()
842 842
 		{
843 843
 			return '[tr]';
844 844
 		},
845
-		'~</tr>~i' => function ()
845
+		'~</tr>~i' => function()
846 846
 		{
847 847
 			return '[/tr]';
848 848
 		},
849
-		'~<(td|th)\s[^<>]*?colspan="?(\d{1,2})"?.*?' . '>~i' => function ($matches)
849
+		'~<(td|th)\s[^<>]*?colspan="?(\d{1,2})"?.*?' . '>~i' => function($matches)
850 850
 		{
851 851
 			return str_repeat('[td][/td]', $matches[2] - 1) . '[td]';
852 852
 		},
853
-		'~<(td|th)(\s(.)*?)*?' . '>~i' => function ()
853
+		'~<(td|th)(\s(.)*?)*?' . '>~i' => function()
854 854
 		{
855 855
 			return '[td]';
856 856
 		},
857
-		'~</(td|th)>~i' => function ()
857
+		'~</(td|th)>~i' => function()
858 858
 		{
859 859
 			return '[/td]';
860 860
 		},
861
-		'~<br(?:\s[^<>]*?)?' . '>~i' => function ()
861
+		'~<br(?:\s[^<>]*?)?' . '>~i' => function()
862 862
 		{
863 863
 			return "\n";
864 864
 		},
865
-		'~<hr[^<>]*>(\n)?~i' => function ($matches)
865
+		'~<hr[^<>]*>(\n)?~i' => function($matches)
866 866
 		{
867
-			return "[hr]\n". $matches[0];
867
+			return "[hr]\n" . $matches[0];
868 868
 		},
869
-		'~(\n)?\\[hr\\]~i' => function ()
869
+		'~(\n)?\\[hr\\]~i' => function()
870 870
 		{
871 871
 			return "\n[hr]";
872 872
 		},
873
-		'~^\n\\[hr\\]~i' => function ()
873
+		'~^\n\\[hr\\]~i' => function()
874 874
 		{
875 875
 			return "[hr]";
876 876
 		},
877
-		'~<blockquote(\s(.)*?)*?' . '>~i' =>  function ()
877
+		'~<blockquote(\s(.)*?)*?' . '>~i' =>  function()
878 878
 		{
879 879
 			return "&lt;blockquote&gt;";
880 880
 		},
881
-		'~</blockquote>~i' => function ()
881
+		'~</blockquote>~i' => function()
882 882
 		{
883 883
 			return "&lt;/blockquote&gt;";
884 884
 		},
885
-		'~<ins(\s(.)*?)*?' . '>~i' => function ()
885
+		'~<ins(\s(.)*?)*?' . '>~i' => function()
886 886
 		{
887 887
 			return "&lt;ins&gt;";
888 888
 		},
889
-		'~</ins>~i' => function ()
889
+		'~</ins>~i' => function()
890 890
 		{
891 891
 			return "&lt;/ins&gt;";
892 892
 		},
@@ -2391,7 +2391,7 @@  discard block
 block discarded – undo
2391 2391
 		array(
2392 2392
 			'group_name' => $smcFunc['db_case_sensitive'] ? 'LOWER(group_name}' : 'group_name',
2393 2393
 			'min_posts' => -1,
2394
-			'invalid_groups' => array(1,3),
2394
+			'invalid_groups' => array(1, 3),
2395 2395
 			'hidden' => 2,
2396 2396
 			'search' => $_REQUEST['search'],
2397 2397
 		)
Please login to merge, or discard this patch.
Braces   +397 added lines, -299 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * !!!Compatibility!!!
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 {
31 32
 	global $modSettings;
32 33
 
33
-	if (!$compat_mode)
34
-		return $text;
34
+	if (!$compat_mode) {
35
+			return $text;
36
+	}
35 37
 
36 38
 	// Turn line breaks back into br's.
37 39
 	$text = strtr($text, array("\r" => '', "\n" => '<br>'));
@@ -48,8 +50,9 @@  discard block
 block discarded – undo
48 50
 			for ($i = 0, $n = count($parts); $i < $n; $i++)
49 51
 			{
50 52
 				// Value of 2 means we're inside the tag.
51
-				if ($i % 4 == 2)
52
-					$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
53
+				if ($i % 4 == 2) {
54
+									$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
55
+				}
53 56
 			}
54 57
 			// Put our humpty dumpty message back together again.
55 58
 			$text = implode('', $parts);
@@ -107,8 +110,9 @@  discard block
 block discarded – undo
107 110
 	$text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text);
108 111
 
109 112
 	// Safari/webkit wraps lines in Wysiwyg in <div>'s.
110
-	if (isBrowser('webkit'))
111
-		$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
113
+	if (isBrowser('webkit')) {
114
+			$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
115
+	}
112 116
 
113 117
 	// If there's a trailing break get rid of it - Firefox tends to add one.
114 118
 	$text = preg_replace('~<br\s?/?' . '>$~i', '', $text);
@@ -123,8 +127,9 @@  discard block
 block discarded – undo
123 127
 		for ($i = 0, $n = count($parts); $i < $n; $i++)
124 128
 		{
125 129
 			// Value of 2 means we're inside the tag.
126
-			if ($i % 4 == 2)
127
-				$parts[$i] = strip_tags($parts[$i]);
130
+			if ($i % 4 == 2) {
131
+							$parts[$i] = strip_tags($parts[$i]);
132
+			}
128 133
 		}
129 134
 
130 135
 		$text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>'));
@@ -150,18 +155,19 @@  discard block
 block discarded – undo
150 155
 			{
151 156
 				$found = array_search($file, $smileysto);
152 157
 				// Note the weirdness here is to stop double spaces between smileys.
153
-				if ($found)
154
-					$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
155
-				else
156
-					$matches[1][$k] = '';
158
+				if ($found) {
159
+									$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
160
+				} else {
161
+									$matches[1][$k] = '';
162
+				}
157 163
 			}
158
-		}
159
-		else
164
+		} else
160 165
 		{
161 166
 			// Load all the smileys.
162 167
 			$names = array();
163
-			foreach ($matches[1] as $file)
164
-				$names[] = $file;
168
+			foreach ($matches[1] as $file) {
169
+							$names[] = $file;
170
+			}
165 171
 			$names = array_unique($names);
166 172
 
167 173
 			if (!empty($names))
@@ -175,13 +181,15 @@  discard block
 block discarded – undo
175 181
 					)
176 182
 				);
177 183
 				$mappings = array();
178
-				while ($row = $smcFunc['db_fetch_assoc']($request))
179
-					$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
184
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+									$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
186
+				}
180 187
 				$smcFunc['db_free_result']($request);
181 188
 
182
-				foreach ($matches[1] as $k => $file)
183
-					if (isset($mappings[$file]))
189
+				foreach ($matches[1] as $k => $file) {
190
+									if (isset($mappings[$file]))
184 191
 						$matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#';
192
+				}
185 193
 			}
186 194
 		}
187 195
 
@@ -193,8 +201,9 @@  discard block
 block discarded – undo
193 201
 	}
194 202
 
195 203
 	// Only try to buy more time if the client didn't quit.
196
-	if (connection_aborted() && $context['server']['is_apache'])
197
-		@apache_reset_timeout();
204
+	if (connection_aborted() && $context['server']['is_apache']) {
205
+			@apache_reset_timeout();
206
+	}
198 207
 
199 208
 	$parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
200 209
 	$replacement = '';
@@ -205,9 +214,9 @@  discard block
 block discarded – undo
205 214
 		if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1)
206 215
 		{
207 216
 			// If it's being closed instantly, we can't deal with it...yet.
208
-			if ($matches[5] === '/')
209
-				continue;
210
-			else
217
+			if ($matches[5] === '/') {
218
+							continue;
219
+			} else
211 220
 			{
212 221
 				// Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.)
213 222
 				$styles = explode(';', strtr($matches[3], array('&quot;' => '')));
@@ -223,8 +232,9 @@  discard block
 block discarded – undo
223 232
 					$clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':'));
224 233
 
225 234
 					// Something like 'font-weight: bold' is expected here.
226
-					if (strpos($clean_type_value_pair, ':') === false)
227
-						continue;
235
+					if (strpos($clean_type_value_pair, ':') === false) {
236
+											continue;
237
+					}
228 238
 
229 239
 					// Capture the elements of a single style item (e.g. 'font-weight' and 'bold').
230 240
 					list ($style_type, $style_value) = explode(':', $type_value_pair);
@@ -246,8 +256,7 @@  discard block
 block discarded – undo
246 256
 							{
247 257
 								$curCloseTags .= '[/u]';
248 258
 								$replacement .= '[u]';
249
-							}
250
-							elseif ($style_value == 'line-through')
259
+							} elseif ($style_value == 'line-through')
251 260
 							{
252 261
 								$curCloseTags .= '[/s]';
253 262
 								$replacement .= '[s]';
@@ -259,13 +268,11 @@  discard block
 block discarded – undo
259 268
 							{
260 269
 								$curCloseTags .= '[/left]';
261 270
 								$replacement .= '[left]';
262
-							}
263
-							elseif ($style_value == 'center')
271
+							} elseif ($style_value == 'center')
264 272
 							{
265 273
 								$curCloseTags .= '[/center]';
266 274
 								$replacement .= '[center]';
267
-							}
268
-							elseif ($style_value == 'right')
275
+							} elseif ($style_value == 'right')
269 276
 							{
270 277
 								$curCloseTags .= '[/right]';
271 278
 								$replacement .= '[right]';
@@ -287,8 +294,9 @@  discard block
 block discarded – undo
287 294
 
288 295
 						case 'font-size':
289 296
 							// Sometimes people put decimals where decimals should not be.
290
-							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1)
291
-								$style_value = $dec_matches[1] . $dec_matches[2];
297
+							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) {
298
+															$style_value = $dec_matches[1] . $dec_matches[2];
299
+							}
292 300
 
293 301
 							$curCloseTags .= '[/size]';
294 302
 							$replacement .= '[size=' . $style_value . ']';
@@ -296,8 +304,9 @@  discard block
 block discarded – undo
296 304
 
297 305
 						case 'font-family':
298 306
 							// Only get the first freaking font if there's a list!
299
-							if (strpos($style_value, ',') !== false)
300
-								$style_value = substr($style_value, 0, strpos($style_value, ','));
307
+							if (strpos($style_value, ',') !== false) {
308
+															$style_value = substr($style_value, 0, strpos($style_value, ','));
309
+							}
301 310
 
302 311
 							$curCloseTags .= '[/font]';
303 312
 							$replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']';
@@ -306,13 +315,15 @@  discard block
 block discarded – undo
306 315
 						// This is a hack for images with dimensions embedded.
307 316
 						case 'width':
308 317
 						case 'height':
309
-							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1)
310
-								$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
318
+							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
319
+															$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
320
+							}
311 321
 						break;
312 322
 
313 323
 						case 'list-style-type':
314
-							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1)
315
-								$extra_attr .= ' listtype="' . $listType[0] . '"';
324
+							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) {
325
+															$extra_attr .= ' listtype="' . $listType[0] . '"';
326
+							}
316 327
 						break;
317 328
 					}
318 329
 				}
@@ -325,18 +336,17 @@  discard block
 block discarded – undo
325 336
 				}
326 337
 
327 338
 				// If there's something that still needs closing, push it to the stack.
328
-				if (!empty($curCloseTags))
329
-					array_push($stack, array(
339
+				if (!empty($curCloseTags)) {
340
+									array_push($stack, array(
330 341
 							'element' => strtolower($curElement),
331 342
 							'closeTags' => $curCloseTags
332 343
 						)
333 344
 					);
334
-				elseif (!empty($extra_attr))
335
-					$replacement .= $precedingStyle . $extra_attr . $afterStyle;
345
+				} elseif (!empty($extra_attr)) {
346
+									$replacement .= $precedingStyle . $extra_attr . $afterStyle;
347
+				}
336 348
 			}
337
-		}
338
-
339
-		elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
349
+		} elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
340 350
 		{
341 351
 			// Is this the element that we've been waiting for to be closed?
342 352
 			if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element'])
@@ -346,28 +356,32 @@  discard block
 block discarded – undo
346 356
 			}
347 357
 
348 358
 			// Must've been something else.
349
-			else
350
-				$replacement .= $part;
359
+			else {
360
+							$replacement .= $part;
361
+			}
351 362
 		}
352 363
 		// In all other cases, just add the part to the replacement.
353
-		else
354
-			$replacement .= $part;
364
+		else {
365
+					$replacement .= $part;
366
+		}
355 367
 	}
356 368
 
357 369
 	// Now put back the replacement in the text.
358 370
 	$text = $replacement;
359 371
 
360 372
 	// We are not finished yet, request more time.
361
-	if (connection_aborted() && $context['server']['is_apache'])
362
-		@apache_reset_timeout();
373
+	if (connection_aborted() && $context['server']['is_apache']) {
374
+			@apache_reset_timeout();
375
+	}
363 376
 
364 377
 	// Let's pull out any legacy alignments.
365 378
 	while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1)
366 379
 	{
367 380
 		// Find the position in the text of this tag over again.
368 381
 		$start_pos = strpos($text, $matches[0]);
369
-		if ($start_pos === false)
370
-			break;
382
+		if ($start_pos === false) {
383
+					break;
384
+		}
371 385
 
372 386
 		// End tag?
373 387
 		if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false)
@@ -382,8 +396,7 @@  discard block
 block discarded – undo
382 396
 
383 397
 			// Put the tags back into the body.
384 398
 			$text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos);
385
-		}
386
-		else
399
+		} else
387 400
 		{
388 401
 			// Just get rid of this evil tag.
389 402
 			$text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0]));
@@ -396,8 +409,9 @@  discard block
 block discarded – undo
396 409
 		// Find the position of this again.
397 410
 		$start_pos = strpos($text, $matches[0]);
398 411
 		$end_pos = false;
399
-		if ($start_pos === false)
400
-			break;
412
+		if ($start_pos === false) {
413
+					break;
414
+		}
401 415
 
402 416
 		// This must have an end tag - and we must find the right one.
403 417
 		$lower_text = strtolower($text);
@@ -430,8 +444,9 @@  discard block
 block discarded – undo
430 444
 				break;
431 445
 			}
432 446
 		}
433
-		if ($end_pos === false)
434
-			break;
447
+		if ($end_pos === false) {
448
+					break;
449
+		}
435 450
 
436 451
 		// Now work out what the attributes are.
437 452
 		$attribs = fetchTagAttributes($matches[1]);
@@ -445,11 +460,11 @@  discard block
 block discarded – undo
445 460
 				$v = (int) trim($v);
446 461
 				$v = empty($v) ? 1 : $v;
447 462
 				$tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]');
463
+			} elseif ($s == 'face') {
464
+							$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
465
+			} elseif ($s == 'color') {
466
+							$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
448 467
 			}
449
-			elseif ($s == 'face')
450
-				$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
451
-			elseif ($s == 'color')
452
-				$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
453 468
 		}
454 469
 
455 470
 		// As before add in our tags.
@@ -457,8 +472,9 @@  discard block
 block discarded – undo
457 472
 		foreach ($tags as $tag)
458 473
 		{
459 474
 			$before .= $tag[0];
460
-			if (isset($tag[1]))
461
-				$after = $tag[1] . $after;
475
+			if (isset($tag[1])) {
476
+							$after = $tag[1] . $after;
477
+			}
462 478
 		}
463 479
 
464 480
 		// Remove the tag so it's never checked again.
@@ -469,8 +485,9 @@  discard block
 block discarded – undo
469 485
 	}
470 486
 
471 487
 	// Almost there, just a little more time.
472
-	if (connection_aborted() && $context['server']['is_apache'])
473
-		@apache_reset_timeout();
488
+	if (connection_aborted() && $context['server']['is_apache']) {
489
+			@apache_reset_timeout();
490
+	}
474 491
 
475 492
 	if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1)
476 493
 	{
@@ -526,12 +543,13 @@  discard block
 block discarded – undo
526 543
 						{
527 544
 							$inList = true;
528 545
 
529
-							if ($tag === 'ol')
530
-								$listType = 'decimal';
531
-							elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1)
532
-								$listType = $listTypeMapping[$match[1]];
533
-							else
534
-								$listType = null;
546
+							if ($tag === 'ol') {
547
+															$listType = 'decimal';
548
+							} elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) {
549
+															$listType = $listTypeMapping[$match[1]];
550
+							} else {
551
+															$listType = null;
552
+							}
535 553
 
536 554
 							$listDepth++;
537 555
 
@@ -595,9 +613,7 @@  discard block
 block discarded – undo
595 613
 							$parts[$i + 1] = '';
596 614
 							$parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]';
597 615
 							$parts[$i + 3] = '';
598
-						}
599
-
600
-						else
616
+						} else
601 617
 						{
602 618
 							// We're in a list item.
603 619
 							if ($listDepth > 0)
@@ -634,9 +650,7 @@  discard block
 block discarded – undo
634 650
 							$parts[$i + 1] = '';
635 651
 							$parts[$i + 2] = '';
636 652
 							$parts[$i + 3] = '';
637
-						}
638
-
639
-						else
653
+						} else
640 654
 						{
641 655
 							// Remove the trailing breaks from the list item.
642 656
 							$parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]);
@@ -674,8 +688,9 @@  discard block
 block discarded – undo
674 688
 			$text .= str_repeat("\t", $listDepth) . '[/list]';
675 689
 		}
676 690
 
677
-		for ($i = $listDepth; $i > 0; $i--)
678
-			$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
691
+		for ($i = $listDepth; $i > 0; $i--) {
692
+					$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
693
+		}
679 694
 
680 695
 	}
681 696
 
@@ -684,8 +699,9 @@  discard block
 block discarded – undo
684 699
 	{
685 700
 		// Find the position of the image.
686 701
 		$start_pos = strpos($text, $matches[0]);
687
-		if ($start_pos === false)
688
-			break;
702
+		if ($start_pos === false) {
703
+					break;
704
+		}
689 705
 		$end_pos = $start_pos + strlen($matches[0]);
690 706
 
691 707
 		$params = '';
@@ -695,12 +711,13 @@  discard block
 block discarded – undo
695 711
 		$attrs = fetchTagAttributes($matches[1]);
696 712
 		foreach ($attrs as $attrib => $value)
697 713
 		{
698
-			if (in_array($attrib, array('width', 'height')))
699
-				$params .= ' ' . $attrib . '=' . (int) $value;
700
-			elseif ($attrib == 'alt' && trim($value) != '')
701
-				$params .= ' alt=' . trim($value);
702
-			elseif ($attrib == 'src')
703
-				$src = trim($value);
714
+			if (in_array($attrib, array('width', 'height'))) {
715
+							$params .= ' ' . $attrib . '=' . (int) $value;
716
+			} elseif ($attrib == 'alt' && trim($value) != '') {
717
+							$params .= ' alt=' . trim($value);
718
+			} elseif ($attrib == 'src') {
719
+							$src = trim($value);
720
+			}
704 721
 		}
705 722
 
706 723
 		$tag = '';
@@ -711,10 +728,11 @@  discard block
 block discarded – undo
711 728
 			{
712 729
 				$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
713 730
 
714
-				if (substr($src, 0, 1) === '/')
715
-					$src = $baseURL . $src;
716
-				else
717
-					$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
731
+				if (substr($src, 0, 1) === '/') {
732
+									$src = $baseURL . $src;
733
+				} else {
734
+									$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
735
+				}
718 736
 			}
719 737
 
720 738
 			$tag = '[img' . $params . ']' . $src . '[/img]';
@@ -892,20 +910,23 @@  discard block
 block discarded – undo
892 910
 		},
893 911
 	);
894 912
 
895
-	foreach ($tags as $tag => $replace)
896
-		$text = preg_replace_callback($tag, $replace, $text);
913
+	foreach ($tags as $tag => $replace) {
914
+			$text = preg_replace_callback($tag, $replace, $text);
915
+	}
897 916
 
898 917
 	// Please give us just a little more time.
899
-	if (connection_aborted() && $context['server']['is_apache'])
900
-		@apache_reset_timeout();
918
+	if (connection_aborted() && $context['server']['is_apache']) {
919
+			@apache_reset_timeout();
920
+	}
901 921
 
902 922
 	// What about URL's - the pain in the ass of the tag world.
903 923
 	while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1)
904 924
 	{
905 925
 		// Find the position of the URL.
906 926
 		$start_pos = strpos($text, $matches[0]);
907
-		if ($start_pos === false)
908
-			break;
927
+		if ($start_pos === false) {
928
+					break;
929
+		}
909 930
 		$end_pos = $start_pos + strlen($matches[0]);
910 931
 
911 932
 		$tag_type = 'url';
@@ -919,8 +940,9 @@  discard block
 block discarded – undo
919 940
 				$href = trim($value);
920 941
 
921 942
 				// Are we dealing with an FTP link?
922
-				if (preg_match('~^ftps?://~', $href) === 1)
923
-					$tag_type = 'ftp';
943
+				if (preg_match('~^ftps?://~', $href) === 1) {
944
+									$tag_type = 'ftp';
945
+				}
924 946
 
925 947
 				// Or is this a link to an email address?
926 948
 				elseif (substr($href, 0, 7) == 'mailto:')
@@ -934,28 +956,31 @@  discard block
 block discarded – undo
934 956
 				{
935 957
 					$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
936 958
 
937
-					if (substr($href, 0, 1) === '/')
938
-						$href = $baseURL . $href;
939
-					else
940
-						$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
959
+					if (substr($href, 0, 1) === '/') {
960
+											$href = $baseURL . $href;
961
+					} else {
962
+											$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
963
+					}
941 964
 				}
942 965
 			}
943 966
 
944 967
 			// External URL?
945 968
 			if ($attrib == 'target' && $tag_type == 'url')
946 969
 			{
947
-				if (trim($value) == '_blank')
948
-					$tag_type == 'iurl';
970
+				if (trim($value) == '_blank') {
971
+									$tag_type == 'iurl';
972
+				}
949 973
 			}
950 974
 		}
951 975
 
952 976
 		$tag = '';
953 977
 		if ($href != '')
954 978
 		{
955
-			if ($matches[2] == $href)
956
-				$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
957
-			else
958
-				$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
979
+			if ($matches[2] == $href) {
980
+							$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
981
+			} else {
982
+							$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
983
+			}
959 984
 		}
960 985
 
961 986
 		// Replace the tag
@@ -995,17 +1020,18 @@  discard block
 block discarded – undo
995 1020
 		// We're either moving from the key to the attribute or we're in a string and this is fine.
996 1021
 		if ($text[$i] == '=')
997 1022
 		{
998
-			if ($tag_state == 0)
999
-				$tag_state = 1;
1000
-			elseif ($tag_state == 2)
1001
-				$value .= '=';
1023
+			if ($tag_state == 0) {
1024
+							$tag_state = 1;
1025
+			} elseif ($tag_state == 2) {
1026
+							$value .= '=';
1027
+			}
1002 1028
 		}
1003 1029
 		// A space is either moving from an attribute back to a potential key or in a string is fine.
1004 1030
 		elseif ($text[$i] == ' ')
1005 1031
 		{
1006
-			if ($tag_state == 2)
1007
-				$value .= ' ';
1008
-			elseif ($tag_state == 1)
1032
+			if ($tag_state == 2) {
1033
+							$value .= ' ';
1034
+			} elseif ($tag_state == 1)
1009 1035
 			{
1010 1036
 				$attribs[$key] = $value;
1011 1037
 				$key = $value = '';
@@ -1016,24 +1042,27 @@  discard block
 block discarded – undo
1016 1042
 		elseif ($text[$i] == '"')
1017 1043
 		{
1018 1044
 			// Must be either going into or out of a string.
1019
-			if ($tag_state == 1)
1020
-				$tag_state = 2;
1021
-			else
1022
-				$tag_state = 1;
1045
+			if ($tag_state == 1) {
1046
+							$tag_state = 2;
1047
+			} else {
1048
+							$tag_state = 1;
1049
+			}
1023 1050
 		}
1024 1051
 		// Otherwise it's fine.
1025 1052
 		else
1026 1053
 		{
1027
-			if ($tag_state == 0)
1028
-				$key .= $text[$i];
1029
-			else
1030
-				$value .= $text[$i];
1054
+			if ($tag_state == 0) {
1055
+							$key .= $text[$i];
1056
+			} else {
1057
+							$value .= $text[$i];
1058
+			}
1031 1059
 		}
1032 1060
 	}
1033 1061
 
1034 1062
 	// Anything left?
1035
-	if ($key != '' && $value != '')
1036
-		$attribs[$key] = $value;
1063
+	if ($key != '' && $value != '') {
1064
+			$attribs[$key] = $value;
1065
+	}
1037 1066
 
1038 1067
 	return $attribs;
1039 1068
 }
@@ -1049,8 +1078,9 @@  discard block
 block discarded – undo
1049 1078
 	global $modSettings;
1050 1079
 
1051 1080
 	// Don't care about the texts that are too short.
1052
-	if (strlen($text) < 3)
1053
-		return $text;
1081
+	if (strlen($text) < 3) {
1082
+			return $text;
1083
+	}
1054 1084
 
1055 1085
 	// We are going to cycle through the BBC and keep track of tags as they arise - in order. If get to a block level tag we're going to make sure it's not in a non-block level tag!
1056 1086
 	// This will keep the order of tags that are open.
@@ -1063,8 +1093,9 @@  discard block
 block discarded – undo
1063 1093
 	$disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC'])));
1064 1094
 
1065 1095
 	// Add flash if it's disabled as embedded tag.
1066
-	if (empty($modSettings['enableEmbeddedFlash']))
1067
-		$disabled['flash'] = true;
1096
+	if (empty($modSettings['enableEmbeddedFlash'])) {
1097
+			$disabled['flash'] = true;
1098
+	}
1068 1099
 
1069 1100
 	// Get a list of all the tags that are not disabled.
1070 1101
 	$all_tags = parse_bbc(false);
@@ -1072,10 +1103,12 @@  discard block
 block discarded – undo
1072 1103
 	$self_closing_tags = array();
1073 1104
 	foreach ($all_tags as $tag)
1074 1105
 	{
1075
-		if (!isset($disabled[$tag['tag']]))
1076
-			$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1077
-		if (isset($tag['type']) && $tag['type'] == 'closed')
1078
-			$self_closing_tags[] = $tag['tag'];
1106
+		if (!isset($disabled[$tag['tag']])) {
1107
+					$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1108
+		}
1109
+		if (isset($tag['type']) && $tag['type'] == 'closed') {
1110
+					$self_closing_tags[] = $tag['tag'];
1111
+		}
1079 1112
 	}
1080 1113
 
1081 1114
 	// Don't worry if we're in a code/nobbc.
@@ -1105,16 +1138,19 @@  discard block
 block discarded – undo
1105 1138
 				$tagName = substr($match, $isClosingTag ? 2 : 1, -1);
1106 1139
 
1107 1140
 				// We're closing the exact same tag that we opened.
1108
-				if ($isClosingTag && $insideTag === $tagName)
1109
-					$insideTag = null;
1141
+				if ($isClosingTag && $insideTag === $tagName) {
1142
+									$insideTag = null;
1143
+				}
1110 1144
 
1111 1145
 				// We're opening a tag and we're not yet inside one either
1112
-				elseif (!$isClosingTag && $insideTag === null)
1113
-					$insideTag = $tagName;
1146
+				elseif (!$isClosingTag && $insideTag === null) {
1147
+									$insideTag = $tagName;
1148
+				}
1114 1149
 
1115 1150
 				// In all other cases, this tag must be invalid
1116
-				else
1117
-					unset($matches[$i]);
1151
+				else {
1152
+									unset($matches[$i]);
1153
+				}
1118 1154
 			}
1119 1155
 
1120 1156
 			// The next one is gonna be the other one.
@@ -1122,8 +1158,9 @@  discard block
 block discarded – undo
1122 1158
 		}
1123 1159
 
1124 1160
 		// We're still inside a tag and had no chance for closure?
1125
-		if ($insideTag !== null)
1126
-			$matches[] = '[/' . $insideTag . ']';
1161
+		if ($insideTag !== null) {
1162
+					$matches[] = '[/' . $insideTag . ']';
1163
+		}
1127 1164
 
1128 1165
 		// And a complete text string again.
1129 1166
 		$text = implode('', $matches);
@@ -1132,8 +1169,9 @@  discard block
 block discarded – undo
1132 1169
 	// Quickly remove any tags which are back to back.
1133 1170
 	$backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~';
1134 1171
 	$lastlen = 0;
1135
-	while (strlen($text) !== $lastlen)
1136
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1172
+	while (strlen($text) !== $lastlen) {
1173
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1174
+	}
1137 1175
 
1138 1176
 	// Need to sort the tags my name length.
1139 1177
 	uksort($valid_tags, 'sort_array_length');
@@ -1177,8 +1215,9 @@  discard block
 block discarded – undo
1177 1215
 			$isCompetingTag = in_array($tag, $competing_tags);
1178 1216
 
1179 1217
 			// Check if this might be one of those cleaned out tags.
1180
-			if ($tag === '')
1181
-				continue;
1218
+			if ($tag === '') {
1219
+							continue;
1220
+			}
1182 1221
 
1183 1222
 			// Special case: inside [code] blocks any code is left untouched.
1184 1223
 			elseif ($tag === 'code')
@@ -1189,8 +1228,9 @@  discard block
 block discarded – undo
1189 1228
 					$inCode = false;
1190 1229
 
1191 1230
 					// Reopen tags that were closed before the code block.
1192
-					if (!empty($inlineElements))
1193
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1231
+					if (!empty($inlineElements)) {
1232
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1233
+					}
1194 1234
 				}
1195 1235
 
1196 1236
 				// We're outside a coding and nobbc block and opening it.
@@ -1219,8 +1259,9 @@  discard block
 block discarded – undo
1219 1259
 					$inNoBbc = false;
1220 1260
 
1221 1261
 					// Some inline elements might've been closed that need reopening.
1222
-					if (!empty($inlineElements))
1223
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1262
+					if (!empty($inlineElements)) {
1263
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1264
+					}
1224 1265
 				}
1225 1266
 
1226 1267
 				// We're outside a nobbc and coding block and opening it.
@@ -1240,8 +1281,9 @@  discard block
 block discarded – undo
1240 1281
 			}
1241 1282
 
1242 1283
 			// So, we're inside one of the special blocks: ignore any tag.
1243
-			elseif ($inCode || $inNoBbc)
1244
-				continue;
1284
+			elseif ($inCode || $inNoBbc) {
1285
+							continue;
1286
+			}
1245 1287
 
1246 1288
 			// We're dealing with an opening tag.
1247 1289
 			if ($isOpeningTag)
@@ -1282,8 +1324,9 @@  discard block
 block discarded – undo
1282 1324
 							if ($parts[$j + 3] === $tag)
1283 1325
 							{
1284 1326
 								// If it's an opening tag, increase the level.
1285
-								if ($parts[$j + 2] === '')
1286
-									$curLevel++;
1327
+								if ($parts[$j + 2] === '') {
1328
+																	$curLevel++;
1329
+								}
1287 1330
 
1288 1331
 								// A closing tag, decrease the level.
1289 1332
 								else
@@ -1306,13 +1349,15 @@  discard block
 block discarded – undo
1306 1349
 					{
1307 1350
 						if ($isCompetingTag)
1308 1351
 						{
1309
-							if (!isset($competingElements[$tag]))
1310
-								$competingElements[$tag] = array();
1352
+							if (!isset($competingElements[$tag])) {
1353
+															$competingElements[$tag] = array();
1354
+							}
1311 1355
 
1312 1356
 							$competingElements[$tag][] = $parts[$i + 4];
1313 1357
 
1314
-							if (count($competingElements[$tag]) > 1)
1315
-								$parts[$i] .= '[/' . $tag . ']';
1358
+							if (count($competingElements[$tag]) > 1) {
1359
+															$parts[$i] .= '[/' . $tag . ']';
1360
+							}
1316 1361
 						}
1317 1362
 
1318 1363
 						$inlineElements[$elementContent] = $tag;
@@ -1333,15 +1378,17 @@  discard block
 block discarded – undo
1333 1378
 						$addClosingTags = array();
1334 1379
 						while ($element = array_pop($blockElements))
1335 1380
 						{
1336
-							if ($element === $tag)
1337
-								break;
1381
+							if ($element === $tag) {
1382
+															break;
1383
+							}
1338 1384
 
1339 1385
 							// Still a block tag was open not equal to this tag.
1340 1386
 							$addClosingTags[] = $element['type'];
1341 1387
 						}
1342 1388
 
1343
-						if (!empty($addClosingTags))
1344
-							$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1389
+						if (!empty($addClosingTags)) {
1390
+													$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1391
+						}
1345 1392
 
1346 1393
 						// Apparently the closing tag was not found on the stack.
1347 1394
 						if (!is_string($element) || $element !== $tag)
@@ -1351,8 +1398,7 @@  discard block
 block discarded – undo
1351 1398
 							$parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1352 1399
 							continue;
1353 1400
 						}
1354
-					}
1355
-					else
1401
+					} else
1356 1402
 					{
1357 1403
 						// Get rid of this closing tag!
1358 1404
 						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
@@ -1381,53 +1427,62 @@  discard block
 block discarded – undo
1381 1427
 							unset($inlineElements[$tagContentToBeClosed]);
1382 1428
 
1383 1429
 							// Was this the tag we were looking for?
1384
-							if ($tagToBeClosed === $tag)
1385
-								break;
1430
+							if ($tagToBeClosed === $tag) {
1431
+															break;
1432
+							}
1386 1433
 
1387 1434
 							// Nope, close it and look further!
1388
-							else
1389
-								$parts[$i] .= '[/' . $tagToBeClosed . ']';
1435
+							else {
1436
+															$parts[$i] .= '[/' . $tagToBeClosed . ']';
1437
+							}
1390 1438
 						}
1391 1439
 
1392 1440
 						if ($isCompetingTag && !empty($competingElements[$tag]))
1393 1441
 						{
1394 1442
 							array_pop($competingElements[$tag]);
1395 1443
 
1396
-							if (count($competingElements[$tag]) > 0)
1397
-								$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1444
+							if (count($competingElements[$tag]) > 0) {
1445
+															$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1446
+							}
1398 1447
 						}
1399 1448
 					}
1400 1449
 
1401 1450
 					// Unexpected closing tag, ex-ter-mi-nate.
1402
-					else
1403
-						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1451
+					else {
1452
+											$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1453
+					}
1404 1454
 				}
1405 1455
 			}
1406 1456
 		}
1407 1457
 
1408 1458
 		// Close the code tags.
1409
-		if ($inCode)
1410
-			$parts[$i] .= '[/code]';
1459
+		if ($inCode) {
1460
+					$parts[$i] .= '[/code]';
1461
+		}
1411 1462
 
1412 1463
 		// The same for nobbc tags.
1413
-		elseif ($inNoBbc)
1414
-			$parts[$i] .= '[/nobbc]';
1464
+		elseif ($inNoBbc) {
1465
+					$parts[$i] .= '[/nobbc]';
1466
+		}
1415 1467
 
1416 1468
 		// Still inline tags left unclosed? Close them now, better late than never.
1417
-		elseif (!empty($inlineElements))
1418
-			$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1469
+		elseif (!empty($inlineElements)) {
1470
+					$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1471
+		}
1419 1472
 
1420 1473
 		// Now close the block elements.
1421
-		if (!empty($blockElements))
1422
-			$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1474
+		if (!empty($blockElements)) {
1475
+					$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1476
+		}
1423 1477
 
1424 1478
 		$text = implode('', $parts);
1425 1479
 	}
1426 1480
 
1427 1481
 	// Final clean up of back to back tags.
1428 1482
 	$lastlen = 0;
1429
-	while (strlen($text) !== $lastlen)
1430
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1483
+	while (strlen($text) !== $lastlen) {
1484
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1485
+	}
1431 1486
 
1432 1487
 	return $text;
1433 1488
 }
@@ -1456,22 +1511,25 @@  discard block
 block discarded – undo
1456 1511
 	$context['template_layers'] = array();
1457 1512
 	// Lets make sure we aren't going to output anything nasty.
1458 1513
 	@ob_end_clean();
1459
-	if (!empty($modSettings['enableCompressedOutput']))
1460
-		@ob_start('ob_gzhandler');
1461
-	else
1462
-		@ob_start();
1514
+	if (!empty($modSettings['enableCompressedOutput'])) {
1515
+			@ob_start('ob_gzhandler');
1516
+	} else {
1517
+			@ob_start();
1518
+	}
1463 1519
 
1464 1520
 	// If we don't have any locale better avoid broken js
1465
-	if (empty($txt['lang_locale']))
1466
-		die();
1521
+	if (empty($txt['lang_locale'])) {
1522
+			die();
1523
+	}
1467 1524
 
1468 1525
 	$file_data = '(function ($) {
1469 1526
 	\'use strict\';
1470 1527
 
1471 1528
 	$.sceditor.locale[' . javaScriptEscape($txt['lang_locale']) . '] = {';
1472
-	foreach ($editortxt as $key => $val)
1473
-		$file_data .= '
1529
+	foreach ($editortxt as $key => $val) {
1530
+			$file_data .= '
1474 1531
 		' . javaScriptEscape($key) . ': ' . javaScriptEscape($val) . ',';
1532
+	}
1475 1533
 
1476 1534
 	$file_data .= '
1477 1535
 		dateFormat: "day.month.year"
@@ -1539,8 +1597,9 @@  discard block
 block discarded – undo
1539 1597
 				)
1540 1598
 			);
1541 1599
 			$icon_data = array();
1542
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1543
-				$icon_data[] = $row;
1600
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1601
+							$icon_data[] = $row;
1602
+			}
1544 1603
 			$smcFunc['db_free_result']($request);
1545 1604
 
1546 1605
 			$icons = array();
@@ -1555,9 +1614,9 @@  discard block
 block discarded – undo
1555 1614
 			}
1556 1615
 
1557 1616
 			cache_put_data('posting_icons-' . $board_id, $icons, 480);
1617
+		} else {
1618
+					$icons = $temp;
1558 1619
 		}
1559
-		else
1560
-			$icons = $temp;
1561 1620
 	}
1562 1621
 	call_integration_hook('integrate_load_message_icons', array(&$icons));
1563 1622
 
@@ -1598,8 +1657,9 @@  discard block
 block discarded – undo
1598 1657
 	{
1599 1658
 		// Some general stuff.
1600 1659
 		$settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
1601
-		if (!empty($context['drafts_autosave']))
1602
-			$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1660
+		if (!empty($context['drafts_autosave'])) {
1661
+					$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1662
+		}
1603 1663
 
1604 1664
 		// This really has some WYSIWYG stuff.
1605 1665
 		loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor');
@@ -1615,8 +1675,9 @@  discard block
 block discarded – undo
1615 1675
 		var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\';
1616 1676
 		var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';');
1617 1677
 		// editor language file
1618
-		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US')
1619
-			loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1678
+		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') {
1679
+					loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1680
+		}
1620 1681
 
1621 1682
 		$context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (isBrowser('is_firefox') ? '_firefox' : '')];
1622 1683
 		$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
@@ -1625,11 +1686,12 @@  discard block
 block discarded – undo
1625 1686
 			loadJavaScriptFile('spellcheck.js', array(), 'smf_spellcheck');
1626 1687
 
1627 1688
 			// Some hidden information is needed in order to make the spell checking work.
1628
-			if (!isset($_REQUEST['xml']))
1629
-				$context['insert_after_template'] .= '
1689
+			if (!isset($_REQUEST['xml'])) {
1690
+							$context['insert_after_template'] .= '
1630 1691
 		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
1631 1692
 			<input type="hidden" name="spellstring" value="">
1632 1693
 		</form>';
1694
+			}
1633 1695
 		}
1634 1696
 	}
1635 1697
 
@@ -1786,10 +1848,12 @@  discard block
 block discarded – undo
1786 1848
 
1787 1849
 		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
1788 1850
 		$disabled_tags = array();
1789
-		if (!empty($modSettings['disabledBBC']))
1790
-			$disabled_tags = explode(',', $modSettings['disabledBBC']);
1791
-		if (empty($modSettings['enableEmbeddedFlash']))
1792
-			$disabled_tags[] = 'flash';
1851
+		if (!empty($modSettings['disabledBBC'])) {
1852
+					$disabled_tags = explode(',', $modSettings['disabledBBC']);
1853
+		}
1854
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1855
+					$disabled_tags[] = 'flash';
1856
+		}
1793 1857
 
1794 1858
 		foreach ($disabled_tags as $tag)
1795 1859
 		{
@@ -1799,9 +1863,10 @@  discard block
 block discarded – undo
1799 1863
 				$context['disabled_tags']['orderedlist'] = true;
1800 1864
 			}
1801 1865
 
1802
-			foreach ($editor_tag_map as $thisTag => $tagNameBBC)
1803
-				if ($tag === $thisTag)
1866
+			foreach ($editor_tag_map as $thisTag => $tagNameBBC) {
1867
+							if ($tag === $thisTag)
1804 1868
 					$context['disabled_tags'][$tagNameBBC] = true;
1869
+			}
1805 1870
 
1806 1871
 			$context['disabled_tags'][trim($tag)] = true;
1807 1872
 		}
@@ -1811,19 +1876,21 @@  discard block
 block discarded – undo
1811 1876
 		$context['bbc_toolbar'] = array();
1812 1877
 		foreach ($context['bbc_tags'] as $row => $tagRow)
1813 1878
 		{
1814
-			if (!isset($context['bbc_toolbar'][$row]))
1815
-				$context['bbc_toolbar'][$row] = array();
1879
+			if (!isset($context['bbc_toolbar'][$row])) {
1880
+							$context['bbc_toolbar'][$row] = array();
1881
+			}
1816 1882
 			$tagsRow = array();
1817 1883
 			foreach ($tagRow as $tag)
1818 1884
 			{
1819 1885
 				if ((!empty($tag['code'])) && empty($context['disabled_tags'][$tag['code']]))
1820 1886
 				{
1821 1887
 					$tagsRow[] = $tag['code'];
1822
-					if (isset($tag['image']))
1823
-						$bbcodes_styles .= '
1888
+					if (isset($tag['image'])) {
1889
+											$bbcodes_styles .= '
1824 1890
 			.sceditor-button-' . $tag['code'] . ' div {
1825 1891
 				background: url(\'' . $settings['default_theme_url'] . '/images/bbc/' . $tag['image'] . '.png\');
1826 1892
 			}';
1893
+					}
1827 1894
 					if (isset($tag['before']))
1828 1895
 					{
1829 1896
 						$context['bbcodes_handlers'] .= '
@@ -1837,8 +1904,7 @@  discard block
 block discarded – undo
1837 1904
 				});';
1838 1905
 					}
1839 1906
 
1840
-				}
1841
-				else
1907
+				} else
1842 1908
 				{
1843 1909
 					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1844 1910
 					$tagsRow = array();
@@ -1849,14 +1915,16 @@  discard block
 block discarded – undo
1849 1915
 			{
1850 1916
 				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1851 1917
 				$tagsRow = array();
1852
-				if (!isset($context['disabled_tags']['font']))
1853
-					$tagsRow[] = 'font';
1854
-				if (!isset($context['disabled_tags']['size']))
1855
-					$tagsRow[] = 'size';
1856
-				if (!isset($context['disabled_tags']['color']))
1857
-					$tagsRow[] = 'color';
1858
-			}
1859
-			elseif ($row == 1 && empty($modSettings['disable_wysiwyg']))
1918
+				if (!isset($context['disabled_tags']['font'])) {
1919
+									$tagsRow[] = 'font';
1920
+				}
1921
+				if (!isset($context['disabled_tags']['size'])) {
1922
+									$tagsRow[] = 'size';
1923
+				}
1924
+				if (!isset($context['disabled_tags']['color'])) {
1925
+									$tagsRow[] = 'color';
1926
+				}
1927
+			} elseif ($row == 1 && empty($modSettings['disable_wysiwyg']))
1860 1928
 			{
1861 1929
 				$tmp = array();
1862 1930
 				$tagsRow[] = 'removeformat';
@@ -1867,13 +1935,15 @@  discard block
 block discarded – undo
1867 1935
 				}
1868 1936
 			}
1869 1937
 
1870
-			if (!empty($tagsRow))
1871
-				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1938
+			if (!empty($tagsRow)) {
1939
+							$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1940
+			}
1872 1941
 		}
1873
-		if (!empty($bbcodes_styles))
1874
-			$context['html_headers'] .= '
1942
+		if (!empty($bbcodes_styles)) {
1943
+					$context['html_headers'] .= '
1875 1944
 		<style>' . $bbcodes_styles . '
1876 1945
 		</style>';
1946
+		}
1877 1947
 	}
1878 1948
 
1879 1949
 	// Initialize smiley array... if not loaded before.
@@ -1885,8 +1955,8 @@  discard block
 block discarded – undo
1885 1955
 		);
1886 1956
 
1887 1957
 		// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
1888
-		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none')
1889
-			$context['smileys']['postform'][] = array(
1958
+		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
1959
+					$context['smileys']['postform'][] = array(
1890 1960
 				'smileys' => array(
1891 1961
 					array(
1892 1962
 						'code' => ':)',
@@ -1972,7 +2042,7 @@  discard block
 block discarded – undo
1972 2042
 				),
1973 2043
 				'isLast' => true,
1974 2044
 			);
1975
-		elseif ($user_info['smiley_set'] != 'none')
2045
+		} elseif ($user_info['smiley_set'] != 'none')
1976 2046
 		{
1977 2047
 			if (($temp = cache_get_data('posting_smileys', 480)) == null)
1978 2048
 			{
@@ -1995,17 +2065,19 @@  discard block
 block discarded – undo
1995 2065
 
1996 2066
 				foreach ($context['smileys'] as $section => $smileyRows)
1997 2067
 				{
1998
-					foreach ($smileyRows as $rowIndex => $smileys)
1999
-						$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2068
+					foreach ($smileyRows as $rowIndex => $smileys) {
2069
+											$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2070
+					}
2000 2071
 
2001
-					if (!empty($smileyRows))
2002
-						$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2072
+					if (!empty($smileyRows)) {
2073
+											$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2074
+					}
2003 2075
 				}
2004 2076
 
2005 2077
 				cache_put_data('posting_smileys', $context['smileys'], 480);
2078
+			} else {
2079
+							$context['smileys'] = $temp;
2006 2080
 			}
2007
-			else
2008
-				$context['smileys'] = $temp;
2009 2081
 		}
2010 2082
 	}
2011 2083
 
@@ -2031,8 +2103,9 @@  discard block
 block discarded – undo
2031 2103
 		loadTemplate('GenericControls');
2032 2104
 
2033 2105
 		// Some javascript ma'am?
2034
-		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])))
2035
-			loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2106
+		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) {
2107
+					loadJavaScriptFile('captcha.js', array(), 'smf_captcha');
2108
+		}
2036 2109
 
2037 2110
 		$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
2038 2111
 
@@ -2045,8 +2118,8 @@  discard block
 block discarded – undo
2045 2118
 	$isNew = !isset($context['controls']['verification'][$verificationOptions['id']]);
2046 2119
 
2047 2120
 	// Log this into our collection.
2048
-	if ($isNew)
2049
-		$context['controls']['verification'][$verificationOptions['id']] = array(
2121
+	if ($isNew) {
2122
+			$context['controls']['verification'][$verificationOptions['id']] = array(
2050 2123
 			'id' => $verificationOptions['id'],
2051 2124
 			'empty_field' => empty($verificationOptions['no_empty_field']),
2052 2125
 			'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])),
@@ -2056,20 +2129,23 @@  discard block
 block discarded – undo
2056 2129
 			'text_value' => '',
2057 2130
 			'questions' => array(),
2058 2131
 		);
2132
+	}
2059 2133
 	$thisVerification = &$context['controls']['verification'][$verificationOptions['id']];
2060 2134
 
2061 2135
 	// Add javascript for the object.
2062
-	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual'])
2063
-		$context['insert_after_template'] .= '
2136
+	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) {
2137
+			$context['insert_after_template'] .= '
2064 2138
 			<script>
2065 2139
 				var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . ');
2066 2140
 			</script>';
2141
+	}
2067 2142
 
2068 2143
 	// Is there actually going to be anything?
2069
-	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']))
2070
-		return false;
2071
-	elseif (!$isNew && !$do_test)
2072
-		return true;
2144
+	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions'])) {
2145
+			return false;
2146
+	} elseif (!$isNew && !$do_test) {
2147
+			return true;
2148
+	}
2073 2149
 
2074 2150
 	// If we want questions do we have a cache of all the IDs?
2075 2151
 	if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache']))
@@ -2092,8 +2168,9 @@  discard block
 block discarded – undo
2092 2168
 				unset ($row['id_question']);
2093 2169
 				// Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh?
2094 2170
 				$row['answers'] = smf_json_decode($row['answers'], true);
2095
-				foreach ($row['answers'] as $k => $v)
2096
-					$row['answers'][$k] = $smcFunc['strtolower']($v);
2171
+				foreach ($row['answers'] as $k => $v) {
2172
+									$row['answers'][$k] = $smcFunc['strtolower']($v);
2173
+				}
2097 2174
 
2098 2175
 				$modSettings['question_id_cache']['questions'][$id_question] = $row;
2099 2176
 				$modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question;
@@ -2104,46 +2181,55 @@  discard block
 block discarded – undo
2104 2181
 		}
2105 2182
 	}
2106 2183
 
2107
-	if (!isset($_SESSION[$verificationOptions['id'] . '_vv']))
2108
-		$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2184
+	if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) {
2185
+			$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2186
+	}
2109 2187
 
2110 2188
 	// Do we need to refresh the verification?
2111
-	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh']))
2112
-		$force_refresh = true;
2113
-	else
2114
-		$force_refresh = false;
2189
+	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) {
2190
+			$force_refresh = true;
2191
+	} else {
2192
+			$force_refresh = false;
2193
+	}
2115 2194
 
2116 2195
 	// This can also force a fresh, although unlikely.
2117
-	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q'])))
2118
-		$force_refresh = true;
2196
+	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) {
2197
+			$force_refresh = true;
2198
+	}
2119 2199
 
2120 2200
 	$verification_errors = array();
2121 2201
 	// Start with any testing.
2122 2202
 	if ($do_test)
2123 2203
 	{
2124 2204
 		// This cannot happen!
2125
-		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count']))
2126
-			fatal_lang_error('no_access', false);
2205
+		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) {
2206
+					fatal_lang_error('no_access', false);
2207
+		}
2127 2208
 		// ... nor this!
2128
-		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'])))
2129
-			fatal_lang_error('no_access', false);
2209
+		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) {
2210
+					fatal_lang_error('no_access', false);
2211
+		}
2130 2212
 		// Hmm, it's requested but not actually declared. This shouldn't happen.
2131
-		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2132
-			fatal_lang_error('no_access', false);
2213
+		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) {
2214
+					fatal_lang_error('no_access', false);
2215
+		}
2133 2216
 		// While we're here, did the user do something bad?
2134
-		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']]))
2135
-			$verification_errors[] = 'wrong_verification_answer';
2217
+		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) {
2218
+					$verification_errors[] = 'wrong_verification_answer';
2219
+		}
2136 2220
 
2137
-		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code']))
2138
-			$verification_errors[] = 'wrong_verification_code';
2221
+		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) {
2222
+					$verification_errors[] = 'wrong_verification_code';
2223
+		}
2139 2224
 		if ($thisVerification['number_questions'])
2140 2225
 		{
2141 2226
 			$incorrectQuestions = array();
2142 2227
 			foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q)
2143 2228
 			{
2144 2229
 				// We don't have this question any more, thus no answers.
2145
-				if (!isset($modSettings['question_id_cache']['questions'][$q]))
2146
-					continue;
2230
+				if (!isset($modSettings['question_id_cache']['questions'][$q])) {
2231
+									continue;
2232
+				}
2147 2233
 				// This is quite complex. We have our question but it might have multiple answers.
2148 2234
 				// First, did they actually answer this question?
2149 2235
 				if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '')
@@ -2155,24 +2241,28 @@  discard block
 block discarded – undo
2155 2241
 				else
2156 2242
 				{
2157 2243
 					$given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q])));
2158
-					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers']))
2159
-						$incorrectQuestions[] = $q;
2244
+					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) {
2245
+											$incorrectQuestions[] = $q;
2246
+					}
2160 2247
 				}
2161 2248
 			}
2162 2249
 
2163
-			if (!empty($incorrectQuestions))
2164
-				$verification_errors[] = 'wrong_verification_answer';
2250
+			if (!empty($incorrectQuestions)) {
2251
+							$verification_errors[] = 'wrong_verification_answer';
2252
+			}
2165 2253
 		}
2166 2254
 	}
2167 2255
 
2168 2256
 	// Any errors means we refresh potentially.
2169 2257
 	if (!empty($verification_errors))
2170 2258
 	{
2171
-		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors']))
2172
-			$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2259
+		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) {
2260
+					$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2261
+		}
2173 2262
 		// Too many errors?
2174
-		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors'])
2175
-			$force_refresh = true;
2263
+		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) {
2264
+					$force_refresh = true;
2265
+		}
2176 2266
 
2177 2267
 		// Keep a track of these.
2178 2268
 		$_SESSION[$verificationOptions['id'] . '_vv']['errors']++;
@@ -2205,8 +2295,9 @@  discard block
 block discarded – undo
2205 2295
 			// Are we overriding the range?
2206 2296
 			$character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range'];
2207 2297
 
2208
-			for ($i = 0; $i < 6; $i++)
2209
-				$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2298
+			for ($i = 0; $i < 6; $i++) {
2299
+							$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2300
+			}
2210 2301
 		}
2211 2302
 
2212 2303
 		// Getting some new questions?
@@ -2214,8 +2305,9 @@  discard block
 block discarded – undo
2214 2305
 		{
2215 2306
 			// Attempt to try the current page's language, followed by the user's preference, followed by the site default.
2216 2307
 			$possible_langs = array();
2217
-			if (isset($_SESSION['language']))
2218
-				$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2308
+			if (isset($_SESSION['language'])) {
2309
+							$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2310
+			}
2219 2311
 			if (!empty($user_info['language']));
2220 2312
 			$possible_langs[] = $user_info['language'];
2221 2313
 			$possible_langs[] = $language;
@@ -2234,8 +2326,7 @@  discard block
 block discarded – undo
2234 2326
 				}
2235 2327
 			}
2236 2328
 		}
2237
-	}
2238
-	else
2329
+	} else
2239 2330
 	{
2240 2331
 		// Same questions as before.
2241 2332
 		$questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array();
@@ -2245,8 +2336,9 @@  discard block
 block discarded – undo
2245 2336
 	// If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway.
2246 2337
 	if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2247 2338
 	{
2248
-		if (!isset($context['html_headers']))
2249
-			$context['html_headers'] = '';
2339
+		if (!isset($context['html_headers'])) {
2340
+					$context['html_headers'] = '';
2341
+		}
2250 2342
 		$context['html_headers'] .= '<style>.vv_special { display:none; }</style>';
2251 2343
 	}
2252 2344
 
@@ -2272,11 +2364,13 @@  discard block
 block discarded – undo
2272 2364
 	$_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1;
2273 2365
 
2274 2366
 	// Return errors if we have them.
2275
-	if (!empty($verification_errors))
2276
-		return $verification_errors;
2367
+	if (!empty($verification_errors)) {
2368
+			return $verification_errors;
2369
+	}
2277 2370
 	// If we had a test that one, make a note.
2278
-	elseif ($do_test)
2279
-		$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2371
+	elseif ($do_test) {
2372
+			$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2373
+	}
2280 2374
 
2281 2375
 	// Say that everything went well chaps.
2282 2376
 	return true;
@@ -2301,8 +2395,9 @@  discard block
 block discarded – undo
2301 2395
 	call_integration_hook('integrate_autosuggest', array(&$searchTypes));
2302 2396
 
2303 2397
 	// If we're just checking the callback function is registered return true or false.
2304
-	if ($checkRegistered != null)
2305
-		return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2398
+	if ($checkRegistered != null) {
2399
+			return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2400
+	}
2306 2401
 
2307 2402
 	checkSession('get');
2308 2403
 	loadTemplate('Xml');
@@ -2453,24 +2548,27 @@  discard block
 block discarded – undo
2453 2548
 		foreach ($possible_versions as $ver)
2454 2549
 		{
2455 2550
 			$ver = trim($ver);
2456
-			if (strpos($ver, 'SMF') === 0)
2457
-				$versions[] = $ver;
2551
+			if (strpos($ver, 'SMF') === 0) {
2552
+							$versions[] = $ver;
2553
+			}
2458 2554
 		}
2459 2555
 	}
2460 2556
 	$smcFunc['db_free_result']($request);
2461 2557
 
2462 2558
 	// Just in case we don't have ANYthing.
2463
-	if (empty($versions))
2464
-		$versions = array('SMF 2.0');
2559
+	if (empty($versions)) {
2560
+			$versions = array('SMF 2.0');
2561
+	}
2465 2562
 
2466
-	foreach ($versions as $id => $version)
2467
-		if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2563
+	foreach ($versions as $id => $version) {
2564
+			if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2468 2565
 			$xml_data['items']['children'][] = array(
2469 2566
 				'attributes' => array(
2470 2567
 					'id' => $id,
2471 2568
 				),
2472 2569
 				'value' => $version,
2473 2570
 			);
2571
+	}
2474 2572
 
2475 2573
 	return $xml_data;
2476 2574
 }
Please login to merge, or discard this patch.