Completed
Push — release-2.1 ( cfdc59...af3d3b )
by Jeremy
12:06 queued 05:35
created
Sources/ManageScheduledTasks.php 1 patch
Braces   +57 added lines, -40 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
  * Scheduled tasks management dispatcher. This function checks permissions and delegates
@@ -41,10 +42,11 @@  discard block
 block discarded – undo
41 42
 	);
42 43
 
43 44
 	// We need to find what's the action.
44
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
45
-		$context['sub_action'] = $_REQUEST['sa'];
46
-	else
47
-		$context['sub_action'] = 'tasks';
45
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
46
+			$context['sub_action'] = $_REQUEST['sa'];
47
+	} else {
48
+			$context['sub_action'] = 'tasks';
49
+	}
48 50
 
49 51
 	// Now for the lovely tabs. That we all love.
50 52
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -94,9 +96,10 @@  discard block
 block discarded – undo
94 96
 
95 97
 		// Enable and disable as required.
96 98
 		$enablers = array(0);
97
-		foreach ($_POST['enable_task'] as $id => $enabled)
98
-			if ($enabled)
99
+		foreach ($_POST['enable_task'] as $id => $enabled) {
100
+					if ($enabled)
99 101
 				$enablers[] = (int) $id;
102
+		}
100 103
 
101 104
 		// Do the update!
102 105
 		$smcFunc['db_query']('', '
@@ -134,8 +137,9 @@  discard block
 block discarded – undo
134 137
 
135 138
 		// Lets figure out which ones they want to run.
136 139
 		$tasks = array();
137
-		foreach ($_POST['run_task'] as $task => $dummy)
138
-			$tasks[] = (int) $task;
140
+		foreach ($_POST['run_task'] as $task => $dummy) {
141
+					$tasks[] = (int) $task;
142
+		}
139 143
 
140 144
 		// Load up the tasks.
141 145
 		$request = $smcFunc['db_query']('', '
@@ -155,36 +159,41 @@  discard block
 block discarded – undo
155 159
 		while ($row = $smcFunc['db_fetch_assoc']($request))
156 160
 		{
157 161
 			// What kind of task are we handling?
158
-			if (!empty($row['callable']))
159
-				$task_string = $row['callable'];
162
+			if (!empty($row['callable'])) {
163
+							$task_string = $row['callable'];
164
+			}
160 165
 
161 166
 			// Default SMF task or old mods?
162
-			elseif (function_exists('scheduled_' . $row['task']))
163
-				$task_string = 'scheduled_' . $row['task'];
167
+			elseif (function_exists('scheduled_' . $row['task'])) {
168
+							$task_string = 'scheduled_' . $row['task'];
169
+			}
164 170
 
165 171
 			// One last resource, the task name.
166
-			elseif (!empty($row['task']))
167
-				$task_string = $row['task'];
172
+			elseif (!empty($row['task'])) {
173
+							$task_string = $row['task'];
174
+			}
168 175
 
169 176
 			$start_time = microtime();
170 177
 			// The functions got to exist for us to use it.
171
-			if (empty($task_string))
172
-				continue;
178
+			if (empty($task_string)) {
179
+							continue;
180
+			}
173 181
 
174 182
 			// Try to stop a timeout, this would be bad...
175 183
 			@set_time_limit(300);
176
-			if (function_exists('apache_reset_timeout'))
177
-				@apache_reset_timeout();
184
+			if (function_exists('apache_reset_timeout')) {
185
+							@apache_reset_timeout();
186
+			}
178 187
 
179 188
 			// Get the callable.
180 189
 			$callable_task = call_helper($task_string, true);
181 190
 
182 191
 			// Perform the task.
183
-			if (!empty($callable_task))
184
-				$completed = call_user_func($callable_task);
185
-
186
-			else
187
-				$completed = false;
192
+			if (!empty($callable_task)) {
193
+							$completed = call_user_func($callable_task);
194
+			} else {
195
+							$completed = false;
196
+			}
188 197
 
189 198
 			// Log that we did it ;)
190 199
 			if ($completed)
@@ -201,8 +210,9 @@  discard block
 block discarded – undo
201 210
 		$smcFunc['db_free_result']($request);
202 211
 
203 212
 		// If we had any errors, push them to session so we can pick them up next time to tell the user.
204
-		if (!empty($context['scheduled_errors']))
205
-			$_SESSION['st_error'] = $context['scheduled_errors'];
213
+		if (!empty($context['scheduled_errors'])) {
214
+					$_SESSION['st_error'] = $context['scheduled_errors'];
215
+		}
206 216
 
207 217
 		redirectexit('action=admin;area=scheduledtasks;done');
208 218
 	}
@@ -374,8 +384,9 @@  discard block
 block discarded – undo
374 384
 	$context['server_time'] = timeformat(time(), false, 'server');
375 385
 
376 386
 	// Cleaning...
377
-	if (!isset($_GET['tid']))
378
-		fatal_lang_error('no_access', false);
387
+	if (!isset($_GET['tid'])) {
388
+			fatal_lang_error('no_access', false);
389
+	}
379 390
 	$_GET['tid'] = (int) $_GET['tid'];
380 391
 
381 392
 	// Saving?
@@ -391,10 +402,12 @@  discard block
 block discarded – undo
391 402
 		preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches);
392 403
 
393 404
 		// If a half is empty then assume zero offset!
394
-		if (!isset($matches[2]) || $matches[2] > 59)
395
-			$matches[2] = 0;
396
-		if (!isset($matches[1]) || $matches[1] > 23)
397
-			$matches[1] = 0;
405
+		if (!isset($matches[2]) || $matches[2] > 59) {
406
+					$matches[2] = 0;
407
+		}
408
+		if (!isset($matches[1]) || $matches[1] > 23) {
409
+					$matches[1] = 0;
410
+		}
398 411
 
399 412
 		// Now the offset is easy; easy peasy - except we need to offset by a few hours...
400 413
 		$offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z');
@@ -404,8 +417,9 @@  discard block
 block discarded – undo
404 417
 		$unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd';
405 418
 
406 419
 		// Don't allow one minute intervals.
407
-		if ($interval == 1 && $unit == 'm')
408
-			$interval = 2;
420
+		if ($interval == 1 && $unit == 'm') {
421
+					$interval = 2;
422
+		}
409 423
 
410 424
 		// Is it disabled?
411 425
 		$disabled = !isset($_POST['enabled']) ? 1 : 0;
@@ -443,8 +457,9 @@  discard block
 block discarded – undo
443 457
 	);
444 458
 
445 459
 	// Should never, ever, happen!
446
-	if ($smcFunc['db_num_rows']($request) == 0)
447
-		fatal_lang_error('no_access', false);
460
+	if ($smcFunc['db_num_rows']($request) == 0) {
461
+			fatal_lang_error('no_access', false);
462
+	}
448 463
 
449 464
 	while ($row = $smcFunc['db_fetch_assoc']($request))
450 465
 	{
@@ -602,13 +617,14 @@  discard block
 block discarded – undo
602 617
 		)
603 618
 	);
604 619
 	$log_entries = array();
605
-	while ($row = $smcFunc['db_fetch_assoc']($request))
606
-		$log_entries[] = array(
620
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
621
+			$log_entries[] = array(
607 622
 			'id' => $row['id_log'],
608 623
 			'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'],
609 624
 			'time_run' => $row['time_run'],
610 625
 			'time_taken' => $row['time_taken'],
611 626
 		);
627
+	}
612 628
 	$smcFunc['db_free_result']($request);
613 629
 
614 630
 	return $log_entries;
@@ -649,8 +665,9 @@  discard block
 block discarded – undo
649 665
 
650 666
 	call_integration_hook('integrate_scheduled_tasks_settings', array(&$config_vars));
651 667
 
652
-	if ($return_config)
653
-		return $config_vars;
668
+	if ($return_config) {
669
+			return $config_vars;
670
+	}
654 671
 
655 672
 	// Set up the template.
656 673
 	$context['page_title'] = $txt['scheduled_tasks_settings'];
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +227 added lines, -165 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
  * Get all birthdays within the given time range.
@@ -60,8 +61,7 @@  discard block
 block discarded – undo
60 61
 				'max_year' => $year_high,
61 62
 			)
62 63
 		);
63
-	}
64
-	else
64
+	} else
65 65
 	{
66 66
 		$result = $smcFunc['db_query']('birthday_array', '
67 67
 			SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate
@@ -91,10 +91,11 @@  discard block
 block discarded – undo
91 91
 	$bday = array();
92 92
 	while ($row = $smcFunc['db_fetch_assoc']($result))
93 93
 	{
94
-		if ($year_low != $year_high)
95
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
-		else
97
-			$age_year = $year_low;
94
+		if ($year_low != $year_high) {
95
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
+		} else {
97
+					$age_year = $year_low;
98
+		}
98 99
 
99 100
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
100 101
 			'id' => $row['id_member'],
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 	ksort($bday);
109 110
 
110 111
 	// Set is_last, so the themes know when to stop placing separators.
111
-	foreach ($bday as $mday => $array)
112
-		$bday[$mday][count($array) - 1]['is_last'] = true;
112
+	foreach ($bday as $mday => $array) {
113
+			$bday[$mday][count($array) - 1]['is_last'] = true;
114
+	}
113 115
 
114 116
 	return $bday;
115 117
 }
@@ -133,8 +135,9 @@  discard block
 block discarded – undo
133 135
 	static $timezone_array = array();
134 136
 	require_once($sourcedir . '/Subs.php');
135 137
 
136
-	if (empty($timezone_array['default']))
137
-		$timezone_array['default'] = timezone_open(date_default_timezone_get());
138
+	if (empty($timezone_array['default'])) {
139
+			$timezone_array['default'] = timezone_open(date_default_timezone_get());
140
+	}
138 141
 
139 142
 	$low_object = date_create($low_date);
140 143
 	$high_object = date_create($high_date);
@@ -161,8 +164,9 @@  discard block
 block discarded – undo
161 164
 	while ($row = $smcFunc['db_fetch_assoc']($result))
162 165
 	{
163 166
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
164
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
165
-			continue;
167
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
168
+					continue;
169
+		}
166 170
 
167 171
 		// Force a censor of the title - as often these are used by others.
168 172
 		censorText($row['title'], $use_permissions ? false : true);
@@ -170,12 +174,14 @@  discard block
 block discarded – undo
170 174
 		// Get the various time and date properties for this event
171 175
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
172 176
 
173
-		if (empty($timezone_array[$tz]))
174
-			$timezone_array[$tz] = timezone_open($tz);
177
+		if (empty($timezone_array[$tz])) {
178
+					$timezone_array[$tz] = timezone_open($tz);
179
+		}
175 180
 
176 181
 		// Sanity check
177
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
178
-			continue;
182
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
183
+					continue;
184
+		}
179 185
 
180 186
 		// Get set up for the loop
181 187
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), $timezone_array[$tz]);
@@ -239,8 +245,8 @@  discard block
 block discarded – undo
239 245
 			);
240 246
 
241 247
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
242
-			if ($use_permissions)
243
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
248
+			if ($use_permissions) {
249
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
244 250
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
245 251
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
246 252
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -248,9 +254,10 @@  discard block
 block discarded – undo
248 254
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
249 255
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
250 256
 				));
257
+			}
251 258
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
252
-			else
253
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
259
+			else {
260
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
254 261
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
255 262
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
256 263
 					'can_edit' => false,
@@ -260,6 +267,7 @@  discard block
 block discarded – undo
260 267
 					'poster' => $row['id_member'],
261 268
 					'allowed_groups' => explode(',', $row['member_groups']),
262 269
 				));
270
+			}
263 271
 
264 272
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
265 273
 		}
@@ -269,8 +277,9 @@  discard block
 block discarded – undo
269 277
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
270 278
 	if ($use_permissions)
271 279
 	{
272
-		foreach ($events as $mday => $array)
273
-			$events[$mday][count($array) - 1]['is_last'] = true;
280
+		foreach ($events as $mday => $array) {
281
+					$events[$mday][count($array) - 1]['is_last'] = true;
282
+		}
274 283
 	}
275 284
 
276 285
 	ksort($events);
@@ -290,11 +299,12 @@  discard block
 block discarded – undo
290 299
 	global $smcFunc;
291 300
 
292 301
 	// Get the lowest and highest dates for "all years".
293
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
294
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
302
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
303
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
295 304
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
296
-	else
297
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
305
+	} else {
306
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
307
+	}
298 308
 
299 309
 	// Find some holidays... ;).
300 310
 	$result = $smcFunc['db_query']('', '
@@ -314,10 +324,11 @@  discard block
 block discarded – undo
314 324
 	$holidays = array();
315 325
 	while ($row = $smcFunc['db_fetch_assoc']($result))
316 326
 	{
317
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
318
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
319
-		else
320
-			$event_year = substr($low_date, 0, 4);
327
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
328
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
329
+		} else {
330
+					$event_year = substr($low_date, 0, 4);
331
+		}
321 332
 
322 333
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
323 334
 	}
@@ -343,10 +354,12 @@  discard block
 block discarded – undo
343 354
 	isAllowedTo('calendar_post');
344 355
 
345 356
 	// No board?  No topic?!?
346
-	if (empty($board))
347
-		fatal_lang_error('missing_board_id', false);
348
-	if (empty($topic))
349
-		fatal_lang_error('missing_topic_id', false);
357
+	if (empty($board)) {
358
+			fatal_lang_error('missing_board_id', false);
359
+	}
360
+	if (empty($topic)) {
361
+			fatal_lang_error('missing_topic_id', false);
362
+	}
350 363
 
351 364
 	// Administrator, Moderator, or owner.  Period.
352 365
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -364,12 +377,14 @@  discard block
 block discarded – undo
364 377
 		if ($row = $smcFunc['db_fetch_assoc']($result))
365 378
 		{
366 379
 			// Not the owner of the topic.
367
-			if ($row['id_member_started'] != $user_info['id'])
368
-				fatal_lang_error('not_your_topic', 'user');
380
+			if ($row['id_member_started'] != $user_info['id']) {
381
+							fatal_lang_error('not_your_topic', 'user');
382
+			}
369 383
 		}
370 384
 		// Topic/Board doesn't exist.....
371
-		else
372
-			fatal_lang_error('calendar_no_topic', 'general');
385
+		else {
386
+					fatal_lang_error('calendar_no_topic', 'general');
387
+		}
373 388
 		$smcFunc['db_free_result']($result);
374 389
 	}
375 390
 }
@@ -457,14 +472,16 @@  discard block
 block discarded – undo
457 472
 	if (!empty($calendarOptions['start_day']))
