Completed
Push — release-2.1 ( 29513c...1198c1 )
by Colin
08:53
created
Themes/default/ManageCalendar.template.php 1 patch
Braces   +14 added lines, -10 removed lines patch added patch discarded remove patch
@@ -40,9 +40,10 @@  discard block
 block discarded – undo
40 40
 							<option value="0000"', $context['holiday']['year'] == '0000' ? ' selected' : '', '>', $txt['every_year'], '</option>';
41 41
 
42 42
 	// Show a list of all the years we allow...
43
-	for ($year = $modSettings['cal_minyear']; $year <= $modSettings['cal_maxyear']; $year++)
44
-		echo '
43
+	for ($year = $modSettings['cal_minyear']; $year <= $modSettings['cal_maxyear']; $year++) {
44
+			echo '
45 45
 							<option value="', $year, '"', $year == $context['holiday']['year'] ? ' selected' : '', '>', $year, '</option>';
46
+	}
46 47
 
47 48
 	echo '
48 49
 						</select>
@@ -50,9 +51,10 @@  discard block
 block discarded – undo
50 51
 						<select name="month" id="month" onchange="generateDays();">';
51 52
 
52 53
 	// There are 12 months per year - ensure that they all get listed.
53
-	for ($month = 1; $month <= 12; $month++)
54
-		echo '
54
+	for ($month = 1; $month <= 12; $month++) {
55
+			echo '
55 56
 							<option value="', $month, '"', $month == $context['holiday']['month'] ? ' selected' : '', '>', $txt['months'][$month], '</option>';
57
+	}
56 58
 
57 59
 	echo '
58 60
 						</select>
@@ -60,23 +62,25 @@  discard block
 block discarded – undo
60 62
 						<select name="day" id="day" onchange="generateDays();">';
61 63
 
62 64
 	// This prints out all the days in the current month - this changes dynamically as we switch months.
63
-	for ($day = 1; $day <= $context['holiday']['last_day']; $day++)
64
-		echo '
65
+	for ($day = 1; $day <= $context['holiday']['last_day']; $day++) {
66
+			echo '
65 67
 							<option value="', $day, '"', $day == $context['holiday']['day'] ? ' selected' : '', '>', $day, '</option>';
68
+	}
66 69
 
67 70
 	echo '
68 71
 						</select>
69 72
 					</dd>
70 73
 				</dl>';
71 74
 
72
-	if ($context['is_new'])
73
-		echo '
75
+	if ($context['is_new']) {
76
+			echo '
74 77
 				<input type="submit" value="', $txt['holidays_button_add'], '" class="button">';
75
-	else
76
-		echo '
78
+	} else {
79
+			echo '
77 80
 				<input type="submit" name="edit" value="', $txt['holidays_button_edit'], '" class="button">
78 81
 				<input type="submit" name="delete" value="', $txt['holidays_button_remove'], '" class="button">
79 82
 				<input type="hidden" name="holiday" value="', $context['holiday']['id'], '">';
83
+	}
80 84
 	echo '
81 85
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
82 86
 			</div><!-- .windowbg2 -->
Please login to merge, or discard this patch.
Sources/Subs-BoardIndex.php 1 patch
Braces   +60 added lines, -47 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Fetches a list of boards and (optional) categories including
@@ -37,11 +38,12 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Boards.php');
38 39
 
39 40
 	// For performance, track the latest post while going through the boards.
40
-	if (!empty($boardIndexOptions['set_latest_post']))
41
-		$latest_post = array(
41
+	if (!empty($boardIndexOptions['set_latest_post'])) {
42
+			$latest_post = array(
42 43
 			'timestamp' => 0,
43 44
 			'ref' => 0,
44 45
 		);
46
+	}
45 47
 
46 48
 	// Find all boards and categories, as well as related information.  This will be sorted by the natural order of boards and categories, which we control.
47 49
 	$result_boards = $smcFunc['db_query']('', '
@@ -74,10 +76,11 @@  discard block
 block discarded – undo
74 76
 	);
75 77
 
76 78
 	// Start with an empty array.
77
-	if ($boardIndexOptions['include_categories'])
78
-		$categories = array();
79
-	else
80
-		$this_category = array();
79
+	if ($boardIndexOptions['include_categories']) {
80
+			$categories = array();
81
+	} else {
82
+			$this_category = array();
83
+	}
81 84
 	$boards = array();
82 85
 
83 86
 	// Run through the categories and boards (or only boards)....
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 		$row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
89 92
 
90 93
 		// Add parent boards to the $boards list later used to fetch moderators
91
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'])
92
-			$boards[] = $row_board['id_board'];
94
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) {
95
+					$boards[] = $row_board['id_board'];
96
+		}
93 97
 
94 98
 		if ($boardIndexOptions['include_categories'])
95 99
 		{
@@ -111,8 +115,9 @@  discard block
 block discarded – undo
111 115
 			}
112 116
 
113 117
 			// If this board has new posts in it (and isn't the recycle bin!) then the category is new.
114
-			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
115
-				$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
118
+			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) {
119
+							$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
120
+			}
116 121
 
117 122
 			// Avoid showing category unread link where it only has redirection boards.
118 123
 			$categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
@@ -161,14 +166,12 @@  discard block
 block discarded – undo
161 166
 				{
162 167
 					$this_category[$row_board['id_board']]['board_class'] = 'redirect';
163 168
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board'];
164
-				}
165
-				elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
169
+				} elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
166 170
 				{
167 171
 					// If we're showing to guests, we want to give them the idea that something interesting is going on!
168 172
 					$this_category[$row_board['id_board']]['board_class'] = 'on';
169 173
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts'];
170
-				}
171
-				else
174
+				} else
172 175
 				{
173 176
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts'];
174 177
 				}
@@ -219,14 +222,16 @@  discard block
 block discarded – undo
219 222
 		// Child of a child... just add it on...
220 223
 		elseif (!empty($boardIndexOptions['countChildPosts']))
221 224
 		{
222
-			if (!isset($parent_map))
223
-				$parent_map = array();
225
+			if (!isset($parent_map)) {
226
+							$parent_map = array();
227
+			}
224 228
 
225
-			if (!isset($parent_map[$row_board['id_parent']]))
226
-				foreach ($this_category as $id => $board)
229
+			if (!isset($parent_map[$row_board['id_parent']])) {
230
+							foreach ($this_category as $id => $board)
227 231
 				{
228 232
 					if (!isset($board['children'][$row_board['id_parent']]))
229 233
 						continue;
234
+			}
230 235
 
231 236
 					$parent_map[$row_board['id_parent']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
232 237
 					$parent_map[$row_board['id_board']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
@@ -247,8 +252,9 @@  discard block
 block discarded – undo
247 252
 			continue;
248 253
 		}
249 254
 		// Found a child of a child - skip.
250
-		else
251
-			continue;
255
+		else {
256
+					continue;
257
+		}
252 258
 
253 259
 		// Prepare the subject, and make sure it's not too long.
254 260
 		censorText($row_board['subject']);
@@ -269,12 +275,13 @@  discard block
 block discarded – undo
269 275
 			'topic' => $row_board['id_topic']
270 276
 		);
271 277
 
272
-		if (!empty($settings['avatars_on_boardIndex']))
273
-			$this_last_post['member']['avatar'] = set_avatar_data(array(
278
+		if (!empty($settings['avatars_on_boardIndex'])) {
279
+					$this_last_post['member']['avatar'] = set_avatar_data(array(
274 280
 				'avatar' => $row_board['avatar'],
275 281
 				'email' => $row_board['email_address'],
276 282
 				'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '',
277 283
 			));
284
+		}
278 285
 
279 286
 		// Provide the href and link.
280 287
 		if ($row_board['subject'] != '')
@@ -286,8 +293,7 @@  discard block
 block discarded – undo
286 293
 			link, href, subject, start (where they should go for the first unread post.),
287 294
 			and member. (which has id, name, link, href, username in it.) */
288 295
 			$this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']);
289
-		}
290
-		else
296
+		} else
291 297
 		{
292 298
 			$this_last_post['href'] = '';
293 299
 			$this_last_post['link'] = $txt['not_applicable'];
@@ -295,8 +301,9 @@  discard block
 block discarded – undo
295 301
 		}
296 302
 
297 303
 		// Set the last post in the parent board.
298
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time'])))
299
-			$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
304
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']))) {
305
+					$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
306
+		}
300 307
 		// Just in the child...?
301 308
 		if ($isChild)
302 309
 		{
@@ -306,15 +313,17 @@  discard block
 block discarded – undo
306 313
 			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != '';
307 314
 		}
308 315
 		// No last post for this board?  It's not new then, is it..?
309
-		elseif ($row_board['poster_name'] == '')
310
-			$this_category[$row_board['id_board']]['new'] = false;
316
+		elseif ($row_board['poster_name'] == '') {
317
+					$this_category[$row_board['id_board']]['new'] = false;
318
+		}
311 319
 
312 320
 		// Determine a global most recent topic.
313
-		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
314
-			$latest_post = array(
321
+		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) {
322
+					$latest_post = array(
315 323
 				'timestamp' => $row_board['poster_time'],
316 324
 				'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'],
317 325
 			);
326
+		}
318 327
 	}
319 328
 	$smcFunc['db_free_result']($result_boards);
320 329
 
@@ -331,8 +340,9 @@  discard block
 block discarded – undo
331 340
 				if (!empty($moderators[$board['id']]))
332 341
 				{
333 342
 					$categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']];
334
-					foreach ($moderators[$board['id']] as $moderator)
335
-						$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
343
+					foreach ($moderators[$board['id']] as $moderator) {
344
+											$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
345
+					}
336 346
 				}
337 347
 				if (!empty($groups[$board['id']]))
338 348
 				{
@@ -345,16 +355,16 @@  discard block
 block discarded – undo
345 355
 				}
346 356
 			}
347 357
 		}
348
-	}
349
-	else
358
+	} else
350 359
 	{
351 360
 		foreach ($this_category as $k => $board)
352 361
 		{
353 362
 			if (!empty($moderators[$board['id']]))
354 363
 			{
355 364
 				$this_category[$k]['moderators'] = $moderators[$board['id']];
356
-				foreach ($moderators[$board['id']] as $moderator)
357
-					$this_category[$k]['link_moderators'][] = $moderator['link'];
365
+				foreach ($moderators[$board['id']] as $moderator) {
366
+									$this_category[$k]['link_moderators'][] = $moderator['link'];
367
+				}
358 368
 			}
359 369
 			if (!empty($groups[$board['id']]))
360 370
 			{
@@ -368,20 +378,23 @@  discard block
 block discarded – undo
368 378
 		}
369 379
 	}
370 380
 
371
-	if ($boardIndexOptions['include_categories'])
372
-		sortCategories($categories);
373
-	else
374
-		sortBoards($this_category);
381
+	if ($boardIndexOptions['include_categories']) {
382
+			sortCategories($categories);
383
+	} else {
384
+			sortBoards($this_category);
385
+	}
375 386
 
376 387
 	// By now we should know the most recent post...if we wanna know it that is.
377
-	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref']))
378
-		$context['latest_post'] = $latest_post['ref'];
388
+	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) {
389
+			$context['latest_post'] = $latest_post['ref'];
390
+	}
379 391
 
380 392
 	// I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea.
381
-	if ($boardIndexOptions['include_categories'])
382
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
383
-	else
384
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
393
+	if ($boardIndexOptions['include_categories']) {
394
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
395
+	} else {
396
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
397
+	}
385 398
 
386 399
 	return $boardIndexOptions['include_categories'] ? $categories : $this_category;
387 400
 }
Please login to merge, or discard this patch.
Sources/ManageSearch.php 1 patch
Braces   +109 added lines, -90 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Main entry point for the admin search settings screen.
@@ -107,11 +108,13 @@  discard block
 block discarded – undo
107 108
 	// Perhaps the search method wants to add some settings?
108 109
 	require_once($sourcedir . '/Search.php');
109 110
 	$searchAPI = findSearchAPI();
110
-	if (is_callable(array($searchAPI, 'searchSettings')))
111
-		call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
111
+	if (is_callable(array($searchAPI, 'searchSettings'))) {
112
+			call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
113
+	}
112 114
 
113
-	if ($return_config)
114
-		return $config_vars;
115
+	if ($return_config) {
116
+			return $config_vars;
117
+	}
115 118
 
116 119
 	$context['page_title'] = $txt['search_settings_title'];
117 120
 	$context['sub_template'] = 'show_settings';
@@ -126,8 +129,9 @@  discard block
 block discarded – undo
126 129
 
127 130
 		call_integration_hook('integrate_save_search_settings');
128 131
 
129
-		if (empty($_POST['search_results_per_page']))
130
-			$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
132
+		if (empty($_POST['search_results_per_page'])) {
133
+					$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
134
+		}
131 135
 		saveDBSettings($config_vars);
132 136
 		$_SESSION['adm-save'] = true;
133 137
 		redirectexit('action=admin;area=managesearch;sa=settings;' . $context['session_var'] . '=' . $context['session_id']);
@@ -177,17 +181,20 @@  discard block
 block discarded – undo
177 181
 		call_integration_hook('integrate_save_search_weights');
178 182
 
179 183
 		$changes = array();
180
-		foreach ($factors as $factor)
181
-			$changes[$factor] = (int) $_POST[$factor];
184
+		foreach ($factors as $factor) {
185
+					$changes[$factor] = (int) $_POST[$factor];
186
+		}
182 187
 		updateSettings($changes);
183 188
 	}
184 189
 
185 190
 	$context['relative_weights'] = array('total' => 0);
186
-	foreach ($factors as $factor)
187
-		$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
191
+	foreach ($factors as $factor) {
192
+			$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
193
+	}
188 194
 
189
-	foreach ($factors as $factor)
190
-		$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
195
+	foreach ($factors as $factor) {
196
+			$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
197
+	}
191 198
 
192 199
 	createToken('admin-msw');
193 200
 }
@@ -215,8 +222,9 @@  discard block
 block discarded – undo
215 222
 	$context['search_apis'] = loadSearchAPIs();
216 223
 
217 224
 	// Detect whether a fulltext index is set.
218
-	if ($context['supports_fulltext'])
219
-		detectFulltextIndex();
225
+	if ($context['supports_fulltext']) {
226
+			detectFulltextIndex();
227
+	}
220 228
 
221 229
 	if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'createfulltext')
222 230
 	{
@@ -240,8 +248,7 @@  discard block
 block discarded – undo
240 248
 					'language' => $language_ftx
241 249
 				)
242 250
 			);
243
-		}
244
-		else
251
+		} else
245 252
 		{
246 253
 			// Make sure it's gone before creating it.
247 254
 			$smcFunc['db_query']('', '
@@ -259,8 +266,7 @@  discard block
 block discarded – undo
259 266
 				)
260 267
 			);
261 268
 		}
262
-	}
263
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
269
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
264 270
 	{
265 271
 		checkSession('get');
266 272
 		validateToken('admin-msm', 'get');
@@ -277,12 +283,12 @@  discard block
 block discarded – undo
277 283
 		$context['fulltext_index'] = array();
278 284
 
279 285
 		// Go back to the default search method.
280
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext')
281
-			updateSettings(array(
286
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') {
287
+					updateSettings(array(
282 288
 				'search_index' => '',
283 289
 			));
284
-	}
285
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
290
+		}
291
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
286 292
 	{
287 293
 		checkSession('get');
288 294
 		validateToken('admin-msm', 'get');
@@ -304,12 +310,12 @@  discard block
 block discarded – undo
304 310
 		));
305 311
 
306 312
 		// Go back to the default search method.
307
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
308
-			updateSettings(array(
313
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
314
+					updateSettings(array(
309 315
 				'search_index' => '',
310 316
 			));
311
-	}
312
-	elseif (isset($_POST['save']))
317
+		}
318
+	} elseif (isset($_POST['save']))
313 319
 	{
314 320
 		checkSession();
315 321
 		validateToken('admin-msmpost');
@@ -331,8 +337,8 @@  discard block
 block discarded – undo
331 337
 	// Get some info about the messages table, to show its size and index size.
332 338
 	if ($db_type == 'mysql')
333 339
 	{
334
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
335
-			$request = $smcFunc['db_query']('', '
340
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
341
+					$request = $smcFunc['db_query']('', '
336 342
 				SHOW TABLE STATUS
337 343
 				FROM {string:database_name}
338 344
 				LIKE {string:table_name}',
@@ -341,14 +347,15 @@  discard block
 block discarded – undo
341 347
 					'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
342 348
 				)
343 349
 			);
344
-		else
345
-			$request = $smcFunc['db_query']('', '
350
+		} else {
351
+					$request = $smcFunc['db_query']('', '
346 352
 				SHOW TABLE STATUS
347 353
 				LIKE {string:table_name}',
348 354
 				array(
349 355
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
350 356
 				)
351 357
 			);
358
+		}
352 359
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
353 360
 		{
354 361
 			// Only do this if the user has permission to execute this query.
@@ -360,8 +367,8 @@  discard block
 block discarded – undo
360 367
 		}
361 368
 
362 369
 		// Now check the custom index table, if it exists at all.
363
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
364
-			$request = $smcFunc['db_query']('', '
370
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
371
+					$request = $smcFunc['db_query']('', '
365 372
 				SHOW TABLE STATUS
366 373
 				FROM {string:database_name}
367 374
 				LIKE {string:table_name}',
@@ -370,14 +377,15 @@  discard block
 block discarded – undo
370 377
 					'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words',
371 378
 				)
372 379
 			);
373
-		else
374
-			$request = $smcFunc['db_query']('', '
380
+		} else {
381
+					$request = $smcFunc['db_query']('', '
375 382
 				SHOW TABLE STATUS
376 383
 				LIKE {string:table_name}',
377 384
 				array(
378 385
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words',
379 386
 				)
380 387
 			);
388
+		}
381 389
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
382 390
 		{
383 391
 			// Only do this if the user has permission to execute this query.
@@ -386,8 +394,7 @@  discard block
 block discarded – undo
386 394
 			$context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length'];
387 395
 			$smcFunc['db_free_result']($request);
388 396
 		}
389
-	}
390
-	elseif ($db_type == 'postgresql')
397
+	} elseif ($db_type == 'postgresql')
391 398
 	{
392 399
 		// In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using.
393 400
 		//db_extend();
@@ -429,38 +436,38 @@  discard block
 block discarded – undo
429 436
 					$context['table_info']['data_length'] = (int) $row['table_size'];
430 437
 					$context['table_info']['index_length'] = (int) $row['index_size'];
431 438
 					$context['table_info']['fulltext_length'] = (int) $row['index_size'];
432
-				}
433
-				elseif ($row['indexname'] == $db_prefix . 'log_search_words')
439
+				} elseif ($row['indexname'] == $db_prefix . 'log_search_words')
434 440
 				{
435 441
 					$context['table_info']['index_length'] = (int) $row['index_size'];
436 442
 					$context['table_info']['custom_index_length'] = (int) $row['index_size'];
437 443
 				}
438 444
 			}
439 445
 			$smcFunc['db_free_result']($request);
440
-		}
441
-		else
442
-			// Didn't work for some reason...
446
+		} else {
447
+					// Didn't work for some reason...
443 448
 			$context['table_info'] = array(
444 449
 				'data_length' => $txt['not_applicable'],
445 450
 				'index_length' => $txt['not_applicable'],
446 451
 				'fulltext_length' => $txt['not_applicable'],
447 452
 				'custom_index_length' => $txt['not_applicable'],
448 453
 			);
449
-	}
450
-	else
451
-		$context['table_info'] = array(
454
+		}
455
+	} else {
456
+			$context['table_info'] = array(
452 457
 			'data_length' => $txt['not_applicable'],
453 458
 			'index_length' => $txt['not_applicable'],
454 459
 			'fulltext_length' => $txt['not_applicable'],
455 460
 			'custom_index_length' => $txt['not_applicable'],
456 461
 		);
462
+	}
457 463
 
458 464
 	// Format the data and index length in kilobytes.
459 465
 	foreach ($context['table_info'] as $type => $size)
460 466
 	{
461 467
 		// If it's not numeric then just break.  This database engine doesn't support size.
462
-		if (!is_numeric($size))
463
-			break;
468
+		if (!is_numeric($size)) {
469
+					break;
470
+		}
464 471
 
465 472
 		$context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes'];
466 473
 	}
@@ -489,8 +496,9 @@  discard block
 block discarded – undo
489 496
 
490 497
 	// Scotty, we need more time...
491 498
 	@set_time_limit(600);
492
-	if (function_exists('apache_reset_timeout'))
493
-		@apache_reset_timeout();
499
+	if (function_exists('apache_reset_timeout')) {
500
+			@apache_reset_timeout();
501
+	}
494 502
 
495 503
 	$context[$context['admin_menu_name']]['current_subsection'] = 'method';
496 504
 	$context['page_title'] = $txt['search_index_custom'];
@@ -520,8 +528,7 @@  discard block
 block discarded – undo
520 528
 		$context['start'] = (int) $context['index_settings']['resume_at'];
521 529
 		unset($context['index_settings']['resume_at']);
522 530
 		$context['step'] = 1;
523
-	}
524
-	else
531
+	} else
525 532
 	{
526 533
 		$context['index_settings'] = array(
527 534
 			'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2,
@@ -530,12 +537,14 @@  discard block
 block discarded – undo
530 537
 		$context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
531 538
 
532 539
 		// admin timeouts are painful when building these long indexes - but only if we actually have such things enabled
533
-		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1)
534
-			$_SESSION['admin_time'] = time();
540
+		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) {
541
+					$_SESSION['admin_time'] = time();
542
+		}
535 543
 	}
536 544
 
537
-	if ($context['step'] !== 0)
538
-		checkSession('request');
545
+	if ($context['step'] !== 0) {
546
+			checkSession('request');
547
+	}
539 548
 
540 549
 	// Step 0: let the user determine how they like their index.
541 550
 	if ($context['step'] === 0)
@@ -564,12 +573,14 @@  discard block
 block discarded – undo
564 573
 			$smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']);
565 574
 
566 575
 			// Temporarily switch back to not using a search index.
567
-			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
568
-				updateSettings(array('search_index' => ''));
576
+			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
577
+							updateSettings(array('search_index' => ''));
578
+			}
569 579
 
570 580
 			// Don't let simultanious processes be updating the search index.
571
-			if (!empty($modSettings['search_custom_index_config']))
572
-				updateSettings(array('search_custom_index_config' => ''));
581
+			if (!empty($modSettings['search_custom_index_config'])) {
582
+							updateSettings(array('search_custom_index_config' => ''));
583
+			}
573 584
 		}
574 585
 
575 586
 		$num_messages = array(
@@ -585,16 +596,16 @@  discard block
 block discarded – undo
585 596
 				'starting_id' => $context['start'],
586 597
 			)
587 598
 		);
588
-		while ($row = $smcFunc['db_fetch_assoc']($request))
589
-			$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
599
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
600
+					$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
601
+		}
590 602
 
591 603
 		if (empty($num_messages['todo']))
592 604
 		{
593 605
 			$context['step'] = 2;
594 606
 			$context['percentage'] = 80;
595 607
 			$context['start'] = 0;
596
-		}
597
-		else
608
+		} else
598 609
 		{
599 610
 			// Number of seconds before the next step.
600 611
 			$stop = time() + 3;
@@ -635,21 +646,22 @@  discard block
 block discarded – undo
635 646
 
636 647
 				$context['start'] += $forced_break ? $number_processed : $messages_per_batch;
637 648
 
638
-				if (!empty($inserts))
639
-					$smcFunc['db_insert']('ignore',
649
+				if (!empty($inserts)) {
650
+									$smcFunc['db_insert']('ignore',
640 651
 						'{db_prefix}log_search_words',
641 652
 						array('id_word' => 'int', 'id_msg' => 'int'),
642 653
 						$inserts,
643 654
 						array('id_word', 'id_msg')
644 655
 					);
656
+				}
645 657
 				if ($num_messages['todo'] === 0)
646 658
 				{
647 659
 					$context['step'] = 2;
648 660
 					$context['start'] = 0;
649 661
 					break;
662
+				} else {
663
+									updateSettings(array('search_custom_index_resume' => $smcFunc['json_encode'](array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
650 664
 				}
651
-				else
652
-					updateSettings(array('search_custom_index_resume' => $smcFunc['json_encode'](array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
653 665
 			}
654 666
 
655 667
 			// Since there are still two steps to go, 80% is the maximum here.
@@ -660,9 +672,9 @@  discard block
 block discarded – undo
660 672
 	// Step 2: removing the words that occur too often and are of no use.
661 673
 	elseif ($context['step'] === 2)
662 674
 	{
663
-		if ($context['index_settings']['bytes_per_word'] < 4)
664
-			$context['step'] = 3;
665
-		else
675
+		if ($context['index_settings']['bytes_per_word'] < 4) {
676
+					$context['step'] = 3;
677
+		} else
666 678
 		{
667 679
 			$stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']);
668 680
 			$stop = time() + 3;
@@ -683,20 +695,22 @@  discard block
 block discarded – undo
683 695
 						'minimum_messages' => $max_messages,
684 696
 					)
685 697
 				);
686
-				while ($row = $smcFunc['db_fetch_assoc']($request))
687
-					$stop_words[] = $row['id_word'];
698
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
699
+									$stop_words[] = $row['id_word'];
700
+				}
688 701
 				$smcFunc['db_free_result']($request);
689 702
 
690 703
 				updateSettings(array('search_stopwords' => implode(',', $stop_words)));
691 704
 
692
-				if (!empty($stop_words))
693
-					$smcFunc['db_query']('', '
705
+				if (!empty($stop_words)) {
706
+									$smcFunc['db_query']('', '
694 707
 						DELETE FROM {db_prefix}log_search_words
695 708
 						WHERE id_word in ({array_int:stop_words})',
696 709
 						array(
697 710
 							'stop_words' => $stop_words,
698 711
 						)
699 712
 					);
713
+				}
700 714
 
701 715
 				$context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size'];
702 716
 				if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size'])
@@ -757,8 +771,9 @@  discard block
 block discarded – undo
757 771
 					$searchAPI = new $search_class_name();
758 772
 
759 773
 					// No Support?  NEXT!
760
-					if (!$searchAPI->is_supported)
761
-						continue;
774
+					if (!$searchAPI->is_supported) {
775
+											continue;
776
+					}
762 777
 
763 778
 					$apis[$index_name] = array(
764 779
 						'filename' => $file,
@@ -805,10 +820,10 @@  discard block
 block discarded – undo
805 820
 				'messages_ftx' => $db_prefix . 'messages_ftx',
806 821
 			)
807 822
 		);
808
-		while ($row = $smcFunc['db_fetch_assoc']($request))
809
-			$context['fulltext_index'][] = $row['indexname'];
810
-	}
811
-	else
823
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
824
+					$context['fulltext_index'][] = $row['indexname'];
825
+		}
826
+	} else
812 827
 	{
813 828
 		$request = $smcFunc['db_query']('', '
814 829
 			SHOW INDEX
@@ -819,17 +834,19 @@  discard block
 block discarded – undo
819 834
 		$context['fulltext_index'] = array();
820 835
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
821 836
 		{
822
-			while ($row = $smcFunc['db_fetch_assoc']($request))
823
-			if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
837
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
838
+						if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
824 839
 				$context['fulltext_index'][] = $row['Key_name'];
840
+			}
825 841
 			$smcFunc['db_free_result']($request);
826 842
 
827
-			if (is_array($context['fulltext_index']))
828
-				$context['fulltext_index'] = array_unique($context['fulltext_index']);
843
+			if (is_array($context['fulltext_index'])) {
844
+							$context['fulltext_index'] = array_unique($context['fulltext_index']);
845
+			}
829 846
 		}
830 847
 
831
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
832
-			$request = $smcFunc['db_query']('', '
848
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
849
+					$request = $smcFunc['db_query']('', '
833 850
 			SHOW TABLE STATUS
834 851
 			FROM {string:database_name}
835 852
 			LIKE {string:table_name}',
@@ -838,20 +855,22 @@  discard block
 block discarded – undo
838 855
 				'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
839 856
 			)
840 857
 			);
841
-		else
842
-			$request = $smcFunc['db_query']('', '
858
+		} else {
859
+					$request = $smcFunc['db_query']('', '
843 860
 			SHOW TABLE STATUS
844 861
 			LIKE {string:table_name}',
845 862
 			array(
846 863
 				'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
847 864
 			)
848 865
 			);
866
+		}
849 867
 
850 868
 		if ($request !== false)
851 869
 		{
852
-			while ($row = $smcFunc['db_fetch_assoc']($request))
853
-			if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'](), '5.6.4', '>=')))
870
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
871
+						if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'](), '5.6.4', '>=')))
854 872
 				$context['cannot_create_fulltext'] = true;
873
+			}
855 874
 			$smcFunc['db_free_result']($request);
856 875
 		}
857 876
 	}
Please login to merge, or discard this patch.
Sources/ManageNews.php 1 patch
Braces   +140 added lines, -102 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The news dispatcher; doesn't do anything, just delegates.
@@ -67,8 +68,9 @@  discard block
 block discarded – undo
67 68
 	);
68 69
 
69 70
 	// Force the right area...
70
-	if (substr($_REQUEST['sa'], 0, 7) == 'mailing')
71
-		$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
71
+	if (substr($_REQUEST['sa'], 0, 7) == 'mailing') {
72
+			$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
73
+	}
72 74
 
73 75
 	call_helper($subActions[$_REQUEST['sa']][0]);
74 76
 }
@@ -99,9 +101,10 @@  discard block
 block discarded – undo
99 101
 		$temp_news = explode("\n", $modSettings['news']);
100 102
 
101 103
 		// Remove the items that were selected.
102
-		foreach ($temp_news as $i => $news)
103
-			if (in_array($i, $_POST['remove']))
104
+		foreach ($temp_news as $i => $news) {
105
+					if (in_array($i, $_POST['remove']))
104 106
 				unset($temp_news[$i]);
107
+		}
105 108
 
106 109
 		// Update the database.
107 110
 		updateSettings(array('news' => implode("\n", $temp_news)));
@@ -117,9 +120,9 @@  discard block
 block discarded – undo
117 120
 
118 121
 		foreach ($_POST['news'] as $i => $news)
119 122
 		{
120
-			if (trim($news) == '')
121
-				unset($_POST['news'][$i]);
122
-			else
123
+			if (trim($news) == '') {
124
+							unset($_POST['news'][$i]);
125
+			} else
123 126
 			{
124 127
 				$_POST['news'][$i] = $smcFunc['htmlspecialchars']($_POST['news'][$i], ENT_QUOTES);
125 128
 				preparsecode($_POST['news'][$i]);
@@ -155,12 +158,13 @@  discard block
 block discarded – undo
155 158
 				'data' => array(
156 159
 					'function' => function($news)
157 160
 					{
158
-						if (is_numeric($news['id']))
159
-							return '
161
+						if (is_numeric($news['id'])) {
162
+													return '
160 163
 								<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea>
161 164
 								<div class="floatleft" id="preview_' . $news['id'] . '"></div>';
162
-						else
163
-							return $news['unparsed'];
165
+						} else {
166
+													return $news['unparsed'];
167
+						}
164 168
 					},
165 169
 					'class' => 'half_table',
166 170
 				),
@@ -186,10 +190,11 @@  discard block
 block discarded – undo
186 190
 				'data' => array(
187 191
 					'function' => function($news)
188 192
 					{
189
-						if (is_numeric($news['id']))
190
-							return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">';
191
-						else
192
-							return '';
193
+						if (is_numeric($news['id'])) {
194
+													return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">';
195
+						} else {
196
+													return '';
197
+						}
193 198
 					},
194 199
 					'class' => 'centercol icon',
195 200
 				),
@@ -283,12 +288,13 @@  discard block
 block discarded – undo
283 288
 
284 289
 	$admin_current_news = array();
285 290
 	// Ready the current news.
286
-	foreach (explode("\n", $modSettings['news']) as $id => $line)
287
-		$admin_current_news[$id] = array(
291
+	foreach (explode("\n", $modSettings['news']) as $id => $line) {
292
+			$admin_current_news[$id] = array(
288 293
 			'id' => $id,
289 294
 			'unparsed' => un_preparsecode($line),
290 295
 			'parsed' => preg_replace('~<([/]?)form[^>]*?[>]*>~i', '<em class="smalltext">&lt;$1form&gt;</em>', parse_bbc($line)),
291 296
 		);
297
+	}
292 298
 
293 299
 	$admin_current_news['last'] = array(
294 300
 		'id' => 'last',
@@ -355,10 +361,11 @@  discard block
 block discarded – undo
355 361
 			'member_count' => 0,
356 362
 		);
357 363
 
358
-		if ($row['min_posts'] == -1)
359
-			$normalGroups[$row['id_group']] = $row['id_group'];
360
-		else
361
-			$postGroups[$row['id_group']] = $row['id_group'];
364
+		if ($row['min_posts'] == -1) {
365
+					$normalGroups[$row['id_group']] = $row['id_group'];
366
+		} else {
367
+					$postGroups[$row['id_group']] = $row['id_group'];
368
+		}
362 369
 	}
363 370
 	$smcFunc['db_free_result']($request);
364 371
 
@@ -374,8 +381,9 @@  discard block
 block discarded – undo
374 381
 				'post_group_list' => $postGroups,
375 382
 			)
376 383
 		);
377
-		while ($row = $smcFunc['db_fetch_assoc']($query))
378
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
384
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
385
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
386
+		}
379 387
 		$smcFunc['db_free_result']($query);
380 388
 	}
381 389
 
@@ -391,8 +399,9 @@  discard block
 block discarded – undo
391 399
 				'normal_group_list' => $normalGroups,
392 400
 			)
393 401
 		);
394
-		while ($row = $smcFunc['db_fetch_assoc']($query))
395
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
402
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
403
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
404
+		}
396 405
 		$smcFunc['db_free_result']($query);
397 406
 
398 407
 		// Also do those who have it as an additional membergroup - this ones more yucky...
@@ -409,8 +418,9 @@  discard block
 block discarded – undo
409 418
 				'blank_string' => '',
410 419
 			)
411 420
 		);
412
-		while ($row = $smcFunc['db_fetch_assoc']($query))
413
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
421
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
422
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
423
+		}
414 424
 		$smcFunc['db_free_result']($query);
415 425
 	}
416 426
 
@@ -461,10 +471,11 @@  discard block
 block discarded – undo
461 471
 	{
462 472
 		$context[$key] = !empty($_REQUEST[$post]) ? $_REQUEST[$post] : '';
463 473
 
464
-		if (empty($context[$key]) && empty($_REQUEST['xml']))
465
-			$context['post_error']['messages'][] = $txt['error_no_' . $post];
466
-		elseif (!empty($_REQUEST['xml']))
467
-			continue;
474
+		if (empty($context[$key]) && empty($_REQUEST['xml'])) {
475
+					$context['post_error']['messages'][] = $txt['error_no_' . $post];
476
+		} elseif (!empty($_REQUEST['xml'])) {
477
+					continue;
478
+		}
468 479
 
469 480
 		preparsecode($context[$key]);
470 481
 		if ($html)
@@ -543,10 +554,12 @@  discard block
 block discarded – undo
543 554
 
544 555
 	// Start by finding any members!
545 556
 	$toClean = array();
546
-	if (!empty($_POST['members']))
547
-		$toClean[] = 'members';
548
-	if (!empty($_POST['exclude_members']))
549
-		$toClean[] = 'exclude_members';
557
+	if (!empty($_POST['members'])) {
558
+			$toClean[] = 'members';
559
+	}
560
+	if (!empty($_POST['exclude_members'])) {
561
+			$toClean[] = 'exclude_members';
562
+	}
550 563
 	if (!empty($toClean))
551 564
 	{
552 565
 		require_once($sourcedir . '/Subs-Auth.php');
@@ -558,11 +571,13 @@  discard block
 block discarded – undo
558 571
 			preg_match_all('~"([^"]+)"~', $_POST[$type], $matches);
559 572
 			$_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type]))));
560 573
 
561
-			foreach ($_POST[$type] as $index => $member)
562
-				if (strlen(trim($member)) > 0)
574
+			foreach ($_POST[$type] as $index => $member) {
575
+							if (strlen(trim($member)) > 0)
563 576
 					$_POST[$type][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($member)));
564
-				else
565
-					unset($_POST[$type][$index]);
577
+			}
578
+				else {
579
+									unset($_POST[$type][$index]);
580
+				}
566 581
 
567 582
 			// Find the members
568 583
 			$_POST[$type] = implode(',', array_keys(findMembers($_POST[$type])));
@@ -572,16 +587,18 @@  discard block
 block discarded – undo
572 587
 	if (isset($_POST['member_list']) && is_array($_POST['member_list']))
573 588
 	{
574 589
 		$members = array();
575
-		foreach ($_POST['member_list'] as $member_id)
576
-			$members[] = (int) $member_id;
590
+		foreach ($_POST['member_list'] as $member_id) {
591
+					$members[] = (int) $member_id;
592
+		}
577 593
 		$_POST['members'] = implode(',', $members);
578 594
 	}
579 595
 
580 596
 	if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list']))
581 597
 	{
582 598
 		$members = array();
583
-		foreach ($_POST['exclude_member_list'] as $member_id)
584
-			$members[] = (int) $member_id;
599
+		foreach ($_POST['exclude_member_list'] as $member_id) {
600
+					$members[] = (int) $member_id;
601
+		}
585 602
 		$_POST['exclude_members'] = implode(',', $members);
586 603
 	}
587 604
 
@@ -605,8 +622,9 @@  discard block
 block discarded – undo
605 622
 			'current_time' => time(),
606 623
 		)
607 624
 	);
608
-	while ($row = $smcFunc['db_fetch_assoc']($request))
609
-		$context['recipients']['exclude_members'][] = $row['id_member'];
625
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
626
+			$context['recipients']['exclude_members'][] = $row['id_member'];
627
+	}
610 628
 	$smcFunc['db_free_result']($request);
611 629
 
612 630
 	$request = $smcFunc['db_query']('', '
@@ -641,8 +659,9 @@  discard block
 block discarded – undo
641 659
 			WHERE email_address IN(' . implode(', ', $condition_array) . ')',
642 660
 			$condition_array_params
643 661
 		);
644
-		while ($row = $smcFunc['db_fetch_assoc']($request))
645
-			$context['recipients']['exclude_members'][] = $row['id_member'];
662
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
663
+					$context['recipients']['exclude_members'][] = $row['id_member'];
664
+		}
646 665
 		$smcFunc['db_free_result']($request);
647 666
 	}
648 667
 
@@ -660,10 +679,11 @@  discard block
 block discarded – undo
660 679
 		);
661 680
 		while ($row = $smcFunc['db_fetch_assoc']($request))
662 681
 		{
663
-			if (in_array(3, $context['recipients']))
664
-				$context['recipients']['exclude_members'][] = $row['identifier'];
665
-			else
666
-				$context['recipients']['members'][] = $row['identifier'];
682
+			if (in_array(3, $context['recipients'])) {
683
+							$context['recipients']['exclude_members'][] = $row['identifier'];
684
+			} else {
685
+							$context['recipients']['members'][] = $row['identifier'];
686
+			}
667 687
 		}
668 688
 		$smcFunc['db_free_result']($request);
669 689
 	}
@@ -710,8 +730,9 @@  discard block
 block discarded – undo
710 730
 	$num_at_once = 1000;
711 731
 
712 732
 	// If by PM's I suggest we half the above number.
713
-	if (!empty($_POST['send_pm']))
714
-		$num_at_once /= 2;
733
+	if (!empty($_POST['send_pm'])) {
734
+			$num_at_once /= 2;
735
+	}
715 736
 
716 737
 	checkSession();
717 738
 
@@ -734,8 +755,7 @@  discard block
 block discarded – undo
734 755
 		);
735 756
 		list ($context['total_members']) = $smcFunc['db_fetch_row']($request);
736 757
 		$smcFunc['db_free_result']($request);
737
-	}
738
-	else
758
+	} else
739 759
 	{
740 760
 		$context['total_members'] = (int) $_REQUEST['total_members'];
741 761
 	}
@@ -753,32 +773,35 @@  discard block
 block discarded – undo
753 773
 	if (!empty($_POST['exclude_members']))
754 774
 	{
755 775
 		$members = explode(',', $_POST['exclude_members']);
756
-		foreach ($members as $member)
757
-			if ($member >= $context['start'])
776
+		foreach ($members as $member) {
777
+					if ($member >= $context['start'])
758 778
 				$context['recipients']['exclude_members'][] = (int) $member;
779
+		}
759 780
 	}
760 781
 
761 782
 	// What about members we *must* do?
762 783
 	if (!empty($_POST['members']))
763 784
 	{
764 785
 		$members = explode(',', $_POST['members']);
765
-		foreach ($members as $member)
766
-			if ($member >= $context['start'])
786
+		foreach ($members as $member) {
787
+					if ($member >= $context['start'])
767 788
 				$context['recipients']['members'][] = (int) $member;
789
+		}
768 790
 	}
769 791
 	// Cleaning groups is simple - although deal with both checkbox and commas.
770 792
 	if (isset($_POST['groups']))
771 793
 	{
772 794
 		if (is_array($_POST['groups']))
773 795
 		{
774
-			foreach ($_POST['groups'] as $group => $dummy)
775
-				$context['recipients']['groups'][] = (int) $group;
776
-		}
777
-		else
796
+			foreach ($_POST['groups'] as $group => $dummy) {
797
+							$context['recipients']['groups'][] = (int) $group;
798
+			}
799
+		} else
778 800
 		{
779 801
 			$groups = explode(',', $_POST['groups']);
780
-			foreach ($groups as $group)
781
-				$context['recipients']['groups'][] = (int) $group;
802
+			foreach ($groups as $group) {
803
+							$context['recipients']['groups'][] = (int) $group;
804
+			}
782 805
 		}
783 806
 	}
784 807
 	// Same for excluded groups
@@ -786,15 +809,17 @@  discard block
 block discarded – undo
786 809
 	{
787 810
 		if (is_array($_POST['exclude_groups']))
788 811
 		{
789
-			foreach ($_POST['exclude_groups'] as $group => $dummy)
790
-				$context['recipients']['exclude_groups'][] = (int) $group;
812
+			foreach ($_POST['exclude_groups'] as $group => $dummy) {
813
+							$context['recipients']['exclude_groups'][] = (int) $group;
814
+			}
791 815
 		}
792 816
 		// Ignore an empty string - we don't want to exclude "Regular Members" unless it's specifically selected
793 817
 		elseif ($_POST['exclude_groups'] != '')
794 818
 		{
795 819
 			$groups = explode(',', $_POST['exclude_groups']);
796
-			foreach ($groups as $group)
797
-				$context['recipients']['exclude_groups'][] = (int) $group;
820
+			foreach ($groups as $group) {
821
+							$context['recipients']['exclude_groups'][] = (int) $group;
822
+			}
798 823
 		}
799 824
 	}
800 825
 	// Finally - emails!
@@ -804,14 +829,16 @@  discard block
 block discarded – undo
804 829
 		foreach ($addressed as $curmem)
805 830
 		{
806 831
 			$curmem = trim($curmem);
807
-			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL))
808
-				$context['recipients']['emails'][$curmem] = $curmem;
832
+			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL)) {
833
+							$context['recipients']['emails'][$curmem] = $curmem;
834
+			}
809 835
 		}
810 836
 	}
811 837
 
812 838
 	// If we're only cleaning drop out here.
813
-	if ($clean_only)
814
-		return;
839
+	if ($clean_only) {
840
+			return;
841
+	}
815 842
 
816 843
 	require_once($sourcedir . '/Subs-Post.php');
817 844
 
@@ -827,16 +854,18 @@  discard block
 block discarded – undo
827 854
 	if (!$context['send_pm'] && !empty($_POST['send_html']))
828 855
 	{
829 856
 		// Prepare the message for HTML.
830
-		if (!empty($_POST['parse_html']))
831
-			$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
857
+		if (!empty($_POST['parse_html'])) {
858
+					$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
859
+		}
832 860
 
833 861
 		// This is here to prevent spam filters from tagging this as spam.
834 862
 		if (preg_match('~\<html~i', $_POST['message']) == 0)
835 863
 		{
836
-			if (preg_match('~\<body~i', $_POST['message']) == 0)
837
-				$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
838
-			else
839
-				$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
864
+			if (preg_match('~\<body~i', $_POST['message']) == 0) {
865
+							$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
866
+			} else {
867
+							$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
868
+			}
840 869
 		}
841 870
 	}
842 871
 
@@ -890,15 +919,17 @@  discard block
 block discarded – undo
890 919
 	foreach ($context['recipients']['emails'] as $k => $email)
891 920
 	{
892 921
 		// Done as many as we can?
893
-		if ($i >= $num_at_once)
894
-			break;
922
+		if ($i >= $num_at_once) {
923
+					break;
924
+		}
895 925
 
896 926
 		// Don't sent it twice!
897 927
 		unset($context['recipients']['emails'][$k]);
898 928
 
899 929
 		// Dammit - can't PM emails!
900
-		if ($context['send_pm'])
901
-			continue;
930
+		if ($context['send_pm']) {
931
+					continue;
932
+		}
902 933
 
903 934
 		$to_member = array(
904 935
 			$email,
@@ -932,8 +963,9 @@  discard block
 block discarded – undo
932 963
 					$queryBuild[] = 'mem.id_post_group = {int:group_' . $group . '}';
933 964
 				}
934 965
 			}
935
-			if (!empty($queryBuild))
936
-			$sendQuery .= implode(' OR ', $queryBuild);
966
+			if (!empty($queryBuild)) {
967
+						$sendQuery .= implode(' OR ', $queryBuild);
968
+			}
937 969
 		}
938 970
 		if (!empty($context['recipients']['members']))
939 971
 		{
@@ -952,8 +984,9 @@  discard block
 block discarded – undo
952 984
 		}
953 985
 
954 986
 		// Anything to exclude?
955
-		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups']))
956
-			$sendQuery .= ' AND mem.id_group != {int:regular_group}';
987
+		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) {
988
+					$sendQuery .= ' AND mem.id_group != {int:regular_group}';
989
+		}
957 990
 		if (!empty($context['recipients']['exclude_members']))
958 991
 		{
959 992
 			$sendQuery .= ' AND mem.id_member NOT IN ({array_int:exclude_members})';
@@ -989,21 +1022,24 @@  discard block
 block discarded – undo
989 1022
 		foreach ($rows as $row)
990 1023
 		{
991 1024
 			// Force them to have it?
992
-			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements']))
993
-				continue;
1025
+			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements'])) {
1026
+							continue;
1027
+			}
994 1028
 
995 1029
 			// What groups are we looking at here?
996
-			if (empty($row['additional_groups']))
997
-				$groups = array($row['id_group'], $row['id_post_group']);
998
-			else
999
-				$groups = array_merge(
1030
+			if (empty($row['additional_groups'])) {
1031
+							$groups = array($row['id_group'], $row['id_post_group']);
1032
+			} else {
1033
+							$groups = array_merge(
1000 1034
 					array($row['id_group'], $row['id_post_group']),
1001 1035
 					explode(',', $row['additional_groups'])
1002 1036
 				);
1037
+			}
1003 1038
 
1004 1039
 			// Excluded groups?
1005
-			if (array_intersect($groups, $context['recipients']['exclude_groups']))
1006
-				continue;
1040
+			if (array_intersect($groups, $context['recipients']['exclude_groups'])) {
1041
+							continue;
1042
+			}
1007 1043
 
1008 1044
 			// We might need this
1009 1045
 			$cleanMemberName = empty($_POST['send_html']) || $context['send_pm'] ? un_htmlspecialchars($row['real_name']) : $row['real_name'];
@@ -1026,10 +1062,11 @@  discard block
 block discarded – undo
1026 1062
 				), $_POST['subject']);
1027 1063
 
1028 1064
 			// Send the actual email - or a PM!
1029
-			if (!$context['send_pm'])
1030
-				sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1031
-			else
1032
-				sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1065
+			if (!$context['send_pm']) {
1066
+							sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1067
+			} else {
1068
+							sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1069
+			}
1033 1070
 		}
1034 1071
 	}
1035 1072
 
@@ -1079,8 +1116,9 @@  discard block
 block discarded – undo
1079 1116
 
1080 1117
 	call_integration_hook('integrate_modify_news_settings', array(&$config_vars));
1081 1118
 
1082
-	if ($return_config)
1083
-		return $config_vars;
1119
+	if ($return_config) {
1120
+			return $config_vars;
1121
+	}
1084 1122
 
1085 1123
 	$context['page_title'] = $txt['admin_edit_news'] . ' - ' . $txt['settings'];
1086 1124
 	$context['sub_template'] = 'show_settings';
Please login to merge, or discard this patch.
Sources/Subs.php 4 patches
Indentation   +1 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5495,7 +5495,6 @@  discard block
 block discarded – undo
5495 5495
 
5496 5496
 /**
5497 5497
  * Tries different modes to make file/dirs writable. Wrapper function for chmod()
5498
-
5499 5498
  * @param string $file The file/dir full path.
5500 5499
  * @param int $value Not needed, added for legacy reasons.
5501 5500
  * @return boolean  true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable.
@@ -5535,7 +5534,6 @@  discard block
 block discarded – undo
5535 5534
 
5536 5535
 /**
5537 5536
  * Wrapper function for json_decode() with error handling.
5538
-
5539 5537
  * @param string $json The string to decode.
5540 5538
  * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default.
5541 5539
  * @param bool $logIt To specify if the error will be logged if theres any.
@@ -6029,7 +6027,7 @@  discard block
 block discarded – undo
6029 6027
 		$params = stream_context_get_params($stream);
6030 6028
 		$result = isset($params["options"]["ssl"]["peer_certificate"]) ? true : false;
6031 6029
 	}
6032
-    return $result;
6030
+	return $result;
6033 6031
 }
6034 6032
 
6035 6033
 /**
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
  * - caches the formatting data from the setting for optimization.
694 694
  *
695 695
  * @param float $number A number
696
- * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
696
+ * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined
697 697
  * @return string A formatted number
698 698
  */
699 699
 function comma_format($number, $override_decimal_count = false)
@@ -5869,7 +5869,7 @@  discard block
 block discarded – undo
5869 5869
  * It assumes the data is already a string.
5870 5870
  * @param string $data The data to print
5871 5871
  * @param string $type The content type. Defaults to Json.
5872
- * @return void
5872
+ * @return false|null
5873 5873
  */
5874 5874
 function smf_serverResponse($data = '', $type = 'content-type: application/json')
5875 5875
 {
@@ -6351,7 +6351,7 @@  discard block
 block discarded – undo
6351 6351
  *
6352 6352
  * @param string $iri The IRI to test.
6353 6353
  * @param int $flags Optional flags to pass to filter_var()
6354
- * @return string|bool Either the original IRI, or false if the IRI was invalid.
6354
+ * @return string|false Either the original IRI, or false if the IRI was invalid.
6355 6355
  */
6356 6356
 function validate_iri($iri, $flags = null)
6357 6357
 {
Please login to merge, or discard this patch.
Braces   +1454 added lines, -1079 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -385,18 +394,17 @@  discard block
 block discarded – undo
385 394
 			if (is_array($members))
386 395
 			{
387 396
 				$val = 'CASE ';
388
-				foreach ($members as $k => $v)
389
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
397
+				foreach ($members as $k => $v) {
398
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				}
390 400
 				$val = $val . ' END';
391 401
 				$type = 'raw';
392
-			}
393
-			else
402
+			} else
394 403
 			{
395 404
 				$blub = fetch_alerts($members, false, 0, array(), false);
396 405
 				$val = count($blub);
397 406
 			}
398
-		}
399
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
407
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
400 408
 		{
401 409
 			$val = $var . ' ' . $val . ' 1';
402 410
 			$type = 'raw';
@@ -407,8 +415,9 @@  discard block
 block discarded – undo
407 415
 		{
408 416
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
409 417
 			{
410
-				if ($match[1] != '+ ')
411
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
418
+				if ($match[1] != '+ ') {
419
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				}
412 421
 				$type = 'raw';
413 422
 			}
414 423
 		}
@@ -429,8 +438,9 @@  discard block
 block discarded – undo
429 438
 	// Clear any caching?
430 439
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
431 440
 	{
432
-		if (!is_array($members))
433
-			$members = array($members);
441
+		if (!is_array($members)) {
442
+					$members = array($members);
443
+		}
434 444
 
435 445
 		foreach ($members as $member)
436 446
 		{
@@ -463,29 +473,32 @@  discard block
 block discarded – undo
463 473
 {
464 474
 	global $modSettings, $smcFunc;
465 475
 
466
-	if (empty($changeArray) || !is_array($changeArray))
467
-		return;
476
+	if (empty($changeArray) || !is_array($changeArray)) {
477
+			return;
478
+	}
468 479
 
469 480
 	$toRemove = array();
470 481
 
471 482
 	// Go check if there is any setting to be removed.
472
-	foreach ($changeArray as $k => $v)
473
-		if ($v === null)
483
+	foreach ($changeArray as $k => $v) {
484
+			if ($v === null)
474 485
 		{
475 486
 			// Found some, remove them from the original array and add them to ours.
476 487
 			unset($changeArray[$k]);
488
+	}
477 489
 			$toRemove[] = $k;
478 490
 		}
479 491
 
480 492
 	// Proceed with the deletion.
481
-	if (!empty($toRemove))
482
-		$smcFunc['db_query']('', '
493
+	if (!empty($toRemove)) {
494
+			$smcFunc['db_query']('', '
483 495
 			DELETE FROM {db_prefix}settings
484 496
 			WHERE variable IN ({array_string:remove})',
485 497
 			array(
486 498
 				'remove' => $toRemove,
487 499
 			)
488 500
 		);
501
+	}
489 502
 
490 503
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
491 504
 	if ($update)
@@ -514,19 +527,22 @@  discard block
 block discarded – undo
514 527
 	foreach ($changeArray as $variable => $value)
515 528
 	{
516 529
 		// Don't bother if it's already like that ;).
517
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
518
-			continue;
530
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
531
+					continue;
532
+		}
519 533
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
520
-		elseif (!isset($modSettings[$variable]) && empty($value))
521
-			continue;
534
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
535
+					continue;
536
+		}
522 537
 
523 538
 		$replaceArray[] = array($variable, $value);
524 539
 
525 540
 		$modSettings[$variable] = $value;
526 541
 	}
527 542
 
528
-	if (empty($replaceArray))
529
-		return;
543
+	if (empty($replaceArray)) {
544
+			return;
545
+	}
530 546
 
531 547
 	$smcFunc['db_insert']('replace',
532 548
 		'{db_prefix}settings',
@@ -572,14 +588,17 @@  discard block
 block discarded – undo
572 588
 	$start_invalid = $start < 0;
573 589
 
574 590
 	// Make sure $start is a proper variable - not less than 0.
575
-	if ($start_invalid)
576
-		$start = 0;
591
+	if ($start_invalid) {
592
+			$start = 0;
593
+	}
577 594
 	// Not greater than the upper bound.
578
-	elseif ($start >= $max_value)
579
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
595
+	elseif ($start >= $max_value) {
596
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
597
+	}
580 598
 	// And it has to be a multiple of $num_per_page!
581
-	else
582
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
599
+	else {
600
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	}
583 602
 
584 603
 	$context['current_page'] = $start / $num_per_page;
585 604
 
@@ -609,77 +628,87 @@  discard block
 block discarded – undo
609 628
 
610 629
 		// Show all the pages.
611 630
 		$display_page = 1;
612
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
613
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
631
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
632
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		}
614 634
 
615 635
 		// Show the right arrow.
616 636
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
617
-		if ($start != $counter - $max_value && !$start_invalid)
618
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
619
-	}
620
-	else
637
+		if ($start != $counter - $max_value && !$start_invalid) {
638
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
639
+		}
640
+	} else
621 641
 	{
622 642
 		// If they didn't enter an odd value, pretend they did.
623 643
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
624 644
 
625 645
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
626
-		if (!empty($start) && $show_prevnext)
627
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
628
-		else
629
-			$pageindex .= '';
646
+		if (!empty($start) && $show_prevnext) {
647
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
648
+		} else {
649
+					$pageindex .= '';
650
+		}
630 651
 
631 652
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
632
-		if ($start > $num_per_page * $PageContiguous)
633
-			$pageindex .= sprintf($base_link, 0, '1');
653
+		if ($start > $num_per_page * $PageContiguous) {
654
+					$pageindex .= sprintf($base_link, 0, '1');
655
+		}
634 656
 
635 657
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
636
-		if ($start > $num_per_page * ($PageContiguous + 1))
637
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
658
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
659
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
638 660
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
639 661
 				'{FIRST_PAGE}' => $num_per_page,
640 662
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
641 663
 				'{PER_PAGE}' => $num_per_page,
642 664
 			));
665
+		}
643 666
 
644 667
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
645
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
646
-			if ($start >= $num_per_page * $nCont)
668
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
669
+					if ($start >= $num_per_page * $nCont)
647 670
 			{
648 671
 				$tmpStart = $start - $num_per_page * $nCont;
672
+		}
649 673
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
650 674
 			}
651 675
 
652 676
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
653
-		if (!$start_invalid)
654
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
655
-		else
656
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
677
+		if (!$start_invalid) {
678
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
679
+		} else {
680
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
681
+		}
657 682
 
658 683
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
659 684
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
660
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
661
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
685
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
686
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
662 687
 			{
663 688
 				$tmpStart = $start + $num_per_page * $nCont;
689
+		}
664 690
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
665 691
 			}
666 692
 
667 693
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
668
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
669
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
694
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
695
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
670 696
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
671 697
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
672 698
 				'{LAST_PAGE}' => $tmpMaxPages,
673 699
 				'{PER_PAGE}' => $num_per_page,
674 700
 			));
701
+		}
675 702
 
676 703
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
677
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
678
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
704
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
705
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		}
679 707
 
680 708
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
681
-		if ($start != $tmpMaxPages && $show_prevnext)
682
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
709
+		if ($start != $tmpMaxPages && $show_prevnext) {
710
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		}
683 712
 	}
684 713
 	$pageindex .= $settings['page_index']['extra_after'];
685 714
 
@@ -705,8 +734,9 @@  discard block
 block discarded – undo
705 734
 	if ($decimal_separator === null)
706 735
 	{
707 736
 		// Not set for whatever reason?
708
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
709
-			return $number;
737
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
738
+					return $number;
739
+		}
710 740
 
711 741
 		// Cache these each load...
712 742
 		$thousands_separator = $matches[1];
@@ -745,17 +775,20 @@  discard block
 block discarded – undo
745 775
 	$user_info['time_format'] = !empty($user_info['time_format']) ? $user_info['time_format'] : (!empty($modSettings['time_format']) ? $modSettings['time_format'] : '%F %H:%M');
746 776
 
747 777
 	// Offset the time.
748
-	if (!$offset_type)
749
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
778
+	if (!$offset_type) {
779
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
780
+	}
750 781
 	// Just the forum offset?
751
-	elseif ($offset_type == 'forum')
752
-		$time = $log_time + $modSettings['time_offset'] * 3600;
753
-	else
754
-		$time = $log_time;
782
+	elseif ($offset_type == 'forum') {
783
+			$time = $log_time + $modSettings['time_offset'] * 3600;
784
+	} else {
785
+			$time = $log_time;
786
+	}
755 787
 
756 788
 	// We can't have a negative date (on Windows, at least.)
757
-	if ($log_time < 0)
758
-		$log_time = 0;
789
+	if ($log_time < 0) {
790
+			$log_time = 0;
791
+	}
759 792
 
760 793
 	// Today and Yesterday?
761 794
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -772,24 +805,27 @@  discard block
 block discarded – undo
772 805
 		{
773 806
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
774 807
 			$today_fmt = $h . ':%M' . $s . ' %p';
808
+		} else {
809
+					$today_fmt = '%H:%M' . $s;
775 810
 		}
776
-		else
777
-			$today_fmt = '%H:%M' . $s;
778 811
 
779 812
 		// Same day of the year, same year.... Today!
780
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
781
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
813
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
814
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
815
+		}
782 816
 
783 817
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
784
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
785
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
818
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
819
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
820
+		}
786 821
 	}
787 822
 
788 823
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
789 824
 
790 825
 	// Use the cached formats if available
791
-	if (is_null($finalizedFormats))
792
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
826
+	if (is_null($finalizedFormats)) {
827
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
828
+	}
793 829
 
794 830
 	// Make a supported version for this format if we don't already have one
795 831
 	if (empty($finalizedFormats[$str]))
@@ -818,8 +854,9 @@  discard block
 block discarded – undo
818 854
 		);
819 855
 
820 856
 		// No need to do this part again if we already did it once
821
-		if (is_null($unsupportedFormats))
822
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
857
+		if (is_null($unsupportedFormats)) {
858
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
859
+		}
823 860
 		if (empty($unsupportedFormats))
824 861
 		{
825 862
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -828,20 +865,23 @@  discard block
 block discarded – undo
828 865
 
829 866
 				// Windows will return false for unsupported formats
830 867
 				// Other operating systems return the format string as a literal
831
-				if ($value === false || $value === $format)
832
-					$unsupportedFormats[] = $format;
868
+				if ($value === false || $value === $format) {
869
+									$unsupportedFormats[] = $format;
870
+				}
833 871
 			}
834 872
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
835 873
 		}
836 874
 
837 875
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
838
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
839
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
876
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
877
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
878
+		}
840 879
 
841 880
 		// Substitute unsupported formats with supported ones
842
-		if (!empty($unsupportedFormats))
843
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
881
+		if (!empty($unsupportedFormats)) {
882
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
844 883
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
884
+		}
845 885
 
846 886
 		// Remember this so we don't need to do it again
847 887
 		$finalizedFormats[$str] = $timeformat;
@@ -850,33 +890,39 @@  discard block
 block discarded – undo
850 890
 
851 891
 	$str = $finalizedFormats[$str];
852 892
 
853
-	if (!isset($locale_cache))
854
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
893
+	if (!isset($locale_cache)) {
894
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
895
+	}
855 896
 
856 897
 	if ($locale_cache !== false)
857 898
 	{
858 899
 		// Check if another process changed the locale
859
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
860
-			setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
900
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
901
+					setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
902
+		}
861 903
 
862
-		if (!isset($non_twelve_hour))
863
-			$non_twelve_hour = trim(strftime('%p')) === '';
864
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
865
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
904
+		if (!isset($non_twelve_hour)) {
905
+					$non_twelve_hour = trim(strftime('%p')) === '';
906
+		}
907
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
908
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
909
+		}
866 910
 
867
-		foreach (array('%a', '%A', '%b', '%B') as $token)
868
-			if (strpos($str, $token) !== false)
911
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
912
+					if (strpos($str, $token) !== false)
869 913
 				$str = str_replace($token, strftime($token, $time), $str);
870
-	}
871
-	else
914
+		}
915
+	} else
872 916
 	{
873 917
 		// Do-it-yourself time localization.  Fun.
874
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
875
-			if (strpos($str, $token) !== false)
918
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
919
+					if (strpos($str, $token) !== false)
876 920
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
921
+		}
877 922
 
878
-		if (strpos($str, '%p') !== false)
879
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
923
+		if (strpos($str, '%p') !== false) {
924
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
925
+		}
880 926
 	}
881 927
 
882 928
 	// Format the time and then restore any literal percent characters
@@ -899,16 +945,19 @@  discard block
 block discarded – undo
899 945
 	static $translation = array();
900 946
 
901 947
 	// Determine the character set... Default to UTF-8
902
-	if (empty($context['character_set']))
903
-		$charset = 'UTF-8';
948
+	if (empty($context['character_set'])) {
949
+			$charset = 'UTF-8';
950
+	}
904 951
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
905
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
906
-		$charset = 'ISO-8859-1';
907
-	else
908
-		$charset = $context['character_set'];
952
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
953
+			$charset = 'ISO-8859-1';
954
+	} else {
955
+			$charset = $context['character_set'];
956
+	}
909 957
 
910
-	if (empty($translation))
911
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
958
+	if (empty($translation)) {
959
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
960
+	}
912 961
 
913 962
 	return strtr($string, $translation);
914 963
 }
@@ -930,8 +979,9 @@  discard block
 block discarded – undo
930 979
 	global $smcFunc;
931 980
 
932 981
 	// It was already short enough!
933
-	if ($smcFunc['strlen']($subject) <= $len)
934
-		return $subject;
982
+	if ($smcFunc['strlen']($subject) <= $len) {
983
+			return $subject;
984
+	}
935 985
 
936 986
 	// Shorten it by the length it was too long, and strip off junk from the end.
937 987
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -950,10 +1000,11 @@  discard block
 block discarded – undo
950 1000
 {
951 1001
 	global $user_info, $modSettings;
952 1002
 
953
-	if ($timestamp === null)
954
-		$timestamp = time();
955
-	elseif ($timestamp == 0)
956
-		return 0;
1003
+	if ($timestamp === null) {
1004
+			$timestamp = time();
1005
+	} elseif ($timestamp == 0) {
1006
+			return 0;
1007
+	}
957 1008
 
958 1009
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
959 1010
 }
@@ -982,8 +1033,9 @@  discard block
 block discarded – undo
982 1033
 		$array[$i] = $array[$j];
983 1034
 		$array[$j] = $temp;
984 1035
 
985
-		for ($i = 1; $p[$i] == 0; $i++)
986
-			$p[$i] = 1;
1036
+		for ($i = 1; $p[$i] == 0; $i++) {
1037
+					$p[$i] = 1;
1038
+		}
987 1039
 
988 1040
 		$orders[] = $array;
989 1041
 	}
@@ -1015,12 +1067,14 @@  discard block
 block discarded – undo
1015 1067
 	static $disabled;
1016 1068
 
1017 1069
 	// Don't waste cycles
1018
-	if ($message === '')
1019
-		return '';
1070
+	if ($message === '') {
1071
+			return '';
1072
+	}
1020 1073
 
1021 1074
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1022
-	if (!isset($context['utf8']))
1023
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1075
+	if (!isset($context['utf8'])) {
1076
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1077
+	}
1024 1078
 
1025 1079
 	// Clean up any cut/paste issues we may have
1026 1080
 	$message = sanitizeMSCutPaste($message);
@@ -1032,13 +1086,15 @@  discard block
 block discarded – undo
1032 1086
 		return $message;
1033 1087
 	}
1034 1088
 
1035
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1036
-		$smileys = (bool) $smileys;
1089
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1090
+			$smileys = (bool) $smileys;
1091
+	}
1037 1092
 
1038 1093
 	if (empty($modSettings['enableBBC']) && $message !== false)
1039 1094
 	{
1040
-		if ($smileys === true)
1041
-			parsesmileys($message);
1095
+		if ($smileys === true) {
1096
+					parsesmileys($message);
1097
+		}
1042 1098
 
1043 1099
 		return $message;
1044 1100
 	}
@@ -1051,8 +1107,9 @@  discard block
 block discarded – undo
1051 1107
 	}
1052 1108
 
1053 1109
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1054
-	if (!empty($modSettings['autoLinkUrls']))
1055
-		set_tld_regex();
1110
+	if (!empty($modSettings['autoLinkUrls'])) {
1111
+			set_tld_regex();
1112
+	}
1056 1113
 
1057 1114
 	// Allow mods access before entering the main parse_bbc loop
1058 1115
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1066,12 +1123,14 @@  discard block
 block discarded – undo
1066 1123
 
1067 1124
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1068 1125
 
1069
-			foreach ($temp as $tag)
1070
-				$disabled[trim($tag)] = true;
1126
+			foreach ($temp as $tag) {
1127
+							$disabled[trim($tag)] = true;
1128
+			}
1071 1129
 		}
1072 1130
 
1073
-		if (empty($modSettings['enableEmbeddedFlash']))
1074
-			$disabled['flash'] = true;
1131
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1132
+					$disabled['flash'] = true;
1133
+		}
1075 1134
 