458 473
 	{
459 474
 		$nShift -= $calendarOptions['start_day'];
460
-		if ($nShift < 0)
461
-			$nShift = 7 + $nShift;
475
+		if ($nShift < 0) {
476
+					$nShift = 7 + $nShift;
477
+		}
462 478
 	}
463 479
 
464 480
 	// Number of rows required to fit the month.
465 481
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
466
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
467
-		$nRows++;
482
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
483
+			$nRows++;
484
+	}
468 485
 
469 486
 	// Fetch the arrays for birthdays, posted events, and holidays.
470 487
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -477,8 +494,9 @@  discard block
 block discarded – undo
477 494
 	{
478 495
 		$calendarGrid['week_days'][] = $count;
479 496
 		$count++;
480
-		if ($count == 7)
481
-			$count = 0;
497
+		if ($count == 7) {
498
+					$count = 0;
499
+		}
482 500
 	}
483 501
 
484 502
 	// Iterate through each week.
@@ -495,8 +513,9 @@  discard block
 block discarded – undo
495 513
 		{
496 514
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
497 515
 
498
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
499
-				$nDay = 0;
516
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
517
+							$nDay = 0;
518
+			}
500 519
 
501 520
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
502 521
 
@@ -514,8 +533,9 @@  discard block
 block discarded – undo
514 533
 	}
515 534
 
516 535
 	// What is the last day of the month?
517
-	if ($is_previous === true)
518
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
536
+	if ($is_previous === true) {
537
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
538
+	}
519 539
 
520 540
 	// We'll use the shift in the template.
521 541
 	$calendarGrid['shift'] = $nShift;
@@ -549,8 +569,9 @@  discard block
 block discarded – undo
549 569
 	{
550 570
 		// Here we offset accordingly to get things to the real start of a week.
551 571
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
552
-		if ($date_diff < 0)
553
-			$date_diff += 7;
572
+		if ($date_diff < 0) {
573
+					$date_diff += 7;
574
+		}
554 575
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
555 576
 		$day = (int) strftime('%d', $new_timestamp);
556 577
 		$month = (int) strftime('%m', $new_timestamp);
@@ -680,18 +701,20 @@  discard block
 block discarded – undo
680 701
 	{
681 702
 		foreach ($date_events as $event_key => $event_val)
682 703
 		{
683
-			if (in_array($event_val['id'], $temp))
684
-				unset($calendarGrid['events'][$date][$event_key]);
685
-			else
686
-				$temp[] = $event_val['id'];
704
+			if (in_array($event_val['id'], $temp)) {
705
+							unset($calendarGrid['events'][$date][$event_key]);
706
+			} else {
707
+							$temp[] = $event_val['id'];
708
+			}
687 709
 		}
688 710
 	}
689 711
 
690 712
 	// Give birthdays and holidays a friendly format, without the year
691
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
692
-		$date_format = '%b %d';
693
-	else
694
-		$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
713
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
714
+			$date_format = '%b %d';
715
+	} else {
716
+			$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
717
+	}
695 718
 
696 719
 	foreach (array('birthdays', 'holidays') as $type)
697 720
 	{
@@ -790,8 +813,9 @@  discard block
 block discarded – undo
790 813
 		// Holidays between now and now + days.
791 814
 		for ($i = $now; $i < $now + $days_for_index; $i += 86400)
792 815
 		{
793
-			if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
794
-				$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
816
+			if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
817
+							$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
818
+			}
795 819
 		}
796 820
 	}
797 821
 
@@ -803,8 +827,9 @@  discard block
 block discarded – undo
803 827
 			$loop_date = strftime('%Y-%m-%d', $i);
804 828
 			if (isset($cached_data['birthdays'][$loop_date]))
805 829
 			{
806
-				foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
807
-					$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
830
+				foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
831
+									$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
832
+				}
808 833
 				$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
809 834
 			}
810 835
 		}
@@ -819,8 +844,9 @@  discard block
 block discarded – undo
819 844
 			$loop_date = strftime('%Y-%m-%d', $i);
820 845
 
821 846
 			// No events today? Check the next day.
822
-			if (empty($cached_data['events'][$loop_date]))
823
-				continue;
847
+			if (empty($cached_data['events'][$loop_date])) {
848
+							continue;
849
+			}
824 850
 
825 851
 			// Loop through all events to add a few last-minute values.
826 852
 			foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -833,9 +859,9 @@  discard block
 block discarded – undo
833 859
 				{
834 860
 					unset($cached_data['events'][$loop_date][$ev]);
835 861
 					continue;
862
+				} else {
863
+									$duplicates[$this_event['topic'] . $this_event['title']] = true;
836 864
 				}
837
-				else
838
-					$duplicates[$this_event['topic'] . $this_event['title']] = true;
839 865
 
840 866
 				// Might be set to true afterwards, depending on the permissions.
841 867
 				$this_event['can_edit'] = false;
@@ -843,16 +869,19 @@  discard block
 block discarded – undo
843 869
 				$this_event['date'] = $loop_date;
844 870
 			}
845 871
 
846
-			if (!empty($cached_data['events'][$loop_date]))
847
-				$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
872
+			if (!empty($cached_data['events'][$loop_date])) {
873
+							$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
874
+			}
848 875
 		}
849 876
 	}
850 877
 
851 878
 	// Mark the last item so that a list separator can be used in the template.
852
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
853
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
854
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
855
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
879
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
880
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
881
+	}
882
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
883
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
884
+	}
856 885
 
857 886
 	return array(
858 887
 		'data' => $return_data,
@@ -900,37 +929,46 @@  discard block
 block discarded – undo
900 929
 		if (isset($_POST['start_date']))
901 930
 		{
902 931
 			$d = date_parse($_POST['start_date']);
903
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
904
-				fatal_lang_error('invalid_date', false);
905
-			if (empty($d['year']))
906
-				fatal_lang_error('event_year_missing', false);
907
-			if (empty($d['month']))
908
-				fatal_lang_error('event_month_missing', false);
909
-		}
910
-		elseif (isset($_POST['start_datetime']))
932
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
933
+							fatal_lang_error('invalid_date', false);
934
+			}
935
+			if (empty($d['year'])) {
936
+							fatal_lang_error('event_year_missing', false);
937
+			}
938
+			if (empty($d['month'])) {
939
+							fatal_lang_error('event_month_missing', false);
940
+			}
941
+		} elseif (isset($_POST['start_datetime']))
911 942
 		{
912 943
 			$d = date_parse($_POST['start_datetime']);
913
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
914
-				fatal_lang_error('invalid_date', false);
915
-			if (empty($d['year']))
916
-				fatal_lang_error('event_year_missing', false);
917
-			if (empty($d['month']))
918
-				fatal_lang_error('event_month_missing', false);
944
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
945
+							fatal_lang_error('invalid_date', false);
946
+			}
947
+			if (empty($d['year'])) {
948
+							fatal_lang_error('event_year_missing', false);
949
+			}
950
+			if (empty($d['month'])) {
951
+							fatal_lang_error('event_month_missing', false);
952
+			}
919 953
 		}
920 954
 		// The 2.0 way
921 955
 		else
922 956
 		{
923 957
 			// No month?  No year?
924
-			if (!isset($_POST['month']))
925
-				fatal_lang_error('event_month_missing', false);
926
-			if (!isset($_POST['year']))
927
-				fatal_lang_error('event_year_missing', false);
958
+			if (!isset($_POST['month'])) {
959
+							fatal_lang_error('event_month_missing', false);
960
+			}
961
+			if (!isset($_POST['year'])) {
962
+							fatal_lang_error('event_year_missing', false);
963
+			}
928 964
 
929 965
 			// Check the month and year...
930
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
931
-				fatal_lang_error('invalid_month', false);
932
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
933
-				fatal_lang_error('invalid_year', false);
966
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
967
+							fatal_lang_error('invalid_month', false);
968
+			}
969
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
970
+							fatal_lang_error('invalid_year', false);
971
+			}
934 972
 		}
935 973
 	}
936 974
 
@@ -940,8 +978,9 @@  discard block
 block discarded – undo
940 978
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
941 979
 	if (isset($_POST['span']))
942 980
 	{
943
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
944
-			fatal_lang_error('invalid_days_numb', false);
981
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
982
+					fatal_lang_error('invalid_days_numb', false);
983
+		}
945 984
 	}
946 985
 
947 986
 	// There is no need to validate the following values if we are just deleting the event.
@@ -951,24 +990,29 @@  discard block
 block discarded – undo
951 990
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
952 991
 		{
953 992
 			// No day?
954
-			if (!isset($_POST['day']))
955
-				fatal_lang_error('event_day_missing', false);
993
+			if (!isset($_POST['day'])) {
994
+							fatal_lang_error('event_day_missing', false);
995
+			}
956 996
 
957 997
 			// Bad day?
958
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
959
-				fatal_lang_error('invalid_date', false);
998
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
999
+							fatal_lang_error('invalid_date', false);
1000
+			}
960 1001
 		}
961 1002
 
962
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
963
-			fatal_lang_error('event_title_missing', false);
964
-		elseif (!isset($_POST['evtitle']))
965
-			$_POST['evtitle'] = $_POST['subject'];
1003
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
1004
+					fatal_lang_error('event_title_missing', false);
1005
+		} elseif (!isset($_POST['evtitle'])) {
1006
+					$_POST['evtitle'] = $_POST['subject'];
1007
+		}
966 1008
 
967 1009
 		// No title?
968
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
969
-			fatal_lang_error('no_event_title', false);
970
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
971
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
1010
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
1011
+					fatal_lang_error('no_event_title', false);
1012
+		}
1013
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
1014
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
1015
+		}
972 1016
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
973 1017
 	}
974 1018
 }
@@ -995,8 +1039,9 @@  discard block
 block discarded – undo
995 1039
 	);
996 1040
 
997 1041
 	// No results, return false.
998
-	if ($smcFunc['db_num_rows'] === 0)
999
-		return false;
1042
+	if ($smcFunc['db_num_rows'] === 0) {
1043
+			return false;
1044
+	}
1000 1045
 
1001 1046
 	// Grab the results and return.
1002 1047
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -1130,8 +1175,9 @@  discard block
 block discarded – undo
1130 1175
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
1131 1176
 
1132 1177
 	$column_clauses = array();
1133
-	foreach ($event_columns as $col => $crit)
1134
-		$column_clauses[] = $col . ' = ' . $crit;
1178
+	foreach ($event_columns as $col => $crit) {
1179
+			$column_clauses[] = $col . ' = ' . $crit;
1180
+	}
1135 1181
 
1136 1182
 	$smcFunc['db_query']('', '
1137 1183
 		UPDATE {db_prefix}calendar
@@ -1216,8 +1262,9 @@  discard block
 block discarded – undo
1216 1262
 	);
1217 1263
 
1218 1264
 	// If nothing returned, we are in poo, poo.
1219
-	if ($smcFunc['db_num_rows']($request) === 0)
1220
-		return false;
1265
+	if ($smcFunc['db_num_rows']($request) === 0) {
1266
+			return false;
1267
+	}
1221 1268
 
1222 1269
 	$row = $smcFunc['db_fetch_assoc']($request);
1223 1270
 	$smcFunc['db_free_result']($request);
@@ -1225,8 +1272,9 @@  discard block
 block discarded – undo
1225 1272
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1226 1273
 
1227 1274
 	// Sanity check
1228
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1229
-		return false;
1275
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1276
+			return false;
1277
+	}
1230 1278
 
1231 1279
 	$return_value = array(
1232 1280
 		'boards' => array(),
@@ -1363,24 +1411,27 @@  discard block
 block discarded – undo
1363 1411
 
1364 1412
 	// Set $span, in case we need it
1365 1413
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1366
-	if ($span > 0)
1367
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1414
+	if ($span > 0) {
1415
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1416
+	}
1368 1417
 
1369 1418
 	// Define the timezone for this event, falling back to the default if not provided
1370
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1371
-		$tz = $eventOptions['tz'];
1372
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1373
-		$tz = $_POST['tz'];
1374
-	else
1375
-		$tz = getUserTimezone();
1419
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1420
+			$tz = $eventOptions['tz'];
1421
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1422
+			$tz = $_POST['tz'];
1423
+	} else {
1424
+			$tz = getUserTimezone();
1425
+	}
1376 1426
 
1377 1427
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1378
-	if (isset($eventOptions['allday']))
1379
-		$allday = $eventOptions['allday'];
1380
-	elseif (empty($_POST['allday']))
1381
-		$allday = false;
1382
-	else
1383
-		$allday = true;
1428
+	if (isset($eventOptions['allday'])) {
1429
+			$allday = $eventOptions['allday'];
1430
+	} elseif (empty($_POST['allday'])) {
1431
+			$allday = false;
1432
+	} else {
1433
+			$allday = true;
1434
+	}
1384 1435
 
1385 1436
 	// Input might come as individual parameters...
1386 1437
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1407,10 +1458,12 @@  discard block
 block discarded – undo
1407 1458
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1408 1459
 
1409 1460
 	// If the date and time were given in separate strings, combine them
1410
-	if (empty($start_string) && isset($start_date_string))
1411
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1412
-	if (empty($end_string) && isset($end_date_string))
1413
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1461
+	if (empty($start_string) && isset($start_date_string)) {
1462
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1463
+	}
1464
+	if (empty($end_string) && isset($end_date_string)) {
1465
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1466
+	}
1414 1467
 
1415 1468
 	// If some form of string input was given, override individually defined options with it
1416 1469
 	if (isset($start_string))
@@ -1501,10 +1554,11 @@  discard block
 block discarded – undo
1501 1554
 	if ($start_object >= $end_object)
1502 1555
 	{
1503 1556
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1504
-		if ($span > 0)
1505
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1506
-		else
1507
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1557
+		if ($span > 0) {
1558
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1559
+		} else {
1560
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1561
+		}
1508 1562
 	}
1509 1563
 
1510 1564
 	// Is $end_object too late?
@@ -1517,9 +1571,9 @@  discard block
 block discarded – undo
1517 1571
 			{
1518 1572
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1519 1573
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1574
+			} else {
1575
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1520 1576
 			}
1521
-			else
1522
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1523 1577
 		}
1524 1578
 	}
1525 1579
 
@@ -1532,8 +1586,7 @@  discard block
 block discarded – undo
1532 1586
 		$start_time = null;
1533 1587
 		$end_time = null;
1534 1588
 		$tz = null;
1535
-	}
1536
-	else
1589
+	} else
1537 1590
 	{
1538 1591
 		$start_time = date_format($start_object, 'H:i:s');
1539 1592
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1561,19 +1614,21 @@  discard block
 block discarded – undo
1561 1614
 	// First, try to create a better date format, ignoring the "time" elements.
1562 1615
 	if (empty($date_format))
1563 1616
 	{
1564
-		if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1565
-			$date_format = '%F';
1566
-		else
1567
-			$date_format = $matches[0];
1617
+		if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1618
+					$date_format = '%F';
1619
+		} else {
1620
+					$date_format = $matches[0];
1621
+		}
1568 1622
 	}