1076 1135
 		/* The following bbc are formatted as an array, with keys as follows:
1077 1136
 
@@ -1192,8 +1251,9 @@  discard block
 block discarded – undo
1192 1251
 					$returnContext = '';
1193 1252
 
1194 1253
 					// BBC or the entire attachments feature is disabled
1195
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1196
-						return $data;
1254
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1255
+											return $data;
1256
+					}
1197 1257
 
1198 1258
 					// Save the attach ID.
1199 1259
 					$attachID = $data;
@@ -1204,8 +1264,9 @@  discard block
 block discarded – undo
1204 1264
 					$currentAttachment = parseAttachBBC($attachID);
1205 1265
 
1206 1266
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1207
-					if (is_string($currentAttachment))
1208
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1267
+					if (is_string($currentAttachment)) {
1268
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1269
+					}
1209 1270
 
1210 1271
 					if (!empty($currentAttachment['is_image']))
1211 1272
 					{
@@ -1221,15 +1282,17 @@  discard block
 block discarded – undo
1221 1282
 							$height = ' height="' . $currentAttachment['height'] . '"';
1222 1283
 						}
1223 1284
 
1224
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1225
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1226
-						else
1227
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1285
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1286
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1287
+						} else {
1288
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1289
+						}
1228 1290
 					}
1229 1291
 
1230 1292
 					// No image. Show a link.
1231
-					else
1232
-						$returnContext .= $currentAttachment['link'];
1293
+					else {
1294
+											$returnContext .= $currentAttachment['link'];
1295
+					}
1233 1296
 
1234 1297
 					// Gotta append what we just did.
1235 1298
 					$data = $returnContext;
@@ -1260,8 +1323,9 @@  discard block
 block discarded – undo
1260 1323
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1261 1324
 						{
1262 1325
 							// Do PHP code coloring?
1263
-							if ($php_parts[$php_i] != '&lt;?php')
1264
-								continue;
1326
+							if ($php_parts[$php_i] != '&lt;?php') {
1327
+															continue;
1328
+							}
1265 1329
 
1266 1330
 							$php_string = '';
1267 1331
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1277,8 +1341,9 @@  discard block
 block discarded – undo
1277 1341
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1278 1342
 
1279 1343
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1280
-						if ($context['browser']['is_opera'])
1281
-							$data .= '&nbsp;';
1344
+						if ($context['browser']['is_opera']) {
1345
+													$data .= '&nbsp;';
1346
+						}
1282 1347
 					}
1283 1348
 				},
1284 1349
 				'block_level' => true,
@@ -1297,8 +1362,9 @@  discard block
 block discarded – undo
1297 1362
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1298 1363
 						{
1299 1364
 							// Do PHP code coloring?
1300
-							if ($php_parts[$php_i] != '&lt;?php')
1301
-								continue;
1365
+							if ($php_parts[$php_i] != '&lt;?php') {
1366
+															continue;
1367
+							}
1302 1368
 
1303 1369
 							$php_string = '';
1304 1370
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1314,8 +1380,9 @@  discard block
 block discarded – undo
1314 1380
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1315 1381
 
1316 1382
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1317
-						if ($context['browser']['is_opera'])
1318
-							$data[0] .= '&nbsp;';
1383
+						if ($context['browser']['is_opera']) {
1384
+													$data[0] .= '&nbsp;';
1385
+						}
1319 1386
 					}
1320 1387
 				},
1321 1388
 				'block_level' => true,
@@ -1353,11 +1420,13 @@  discard block
 block discarded – undo
1353 1420
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1354 1421
 				'validate' => function (&$tag, &$data, $disabled)
1355 1422
 				{
1356
-					if (isset($disabled['url']))
1357
-						$tag['content'] = '$1';
1423
+					if (isset($disabled['url'])) {
1424
+											$tag['content'] = '$1';
1425
+					}
1358 1426
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1359
-					if (empty($scheme))
1360
-						$data[0] = '//' . ltrim($data[0], ':/');
1427
+					if (empty($scheme)) {
1428
+											$data[0] = '//' . ltrim($data[0], ':/');
1429
+					}
1361 1430
 				},
1362 1431
 				'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>',
1363 1432
 			),
@@ -1371,10 +1440,11 @@  discard block
 block discarded – undo
1371 1440
 				{
1372 1441
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1373 1442
 
1374
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1375
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1376
-					else
1377
-						$css = '';
1443
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1444
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1445
+					} else {
1446
+											$css = '';
1447
+					}
1378 1448
 
1379 1449
 					$data = $class . $css;
1380 1450
 				},
@@ -1424,17 +1494,20 @@  discard block
 block discarded – undo
1424 1494
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1425 1495
 					if ($image_proxy_enabled)
1426 1496
 					{
1427
-						if (!empty($user_info['possibly_robot']))
1428
-							return;
1497
+						if (!empty($user_info['possibly_robot'])) {
1498
+													return;
1499
+						}
1429 1500
 
1430
-						if (empty($scheme))
1431
-							$data = 'http://' . ltrim($data, ':/');
1501
+						if (empty($scheme)) {
1502
+													$data = 'http://' . ltrim($data, ':/');
1503
+						}
1432 1504
 
1433
-						if ($scheme != 'https')
1434
-							$data = get_proxied_url($data);
1505
+						if ($scheme != 'https') {
1506
+													$data = get_proxied_url($data);
1507
+						}
1508
+					} elseif (empty($scheme)) {
1509
+											$data = '//' . ltrim($data, ':/');
1435 1510
 					}
1436
-					elseif (empty($scheme))
1437
-						$data = '//' . ltrim($data, ':/');
1438 1511
 				},
1439 1512
 				'disabled_content' => '($1)',
1440 1513
 			),
@@ -1450,17 +1523,20 @@  discard block
 block discarded – undo
1450 1523
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1451 1524
 					if ($image_proxy_enabled)
1452 1525
 					{
1453
-						if (!empty($user_info['possibly_robot']))
1454
-							return;
1526
+						if (!empty($user_info['possibly_robot'])) {
1527
+													return;
1528
+						}
1455 1529
 
1456
-						if (empty($scheme))
1457
-							$data = 'http://' . ltrim($data, ':/');
1530
+						if (empty($scheme)) {
1531
+													$data = 'http://' . ltrim($data, ':/');
1532
+						}
1458 1533
 
1459
-						if ($scheme != 'https')
1460
-							$data = get_proxied_url($data);
1534
+						if ($scheme != 'https') {
1535
+													$data = get_proxied_url($data);
1536
+						}
1537
+					} elseif (empty($scheme)) {
1538
+											$data = '//' . ltrim($data, ':/');
1461 1539
 					}
1462
-					elseif (empty($scheme))
1463
-						$data = '//' . ltrim($data, ':/');
1464 1540
 				},
1465 1541
 				'disabled_content' => '($1)',
1466 1542
 			),
@@ -1472,8 +1548,9 @@  discard block
 block discarded – undo
1472 1548
 				{
1473 1549
 					$data = strtr($data, array('<br>' => ''));
1474 1550
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1475
-					if (empty($scheme))
1476
-						$data = '//' . ltrim($data, ':/');
1551
+					if (empty($scheme)) {
1552
+											$data = '//' . ltrim($data, ':/');
1553
+					}
1477 1554
 				},
1478 1555
 			),
1479 1556
 			array(
@@ -1484,13 +1561,14 @@  discard block
 block discarded – undo
1484 1561
 				'after' => '</a>',
1485 1562
 				'validate' => function (&$tag, &$data, $disabled)
1486 1563
 				{
1487
-					if (substr($data, 0, 1) == '#')
1488
-						$data = '#post_' . substr($data, 1);
1489
-					else
1564
+					if (substr($data, 0, 1) == '#') {
1565
+											$data = '#post_' . substr($data, 1);
1566
+					} else
1490 1567
 					{
1491 1568
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1492
-						if (empty($scheme))
1493
-							$data = '//' . ltrim($data, ':/');
1569
+						if (empty($scheme)) {
1570
+													$data = '//' . ltrim($data, ':/');
1571
+						}
1494 1572
 					}
1495 1573
 				},
1496 1574
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1574,8 +1652,9 @@  discard block
 block discarded – undo
1574 1652
 					{
1575 1653
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1576 1654
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1577
-						if ($add_begin)
1578
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1655
+						if ($add_begin) {
1656
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1657
+						}
1579 1658
 					}
1580 1659
 				},
1581 1660
 				'block_level' => false,
@@ -1706,10 +1785,11 @@  discard block
 block discarded – undo
1706 1785
 				'content' => '$1',
1707 1786
 				'validate' => function (&$tag, &$data, $disabled)
1708 1787
 				{
1709
-					if (is_numeric($data))
1710
-						$data = timeformat($data);
1711
-					else
1712
-						$tag['content'] = '[time]$1[/time]';
1788
+					if (is_numeric($data)) {
1789
+											$data = timeformat($data);
1790
+					} else {
1791
+											$tag['content'] = '[time]$1[/time]';
1792
+					}
1713 1793
 				},
1714 1794
 			),
1715 1795
 			array(
@@ -1736,8 +1816,9 @@  discard block
 block discarded – undo
1736 1816
 				{
1737 1817
 					$data = strtr($data, array('<br>' => ''));
1738 1818
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1739
-					if (empty($scheme))
1740
-						$data = '//' . ltrim($data, ':/');
1819
+					if (empty($scheme)) {
1820
+											$data = '//' . ltrim($data, ':/');
1821
+					}
1741 1822
 				},
1742 1823
 			),
1743 1824
 			array(
@@ -1749,8 +1830,9 @@  discard block
 block discarded – undo
1749 1830
 				'validate' => function (&$tag, &$data, $disabled)
1750 1831
 				{
1751 1832
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1752
-					if (empty($scheme))
1753
-						$data = '//' . ltrim($data, ':/');
1833
+					if (empty($scheme)) {
1834
+											$data = '//' . ltrim($data, ':/');
1835
+					}
1754 1836
 				},
1755 1837
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1756 1838
 				'disabled_after' => ' ($1)',
@@ -1776,8 +1858,9 @@  discard block
 block discarded – undo
1776 1858
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1777 1859
 		if ($message === false)
1778 1860
 		{
1779
-			if (isset($temp_bbc))
1780
-				$bbc_codes = $temp_bbc;
1861
+			if (isset($temp_bbc)) {
1862
+							$bbc_codes = $temp_bbc;
1863
+			}
1781 1864
 			usort($codes, function ($a, $b) {
1782 1865
 				return strcmp($a['tag'], $b['tag']);
1783 1866
 			});
@@ -1797,8 +1880,9 @@  discard block
 block discarded – undo
1797 1880
 		);
1798 1881
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1799 1882
 		{
1800
-			foreach ($itemcodes as $c => $dummy)
1801
-				$bbc_codes[$c] = array();
1883
+			foreach ($itemcodes as $c => $dummy) {
1884
+							$bbc_codes[$c] = array();
1885
+			}
1802 1886
 		}
1803 1887
 
1804 1888
 		// Shhhh!
@@ -1819,12 +1903,14 @@  discard block
 block discarded – undo
1819 1903
 		foreach ($codes as $code)
1820 1904
 		{
1821 1905
 			// Make it easier to process parameters later
1822
-			if (!empty($code['parameters']))
1823
-				ksort($code['parameters'], SORT_STRING);
1906
+			if (!empty($code['parameters'])) {
1907
+							ksort($code['parameters'], SORT_STRING);
1908
+			}
1824 1909
 
1825 1910
 			// If we are not doing every tag only do ones we are interested in.
1826
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1827
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1911
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1912
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1913
+			}
1828 1914
 		}
1829 1915
 		$codes = null;
1830 1916
 	}
@@ -1835,8 +1921,9 @@  discard block
 block discarded – undo
1835 1921
 		// It's likely this will change if the message is modified.
1836 1922
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1837 1923
 
1838
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1839
-			return $temp;
1924
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1925
+					return $temp;
1926
+		}
1840 1927
 
1841 1928
 		$cache_t = microtime();
1842 1929
 	}
@@ -1868,8 +1955,9 @@  discard block
 block discarded – undo
1868 1955
 		$disabled['flash'] = true;
1869 1956
 
1870 1957
 		// @todo Change maybe?
1871
-		if (!isset($_GET['images']))
1872
-			$disabled['img'] = true;
1958
+		if (!isset($_GET['images'])) {
1959
+					$disabled['img'] = true;
1960
+		}
1873 1961
 
1874 1962
 		// @todo Interface/setting to add more?
1875 1963
 	}
@@ -1880,8 +1968,9 @@  discard block
 block discarded – undo
1880 1968
 	$alltags = array();
1881 1969
 	foreach ($bbc_codes as $section)
1882 1970
 	{
1883
-		foreach ($section as $code)
1884
-			$alltags[] = $code['tag'];
1971
+		foreach ($section as $code) {
1972
+					$alltags[] = $code['tag'];
1973
+		}
1885 1974
 	}
1886 1975
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
1887 1976
 
@@ -1893,8 +1982,9 @@  discard block
 block discarded – undo
1893 1982
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1894 1983
 
1895 1984
 		// Failsafe.
1896
-		if ($pos === false || $last_pos > $pos)
1897
-			$pos = strlen($message) + 1;
1985
+		if ($pos === false || $last_pos > $pos) {
1986
+					$pos = strlen($message) + 1;
1987
+		}
1898 1988
 
1899 1989
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1900 1990
 		if ($last_pos < $pos - 1)
@@ -1912,8 +2002,9 @@  discard block
 block discarded – undo
1912 2002
 
1913 2003
 				// <br> should be empty.
1914 2004
 				$empty_tags = array('br', 'hr');
1915
-				foreach ($empty_tags as $tag)
1916
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2005
+				foreach ($empty_tags as $tag) {
2006
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2007
+				}
1917 2008
 
1918 2009
 				// b, u, i, s, pre... basic tags.
1919 2010
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -1922,8 +2013,9 @@  discard block
 block discarded – undo
1922 2013
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1923 2014
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1924 2015
 
1925
-					if ($diff > 0)
1926
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2016
+					if ($diff > 0) {
2017
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2018
+					}
1927 2019
 				}
1928 2020
 
1929 2021
 				// Do <img ...> - with security... action= -> action-.
@@ -1936,8 +2028,9 @@  discard block
 block discarded – undo
1936 2028
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1937 2029
 
1938 2030
 						// Remove action= from the URL - no funny business, now.
1939
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1940
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2031
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2032
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2033
+						}
1941 2034
 
1942 2035
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1943 2036
 					}
@@ -1952,16 +2045,18 @@  discard block
 block discarded – undo
1952 2045
 				$no_autolink_area = false;
1953 2046
 				if (!empty($open_tags))
1954 2047
 				{
1955
-					foreach ($open_tags as $open_tag)
1956
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2048
+					foreach ($open_tags as $open_tag) {
2049
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1957 2050
 							$no_autolink_area = true;
2051
+					}
1958 2052
 				}
1959 2053
 
1960 2054
 				// Don't go backwards.
1961 2055
 				// @todo Don't think is the real solution....
1962 2056
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1963
-				if ($pos < $lastAutoPos)
1964
-					$no_autolink_area = true;
2057
+				if ($pos < $lastAutoPos) {
2058
+									$no_autolink_area = true;
2059
+				}
1965 2060
 				$lastAutoPos = $pos;
1966 2061
 
1967 2062
 				if (!$no_autolink_area)
@@ -2066,29 +2161,33 @@  discard block
 block discarded – undo
2066 2161
 							$url = array_shift($matches);
2067 2162
 
2068 2163
 							// If this isn't a clean URL, bail out
2069
-							if ($url != sanitize_iri($url))
2070
-								return $url;
2164
+							if ($url != sanitize_iri($url)) {
2165
+															return $url;
2166
+							}
2071 2167
 
2072 2168
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2073 2169
 
2074 2170
 							if ($scheme == 'mailto')
2075 2171
 							{
2076 2172
 								$email_address = str_replace('mailto:', '', $url);
2077
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2078
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2079
-								else
2080
-									return $url;
2173
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2174
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2175
+								} else {
2176
+																	return $url;
2177
+								}
2081 2178
 							}
2082 2179
 
2083 2180
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2084
-							if (empty($scheme))
2085
-								$fullUrl = '//' . ltrim($url, ':/');
2086
-							else
2087
-								$fullUrl = $url;
2181
+							if (empty($scheme)) {
2182
+															$fullUrl = '//' . ltrim($url, ':/');
2183
+							} else {
2184
+															$fullUrl = $url;
2185
+							}
2088 2186
 
2089 2187
 							// Make sure that $fullUrl really is valid
2090
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2091
-								return $url;
2188
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2189
+															return $url;
2190
+							}
2092 2191
 
2093 2192
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2094 2193
 						}, $data);
@@ -2137,22 +2236,25 @@  discard block
 block discarded – undo
2137 2236
 		}
2138 2237
 
2139 2238
 		// Are we there yet?  Are we there yet?
2140
-		if ($pos >= strlen($message) - 1)
2141
-			break;
2239
+		if ($pos >= strlen($message) - 1) {
2240
+					break;
2241
+		}
2142 2242
 
2143 2243
 		$tags = strtolower($message[$pos + 1]);
2144 2244
 
2145 2245
 		if ($tags == '/' && !empty($open_tags))
2146 2246
 		{
2147 2247
 			$pos2 = strpos($message, ']', $pos + 1);
2148
-			if ($pos2 == $pos + 2)
2149
-				continue;
2248
+			if ($pos2 == $pos + 2) {
2249
+							continue;
2250
+			}
2150 2251
 
2151 2252
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2152 2253
 
2153 2254
 			// A closing tag that doesn't match any open tags? Skip it.
2154
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2155
-				continue;
2255
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2256
+							continue;
2257
+			}
2156 2258
 
2157 2259
 			$to_close = array();
2158 2260
 			$block_level = null;
@@ -2160,8 +2262,9 @@  discard block
 block discarded – undo
2160 2262
 			do
2161 2263
 			{
2162 2264
 				$tag = array_pop($open_tags);
2163
-				if (!$tag)
2164
-					break;
2265
+				if (!$tag) {
2266
+									break;
2267
+				}
2165 2268
 
2166 2269
 				if (!empty($tag['block_level']))
2167 2270
 				{
@@ -2175,10 +2278,11 @@  discard block
 block discarded – undo
2175 2278
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2176 2279
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2177 2280
 					{
2178
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2179
-							if ($temp['tag'] == $look_for)
2281
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2282
+													if ($temp['tag'] == $look_for)
2180 2283
 							{
2181 2284
 								$block_level = !empty($temp['block_level']);
2285
+						}
2182 2286
 								break;
2183 2287
 							}
2184 2288
 					}
@@ -2200,15 +2304,15 @@  discard block
 block discarded – undo
2200 2304
 			{
2201 2305
 				$open_tags = $to_close;
2202 2306
 				continue;
2203
-			}
2204
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2307
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2205 2308
 			{
2206 2309
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2207 2310
 				{
2208
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2209
-						if ($temp['tag'] == $look_for)
2311
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2312
+											if ($temp['tag'] == $look_for)
2210 2313
 						{
2211 2314
 							$block_level = !empty($temp['block_level']);
2315
+					}
2212 2316
 							break;
2213 2317
 						}
2214 2318
 				}
@@ -2216,8 +2320,9 @@  discard block
 block discarded – undo
2216 2320
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2217 2321
 				if (!$block_level)
2218 2322
 				{
2219
-					foreach ($to_close as $tag)
2220
-						array_push($open_tags, $tag);
2323
+					foreach ($to_close as $tag) {
2324
+											array_push($open_tags, $tag);
2325
+					}
2221 2326
 					continue;
2222 2327
 				}
2223 2328
 			}
@@ -2230,14 +2335,17 @@  discard block
 block discarded – undo
2230 2335
 
2231 2336
 				// See the comment at the end of the big loop - just eating whitespace ;).
2232 2337
 				$whitespace_regex = '';
2233
-				if (!empty($tag['block_level']))
2234
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2338
+				if (!empty($tag['block_level'])) {
2339
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2340
+				}
2235 2341
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2236
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2237
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2342
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2343
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2344
+				}
2238 2345
 
2239
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2240
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2346
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2347
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2348
+				}
2241 2349
 			}
2242 2350
 
2243 2351
 			if (!empty($to_close))
@@ -2250,8 +2358,9 @@  discard block
 block discarded – undo
2250 2358
 		}
2251 2359
 
2252 2360
 		// No tags for this character, so just keep going (fastest possible course.)
2253
-		if (!isset($bbc_codes[$tags]))
2254
-			continue;
2361
+		if (!isset($bbc_codes[$tags])) {
2362
+					continue;
2363
+		}
2255 2364
 
2256 2365
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2257 2366
 		$tag = null;
@@ -2260,48 +2369,57 @@  discard block
 block discarded – undo
2260 2369
 			$pt_strlen = strlen($possible['tag']);
2261 2370
 
2262 2371
 			// Not a match?
2263
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2264
-				continue;
2372
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2373
+							continue;
2374
+			}
2265 2375
 
2266 2376
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2267 2377
 
2268 2378
 			// A tag is the last char maybe
2269
-			if ($next_c == '')
2270
-				break;
2379
+			if ($next_c == '') {
2380
+							break;
2381
+			}
2271 2382
 
2272 2383
 			// A test validation?
2273
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2274
-				continue;
2384
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2385
+							continue;
2386
+			}
2275 2387
 			// Do we want parameters?
2276 2388
 			elseif (!empty($possible['parameters']))
2277 2389
 			{
2278
-				if ($next_c != ' ')
2279
-					continue;
2280
-			}
2281
-			elseif (isset($possible['type']))
2390
+				if ($next_c != ' ') {
2391
+									continue;
2392
+				}
2393
+			} elseif (isset($possible['type']))
2282 2394
 			{
2283 2395
 				// Do we need an equal sign?
2284
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2285
-					continue;
2396
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2397
+									continue;
2398
+				}
2286 2399
 				// Maybe we just want a /...
2287
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2288
-					continue;
2400
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2401
+									continue;
2402
+				}
2289 2403
 				// An immediate ]?
2290
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2291
-					continue;
2404
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2405
+									continue;
2406
+				}
2292 2407
 			}
2293 2408
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2294
-			elseif ($next_c != ']')
2295
-				continue;
2409
+			elseif ($next_c != ']') {
2410
+							continue;
2411
+			}
2296 2412
 
2297 2413
 			// Check allowed tree?
2298
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2299
-				continue;
2300
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2301
-				continue;
2414
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2415
+							continue;
2416
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2417
+							continue;
2418
+			}
2302 2419
 			// If this is in the list of disallowed child tags, don't parse it.
2303
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2304
-				continue;
2420
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2421
+							continue;
2422
+			}
2305 2423
 
2306 2424
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2307 2425
 
@@ -2313,8 +2431,9 @@  discard block
 block discarded – undo
2313 2431
 				foreach ($open_tags as $open_quote)
2314 2432
 				{
2315 2433
 					// Every parent quote this quote has flips the styling
2316
-					if ($open_quote['tag'] == 'quote')
2317
-						$quote_alt = !$quote_alt;
2434
+					if ($open_quote['tag'] == 'quote') {
2435
+											$quote_alt = !$quote_alt;
2436
+					}
2318 2437
 				}
2319 2438
 				// Add a class to the quote to style alternating blockquotes
2320 2439
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2325,8 +2444,9 @@  discard block
 block discarded – undo
2325 2444
 			{
2326 2445
 				// Build a regular expression for each parameter for the current tag.
2327 2446
 				$preg = array();
2328
-				foreach ($possible['parameters'] as $p => $info)
2329
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2447
+				foreach ($possible['parameters'] as $p => $info) {
2448
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2449
+				}
2330 2450
 
2331 2451
 				// Extract the string that potentially holds our parameters.
2332 2452
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2345,24 +2465,27 @@  discard block
 block discarded – undo
2345 2465
 
2346 2466
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2347 2467
 
2348
-					if ($match)
2349
-						$blob_counter = count($blobs) + 1;
2468
+					if ($match) {
2469
+											$blob_counter = count($blobs) + 1;
2470
+					}
2350 2471
 				}
2351 2472
 
2352 2473
 				// Didn't match our parameter list, try the next possible.
2353
-				if (!$match)
2354
-					continue;
2474
+				if (!$match) {
2475
+									continue;
2476
+				}
2355 2477
 
2356 2478
 				$params = array();
2357 2479
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2358 2480
 				{
2359 2481
 					$key = strtok(ltrim($matches[$i]), '=');
2360
-					if (isset($possible['parameters'][$key]['value']))
2361
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2362
-					elseif (isset($possible['parameters'][$key]['validate']))
2363
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2364
-					else
2365
-						$params['{' . $key . '}'] = $matches[$i + 1];
2482
+					if (isset($possible['parameters'][$key]['value'])) {
2483
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2484
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2485
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2486
+					} else {
2487
+											$params['{' . $key . '}'] = $matches[$i + 1];
2488
+					}
2366 2489
 
2367 2490
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2368 2491
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2370,23 +2493,26 @@  discard block
 block discarded – undo
2370 2493
 
2371 2494
 				foreach ($possible['parameters'] as $p => $info)
2372 2495
 				{
2373
-					if (!isset($params['{' . $p . '}']))
2374
-						$params['{' . $p . '}'] = '';
2496
+					if (!isset($params['{' . $p . '}'])) {
2497
+											$params['{' . $p . '}'] = '';
2498
+					}
2375 2499
 				}
2376 2500
 
2377 2501
 				$tag = $possible;
2378 2502
 
2379 2503
 				// Put the parameters into the string.
2380
-				if (isset($tag['before']))
2381
-					$tag['before'] = strtr($tag['before'], $params);
2382
-				if (isset($tag['after']))
2383
-					$tag['after'] = strtr($tag['after'], $params);
2384
-				if (isset($tag['content']))
2385
-					$tag['content'] = strtr($tag['content'], $params);
2504
+				if (isset($tag['before'])) {
2505
+									$tag['before'] = strtr($tag['before'], $params);
2506
+				}
2507
+				if (isset($tag['after'])) {
2508
+									$tag['after'] = strtr($tag['after'], $params);
2509
+				}
2510
+				if (isset($tag['content'])) {
2511
+									$tag['content'] = strtr($tag['content'], $params);
2512
+				}
2386 2513
 
2387 2514
 				$pos1 += strlen($given_param_string);
2388
-			}
2389
-			else
2515
+			} else
2390 2516
 			{
2391 2517
 				$tag = $possible;
2392 2518
 				$params = array();
@@ -2397,8 +2523,9 @@  discard block
 block discarded – undo
2397 2523
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2398 2524
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2399 2525
 		{
2400
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2401
-				continue;
2526
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2527
+							continue;
2528
+			}
2402 2529
 
2403 2530
 			$tag = $itemcodes[$message[$pos + 1]];
2404 2531
 
@@ -2419,9 +2546,9 @@  discard block
 block discarded – undo
2419 2546
 			{
2420 2547
 				array_pop($open_tags);
2421 2548
 				$code = '</li>';
2549
+			} else {
2550
+							$code = '';
2422 2551
 			}
2423
-			else
2424
-				$code = '';
2425 2552
 
2426 2553
 			// Now we open a new tag.
2427 2554
 			$open_tags[] = array(
@@ -2468,12 +2595,14 @@  discard block
 block discarded – undo
2468 2595
 		}
2469 2596
 
2470 2597
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2471
-		if ($tag === null)
2472
-			continue;
2598
+		if ($tag === null) {
2599
+					continue;
2600
+		}
2473 2601
 
2474 2602
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2475
-		if (isset($inside['disallow_children']))
2476
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2603
+		if (isset($inside['disallow_children'])) {
2604
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2605
+		}
2477 2606
 
2478 2607
 		// Is this tag disabled?
2479 2608
 		if (isset($disabled[$tag['tag']]))
@@ -2483,14 +2612,13 @@  discard block
 block discarded – undo
2483 2612
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2484 2613
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2485 2614
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2486
-			}
2487
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2615
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2488 2616
 			{
2489 2617
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2490 2618
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2619
+			} else {
2620
+							$tag['content'] = $tag['disabled_content'];
2491 2621
 			}
2492
-			else
2493
-				$tag['content'] = $tag['disabled_content'];
2494 2622
 		}
2495 2623
 
2496 2624
 		// we use this a lot
@@ -2500,8 +2628,9 @@  discard block
 block discarded – undo
2500 2628
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2501 2629
 		{
2502 2630
 			$n = count($open_tags) - 1;
2503
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2504
-				$n--;
2631
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2632
+							$n--;
2633
+			}
2505 2634
 
2506 2635
 			// Close all the non block level tags so this tag isn't surrounded by them.
2507 2636
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2513,12 +2642,15 @@  discard block
 block discarded – undo
2513 2642
 
2514 2643
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2515 2644
 				$whitespace_regex = '';
2516
-				if (!empty($tag['block_level']))
2517
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2518
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2519
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2520
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2521
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2645
+				if (!empty($tag['block_level'])) {
2646
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2647
+				}
2648
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2649
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2650
+				}
2651
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2652
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2653
+				}
2522 2654
 
2523 2655
 				array_pop($open_tags);
2524 2656
 			}
@@ -2539,16 +2671,19 @@  discard block
 block discarded – undo
2539 2671
 		elseif ($tag['type'] == 'unparsed_content')
2540 2672
 		{
2541 2673
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2542
-			if ($pos2 === false)
2543
-				continue;
2674
+			if ($pos2 === false) {
2675
+							continue;
2676
+			}
2544 2677
 
2545 2678
 			$data = substr($message, $pos1, $pos2 - $pos1);
2546 2679
 
2547
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2548
-				$data = substr($data, 4);
2680
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2681
+							$data = substr($data, 4);
2682
+			}
2549 2683
 
2550
-			if (isset($tag['validate']))
2551
-				$tag['validate']($tag, $data, $disabled, $params);
2684
+			if (isset($tag['validate'])) {
2685
+							$tag['validate']($tag, $data, $disabled, $params);
2686
+			}
2552 2687
 
2553 2688
 			$code = strtr($tag['content'], array('$1' => $data));
2554 2689
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2563,34 +2698,40 @@  discard block
 block discarded – undo
2563 2698
 			if (isset($tag['quoted']))
2564 2699
 			{
2565 2700
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2566
-				if ($tag['quoted'] != 'optional' && !$quoted)
2567
-					continue;
2701
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2702
+									continue;
2703
+				}
2568 2704
 
2569
-				if ($quoted)
2570
-					$pos1 += 6;
2705
+				if ($quoted) {
2706
+									$pos1 += 6;
2707
+				}
2708
+			} else {
2709
+							$quoted = false;
2571 2710
 			}
2572
-			else
2573
-				$quoted = false;
2574 2711
 
2575 2712
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2576
-			if ($pos2 === false)
2577
-				continue;
2713
+			if ($pos2 === false) {
2714
+							continue;
2715
+			}
2578 2716
 
2579 2717
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2580
-			if ($pos3 === false)
2581
-				continue;
2718
+			if ($pos3 === false) {
2719
+							continue;
2720
+			}
2582 2721
 
2583 2722
 			$data = array(
2584 2723
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2585 2724
 				substr($message, $pos1, $pos2 - $pos1)
2586 2725
 			);
2587 2726
 
2588
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2589
-				$data[0] = substr($data[0], 4);
2727
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2728
+							$data[0] = substr($data[0], 4);
2729
+			}
2590 2730
 
2591 2731
 			// Validation for my parking, please!
2592
-			if (isset($tag['validate']))
2593
-				$tag['validate']($tag, $data, $disabled, $params);
2732
+			if (isset($tag['validate'])) {
2733
+							$tag['validate']($tag, $data, $disabled, $params);
2734
+			}
2594 2735
 
2595 2736
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2596 2737
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2607,23 +2748,27 @@  discard block
 block discarded – undo
2607 2748
 		elseif ($tag['type'] == 'unparsed_commas_content')
2608 2749
 		{
2609 2750
 			$pos2 = strpos($message, ']', $pos1);
2610
-			if ($pos2 === false)
2611
-				continue;
2751
+			if ($pos2 === false) {
2752
+							continue;
2753
+			}
2612 2754
 
2613 2755
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2614
-			if ($pos3 === false)
2615
-				continue;
2756
+			if ($pos3 === false) {
2757
+							continue;
2758
+			}
2616 2759
 
2617 2760
 			// We want $1 to be the content, and the rest to be csv.
2618 2761
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2619 2762
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2620 2763
 
2621
-			if (isset($tag['validate']))
2622
-				$tag['validate']($tag, $data, $disabled, $params);
2764
+			if (isset($tag['validate'])) {
2765
+							$tag['validate']($tag, $data, $disabled, $params);
2766
+			}
2623 2767
 
2624 2768
 			$code = $tag['content'];
2625
-			foreach ($data as $k => $d)
2626
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2769
+			foreach ($data as $k => $d) {
2770
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2771
+			}
2627 2772
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2628 2773
 			$pos += strlen($code) - 1 + 2;
2629 2774
 		}
@@ -2631,24 +2776,28 @@  discard block
 block discarded – undo
2631 2776
 		elseif ($tag['type'] == 'unparsed_commas')
2632 2777
 		{
2633 2778
 			$pos2 = strpos($message, ']', $pos1);
2634
-			if ($pos2 === false)
2635
-				continue;
2779
+			if ($pos2 === false) {
2780
+							continue;
2781
+			}
2636 2782
 
2637 2783
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2638 2784
 
2639
-			if (isset($tag['validate']))
2640
-				$tag['validate']($tag, $data, $disabled, $params);
2785
+			if (isset($tag['validate'])) {
2786
+							$tag['validate']($tag, $data, $disabled, $params);
2787
+			}
2641 2788
 
2642 2789
 			// Fix after, for disabled code mainly.
2643
-			foreach ($data as $k => $d)
2644
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2790
+			foreach ($data as $k => $d) {
2791
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2792
+			}
2645 2793
 
2646 2794
 			$open_tags[] = $tag;
2647 2795
 
2648 2796
 			// Replace them out, $1, $2, $3, $4, etc.
2649 2797
 			$code = $tag['before'];
2650
-			foreach ($data as $k => $d)
2651
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2798
+			foreach ($data as $k => $d) {
2799
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2800
+			}
2652 2801
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2653 2802
 			$pos += strlen($code) - 1 + 2;
2654 2803
 		}
@@ -2659,28 +2808,33 @@  discard block
 block discarded – undo
2659 2808
 			if (isset($tag['quoted']))
2660 2809
 			{
2661 2810
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2662
-				if ($tag['quoted'] != 'optional' && !$quoted)
2663
-					continue;
2811
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2812
+									continue;
2813
+				}
2664 2814
 
2665
-				if ($quoted)
2666
-					$pos1 += 6;
2815
+				if ($quoted) {
2816
+									$pos1 += 6;
2817
+				}
2818
+			} else {
2819
+							$quoted = false;
2667 2820
 			}
2668
-			else
2669
-				$quoted = false;
2670 2821
 
2671 2822
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2672
-			if ($pos2 === false)
2673
-				continue;
2823
+			if ($pos2 === false) {
2824
+							continue;
2825
+			}
2674 2826
 
2675 2827
 			$data = substr($message, $pos1, $pos2 - $pos1);
2676 2828
 
2677 2829
 			// Validation for my parking, please!
2678
-			if (isset($tag['validate']))
2679
-				$tag['validate']($tag, $data, $disabled, $params);
2830
+			if (isset($tag['validate'])) {
2831
+							$tag['validate']($tag, $data, $disabled, $params);
2832
+			}
2680 2833
 
2681 2834
 			// For parsed content, we must recurse to avoid security problems.
2682
-			if ($tag['type'] != 'unparsed_equals')
2683
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2835
+			if ($tag['type'] != 'unparsed_equals') {
2836
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2837
+			}
2684 2838
 
2685 2839
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2686 2840
 
@@ -2692,34 +2846,40 @@  discard block
 block discarded – undo
2692 2846
 		}
2693 2847
 
2694 2848
 		// If this is block level, eat any breaks after it.
2695
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2696
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2849
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2850
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2851
+		}
2697 2852
 
2698 2853
 		// Are we trimming outside this tag?
2699
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2700
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2854
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2855
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2856
+		}
2701 2857
 	}
2702 2858
 
2703 2859
 	// Close any remaining tags.
2704
-	while ($tag = array_pop($open_tags))
2705
-		$message .= "\n" . $tag['after'] . "\n";
2860
+	while ($tag = array_pop($open_tags)) {
2861
+			$message .= "\n" . $tag['after'] . "\n";
2862
+	}
2706 2863
 
2707 2864
 	// Parse the smileys within the parts where it can be done safely.
2708 2865
 	if ($smileys === true)
2709 2866
 	{
2710 2867
 		$message_parts = explode("\n", $message);
2711
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2712
-			parsesmileys($message_parts[$i]);
2868
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2869
+					parsesmileys($message_parts[$i]);
2870
+		}
2713 2871
 
2714 2872
 		$message = implode('', $message_parts);
2715 2873
 	}
2716 2874
 
2717 2875
 	// No smileys, just get rid of the markers.
2718
-	else
2719
-		$message = strtr($message, array("\n" => ''));
2876
+	else {
2877
+			$message = strtr($message, array("\n" => ''));
2878
+	}
2720 2879
 
2721
-	if ($message !== '' && $message[0] === ' ')
2722
-		$message = '&nbsp;' . substr($message, 1);
2880
+	if ($message !== '' && $message[0] === ' ') {
2881
+			$message = '&nbsp;' . substr($message, 1);
2882
+	}
2723 2883
 
2724 2884
 	// Cleanup whitespace.
2725 2885
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2728,15 +2888,16 @@  discard block
 block discarded – undo
2728 2888
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2729 2889
 
2730 2890
 	// Cache the output if it took some time...
2731
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2732
-		cache_put_data($cache_key, $message, 240);
2891
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2892
+			cache_put_data($cache_key, $message, 240);
2893
+	}
2733 2894
 
2734 2895
 	// If this was a force parse revert if needed.
2735 2896
 	if (!empty($parse_tags))
2736 2897
 	{
2737
-		if (empty($temp_bbc))
2738
-			$bbc_codes = array();
2739
-		else
2898
+		if (empty($temp_bbc)) {
2899
+					$bbc_codes = array();
2900
+		} else
2740 2901
 		{
2741 2902
 			$bbc_codes = $temp_bbc;
2742 2903
 			unset($temp_bbc);
@@ -2763,8 +2924,9 @@  discard block
 block discarded – undo
2763 2924
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2764 2925
 
2765 2926
 	// No smiley set at all?!
2766
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2767
-		return;
2927
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2928
+			return;
2929
+	}
2768 2930
 
2769 2931
 	// If smileyPregSearch hasn't been set, do it now.
2770 2932
 	if (empty($smileyPregSearch))
@@ -2775,8 +2937,7 @@  discard block
 block discarded – undo
2775 2937
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2776 2938
 			$smileysto = array('evil.png', 'cheesy.png', 'rolleyes.png', 'angry.png', 'laugh.png', 'smiley.png', 'wink.png', 'grin.png', 'sad.png', 'shocked.png', 'cool.png', 'tongue.png', 'huh.png', 'embarrassed.png', 'lipsrsealed.png', 'kiss.png', 'cry.png', 'undecided.png', 'azn.png', 'afro.png', 'police.png', 'angel.png');
2777 2939
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2778
-		}
2779
-		else
2940
+		} else
2780 2941
 		{
2781 2942
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2782 2943
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2800,9 +2961,9 @@  discard block
 block discarded – undo
2800 2961
 				$smcFunc['db_free_result']($result);
2801 2962
 
2802 2963
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2964
+			} else {
2965
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2803 2966
 			}
2804
-			else
2805
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2806 2967
 		}
2807 2968
 
2808 2969
 		// The non-breaking-space is a complex thing...
@@ -2880,12 +3041,14 @@  discard block
 block discarded – undo
2880 3041
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
2881 3042
 
2882 3043
 	// Only use the proxy if enabled and necessary
2883
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
2884
-		return $url;
3044
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3045
+			return $url;
3046
+	}
2885 3047
 
2886 3048
 	// We don't need to proxy our own resources
2887
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
2888
-		return strtr($url, array('http://' => 'https://'));
3049
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3050
+			return strtr($url, array('http://' => 'https://'));
3051
+	}
2889 3052
 
2890 3053
 	// By default, use SMF's own image proxy script
2891 3054
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -2910,35 +3073,41 @@  discard block
 block discarded – undo
2910 3073
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2911 3074
 
2912 3075
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2913
-	if (!empty($context['flush_mail']))
2914
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3076
+	if (!empty($context['flush_mail'])) {
3077
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2915 3078
 		AddMailQueue(true);
3079
+	}
2916 3080
 
2917 3081
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2918 3082
 
2919
-	if ($add)
2920
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3083
+	if ($add) {
3084
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3085
+	}
2921 3086
 
2922 3087
 	// Put the session ID in.
2923
-	if (defined('SID') && SID != '')
2924
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3088
+	if (defined('SID') && SID != '') {
3089
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3090
+	}
2925 3091
 	// Keep that debug in their for template debugging!
2926
-	elseif (isset($_GET['debug']))
2927
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3092
+	elseif (isset($_GET['debug'])) {
3093
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3094
+	}
2928 3095
 
2929 3096
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2930 3097
 	{
2931
-		if (defined('SID') && SID != '')
2932
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3098
+		if (defined('SID') && SID != '') {
3099
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2933 3100
 				function ($m) use ($scripturl)
2934 3101
 				{
2935 3102
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3103
+		}
2936 3104
 				}, $setLocation);
2937
-		else
2938
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3105
+		else {
3106
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2939 3107
 				function ($m) use ($scripturl)
2940 3108
 				{
2941 3109
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3110
+		}
2942 3111
 				}, $setLocation);
2943 3112
 	}
2944 3113
 
@@ -2949,8 +3118,9 @@  discard block
 block discarded – undo
2949 3118
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2950 3119
 
2951 3120
 	// Debugging.
2952
-	if (isset($db_show_debug) && $db_show_debug === true)
2953
-		$_SESSION['debug_redirect'] = $db_cache;
3121
+	if (isset($db_show_debug) && $db_show_debug === true) {
3122
+			$_SESSION['debug_redirect'] = $db_cache;
3123
+	}
2954 3124
 
2955 3125
 	obExit(false);
2956 3126
 }
@@ -2969,51 +3139,60 @@  discard block
 block discarded – undo
2969 3139
 
2970 3140
 	// Attempt to prevent a recursive loop.
2971 3141
 	++$level;
2972
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2973
-		exit;
2974
-	if ($from_fatal_error)
2975
-		$has_fatal_error = true;
3142
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3143
+			exit;
3144
+	}
3145
+	if ($from_fatal_error) {
3146
+			$has_fatal_error = true;
3147
+	}
2976 3148
 
2977 3149
 	// Clear out the stat cache.
2978 3150
 	trackStats();
2979 3151
 
2980 3152
 	// If we have mail to send, send it.
2981
-	if (!empty($context['flush_mail']))
2982
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3153
+	if (!empty($context['flush_mail'])) {
3154
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2983 3155
 		AddMailQueue(true);
3156
+	}
2984 3157
 
2985 3158
 	$do_header = $header === null ? !$header_done : $header;
2986
-	if ($do_footer === null)
2987
-		$do_footer = $do_header;
3159
+	if ($do_footer === null) {
3160
+			$do_footer = $do_header;
3161
+	}
2988 3162
 
2989 3163
 	// Has the template/header been done yet?
2990 3164
 	if ($do_header)
2991 3165
 	{
2992 3166
 		// Was the page title set last minute? Also update the HTML safe one.
2993
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2994
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3167
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3168
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3169
+		}
2995 3170
 
2996 3171
 		// Start up the session URL fixer.
2997 3172
 		ob_start('ob_sessrewrite');
2998 3173
 
2999
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
3000
-			$buffers = explode(',', $settings['output_buffers']);
3001
-		elseif (!empty($settings['output_buffers']))
3002
-			$buffers = $settings['output_buffers'];
3003
-		else
3004
-			$buffers = array();
3174
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3175
+					$buffers = explode(',', $settings['output_buffers']);
3176
+		} elseif (!empty($settings['output_buffers'])) {
3177
+					$buffers = $settings['output_buffers'];
3178
+		} else {
3179
+					$buffers = array();
3180
+		}
3005 3181
 
3006
-		if (isset($modSettings['integrate_buffer']))
3007
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3182
+		if (isset($modSettings['integrate_buffer'])) {
3183
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3184
+		}
3008 3185
 
3009
-		if (!empty($buffers))
3010
-			foreach ($buffers as $function)
3186
+		if (!empty($buffers)) {
3187
+					foreach ($buffers as $function)
3011 3188
 			{
3012 3189
 				$call = call_helper($function, true);
3190
+		}
3013 3191
 
3014 3192
 				// Is it valid?
3015
-				if (!empty($call))
3016
-					ob_start($call);
3193
+				if (!empty($call)) {
3194
+									ob_start($call);
3195
+				}
3017 3196
 			}
3018 3197
 
3019 3198
 		// Display the screen in the logical order.
@@ -3025,8 +3204,9 @@  discard block
 block discarded – undo
3025 3204
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3026 3205
 
3027 3206
 		// Anything special to put out?
3028
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3029
-			echo $context['insert_after_template'];
3207
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3208
+					echo $context['insert_after_template'];
3209
+		}
3030 3210
 
3031 3211
 		// Just so we don't get caught in an endless loop of errors from the footer...
3032 3212
 		if (!$footer_done)
@@ -3035,14 +3215,16 @@  discard block
 block discarded – undo
3035 3215
 			template_footer();
3036 3216
 
3037 3217
 			// (since this is just debugging... it's okay that it's after </html>.)
3038
-			if (!isset($_REQUEST['xml']))
3039
-				displayDebug();
3218
+			if (!isset($_REQUEST['xml'])) {
3219
+							displayDebug();
3220
+			}
3040 3221
 		}
3041 3222
 	}
3042 3223
 
3043 3224
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3044
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3045
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3225
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3226
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3227
+	}
3046 3228
 
3047 3229
 	// For session check verification.... don't switch browsers...
3048 3230
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3051,9 +3233,10 @@  discard block
 block discarded – undo
3051 3233
 	call_integration_hook('integrate_exit', array($do_footer));
3052 3234
 
3053 3235
 	// Don't exit if we're coming from index.php; that will pass through normally.
3054
-	if (!$from_index)
3055
-		exit;
3056
-}
3236
+	if (!$from_index) {
3237
+			exit;
3238
+	}
3239
+	}
3057 3240
 
3058 3241
 /**
3059 3242
  * Get the size of a specified image with better error handling.
@@ -3072,8 +3255,9 @@  discard block
 block discarded – undo
3072 3255
 	$url = str_replace(' ', '%20', $url);
3073 3256
 
3074 3257
 	// Can we pull this from the cache... please please?
3075
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3076
-		return $temp;
3258
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3259
+			return $temp;
3260
+	}
3077 3261
 	$t = microtime();
3078 3262
 
3079 3263
 	// Get the host to pester...
@@ -3083,12 +3267,10 @@  discard block
 block discarded – undo
3083 3267
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3084 3268
 	{
3085 3269
 		return false;
3086
-	}
3087
-	elseif (!isset($match[1]))
3270
+	} elseif (!isset($match[1]))
3088 3271
 	{
3089 3272
 		$size = @getimagesize($url);
3090
-	}
3091
-	else
3273
+	} else
3092 3274
 	{
3093 3275
 		// Try to connect to the server... give it half a second.
3094 3276
 		$temp = 0;
@@ -3125,12 +3307,14 @@  discard block
 block discarded – undo
3125 3307
 	}
3126 3308
 
3127 3309
 	// If we didn't get it, we failed.
3128
-	if (!isset($size))
3129
-		$size = false;
3310
+	if (!isset($size)) {
3311
+			$size = false;
3312
+	}
3130 3313
 
3131 3314
 	// If this took a long time, we may never have to do it again, but then again we might...
3132
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3133
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3315
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3316
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3317
+	}
3134 3318
 
3135 3319
 	// Didn't work.
3136 3320
 	return $size;
@@ -3148,8 +3332,9 @@  discard block
 block discarded – undo
3148 3332
 
3149 3333
 	// Under SSI this function can be called more then once.  That can cause some problems.
3150 3334
 	//   So only run the function once unless we are forced to run it again.
3151
-	if ($loaded && !$forceload)
3152
-		return;
3335
+	if ($loaded && !$forceload) {
3336
+			return;
3337
+	}
3153 3338
 
3154 3339
 	$loaded = true;
3155 3340
 
@@ -3161,14 +3346,16 @@  discard block
 block discarded – undo
3161 3346
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3162 3347
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3163 3348
 	{
3164
-		if (trim($context['news_lines'][$i]) == '')
3165
-			continue;
3349
+		if (trim($context['news_lines'][$i]) == '') {
3350
+					continue;
3351
+		}
3166 3352
 
3167 3353
 		// Clean it up for presentation ;).
3168 3354
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3169 3355
 	}
3170
-	if (!empty($context['news_lines']))
3171
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3356
+	if (!empty($context['news_lines'])) {
3357
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3358
+	}
3172 3359
 
3173 3360
 	if (!$user_info['is_guest'])
3174 3361
 	{
@@ -3177,40 +3364,48 @@  discard block
 block discarded – undo
3177 3364
 		$context['user']['alerts'] = &$user_info['alerts'];
3178 3365
 
3179 3366
 		// Personal message popup...
3180
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3181
-			$context['user']['popup_messages'] = true;
3182
-		else
3183
-			$context['user']['popup_messages'] = false;
3367
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3368
+					$context['user']['popup_messages'] = true;
3369
+		} else {
3370
+					$context['user']['popup_messages'] = false;
3371
+		}
3184 3372
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3185 3373
 
3186
-		if (allowedTo('moderate_forum'))
3187
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3374
+		if (allowedTo('moderate_forum')) {
3375
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3376
+		}
3188 3377
 
3189 3378
 		$context['user']['avatar'] = array();
3190 3379
 
3191 3380
 		// Check for gravatar first since we might be forcing them...
3192 3381
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3193 3382
 		{
3194
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3195
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3196
-			else
3197
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3383
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3384
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3385
+			} else {
3386
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3387
+			}
3198 3388
 		}
3199 3389
 		// Uploaded?
3200
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3201
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3390
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3391
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3392
+		}
3202 3393
 		// Full URL?
3203
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3204
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3394
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3395
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3396
+		}
3205 3397
 		// Otherwise we assume it's server stored.
3206
-		elseif ($user_info['avatar']['url'] != '')
3207
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3398
+		elseif ($user_info['avatar']['url'] != '') {
3399
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3400
+		}
3208 3401
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3209
-		else
3210
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3402
+		else {
3403
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3404
+		}
3211 3405
 
3212
-		if (!empty($context['user']['avatar']))
3213
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3406
+		if (!empty($context['user']['avatar'])) {
3407
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3408
+		}
3214 3409
 
3215 3410
 		// Figure out how long they've been logged in.
3216 3411
 		$context['user']['total_time_logged_in'] = array(
@@ -3218,8 +3413,7 @@  discard block
 block discarded – undo
3218 3413
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3219 3414
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3220 3415
 		);
3221
-	}
3222
-	else
3416
+	} else
3223 3417
 	{
3224 3418
 		$context['user']['messages'] = 0;
3225 3419
 		$context['user']['unread_messages'] = 0;
@@ -3227,12 +3421,14 @@  discard block
 block discarded – undo
3227 3421
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3228 3422
 		$context['user']['popup_messages'] = false;
3229 3423
 
3230
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3231
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3424
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3425
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3426
+		}
3232 3427
 
3233 3428
 		// If we've upgraded recently, go easy on the passwords.
3234
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3235
-			$context['disable_login_hashing'] = true;
3429
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3430
+					$context['disable_login_hashing'] = true;
3431
+		}
3236 3432
 	}
3237 3433
 
3238 3434
 	// Setup the main menu items.
@@ -3245,8 +3441,8 @@  discard block
 block discarded – undo
3245 3441
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3246 3442
 
3247 3443
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3248
-	if ($context['show_pm_popup'])
3249
-		addInlineJavaScript('
3444
+	if ($context['show_pm_popup']) {
3445
+			addInlineJavaScript('
3250 3446
 		jQuery(document).ready(function($) {
3251 3447
 			new smc_Popup({
3252 3448
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3254,24 +3450,28 @@  discard block
 block discarded – undo
3254 3450
 				icon_class: \'generic_icons mail_new\'
3255 3451
 			});
3256 3452
 		});');
3453
+	}
3257 3454
 
3258 3455
 	// Add a generic "Are you sure?" confirmation message.
3259 3456
 	addInlineJavaScript('
3260 3457
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3261 3458
 
3262 3459
 	// Now add the capping code for avatars.
3263
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3264
-		addInlineCss('
3460
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3461
+			addInlineCss('
3265 3462
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3463
+	}
3266 3464
 
3267 3465
 	// Add max image limits
3268
-	if (!empty($modSettings['max_image_width']))
3269
-		addInlineCss('
3466
+	if (!empty($modSettings['max_image_width'])) {
3467
+			addInlineCss('
3270 3468
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3469
+	}
3271 3470
 
3272
-	if (!empty($modSettings['max_image_height']))
3273
-		addInlineCss('
3471
+	if (!empty($modSettings['max_image_height'])) {
3472
+			addInlineCss('
3274 3473
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3474
+	}
3275 3475
 
3276 3476
 	// This looks weird, but it's because BoardIndex.php references the variable.
3277 3477
 	$context['common_stats']['latest_member'] = array(
@@ -3288,11 +3488,13 @@  discard block
 block discarded – undo
3288 3488
 	);
3289 3489
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3290 3490
 
3291
-	if (empty($settings['theme_version']))
3292
-		addJavaScriptVar('smf_scripturl', $scripturl);
3491
+	if (empty($settings['theme_version'])) {
3492
+			addJavaScriptVar('smf_scripturl', $scripturl);
3493
+	}
3293 3494
 
3294
-	if (!isset($context['page_title']))
3295
-		$context['page_title'] = '';
3495
+	if (!isset($context['page_title'])) {
3496
+			$context['page_title'] = '';
3497
+	}
3296 3498
 
3297 3499
 	// Set some specific vars.
3298 3500
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3302,21 +3504,23 @@  discard block
 block discarded – undo
3302 3504
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3303 3505
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3304 3506
 
3305
-	if (!empty($context['meta_keywords']))
3306
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3507
+	if (!empty($context['meta_keywords'])) {
3508
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3509
+	}
3307 3510
 
3308
-	if (!empty($context['canonical_url']))
3309
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3511
+	if (!empty($context['canonical_url'])) {
3512
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3513
+	}
3310 3514
 
3311
-	if (!empty($settings['og_image']))
3312
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3515
+	if (!empty($settings['og_image'])) {
3516
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3517
+	}
3313 3518
 
3314 3519
 	if (!empty($context['meta_description']))
3315 3520
 	{
3316 3521
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3317 3522
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3318
-	}
3319
-	else
3523
+	} else
3320 3524
 	{
3321 3525
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3322 3526
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3341,8 +3545,9 @@  discard block
 block discarded – undo
3341 3545
 	$memory_needed = memoryReturnBytes($needed);
3342 3546
 
3343 3547
 	// should we account for how much is currently being used?
3344
-	if ($in_use)
3345
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3548
+	if ($in_use) {
3549
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3550
+	}
3346 3551
 
3347 3552
 	// if more is needed, request it
3348 3553
 	if ($memory_current < $memory_needed)
@@ -3365,8 +3570,9 @@  discard block
 block discarded – undo
3365 3570
  */
3366 3571
 function memoryReturnBytes($val)
3367 3572
 {
3368
-	if (is_integer($val))
3369
-		return $val;
3573
+	if (is_integer($val)) {
3574
+			return $val;
3575
+	}
3370 3576
 
3371 3577
 	// Separate the number from the designator
3372 3578
 	$val = trim($val);
@@ -3402,10 +3608,11 @@  discard block
 block discarded – undo
3402 3608
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3403 3609
 
3404 3610
 		// Are we debugging the template/html content?
3405
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3406
-			header('content-type: application/xhtml+xml');
3407
-		elseif (!isset($_REQUEST['xml']))
3408
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3611
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3612
+					header('content-type: application/xhtml+xml');
3613
+		} elseif (!isset($_REQUEST['xml'])) {
3614
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3615
+		}
3409 3616
 	}
3410 3617
 
3411 3618
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3414,8 +3621,9 @@  discard block
 block discarded – undo
3414 3621
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3415 3622
 	{
3416 3623
 		$position = array_search('body', $context['template_layers']);
3417
-		if ($position === false)
3418
-			$position = array_search('main', $context['template_layers']);
3624
+		if ($position === false) {
3625
+					$position = array_search('main', $context['template_layers']);
3626
+		}
3419 3627
 
3420 3628
 		if ($position !== false)
3421 3629
 		{
@@ -3443,23 +3651,25 @@  discard block
 block discarded – undo
3443 3651
 
3444 3652
 			foreach ($securityFiles as $i => $securityFile)
3445 3653
 			{
3446
-				if (!file_exists($boarddir . '/' . $securityFile))
3447
-					unset($securityFiles[$i]);
3654
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3655
+									unset($securityFiles[$i]);
3656
+				}
3448 3657
 			}
3449 3658
 
3450 3659
 			// We are already checking so many files...just few more doesn't make any difference! :P
3451
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3452
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3453
-
3454
-			else
3455
-				$path = $modSettings['attachmentUploadDir'];
3660
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3661
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3662
+			} else {
3663
+							$path = $modSettings['attachmentUploadDir'];
3664
+			}
3456 3665
 
3457 3666
 			secureDirectory($path, true);
3458 3667
 			secureDirectory($cachedir);
3459 3668
 
3460 3669
 			// If agreement is enabled, at least the english version shall exists
3461
-			if ($modSettings['requireAgreement'])
3462
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3670
+			if ($modSettings['requireAgreement']) {
3671
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3672
+			}
3463 3673
 
3464 3674
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3465 3675
 			{
@@ -3474,18 +3684,21 @@  discard block
 block discarded – undo
3474 3684
 					echo '
3475 3685
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3476 3686
 
3477
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3478
-						echo '
3687
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3688
+											echo '
3479 3689
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3690
+					}
3480 3691
 				}
3481 3692
 
3482
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3483
-					echo '
3693
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3694
+									echo '
3484 3695
 				<strong>', $txt['cache_writable'], '</strong><br>';
3696
+				}
3485 3697
 
3486
-				if (!empty($agreement))
3487
-					echo '
3698
+				if (!empty($agreement)) {
3699
+									echo '
3488 3700
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3701
+				}
3489 3702
 
3490 3703
 				echo '
3491 3704
 			</p>
@@ -3500,16 +3713,18 @@  discard block
 block discarded – undo
3500 3713
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3501 3714
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3502 3715
 
3503
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3504
-				echo '
3716
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3717
+							echo '
3505 3718
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3719
+			}
3506 3720
 
3507
-			if (!empty($_SESSION['ban']['expire_time']))
3508
-				echo '
3721
+			if (!empty($_SESSION['ban']['expire_time'])) {
3722
+							echo '
3509 3723
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3510
-			else
3511
-				echo '
3724
+			} else {
3725
+							echo '
3512 3726
 					<div>', $txt['your_ban_expires_never'], '</div>';
3727
+			}
3513 3728
 
3514 3729
 			echo '
3515 3730
 				</div>';
@@ -3525,8 +3740,9 @@  discard block
 block discarded – undo
3525 3740
 	global $forum_copyright, $software_year, $forum_version;
3526 3741
 
3527 3742
 	// Don't display copyright for things like SSI.
3528
-	if (!isset($forum_version) || !isset($software_year))
3529
-		return;
3743
+	if (!isset($forum_version) || !isset($software_year)) {
3744
+			return;
3745
+	}
3530 3746
 
3531 3747
 	// Put in the version...
3532 3748
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3544,9 +3760,10 @@  discard block
 block discarded – undo
3544 3760
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3545 3761
 	$context['load_queries'] = $db_count;
3546 3762
 
3547
-	foreach (array_reverse($context['template_layers']) as $layer)
3548
-		loadSubTemplate($layer . '_below', true);
3549
-}
3763
+	foreach (array_reverse($context['template_layers']) as $layer) {
3764
+			loadSubTemplate($layer . '_below', true);
3765
+	}
3766
+	}
3550 3767
 