1569 1623
 
1570 1624
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1571 1625
 	if (empty($time_format))
1572 1626
 	{
1573
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1574
-			$time_format = '%k:%M';
1575
-		else
1576
-			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1627
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1628
+					$time_format = '%k:%M';
1629
+		} else {
1630
+					$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1631
+		}
1577 1632
 	}
1578 1633
 
1579 1634
 	// Should this be an all day event?
@@ -1583,11 +1638,13 @@  discard block
 block discarded – undo
1583 1638
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1584 1639
 
1585 1640
 	// We need to have a defined timezone in the steps below
1586
-	if (empty($row['timezone']))
1587
-		$row['timezone'] = getUserTimezone();
1641
+	if (empty($row['timezone'])) {
1642
+			$row['timezone'] = getUserTimezone();
1643
+	}
1588 1644
 
1589
-	if (empty($timezone_array[$row['timezone']]))
1590
-		$timezone_array[$row['timezone']] = timezone_open($row['timezone']);
1645
+	if (empty($timezone_array[$row['timezone']])) {
1646
+			$timezone_array[$row['timezone']] = timezone_open($row['timezone']);
1647
+	}
1591 1648
 
1592 1649
 	// Get most of the standard date information for the start and end datetimes
1593 1650
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1622,8 +1679,9 @@  discard block
 block discarded – undo
1622 1679
 	$tz_abbrev = date_format($start_object, 'T');
1623 1680
 
1624 1681
 	// If the abbreviation is just a numerical offset from UTC, make that clear.
1625
-	if (strspn($tz_abbrev, '+-') > 0)
1626
-		$tz_abbrev = 'UTC' . $tz_abbrev;
1682
+	if (strspn($tz_abbrev, '+-') > 0) {
1683
+			$tz_abbrev = 'UTC' . $tz_abbrev;
1684
+	}
1627 1685
 
1628 1686
 	return array($start, $end, $allday, $span, $tz, $tz_abbrev);
1629 1687
 }
@@ -1639,8 +1697,9 @@  discard block
 block discarded – undo
1639 1697
 	global $smcFunc, $context, $user_info, $modSettings, $user_settings;
1640 1698
 	static $member_cache = array();
1641 1699
 
1642
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1643
-		$id_member = $context['user']['id'];
1700
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1701
+			$id_member = $context['user']['id'];
1702
+	}
1644 1703
 
1645 1704
 	//check if the cache got the data
1646 1705
 	if (isset($id_member) && isset($member_cache[$id_member]))
@@ -1669,11 +1728,13 @@  discard block
 block discarded – undo
1669 1728
 		$smcFunc['db_free_result']($request);
1670 1729
 	}
1671 1730
 
1672
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1673
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1731
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1732
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1733
+	}
1674 1734
 
1675
-	if (isset($id_member))
1676
-		$member_cache[$id_member] = $timezone;
1735
+	if (isset($id_member)) {
1736
+			$member_cache[$id_member] = $timezone;
1737
+	}
1677 1738
 
1678 1739
 	return $timezone;
1679 1740
 }
@@ -1702,8 +1763,9 @@  discard block
 block discarded – undo
1702 1763
 		)
1703 1764
 	);
1704 1765
 	$holidays = array();
1705
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1706
-		$holidays[] = $row;
1766
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1767
+			$holidays[] = $row;
1768
+	}
1707 1769
 	$smcFunc['db_free_result']($request);
1708 1770
 
1709 1771
 	return $holidays;
Please login to merge, or discard this patch.
Sources/Class-SearchAPI.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -233,11 +233,13 @@
 block discarded – undo
233 233
 		);
234 234
 
235 235
 		$id_searchs = array();
236
-		while ($row = $smcFunc['db_fetch_assoc']($result))
237
-			$id_searchs[] = $row['id_search'];
236
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
237
+					$id_searchs[] = $row['id_search'];
238
+		}
238 239
 
239
-		if (count($id_searchs) < 1)
240
-			return;
240
+		if (count($id_searchs) < 1) {
241
+					return;
242
+		}
241 243
 
242 244
 		$smcFunc['db_query']('','
243 245
 			DELETE FROM {db_prefix}log_search_results
Please login to merge, or discard this patch.
Sources/SearchAPI-Standard.php 1 patch
Braces   +5 added lines, -3 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
  * Standard non full index, non custom index search
@@ -27,8 +28,9 @@  discard block
 block discarded – undo
27 28
 		$return = false;
28 29
 
29 30
 		// Maybe parent got support
30
-		if (!$return)
31
-			$return = parent::supportsMethod($methodName, $query_params);
31
+		if (!$return) {
32
+					$return = parent::supportsMethod($methodName, $query_params);
33
+		}
32 34
 
33 35
 		return $return;
34 36
 	}
Please login to merge, or discard this patch.
Sources/SearchAPI-Fulltext.php 1 patch
Braces   +53 added lines, -40 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
@@ -75,8 +76,9 @@  discard block
 block discarded – undo
75 76
 		}
76 77
 
77 78
 		// Maybe parent got support
78
-		if (!$return)
79
-			$return = parent::supportsMethod($methodName, $query_params);
79
+		if (!$return) {
80
+					$return = parent::supportsMethod($methodName, $query_params);
81
+		}
80 82
 
81 83
 		return $return;
82 84
 	}
@@ -92,8 +94,9 @@  discard block
 block discarded – undo
92 94
 	{
93 95
 		global $smcFunc, $db_type;
94 96
 
95
-		if ($db_type == 'postgresql')
96
-			return 0;
97
+		if ($db_type == 'postgresql') {
98
+					return 0;
99
+		}
97 100
 		// Try to determine the minimum number of letters for a fulltext search.
98 101
 		$request = $smcFunc['db_search_query']('max_fulltext_length', '
99 102
 			SHOW VARIABLES
@@ -108,8 +111,9 @@  discard block
 block discarded – undo
108 111
 			$smcFunc['db_free_result']($request);
109 112
 		}
110 113
 		// 4 is the MySQL default...
111
-		else
112
-			$min_word_length = 4;
114
+		else {
115
+					$min_word_length = 4;
116
+		}
113 117
 
114 118
 		return $min_word_length;
115 119
 	}
@@ -148,8 +152,7 @@  discard block
 block discarded – undo
148 152
 					$wordsSearch['words'][] = trim($word, "/*- ");
149 153
 					$wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"';
150 154
 				}
151
-			}
152
-			elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length)
155
+			} elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length)
153 156
 			{
154 157
 				// short words have feelings too
155 158
 				$wordsSearch['words'][] = trim($word, "/*- ");
@@ -159,8 +162,9 @@  discard block
 block discarded – undo
159 162
 
160 163
 		$fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"';
161 164
 		$wordsSearch['indexed_words'][] = $fulltextWord;
162
-		if ($isExcluded)
163
-			$wordsExclude[] = $fulltextWord;
165
+		if ($isExcluded) {
166
+					$wordsExclude[] = $fulltextWord;
167
+		}
164 168
 	}
165 169
 