3551 3768
 /**
3552 3769
  * Output the Javascript files
@@ -3580,8 +3797,7 @@  discard block
 block discarded – undo
3580 3797
 			{
3581 3798
 				echo '
3582 3799
 		var ', $key, ';';
3583
-			}
3584
-			else
3800
+			} else
3585 3801
 			{
3586 3802
 				echo '
3587 3803
 		var ', $key, ' = ', $value, ';';
@@ -3600,27 +3816,29 @@  discard block
 block discarded – undo
3600 3816
 		foreach ($context['javascript_files'] as $id => $js_file)
3601 3817
 		{
3602 3818
 			// Last minute call! allow theme authors to disable single files.
3603
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3604
-				continue;
3819
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3820
+							continue;
3821
+			}
3605 3822
 
3606 3823
 			// By default files don't get minimized unless the file explicitly says so!
3607 3824
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3608 3825
 			{
3609
-				if (!empty($js_file['options']['async']))
3610
-					$toMinify['async'][] = $js_file;
3611
-				elseif (!empty($js_file['options']['defer']))
3612
-					$toMinify['defer'][] = $js_file;
3613
-				else
3614
-					$toMinify['standard'][] = $js_file;
3826
+				if (!empty($js_file['options']['async'])) {
3827
+									$toMinify['async'][] = $js_file;
3828
+				} elseif (!empty($js_file['options']['defer'])) {
3829
+									$toMinify['defer'][] = $js_file;
3830
+				} else {
3831
+									$toMinify['standard'][] = $js_file;
3832
+				}
3615 3833
 
3616 3834
 				// Grab a random seed.
3617
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3618
-					$minSeed = $js_file['options']['seed'];
3619
-			}
3620
-
3621
-			else
3622
-				echo '
3835
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3836
+									$minSeed = $js_file['options']['seed'];
3837
+				}
3838
+			} else {
3839
+							echo '
3623 3840
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
3841
+			}
3624 3842
 		}
3625 3843
 
3626 3844
 		foreach ($toMinify as $js_files)
@@ -3631,9 +3849,10 @@  discard block
 block discarded – undo
3631 3849
 
3632 3850
 				$minSuccessful = array_keys($result) === array('smf_minified');
3633 3851
 
3634
-				foreach ($result as $minFile)
3635
-					echo '
3852
+				foreach ($result as $minFile) {
3853
+									echo '
3636 3854
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
3855
+				}
3637 3856
 			}
3638 3857
 		}
3639 3858
 	}
@@ -3647,8 +3866,9 @@  discard block
 block discarded – undo
3647 3866
 <script>
3648 3867
 window.addEventListener("DOMContentLoaded", function() {';
3649 3868
 
3650
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3651
-				echo $js_code;
3869
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3870
+							echo $js_code;
3871
+			}
3652 3872
 
3653 3873
 			echo '
3654 3874
 });
@@ -3660,8 +3880,9 @@  discard block
 block discarded – undo
3660 3880
 			echo '
3661 3881
 	<script>';
3662 3882
 
3663
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3664
-				echo $js_code;
3883
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3884
+							echo $js_code;
3885
+			}
3665 3886
 
3666 3887
 			echo '
3667 3888
 	</script>';
@@ -3689,23 +3910,26 @@  discard block
 block discarded – undo
3689 3910
 	foreach ($context['css_files'] as $id => $file)
3690 3911
 	{
3691 3912
 		// Last minute call! allow theme authors to disable single files.
3692
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3693
-			continue;
3913
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3914
+					continue;
3915
+		}
3694 3916
 
3695 3917
 		// Files are minimized unless they explicitly opt out.
3696
-		if (!isset($file['options']['minimize']))
3697
-			$file['options']['minimize'] = true;
3918
+		if (!isset($file['options']['minimize'])) {
3919
+					$file['options']['minimize'] = true;
3920
+		}
3698 3921
 
3699 3922
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3700 3923
 		{
3701 3924
 			$toMinify[] = $file;
3702 3925
 
3703 3926
 			// Grab a random seed.
3704
-			if (!isset($minSeed) && isset($file['options']['seed']))
3705
-				$minSeed = $file['options']['seed'];
3927
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
3928
+							$minSeed = $file['options']['seed'];
3929
+			}
3930
+		} else {
3931
+					$normal[] = $file['fileUrl'];
3706 3932
 		}
3707
-		else
3708
-			$normal[] = $file['fileUrl'];
3709 3933
 	}
3710 3934
 
3711 3935
 	if (!empty($toMinify))
@@ -3714,23 +3938,26 @@  discard block
 block discarded – undo
3714 3938
 
3715 3939
 		$minSuccessful = array_keys($result) === array('smf_minified');
3716 3940
 
3717
-		foreach ($result as $minFile)
3718
-			echo '
3941
+		foreach ($result as $minFile) {
3942
+					echo '
3719 3943
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
3944
+		}
3720 3945
 	}
3721 3946
 
3722 3947
 	// Print the rest after the minified files.
3723
-	if (!empty($normal))
3724
-		foreach ($normal as $nf)
3948
+	if (!empty($normal)) {
3949
+			foreach ($normal as $nf)
3725 3950
 			echo '
3726 3951
 	<link rel="stylesheet" href="', $nf ,'">';
3952
+	}
3727 3953
 
3728 3954
 	if ($db_show_debug === true)
3729 3955
 	{
3730 3956
 		// Try to keep only what's useful.
3731 3957
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3732
-		foreach ($context['css_files'] as $file)
3733
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3958
+		foreach ($context['css_files'] as $file) {
3959
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3960
+		}
3734 3961
 	}
3735 3962
 
3736 3963
 	if (!empty($context['css_header']))
@@ -3738,9 +3965,10 @@  discard block
 block discarded – undo
3738 3965
 		echo '
3739 3966
 	<style>';
3740 3967
 
3741
-		foreach ($context['css_header'] as $css)
3742
-			echo $css .'
3968
+		foreach ($context['css_header'] as $css) {
3969
+					echo $css .'
3743 3970
 	';
3971
+		}
3744 3972
 
3745 3973
 		echo'
3746 3974
 	</style>';
@@ -3763,8 +3991,9 @@  discard block
 block discarded – undo
3763 3991
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3764 3992
 	$data = is_array($data) ? $data : array();
3765 3993
 
3766
-	if (empty($type) || empty($data))
3767
-		return $data;
3994
+	if (empty($type) || empty($data)) {
3995
+			return $data;
3996
+	}
3768 3997
 
3769 3998
 	// Different pages include different files, so we use a hash to label the different combinations
3770 3999
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3773,13 +4002,14 @@  discard block
 block discarded – undo
3773 4002
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3774 4003
 
3775 4004
 	// Already done?
3776
-	if (!empty($toCache))
3777
-		return array('smf_minified' => array(
4005
+	if (!empty($toCache)) {
4006
+			return array('smf_minified' => array(
3778 4007
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3779 4008
 			'filePath' => $toCache,
3780 4009
 			'fileName' => basename($toCache),
3781 4010
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3782 4011
 		));
4012
+	}
3783 4013
 
3784 4014
 
3785 4015
 	// No namespaces, sorry!
@@ -3809,9 +4039,9 @@  discard block
 block discarded – undo
3809 4039
 
3810 4040
 	foreach ($data as $id => $file)
3811 4041
 	{
3812
-		if (empty($file['filePath']))
3813
-			$toAdd = false;
3814
-		else
4042
+		if (empty($file['filePath'])) {
4043
+					$toAdd = false;
4044
+		} else
3815 4045
 		{
3816 4046
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3817 4047
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3819,12 +4049,14 @@  discard block
 block discarded – undo
3819 4049
 		}
3820 4050
 
3821 4051
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3822
-		if (empty($file['options']['async']))
3823
-			$async = false;
4052
+		if (empty($file['options']['async'])) {
4053
+					$async = false;
4054
+		}
3824 4055
 
3825 4056
 		// A minified script should only be deferred if all its components wanted to be.
3826
-		if (empty($file['options']['defer']))
3827
-			$defer = false;
4057
+		if (empty($file['options']['defer'])) {
4058
+					$defer = false;
4059
+		}
3828 4060
 
3829 4061
 		// The file couldn't be located so it won't be added. Log this error.
3830 4062
 		if (empty($toAdd))
@@ -3890,12 +4122,14 @@  discard block
 block discarded – undo
3890 4122
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
3891 4123
 			{
3892 4124
 				// Remove the cache entry
3893
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
3894
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4125
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4126
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4127
+				}
3895 4128
 
3896 4129
 				// Try to delete the file. Add it to our error list if it fails.
3897
-				if (!@unlink($filename))
3898
-					$not_deleted[] = $filename;
4130
+				if (!@unlink($filename)) {
4131
+									$not_deleted[] = $filename;
4132
+				}
3899 4133
 			}
3900 4134
 		}
3901 4135
 	}
@@ -3927,8 +4161,9 @@  discard block
 block discarded – undo
3927 4161
 	global $modSettings, $smcFunc;
3928 4162
 
3929 4163
 	// Just make up a nice hash...
3930
-	if ($new)
3931
-		return sha1(md5($filename . time()) . mt_rand());
4164
+	if ($new) {
4165
+			return sha1(md5($filename . time()) . mt_rand());
4166
+	}
3932 4167
 
3933 4168
 	// Just make sure that attachment id is only a int
3934 4169
 	$attachment_id = (int) $attachment_id;
@@ -3945,23 +4180,25 @@  discard block
 block discarded – undo
3945 4180
 				'id_attach' => $attachment_id,
3946 4181
 			));
3947 4182
 
3948
-		if ($smcFunc['db_num_rows']($request) === 0)
3949
-			return false;
4183
+		if ($smcFunc['db_num_rows']($request) === 0) {
4184
+					return false;
4185
+		}
3950 4186
 
3951 4187
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3952 4188
 		$smcFunc['db_free_result']($request);
3953 4189
 	}
3954 4190
 
3955 4191
 	// Still no hash? mmm...
3956
-	if (empty($file_hash))
3957
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4192
+	if (empty($file_hash)) {
4193
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4194
+	}
3958 4195
 
3959 4196
 	// Are we using multiple directories?
3960
-	if (is_array($modSettings['attachmentUploadDir']))
3961
-		$path = $modSettings['attachmentUploadDir'][$dir];
3962
-
3963
-	else
3964
-		$path = $modSettings['attachmentUploadDir'];
4197
+	if (is_array($modSettings['attachmentUploadDir'])) {
4198
+			$path = $modSettings['attachmentUploadDir'][$dir];
4199
+	} else {
4200
+			$path = $modSettings['attachmentUploadDir'];
4201
+	}
3965 4202
 
3966 4203
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3967 4204
 }
@@ -3976,8 +4213,9 @@  discard block
 block discarded – undo
3976 4213
 function ip2range($fullip)
3977 4214
 {
3978 4215
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3979
-	if ($fullip == 'unknown')
3980
-		$fullip = '255.255.255.255';
4216
+	if ($fullip == 'unknown') {
4217
+			$fullip = '255.255.255.255';
4218
+	}
3981 4219
 
3982 4220
 	$ip_parts = explode('-', $fullip);
3983 4221
 	$ip_array = array();
@@ -4001,10 +4239,11 @@  discard block
 block discarded – undo
4001 4239
 		$ip_array['low'] = $ip_parts[0];
4002 4240
 		$ip_array['high'] = $ip_parts[1];
4003 4241
 		return $ip_array;
4004
-	}
4005
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4242
+	} elseif (count($ip_parts) == 2) {
4243
+		// if ip 22.22.*-22.22.*
4006 4244
 	{
4007 4245
 		$valid_low = isValidIP($ip_parts[0]);
4246
+	}
4008 4247
 		$valid_high = isValidIP($ip_parts[1]);
4009 4248
 		$count = 0;
4010 4249
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4019,7 +4258,9 @@  discard block
 block discarded – undo
4019 4258
 				$ip_parts[0] .= $mode . $min;
4020 4259
 				$valid_low = isValidIP($ip_parts[0]);
4021 4260
 				$count++;
4022
-				if ($count > 9) break;
4261
+				if ($count > 9) {
4262
+					break;
4263
+				}
4023 4264
 			}
4024 4265
 		}
4025 4266
 
@@ -4033,7 +4274,9 @@  discard block
 block discarded – undo
4033 4274
 				$ip_parts[1] .= $mode . $max;
4034 4275
 				$valid_high = isValidIP($ip_parts[1]);
4035 4276
 				$count++;
4036
-				if ($count > 9) break;
4277
+				if ($count > 9) {
4278
+					break;
4279
+				}
4037 4280
 			}
4038 4281
 		}
4039 4282
 
@@ -4057,46 +4300,54 @@  discard block
 block discarded – undo
4057 4300
 {
4058 4301
 	global $modSettings;
4059 4302
 
4060
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4061
-		return $host;
4303
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4304
+			return $host;
4305
+	}
4062 4306
 	$t = microtime();
4063 4307
 
4064 4308
 	// Try the Linux host command, perhaps?
4065 4309
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
4066 4310
 	{
4067
-		if (!isset($modSettings['host_to_dis']))
4068
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4069
-		else
4070
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4311
+		if (!isset($modSettings['host_to_dis'])) {
4312
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4313
+		} else {
4314
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4315
+		}
4071 4316
 
4072 4317
 		// Did host say it didn't find anything?
4073
-		if (strpos($test, 'not found') !== false)
4074
-			$host = '';
4318
+		if (strpos($test, 'not found') !== false) {
4319
+					$host = '';
4320
+		}
4075 4321
 		// Invalid server option?
4076
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4077
-			updateSettings(array('host_to_dis' => 1));
4322
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4323
+					updateSettings(array('host_to_dis' => 1));
4324
+		}
4078 4325
 		// Maybe it found something, after all?
4079
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4080
-			$host = $match[1];
4326
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4327
+					$host = $match[1];
4328
+		}
4081 4329
 	}
4082 4330
 
4083 4331
 	// This is nslookup; usually only Windows, but possibly some Unix?
4084 4332
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
4085 4333
 	{
4086 4334
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4087
-		if (strpos($test, 'Non-existent domain') !== false)
4088
-			$host = '';
4089
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4090
-			$host = $match[1];
4335
+		if (strpos($test, 'Non-existent domain') !== false) {
4336
+					$host = '';
4337
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4338
+					$host = $match[1];
4339
+		}
4091 4340
 	}
4092 4341
 
4093 4342
 	// This is the last try :/.
4094
-	if (!isset($host) || $host === false)
4095
-		$host = @gethostbyaddr($ip);
4343
+	if (!isset($host) || $host === false) {
4344
+			$host = @gethostbyaddr($ip);
4345
+	}
4096 4346
 
4097 4347
 	// It took a long time, so let's cache it!
4098
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4099
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4348
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4349
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4350
+	}
4100 4351
 
4101 4352
 	return $host;
4102 4353
 }
@@ -4132,20 +4383,21 @@  discard block
 block discarded – undo
4132 4383
 			{
4133 4384
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4134 4385
 				$total = 0;
4135
-				for ($i = 0; $i < $max_chars; $i++)
4136
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4386
+				for ($i = 0; $i < $max_chars; $i++) {
4387
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4388
+				}
4137 4389
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4138 4390
 			}
4139 4391
 		}
4140 4392
 		return array_unique($returned_ints);
4141
-	}
4142
-	else
4393
+	} else
4143 4394
 	{
4144 4395
 		// Trim characters before and after and add slashes for database insertion.
4145 4396
 		$returned_words = array();
4146
-		foreach ($words as $word)
4147
-			if (($word = trim($word, '-_\'')) !== '')
4397
+		foreach ($words as $word) {
4398
+					if (($word = trim($word, '-_\'')) !== '')
4148 4399
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4400
+		}
4149 4401
 
4150 4402
 		// Filter out all words that occur more than once.
4151 4403
 		return array_unique($returned_words);
@@ -4167,16 +4419,18 @@  discard block
 block discarded – undo
4167 4419
 	global $settings, $txt;
4168 4420
 
4169 4421
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4170
-	if (function_exists('template_create_button') && !$force_use)
4171
-		return template_create_button($name, $alt, $label = '', $custom = '');
4422
+	if (function_exists('template_create_button') && !$force_use) {
4423
+			return template_create_button($name, $alt, $label = '', $custom = '');
4424
+	}
4172 4425
 
4173
-	if (!$settings['use_image_buttons'])
4174
-		return $txt[$alt];
4175
-	elseif (!empty($settings['use_buttons']))
4176
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4177
-	else
4178
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4179
-}
4426
+	if (!$settings['use_image_buttons']) {
4427
+			return $txt[$alt];
4428
+	} elseif (!empty($settings['use_buttons'])) {
4429
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4430
+	} else {
4431
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4432
+	}
4433
+	}
4180 4434
 
4181 4435
 /**
4182 4436
  * Sets up all of the top menu buttons
@@ -4219,9 +4473,10 @@  discard block
 block discarded – undo
4219 4473
 	var user_menus = new smc_PopupMenu();
4220 4474
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4221 4475
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4222
-		if ($context['allow_pm'])
4223
-			addInlineJavaScript('
4476
+		if ($context['allow_pm']) {
4477
+					addInlineJavaScript('
4224 4478
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4479
+		}
4225 4480
 
4226 4481
 		if (!empty($modSettings['enable_ajax_alerts']))
4227 4482
 		{
@@ -4381,88 +4636,96 @@  discard block
 block discarded – undo
4381 4636
 
4382 4637
 		// Now we put the buttons in the context so the theme can use them.
4383 4638
 		$menu_buttons = array();
4384
-		foreach ($buttons as $act => $button)
4385
-			if (!empty($button['show']))
4639
+		foreach ($buttons as $act => $button) {
4640
+					if (!empty($button['show']))
4386 4641
 			{
4387 4642
 				$button['active_button'] = false;
4643
+		}
4388 4644
 
4389 4645
 				// This button needs some action.
4390
-				if (isset($button['action_hook']))
4391
-					$needs_action_hook = true;
4646
+				if (isset($button['action_hook'])) {
4647
+									$needs_action_hook = true;
4648
+				}
4392 4649
 
4393 4650
 				// Make sure the last button truly is the last button.
4394 4651
 				if (!empty($button['is_last']))
4395 4652
 				{
4396
-					if (isset($last_button))
4397
-						unset($menu_buttons[$last_button]['is_last']);
4653
+					if (isset($last_button)) {
4654
+											unset($menu_buttons[$last_button]['is_last']);
4655
+					}
4398 4656
 					$last_button = $act;
4399 4657
 				}
4400 4658
 
4401 4659
 				// Go through the sub buttons if there are any.
4402
-				if (!empty($button['sub_buttons']))
4403
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4660
+				if (!empty($button['sub_buttons'])) {
4661
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4404 4662
 					{
4405 4663
 						if (empty($subbutton['show']))
4406 4664
 							unset($button['sub_buttons'][$key]);
4665
+				}
4407 4666
 
4408 4667
 						// 2nd level sub buttons next...
4409 4668
 						if (!empty($subbutton['sub_buttons']))
4410 4669
 						{
4411 4670
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4412 4671
 							{
4413
-								if (empty($sub_button2['show']))
4414
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4672
+								if (empty($sub_button2['show'])) {
4673
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4674
+								}
4415 4675
 							}
4416 4676
 						}
4417 4677
 					}
4418 4678
 
4419 4679
 				// Does this button have its own icon?
4420
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4421
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4422
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4423
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4424
-				elseif (isset($button['icon']))
4425
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4426
-				else
4427
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4680
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4681
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4682
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4683
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4684
+				} elseif (isset($button['icon'])) {
4685
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4686
+				} else {
4687
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4688
+				}
4428 4689
 
4429 4690
 				$menu_buttons[$act] = $button;
4430 4691
 			}
4431 4692
 
4432
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4433
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4693
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4694
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4695
+		}
4434 4696
 	}
4435 4697
 
4436 4698
 	$context['menu_buttons'] = $menu_buttons;
4437 4699
 
4438 4700
 	// Logging out requires the session id in the url.
4439
-	if (isset($context['menu_buttons']['logout']))
4440
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4701
+	if (isset($context['menu_buttons']['logout'])) {
4702
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4703
+	}
4441 4704
 
4442 4705
 	// Figure out which action we are doing so we can set the active tab.
4443 4706
 	// Default to home.
4444 4707
 	$current_action = 'home';
4445 4708
 
4446
-	if (isset($context['menu_buttons'][$context['current_action']]))
4447
-		$current_action = $context['current_action'];
4448
-	elseif ($context['current_action'] == 'search2')
4449
-		$current_action = 'search';
4450
-	elseif ($context['current_action'] == 'theme')
4451
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4452
-	elseif ($context['current_action'] == 'register2')
4453
-		$current_action = 'register';
4454
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4455
-		$current_action = 'login';
4456
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4457
-		$current_action = 'moderate';
4709
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4710
+			$current_action = $context['current_action'];
4711
+	} elseif ($context['current_action'] == 'search2') {
4712
+			$current_action = 'search';
4713
+	} elseif ($context['current_action'] == 'theme') {
4714
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4715
+	} elseif ($context['current_action'] == 'register2') {
4716
+			$current_action = 'register';
4717
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4718
+			$current_action = 'login';
4719
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4720
+			$current_action = 'moderate';
4721
+	}
4458 4722
 
4459 4723
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4460 4724
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4461 4725
 	{
4462 4726
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4463 4727
 		$context[$current_action] = true;
4464
-	}
4465
-	elseif ($context['current_action'] == 'pm')
4728
+	} elseif ($context['current_action'] == 'pm')
4466 4729
 	{
4467 4730
 		$current_action = 'self_pm';
4468 4731
 		$context['self_pm'] = true;
@@ -4519,12 +4782,14 @@  discard block
 block discarded – undo
4519 4782
 	}
4520 4783
 
4521 4784
 	// Not all actions are simple.
4522
-	if (!empty($needs_action_hook))
4523
-		call_integration_hook('integrate_current_action', array(&$current_action));
4785
+	if (!empty($needs_action_hook)) {
4786
+			call_integration_hook('integrate_current_action', array(&$current_action));
4787
+	}
4524 4788
 
4525
-	if (isset($context['menu_buttons'][$current_action]))
4526
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4527
-}
4789
+	if (isset($context['menu_buttons'][$current_action])) {
4790
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4791
+	}
4792
+	}
4528 4793
 
4529 4794
 /**
4530 4795
  * Generate a random seed and ensure it's stored in settings.
@@ -4548,30 +4813,35 @@  discard block
 block discarded – undo
4548 4813
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4549 4814
 	global $context, $txt;
4550 4815
 
4551
-	if ($db_show_debug === true)
4552
-		$context['debug']['hooks'][] = $hook;
4816
+	if ($db_show_debug === true) {
4817
+			$context['debug']['hooks'][] = $hook;
4818
+	}
4553 4819
 
4554 4820
 	// Need to have some control.
4555
-	if (!isset($context['instances']))
4556
-		$context['instances'] = array();
4821
+	if (!isset($context['instances'])) {
4822
+			$context['instances'] = array();
4823
+	}
4557 4824
 
4558 4825
 	$results = array();
4559
-	if (empty($modSettings[$hook]))
4560
-		return $results;
4826
+	if (empty($modSettings[$hook])) {
4827
+			return $results;
4828
+	}
4561 4829
 
4562 4830
 	$functions = explode(',', $modSettings[$hook]);
4563 4831
 	// Loop through each function.
4564 4832
 	foreach ($functions as $function)
4565 4833
 	{
4566 4834
 		// Hook has been marked as "disabled". Skip it!
4567
-		if (strpos($function, '!') !== false)
4568
-			continue;
4835
+		if (strpos($function, '!') !== false) {
4836
+					continue;
4837
+		}
4569 4838
 
4570 4839
 		$call = call_helper($function, true);
4571 4840
 
4572 4841
 		// Is it valid?
4573
-		if (!empty($call))
4574
-			$results[$function] = call_user_func_array($call, $parameters);
4842
+		if (!empty($call)) {
4843
+					$results[$function] = call_user_func_array($call, $parameters);
4844
+		}
4575 4845
 
4576 4846
 		// Whatever it was suppose to call, it failed :(
4577 4847
 		elseif (!empty($function))
@@ -4587,8 +4857,9 @@  discard block
 block discarded – undo
4587 4857
 			}
4588 4858
 
4589 4859
 			// "Assume" the file resides on $boarddir somewhere...
4590
-			else
4591
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4860
+			else {
4861
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4862
+			}
4592 4863
 		}
4593 4864
 	}
4594 4865
 
@@ -4610,12 +4881,14 @@  discard block
 block discarded – undo
4610 4881
 	global $smcFunc, $modSettings;
4611 4882
 
4612 4883
 	// Any objects?
4613
-	if ($object)
4614
-		$function = $function . '#';
4884
+	if ($object) {
4885
+			$function = $function . '#';
4886
+	}
4615 4887
 
4616 4888
 	// Any files  to load?
4617
-	if (!empty($file) && is_string($file))
4618
-		$function = $file . (!empty($function) ? '|' . $function : '');
4889
+	if (!empty($file) && is_string($file)) {
4890
+			$function = $file . (!empty($function) ? '|' . $function : '');
4891
+	}
4619 4892
 
4620 4893
 	// Get the correct string.
4621 4894
 	$integration_call = $function;
@@ -4637,13 +4910,14 @@  discard block
 block discarded – undo
4637 4910
 		if (!empty($current_functions))
4638 4911
 		{
4639 4912
 			$current_functions = explode(',', $current_functions);
4640
-			if (in_array($integration_call, $current_functions))
4641
-				return;
4913
+			if (in_array($integration_call, $current_functions)) {
4914
+							return;
4915
+			}
4642 4916
 
4643 4917
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4918
+		} else {
4919
+					$permanent_functions = array($integration_call);
4644 4920
 		}
4645
-		else
4646
-			$permanent_functions = array($integration_call);
4647 4921
 
4648 4922
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4649 4923
 	}
@@ -4652,8 +4926,9 @@  discard block
 block discarded – undo
4652 4926
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4653 4927
 
4654 4928
 	// Do nothing, if it's already there.
4655
-	if (in_array($integration_call, $functions))
4656
-		return;
4929
+	if (in_array($integration_call, $functions)) {
4930
+			return;
4931
+	}
4657 4932
 
4658 4933
 	$functions[] = $integration_call;
4659 4934
 	$modSettings[$hook] = implode(',', $functions);
@@ -4676,12 +4951,14 @@  discard block
 block discarded – undo
4676 4951
 	global $smcFunc, $modSettings;
4677 4952
 
4678 4953
 	// Any objects?
4679
-	if ($object)
4680
-		$function = $function . '#';
4954
+	if ($object) {
4955
+			$function = $function . '#';
4956
+	}
4681 4957
 
4682 4958
 	// Any files  to load?
4683
-	if (!empty($file) && is_string($file))
4684
-		$function = $file . '|' . $function;
4959
+	if (!empty($file) && is_string($file)) {
4960
+			$function = $file . '|' . $function;
4961
+	}
4685 4962
 
4686 4963
 	// Get the correct string.
4687 4964
 	$integration_call = $function;
@@ -4702,16 +4979,18 @@  discard block
 block discarded – undo
4702 4979
 	{
4703 4980
 		$current_functions = explode(',', $current_functions);
4704 4981
 
4705
-		if (in_array($integration_call, $current_functions))
4706
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4982
+		if (in_array($integration_call, $current_functions)) {
4983
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4984
+		}
4707 4985
 	}
4708 4986
 
4709 4987
 	// Turn the function list into something usable.
4710 4988
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4711 4989
 
4712 4990
 	// You can only remove it if it's available.
4713
-	if (!in_array($integration_call, $functions))
4714
-		return;
4991
+	if (!in_array($integration_call, $functions)) {
4992
+			return;
4993
+	}
4715 4994
 
4716 4995
 	$functions = array_diff($functions, array($integration_call));
4717 4996
 	$modSettings[$hook] = implode(',', $functions);
@@ -4732,17 +5011,20 @@  discard block
 block discarded – undo
4732 5011
 	global $context, $smcFunc, $txt, $db_show_debug;
4733 5012
 
4734 5013
 	// Really?
4735
-	if (empty($string))
4736
-		return false;
5014
+	if (empty($string)) {
5015
+			return false;
5016
+	}
4737 5017
 
4738 5018
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4739 5019
 	// A closure? should be a callable one.
4740
-	if (is_array($string) || $string instanceof Closure)
4741
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5020
+	if (is_array($string) || $string instanceof Closure) {
5021
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5022
+	}
4742 5023
 
4743 5024
 	// No full objects, sorry! pass a method or a property instead!
4744
-	if (is_object($string))
4745
-		return false;
5025
+	if (is_object($string)) {
5026
+			return false;
5027
+	}
4746 5028
 
4747 5029
 	// Stay vitaminized my friends...
4748 5030
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4751,8 +5033,9 @@  discard block
 block discarded – undo
4751 5033
 	$string = load_file($string);
4752 5034
 
4753 5035
 	// Loaded file failed
4754
-	if (empty($string))
4755
-		return false;
5036
+	if (empty($string)) {
5037
+			return false;
5038
+	}
4756 5039
 
4757 5040
 	// Found a method.
4758 5041
 	if (strpos($string, '::') !== false)
@@ -4773,8 +5056,9 @@  discard block
 block discarded – undo
4773 5056
 				// Add another one to the list.
4774 5057
 				if ($db_show_debug === true)
4775 5058
 				{
4776
-					if (!isset($context['debug']['instances']))
4777
-						$context['debug']['instances'] = array();
5059
+					if (!isset($context['debug']['instances'])) {
5060
+											$context['debug']['instances'] = array();
5061
+					}
4778 5062
 
4779 5063
 					$context['debug']['instances'][$class] = $class;
4780 5064
 				}
@@ -4784,13 +5068,15 @@  discard block
 block discarded – undo
4784 5068
 		}
4785 5069
 
4786 5070
 		// Right then. This is a call to a static method.
4787
-		else
4788
-			$func = array($class, $method);
5071
+		else {
5072
+					$func = array($class, $method);
5073
+		}
4789 5074
 	}
4790 5075
 
4791 5076
 	// Nope! just a plain regular function.
4792
-	else
4793
-		$func = $string;
5077
+	else {
5078
+			$func = $string;
5079
+	}
4794 5080
 
4795 5081
 	// Right, we got what we need, time to do some checks.
4796 5082
 	if (!is_callable($func, false, $callable_name))
@@ -4806,17 +5092,18 @@  discard block
 block discarded – undo
4806 5092
 	else
4807 5093
 	{
4808 5094
 		// What are we gonna do about it?
4809
-		if ($return)
4810
-			return $func;
5095
+		if ($return) {
5096
+					return $func;
5097
+		}
4811 5098
 
4812 5099
 		// If this is a plain function, avoid the heat of calling call_user_func().
4813 5100
 		else
4814 5101
 		{
4815
-			if (is_array($func))
4816
-				call_user_func($func);
4817
-
4818
-			else
4819
-				$func();
5102
+			if (is_array($func)) {
5103
+							call_user_func($func);
5104
+			} else {
5105
+							$func();
5106
+			}
4820 5107
 		}
4821 5108
 	}
4822 5109
 }
@@ -4833,31 +5120,34 @@  discard block
 block discarded – undo
4833 5120
 {
4834 5121
 	global $sourcedir, $txt, $boarddir, $settings;
4835 5122
 
4836
-	if (empty($string))
4837
-		return false;
5123
+	if (empty($string)) {
5124
+			return false;
5125
+	}
4838 5126
 
4839 5127
 	if (strpos($string, '|') !== false)
4840 5128
 	{
4841 5129
 		list ($file, $string) = explode('|', $string);
4842 5130
 
4843 5131
 		// Match the wildcards to their regular vars.
4844
-		if (empty($settings['theme_dir']))
4845
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4846
-
4847
-		else
4848
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5132
+		if (empty($settings['theme_dir'])) {
5133
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5134
+		} else {
5135
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5136
+		}
4849 5137
 
4850 5138
 		// Load the file if it can be loaded.
4851
-		if (file_exists($absPath))
4852
-			require_once($absPath);
5139
+		if (file_exists($absPath)) {
5140
+					require_once($absPath);
5141
+		}
4853 5142
 
4854 5143
 		// No? try a fallback to $sourcedir
4855 5144
 		else
4856 5145
 		{
4857 5146
 			$absPath = $sourcedir .'/'. $file;
4858 5147
 
4859
-			if (file_exists($absPath))
4860
-				require_once($absPath);
5148
+			if (file_exists($absPath)) {
5149
+							require_once($absPath);
5150
+			}
4861 5151
 
4862 5152
 			// Sorry, can't do much for you at this point.
4863 5153
 			else
@@ -4896,8 +5186,9 @@  discard block
 block discarded – undo
4896 5186
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
4897 5187
 
4898 5188
 	// No scheme? No data for you!
4899
-	if (empty($match[1]))
4900
-		return false;
5189
+	if (empty($match[1])) {
5190
+			return false;
5191
+	}
4901 5192
 
4902 5193
 	// An FTP url. We should try connecting and RETRieving it...
4903 5194
 	elseif ($match[1] == 'ftp')
@@ -4907,23 +5198,26 @@  discard block
 block discarded – undo
4907 5198
 
4908 5199
 		// Establish a connection and attempt to enable passive mode.
4909 5200
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
4910
-		if ($ftp->error !== false || !$ftp->passive())
4911
-			return false;
5201
+		if ($ftp->error !== false || !$ftp->passive()) {
5202
+					return false;
5203
+		}
4912 5204
 
4913 5205
 		// I want that one *points*!
4914 5206
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
4915 5207
 
4916 5208
 		// Since passive mode worked (or we would have returned already!) open the connection.
4917 5209
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
4918
-		if (!$fp)
4919
-			return false;
5210
+		if (!$fp) {
5211
+					return false;
5212
+		}
4920 5213
 
4921 5214
 		// The server should now say something in acknowledgement.
4922 5215
 		$ftp->check_response(150);
4923 5216
 
4924 5217
 		$data = '';
4925
-		while (!feof($fp))
4926
-			$data .= fread($fp, 4096);
5218
+		while (!feof($fp)) {
5219
+					$data .= fread($fp, 4096);
5220
+		}
4927 5221
 		fclose($fp);
4928 5222
 
4929 5223
 		// All done, right?  Good.
@@ -4935,8 +5229,9 @@  discard block
 block discarded – undo
4935 5229
 	elseif (isset($match[1]) && $match[1] == 'http')
4936 5230
 	{
4937 5231
 		// First try to use fsockopen, because it is fastest.
4938
-		if ($keep_alive && $match[3] == $keep_alive_dom)
4939
-			$fp = $keep_alive_fp;
5232
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5233
+					$fp = $keep_alive_fp;
5234
+		}
4940 5235
 		if (empty($fp))
4941 5236
 		{
4942 5237
 			// Open the socket on the port we want...
@@ -4956,20 +5251,21 @@  discard block
 block discarded – undo
4956 5251
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
4957 5252
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
4958 5253
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
4959
-				if ($keep_alive)
4960
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
4961
-				else
4962
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
4963
-			}
4964
-			else
5254
+				if ($keep_alive) {
5255
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5256
+				} else {
5257
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5258
+				}
5259
+			} else
4965 5260
 			{
4966 5261
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
4967 5262
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
4968 5263
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
4969
-				if ($keep_alive)
4970
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
4971
-				else
4972
-					fwrite($fp, 'connection: close' . "\r\n");
5264
+				if ($keep_alive) {
5265
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5266
+				} else {
5267
+									fwrite($fp, 'connection: close' . "\r\n");
5268
+				}
4973 5269
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
4974 5270
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
4975 5271
 				fwrite($fp, $post_data);
@@ -4982,30 +5278,33 @@  discard block
 block discarded – undo
4982 5278
 			{
4983 5279
 				$header = '';
4984 5280
 				$location = '';
4985
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
4986
-					if (strpos($header, 'location:') !== false)
5281
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5282
+									if (strpos($header, 'location:') !== false)
4987 5283
 						$location = trim(substr($header, strpos($header, ':') + 1));
5284
+				}
4988 5285
 
4989
-				if (empty($location))
4990
-					return false;
4991
-				else
5286
+				if (empty($location)) {
5287
+									return false;
5288
+				} else
4992 5289
 				{
4993
-					if (!$keep_alive)
4994
-						fclose($fp);
5290
+					if (!$keep_alive) {
5291
+											fclose($fp);
5292
+					}
4995 5293
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
4996 5294
 				}
4997 5295
 			}
4998 5296
 
4999 5297
 			// Make sure we get a 200 OK.
5000
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
5001
-				return false;
5298
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5299
+							return false;
5300
+			}
5002 5301
 
5003 5302
 			// Skip the headers...
5004 5303
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5005 5304
 			{
5006
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5007
-					$content_length = $match[1];
5008
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5305
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5306
+									$content_length = $match[1];
5307
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5009 5308
 				{
5010 5309
 					$keep_alive_dom = null;
5011 5310
 					$keep_alive = false;
@@ -5017,17 +5316,19 @@  discard block
 block discarded – undo
5017 5316
 			$data = '';
5018 5317
 			if (isset($content_length))
5019 5318
 			{
5020
-				while (!feof($fp) && strlen($data) < $content_length)
5021
-					$data .= fread($fp, $content_length - strlen($data));
5022
-			}
5023
-			else
5319
+				while (!feof($fp) && strlen($data) < $content_length) {
5320
+									$data .= fread($fp, $content_length - strlen($data));
5321
+				}
5322
+			} else
5024 5323
 			{
5025
-				while (!feof($fp))
5026
-					$data .= fread($fp, 4096);
5324
+				while (!feof($fp)) {
5325
+									$data .= fread($fp, 4096);
5326
+				}
5027 5327
 			}
5028 5328
 
5029
-			if (!$keep_alive)
5030
-				fclose($fp);
5329
+			if (!$keep_alive) {
5330
+							fclose($fp);
5331
+			}
5031 5332
 		}
5032 5333
 
5033 5334
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5040,17 +5341,18 @@  discard block
 block discarded – undo
5040 5341
 			$fetch_data->get_url_data($url, $post_data);
5041 5342
 
5042 5343
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5043
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5044
-				$data = $fetch_data->result('body');
5045
-			else
5046
-				return false;
5344
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5345
+							$data = $fetch_data->result('body');
5346
+			} else {
5347
+							return false;
5348
+			}
5047 5349
 		}
5048 5350
 
5049 5351
 		// Neither fsockopen nor curl are available. Well, phooey.
5050
-		else
5051
-			return false;
5052
-	}
5053
-	else
5352
+		else {
5353
+					return false;
5354
+		}
5355
+	} else
5054 5356
 	{
5055 5357
 		// Umm, this shouldn't happen?
5056 5358
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5070,8 +5372,9 @@  discard block
 block discarded – undo
5070 5372
 	global $user_info, $smcFunc;
5071 5373
 
5072 5374
 	// Make sure we have something to work with.
5073
-	if (empty($topic))
5074
-		return array();
5375
+	if (empty($topic)) {
5376
+			return array();
5377
+	}
5075 5378
 
5076 5379
 
5077 5380
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5094,8 +5397,9 @@  discard block
 block discarded – undo
5094 5397
 				'topic' => $topic,
5095 5398
 			)
5096 5399
 		);
5097
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5098
-			$temp[] = (int) $row['content_id'];
5400
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5401
+					$temp[] = (int) $row['content_id'];
5402
+		}
5099 5403
 
5100 5404
 		cache_put_data($cache_key, $temp, $ttl);
5101 5405
 	}
@@ -5116,8 +5420,9 @@  discard block
 block discarded – undo
5116 5420
 {
5117 5421
 	global $context;
5118 5422
 
5119
-	if (empty($string))
5120
-		return $string;
5423
+	if (empty($string)) {
5424
+			return $string;
5425
+	}
5121 5426
 
5122 5427
 	// UTF-8 occurences of MS special characters
5123 5428
 	$findchars_utf8 = array(
@@ -5158,10 +5463,11 @@  discard block
 block discarded – undo
5158 5463
 		'--',	// &mdash;
5159 5464
 	);
5160 5465
 
5161
-	if ($context['utf8'])
5162
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5163
-	else
5164
-		$string = str_replace($findchars_iso, $replacechars, $string);
5466
+	if ($context['utf8']) {
5467
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5468
+	} else {
5469
+			$string = str_replace($findchars_iso, $replacechars, $string);
5470
+	}
5165 5471
 
5166 5472
 	return $string;
5167 5473
 }
@@ -5180,49 +5486,59 @@  discard block
 block discarded – undo
5180 5486
 {
5181 5487
 	global $context;
5182 5488
 
5183
-	if (!isset($matches[2]))
5184
-		return '';
5489
+	if (!isset($matches[2])) {
5490
+			return '';
5491
+	}
5185 5492
 
5186 5493
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5187 5494
 
5188 5495
 	// remove left to right / right to left overrides
5189
-	if ($num === 0x202D || $num === 0x202E)
5190
-		return '';
5496
+	if ($num === 0x202D || $num === 0x202E) {
5497
+			return '';
5498
+	}
5191 5499
 
5192 5500
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5193
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5194
-		return '&#' . $num . ';';
5501
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5502
+			return '&#' . $num . ';';
5503
+	}
5195 5504
 
5196 5505
 	if (empty($context['utf8']))
5197 5506
 	{
5198 5507
 		// no control characters
5199
-		if ($num < 0x20)
5200
-			return '';
5508
+		if ($num < 0x20) {
5509
+					return '';
5510
+		}
5201 5511
 		// text is text
5202
-		elseif ($num < 0x80)
5203
-			return chr($num);
5512
+		elseif ($num < 0x80) {
5513
+					return chr($num);
5514
+		}
5204 5515
 		// all others get html-ised
5205
-		else
5206
-			return '&#' . $matches[2] . ';';
5207
-	}
5208
-	else
5516
+		else {
5517
+					return '&#' . $matches[2] . ';';
5518
+		}
5519
+	} else
5209 5520
 	{
5210 5521
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5211 5522
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5212
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5213
-			return '';
5523
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5524
+					return '';
5525
+		}
5214 5526
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5215
-		elseif ($num < 0x80)
5216
-			return chr($num);
5527
+		elseif ($num < 0x80) {
5528
+					return chr($num);
5529
+		}
5217 5530
 		// <0x800 (2048)
5218
-		elseif ($num < 0x800)
5219
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5531
+		elseif ($num < 0x800) {
5532
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5533
+		}
5220 5534
 		// < 0x10000 (65536)
5221
-		elseif ($num < 0x10000)
5222
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5535
+		elseif ($num < 0x10000) {
5536
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5537
+		}
5223 5538
 		// <= 0x10FFFF (1114111)
5224
-		else
5225
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5539
+		else {
5540
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5541
+		}
5226 5542
 	}
5227 5543
 }
5228 5544
 
@@ -5238,28 +5554,34 @@  discard block
 block discarded – undo
5238 5554
  */
5239 5555
 function fixchar__callback($matches)
5240 5556
 {
5241
-	if (!isset($matches[1]))
5242
-		return '';
5557
+	if (!isset($matches[1])) {
5558
+			return '';
5559
+	}
5243 5560
 
5244 5561
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5245 5562
 
5246 5563
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5247 5564
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5248
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5249
-		return '';
5565
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5566
+			return '';
5567
+	}
5250 5568
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5251
-	elseif ($num < 0x80)
5252
-		return chr($num);
5569
+	elseif ($num < 0x80) {
5570
+			return chr($num);
5571
+	}
5253 5572
 	// <0x800 (2048)
5254
-	elseif ($num < 0x800)
5255
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5573
+	elseif ($num < 0x800) {
5574
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5575
+	}
5256 5576
 	// < 0x10000 (65536)
5257
-	elseif ($num < 0x10000)
5258
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5577
+	elseif ($num < 0x10000) {
5578
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5579
+	}
5259 5580
 	// <= 0x10FFFF (1114111)
5260
-	else
5261
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5262
-}
5581
+	else {
5582
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5583
+	}
5584
+	}
5263 5585
 
5264 5586
 /**
5265 5587
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5272,17 +5594,19 @@  discard block
 block discarded – undo
5272 5594
  */
5273 5595
 function entity_fix__callback($matches)
5274 5596
 {
5275
-	if (!isset($matches[2]))
5276
-		return '';
5597
+	if (!isset($matches[2])) {
5598
+			return '';
5599
+	}
5277 5600
 
5278 5601
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5279 5602
 
5280 5603
 	// we don't allow control characters, characters out of range, byte markers, etc
5281
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5282
-		return '';
5283
-	else
5284
-		return '&#' . $num . ';';
5285
-}
5604
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5605
+			return '';
5606
+	} else {
5607
+			return '&#' . $num . ';';
5608
+	}
5609
+	}
5286 5610
 
5287 5611
 /**
5288 5612
  * Return a Gravatar URL based on
@@ -5306,18 +5630,23 @@  discard block
 block discarded – undo
5306 5630
 		$ratings = array('G', 'PG', 'R', 'X');
5307 5631
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5308 5632
 		$url_params = array();
5309
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5310
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5311
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5312
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5313
-		if (!empty($modSettings['avatar_max_width_external']))
5314
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5315
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5316
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5633
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5634
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5635
+		}
5636
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5637
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5638
+		}
5639
+		if (!empty($modSettings['avatar_max_width_external'])) {
5640
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5641
+		}
5642
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5643
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5317 5644
 				$size_string = $modSettings['avatar_max_height_external'];
5645
+		}
5318 5646
 
5319
-		if (!empty($size_string))
5320
-			$url_params[] = 's=' . $size_string;
5647
+		if (!empty($size_string)) {
5648
+					$url_params[] = 's=' . $size_string;
5649
+		}
5321 5650
 	}
5322 5651
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5323 5652
 
@@ -5336,22 +5665,26 @@  discard block
 block discarded – undo
5336 5665
 	static $timezones = null, $lastwhen = null;
5337 5666
 
5338 5667
 	// No point doing this over if we already did it once
5339
-	if (!empty($timezones) && $when == $lastwhen)
5340
-		return $timezones;
5341
-	else
5342
-		$lastwhen = $when;
5668
+	if (!empty($timezones) && $when == $lastwhen) {
5669
+			return $timezones;
5670
+	} else {
5671
+			$lastwhen = $when;
5672
+	}
5343 5673
 
5344 5674
 	// Parseable datetime string?
5345
-	if (is_int($timestamp = strtotime($when)))
5346
-		$when = $timestamp;
5675
+	if (is_int($timestamp = strtotime($when))) {
5676
+			$when = $timestamp;
5677
+	}
5347 5678
 
5348 5679
 	// A Unix timestamp?
5349
-	elseif (is_numeric($when))
5350
-		$when = intval($when);
5680
+	elseif (is_numeric($when)) {
5681
+			$when = intval($when);
5682
+	}
5351 5683
 
5352 5684
 	// Invalid value? Just get current Unix timestamp.
5353
-	else
5354
-		$when = time();
5685
+	else {
5686
+			$when = time();
5687
+	}
5355 5688
 
5356 5689
 	// We'll need these too
5357 5690
 	$date_when = date_create('@' . $when);
@@ -5366,8 +5699,9 @@  discard block
 block discarded – undo
5366 5699
 	foreach ($priority_countries as $country)
5367 5700
 	{
5368 5701
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5369
-		if (!empty($country_tzids))
5370
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5702
+		if (!empty($country_tzids)) {
5703
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5704
+		}
5371 5705
 	}
5372 5706
 
5373 5707
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5381,8 +5715,9 @@  discard block
 block discarded – undo
5381 5715
 	foreach ($tzids as $tzid)
5382 5716
 	{
5383 5717
 		// We don't want UTC right now
5384
-		if ($tzid == 'UTC')
5385
-			continue;
5718
+		if ($tzid == 'UTC') {
5719
+					continue;
5720
+		}
5386 5721
 
5387 5722
 		$tz = timezone_open($tzid);
5388 5723
 
@@ -5403,13 +5738,14 @@  discard block
 block discarded – undo
5403 5738
 		}
5404 5739
 
5405 5740
 		// A time zone from a prioritized country?
5406
-		if (in_array($tzid, $priority_tzids))
5407
-			$priority_zones[$tzkey] = true;
5741
+		if (in_array($tzid, $priority_tzids)) {
5742
+					$priority_zones[$tzkey] = true;
5743
+		}
5408 5744
 
5409 5745
 		// Keep track of the location and offset for this tzid
5410
-		if (!empty($txt[$tzid]))
5411
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5412
-		else
5746
+		if (!empty($txt[$tzid])) {
5747
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5748
+		} else
5413 5749
 		{
5414 5750
 			$tzid_parts = explode('/', $tzid);
5415 5751
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5429,23 +5765,27 @@  discard block
 block discarded – undo
5429 5765
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5430 5766
 
5431 5767
 		// Use the custom description, if there is one
5432
-		if (!empty($tztxt[$tzvalue['tzid']]))
5433
-			$desc = $tztxt[$tzvalue['tzid']];
5768
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5769
+					$desc = $tztxt[$tzvalue['tzid']];
5770
+		}
5434 5771
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5435
-		else
5436
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5772
+		else {
5773
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5774
+		}
5437 5775
 
5438 5776
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5439 5777
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5440 5778
 
5441
-		if (isset($priority_zones[$tzkey]))
5442
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5443
-		else
5444
-			$timezones[$tzvalue['tzid']] = $desc;
5779
+		if (isset($priority_zones[$tzkey])) {
5780
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5781
+		} else {
5782
+					$timezones[$tzvalue['tzid']] = $desc;
5783
+		}
5445 5784
 	}
5446 5785
 
5447
-	if (!empty($priority_timezones))
5448
-		$priority_timezones[] = '-----';
5786
+	if (!empty($priority_timezones)) {
5787
+			$priority_timezones[] = '-----';
5788
+	}
5449 5789
 
5450 5790
 	$timezones = array_merge(
5451 5791
 		$priority_timezones,
@@ -5462,8 +5802,9 @@  discard block
 block discarded – undo
5462 5802
  */
5463 5803
 function inet_ptod($ip_address)
5464 5804
 {
5465
-	if (!isValidIP($ip_address))
5466
-		return $ip_address;
5805
+	if (!isValidIP($ip_address)) {
5806
+			return $ip_address;
5807
+	}
5467 5808
 
5468 5809
 	$bin = inet_pton($ip_address);
5469 5810
 	return $bin;
@@ -5475,13 +5816,15 @@  discard block
 block discarded – undo
5475 5816
  */
5476 5817
 function inet_dtop($bin)
5477 5818
 {
5478
-	if(empty($bin))
5479
-		return '';
5819
+	if(empty($bin)) {
5820
+			return '';
5821
+	}
5480 5822
 
5481 5823
 	global $db_type;
5482 5824
 
5483
-	if ($db_type == 'postgresql')
5484
-		return $bin;
5825
+	if ($db_type == 'postgresql') {
5826
+			return $bin;
5827
+	}
5485 5828
 
5486 5829
 	$ip_address = inet_ntop($bin);
5487 5830
 
@@ -5506,26 +5849,32 @@  discard block
 block discarded – undo
5506 5849
  */
5507 5850
 function _safe_serialize($value)
5508 5851
 {
5509
-	if(is_null($value))
5510
-		return 'N;';
5852
+	if(is_null($value)) {
5853
+			return 'N;';
5854
+	}
5511 5855
 
5512
-	if(is_bool($value))
5513
-		return 'b:'. (int) $value .';';
5856
+	if(is_bool($value)) {
5857
+			return 'b:'. (int) $value .';';
5858
+	}
5514 5859
 
5515
-	if(is_int($value))
5516
-		return 'i:'. $value .';';
5860
+	if(is_int($value)) {
5861
+			return 'i:'. $value .';';
5862
+	}
5517 5863
 
5518
-	if(is_float($value))
5519
-		return 'd:'. str_replace(',', '.', $value) .';';
5864
+	if(is_float($value)) {
5865
+			return 'd:'. str_replace(',', '.', $value) .';';
5866
+	}
5520 5867
 
5521
-	if(is_string($value))
5522
-		return 's:'. strlen($value) .':"'. $value .'";';
5868
+	if(is_string($value)) {
5869
+			return 's:'. strlen($value) .':"'. $value .'";';
5870
+	}
5523 5871
 
5524 5872
 	if(is_array($value))
5525 5873
 	{
5526 5874
 		$out = '';
5527
-		foreach($value as $k => $v)
5528
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5875
+		foreach($value as $k => $v) {
5876
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5877
+		}
5529 5878
 
5530 5879
 		return 'a:'. count($value) .':{'. $out .'}';
5531 5880
 	}
@@ -5551,8 +5900,9 @@  discard block
 block discarded – undo
5551 5900
 
5552 5901
 	$out = _safe_serialize($value);
5553 5902
 
5554
-	if (isset($mbIntEnc))
5555
-		mb_internal_encoding($mbIntEnc);
5903
+	if (isset($mbIntEnc)) {
5904
+			mb_internal_encoding($mbIntEnc);
5905
+	}
5556 5906
 
5557 5907
 	return $out;
5558 5908
 }
@@ -5569,8 +5919,9 @@  discard block
 block discarded – undo
5569 5919
 function _safe_unserialize($str)
5570 5920
 {
5571 5921
 	// Input  is not a string.
5572
-	if(empty($str) || !is_string($str))
5573
-		return false;
5922
+	if(empty($str) || !is_string($str)) {
5923
+			return false;
5924
+	}
5574 5925
 
5575 5926
 	$stack = array();
5576 5927
 	$expected = array();
@@ -5586,43 +5937,38 @@  discard block
 block discarded – undo
5586 5937
 	while($state != 1)
5587 5938
 	{
5588 5939
 		$type = isset($str[0]) ? $str[0] : '';
5589
-		if($type == '}')
5590
-			$str = substr($str, 1);
5591
-
5592
-		else if($type == 'N' && $str[1] == ';')
5940
+		if($type == '}') {
5941
+					$str = substr($str, 1);
5942
+		} else if($type == 'N' && $str[1] == ';')
5593 5943
 		{
5594 5944
 			$value = null;
5595 5945
 			$str = substr($str, 2);
5596
-		}
5597
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5946
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5598 5947
 		{
5599 5948
 			$value = $matches[1] == '1' ? true : false;
5600 5949
 			$str = substr($str, 4);
5601
-		}
5602
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5950
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5603 5951
 		{
5604 5952
 			$value = (int)$matches[1];
5605 5953
 			$str = $matches[2];
5606
-		}
5607
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5954
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5608 5955
 		{
5609 5956
 			$value = (float)$matches[1];
5610 5957
 			$str = $matches[3];
5611
-		}
5612
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5958
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5613 5959
 		{
5614 5960
 			$value = substr($matches[2], 0, (int)$matches[1]);
5615 5961
 			$str = substr($matches[2], (int)$matches[1] + 2);
5616
-		}
5617
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5962
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5618 5963
 		{
5619 5964
 			$expectedLength = (int)$matches[1];
5620 5965
 			$str = $matches[2];
5621 5966
 		}
5622 5967
 
5623 5968
 		// Object or unknown/malformed type.
5624
-		else
5625
-			return false;
5969
+		else {
5970
+					return false;
5971
+		}
5626 5972
 
5627 5973
 		switch($state)
5628 5974
 		{
@@ -5650,8 +5996,9 @@  discard block
 block discarded – undo
5650 5996
 				if($type == '}')
5651 5997
 				{
5652 5998
 					// Array size is less than expected.
5653
-					if(count($list) < end($expected))
5654
-						return false;
5999
+					if(count($list) < end($expected)) {
6000
+											return false;
6001
+					}
5655 6002
 
5656 6003
 					unset($list);
5657 6004
 					$list = &$stack[count($stack)-1];
@@ -5660,8 +6007,9 @@  discard block
 block discarded – undo
5660 6007
 					// Go to terminal state if we're at the end of the root array.
5661 6008
 					array_pop($expected);
5662 6009
 
5663
-					if(count($expected) == 0)
5664
-						$state = 1;
6010
+					if(count($expected) == 0) {
6011
+											$state = 1;
6012
+					}
5665 6013
 
5666 6014
 					break;
5667 6015
 				}
@@ -5669,8 +6017,9 @@  discard block
 block discarded – undo
5669 6017
 				if($type == 'i' || $type == 's')
5670 6018
 				{
5671 6019
 					// Array size exceeds expected length.
5672
-					if(count($list) >= end($expected))
5673
-						return false;
6020
+					if(count($list) >= end($expected)) {
6021
+											return false;
6022
+					}
5674 6023
 
5675 6024
 					$key = $value;
5676 6025
 					$state = 3;
@@ -5704,8 +6053,9 @@  discard block
 block discarded – undo
5704 6053
 	}
5705 6054
 
5706 6055
 	// Trailing data in input.
5707
-	if(!empty($str))
5708
-		return false;
6056
+	if(!empty($str)) {
6057
+			return false;
6058
+	}
5709 6059
 
5710 6060
 	return $data;
5711 6061
 }
@@ -5728,8 +6078,9 @@  discard block
 block discarded – undo
5728 6078
 
5729 6079
 	$out = _safe_unserialize($str);
5730 6080
 
5731
-	if (isset($mbIntEnc))
5732
-		mb_internal_encoding($mbIntEnc);
6081
+	if (isset($mbIntEnc)) {
6082
+			mb_internal_encoding($mbIntEnc);
6083
+	}
5733 6084
 
5734 6085
 	return $out;
5735 6086
 }
@@ -5744,12 +6095,14 @@  discard block
 block discarded – undo
5744 6095
 function smf_chmod($file, $value = 0)
5745 6096
 {
5746 6097
 	// No file? no checks!
5747
-	if (empty($file))
5748
-		return false;
6098
+	if (empty($file)) {
6099
+			return false;
6100
+	}
5749 6101
 
5750 6102
 	// Already writable?
5751
-	if (is_writable($file))
5752
-		return true;
6103
+	if (is_writable($file)) {
6104
+			return true;
6105
+	}
5753 6106
 
5754 6107
 	// Do we have a file or a dir?
5755 6108
 	$isDir = is_dir($file);
@@ -5765,10 +6118,9 @@  discard block
 block discarded – undo
5765 6118
 		{
5766 6119
 			$isWritable = true;
5767 6120
 			break;
6121
+		} else {
6122
+					@chmod($file, $val);
5768 6123
 		}
5769
-
5770
-		else
5771
-			@chmod($file, $val);
5772 6124
 	}
5773 6125
 
5774 6126
 	return $isWritable;
@@ -5787,8 +6139,9 @@  discard block
 block discarded – undo
5787 6139
 	global $txt;
5788 6140
 
5789 6141
 	// Come on...
5790
-	if (empty($json) || !is_string($json))
5791
-		return array();
6142
+	if (empty($json) || !is_string($json)) {
6143
+			return array();
6144
+	}
5792 6145
 
5793 6146
 	$returnArray = @json_decode($json, $returnAsArray);
5794 6147
 
@@ -5826,11 +6179,11 @@  discard block
 block discarded – undo
5826 6179
 		$jsonDebug = $jsonDebug[0];
5827 6180
 		loadLanguage('Errors');
5828 6181
 
5829
-		if (!empty($jsonDebug))
5830
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5831
-
5832
-		else
5833
-			log_error($txt['json_'. $jsonError], 'critical');
6182
+		if (!empty($jsonDebug)) {
6183
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6184
+		} else {
6185
+					log_error($txt['json_'. $jsonError], 'critical');
6186
+		}
5834 6187
 
5835 6188
 		// Everyone expects an array.
5836 6189
 		return array();
@@ -5864,8 +6217,9 @@  discard block
 block discarded – undo
5864 6217
 	global $db_show_debug, $modSettings;
5865 6218
 
5866 6219
 	// Defensive programming anyone?
5867
-	if (empty($data))
5868
-		return false;
6220
+	if (empty($data)) {
6221
+			return false;
6222
+	}
5869 6223
 
5870 6224
 	// Don't need extra stuff...
5871 6225
 	$db_show_debug = false;
@@ -5873,11 +6227,11 @@  discard block
 block discarded – undo
5873 6227
 	// Kill anything else.
5874 6228
 	ob_end_clean();
5875 6229
 
5876
-	if (!empty($modSettings['CompressedOutput']))
5877
-		@ob_start('ob_gzhandler');
5878
-
5879
-	else
5880
-		ob_start();
6230
+	if (!empty($modSettings['CompressedOutput'])) {
6231
+			@ob_start('ob_gzhandler');
6232
+	} else {
6233
+			ob_start();
6234
+	}
5881 6235
 
5882 6236
 	// Set the header.
5883 6237
 	header($type);
@@ -5909,8 +6263,9 @@  discard block
 block discarded – undo
5909 6263
 	static $done = false;
5910 6264
 
5911 6265
 	// If we don't need to do anything, don't
5912
-	if (!$update && $done)
5913
-		return;
6266
+	if (!$update && $done) {
6267
+			return;
6268
+	}
5914 6269
 
5915 6270
 	// Should we get a new copy of the official list of TLDs?
5916 6271
 	if ($update)
@@ -5922,8 +6277,9 @@  discard block
 block discarded – undo
5922 6277
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
5923 6278
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
5924 6279
 		// update to see if civilization has been restored.
5925
-		if ($tlds === false)
5926
-			$postapocalypticNightmare = true;
6280
+		if ($tlds === false) {
6281
+					$postapocalypticNightmare = true;
6282
+		}
5927 6283
 	}
5928 6284
 	// If we aren't updating and the regex is valid, we're done
5929 6285
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -5938,10 +6294,11 @@  discard block
 block discarded – undo
5938 6294
 		// Clean $tlds and convert it to an array
5939 6295
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5940 6296
 			$line = trim($line);
5941
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5942
-				return false;
5943
-			else
5944
-				return true;
6297
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6298
+							return false;
6299
+			} else {
6300
+							return true;
6301
+			}
5945 6302
 		});
5946 6303
 
5947 6304
 		// Convert Punycode to Unicode
@@ -6033,8 +6390,7 @@  discard block
 block discarded – undo
6033 6390
 
6034 6391
 		$strlen = 'mb_strlen';
6035 6392
 		$substr = 'mb_substr';
6036
-	}
6037
-	else
6393
+	} else
6038 6394
 	{
6039 6395
 		$strlen = $smcFunc['strlen'];
6040 6396
 		$substr = $smcFunc['substr'];
@@ -6048,20 +6404,21 @@  discard block
 block discarded – undo
6048 6404
 
6049 6405
 		$first = $substr($string, 0, 1);
6050 6406
 
6051
-		if (empty($index[$first]))
6052
-			$index[$first] = array();
6407
+		if (empty($index[$first])) {
6408
+					$index[$first] = array();
6409
+		}
6053 6410
 
6054 6411
 		if ($strlen($string) > 1)
6055 6412
 		{
6056 6413
 			// Sanity check on recursion
6057
-			if ($depth > 99)
6058
-				$index[$first][$substr($string, 1)] = '';
6059
-
6060
-			else
6061
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6414
+			if ($depth > 99) {
6415
+							$index[$first][$substr($string, 1)] = '';
6416
+			} else {
6417
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6418
+			}
6419
+		} else {
6420
+					$index[$first][''] = '';
6062 6421
 		}
6063
-		else
6064
-			$index[$first][''] = '';
6065 6422
 
6066 6423
 		$depth--;
6067 6424
 		return $index;
@@ -6084,9 +6441,9 @@  discard block
 block discarded – undo
6084 6441
 			$key_regex = preg_quote($key, $delim);
6085 6442
 			$new_key = $key;
6086 6443
 
6087
-			if (empty($value))
6088
-				$sub_regex = '';
6089
-			else
6444
+			if (empty($value)) {
6445
+							$sub_regex = '';
6446
+			} else
6090 6447
 			{
6091 6448
 				$sub_regex = $index_to_regex($value, $delim);
6092 6449
 
@@ -6094,22 +6451,22 @@  discard block
 block discarded – undo
6094 6451
 				{
6095 6452
 					$new_key_array = explode('(?'.'>', $sub_regex);
6096 6453
 					$new_key .= $new_key_array[0];
6454
+				} else {
6455
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6097 6456
 				}
6098
-				else
6099
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6100 6457
 			}
6101 6458
 
6102
-			if ($depth > 1)
6103
-				$regex[$new_key] = $key_regex . $sub_regex;
6104
-			else
6459
+			if ($depth > 1) {
6460
+							$regex[$new_key] = $key_regex . $sub_regex;
6461
+			} else
6105 6462
 			{
6106 6463
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6107 6464
 				{
6108 6465
 					$regex[$new_key] = $key_regex . $sub_regex;
6109 6466
 					unset($index[$key]);
6467
+				} else {
6468
+									break;
6110 6469
 				}
6111
-				else
6112
-					break;
6113 6470
 			}
6114 6471
 		}
6115 6472
 
@@ -6118,10 +6475,11 @@  discard block
 block discarded – undo
6118 6475
 			$l1 = $strlen($k1);
6119 6476
 			$l2 = $strlen($k2);
6120 6477
 
6121
-			if ($l1 == $l2)
6122
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6123
-			else
6124
-				return $l1 > $l2 ? -1 : 1;
6478
+			if ($l1 == $l2) {
6479
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6480
+			} else {
6481
+							return $l1 > $l2 ? -1 : 1;
6482
+			}
6125 6483
 		});
6126 6484
 
6127 6485
 		$depth--;
@@ -6132,21 +6490,24 @@  discard block
 block discarded – undo
6132 6490
 	$index = array();
6133 6491
 	$regex = '';
6134 6492
 
6135
-	foreach ($strings as $string)
6136
-		$index = $add_string_to_index($string, $index);
6493
+	foreach ($strings as $string) {
6494
+			$index = $add_string_to_index($string, $index);
6495
+	}
6137 6496
 
6138 6497
 	if ($returnArray === true)
6139 6498
 	{
6140 6499
 		$regex = array();
6141
-		while (!empty($index))
6142
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6500
+		while (!empty($index)) {
6501
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6502
+		}
6503
+	} else {
6504
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6143 6505
 	}
6144
-	else
6145
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6146 6506
 
6147 6507
 	// Restore PHP's internal character encoding to whatever it was originally
6148
-	if (!empty($current_encoding))
6149
-		mb_internal_encoding($current_encoding);
6508
+	if (!empty($current_encoding)) {
6509
+			mb_internal_encoding($current_encoding);
6510
+	}
6150 6511
 
6151 6512
 	return $regex;
6152 6513
 }
@@ -6189,13 +6550,15 @@  discard block
 block discarded – undo
6189 6550
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6190 6551
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6191 6552
 	$headers = @get_headers($url);
6192
-	if ($headers === false)
6193
-		return false;
6553
+	if ($headers === false) {
6554
+			return false;
6555
+	}
6194 6556
 
6195 6557
 	// Now to see if it came back https...
6196 6558
 	// First check for a redirect status code in first row (301, 302, 307)
6197
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6198
-		return false;
6559
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6560
+			return false;
6561
+	}
6199 6562
 
6200 6563
 	// Search for the location entry to confirm https
6201 6564
 	$result = false;
@@ -6233,8 +6596,7 @@  discard block
 block discarded – undo
6233 6596
 		$is_admin = $user_info['is_admin'];
6234 6597
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6235 6598
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6236
-	}
6237
-	else
6599
+	} else
6238 6600
 	{
6239 6601
 		$request = $smcFunc['db_query']('', '
6240 6602
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6248,17 +6610,19 @@  discard block
 block discarded – undo
6248 6610
 
6249 6611
 		$row = $smcFunc['db_fetch_assoc']($request);
6250 6612
 
6251
-		if (empty($row['additional_groups']))
6252
-			$groups = array($row['id_group'], $row['id_post_group']);
6253
-		else
6254
-			$groups = array_merge(
6613
+		if (empty($row['additional_groups'])) {
6614
+					$groups = array($row['id_group'], $row['id_post_group']);
6615
+		} else {
6616
+					$groups = array_merge(
6255 6617
 					array($row['id_group'], $row['id_post_group']),
6256 6618
 					explode(',', $row['additional_groups'])
6257 6619
 			);
6620
+		}
6258 6621
 
6259 6622
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6260
-		foreach ($groups as $k => $v)
6261
-			$groups[$k] = (int) $v;
6623
+		foreach ($groups as $k => $v) {
6624
+					$groups[$k] = (int) $v;
6625
+		}
6262 6626
 
6263 6627
 		$is_admin = in_array(1, $groups);
6264 6628
 
@@ -6275,8 +6639,9 @@  discard block
 block discarded – undo
6275 6639
 				'current_member' => $userid,
6276 6640
 			)
6277 6641
 		);
6278
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6279
-			$boards_mod[] = $row['id_board'];
6642
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6643
+					$boards_mod[] = $row['id_board'];
6644
+		}
6280 6645
 		$smcFunc['db_free_result']($request);
6281 6646
 
6282 6647
 		// Can any of the groups they're in moderate any of the boards?
@@ -6288,8 +6653,9 @@  discard block
 block discarded – undo
6288 6653
 				'groups' => $groups,
6289 6654
 			)
6290 6655
 		);
6291
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6292
-			$boards_mod[] = $row['id_board'];
6656
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6657
+					$boards_mod[] = $row['id_board'];
6658
+		}
6293 6659
 		$smcFunc['db_free_result']($request);
6294 6660
 
6295 6661
 		// Just in case we've got duplicates here...
@@ -6299,21 +6665,25 @@  discard block
 block discarded – undo
6299 6665
 	}
6300 6666
 
6301 6667
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6302
-	if ($is_admin)
6303
-		$query_part['query_see_board'] = '1=1';
6668
+	if ($is_admin) {
6669
+			$query_part['query_see_board'] = '1=1';
6670
+	}
6304 6671
 	// Otherwise just the groups in $user_info['groups'].
6305
-	else
6306
-		$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6672
+	else {
6673
+			$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6674
+	}
6307 6675
 
6308 6676
 	// Build the list of boards they WANT to see.
6309 6677
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6310 6678
 
6311 6679
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6312
-	if (empty($ignoreboards))
6313
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6680
+	if (empty($ignoreboards)) {
6681
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6682
+	}
6314 6683
 	// Ok I guess they don't want to see all the boards
6315
-	else
6316
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6684
+	else {
6685
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6686
+	}
6317 6687
 
6318 6688
 	return $query_part;
6319 6689
 }
@@ -6327,10 +6697,11 @@  discard block
 block discarded – undo
6327 6697
 {
6328 6698
 	$secure = false;
6329 6699
 
6330
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6331
-		$secure = true;
6332
-	elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
6333
-		$secure = true;
6700
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6701
+			$secure = true;
6702
+	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
6703
+			$secure = true;
6704
+	}
6334 6705
 
6335 6706
 	return $secure;
6336 6707
 }
@@ -6347,11 +6718,12 @@  discard block
 block discarded – undo
6347 6718
 {
6348 6719
 	$url = iri_to_url($iri);
6349 6720
 
6350
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6351
-		return $iri;
6352
-	else
6353
-		return false;
6354
-}
6721
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6722
+			return $iri;
6723
+	} else {
6724
+			return false;
6725
+	}
6726
+	}
6355 6727
 