166 170
 	/**
@@ -176,44 +180,54 @@  discard block
 block discarded – undo
176 180
 		$query_where = array();
177 181
 		$query_params = $search_data['params'];
178 182
 
179
-		if( $smcFunc['db_title'] == "PostgreSQL")
180
-			$modSettings['search_simple_fulltext'] = true;
183
+		if( $smcFunc['db_title'] == "PostgreSQL") {
184
+					$modSettings['search_simple_fulltext'] = true;
185
+		}
181 186
 
182
-		if ($query_params['id_search'])
183
-			$query_select['id_search'] = '{int:id_search}';
187
+		if ($query_params['id_search']) {
188
+					$query_select['id_search'] = '{int:id_search}';
189
+		}
184 190
 
185 191
 		$count = 0;
186
-		if (empty($modSettings['search_simple_fulltext']))
187
-			foreach ($words['words'] as $regularWord)
192
+		if (empty($modSettings['search_simple_fulltext'])) {
193
+					foreach ($words['words'] as $regularWord)
188 194
 			{
189 195
 				$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 . '}';
196
+		}
190 197
 				$query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
191 198
 			}
192 199
 
193
-		if ($query_params['user_query'])
194
-			$query_where[] = '{raw:user_query}';
195
-		if ($query_params['board_query'])
196
-			$query_where[] = 'm.id_board {raw:board_query}';
200
+		if ($query_params['user_query']) {
201
+					$query_where[] = '{raw:user_query}';
202
+		}
203
+		if ($query_params['board_query']) {
204
+					$query_where[] = 'm.id_board {raw:board_query}';
205
+		}
197 206
 
198
-		if ($query_params['topic'])
199
-			$query_where[] = 'm.id_topic = {int:topic}';
200
-		if ($query_params['min_msg_id'])
201
-			$query_where[] = 'm.id_msg >= {int:min_msg_id}';
202
-		if ($query_params['max_msg_id'])
203
-			$query_where[] = 'm.id_msg <= {int:max_msg_id}';
207
+		if ($query_params['topic']) {
208
+					$query_where[] = 'm.id_topic = {int:topic}';
209
+		}
210
+		if ($query_params['min_msg_id']) {
211
+					$query_where[] = 'm.id_msg >= {int:min_msg_id}';
212
+		}
213
+		if ($query_params['max_msg_id']) {
214
+					$query_where[] = 'm.id_msg <= {int:max_msg_id}';
215
+		}
204 216
 
205 217
 		$count = 0;
206
-		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index']))
207
-			foreach ($query_params['excluded_phrases'] as $phrase)
218
+		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) {
219
+					foreach ($query_params['excluded_phrases'] as $phrase)
208 220
 			{
209 221
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}';
222
+		}
210 223
 				$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), '\\\'') . '[[:>:]]';
211 224
 			}
212 225
 		$count = 0;
213
-		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index']))
214
-			foreach ($query_params['excluded_subject_words'] as $excludedWord)
226
+		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) {
227
+					foreach ($query_params['excluded_subject_words'] as $excludedWord)
215 228
 			{
216 229
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}';
230
+		}
217 231
 				$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), '\\\'') . '[[:>:]]';
218 232
 			}
219 233
 
@@ -225,12 +239,11 @@  discard block
 block discarded – undo
225 239
 
226 240
 				$query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:body_match})';
227 241
 				$query_params['language_ftx'] = $language_ftx;
242
+			} else {
243
+							$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
228 244
 			}
229
-			else
230
-				$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
231 245
 			$query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words']));
232
-		}
233
-		else
246
+		} else
234 247
 		{
235 248
 			$query_params['boolean_match'] = '';
236 249
 
@@ -246,10 +259,10 @@  discard block
 block discarded – undo
246 259
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' ';
247 260
 					$row++;
248 261
 				}
249
-			}
250
-			else
251
-				foreach ($words['indexed_words'] as $fulltextWord)
262
+			} else {
263
+							foreach ($words['indexed_words'] as $fulltextWord)
252 264
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' ';
265
+			}
253 266
 
254 267
 			$query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1);
255 268
 
@@ -262,9 +275,9 @@  discard block
 block discarded – undo
262 275
 
263 276
 					$query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:boolean_match})';
264 277
 					$query_params['language_ftx'] = $language_ftx;
278
+				} else {
279
+									$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
265 280
 				}
266
-				else
267
-					$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
268 281
 			}
269 282
 		}
270 283
 
Please login to merge, or discard this patch.
Sources/SearchAPI-Custom.php 1 patch
Braces   +51 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
  * Used for the "custom search index" option
@@ -54,8 +55,9 @@  discard block
 block discarded – undo
54 55
 			return;
55 56
 		}
56 57
 
57
-		if (empty($modSettings['search_custom_index_config']))
58
-			return;
58
+		if (empty($modSettings['search_custom_index_config'])) {
59
+					return;
60
+		}
59 61
 
60 62
 		$this->indexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true);
61 63
 
@@ -86,8 +88,9 @@  discard block
 block discarded – undo
86 88
 		}
87 89
 
88 90
 		// Maybe parent got support
89
-		if (!$return)
90
-			$return = parent::supportsMethod($methodName, $query_params);
91
+		if (!$return) {
92
+					$return = parent::supportsMethod($methodName, $query_params);
93
+		}
91 94
 
92 95
 		return $return;
93 96
 	}
@@ -124,21 +127,23 @@  discard block
 block discarded – undo
124 127
 
125 128
 		$subwords = text2words($word, $this->min_word_length, true);
126 129
 
127
-		if (empty($modSettings['search_force_index']))
128
-			$wordsSearch['words'][] = $word;
130
+		if (empty($modSettings['search_force_index'])) {
131
+					$wordsSearch['words'][] = $word;
132
+		}
129 133
 
130 134
 		// Excluded phrases don't benefit from being split into subwords.
131
-		if (count($subwords) > 1 && $isExcluded)
132
-			return;
133
-		else
135
+		if (count($subwords) > 1 && $isExcluded) {
136
+					return;
137
+		} else
134 138
 		{
135 139
 			foreach ($subwords as $subword)
136 140
 			{
137 141
 				if ($smcFunc['strlen']($subword) >= $this->min_word_length && !in_array($subword, $this->bannedWords))
138 142
 				{
139 143
 					$wordsSearch['indexed_words'][] = $subword;
140
-					if ($isExcluded)
141
-						$wordsExclude[] = $subword;
144
+					if ($isExcluded) {
145
+											$wordsExclude[] = $subword;
146
+					}
142 147
 				}
143 148
 			}
144 149
 		}
@@ -159,8 +164,9 @@  discard block
 block discarded – undo
159 164
 		$query_where = array();
160 165
 		$query_params = $search_data['params'];
161 166
 
162
-		if ($query_params['id_search'])
163
-			$query_select['id_search'] = '{int:id_search}';
167
+		if ($query_params['id_search']) {
168
+					$query_select['id_search'] = '{int:id_search}';
169
+		}
164 170
 
165 171
 		$count = 0;
166 172
 		foreach ($words['words'] as $regularWord)
@@ -169,30 +175,37 @@  discard block
 block discarded – undo
169 175
 			$query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
170 176
 		}
171 177
 
172
-		if ($query_params['user_query'])
173
-			$query_where[] = '{raw:user_query}';
174
-		if ($query_params['board_query'])
175
-			$query_where[] = 'm.id_board {raw:board_query}';
178
+		if ($query_params['user_query']) {
179
+					$query_where[] = '{raw:user_query}';
180
+		}
181
+		if ($query_params['board_query']) {
182
+					$query_where[] = 'm.id_board {raw:board_query}';
183
+		}
176 184
 
177
-		if ($query_params['topic'])
178
-			$query_where[] = 'm.id_topic = {int:topic}';
179
-		if ($query_params['min_msg_id'])
180
-			$query_where[] = 'm.id_msg >= {int:min_msg_id}';
181
-		if ($query_params['max_msg_id'])
182
-			$query_where[] = 'm.id_msg <= {int:max_msg_id}';
185
+		if ($query_params['topic']) {
186
+					$query_where[] = 'm.id_topic = {int:topic}';
187
+		}
188
+		if ($query_params['min_msg_id']) {
189
+					$query_where[] = 'm.id_msg >= {int:min_msg_id}';
190
+		}
191
+		if ($query_params['max_msg_id']) {
192
+					$query_where[] = 'm.id_msg <= {int:max_msg_id}';
193
+		}
183 194
 
184 195
 		$count = 0;
185
-		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index']))
186
-			foreach ($query_params['excluded_phrases'] as $phrase)
196
+		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) {
197
+					foreach ($query_params['excluded_phrases'] as $phrase)
187 198
 			{
188 199
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_phrase_' . $count . '}';
200
+		}
189 201
 				$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), '\\\'') . '[[:>:]]';
190 202
 			}
191 203
 		$count = 0;
192
-		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index']))
193
-			foreach ($query_params['excluded_subject_words'] as $excludedWord)
204
+		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) {
205
+					foreach ($query_params['excluded_subject_words'] as $excludedWord)
194 206
 			{
195 207
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_words_' . $count . '}';
208
+		}
196 209
 				$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), '\\\'') . '[[:>:]]';
197 210
 			}
198 211
 
@@ -205,8 +218,7 @@  discard block
 block discarded – undo
205 218
 			{
206 219
 				$query_left_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_word = ' . $indexedWord . ' AND lsw' . $numTables . '.id_msg = m.id_msg)';
207 220
 				$query_where[] = '(lsw' . $numTables . '.id_word IS NULL)';
208
-			}
209
-			else
221
+			} else
210 222
 			{
211 223
 				$query_inner_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_msg = ' . ($prev_join === 0 ? 'm' : 'lsw' . $prev_join) . '.id_msg)';
212 224
 				$query_where[] = 'lsw' . $numTables . '.id_word = ' . $indexedWord;
@@ -242,16 +254,18 @@  discard block
 block discarded – undo
242 254
 		$customIndexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true);
243 255
 
244 256
 		$inserts = array();
245
-		foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word)
246
-			$inserts[] = array($word, $msgOptions['id']);
257
+		foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) {
258
+					$inserts[] = array($word, $msgOptions['id']);
259
+		}
247 260
 
248
-		if (!empty($inserts))
249
-			$smcFunc['db_insert']('ignore',
261
+		if (!empty($inserts)) {
262
+					$smcFunc['db_insert']('ignore',
250 263
 				'{db_prefix}log_search_words',
251 264
 				array('id_word' => 'int', 'id_msg' => 'int'),
252 265
 				$inserts,
253 266
 				array('id_word', 'id_msg')
254 267
 			);
268
+		}
255 269
 	}
256 270
 
257 271
 	/**
@@ -294,8 +308,9 @@  discard block
 block discarded – undo
294 308
 			if (!empty($inserted_words))
295 309
 			{
296 310
 				$inserts = array();
297
-				foreach ($inserted_words as $word)
298
-					$inserts[] = array($word, $msgOptions['id']);
311
+				foreach ($inserted_words as $word) {
312
+									$inserts[] = array($word, $msgOptions['id']);
313
+				}
299 314
 				$smcFunc['db_insert']('insert',
300 315
 					'{db_prefix}log_search_words',
301 316
 					array('id_word' => 'string', 'id_msg' => 'int'),
Please login to merge, or discard this patch.
Sources/Subs-Membergroups.php 1 patch
Braces   +149 added lines, -112 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
  * Delete one of more membergroups.
@@ -31,15 +32,16 @@  discard block
 block discarded – undo
31 32
 	global $smcFunc, $modSettings, $txt;
32 33
 
33 34
 	// Make sure it's an array.
34
-	if (!is_array($groups))
35
-		$groups = array((int) $groups);
36
-	else
35
+	if (!is_array($groups)) {
36
+			$groups = array((int) $groups);
37
+	} else
37 38
 	{
38 39
 		$groups = array_unique($groups);
39 40
 
40 41
 		// Make sure all groups are integer.
41
-		foreach ($groups as $key => $value)
42
-			$groups[$key] = (int) $value;
42
+		foreach ($groups as $key => $value) {
43
+					$groups[$key] = (int) $value;
44
+		}
43 45
 	}
44 46
 
45 47
 	// Some groups are protected (guests, administrators, moderators, newbies).
@@ -56,15 +58,17 @@  discard block
 block discarded – undo
56 58
 				'is_protected' => 1,
57 59
 			)
58 60
 		);
59
-		while ($row = $smcFunc['db_fetch_assoc']($request))
60
-			$protected_groups[] = $row['id_group'];
61
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
62
+					$protected_groups[] = $row['id_group'];
63
+		}
61 64
 		$smcFunc['db_free_result']($request);
62 65
 	}
63 66
 
64 67
 	// Make sure they don't delete protected groups!
65 68
 	$groups = array_diff($groups, array_unique($protected_groups));
66
-	if (empty($groups))
67
-		return 'no_group_found';
69
+	if (empty($groups)) {
70
+			return 'no_group_found';
71
+	}
68 72
 
69 73
 	// Make sure they don't try to delete a group attached to a paid subscription.
70 74
 	$subscriptions = array();
@@ -74,13 +78,14 @@  discard block
 block discarded – undo
74 78
 		ORDER BY name');
75 79
 	while ($row = $smcFunc['db_fetch_assoc']($request))
76 80
 	{
77
-		if (in_array($row['id_group'], $groups))
78
-			$subscriptions[] = $row['name'];
79
-		else
81
+		if (in_array($row['id_group'], $groups)) {
82
+					$subscriptions[] = $row['name'];
83
+		} else
80 84
 		{
81 85
 			$add_groups = explode(',', $row['add_groups']);
82
-			if (count(array_intersect($add_groups, $groups)) != 0)
83
-				$subscriptions[] = $row['name'];
86
+			if (count(array_intersect($add_groups, $groups)) != 0) {
87
+							$subscriptions[] = $row['name'];
88
+			}
84 89
 		}
85 90
 	}
86 91
 	$smcFunc['db_free_result']($request);
@@ -101,8 +106,9 @@  discard block
 block discarded – undo
101 106
 			'group_list' => $groups,
102 107
 		)
103 108
 	);
104
-	while ($row = $smcFunc['db_fetch_assoc']($request))
105
-		logAction('delete_group', array('group' => $row['group_name']), 'admin');
109
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
110
+			logAction('delete_group', array('group' => $row['group_name']), 'admin');
111
+	}
106 112
 	$smcFunc['db_free_result']($request);
107 113
 
108 114
 	call_integration_hook('integrate_delete_membergroups', array($groups));
@@ -187,12 +193,14 @@  discard block
 block discarded – undo
187 193
 		)
188 194
 	);
189 195
 	$updates = array();
190
-	while ($row = $smcFunc['db_fetch_assoc']($request))
191
-		$updates[$row['additional_groups']][] = $row['id_member'];
196
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
197
+			$updates[$row['additional_groups']][] = $row['id_member'];
198
+	}
192 199
 	$smcFunc['db_free_result']($request);
193 200
 
194
-	foreach ($updates as $additional_groups => $memberArray)
195
-		updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups))));
201
+	foreach ($updates as $additional_groups => $memberArray) {
202
+			updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups))));
203
+	}
196 204
 
197 205
 	// No boards can provide access to these membergroups anymore.
198 206
 	$request = $smcFunc['db_query']('', '
@@ -204,12 +212,13 @@  discard block
 block discarded – undo
204 212
 		)
205 213
 	);
206 214
 	$updates = array();
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$updates[$row['member_groups']][] = $row['id_board'];
215
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
216
+			$updates[$row['member_groups']][] = $row['id_board'];
217
+	}
209 218
 	$smcFunc['db_free_result']($request);
210 219
 
211
-	foreach ($updates as $member_groups => $boardArray)
212
-		$smcFunc['db_query']('', '
220
+	foreach ($updates as $member_groups => $boardArray) {
221
+			$smcFunc['db_query']('', '
213 222
 			UPDATE {db_prefix}boards
214 223
 			SET member_groups = {string:member_groups}
215 224
 			WHERE id_board IN ({array_int:board_lists})',
@@ -218,6 +227,7 @@  discard block
 block discarded – undo
218 227
 				'member_groups' => implode(',', array_diff(explode(',', $member_groups), $groups)),
219 228
 			)
220 229
 		);
230
+	}
221 231
 
222 232
 	// Recalculate the post groups, as they likely changed.
223 233
 	updateStats('postgroups');
@@ -225,8 +235,9 @@  discard block
 block discarded – undo
225 235
 	// Make a note of the fact that the cache may be wrong.
226 236
 	$settings_update = array('settings_updated' => time());
227 237
 	// Have we deleted the spider group?
228
-	if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups))
229
-		$settings_update['spider_group'] = 0;
238
+	if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) {
239
+			$settings_update['spider_group'] = 0;
240
+	}
230 241
 
231 242
 	updateSettings($settings_update);
232 243
 
@@ -250,22 +261,24 @@  discard block
 block discarded – undo
250 261
 	global $smcFunc, $modSettings, $sourcedir;
251 262
 
252 263
 	// You're getting nowhere without this permission, unless of course you are the group's moderator.
253
-	if (!$permissionCheckDone)
254
-		isAllowedTo('manage_membergroups');
264
+	if (!$permissionCheckDone) {
265
+			isAllowedTo('manage_membergroups');
266
+	}
255 267
 
256 268
 	// Assume something will happen.
257 269
 	updateSettings(array('settings_updated' => time()));
258 270
 
259 271
 	// Cleaning the input.
260
-	if (!is_array($members))
261
-		$members = array((int) $members);
262
-	else
272
+	if (!is_array($members)) {
273
+			$members = array((int) $members);
274
+	} else
263 275
 	{
264 276
 		$members = array_unique($members);
265 277
 
266 278
 		// Cast the members to integer.
267
-		foreach ($members as $key => $value)
268
-			$members[$key] = (int) $value;
279
+		foreach ($members as $key => $value) {
280
+					$members[$key] = (int) $value;
281
+		}
269 282
 	}
270 283
 
271 284
 	// Before we get started, let's check we won't leave the admin group empty!
@@ -277,14 +290,15 @@  discard block
 block discarded – undo
277 290
 		// Remove any admins if there are too many.
278 291
 		$non_changing_admins = array_diff(array_keys($admins), $members);
279 292
 
280
-		if (empty($non_changing_admins))
281
-			$members = array_diff($members, array_keys($admins));
293
+		if (empty($non_changing_admins)) {
294
+					$members = array_diff($members, array_keys($admins));
295
+		}
282 296
 	}
283 297
 
284 298
 	// Just in case.
285
-	if (empty($members))
286
-		return false;
287
-	elseif ($groups === null)
299
+	if (empty($members)) {
300
+			return false;
301
+	} elseif ($groups === null)
288 302
 	{
289 303
 		// Wanna remove all groups from these members? That's easy.
290 304
 		$smcFunc['db_query']('', '
@@ -306,20 +320,21 @@  discard block
 block discarded – undo
306 320
 		updateStats('postgroups', $members);
307 321
 
308 322
 		// Log what just happened.
309
-		foreach ($members as $member)
310
-			logAction('removed_all_groups', array('member' => $member), 'admin');
323
+		foreach ($members as $member) {
324
+					logAction('removed_all_groups', array('member' => $member), 'admin');
325
+		}
311 326
 
312 327
 		return true;
313
-	}
314
-	elseif (!is_array($groups))
315
-		$groups = array((int) $groups);
316
-	else
328
+	} elseif (!is_array($groups)) {
329
+			$groups = array((int) $groups);
330
+	} else
317 331
 	{
318 332
 		$groups = array_unique($groups);
319 333
 
320 334
 		// Make sure all groups are integer.
321
-		foreach ($groups as $key => $value)
322
-			$groups[$key] = (int) $value;
335
+		foreach ($groups as $key => $value) {
336
+					$groups[$key] = (int) $value;
337
+		}
323 338
 	}
324 339
 
325 340
 	// Fetch a list of groups members cannot be assigned to explicitly, and the group names of the ones we want.
@@ -335,10 +350,11 @@  discard block
 block discarded – undo
335 350
 	$group_names = array();
336 351
 	while ($row = $smcFunc['db_fetch_assoc']($request))
337 352
 	{
338
-		if ($row['min_posts'] != -1)
339
-			$implicitGroups[] = $row['id_group'];
340
-		else
341
-			$group_names[$row['id_group']] = $row['group_name'];
353
+		if ($row['min_posts'] != -1) {
354
+					$implicitGroups[] = $row['id_group'];
355
+		} else {
356
+					$group_names[$row['id_group']] = $row['group_name'];
357
+		}
342 358
 	}
343 359
 	$smcFunc['db_free_result']($request);
344 360
 
@@ -357,8 +373,9 @@  discard block
 block discarded – undo
357 373
 			)
358 374
 		);
359 375
 		$protected_groups = array(1);
360
-		while ($row = $smcFunc['db_fetch_assoc']($request))
361
-			$protected_groups[] = $row['id_group'];
376
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
377
+					$protected_groups[] = $row['id_group'];
378
+		}
362 379
 		$smcFunc['db_free_result']($request);
363 380
 
364 381
 		// If you're not an admin yourself, you can't touch protected groups!
@@ -366,8 +383,9 @@  discard block
 block discarded – undo
366 383
 	}
367 384
 
368 385
 	// Only continue if there are still groups and members left.
369
-	if (empty($groups) || empty($members))
370
-		return false;
386
+	if (empty($groups) || empty($members)) {
387
+			return false;
388
+	}
371 389
 
372 390
 	// First, reset those who have this as their primary group - this is the easy one.
373 391
 	$log_inserts = array();
@@ -381,8 +399,9 @@  discard block
 block discarded – undo
381 399
 			'member_list' => $members,
382 400
 		)
383 401
 	);
384
-	while ($row = $smcFunc['db_fetch_assoc']($request))
385
-		$log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']);
402
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
403
+			$log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']);
404
+	}
386 405
 	$smcFunc['db_free_result']($request);
387 406
 
388 407
 	$smcFunc['db_query']('', '
@@ -414,16 +433,17 @@  discard block
 block discarded – undo
414 433
 	while ($row = $smcFunc['db_fetch_assoc']($request))
415 434
 	{
416 435
 		// What log entries must we make for this one, eh?
417
-		foreach (explode(',', $row['additional_groups']) as $group)
418
-			if (in_array($group, $groups))
436
+		foreach (explode(',', $row['additional_groups']) as $group) {
437
+					if (in_array($group, $groups))
419 438
 				$log_inserts[] = array('group' => $group_names[$group], 'member' => $row['id_member']);
439
+		}
420 440
 
421 441
 		$updates[$row['additional_groups']][] = $row['id_member'];
422 442
 	}
423 443
 	$smcFunc['db_free_result']($request);
424 444
 
425
-	foreach ($updates as $additional_groups => $memberArray)
426
-		$smcFunc['db_query']('', '
445
+	foreach ($updates as $additional_groups => $memberArray) {
446
+			$smcFunc['db_query']('', '
427 447
 			UPDATE {db_prefix}members
428 448
 			SET additional_groups = {string:additional_groups}
429 449
 			WHERE id_member IN ({array_int:member_list})',
@@ -432,6 +452,7 @@  discard block
 block discarded – undo
432 452
 				'additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)),
433 453
 			)
434 454
 		);
455
+	}
435 456
 
436 457
 	// Their post groups may have changed now...
437 458
 	updateStats('postgroups', $members);
@@ -440,8 +461,9 @@  discard block
 block discarded – undo
440 461
 	if (!empty($log_inserts) && !empty($modSettings['modlog_enabled']))
441 462
 	{
442 463
 		require_once($sourcedir . '/Logging.php');
443
-		foreach ($log_inserts as $extra)
444
-			logAction('removed_from_group', $extra, 'admin');
464
+		foreach ($log_inserts as $extra) {
465
+					logAction('removed_from_group', $extra, 'admin');
466
+		}
445 467
 	}
446 468
 
447 469
 	// Mission successful.
@@ -477,21 +499,23 @@  discard block
 block discarded – undo
477 499
 	global $smcFunc, $sourcedir;
478 500
 
479 501
 	// Show your licence, but only if it hasn't been done yet.
480
-	if (!$permissionCheckDone)
481
-		isAllowedTo('manage_membergroups');
502
+	if (!$permissionCheckDone) {
503
+			isAllowedTo('manage_membergroups');
504
+	}
482 505
 
483 506
 	// Make sure we don't keep old stuff cached.
484 507
 	updateSettings(array('settings_updated' => time()));
485 508
 
486
-	if (!is_array($members))
487
-		$members = array((int) $members);
488
-	else
509
+	if (!is_array($members)) {
510
+			$members = array((int) $members);
511
+	} else
489 512
 	{
490 513
 		$members = array_unique($members);
491 514
 
492 515
 		// Make sure all members are integer.
493
-		foreach ($members as $key => $value)
494
-			$members[$key] = (int) $value;
516
+		foreach ($members as $key => $value) {
517
+					$members[$key] = (int) $value;
518
+		}
495 519
 	}
496 520
 	$group = (int) $group;
497 521
 
@@ -508,20 +532,23 @@  discard block
 block discarded – undo
508 532
 	$group_names = array();
509 533
 	while ($row = $smcFunc['db_fetch_assoc']($request))
510 534
 	{
511
-		if ($row['min_posts'] != -1)
512
-			$implicitGroups[] = $row['id_group'];
513
-		else
514
-			$group_names[$row['id_group']] = $row['group_name'];
535
+		if ($row['min_posts'] != -1) {
536
+					$implicitGroups[] = $row['id_group'];
537
+		} else {
538
+					$group_names[$row['id_group']] = $row['group_name'];
539
+		}
515 540
 	}
516 541
 	$smcFunc['db_free_result']($request);
517 542
 
518 543
 	// Sorry, you can't join an implicit group.
519
-	if (in_array($group, $implicitGroups) || empty($members))
520
-		return false;
544
+	if (in_array($group, $implicitGroups) || empty($members)) {
545
+			return false;
546
+	}
521 547
 
522 548
 	// Only admins can add admins...
523
-	if (!allowedTo('admin_forum') && $group == 1)
524
-		return false;
549
+	if (!allowedTo('admin_forum') && $group == 1) {
550
+			return false;
551
+	}
525 552
 	// ... and assign protected groups!
526 553
 	elseif (!allowedTo('admin_forum') && !$ignoreProtected)
527 554
 	{
@@ -539,13 +566,14 @@  discard block
 block discarded – undo
539 566
 		$smcFunc['db_free_result']($request);
540 567
 
541 568
 		// Is it protected?
542
-		if ($is_protected == 1)
543
-			return false;
569
+		if ($is_protected == 1) {
570
+					return false;
571
+		}
544 572
 	}
545 573
 
546 574
 	// Do the actual updates.
547
-	if ($type == 'only_additional')
548
-		$smcFunc['db_query']('', '
575
+	if ($type == 'only_additional') {
576
+			$smcFunc['db_query']('', '
549 577
 			UPDATE {db_prefix}members
550 578
 			SET additional_groups = CASE WHEN additional_groups = {string:blank_string} THEN {string:id_group_string} ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END
551 579
 			WHERE id_member IN ({array_int:member_list})
@@ -559,8 +587,8 @@  discard block
 block discarded – undo
559 587
 				'blank_string' => '',
560 588
 			)
561 589
 		);
562
-	elseif ($type == 'only_primary' || $type == 'force_primary')
563
-		$smcFunc['db_query']('', '
590
+	} elseif ($type == 'only_primary' || $type == 'force_primary') {
591
+			$smcFunc['db_query']('', '
564 592
 			UPDATE {db_prefix}members
565 593
 			SET id_group = {int:id_group}
566 594
 			WHERE id_member IN ({array_int:member_list})' . ($type == 'force_primary' ? '' : '
@@ -572,8 +600,8 @@  discard block
 block discarded – undo
572 600
 				'regular_group' => 0,
573 601
 			)
574 602
 		);
575
-	elseif ($type == 'auto')
576
-		$smcFunc['db_query']('', '
603
+	} elseif ($type == 'auto') {
604
+			$smcFunc['db_query']('', '
577 605
 			UPDATE {db_prefix}members
578 606
 			SET
579 607
 				id_group = CASE WHEN id_group = {int:regular_group} THEN {int:id_group} ELSE id_group END,
@@ -592,9 +620,11 @@  discard block
 block discarded – undo
592 620
 				'id_group_string_extend' => ',' . $group,
593 621
 			)
594 622
 		);
623
+	}
595 624
 	// Ack!!?  What happened?
596
-	else
597
-		trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING);
625
+	else {
626
+			trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING);
627
+	}
598 628
 
599 629
 	call_integration_hook('integrate_add_members_to_group', array($members, $group, &$group_names));
600 630
 
@@ -603,8 +633,9 @@  discard block
 block discarded – undo
603 633
 
604 634
 	// Log the data.
605 635
 	require_once($sourcedir . '/Logging.php');
606
-	foreach ($members as $member)
607
-		logAction('added_to_group', array('group' => $group_names[$group], 'member_affected' => $member), 'admin');
636
+	foreach ($members as $member) {
637
+			logAction('added_to_group', array('group' => $group_names[$group], 'member_affected' => $member), 'admin');
638
+	}
608 639
 
609 640
 	return true;
610 641
 }
@@ -632,8 +663,9 @@  discard block
 block discarded – undo
632 663
 		)
633 664
 	);
634 665
 	$members = array();
635
-	while ($row = $smcFunc['db_fetch_assoc']($request))
636
-		$members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
666
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
667
+			$members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
668
+	}
637 669
 	$smcFunc['db_free_result']($request);
638 670
 
639 671
 	// If there are more than $limit members, add a 'more' link.
@@ -641,10 +673,10 @@  discard block
 block discarded – undo
641 673
 	{
642 674
 		array_pop($members);
643 675
 		return true;
676
+	} else {
677
+			return false;
678
+	}
644 679
 	}
645
-	else
646
-		return false;
647
-}
648 680
 
649 681
 /**
650 682
  * Retrieve a list of (visible) membergroups used by the cache.
@@ -669,8 +701,9 @@  discard block
 block discarded – undo
669 701
 		)
670 702
 	);
671 703
 	$groupCache = array();
672
-	while ($row = $smcFunc['db_fetch_assoc']($request))
673
-		$groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
704
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
705
+			$groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
706
+	}
674 707
 	$smcFunc['db_free_result']($request);
675 708
 
676 709
 	return array(
@@ -716,8 +749,9 @@  discard block
 block discarded – undo
716 749
 	while ($row = $smcFunc['db_fetch_assoc']($request))
717 750
 	{
718 751
 		// We only list the groups they can see.
719
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
720
-			continue;
752
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
753
+					continue;
754
+		}
721 755
 
722 756
 		$row['icons'] = explode('#', $row['icons']);
723 757
 
@@ -752,12 +786,11 @@  discard block
 block discarded – undo
752 786
 					'group_list' => $group_ids,
753 787
 				)
754 788
 			);
755
-			while ($row = $smcFunc['db_fetch_assoc']($query))
756
-				$groups[$row['id_group']]['num_members'] += $row['num_members'];
789
+			while ($row = $smcFunc['db_fetch_assoc']($query)) {
790
+							$groups[$row['id_group']]['num_members'] += $row['num_members'];
791
+			}
757 792
 			$smcFunc['db_free_result']($query);
758
-		}
759
-
760
-		else
793
+		} else
761 794
 		{
762 795
 			$query = $smcFunc['db_query']('', '
763 796
 				SELECT id_group, COUNT(*) AS num_members
@@ -768,8 +801,9 @@  discard block
 block discarded – undo
768 801
 					'group_list' => $group_ids,
769 802
 				)
770 803
 			);
771
-			while ($row = $smcFunc['db_fetch_assoc']($query))
772
-				$groups[$row['id_group']]['num_members'] += $row['num_members'];
804
+			while ($row = $smcFunc['db_fetch_assoc']($query)) {
805
+							$groups[$row['id_group']]['num_members'] += $row['num_members'];
806
+			}
773 807
 			$smcFunc['db_free_result']($query);
774 808
 
775 809
 			// Only do additional groups if we can moderate...
@@ -788,8 +822,9 @@  discard block
 block discarded – undo
788 822
 						'blank_string' => '',
789 823
 					)
790 824
 				);
791
-				while ($row = $smcFunc['db_fetch_assoc']($query))
792
-					$groups[$row['id_group']]['num_members'] += $row['num_members'];
825
+				while ($row = $smcFunc['db_fetch_assoc']($query)) {
826
+									$groups[$row['id_group']]['num_members'] += $row['num_members'];
827
+				}
793 828
 				$smcFunc['db_free_result']($query);
794 829
 			}
795 830
 		}
@@ -803,8 +838,9 @@  discard block
 block discarded – undo
803 838
 				'group_list' => $group_ids,
804 839
 			)
805 840
 		);
806
-		while ($row = $smcFunc['db_fetch_assoc']($query))
807
-			$groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
841
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
842
+					$groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
843
+		}
808 844
 		$smcFunc['db_free_result']($query);
809 845
 	}
810 846
 
@@ -813,8 +849,9 @@  discard block
 block discarded – undo
813 849
 	{
814 850
 		$sort_ascending = strpos($sort, 'DESC') === false;
815 851
 
816
-		foreach ($groups as $group)
817
-			$sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1;
852
+		foreach ($groups as $group) {
853
+					$sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1;
854
+		}
818 855
 
819 856
 		array_multisort($sort_array, $sort_ascending ? SORT_ASC : SORT_DESC, SORT_REGULAR, $groups);
820 857
 	}
Please login to merge, or discard this patch.
Sources/Logging.php 1 patch
Braces   +154 added lines, -111 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Truncate the GET array to a specified length
@@ -26,24 +27,28 @@  discard block
 block discarded – undo
26 27
 function truncateArray($arr, $max_length=1900)
27 28
 {
28 29
 	$curr_length = 0;
29
-	foreach ($arr as $key => $value)
30
-		if (is_array($value))
30
+	foreach ($arr as $key => $value) {
31
+			if (is_array($value))
31 32
 			foreach ($value as $key2 => $value2)
32 33
 				$curr_length += strlen ($value2);
33
-		else
34
-			$curr_length += strlen ($value);
35
-	if ($curr_length <= $max_length)
36
-		return $arr;
37
-	else
34
+	}
35
+		else {
36
+					$curr_length += strlen ($value);
37
+		}
38
+	if ($curr_length <= $max_length) {
39
+			return $arr;
40
+	} else
38 41
 	{
39 42
 		// Truncate each element's value to a reasonable length
40 43
 		$param_max = floor($max_length/count($arr));
41
-		foreach ($arr as $key => &$value)
42
-			if (is_array($value))
44
+		foreach ($arr as $key => &$value) {
45
+					if (is_array($value))
43 46
 				foreach ($value as $key2 => &$value2)
44 47
 					$value2 = substr($value2, 0, $param_max - strlen($key) - 5);
45
-			else
46
-				$value = substr($value, 0, $param_max - strlen($key) - 5);
48
+		}
49
+			else {
50
+							$value = substr($value, 0, $param_max - strlen($key) - 5);
51
+			}
47 52
 		return $arr;
48 53
 	}
49 54
 }
@@ -65,8 +70,9 @@  discard block
 block discarded – undo
65 70
 		// Don't update for every page - this isn't wholly accurate but who cares.
66 71
 		if ($topic)
67 72
 		{
68
-			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic)
69
-				$force = false;
73
+			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) {
74
+							$force = false;
75
+			}
70 76
 			$_SESSION['last_topic_id'] = $topic;
71 77
 		}
72 78
 	}
@@ -79,22 +85,24 @@  discard block
 block discarded – undo
79 85
 	}
80 86
 
81 87
 	// Don't mark them as online more than every so often.
82
-	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force)
83
-		return;
88
+	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) {
89
+			return;
90
+	}
84 91
 
85 92
 	if (!empty($modSettings['who_enabled']))
86 93
 	{
87 94
 		$encoded_get = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
88 95
 
89 96
 		// In the case of a dlattach action, session_var may not be set.
90
-		if (!isset($context['session_var']))
91
-			$context['session_var'] = $_SESSION['session_var'];
97
+		if (!isset($context['session_var'])) {
98
+					$context['session_var'] = $_SESSION['session_var'];
99
+		}
92 100
 
93 101
 		unset($encoded_get['sesc'], $encoded_get[$context['session_var']]);
94 102
 		$encoded_get = $smcFunc['json_encode']($encoded_get);
103
+	} else {
104
+			$encoded_get = '';
95 105
 	}
96
-	else
97
-		$encoded_get = '';
98 106
 
99 107
 	// Guests use 0, members use their session ID.
100 108
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
@@ -134,17 +142,18 @@  discard block
 block discarded – undo
134 142
 		);
135 143
 
136 144
 		// Guess it got deleted.
137
-		if ($smcFunc['db_affected_rows']() == 0)
145
+		if ($smcFunc['db_affected_rows']() == 0) {
146
+					$_SESSION['log_time'] = 0;
147
+		}
148
+	} else {
138 149
 			$_SESSION['log_time'] = 0;
139 150
 	}
140
-	else
141
-		$_SESSION['log_time'] = 0;
142 151
 
143 152
 	// Otherwise, we have to delete and insert.
144 153
 	if (empty($_SESSION['log_time']))
145 154
 	{
146
-		if ($do_delete || !empty($user_info['id']))
147
-			$smcFunc['db_query']('', '
155
+		if ($do_delete || !empty($user_info['id'])) {
156
+					$smcFunc['db_query']('', '
148 157
 				DELETE FROM {db_prefix}log_online
149 158
 				WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'),
150 159
 				array(
@@ -152,6 +161,7 @@  discard block
 block discarded – undo
152 161
 					'log_time' => time() - $modSettings['lastActive'] * 60,
153 162
 				)
154 163
 			);
164
+		}
155 165
 
156 166
 		$smcFunc['db_insert']($do_delete ? 'ignore' : 'replace',
157 167
 			'{db_prefix}log_online',
@@ -165,21 +175,24 @@  discard block
 block discarded – undo
165 175
 	$_SESSION['log_time'] = time();
166 176
 
167 177
 	// Well, they are online now.
168
-	if (empty($_SESSION['timeOnlineUpdated']))
169
-		$_SESSION['timeOnlineUpdated'] = time();
178
+	if (empty($_SESSION['timeOnlineUpdated'])) {
179
+			$_SESSION['timeOnlineUpdated'] = time();
180
+	}
170 181
 
171 182
 	// Set their login time, if not already done within the last minute.
172 183
 	if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa'))))
173 184
 	{
174 185
 		// Don't count longer than 15 minutes.
175
-		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15)
176
-			$_SESSION['timeOnlineUpdated'] = time();
186
+		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) {
187
+					$_SESSION['timeOnlineUpdated'] = time();
188
+		}
177 189
 
178 190
 		$user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
179 191
 		updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in']));
180 192
 
181
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
182
-			cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
193
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
194
+					cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
195
+		}
183 196
 
184 197
 		$user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
185 198
 		$_SESSION['timeOnlineUpdated'] = time();
@@ -216,8 +229,7 @@  discard block
 block discarded – undo
216 229
 			// Oops. maybe we have no more disk space left, or some other troubles, troubles...
217 230
 			// Copy the file back and run for your life!
218 231
 			@copy($cachedir . '/db_last_error_bak.php', $cachedir . '/db_last_error.php');
219
-		}
220
-		else
232
+		} else
221 233
 		{
222 234
 			@touch($boarddir . '/' . 'Settings.php');
223 235
 			return true;
@@ -237,22 +249,27 @@  discard block
 block discarded – undo
237 249
 	global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt;
238 250
 
239 251
 	// Add to Settings.php if you want to show the debugging information.
240
-	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery'))
241
-		return;
252
+	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) {
253
+			return;
254
+	}
242 255
 
243
-	if (empty($_SESSION['view_queries']))
244
-		$_SESSION['view_queries'] = 0;
245
-	if (empty($context['debug']['language_files']))
246
-		$context['debug']['language_files'] = array();
247
-	if (empty($context['debug']['sheets']))
248
-		$context['debug']['sheets'] = array();
256
+	if (empty($_SESSION['view_queries'])) {
257
+			$_SESSION['view_queries'] = 0;
258
+	}
259
+	if (empty($context['debug']['language_files'])) {
260
+			$context['debug']['language_files'] = array();
261
+	}
262
+	if (empty($context['debug']['sheets'])) {
263
+			$context['debug']['sheets'] = array();
264
+	}
249 265
 
250 266
 	$files = get_included_files();
251 267
 	$total_size = 0;
252 268
 	for ($i = 0, $n = count($files); $i < $n; $i++)
253 269
 	{
254
-		if (file_exists($files[$i]))
255
-			$total_size += filesize($files[$i]);
270
+		if (file_exists($files[$i])) {
271
+					$total_size += filesize($files[$i]);
272
+		}
256 273
 		$files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)'));
257 274
 	}
258 275
 
@@ -261,8 +278,9 @@  discard block
 block discarded – undo
261 278
 	{
262 279
 		foreach ($db_cache as $q => $query_data)
263 280
 		{
264
-			if (!empty($query_data['w']))
265
-				$warnings += count($query_data['w']);
281
+			if (!empty($query_data['w'])) {
282
+							$warnings += count($query_data['w']);
283
+			}
266 284
 		}
267 285
 
268 286
 		$_SESSION['debug'] = &$db_cache;
@@ -283,12 +301,14 @@  discard block
 block discarded – undo
283 301
 	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),'
284 302
 	', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>';
285 303
 
286
-	if (function_exists('memory_get_peak_usage'))
287
-		echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
304
+	if (function_exists('memory_get_peak_usage')) {
305
+			echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
306
+	}
288 307
 
289 308
 	// What tokens are active?
290
-	if (isset($_SESSION['token']))
291
-		echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
309
+	if (isset($_SESSION['token'])) {
310
+			echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
311
+	}
292 312
 
293 313
 	if (!empty($modSettings['cache_enable']) && !empty($cache_hits))
294 314
 	{
@@ -302,10 +322,12 @@  discard block
 block discarded – undo
302 322
 			$total_t += $cache_hit['t'];
303 323
 			$total_s += $cache_hit['s'];
304 324
 		}
305
-		if (!isset($cache_misses))
306
-			$cache_misses = array();
307
-		foreach ($cache_misses as $missed)
308
-			$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
325
+		if (!isset($cache_misses)) {
326
+					$cache_misses = array();
327
+		}
328
+		foreach ($cache_misses as $missed) {
329
+					$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
330
+		}
309 331
 
310 332
 		echo '
311 333
 	', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br>
@@ -316,38 +338,44 @@  discard block
 block discarded – undo
316 338
 	<a href="', $scripturl, '?action=viewquery" target="_blank" rel="noopener">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br>
317 339
 	<br>';
318 340
 
319
-	if ($_SESSION['view_queries'] == 1 && !empty($db_cache))
320
-		foreach ($db_cache as $q => $query_data)
341
+	if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) {
342
+			foreach ($db_cache as $q => $query_data)
321 343
 		{
322 344
 			$is_select = strpos(trim($query_data['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($query_data['q'])) != 0;
345
+	}
323 346
 			// Temporary tables created in earlier queries are not explainable.
324 347
 			if ($is_select)
325 348
 			{
326
-				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp)
327
-					if (strpos(trim($query_data['q']), $tmp) !== false)
349
+				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) {
350
+									if (strpos(trim($query_data['q']), $tmp) !== false)
328 351
 					{
329 352
 						$is_select = false;
353
+				}
330 354
 						break;
331 355
 					}
332 356
 			}
333 357
 			// But actual creation of the temporary tables are.
334
-			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0)
335
-				$is_select = true;
358
+			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0) {
359
+							$is_select = true;
360
+			}
336 361
 
337 362
 			// Make the filenames look a bit better.
338
-			if (isset($query_data['f']))
339
-				$query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']);
363
+			if (isset($query_data['f'])) {
364
+							$query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']);
365
+			}
340 366
 
341 367
 			echo '
342 368
 	<strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" rel="noopener" style="text-decoration: none;">' : '', nl2br(str_replace("\t", '&nbsp;&nbsp;&nbsp;', $smcFunc['htmlspecialchars'](ltrim($query_data['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br>
343 369
 	&nbsp;&nbsp;&nbsp;';
344
-			if (!empty($query_data['f']) && !empty($query_data['l']))
345
-				echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']);
370
+			if (!empty($query_data['f']) && !empty($query_data['l'])) {
371
+							echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']);
372
+			}
346 373
 
347
-			if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at']))
348
-				echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>';
349
-			elseif (isset($query_data['t']))
350
-				echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>';
374
+			if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) {
375
+							echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>';
376
+			} elseif (isset($query_data['t'])) {
377
+							echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>';
378
+			}
351 379
 			echo '
352 380
 	<br>';
353 381
 		}
@@ -372,12 +400,14 @@  discard block
 block discarded – undo
372 400
 	global $modSettings, $smcFunc;
373 401
 	static $cache_stats = array();
374 402
 
375
-	if (empty($modSettings['trackStats']))
376
-		return false;
377
-	if (!empty($stats))
378
-		return $cache_stats = array_merge($cache_stats, $stats);
379
-	elseif (empty($cache_stats))
380
-		return false;
403
+	if (empty($modSettings['trackStats'])) {
404
+			return false;
405
+	}
406
+	if (!empty($stats)) {
407
+			return $cache_stats = array_merge($cache_stats, $stats);
408
+	} elseif (empty($cache_stats)) {
409
+			return false;
410
+	}
381 411
 
382 412
 	$setStringUpdate = '';
383 413
 	$insert_keys = array();
@@ -390,10 +420,11 @@  discard block
 block discarded – undo
390 420
 		$setStringUpdate .= '
391 421
 			' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ',';
392 422
 
393
-		if ($change === '+')
394
-			$cache_stats[$field] = 1;
395
-		else
396
-			$update_parameters[$field] = $change;
423
+		if ($change === '+') {
424
+					$cache_stats[$field] = 1;
425
+		} else {
426
+					$update_parameters[$field] = $change;
427
+		}
397 428
 		$insert_keys[$field] = 'int';
398 429
 	}
399 430
 
@@ -457,43 +488,50 @@  discard block
 block discarded – undo
457 488
 	);
458 489
 
459 490
 	// Make sure this particular log is enabled first...
460
-	if (empty($modSettings['modlog_enabled']))
461
-		unset ($log_types['moderate']);
462
-	if (empty($modSettings['userlog_enabled']))
463
-		unset ($log_types['user']);
464
-	if (empty($modSettings['adminlog_enabled']))
465
-		unset ($log_types['admin']);
491
+	if (empty($modSettings['modlog_enabled'])) {
492
+			unset ($log_types['moderate']);
493
+	}
494
+	if (empty($modSettings['userlog_enabled'])) {
495
+			unset ($log_types['user']);
496
+	}
497
+	if (empty($modSettings['adminlog_enabled'])) {
498
+			unset ($log_types['admin']);
499
+	}
466 500
 
467 501
 	call_integration_hook('integrate_log_types', array(&$log_types));
468 502
 
469 503
 	foreach ($logs as $log)
470 504
 	{
471
-		if (!isset($log_types[$log['log_type']]))
472
-			return false;
505
+		if (!isset($log_types[$log['log_type']])) {
506
+					return false;
507
+		}
473 508
 
474
-		if (!is_array($log['extra']))
475
-			trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
509
+		if (!is_array($log['extra'])) {
510
+					trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
511
+		}
476 512
 
477 513
 		// Pull out the parts we want to store separately, but also make sure that the data is proper
478 514
 		if (isset($log['extra']['topic']))
479 515
 		{
480
-			if (!is_numeric($log['extra']['topic']))
481
-				trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
516
+			if (!is_numeric($log['extra']['topic'])) {
517
+							trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
518
+			}
482 519
 			$topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic'];
483 520
 			unset($log['extra']['topic']);
521
+		} else {
522
+					$topic_id = 0;
484 523
 		}
485
-		else
486
-			$topic_id = 0;
487 524
 
488 525
 		if (isset($log['extra']['message']))
489 526
 		{
490
-			if (!is_numeric($log['extra']['message']))
491
-				trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
527
+			if (!is_numeric($log['extra']['message'])) {
528
+							trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
529
+			}
492 530
 			$msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message'];
493 531
 			unset($log['extra']['message']);
532
+		} else {
533
+					$msg_id = 0;
494 534
 		}
495
-		else
496
-			$msg_id = 0;
497 535
 
498 536
 		// @todo cache this?
499 537
 		// Is there an associated report on this?
@@ -520,23 +558,26 @@  discard block
 block discarded – undo
520 558
 			$smcFunc['db_free_result']($request);
521 559
 		}
522 560
 
523
-		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member']))
524
-			trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
561
+		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) {
562
+					trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
563
+		}
525 564
 
526 565
 		if (isset($log['extra']['board']))
527 566
 		{
528
-			if (!is_numeric($log['extra']['board']))
529
-				trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
567
+			if (!is_numeric($log['extra']['board'])) {
568
+							trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
569
+			}
530 570
 			$board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board'];
531 571
 			unset($log['extra']['board']);
572
+		} else {
573
+					$board_id = 0;
532 574
 		}
533
-		else
534
-			$board_id = 0;
535 575
 
536 576
 		if (isset($log['extra']['board_to']))
537 577
 		{
538
-			if (!is_numeric($log['extra']['board_to']))
539
-				trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
578
+			if (!is_numeric($log['extra']['board_to'])) {
579
+							trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
580
+			}
540 581
 			if (empty($board_id))
541 582
 			{
542 583
 				$board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to'];
@@ -544,15 +585,17 @@  discard block
 block discarded – undo
544 585
 			}
545 586
 		}
546 587
 
547
-		if (isset($log['extra']['member_affected']))
548
-			$memID = $log['extra']['member_affected'];
549
-		else
550
-			$memID = $user_info['id'];
588
+		if (isset($log['extra']['member_affected'])) {
589
+					$memID = $log['extra']['member_affected'];
590
+		} else {
591
+					$memID = $user_info['id'];
592
+		}
551 593
 		
552
-		if (isset($user_info['ip']))
553
-			$memIP = $user_info['ip'];
554
-		else
555
-			$memIP = 'null';
594
+		if (isset($user_info['ip'])) {
595
+					$memIP = $user_info['ip'];
596
+		} else {
597
+					$memIP = 'null';
598
+		}
556 599
 
557 600
 		$inserts[] = array(
558 601
 			time(), $log_types[$log['log_type']], $memID, $memIP, $log['action'],
Please login to merge, or discard this patch.
Sources/ManageLanguages.php 1 patch
Braces   +199 added lines, -149 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
  * This is the main function for the languages area.
@@ -150,11 +151,11 @@  discard block
 block discarded – undo
150 151
 	$language_list = new xmlArray(fetch_web_data($url), true);
151 152
 
152 153
 	// Check that the site responded and that the language exists.
153
-	if (!$language_list->exists('languages'))
154
-		$context['smf_error'] = 'no_response';
155
-	elseif (!$language_list->exists('languages/language'))
156
-		$context['smf_error'] = 'no_files';
157
-	else
154
+	if (!$language_list->exists('languages')) {
155
+			$context['smf_error'] = 'no_response';
156
+	} elseif (!$language_list->exists('languages/language')) {
157
+			$context['smf_error'] = 'no_files';
158
+	} else
158 159
 	{
159 160
 		$language_list = $language_list->path('languages[0]');
160 161
 		$lang_files = $language_list->set('language');
@@ -162,8 +163,9 @@  discard block
 block discarded – undo
162 163
 		foreach ($lang_files as $file)
163 164
 		{
164 165
 			// Were we searching?
165
-			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false)
166
-				continue;
166
+			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) {
167
+							continue;
168
+			}
167 169
 
168 170
 			$smf_languages[] = array(
169 171
 				'id' => $file->fetch('id'),
@@ -174,10 +176,11 @@  discard block
 block discarded – undo
174 176
 				'install_link' => '<a href="' . $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['add_language_smf_install'] . '</a>',
175 177
 			);
176 178
 		}
177
-		if (empty($smf_languages))
178
-			$context['smf_error'] = 'no_files';
179
-		else
180
-			return $smf_languages;
179
+		if (empty($smf_languages)) {
180
+					$context['smf_error'] = 'no_files';
181
+		} else {
182
+					return $smf_languages;
183
+		}
181 184
 	}
182 185
 }
183 186
 
@@ -199,8 +202,9 @@  discard block
 block discarded – undo
199 202
 	require_once($sourcedir . '/Subs-Package.php');
200 203
 
201 204
 	// Clearly we need to know what to request.
202
-	if (!isset($_GET['did']))
203
-		fatal_lang_error('no_access', false);
205
+	if (!isset($_GET['did'])) {
206
+			fatal_lang_error('no_access', false);
207
+	}
204 208
 
205 209
 	// Some lovely context.
206 210
 	$context['download_id'] = $_GET['did'];
@@ -220,8 +224,9 @@  discard block
 block discarded – undo
220 224
 		foreach ($_POST['copy_file'] as $file)
221 225
 		{
222 226
 			// Check it's not very bad.
223
-			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file)))
224
-				fatal_error($txt['languages_download_illegal_paths']);
227
+			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) {
228
+							fatal_error($txt['languages_download_illegal_paths']);
229
+			}
225 230
 
226 231
 			$chmod_files[] = $boarddir . '/' . $file;
227 232
 			$install_files[] = $file;
@@ -232,8 +237,9 @@  discard block
 block discarded – undo
232 237
 		$files_left = $file_status['files']['notwritable'];
233 238
 
234 239
 		// Something not writable?
235
-		if (!empty($files_left))
236
-			$context['error_message'] = $txt['languages_download_not_chmod'];
240
+		if (!empty($files_left)) {
241
+					$context['error_message'] = $txt['languages_download_not_chmod'];
242
+		}
237 243
 		// Otherwise, go go go!
238 244
 		elseif (!empty($install_files))
239 245
 		{
@@ -248,11 +254,13 @@  discard block
 block discarded – undo
248 254
 	}
249 255
 
250 256
 	// Open up the old china.
251
-	if (!isset($archive_content))
252
-		$archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
257
+	if (!isset($archive_content)) {
258
+			$archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
259
+	}
253 260
 
254
-	if (empty($archive_content))
255
-		fatal_error($txt['add_language_error_no_response']);
261
+	if (empty($archive_content)) {
262
+			fatal_error($txt['add_language_error_no_response']);
263
+	}
256 264
 
257 265
 	// Now for each of the files, let's do some *stuff*
258 266
 	$context['files'] = array(
@@ -267,8 +275,9 @@  discard block
 block discarded – undo
267 275
 		$extension = substr($filename, strrpos($filename, '.') + 1);
268 276
 
269 277
 		// Don't do anything with files we don't understand.
270
-		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt')))
271
-			continue;
278
+		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) {
279
+					continue;
280
+		}
272 281
 
273 282
 		// Basic data.
274 283
 		$context_data = array(
@@ -287,8 +296,9 @@  discard block
 block discarded – undo
287 296
 		// Does the file exist, is it different and can we overwrite?
288 297
 		if (file_exists($boarddir . '/' . $file['filename']))
289 298
 		{
290
-			if (is_writable($boarddir . '/' . $file['filename']))
291
-				$context_data['writable'] = true;
299
+			if (is_writable($boarddir . '/' . $file['filename'])) {
300
+							$context_data['writable'] = true;
301
+			}
292 302
 
293 303
 			// Finally, do we actually think the content has changed?
294 304
 			if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename']))
@@ -301,16 +311,17 @@  discard block
 block discarded – undo
301 311
 			{
302 312
 				$context_data['exists'] = 'same';
303 313
 				$context_data['default_copy'] = false;
314
+			} else {
315
+							$context_data['exists'] = 'different';
304 316
 			}
305
-			else
306
-				$context_data['exists'] = 'different';
307 317
 		}
308 318
 		// No overwrite?
309 319
 		else
310 320
 		{
311 321
 			// Can we at least stick it in the directory...
312
-			if (is_writable($boarddir . '/' . $dirname))
313
-				$context_data['writable'] = true;
322
+			if (is_writable($boarddir . '/' . $dirname)) {
323
+							$context_data['writable'] = true;
324
+			}
314 325
 		}
315 326
 
316 327
 		// I love PHP files, that's why I'm a developer and not an artistic type spending my time drinking absinth and living a life of sin...
@@ -325,8 +336,9 @@  discard block
 block discarded – undo
325 336
 			list ($name, $language) = explode('.', $filename);
326 337
 
327 338
 			// Let's get the new version, I like versions, they tell me that I'm up to date.
328
-			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1)
329
-				$context_data['version'] = $match[1];
339
+			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) {
340
+							$context_data['version'] = $match[1];
341
+			}
330 342
 
331 343
 			// Now does the old file exist - if so what is it's version?
332 344
 			if (file_exists($boarddir . '/' . $file['filename']))
@@ -342,34 +354,35 @@  discard block
 block discarded – undo
342 354
 					$context_data['cur_version'] = $match[1];
343 355
 
344 356
 					// How does this compare?
345
-					if ($context_data['cur_version'] == $context_data['version'])
346
-						$context_data['version_compare'] = 'same';
347
-					elseif ($context_data['cur_version'] > $context_data['version'])
348
-						$context_data['version_compare'] = 'older';
357
+					if ($context_data['cur_version'] == $context_data['version']) {
358
+											$context_data['version_compare'] = 'same';
359
+					} elseif ($context_data['cur_version'] > $context_data['version']) {
360
+											$context_data['version_compare'] = 'older';
361
+					}
349 362
 
350 363
 					// Don't recommend copying if the version is the same.
351
-					if ($context_data['version_compare'] != 'newer')
352
-						$context_data['default_copy'] = false;
364
+					if ($context_data['version_compare'] != 'newer') {
365
+											$context_data['default_copy'] = false;
366
+					}
353 367
 				}
354 368
 			}
355 369
 
356 370
 			// Add the context data to the main set.
357 371
 			$context['files']['lang'][] = $context_data;
358
-		}
359
-		elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
372
+		} elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
360 373
 		{
361 374
 			// Registration agreement is a primary file
362 375
 			$context['files']['lang'][] = $context_data;
363
-		}
364
-		else
376
+		} else
365 377
 		{
366 378
 			// There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future
367 379
 			$context['files']['other'][] = $context_data;
368 380
 		}
369 381
 
370 382
 		// Collect together all non-writable areas.
371
-		if (!$context_data['writable'])
372
-			$context['make_writable'][] = $context_data['destination'];
383
+		if (!$context_data['writable']) {
384
+					$context['make_writable'][] = $context_data['destination'];
385
+		}
373 386
 	}
374 387
 
375 388
 	// Before we go to far can we make anything writable, eh, eh?
@@ -384,22 +397,24 @@  discard block
 block discarded – undo
384 397
 		{
385 398
 			if ($type == 'lang')
386 399
 			{
387
-				foreach ($data as $k => $file)
388
-					if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
400
+				foreach ($data as $k => $file) {
401
+									if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
389 402
 						$context['files'][$type][$k]['writable'] = true;
390
-			}
391
-			else
403
+				}
404
+			} else
392 405
 			{
393
-				foreach ($data as $theme => $files)
394
-					foreach ($files as $k => $file)
406
+				foreach ($data as $theme => $files) {
407
+									foreach ($files as $k => $file)
395 408
 						if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
396 409
 							$context['files'][$type][$theme][$k]['writable'] = true;
410
+				}
397 411
 			}
398 412
 		}
399 413
 
400 414
 		// Are we going to need more language stuff?
401
-		if (!empty($context['still_not_writable']))
402
-			loadLanguage('Packages');
415
+		if (!empty($context['still_not_writable'])) {
416
+					loadLanguage('Packages');
417
+		}
403 418
 	}
404 419
 
405 420
 	// This is the list for the main files.
@@ -612,12 +627,13 @@  discard block
 block discarded – undo
612 627
 	highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language) . '");', true);
613 628
 
614 629
 	// Display a warning if we cannot edit the default setting.
615
-	if (!is_writable($boarddir . '/Settings.php'))
616
-		$listOptions['additional_rows'][] = array(
630
+	if (!is_writable($boarddir . '/Settings.php')) {
631
+			$listOptions['additional_rows'][] = array(
617 632
 				'position' => 'after_title',
618 633
 				'value' => $txt['language_settings_writable'],
619 634
 				'class' => 'smalltext alert',
620 635
 			);
636
+	}
621 637
 
622 638
 	require_once($sourcedir . '/Subs-List.php');
623 639
 	createList($listOptions);
@@ -659,10 +675,11 @@  discard block
 block discarded – undo
659 675
 
660 676
 	// Put them back.
661 677
 	$settings['actual_theme_dir'] = $backup_actual_theme_dir;
662
-	if (!empty($backup_base_theme_dir))
663
-		$settings['base_theme_dir'] = $backup_base_theme_dir;
664
-	else
665
-		unset($settings['base_theme_dir']);
678
+	if (!empty($backup_base_theme_dir)) {
679
+			$settings['base_theme_dir'] = $backup_base_theme_dir;
680
+	} else {
681
+			unset($settings['base_theme_dir']);
682
+	}
666 683
 
667 684
 	// Get the language files and data...
668 685
 	foreach ($context['languages'] as $lang)
@@ -691,13 +708,15 @@  discard block
 block discarded – undo
691 708
 	while ($row = $smcFunc['db_fetch_assoc']($request))
692 709
 	{
693 710
 		// Default?
694
-		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']]))
695
-			$row['lngfile'] = $language;
711
+		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) {
712
+					$row['lngfile'] = $language;
713
+		}
696 714
 
697
-		if (!isset($languages[$row['lngfile']]) && isset($languages['english']))
698
-			$languages['english']['count'] += $row['num_users'];
699
-		elseif (isset($languages[$row['lngfile']]))
700
-			$languages[$row['lngfile']]['count'] += $row['num_users'];
715
+		if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) {
716
+					$languages['english']['count'] += $row['num_users'];
717
+		} elseif (isset($languages[$row['lngfile']])) {
718
+					$languages[$row['lngfile']]['count'] += $row['num_users'];
719
+		}
701 720
 	}
702 721
 	$smcFunc['db_free_result']($request);
703 722
 
@@ -737,13 +756,15 @@  discard block
 block discarded – undo
737 756
 
738 757
 	call_integration_hook('integrate_language_settings', array(&$config_vars));
739 758
 
740
-	if ($return_config)
741
-		return $config_vars;
759
+	if ($return_config) {
760
+			return $config_vars;
761
+	}
742 762
 
743 763
 	// Get our languages. No cache
744 764
 	getLanguages(false);
745
-	foreach ($context['languages'] as $lang)
746
-		$config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']);
765
+	foreach ($context['languages'] as $lang) {
766
+			$config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']);
767
+	}
747 768
 
748 769
 	// Saving settings?
749 770
 	if (isset($_REQUEST['save']))
@@ -753,8 +774,9 @@  discard block
 block discarded – undo
753 774
 		call_integration_hook('integrate_save_language_settings', array(&$config_vars));
754 775
 
755 776
 		saveSettings($config_vars);
756
-		if (!$settings_not_writable && !$settings_backup_fail)
757
-			$_SESSION['adm-save'] = true;
777
+		if (!$settings_not_writable && !$settings_backup_fail) {
778
+					$_SESSION['adm-save'] = true;
779
+		}
758 780
 		redirectexit('action=admin;area=languages;sa=settings');
759 781
 	}
760 782
 
@@ -763,10 +785,11 @@  discard block
 block discarded – undo
763 785
 	$context['settings_title'] = $txt['language_settings'];
764 786
 	$context['save_disabled'] = $settings_not_writable;
765 787
 
766
-	if ($settings_not_writable)
767
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
768
-	elseif ($settings_backup_fail)
769
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
788
+	if ($settings_not_writable) {
789
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
790
+	} elseif ($settings_backup_fail) {
791
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
792
+	}
770 793
 
771 794
 	// Fill the config array.
772 795
 	prepareServerSettingsContext($config_vars);
@@ -813,8 +836,9 @@  discard block
 block discarded – undo
813 836
 			'theme_dir' => $settings['default_theme_dir'],
814 837
 		),
815 838
 	);
816
-	while ($row = $smcFunc['db_fetch_assoc']($request))
817
-		$themes[$row['id_theme']][$row['variable']] = $row['value'];
839
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
840
+			$themes[$row['id_theme']][$row['variable']] = $row['value'];
841
+	}
818 842
 	$smcFunc['db_free_result']($request);
819 843
 
820 844
 	// This will be where we look
@@ -841,14 +865,16 @@  discard block
 block discarded – undo
841 865
 	// Check we have themes with a path and a name - just in case - and add the path.
842 866
 	foreach ($themes as $id => $data)
843 867
 	{
844
-		if (count($data) != 2)
845
-			unset($themes[$id]);
846
-		elseif (is_dir($data['theme_dir'] . '/languages'))
847
-			$lang_dirs[$id] = $data['theme_dir'] . '/languages';
868
+		if (count($data) != 2) {
869
+					unset($themes[$id]);
870
+		} elseif (is_dir($data['theme_dir'] . '/languages')) {
871
+					$lang_dirs[$id] = $data['theme_dir'] . '/languages';
872
+		}
848 873
 
849 874
 		// How about image directories?
850
-		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id']))
851
-			$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
875
+		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) {
876
+					$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
877
+		}
852 878
 	}
853 879
 
854 880
 	$current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : '';
@@ -862,15 +888,17 @@  discard block
 block discarded – undo
862 888
 		while ($entry = $dir->read())
863 889
 		{
864 890
 			// We're only after the files for this language.
865
-			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0)
866
-				continue;
891
+			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) {
892
+							continue;
893
+			}
867 894
 
868
-			if (!isset($context['possible_files'][$theme]))
869
-				$context['possible_files'][$theme] = array(
895
+			if (!isset($context['possible_files'][$theme])) {
896
+							$context['possible_files'][$theme] = array(
870 897
 					'id' => $theme,
871 898
 					'name' => $themes[$theme]['name'],
872 899
 					'files' => array(),
873 900
 				);
901
+			}
874 902
 
875 903
 			$context['possible_files'][$theme]['files'][] = array(
876 904
 				'id' => $matches[1],
@@ -899,31 +927,36 @@  discard block
 block discarded – undo
899 927
 		{
900 928
 			$_SESSION['last_backup_for'] = $context['lang_id'] . '$$$';
901 929
 			$result = package_create_backup('backup_lang_' . $context['lang_id']);
902
-			if (!$result)
903
-				fatal_lang_error('could_not_language_backup', false);
930
+			if (!$result) {
931
+							fatal_lang_error('could_not_language_backup', false);
932
+			}
904 933
 		}
905 934
 
906 935
 		// Second, loop through the array to remove the files.
907 936
 		foreach ($lang_dirs as $curPath)
908 937
 		{
909
-			foreach ($context['possible_files'][1]['files'] as $lang)
910
-				if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
938
+			foreach ($context['possible_files'][1]['files'] as $lang) {
939
+							if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
911 940
 					unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php');
941
+			}
912 942
 
913 943
 			// Check for the email template.
914
-			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'))
915
-				unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
944
+			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) {
945
+							unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
946
+			}
916 947
 		}
917 948
 
918 949
 		// Third, the agreement file.
919
-		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt'))
920
-			unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
950
+		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) {
951
+					unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
952
+		}
921 953
 
922 954
 		// Fourth, a related images folder, if it exists...
923
-		if (!empty($images_dirs))
924
-			foreach ($images_dirs as $curPath)
955
+		if (!empty($images_dirs)) {
956
+					foreach ($images_dirs as $curPath)
925 957
 				if (is_dir($curPath))
926 958
 					deltree($curPath);
959
+		}
927 960
 
928 961
 		// Members can no longer use this language.
929 962
 		$smcFunc['db_query']('', '
@@ -1010,13 +1043,14 @@  discard block
 block discarded – undo
1010 1043
 			foreach ($_POST['edit'] as $k => $v)
1011 1044
 			{
1012 1045
 				// Only try to save if 'edit' was specified and if the string has changed
1013
-				if ($v == 'edit' && isset($_POST['entry'][$k]) && isset($_POST['comp'][$k]) && $_POST['entry'][$k] != $_POST['comp'][$k])
1014
-					$save_strings[$k] = cleanLangString($_POST['entry'][$k], false);
1046
+				if ($v == 'edit' && isset($_POST['entry'][$k]) && isset($_POST['comp'][$k]) && $_POST['entry'][$k] != $_POST['comp'][$k]) {
1047
+									$save_strings[$k] = cleanLangString($_POST['entry'][$k], false);
1048
+				}
1015 1049
 
1016 1050
 				// Record any add or remove requests. We'll decide on them later.
1017
-				elseif ($v == 'remove')
1018
-					$remove_strings[] = $k;
1019
-				elseif ($v == 'add' && isset($_POST['entry'][$k]))
1051
+				elseif ($v == 'remove') {
1052
+									$remove_strings[] = $k;
1053
+				} elseif ($v == 'add' && isset($_POST['entry'][$k]))
1020 1054
 				{
1021 1055
 					$add_strings[$k] = array(
1022 1056
 						'group' => isset($_POST['grp'][$k]) ? $_POST['grp'][$k] : 'txt',
@@ -1056,8 +1090,9 @@  discard block
 block discarded – undo
1056 1090
 				{
1057 1091
 					$group = !empty($special_groups[$file_id][$matches[1]]) ? $special_groups[$file_id][$matches[1]] : $matches[1];
1058 1092
 
1059
-					if (isset($allows_add_remove[$file_id]['add']) && in_array($matches[1], $allows_add_remove[$file_id]['add']))
1060
-						$context['can_add_lang_entry'][$group] = true;
1093
+					if (isset($allows_add_remove[$file_id]['add']) && in_array($matches[1], $allows_add_remove[$file_id]['add'])) {
1094
+											$context['can_add_lang_entry'][$group] = true;
1095
+					}
1061 1096
 
1062 1097
 					$entries[$matches[2]] = array(
1063 1098
 						'type' => $matches[1],
@@ -1079,8 +1114,9 @@  discard block
 block discarded – undo
1079 1114
 			{
1080 1115
 				$group = !empty($special_groups[$file_id][$matches[1]]) ? $special_groups[$file_id][$matches[1]] : $matches[1];
1081 1116
 
1082
-				if (isset($allows_add_remove[$file_id]['add']) && in_array($matches[1], $allows_add_remove[$file_id]['add']))
1083
-					$context['can_add_lang_entry'][$group] = true;
1117
+				if (isset($allows_add_remove[$file_id]['add']) && in_array($matches[1], $allows_add_remove[$file_id]['add'])) {
1118
+									$context['can_add_lang_entry'][$group] = true;
1119
+				}
1084 1120
 
1085 1121
 				$entries[$matches[2]] = array(
1086 1122
 					'type' => $matches[1],
@@ -1100,8 +1136,9 @@  discard block
 block discarded – undo
1100 1136
 		{
1101 1137
 			// Ignore some things we set separately.
1102 1138
 			$ignore_files = array('lang_character_set', 'lang_locale', 'lang_dictionary', 'lang_spelling', 'lang_rtl');
1103
-			if (in_array($entryKey, $ignore_files))
1104
-				continue;
1139
+			if (in_array($entryKey, $ignore_files)) {
1140
+							continue;
1141
+			}
1105 1142
 
1106 1143
 			// These are arrays that need breaking out.
1107 1144
 			$arrays = array('days', 'days_short', 'months', 'months_titles', 'months_short');
@@ -1134,9 +1171,9 @@  discard block
 block discarded – undo
1134 1171
 					{
1135 1172
 						$save_cache['entries'][$cur_index] = strtr($save_strings[$entryKey . '-+- ' . $cur_index], array('\'' => ''));
1136 1173
 						$save_cache['enabled'] = true;
1174
+					} else {
1175
+											$save_cache['entries'][$cur_index] = $subValue;
1137 1176
 					}
1138
-					else
1139
-						$save_cache['entries'][$cur_index] = $subValue;
1140 1177
 
1141 1178
 					$context['file_entries'][$entryValue['group']][] = array(
1142 1179
 						'key' => $entryKey . '-+- ' . $cur_index,
@@ -1159,9 +1196,9 @@  discard block
 block discarded – undo
1159 1196
 						{
1160 1197
 							$items[] = $k2 . ' => \'' . $v2 . '\'';
1161 1198
 							$cur_index = $k2;
1199
+						} else {
1200
+													$items[] = '\'' . $v2 . '\'';
1162 1201
 						}
1163
-						else
1164
-							$items[] = '\'' . $v2 . '\'';
1165 1202
 
1166 1203
 						$cur_index++;
1167 1204
 					}
@@ -1171,15 +1208,15 @@  discard block
 block discarded – undo
1171 1208
 						'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');',
1172 1209
 					);
1173 1210
 				}
1174
-			}
1175
-			else
1211
+			} else
1176 1212
 			{
1177 1213
 				// Saving?
1178 1214
 				if (isset($save_strings[$entryKey]) && $save_strings[$entryKey] != $entryValue['entry'])
1179 1215
 				{
1180 1216
 					// @todo Fix this properly.
1181
-					if ($save_strings[$entryKey] == '')
1182
-						$save_strings[$entryKey] = '\'\'';
1217
+					if ($save_strings[$entryKey] == '') {
1218
+											$save_strings[$entryKey] = '\'\'';
1219
+					}
1183 1220
 
1184 1221
 					// Set the new value.
1185 1222
 					$entryValue['entry'] = $save_strings[$entryKey];
@@ -1218,8 +1255,9 @@  discard block
 block discarded – undo
1218 1255
 			{
1219 1256
 				$type = isset($special_types[$string_val['group']]) ? $special_types[$string_val['group']] : $string_val['group'];
1220 1257
 
1221
-				if (!in_array($type, $allows_add_remove[$file_id]['add']))
1222
-					continue;
1258
+				if (!in_array($type, $allows_add_remove[$file_id]['add'])) {
1259
+									continue;
1260
+				}
1223 1261
 
1224 1262
 				$final_saves[$string_key] = array(
1225 1263
 					'find' => "\n\n?".'>',
@@ -1234,8 +1272,9 @@  discard block
 block discarded – undo
1234 1272
 			checkSession();
1235 1273
 
1236 1274
 			$file_contents = implode('', file($current_file));
1237
-			foreach ($final_saves as $save)
1238
-				$file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
1275
+			foreach ($final_saves as $save) {
1276
+							$file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
1277
+			}
1239 1278
 
1240 1279
 			// Save the actual changes.
1241 1280
 			$fp = fopen($current_file, 'w+');
@@ -1293,8 +1332,9 @@  discard block
 block discarded – undo
1293 1332
 	}
1294 1333
 
1295 1334
 	// If we saved, redirect.
1296
-	if ($madeSave)
1297
-		redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
1335
+	if ($madeSave) {
1336
+			redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
1337
+	}
1298 1338
 
1299 1339
 	createToken('admin-mlang');
1300 1340
 }
@@ -1326,8 +1366,9 @@  discard block
 block discarded – undo
1326 1366
 				// Toggle the escape.
1327 1367
 				$is_escape = !$is_escape;
1328 1368
 				// If we're now escaped don't add this string.
1329
-				if ($is_escape)
1330
-					continue;
1369
+				if ($is_escape) {
1370
+									continue;
1371
+				}
1331 1372
 			}
1332 1373
 			// Special case - parsed string with line break etc?
1333 1374
 			elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape)
@@ -1344,11 +1385,13 @@  discard block
 block discarded – undo
1344 1385
 				if ($in_string != 2 && ($in_string != 1 || !$is_escape))
1345 1386
 				{
1346 1387
 					// Is it the end of a single quote string?
1347
-					if ($in_string == 1)
1348
-						$in_string = 0;
1388
+					if ($in_string == 1) {
1389
+											$in_string = 0;
1390
+					}
1349 1391
 					// Otherwise it's the start!
1350
-					else
1351
-						$in_string = 1;
1392
+					else {
1393
+											$in_string = 1;
1394
+					}
1352 1395
 
1353 1396
 					// Don't actually include this character!
1354 1397
 					continue;
@@ -1361,19 +1404,22 @@  discard block
 block discarded – undo
1361 1404
 				if ($in_string != 1 && ($in_string != 2 || !$is_escape))
1362 1405
 				{
1363 1406
 					// Is it the end of a double quote string?
1364
-					if ($in_string == 2)
1365
-						$in_string = 0;
1407
+					if ($in_string == 2) {
1408
+											$in_string = 0;
1409
+					}
1366 1410
 					// Otherwise it's the start!
1367
-					else
1368
-						$in_string = 2;
1411
+					else {
1412
+											$in_string = 2;
1413
+					}
1369 1414
 
1370 1415
 					// Don't actually include this character!
1371 1416
 					continue;
1372 1417
 				}
1373 1418
 			}
1374 1419
 			// A join/space outside of a string is simply removed.
1375
-			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.'))
1376
-				continue;
1420
+			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) {
1421
+							continue;
1422
+			}
1377 1423
 			// Start of a variable?
1378 1424
 			elseif ($in_string == 0 && $string{$i} == '$')
1379 1425
 			{
@@ -1407,8 +1453,7 @@  discard block
 block discarded – undo
1407 1453
 
1408 1454
 		// Unhtml then rehtml the whole thing!
1409 1455
 		$new_string = $smcFunc['htmlspecialchars'](un_htmlspecialchars($new_string));
1410
-	}
1411
-	else
1456
+	} else
1412 1457
 	{
1413 1458
 		// Keep track of what we're doing...
1414 1459
 		$in_string = 0;
@@ -1437,10 +1482,11 @@  discard block
 block discarded – undo
1437 1482
 				preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches);
1438 1483
 				if (!empty($matches[1]))
1439 1484
 				{
1440
-					if ($in_string == 1)
1441
-						$new_string .= '\' . ';
1442
-					elseif ($new_string)
1443
-						$new_string .= ' . ';
1485
+					if ($in_string == 1) {
1486
+											$new_string .= '\' . ';
1487
+					} elseif ($new_string) {
1488
+											$new_string .= ' . ';
1489
+					}
1444 1490
 
1445 1491
 					$new_string .= $matches[1];
1446 1492
 					$i += strlen($matches[1]) + 3;
@@ -1453,8 +1499,9 @@  discard block
 block discarded – undo
1453 1499
 			elseif ($string{$i} == '<')
1454 1500
 			{
1455 1501
 				// Probably HTML?
1456
-				if ($string{$i + 1} != ' ')
1457
-					$in_html = true;
1502
+				if ($string{$i + 1} != ' ') {
1503
+									$in_html = true;
1504
+				}
1458 1505
 				// Assume we need an entity...
1459 1506
 				else
1460 1507
 				{
@@ -1466,8 +1513,9 @@  discard block
 block discarded – undo
1466 1513
 			elseif ($string{$i} == '>')
1467 1514
 			{
1468 1515
 				// Will it be HTML?
1469
-				if ($in_html)
1470
-					$in_html = false;
1516
+				if ($in_html) {
1517
+									$in_html = false;
1518
+				}
1471 1519
 				// Otherwise we need an entity...
1472 1520
 				else
1473 1521
 				{
@@ -1476,8 +1524,9 @@  discard block
 block discarded – undo
1476 1524
 				}
1477 1525
 			}
1478 1526
 			// Is it a slash? If so escape it...
1479
-			if ($string{$i} == '\\')
1480
-				$new_string .= '\\';
1527
+			if ($string{$i} == '\\') {
1528
+							$new_string .= '\\';
1529
+			}
1481 1530
 			// The infamous double quote?
1482 1531
 			elseif ($string{$i} == '"')
1483 1532
 			{
@@ -1500,10 +1549,11 @@  discard block
 block discarded – undo
1500 1549
 		}
1501 1550
 
1502 1551
 		// If we ended as a string then close it off.
1503
-		if ($in_string == 1)
1504
-			$new_string .= '\'';
1505
-		elseif ($in_string == 2)
1506
-			$new_string .= '"';
1552
+		if ($in_string == 1) {
1553
+					$new_string .= '\'';
1554
+		} elseif ($in_string == 2) {
1555
+					$new_string .= '"';
1556
+		}
1507 1557
 	}
1508 1558
 
1509 1559
 	return $new_string;
Please login to merge, or discard this patch.