6356 6728
 /**
6357 6729
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6394,8 +6766,9 @@  discard block
 block discarded – undo
6394 6766
 
6395 6767
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6396 6768
 
6397
-	if (empty($host))
6398
-		return $iri;
6769
+	if (empty($host)) {
6770
+			return $iri;
6771
+	}
6399 6772
 
6400 6773
 	// Convert the domain using the Punycode algorithm
6401 6774
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6431,8 +6804,9 @@  discard block
 block discarded – undo
6431 6804
 
6432 6805
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6433 6806
 
6434
-	if (empty($host))
6435
-		return $url;
6807
+	if (empty($host)) {
6808
+			return $url;
6809
+	}
6436 6810
 
6437 6811
 	// Decode the domain from Punycode
6438 6812
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6458,8 +6832,9 @@  discard block
 block discarded – undo
6458 6832
 {
6459 6833
 	global $user_info, $modSettings, $smcFunc, $txt;
6460 6834
 
6461
-	if (empty($modSettings['cron_last_checked']))
6462
-		$modSettings['cron_last_checked'] = 0;
6835
+	if (empty($modSettings['cron_last_checked'])) {
6836
+			$modSettings['cron_last_checked'] = 0;
6837
+	}
6463 6838
 
6464 6839
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6465 6840
 	{
@@ -6479,9 +6854,9 @@  discard block
 block discarded – undo
6479 6854
 			loadLanguage('ManageScheduledTasks');
6480 6855
 			log_error($txt['cron_not_working']);
6481 6856
 			updateSettings(array('cron_is_real_cron' => 0));
6857
+		} else {
6858
+					updateSettings(array('cron_last_checked' => time()));
6482 6859
 		}
6483
-		else
6484
-			updateSettings(array('cron_last_checked' => time()));
6485 6860
 	}
6486 6861
 }
6487 6862
 
Please login to merge, or discard this patch.
Spacing   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 			{
387 387
 				$val = 'CASE ';
388 388
 				foreach ($members as $k => $v)
389
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
389
+					$val .= 'WHEN id_member = ' . $v . ' THEN ' . count(fetch_alerts($v, false, 0, array(), false)) . ' ';
390 390
 				$val = $val . ' END';
391 391
 				$type = 'raw';
392 392
 			}
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 	static $non_twelve_hour, $locale_cache;
740 740
 	static $unsupportedFormats, $finalizedFormats;
741 741
 
742
-	$unsupportedFormatsWindows = array('z','Z');
742
+	$unsupportedFormatsWindows = array('z', 'Z');
743 743
 
744 744
 	// Ensure required values are set
745 745
 	$user_info['time_offset'] = !empty($user_info['time_offset']) ? $user_info['time_offset'] : 0;
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
825 825
 		if (empty($unsupportedFormats))
826 826
 		{
827
-			foreach($strftimeFormatSubstitutions as $format => $substitution)
827
+			foreach ($strftimeFormatSubstitutions as $format => $substitution)
828 828
 			{
829 829
 				// Avoid a crashing bug with PHP 7 on certain versions of Windows
830 830
 				if ($context['server']['is_windows'] && in_array($format, $unsupportedFormatsWindows))
@@ -1196,7 +1196,7 @@  discard block
 block discarded – undo
1196 1196
 					'height' => array('optional' => true, 'match' => '(\d+)'),
1197 1197
 				),
1198 1198
 				'content' => '$1',
1199
-				'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1199
+				'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt)
1200 1200
 				{
1201 1201
 					$returnContext = '';
1202 1202
 
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
 						}
1232 1232
 
1233 1233
 						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1234
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1234
+							$returnContext .= '<a href="' . $currentAttachment['href'] . ';image" id="link_' . $currentAttachment['id'] . '" onclick="' . $currentAttachment['thumbnail']['javascript'] . '"><img src="' . $currentAttachment['thumbnail']['href'] . '"' . $alt . $title . ' id="thumb_' . $currentAttachment['id'] . '" class="atc_img"></a>';
1235 1235
 						else
1236 1236
 							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1237 1237
 					}
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
 				'type' => 'unparsed_content',
1261 1261
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1262 1262
 				// @todo Maybe this can be simplified?
1263
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1263
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1264 1264
 				{
1265 1265
 					if (!isset($disabled['code']))
1266 1266
 					{
@@ -1297,7 +1297,7 @@  discard block
 block discarded – undo
1297 1297
 				'type' => 'unparsed_equals_content',
1298 1298
 				'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>',
1299 1299
 				// @todo Maybe this can be simplified?
1300
-				'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context)
1300
+				'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context)
1301 1301
 				{
1302 1302
 					if (!isset($disabled['code']))
1303 1303
 					{
@@ -1341,7 +1341,7 @@  discard block
 block discarded – undo
1341 1341
 				'type' => 'unparsed_content',
1342 1342
 				'content' => '<a href="mailto:$1" class="bbc_email">$1</a>',
1343 1343
 				// @todo Should this respect guest_hideContacts?
1344
-				'validate' => function (&$tag, &$data, $disabled)
1344
+				'validate' => function(&$tag, &$data, $disabled)
1345 1345
 				{
1346 1346
 					$data = strtr($data, array('<br>' => ''));
1347 1347
 				},
@@ -1360,7 +1360,7 @@  discard block
 block discarded – undo
1360 1360
 				'type' => 'unparsed_commas_content',
1361 1361
 				'test' => '\d+,\d+\]',
1362 1362
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1363
-				'validate' => function (&$tag, &$data, $disabled)
1363
+				'validate' => function(&$tag, &$data, $disabled)
1364 1364
 				{
1365 1365
 					if (isset($disabled['url']))
1366 1366
 						$tag['content'] = '$1';
@@ -1376,7 +1376,7 @@  discard block
 block discarded – undo
1376 1376
 				'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]',
1377 1377
 				'before' => '<div $1>',
1378 1378
 				'after' => '</div>',
1379
-				'validate' => function (&$tag, &$data, $disabled)
1379
+				'validate' => function(&$tag, &$data, $disabled)
1380 1380
 				{
1381 1381
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1382 1382
 
@@ -1425,7 +1425,7 @@  discard block
 block discarded – undo
1425 1425
 					'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
1426 1426
 				),
1427 1427
 				'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">',
1428
-				'validate' => function (&$tag, &$data, $disabled)
1428
+				'validate' => function(&$tag, &$data, $disabled)
1429 1429
 				{
1430 1430
 					global $image_proxy_enabled, $user_info;
1431 1431
 
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
 				'tag' => 'img',
1452 1452
 				'type' => 'unparsed_content',
1453 1453
 				'content' => '<img src="$1" alt="" class="bbc_img">',
1454
-				'validate' => function (&$tag, &$data, $disabled)
1454
+				'validate' => function(&$tag, &$data, $disabled)
1455 1455
 				{
1456 1456
 					global $image_proxy_enabled, $user_info;
1457 1457
 
@@ -1477,7 +1477,7 @@  discard block
 block discarded – undo
1477 1477
 				'tag' => 'iurl',
1478 1478
 				'type' => 'unparsed_content',
1479 1479
 				'content' => '<a href="$1" class="bbc_link">$1</a>',
1480
-				'validate' => function (&$tag, &$data, $disabled)
1480
+				'validate' => function(&$tag, &$data, $disabled)
1481 1481
 				{
1482 1482
 					$data = strtr($data, array('<br>' => ''));
1483 1483
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1491,7 +1491,7 @@  discard block
 block discarded – undo
1491 1491
 				'quoted' => 'optional',
1492 1492
 				'before' => '<a href="$1" class="bbc_link">',
1493 1493
 				'after' => '</a>',
1494
-				'validate' => function (&$tag, &$data, $disabled)
1494
+				'validate' => function(&$tag, &$data, $disabled)
1495 1495
 				{
1496 1496
 					if (substr($data, 0, 1) == '#')
1497 1497
 						$data = '#post_' . substr($data, 1);
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
 				'tag' => 'php',
1578 1578
 				'type' => 'unparsed_content',
1579 1579
 				'content' => '<span class="phpcode">$1</span>',
1580
-				'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled)
1580
+				'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled)
1581 1581
 				{
1582 1582
 					if (!isset($disabled['php']))
1583 1583
 					{
@@ -1675,7 +1675,7 @@  discard block
 block discarded – undo
1675 1675
 				'test' => '[1-7]\]',
1676 1676
 				'before' => '<span style="font-size: $1;" class="bbc_size">',
1677 1677
 				'after' => '</span>',
1678
-				'validate' => function (&$tag, &$data, $disabled)
1678
+				'validate' => function(&$tag, &$data, $disabled)
1679 1679
 				{
1680 1680
 					$sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95);
1681 1681
 					$data = $sizes[$data] . 'em';
@@ -1713,7 +1713,7 @@  discard block
 block discarded – undo
1713 1713
 				'tag' => 'time',
1714 1714
 				'type' => 'unparsed_content',
1715 1715
 				'content' => '$1',
1716
-				'validate' => function (&$tag, &$data, $disabled)
1716
+				'validate' => function(&$tag, &$data, $disabled)
1717 1717
 				{
1718 1718
 					if (is_numeric($data))
1719 1719
 						$data = timeformat($data);
@@ -1741,7 +1741,7 @@  discard block
 block discarded – undo
1741 1741
 				'tag' => 'url',
1742 1742
 				'type' => 'unparsed_content',
1743 1743
 				'content' => '<a href="$1" class="bbc_link" target="_blank" rel="noopener">$1</a>',
1744
-				'validate' => function (&$tag, &$data, $disabled)
1744
+				'validate' => function(&$tag, &$data, $disabled)
1745 1745
 				{
1746 1746
 					$data = strtr($data, array('<br>' => ''));
1747 1747
 					$scheme = parse_url($data, PHP_URL_SCHEME);
@@ -1755,7 +1755,7 @@  discard block
 block discarded – undo
1755 1755
 				'quoted' => 'optional',
1756 1756
 				'before' => '<a href="$1" class="bbc_link" target="_blank" rel="noopener">',
1757 1757
 				'after' => '</a>',
1758
-				'validate' => function (&$tag, &$data, $disabled)
1758
+				'validate' => function(&$tag, &$data, $disabled)
1759 1759
 				{
1760 1760
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1761 1761
 					if (empty($scheme))
@@ -1787,7 +1787,7 @@  discard block
 block discarded – undo
1787 1787
 		{
1788 1788
 			if (isset($temp_bbc))
1789 1789
 				$bbc_codes = $temp_bbc;
1790
-			usort($codes, function ($a, $b) {
1790
+			usort($codes, function($a, $b) {
1791 1791
 				return strcmp($a['tag'], $b['tag']);
1792 1792
 			});
1793 1793
 			return $codes;
@@ -2003,7 +2003,7 @@  discard block
 block discarded – undo
2003 2003
 										# a run of Unicode domain name characters and a dot
2004 2004
 										[\p{L}\p{M}\p{N}\-.:@]+\.
2005 2005
 										# and then a TLD valid in the DNS or the reserved "local" TLD
2006
-										(?:'. $modSettings['tld_regex'] .'|local)
2006
+										(?:'. $modSettings['tld_regex'] . '|local)
2007 2007
 									)
2008 2008
 									# followed by a non-domain character or end of line
2009 2009
 									(?=[^\p{L}\p{N}\-.]|$)
@@ -2071,7 +2071,7 @@  discard block
 block discarded – undo
2071 2071
 						)?
2072 2072
 						';
2073 2073
 
2074
-						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) {
2074
+						$data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) {
2075 2075
 							$url = array_shift($matches);
2076 2076
 
2077 2077
 							// If this isn't a clean URL, bail out
@@ -2096,7 +2096,7 @@  discard block
 block discarded – undo
2096 2096
 								$fullUrl = $url;
2097 2097
 
2098 2098
 							// Make sure that $fullUrl really is valid
2099
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2099
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '') . $fullUrl) === false)
2100 2100
 								return $url;
2101 2101
 
2102 2102
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
@@ -2160,7 +2160,7 @@  discard block
 block discarded – undo
2160 2160
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2161 2161
 
2162 2162
 			// A closing tag that doesn't match any open tags? Skip it.
2163
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2163
+			if (!in_array($look_for, array_map(function($code) {return $code['tag']; }, $open_tags)))
2164 2164
 				continue;
2165 2165
 
2166 2166
 			$to_close = array();
@@ -2825,7 +2825,7 @@  discard block
 block discarded – undo
2825 2825
 		for ($i = 0, $n = count($smileysfrom); $i < $n; $i++)
2826 2826
 		{
2827 2827
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
2828
-			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2828
+			$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => '&#58;', '(' => '&#40;', ')' => '&#41;', '$' => '&#36;', '[' => '&#091;')) . '" class="smiley">';
2829 2829
 
2830 2830
 			$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
2831 2831
 
@@ -2842,7 +2842,7 @@  discard block
 block discarded – undo
2842 2842
 
2843 2843
 	// Replace away!
2844 2844
 	$message = preg_replace_callback($smileyPregSearch,
2845
-		function ($matches) use ($smileyPregReplacements)
2845
+		function($matches) use ($smileyPregReplacements)
2846 2846
 		{
2847 2847
 			return $smileyPregReplacements[$matches[1]];
2848 2848
 		}, $message);
@@ -2939,13 +2939,13 @@  discard block
 block discarded – undo
2939 2939
 	{
2940 2940
 		if (defined('SID') && SID != '')
2941 2941
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2942
-				function ($m) use ($scripturl)
2942
+				function($m) use ($scripturl)
2943 2943
 				{
2944
-					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2944
+					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : "");
2945 2945
 				}, $setLocation);
2946 2946
 		else
2947 2947
 			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2948
-				function ($m) use ($scripturl)
2948
+				function($m) use ($scripturl)
2949 2949
 				{
2950 2950
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2951 2951
 				}, $setLocation);
@@ -3266,7 +3266,7 @@  discard block
 block discarded – undo
3266 3266
 
3267 3267
 	// Add a generic "Are you sure?" confirmation message.
3268 3268
 	addInlineJavaScript('
3269
-	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3269
+	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';');
3270 3270
 
3271 3271
 	// Now add the capping code for avatars.
3272 3272
 	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
@@ -3732,7 +3732,7 @@  discard block
 block discarded – undo
3732 3732
 	if (!empty($normal))
3733 3733
 		foreach ($normal as $nf)
3734 3734
 			echo '
3735
-	<link rel="stylesheet" href="', $nf ,'">';
3735
+	<link rel="stylesheet" href="', $nf, '">';
3736 3736
 
3737 3737
 	if ($db_show_debug === true)
3738 3738
 	{
@@ -3748,7 +3748,7 @@  discard block
 block discarded – undo
3748 3748
 	<style>';
3749 3749
 
3750 3750
 		foreach ($context['css_header'] as $css)
3751
-			echo $css .'
3751
+			echo $css . '
3752 3752
 	';
3753 3753
 
3754 3754
 		echo'
@@ -3792,7 +3792,7 @@  discard block
 block discarded – undo
3792 3792
 
3793 3793
 
3794 3794
 	// No namespaces, sorry!
3795
-	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
3795
+	$classType = 'MatthiasMullie\\Minify\\' . strtoupper($type);
3796 3796
 
3797 3797
 	// Temp path.
3798 3798
 	$cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/';
@@ -3972,7 +3972,7 @@  discard block
 block discarded – undo
3972 3972
 	else
3973 3973
 		$path = $modSettings['attachmentUploadDir'];
3974 3974
 
3975
-	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3975
+	return $path . '/' . $attachment_id . '_' . $file_hash . '.dat';
3976 3976
 }
3977 3977
 
3978 3978
 /**
@@ -4016,10 +4016,10 @@  discard block
 block discarded – undo
4016 4016
 		$valid_low = isValidIP($ip_parts[0]);
4017 4017
 		$valid_high = isValidIP($ip_parts[1]);
4018 4018
 		$count = 0;
4019
-		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
4019
+		$mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.');
4020 4020
 		$max = ($mode == ':' ? 'ffff' : '255');
4021 4021
 		$min = 0;
4022
-		if(!$valid_low)
4022
+		if (!$valid_low)
4023 4023
 		{
4024 4024
 			$ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]);
4025 4025
 			$valid_low = isValidIP($ip_parts[0]);
@@ -4033,7 +4033,7 @@  discard block
 block discarded – undo
4033 4033
 		}
4034 4034
 
4035 4035
 		$count = 0;
4036
-		if(!$valid_high)
4036
+		if (!$valid_high)
4037 4037
 		{
4038 4038
 			$ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]);
4039 4039
 			$valid_high = isValidIP($ip_parts[1]);
@@ -4046,7 +4046,7 @@  discard block
 block discarded – undo
4046 4046
 			}
4047 4047
 		}
4048 4048
 
4049
-		if($valid_high && $valid_low)
4049
+		if ($valid_high && $valid_low)
4050 4050
 		{
4051 4051
 			$ip_array['low'] = $ip_parts[0];
4052 4052
 			$ip_array['high'] = $ip_parts[1];
@@ -4227,7 +4227,7 @@  discard block
 block discarded – undo
4227 4227
 		addInlineJavaScript('
4228 4228
 	var user_menus = new smc_PopupMenu();
4229 4229
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4230
-	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4230
+	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true);
4231 4231
 		if ($context['allow_pm'])
4232 4232
 			addInlineJavaScript('
4233 4233
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
@@ -4863,7 +4863,7 @@  discard block
 block discarded – undo
4863 4863
 		// No? try a fallback to $sourcedir
4864 4864
 		else
4865 4865
 		{
4866
-			$absPath = $sourcedir .'/'. $file;
4866
+			$absPath = $sourcedir . '/' . $file;
4867 4867
 
4868 4868
 			if (file_exists($absPath))
4869 4869
 				require_once($absPath);
@@ -5130,15 +5130,15 @@  discard block
 block discarded – undo
5130 5130
 
5131 5131
 	// UTF-8 occurences of MS special characters
5132 5132
 	$findchars_utf8 = array(
5133
-		"\xe2\x80\x9a",	// single low-9 quotation mark
5134
-		"\xe2\x80\x9e",	// double low-9 quotation mark
5135
-		"\xe2\x80\xa6",	// horizontal ellipsis
5136
-		"\xe2\x80\x98",	// left single curly quote
5137
-		"\xe2\x80\x99",	// right single curly quote
5138
-		"\xe2\x80\x9c",	// left double curly quote
5139
-		"\xe2\x80\x9d",	// right double curly quote
5140
-		"\xe2\x80\x93",	// en dash
5141
-		"\xe2\x80\x94",	// em dash
5133
+		"\xe2\x80\x9a", // single low-9 quotation mark
5134
+		"\xe2\x80\x9e", // double low-9 quotation mark
5135
+		"\xe2\x80\xa6", // horizontal ellipsis
5136
+		"\xe2\x80\x98", // left single curly quote
5137
+		"\xe2\x80\x99", // right single curly quote
5138
+		"\xe2\x80\x9c", // left double curly quote
5139
+		"\xe2\x80\x9d", // right double curly quote
5140
+		"\xe2\x80\x93", // en dash
5141
+		"\xe2\x80\x94", // em dash
5142 5142
 	);
5143 5143
 
5144 5144
 	// windows 1252 / iso equivalents
@@ -5156,15 +5156,15 @@  discard block
 block discarded – undo
5156 5156
 
5157 5157
 	// safe replacements
5158 5158
 	$replacechars = array(
5159
-		',',	// &sbquo;
5160
-		',,',	// &bdquo;
5161
-		'...',	// &hellip;
5162
-		"'",	// &lsquo;
5163
-		"'",	// &rsquo;
5164
-		'"',	// &ldquo;
5165
-		'"',	// &rdquo;
5166
-		'-',	// &ndash;
5167
-		'--',	// &mdash;
5159
+		',', // &sbquo;
5160
+		',,', // &bdquo;
5161
+		'...', // &hellip;
5162
+		"'", // &lsquo;
5163
+		"'", // &rsquo;
5164
+		'"', // &ldquo;
5165
+		'"', // &rdquo;
5166
+		'-', // &ndash;
5167
+		'--', // &mdash;
5168 5168
 	);
5169 5169
 
5170 5170
 	if ($context['utf8'])
@@ -5484,7 +5484,7 @@  discard block
 block discarded – undo
5484 5484
  */
5485 5485
 function inet_dtop($bin)
5486 5486
 {
5487
-	if(empty($bin))
5487
+	if (empty($bin))
5488 5488
 		return '';
5489 5489
 
5490 5490
 	global $db_type;
@@ -5515,28 +5515,28 @@  discard block
 block discarded – undo
5515 5515
  */
5516 5516
 function _safe_serialize($value)
5517 5517
 {
5518
-	if(is_null($value))
5518
+	if (is_null($value))
5519 5519
 		return 'N;';
5520 5520
 
5521
-	if(is_bool($value))
5522
-		return 'b:'. (int) $value .';';
5521
+	if (is_bool($value))
5522
+		return 'b:' . (int) $value . ';';
5523 5523
 
5524
-	if(is_int($value))
5525
-		return 'i:'. $value .';';
5524
+	if (is_int($value))
5525
+		return 'i:' . $value . ';';
5526 5526
 
5527
-	if(is_float($value))
5528
-		return 'd:'. str_replace(',', '.', $value) .';';
5527
+	if (is_float($value))
5528
+		return 'd:' . str_replace(',', '.', $value) . ';';
5529 5529
 
5530
-	if(is_string($value))
5531
-		return 's:'. strlen($value) .':"'. $value .'";';
5530
+	if (is_string($value))
5531
+		return 's:' . strlen($value) . ':"' . $value . '";';
5532 5532
 
5533
-	if(is_array($value))
5533
+	if (is_array($value))
5534 5534
 	{
5535 5535
 		$out = '';
5536
-		foreach($value as $k => $v)
5536
+		foreach ($value as $k => $v)
5537 5537
 			$out .= _safe_serialize($k) . _safe_serialize($v);
5538 5538
 
5539
-		return 'a:'. count($value) .':{'. $out .'}';
5539
+		return 'a:' . count($value) . ':{' . $out . '}';
5540 5540
 	}
5541 5541
 
5542 5542
 	// safe_serialize cannot serialize resources or objects.
@@ -5578,7 +5578,7 @@  discard block
 block discarded – undo
5578 5578
 function _safe_unserialize($str)
5579 5579
 {
5580 5580
 	// Input  is not a string.
5581
-	if(empty($str) || !is_string($str))
5581
+	if (empty($str) || !is_string($str))
5582 5582
 		return false;
5583 5583
 
5584 5584
 	$stack = array();
@@ -5592,40 +5592,40 @@  discard block
 block discarded – undo
5592 5592
 	 *   3 - in array, expecting value or another array
5593 5593
 	 */
5594 5594
 	$state = 0;
5595
-	while($state != 1)
5595
+	while ($state != 1)
5596 5596
 	{
5597 5597
 		$type = isset($str[0]) ? $str[0] : '';
5598
-		if($type == '}')
5598
+		if ($type == '}')
5599 5599
 			$str = substr($str, 1);
5600 5600
 
5601
-		else if($type == 'N' && $str[1] == ';')
5601
+		else if ($type == 'N' && $str[1] == ';')
5602 5602
 		{
5603 5603
 			$value = null;
5604 5604
 			$str = substr($str, 2);
5605 5605
 		}
5606
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5606
+		else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5607 5607
 		{
5608 5608
 			$value = $matches[1] == '1' ? true : false;
5609 5609
 			$str = substr($str, 4);
5610 5610
 		}
5611
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5611
+		else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5612 5612
 		{
5613
-			$value = (int)$matches[1];
5613
+			$value = (int) $matches[1];
5614 5614
 			$str = $matches[2];
5615 5615
 		}
5616
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5616
+		else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5617 5617
 		{
5618
-			$value = (float)$matches[1];
5618
+			$value = (float) $matches[1];
5619 5619
 			$str = $matches[3];
5620 5620
 		}
5621
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5621
+		else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";')
5622 5622
 		{
5623
-			$value = substr($matches[2], 0, (int)$matches[1]);
5624
-			$str = substr($matches[2], (int)$matches[1] + 2);
5623
+			$value = substr($matches[2], 0, (int) $matches[1]);
5624
+			$str = substr($matches[2], (int) $matches[1] + 2);
5625 5625
 		}
5626
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5626
+		else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5627 5627
 		{
5628
-			$expectedLength = (int)$matches[1];
5628
+			$expectedLength = (int) $matches[1];
5629 5629
 			$str = $matches[2];
5630 5630
 		}
5631 5631
 
@@ -5633,10 +5633,10 @@  discard block
 block discarded – undo
5633 5633
 		else
5634 5634
 			return false;
5635 5635
 
5636
-		switch($state)
5636
+		switch ($state)
5637 5637
 		{
5638 5638
 			case 3: // In array, expecting value or another array.
5639
-				if($type == 'a')
5639
+				if ($type == 'a')
5640 5640
 				{
5641 5641
 					$stack[] = &$list;
5642 5642
 					$list[$key] = array();
@@ -5645,7 +5645,7 @@  discard block
 block discarded – undo
5645 5645
 					$state = 2;
5646 5646
 					break;
5647 5647
 				}
5648
-				if($type != '}')
5648
+				if ($type != '}')
5649 5649
 				{
5650 5650
 					$list[$key] = $value;
5651 5651
 					$state = 2;
@@ -5656,29 +5656,29 @@  discard block
 block discarded – undo
5656 5656
 				return false;
5657 5657
 
5658 5658
 			case 2: // in array, expecting end of array or a key
5659
-				if($type == '}')
5659
+				if ($type == '}')
5660 5660
 				{
5661 5661
 					// Array size is less than expected.
5662
-					if(count($list) < end($expected))
5662
+					if (count($list) < end($expected))
5663 5663
 						return false;
5664 5664
 
5665 5665
 					unset($list);
5666
-					$list = &$stack[count($stack)-1];
5666
+					$list = &$stack[count($stack) - 1];
5667 5667
 					array_pop($stack);
5668 5668
 
5669 5669
 					// Go to terminal state if we're at the end of the root array.
5670 5670
 					array_pop($expected);
5671 5671
 
5672
-					if(count($expected) == 0)
5672
+					if (count($expected) == 0)
5673 5673
 						$state = 1;
5674 5674
 
5675 5675
 					break;
5676 5676
 				}
5677 5677
 
5678
-				if($type == 'i' || $type == 's')
5678
+				if ($type == 'i' || $type == 's')
5679 5679
 				{
5680 5680
 					// Array size exceeds expected length.
5681
-					if(count($list) >= end($expected))
5681
+					if (count($list) >= end($expected))
5682 5682
 						return false;
5683 5683
 
5684 5684
 					$key = $value;
@@ -5691,7 +5691,7 @@  discard block
 block discarded – undo
5691 5691
 
5692 5692
 			// Expecting array or value.
5693 5693
 			case 0:
5694
-				if($type == 'a')
5694
+				if ($type == 'a')
5695 5695
 				{
5696 5696
 					$data = array();
5697 5697
 					$list = &$data;
@@ -5700,7 +5700,7 @@  discard block
 block discarded – undo
5700 5700
 					break;
5701 5701
 				}
5702 5702
 
5703
-				if($type != '}')
5703
+				if ($type != '}')
5704 5704
 				{
5705 5705
 					$data = $value;
5706 5706
 					$state = 1;
@@ -5713,7 +5713,7 @@  discard block
 block discarded – undo
5713 5713
 	}
5714 5714
 
5715 5715
 	// Trailing data in input.
5716
-	if(!empty($str))
5716
+	if (!empty($str))
5717 5717
 		return false;
5718 5718
 
5719 5719
 	return $data;
@@ -5767,7 +5767,7 @@  discard block
 block discarded – undo
5767 5767
 	// Set different modes.
5768 5768
 	$chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666);
5769 5769
 
5770
-	foreach($chmodValues as $val)
5770
+	foreach ($chmodValues as $val)
5771 5771
 	{
5772 5772
 		// If it's writable, break out of the loop.
5773 5773
 		if (is_writable($file))
@@ -5802,13 +5802,13 @@  discard block
 block discarded – undo
5802 5802
 	$returnArray = @json_decode($json, $returnAsArray);
5803 5803
 
5804 5804
 	// PHP 5.3 so no json_last_error_msg()
5805
-	switch(json_last_error())
5805
+	switch (json_last_error())
5806 5806
 	{
5807 5807
 		case JSON_ERROR_NONE:
5808 5808
 			$jsonError = false;
5809 5809
 			break;
5810 5810
 		case JSON_ERROR_DEPTH:
5811
-			$jsonError =  'JSON_ERROR_DEPTH';
5811
+			$jsonError = 'JSON_ERROR_DEPTH';
5812 5812
 			break;
5813 5813
 		case JSON_ERROR_STATE_MISMATCH:
5814 5814
 			$jsonError = 'JSON_ERROR_STATE_MISMATCH';
@@ -5836,10 +5836,10 @@  discard block
 block discarded – undo
5836 5836
 		loadLanguage('Errors');
5837 5837
 
5838 5838
 		if (!empty($jsonDebug))
5839
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5839
+			log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5840 5840
 
5841 5841
 		else
5842
-			log_error($txt['json_'. $jsonError], 'critical');
5842
+			log_error($txt['json_' . $jsonError], 'critical');
5843 5843
 
5844 5844
 		// Everyone expects an array.
5845 5845
 		return array();
@@ -5956,7 +5956,7 @@  discard block
 block discarded – undo
5956 5956
 		// Convert Punycode to Unicode
5957 5957
 		require_once($sourcedir . '/Class-Punycode.php');
5958 5958
 		$Punycode = new Punycode();
5959
-		$tlds = array_map(function ($input) use ($Punycode) { return $Punycode->decode($input); }, $tlds);
5959
+		$tlds = array_map(function($input) use ($Punycode) { return $Punycode->decode($input); }, $tlds);
5960 5960
 	}
5961 5961
 	// Otherwise, use the 2012 list of gTLDs and ccTLDs for now and schedule a background update
5962 5962
 	else
@@ -6050,7 +6050,7 @@  discard block
 block discarded – undo
6050 6050
 	}
6051 6051
 
6052 6052
 	// This recursive function creates the index array from the strings
6053
-	$add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
6053
+	$add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index)
6054 6054
 	{
6055 6055
 		static $depth = 0;
6056 6056
 		$depth++;
@@ -6077,7 +6077,7 @@  discard block
 block discarded – undo
6077 6077
 	};
6078 6078
 
6079 6079
 	// This recursive function turns the index array into a regular expression
6080
-	$index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex)
6080
+	$index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex)
6081 6081
 	{
6082 6082
 		static $depth = 0;
6083 6083
 		$depth++;
@@ -6101,11 +6101,11 @@  discard block
 block discarded – undo
6101 6101
 
6102 6102
 				if (count(array_keys($value)) == 1)
6103 6103
 				{
6104
-					$new_key_array = explode('(?'.'>', $sub_regex);
6104
+					$new_key_array = explode('(?' . '>', $sub_regex);
6105 6105
 					$new_key .= $new_key_array[0];
6106 6106
 				}
6107 6107
 				else
6108
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6108
+					$sub_regex = '(?' . '>' . $sub_regex . ')';
6109 6109
 			}
6110 6110
 
6111 6111
 			if ($depth > 1)
@@ -6148,10 +6148,10 @@  discard block
 block discarded – undo
6148 6148
 	{
6149 6149
 		$regex = array();
6150 6150
 		while (!empty($index))
6151
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6151
+			$regex[] = '(?' . '>' . $index_to_regex($index, $delim) . ')';
6152 6152
 	}
6153 6153
 	else
6154
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6154
+		$regex = '(?' . '>' . $index_to_regex($index, $delim) . ')';
6155 6155
 
6156 6156
 	// Restore PHP's internal character encoding to whatever it was originally
6157 6157
 	if (!empty($current_encoding))
@@ -6375,7 +6375,7 @@  discard block
 block discarded – undo
6375 6375
 function sanitize_iri($iri)
6376 6376
 {
6377 6377
 	// Encode any non-ASCII characters (but not space or control characters of any sort)
6378
-	$iri = preg_replace_callback('~[^\x00-\x7F\pZ\pC]~u', function ($matches) {
6378
+	$iri = preg_replace_callback('~[^\x00-\x7F\pZ\pC]~u', function($matches) {
6379 6379
 		return rawurlencode($matches[0]);
6380 6380
 	}, $iri);
6381 6381
 
@@ -6417,7 +6417,7 @@  discard block
 block discarded – undo
6417 6417
 	$unescaped = array(
6418 6418
 		'%21'=>'!', '%23'=>'#', '%24'=>'$', '%26'=>'&',
6419 6419
 		'%27'=>"'", '%28'=>'(', '%29'=>')', '%2A'=>'*',
6420
-		'%2B'=>'+', '%2C'=>',',	'%2F'=>'/', '%3A'=>':',
6420
+		'%2B'=>'+', '%2C'=>',', '%2F'=>'/', '%3A'=>':',
6421 6421
 		'%3B'=>';', '%3D'=>'=', '%3F'=>'?', '%40'=>'@',
6422 6422
 	);
6423 6423
 	$iri = strtr(rawurlencode($iri), $unescaped);
Please login to merge, or discard this patch.
Themes/default/ModerationCenter.template.php 1 patch
Braces   +59 added lines, -41 removed lines patch added patch discarded remove patch
@@ -54,18 +54,20 @@  discard block
 block discarded – undo
54 54
 		<div class="windowbg2 noup" id="group_requests_panel">
55 55
 			<ul>';
56 56
 
57
-	foreach ($context['group_requests'] as $request)
58
-		echo '
57
+	foreach ($context['group_requests'] as $request) {
58
+			echo '
59 59
 				<li class="smalltext">
60 60
 					<a href="', $request['request_href'], '">', $request['group']['name'], '</a> ', $txt['mc_groupr_by'], ' ', $request['member']['link'], '
61 61
 				</li>';
62
+	}
62 63
 
63 64
 	// Don't have any watched users right now?
64
-	if (empty($context['group_requests']))
65
-		echo '
65
+	if (empty($context['group_requests'])) {
66
+			echo '
66 67
 				<li>
67 68
 					<strong class="smalltext">', $txt['mc_group_requests_none'], '</strong>
68 69
 				</li>';
70
+	}
69 71
 
70 72
 	echo '
71 73
 			</ul>
@@ -121,18 +123,20 @@  discard block
 block discarded – undo
121 123
 		<div class="windowbg2 noup" id="watched_users_panel">
122 124
 			<ul>';
123 125
 
124
-	foreach ($context['watched_users'] as $user)
125
-		echo '
126
+	foreach ($context['watched_users'] as $user) {
127
+			echo '
126 128
 				<li>
127 129
 					<span class="smalltext">', sprintf(!empty($user['last_login']) ? $txt['mc_seen'] : $txt['mc_seen_never'], $user['link'], $user['last_login']), '</span>
128 130
 				</li>';
131
+	}
129 132
 
130 133
 	// Don't have any watched users right now?
131
-	if (empty($context['watched_users']))
132
-		echo '
134
+	if (empty($context['watched_users'])) {
135
+			echo '
133 136
 				<li>
134 137
 					<strong class="smalltext">', $txt['mc_watched_users_none'], '</strong>
135 138
 				</li>';
139
+	}
136 140
 
137 141
 	echo '
138 142
 			</ul>
@@ -188,18 +192,20 @@  discard block
 block discarded – undo
188 192
 		<div class="windowbg2 noup" id="reported_posts_panel">
189 193
 			<ul>';
190 194
 
191
-	foreach ($context['reported_posts'] as $post)
192
-		echo '
195
+	foreach ($context['reported_posts'] as $post) {
196
+			echo '
193 197
 				<li>
194 198
 					<span class="smalltext">', sprintf($txt['mc_post_report'], $post['report_link'], $post['author']['link']), '</span>
195 199
 				</li>';
200
+	}
196 201
 
197 202
 	// Don't have any watched users right now?
198
-	if (empty($context['reported_posts']))
199
-		echo '
203
+	if (empty($context['reported_posts'])) {
204
+			echo '
200 205
 				<li>
201 206
 					<strong class="smalltext">', $txt['mc_recent_reports_none'], '</strong>
202 207
 				</li>';
208
+	}
203 209
 
204 210
 	echo '
205 211
 			</ul>
@@ -255,18 +261,20 @@  discard block
 block discarded – undo
255 261
 		<div class="windowbg2 noup" id="reported_users_panel">
256 262
 			<ul>';
257 263
 
258
-	foreach ($context['reported_users'] as $user)
259
-		echo '
264
+	foreach ($context['reported_users'] as $user) {
265
+			echo '
260 266
 				<li>
261 267
 					<span class="smalltext">', $user['user']['link'], '</span>
262 268
 				</li>';
269
+	}
263 270
 
264 271
 	// Don't have any watched users right now?
265
-	if (empty($context['reported_users']))
266
-		echo '
272
+	if (empty($context['reported_users'])) {
273
+			echo '
267 274
 				<li>
268 275
 					<strong class="smalltext">', $txt['mc_reported_users_none'], '</strong>
269 276
 				</li>';
277
+	}
270 278
 
271 279
 	echo '
272 280
 			</ul>
@@ -313,11 +321,12 @@  discard block
 block discarded – undo
313 321
 	global $context, $txt, $scripturl;
314 322
 
315 323
 	// Let them know the action was a success.
316
-	if (!empty($context['report_post_action']))
317
-		echo '
324
+	if (!empty($context['report_post_action'])) {
325
+			echo '
318 326
 		<div class="infobox">
319 327
 			', $txt['report_action_' . $context['report_post_action']], '
320 328
 		</div>';
329
+	}
321 330
 
322 331
 	echo '
323 332
 		<div id="modnotes">
@@ -333,11 +342,12 @@  discard block
 block discarded – undo
333 342
 					<ul class="moderation_notes">';
334 343
 
335 344
 		// Cycle through the notes.
336
-		foreach ($context['notes'] as $note)
337
-			echo '
345
+		foreach ($context['notes'] as $note) {
346
+					echo '
338 347
 						<li class="smalltext">
339 348
 							', ($note['can_delete'] ? '<a href="' . $note['delete_href'] . ';' . $context['mod-modnote-del_token_var'] . '=' . $context['mod-modnote-del_token'] . '" data-confirm="' . $txt['mc_reportedp_delete_confirm'] . '" class="you_sure"><span class="generic_icons delete"></span></a>' : ''), $note['time'], ' <strong>', $note['author']['link'], ':</strong> ', $note['text'], '
340 349
 						</li>';
350
+		}
341 351
 
342 352
 		echo '
343 353
 					</ul>
@@ -378,18 +388,19 @@  discard block
 block discarded – undo
378 388
 	$remove_button = create_button('delete', 'remove_message', 'remove');
379 389
 
380 390
 	// No posts?
381
-	if (empty($context['unapproved_items']))
382
-		echo '
391
+	if (empty($context['unapproved_items'])) {
392
+			echo '
383 393
 			<div class="windowbg2">
384 394
 				<p class="centertext">
385 395
 					', $txt['mc_unapproved_' . $context['current_view'] . '_none_found'], '
386 396
 				</p>
387 397
 			</div>';
388
-	else
389
-		echo '
398
+	} else {
399
+			echo '
390 400
 			<div class="pagesection floatleft">
391 401
 				', $context['page_index'], '
392 402
 			</div>';
403
+	}
393 404
 
394 405
 	foreach ($context['unapproved_items'] as $item)
395 406
 	{
@@ -408,14 +419,16 @@  discard block
 block discarded – undo
408 419
 				<span class="floatright">
409 420
 					<a href="', $scripturl, '?action=moderate;area=postmod;sa=', $context['current_view'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';approve=', $item['id'], '">', $approve_button, '</a>';
410 421
 
411
-		if ($item['can_delete'])
412
-			echo '
422
+		if ($item['can_delete']) {
423
+					echo '
413 424
 					', $context['menu_separator'], '
414 425
 					<a href="', $scripturl, '?action=moderate;area=postmod;sa=', $context['current_view'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';delete=', $item['id'], '">', $remove_button, '</a>';
426
+		}
415 427
 
416
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
417
-			echo '
428
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1) {
429
+					echo '
418 430
 					<input type="checkbox" name="item[]" value="', $item['id'], '" checked> ';
431
+		}
419 432
 
420 433
 		echo '
421 434
 				</span>
@@ -425,8 +438,8 @@  discard block
 block discarded – undo
425 438
 	echo '
426 439
 			<div class="pagesection">';
427 440
 
428
-	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
429
-		echo '
441
+	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1) {
442
+			echo '
430 443
 				<div class="floatright">
431 444
 					<select name="do" onchange="if (this.value != 0 &amp;&amp; confirm(\'', $txt['mc_unapproved_sure'], '\')) submit();">
432 445
 						<option value="0">', $txt['with_selected'], ':</option>
@@ -438,12 +451,14 @@  discard block
 block discarded – undo
438 451
 						<input type="submit" name="mc_go" value="', $txt['go'], '" class="button">
439 452
 					</noscript>
440 453
 				</div>';
454
+	}
441 455
 
442
-	if (!empty($context['unapproved_items']))
443
-		echo '
456
+	if (!empty($context['unapproved_items'])) {
457
+			echo '
444 458
 				<div class="floatleft">
445 459
 					<div class="pagelinks">', $context['page_index'], '</div>
446 460
 				</div>';
461
+	}
447 462
 
448 463
 	echo '
449 464
 			</div><!-- .pagesection -->
@@ -464,8 +479,9 @@  discard block
 block discarded – undo
464 479
 
465 480
 	// We'll have a delete please bob.
466 481
 	// @todo Discuss this with the team and rewrite if required.
467
-	if (empty($delete_button))
468
-		$delete_button = create_button('delete', 'remove_message', 'remove', 'class="centericon"');
482
+	if (empty($delete_button)) {
483
+			$delete_button = create_button('delete', 'remove_message', 'remove', 'class="centericon"');
484
+	}
469 485
 
470 486
 	$output_html = '
471 487
 					<div>
@@ -474,10 +490,11 @@  discard block
 block discarded – undo
474 490
 						</div>
475 491
 						<div class="floatright">';
476 492
 
477
-	if ($post['can_delete'])
478
-		$output_html .= '
493
+	if ($post['can_delete']) {
494
+			$output_html .= '
479 495
 							<a href="' . $scripturl . '?action=moderate;area=userwatch;sa=post;delete=' . $post['id'] . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" data-confirm="' . $txt['mc_watched_users_delete_post'] . '" class="you_sure">' . $delete_button . '</a>
480 496
 							<input type="checkbox" name="delete[]" value="' . $post['id'] . '">';
497
+	}
481 498
 
482 499
 	$output_html .= '
483 500
 						</div>
@@ -521,12 +538,12 @@  discard block
 block discarded – undo
521 538
 				<input type="submit" name="save" value="', $txt['save'], '" class="button">
522 539
 			</div>
523 540
 		</form>';
524
-	}
525
-	else
526
-		echo '
541
+	} else {
542
+			echo '
527 543
 		<div class="windowbg">
528 544
 			<div class="centertext">', $txt['mc_no_settings'], '</div>
529 545
 		</div>';
546
+	}
530 547
 
531 548
 	echo '
532 549
 	</div><!-- #modcenter -->';
@@ -622,13 +639,14 @@  discard block
 block discarded – undo
622 639
 					</dd>
623 640
 				</dl>';
624 641
 
625
-	if ($context['template_data']['can_edit_personal'])
626
-		echo '
642
+	if ($context['template_data']['can_edit_personal']) {
643
+			echo '
627 644
 				<input type="checkbox" name="make_personal" id="make_personal"', $context['template_data']['personal'] ? ' checked' : '', '>
628 645
 					<label for="make_personal">
629 646
 						<strong>', $txt['mc_warning_template_personal'], '</strong>
630 647
 					</label>
631 648
 					<p class="smalltext">', $txt['mc_warning_template_personal_desc'], '</p>';
649
+	}
632 650
 
633 651
 	echo '
634 652
 				<input type="submit" name="preview" id="preview_button" value="', $txt['preview'], '" class="button">
Please login to merge, or discard this patch.
Sources/SearchAPI-Fulltext.php 2 patches
Braces   +47 added lines, -36 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * Class fulltext_search
@@ -98,8 +99,9 @@  discard block
 block discarded – undo
98 99
 			$smcFunc['db_free_result']($request);
99 100
 		}
100 101
 		// 4 is the MySQL default...
101
-		else
102
-			$min_word_length = 4;
102
+		else {
103
+					$min_word_length = 4;
104
+		}
103 105
 
104 106
 		return $min_word_length;
105 107
 	}
@@ -138,8 +140,7 @@  discard block
 block discarded – undo
138 140
 					$wordsSearch['words'][] = trim($word, "/*- ");
139 141
 					$wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"';
140 142
 				}
141
-			}
142
-			elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length)
143
+			} elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length)
143 144
 			{
144 145
 				// short words have feelings too
145 146
 				$wordsSearch['words'][] = trim($word, "/*- ");
@@ -149,8 +150,9 @@  discard block
 block discarded – undo
149 150
 
150 151
 		$fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"';
151 152
 		$wordsSearch['indexed_words'][] = $fulltextWord;
152
-		if ($isExcluded)
153
-			$wordsExclude[] = $fulltextWord;
153
+		if ($isExcluded) {
154
+					$wordsExclude[] = $fulltextWord;
155
+		}
154 156
 	}
155 157
 
156 158
 	/**
@@ -166,44 +168,54 @@  discard block
 block discarded – undo
166 168
 		$query_where = array();
167 169
 		$query_params = $search_data['params'];
168 170
 
169
-		if( $smcFunc['db_title'] == "PostgreSQL")
170
-			$modSettings['search_simple_fulltext'] = true;
171
+		if( $smcFunc['db_title'] == "PostgreSQL") {
172
+					$modSettings['search_simple_fulltext'] = true;
173
+		}
171 174
 
172
-		if ($query_params['id_search'])
173
-			$query_select['id_search'] = '{int:id_search}';
175
+		if ($query_params['id_search']) {
176
+					$query_select['id_search'] = '{int:id_search}';
177
+		}
174 178
 
175 179
 		$count = 0;
176
-		if (empty($modSettings['search_simple_fulltext']))
177
-			foreach ($words['words'] as $regularWord)
180
+		if (empty($modSettings['search_simple_fulltext'])) {
181
+					foreach ($words['words'] as $regularWord)
178 182
 			{
179 183
 				$query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}';
184
+		}
180 185
 				$query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
181 186
 			}
182 187
 
183
-		if ($query_params['user_query'])
184
-			$query_where[] = '{raw:user_query}';
185
-		if ($query_params['board_query'])
186
-			$query_where[] = 'm.id_board {raw:board_query}';
188
+		if ($query_params['user_query']) {
189
+					$query_where[] = '{raw:user_query}';
190
+		}
191
+		if ($query_params['board_query']) {
192
+					$query_where[] = 'm.id_board {raw:board_query}';
193
+		}
187 194
 
188
-		if ($query_params['topic'])
189
-			$query_where[] = 'm.id_topic = {int:topic}';
190
-		if ($query_params['min_msg_id'])
191
-			$query_where[] = 'm.id_msg >= {int:min_msg_id}';
192
-		if ($query_params['max_msg_id'])
193
-			$query_where[] = 'm.id_msg <= {int:max_msg_id}';
195
+		if ($query_params['topic']) {
196
+					$query_where[] = 'm.id_topic = {int:topic}';
197
+		}
198
+		if ($query_params['min_msg_id']) {
199
+					$query_where[] = 'm.id_msg >= {int:min_msg_id}';
200
+		}
201
+		if ($query_params['max_msg_id']) {
202
+					$query_where[] = 'm.id_msg <= {int:max_msg_id}';
203
+		}
194 204
 
195 205
 		$count = 0;
196
-		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index']))
197
-			foreach ($query_params['excluded_phrases'] as $phrase)
206
+		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) {
207
+					foreach ($query_params['excluded_phrases'] as $phrase)
198 208
 			{
199 209
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}';
210
+		}
200 211
 				$query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]';
201 212
 			}
202 213
 		$count = 0;
203
-		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index']))
204
-			foreach ($query_params['excluded_subject_words'] as $excludedWord)
214
+		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) {
215
+					foreach ($query_params['excluded_subject_words'] as $excludedWord)
205 216
 			{
206 217
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}';
218
+		}
207 219
 				$query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]';
208 220
 			}
209 221
 
@@ -215,12 +227,11 @@  discard block
 block discarded – undo
215 227
 
216 228
 				$query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:body_match})';
217 229
 				$query_params['language_ftx'] = $language_ftx;
230
+			} else {
231
+							$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
218 232
 			}
219
-			else
220
-				$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
221 233
 			$query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words']));
222
-		}
223
-		else
234
+		} else
224 235
 		{
225 236
 			$query_params['boolean_match'] = '';
226 237
 
@@ -234,10 +245,10 @@  discard block
 block discarded – undo
234 245
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' ';
235 246
 					$row++;
236 247
 				}
237
-			}
238
-			else
239
-				foreach ($words['indexed_words'] as $fulltextWord)
248
+			} else {
249
+							foreach ($words['indexed_words'] as $fulltextWord)
240 250
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' ';
251
+			}
241 252
 
242 253
 			$query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1);
243 254
 
@@ -249,9 +260,9 @@  discard block
 block discarded – undo
249 260
 
250 261
 					$query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:boolean_match})';
251 262
 					$query_params['language_ftx'] = $language_ftx;
263
+				} else {
264
+									$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
252 265
 				}
253
-				else
254
-					$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
255 266
 			}
256 267
 
257 268
 		}
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 		$query_where = array();
167 167
 		$query_params = $search_data['params'];
168 168
 
169
-		if( $smcFunc['db_title'] == "PostgreSQL")
169
+		if ($smcFunc['db_title'] == "PostgreSQL")
170 170
 			$modSettings['search_simple_fulltext'] = true;
171 171
 
172 172
 		if ($query_params['id_search'])
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 			// if we have bool terms to search, add them in
247 247
 			if ($query_params['boolean_match'])
248 248
 			{
249
-				if($smcFunc['db_title'] == "PostgreSQL")
249
+				if ($smcFunc['db_title'] == "PostgreSQL")
250 250
 				{
251 251
 					$language_ftx = $smcFunc['db_search_language']();
252 252
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 			}
259 259
 		}
260 260
 
261
-		$ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( '
261
+		$ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ('
262 262
 			INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . '
263 263
 				(' . implode(', ', array_keys($query_select)) . ')') : '') . '
264 264
 			SELECT ' . implode(', ', $query_select) . '
Please login to merge, or discard this patch.
Sources/CacheAPI-postgres.php 2 patches
Braces   +28 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * PostgreSQL Cache API class
@@ -49,8 +50,9 @@  discard block
 block discarded – undo
49 50
 
50 51
 		$result = pg_execute($db_connection, '', array('public', $db_prefix . 'cache'));
51 52
 
52
-		if (pg_affected_rows($result) === 0)
53
-			pg_query($db_connection, 'CREATE UNLOGGED TABLE ' . $db_prefix . 'cache (key text, value text, ttl bigint, PRIMARY KEY (key))');			
53
+		if (pg_affected_rows($result) === 0) {
54
+					pg_query($db_connection, 'CREATE UNLOGGED TABLE ' . $db_prefix . 'cache (key text, value text, ttl bigint, PRIMARY KEY (key))');
55
+		}
54 56
 	}
55 57
 
56 58
 	/**
@@ -60,14 +62,16 @@  discard block
 block discarded – undo
60 62
 	{
61 63
 		global $smcFunc, $db_connection;
62 64
 
63
-		if ($smcFunc['db_title'] !== 'PostgreSQL')
64
-			return false;
65
+		if ($smcFunc['db_title'] !== 'PostgreSQL') {
66
+					return false;
67
+		}
65 68
 
66 69
 		$result = pg_query($db_connection, 'SHOW server_version_num');
67 70
 		$res = pg_fetch_assoc($result);
68 71
 		
69
-		if ($res['server_version_num'] < 90500)
70
-			return false;
72
+		if ($res['server_version_num'] < 90500) {
73
+					return false;
74
+		}
71 75
 		
72 76
 		return $test ? true : parent::isSupported();
73 77
 	}
@@ -81,13 +85,15 @@  discard block
 block discarded – undo
81 85
 
82 86
 		$ttl = time() - $ttl;
83 87
 		
84
-		if (empty($this->pg_get_data_prep))
85
-			$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
88
+		if (empty($this->pg_get_data_prep)) {
89
+					$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
90
+		}
86 91
 			
87 92
 		$result = pg_execute($db_connection, 'smf_cache_get_data', array($key, $ttl));
88 93
 		
89
-		if (pg_affected_rows($result) === 0)
90
-			return null;
94
+		if (pg_affected_rows($result) === 0) {
95
+					return null;
96
+		}
91 97
 
92 98
 		$res = pg_fetch_assoc($result);
93 99
 
@@ -101,23 +107,26 @@  discard block
 block discarded – undo
101 107
 	{
102 108
 		global  $db_prefix, $db_connection;
103 109
 
104
-		if (!isset($value))
105
-			$value = '';
110
+		if (!isset($value)) {
111
+					$value = '';
112
+		}
106 113
 
107 114
 		$ttl = time() + $ttl;
108 115
 
109
-		if (empty($this->pg_put_data_prep))
110
-			$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
116
+		if (empty($this->pg_put_data_prep)) {
117
+					$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
111 118
 				'INSERT INTO ' . $db_prefix . 'cache(key,value,ttl) VALUES($1,$2,$3)
112 119
 				ON CONFLICT(key) DO UPDATE SET value = excluded.value, ttl = excluded.ttl'
113 120
 			);
121
+		}
114 122
 
115 123
 		$result = pg_execute($db_connection, 'smf_cache_put_data', array($key, $value, $ttl));
116 124
 
117
-		if (pg_affected_rows($result) > 0)
118
-			return true;
119
-		else
120
-			return false;
125
+		if (pg_affected_rows($result) > 0) {
126
+					return true;
127
+		} else {
128
+					return false;
129
+		}
121 130
 	}
122 131
 
123 132
 	/**
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	{
166 166
 		global $db_connection, $db_prefix;
167 167
 		
168
-		pg_query($db_connection, 'CREATE LOCAL TEMP TABLE IF NOT EXISTS ' . $db_prefix . 'cache_tmp AS SELECT * FROM ' . $db_prefix . 'cache WHERE ttl >= ' . time() );
168
+		pg_query($db_connection, 'CREATE LOCAL TEMP TABLE IF NOT EXISTS ' . $db_prefix . 'cache_tmp AS SELECT * FROM ' . $db_prefix . 'cache WHERE ttl >= ' . time());
169 169
 	}
170 170
 	
171 171
 	/**
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	{
190 190
 		global $db_connection, $db_prefix;
191 191
 		
192
-		pg_query($db_connection, 'INSERT INTO ' . $db_prefix . 'cache SELECT * FROM '. $db_prefix . 'cache_tmp ON CONFLICT DO NOTHING');
192
+		pg_query($db_connection, 'INSERT INTO ' . $db_prefix . 'cache SELECT * FROM ' . $db_prefix . 'cache_tmp ON CONFLICT DO NOTHING');
193 193
 	}
194 194
 }
195 195
 
Please login to merge, or discard this patch.
Sources/Profile-Actions.php 1 patch
Braces   +117 added lines, -86 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Activate an account.
@@ -48,8 +49,9 @@  discard block
 block discarded – undo
48 49
 		logAction('approve_member', array('member' => $memID), 'admin');
49 50
 
50 51
 		// If we are doing approval, update the stats for the member just in case.
51
-		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15)))
52
-			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
52
+		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) {
53
+					updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
54
+		}
53 55
 
54 56
 		// Make sure we update the stats too.
55 57
 		updateStats('member', false);
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$issueErrors = array();
77 79
 
78 80
 	// Doesn't hurt to be overly cautious.
79
-	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning'))
80
-		fatal_lang_error('no_access', false);
81
+	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) {
82
+			fatal_lang_error('no_access', false);
83
+	}
81 84
 
82 85
 	// Get the base (errors related) stuff done.
83 86
 	loadLanguage('Errors');
@@ -135,16 +138,18 @@  discard block
 block discarded – undo
135 138
 
136 139
 		// This cannot be empty!
137 140
 		$_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : '';
138
-		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner'])
139
-			$issueErrors[] = 'warning_no_reason';
141
+		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) {
142
+					$issueErrors[] = 'warning_no_reason';
143
+		}
140 144
 		$_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']);
141 145
 
142 146
 		$_POST['warning_level'] = (int) $_POST['warning_level'];
143 147
 		$_POST['warning_level'] = max(0, min(100, $_POST['warning_level']));
144
-		if ($_POST['warning_level'] < $context['min_allowed'])
145
-			$_POST['warning_level'] = $context['min_allowed'];
146
-		elseif ($_POST['warning_level'] > $context['max_allowed'])
147
-			$_POST['warning_level'] = $context['max_allowed'];
148
+		if ($_POST['warning_level'] < $context['min_allowed']) {
149
+					$_POST['warning_level'] = $context['min_allowed'];
150
+		} elseif ($_POST['warning_level'] > $context['max_allowed']) {
151
+					$_POST['warning_level'] = $context['max_allowed'];
152
+		}
148 153
 
149 154
 		// Do we actually have to issue them with a PM?
150 155
 		$id_notice = 0;
@@ -152,8 +157,9 @@  discard block
 block discarded – undo
152 157
 		{
153 158
 			$_POST['warn_sub'] = trim($_POST['warn_sub']);
154 159
 			$_POST['warn_body'] = trim($_POST['warn_body']);
155
-			if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
156
-				$issueErrors[] = 'warning_notify_blank';
160
+			if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
161
+							$issueErrors[] = 'warning_notify_blank';
162
+			}
157 163
 			// Send the PM?
158 164
 			else
159 165
 			{
@@ -190,8 +196,8 @@  discard block
 block discarded – undo
190 196
 		if (empty($issueErrors))
191 197
 		{
192 198
 			// Log what we've done!
193
-			if (!$context['user']['is_owner'])
194
-				$smcFunc['db_insert']('',
199
+			if (!$context['user']['is_owner']) {
200
+							$smcFunc['db_insert']('',
195 201
 					'{db_prefix}log_comments',
196 202
 					array(
197 203
 						'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255',
@@ -203,14 +209,14 @@  discard block
 block discarded – undo
203 209
 					),
204 210
 					array('id_comment')
205 211
 				);
212
+			}
206 213
 
207 214
 			// Make the change.
208 215
 			updateMemberData($memID, array('warning' => $_POST['warning_level']));
209 216
 
210 217
 			// Leave a lovely message.
211 218
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success'];
212
-		}
213
-		else
219
+		} else
214 220
 		{
215 221
 			// Try to remember some bits.
216 222
 			$context['warning_data'] = array(
@@ -229,8 +235,9 @@  discard block
 block discarded – undo
229 235
 	{
230 236
 		$warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : '';
231 237
 		$context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : '';
232
-		if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
233
-			$issueErrors[] = 'warning_notify_blank';
238
+		if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
239
+					$issueErrors[] = 'warning_notify_blank';
240
+		}
234 241
 
235 242
 		if (!empty($_POST['warn_body']))
236 243
 		{
@@ -254,8 +261,9 @@  discard block
 block discarded – undo
254 261
 	{
255 262
 		// Fill in the suite of errors.
256 263
 		$context['post_errors'] = array();
257
-		foreach ($issueErrors as $error)
258
-			$context['post_errors'][] = $txt[$error];
264
+		foreach ($issueErrors as $error) {
265
+					$context['post_errors'][] = $txt[$error];
266
+		}
259 267
 	}
260 268
 
261 269
 
@@ -272,9 +280,10 @@  discard block
 block discarded – undo
272 280
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_mute'],
273 281
 	);
274 282
 	$context['current_level'] = 0;
275
-	foreach ($context['level_effects'] as $limit => $dummy)
276
-		if ($context['member']['warning'] >= $limit)
283
+	foreach ($context['level_effects'] as $limit => $dummy) {
284
+			if ($context['member']['warning'] >= $limit)
277 285
 			$context['current_level'] = $limit;
286
+	}
278 287
 
279 288
 	$listOptions = array(
280 289
 		'id' => 'view_warnings',
@@ -337,11 +346,12 @@  discard block
 block discarded – undo
337 346
 							' . $warning['reason'] . '
338 347
 						</div>';
339 348
 
340
-						if (!empty($warning['id_notice']))
341
-							$ret .= '
349
+						if (!empty($warning['id_notice'])) {
350
+													$ret .= '
342 351
 						<div class="floatright">
343 352
 							<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $warning['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" rel="noopener" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>
344 353
 						</div>';
354
+						}
345 355
 
346 356
 						return $ret;
347 357
 					},
@@ -413,8 +423,9 @@  discard block
 block discarded – undo
413 423
 	while ($row = $smcFunc['db_fetch_assoc']($request))
414 424
 	{
415 425
 		// If we're not warning for a message skip any that are.
416
-		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false)
417
-			continue;
426
+		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) {
427
+					continue;
428
+		}
418 429
 
419 430
 		$context['notification_templates'][] = array(
420 431
 			'title' => $row['template_title'],
@@ -424,16 +435,18 @@  discard block
 block discarded – undo
424 435
 	$smcFunc['db_free_result']($request);
425 436
 
426 437
 	// Setup the "default" templates.
427
-	foreach (array('spamming', 'offence', 'insulting') as $type)
428
-		$context['notification_templates'][] = array(
438
+	foreach (array('spamming', 'offence', 'insulting') as $type) {
439
+			$context['notification_templates'][] = array(
429 440
 			'title' => $txt['profile_warning_notify_title_' . $type],
430 441
 			'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]),
431 442
 		);
443
+	}
432 444
 
433 445
 	// Replace all the common variables in the templates.
434
-	foreach ($context['notification_templates'] as $k => $name)
435
-		$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
436
-}
446
+	foreach ($context['notification_templates'] as $k => $name) {
447
+			$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
448
+	}
449
+	}
437 450
 
438 451
 /**
439 452
  * Get the number of warnings a user has. Callback for $listOptions['get_count'] in issueWarning()
@@ -517,10 +530,11 @@  discard block
 block discarded – undo
517 530
 {
518 531
 	global $txt, $context, $modSettings, $cur_profile;
519 532
 
520
-	if (!$context['user']['is_owner'])
521
-		isAllowedTo('profile_remove_any');
522
-	elseif (!allowedTo('profile_remove_any'))
523
-		isAllowedTo('profile_remove_own');
533
+	if (!$context['user']['is_owner']) {
534
+			isAllowedTo('profile_remove_any');
535
+	} elseif (!allowedTo('profile_remove_any')) {
536
+			isAllowedTo('profile_remove_own');
537
+	}
524 538
 
525 539
 	// Permissions for removing stuff...
526 540
 	$context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum');
@@ -547,10 +561,11 @@  discard block
 block discarded – undo
547 561
 
548 562
 	// @todo Add a way to delete pms as well?
549 563
 
550
-	if (!$context['user']['is_owner'])
551
-		isAllowedTo('profile_remove_any');
552
-	elseif (!allowedTo('profile_remove_any'))
553
-		isAllowedTo('profile_remove_own');
564
+	if (!$context['user']['is_owner']) {
565
+			isAllowedTo('profile_remove_any');
566
+	} elseif (!allowedTo('profile_remove_any')) {
567
+			isAllowedTo('profile_remove_own');
568
+	}
554 569
 
555 570
 	checkSession();
556 571
 
@@ -576,8 +591,9 @@  discard block
 block discarded – undo
576 591
 		list ($another) = $smcFunc['db_fetch_row']($request);
577 592
 		$smcFunc['db_free_result']($request);
578 593
 
579
-		if (empty($another))
580
-			fatal_lang_error('at_least_one_admin', 'critical');
594
+		if (empty($another)) {
595
+					fatal_lang_error('at_least_one_admin', 'critical');
596
+		}
581 597
 	}
582 598
 
583 599
 	// This file is needed for the deleteMembers function.
@@ -656,8 +672,9 @@  discard block
 block discarded – undo
656 672
 					)
657 673
 				);
658 674
 				$topicIDs = array();
659
-				while ($row = $smcFunc['db_fetch_assoc']($request))
660
-					$topicIDs[] = $row['id_topic'];
675
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
676
+									$topicIDs[] = $row['id_topic'];
677
+				}
661 678
 				$smcFunc['db_free_result']($request);
662 679
 
663 680
 				// Actually remove the topics. Ignore recycling if we want to perma-delete things...
@@ -680,8 +697,9 @@  discard block
 block discarded – undo
680 697
 			// This could take a while... but ya know it's gonna be worth it in the end.
681 698
 			while ($row = $smcFunc['db_fetch_assoc']($request))
682 699
 			{
683
-				if (function_exists('apache_reset_timeout'))
684
-					@apache_reset_timeout();
700
+				if (function_exists('apache_reset_timeout')) {
701
+									@apache_reset_timeout();
702
+				}
685 703
 
686 704
 				removeMessage($row['id_msg']);
687 705
 			}
@@ -689,8 +707,9 @@  discard block
 block discarded – undo
689 707
 		}
690 708
 
691 709
 		// Only delete this poor members account if they are actually being booted out of camp.
692
-		if (isset($_POST['deleteAccount']))
693
-			deleteMembers($memID);
710
+		if (isset($_POST['deleteAccount'])) {
711
+					deleteMembers($memID);
712
+		}
694 713
 	}
695 714
 	// Do they need approval to delete?
696 715
 	elseif (!empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum'))
@@ -741,18 +760,18 @@  discard block
 block discarded – undo
741 760
 		{
742 761
 			foreach ($costs as $duration => $cost)
743 762
 			{
744
-				if ($cost != 0)
745
-					$cost_array[$duration] = $cost;
763
+				if ($cost != 0) {
764
+									$cost_array[$duration] = $cost;
765
+				}
746 766
 			}
747
-		}
748
-		else
767
+		} else
749 768
 		{
750 769
 			$cost_array['fixed'] = $costs['fixed'];
751 770
 		}
752 771
 
753
-		if (empty($cost_array))
754
-			unset($context['subscriptions'][$id]);
755
-		else
772
+		if (empty($cost_array)) {
773
+					unset($context['subscriptions'][$id]);
774
+		} else
756 775
 		{
757 776
 			$context['subscriptions'][$id]['member'] = 0;
758 777
 			$context['subscriptions'][$id]['subscribed'] = false;
@@ -765,13 +784,15 @@  discard block
 block discarded – undo
765 784
 	foreach ($gateways as $id => $gateway)
766 785
 	{
767 786
 		$gateways[$id] = new $gateway['display_class']();
768
-		if (!$gateways[$id]->gatewayEnabled())
769
-			unset($gateways[$id]);
787
+		if (!$gateways[$id]->gatewayEnabled()) {
788
+					unset($gateways[$id]);
789
+		}
770 790
 	}
771 791
 
772 792
 	// No gateways yet?
773
-	if (empty($gateways))
774
-		fatal_error($txt['paid_admin_not_setup_gateway']);
793
+	if (empty($gateways)) {
794
+			fatal_error($txt['paid_admin_not_setup_gateway']);
795
+	}
775 796
 
776 797
 	// Get the current subscriptions.
777 798
 	$request = $smcFunc['db_query']('', '
@@ -786,8 +807,9 @@  discard block
 block discarded – undo
786 807
 	while ($row = $smcFunc['db_fetch_assoc']($request))
787 808
 	{
788 809
 		// The subscription must exist!
789
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
790
-			continue;
810
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
811
+					continue;
812
+		}
791 813
 
792 814
 		$context['current'][$row['id_subscribe']] = array(
793 815
 			'id' => $row['id_sublog'],
@@ -801,8 +823,9 @@  discard block
 block discarded – undo
801 823
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'],
802 824
 		);
803 825
 
804
-		if ($row['status'] == 1)
805
-			$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
826
+		if ($row['status'] == 1) {
827
+					$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
828
+		}
806 829
 	}
807 830
 	$smcFunc['db_free_result']($request);
808 831
 
@@ -853,21 +876,25 @@  discard block
 block discarded – undo
853 876
 	if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id']))
854 877
 	{
855 878
 		// Hopefully just one.
856
-		foreach ($_POST['sub_id'] as $k => $v)
857
-			$ID_SUB = (int) $k;
879
+		foreach ($_POST['sub_id'] as $k => $v) {
880
+					$ID_SUB = (int) $k;
881
+		}
858 882
 
859
-		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0)
860
-			fatal_lang_error('paid_sub_not_active');
883
+		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) {
884
+					fatal_lang_error('paid_sub_not_active');
885
+		}
861 886
 
862 887
 		// Simplify...
863 888
 		$context['sub'] = $context['subscriptions'][$ID_SUB];
864 889
 		$period = 'xx';
865
-		if ($context['sub']['flexible'])
866
-			$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
890
+		if ($context['sub']['flexible']) {
891
+					$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
892
+		}
867 893
 
868 894
 		// Check we have a valid cost.
869
-		if ($context['sub']['flexible'] && $period == 'xx')
870
-			fatal_lang_error('paid_sub_not_active');
895
+		if ($context['sub']['flexible'] && $period == 'xx') {
896
+					fatal_lang_error('paid_sub_not_active');
897
+		}
871 898
 
872 899
 		// Sort out the cost/currency.
873 900
 		$context['currency'] = $modSettings['paid_currency_code'];
@@ -880,8 +907,7 @@  discard block
 block discarded – undo
880 907
 			$context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]];
881 908
 			// The period value for paypal.
882 909
 			$context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1));
883
-		}
884
-		else
910
+		} else
885 911
 		{
886 912
 			// Real cost...
887 913
 			$context['value'] = $context['sub']['costs']['fixed'];
@@ -898,13 +924,15 @@  discard block
 block discarded – undo
898 924
 		foreach ($gateways as $id => $gateway)
899 925
 		{
900 926
 			$fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done');
901
-			if (!empty($fields['form']))
902
-				$context['gateways'][] = $fields;
927
+			if (!empty($fields['form'])) {
928
+							$context['gateways'][] = $fields;
929
+			}
903 930
 		}
904 931
 
905 932
 		// Bugger?!
906
-		if (empty($context['gateways']))
907
-			fatal_error($txt['paid_admin_not_setup_gateway']);
933
+		if (empty($context['gateways'])) {
934
+					fatal_error($txt['paid_admin_not_setup_gateway']);
935
+		}
908 936
 
909 937
 		// Now we are going to assume they want to take this out ;)
910 938
 		$new_data = array($context['sub']['id'], $context['value'], $period, 'prepay');
@@ -912,16 +940,19 @@  discard block
 block discarded – undo
912 940
 		{
913 941
 			// What are the details like?
914 942
 			$current_pending = array();
915
-			if ($context['current'][$context['sub']['id']]['pending_details'] != '')
916
-				$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
943
+			if ($context['current'][$context['sub']['id']]['pending_details'] != '') {
944
+							$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
945
+			}
917 946
 			// Don't get silly.
918
-			if (count($current_pending) > 9)
919
-				$current_pending = array();
947
+			if (count($current_pending) > 9) {
948
+							$current_pending = array();
949
+			}
920 950
 			$pending_count = 0;
921 951
 			// Only record real pending payments as will otherwise confuse the admin!
922
-			foreach ($current_pending as $pending)
923
-				if ($pending[3] == 'payback')
952
+			foreach ($current_pending as $pending) {
953
+							if ($pending[3] == 'payback')
924 954
 					$pending_count++;
955
+			}
925 956
 
926 957
 			if (!in_array($new_data, $current_pending))
927 958
 			{
@@ -966,9 +997,9 @@  discard block
 block discarded – undo
966 997
 
967 998
 		// Quit.
968 999
 		return;
1000
+	} else {
1001
+			$context['sub_template'] = 'user_subscription';
1002
+	}
969 1003
 	}
970
-	else
971
-		$context['sub_template'] = 'user_subscription';
972
-}
973 1004
 
974 1005
 ?>
975 1006
\ No newline at end of file
Please login to merge, or discard this patch.