Completed
Pull Request — release-2.1 (#3923)
by Fran
10:32
created
Themes/default/Calendar.template.php 1 patch
Braces   +152 added lines, -116 removed lines patch added patch discarded remove patch
@@ -40,16 +40,14 @@  discard block
 block discarded – undo
40 40
 				', template_show_upcoming_list('main'), '
41 41
 			</div>
42 42
 		';
43
-	}
44
-	elseif ($context['calendar_view'] == 'view_week')
43
+	} elseif ($context['calendar_view'] == 'view_week')
45 44
 	{
46 45
 		echo '
47 46
 			<div id="main_grid">
48 47
 				', template_show_week_grid('main'), '
49 48
 			</div>
50 49
 		';
51
-	}
52
-	else
50
+	} else
53 51
 	{
54 52
 		echo '
55 53
 			<div id="main_grid">
@@ -75,8 +73,9 @@  discard block
 block discarded – undo
75 73
 	global $context, $scripturl, $txt, $modSettings;
76 74
 
77 75
 	// Bail out if we have nothing to work with
78
-	if (!isset($context['calendar_grid_' . $grid_name]))
79
-		return false;
76
+	if (!isset($context['calendar_grid_' . $grid_name])) {
77
+			return false;
78
+	}
80 79
 
81 80
 	// Protect programmer sanity
82 81
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -113,11 +112,13 @@  discard block
 block discarded – undo
113 112
 					<li class="windowbg">
114 113
 						<b class="event_title">', $event['link'], '</b>';
115 114
 
116
-				if ($event['can_edit'])
117
-					echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
115
+				if ($event['can_edit']) {
116
+									echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
117
+				}
118 118
 
119
-				if ($event['can_export'])
120
-					echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
119
+				if ($event['can_export']) {
120
+									echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
121
+				}
121 122
 
122 123
 				echo '
123 124
 						<br>';
@@ -125,14 +126,14 @@  discard block
 block discarded – undo
125 126
 				if (!empty($event['allday']))
126 127
 				{
127 128
 					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : '';
128
-				}
129
-				else
129
+				} else
130 130
 				{
131 131
 					// Display event info relative to user's local timezone
132 132
 					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
133 133
 
134
-					if ($event['start_date_local'] != $event['end_date_local'])
135
-						echo trim($event['end_date_local']) . ', ';
134
+					if ($event['start_date_local'] != $event['end_date_local']) {
135
+											echo trim($event['end_date_local']) . ', ';
136
+					}
136 137
 
137 138
 					echo trim($event['end_time_local']);
138 139
 
@@ -141,23 +142,27 @@  discard block
 block discarded – undo
141 142
 					{
142 143
 						echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
143 144
 
144
-						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig'])
145
-							echo trim($event['start_date_orig']), ', ';
145
+						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) {
146
+													echo trim($event['start_date_orig']), ', ';
147
+						}
146 148
 
147 149
 						echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
148 150
 
149
-						if ($event['start_date_orig'] != $event['end_date_orig'])
150
-							echo trim($event['end_date_orig']) . ', ';
151
+						if ($event['start_date_orig'] != $event['end_date_orig']) {
152
+													echo trim($event['end_date_orig']) . ', ';
153
+						}
151 154
 
152 155
 						echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
153 156
 					}
154 157
 					// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
155
-					else
156
-						echo ' ', $event['tz_abbrev'], '</time>';
158
+					else {
159
+											echo ' ', $event['tz_abbrev'], '</time>';
160
+					}
157 161
 				}
158 162
 
159
-				if (!empty($event['location']))
160
-					echo '<br>', $event['location'];
163
+				if (!empty($event['location'])) {
164
+									echo '<br>', $event['location'];
165
+				}
161 166
 
162 167
 				echo '
163 168
 					</li>';
@@ -189,8 +194,9 @@  discard block
 block discarded – undo
189 194
 
190 195
 			$birthdays = array();
191 196
 
192
-			foreach ($date as $member)
193
-				$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
197
+			foreach ($date as $member) {
198
+							$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
199
+			}
194 200
 
195 201
 			echo implode(', ', $birthdays);
196 202
 
@@ -221,8 +227,9 @@  discard block
 block discarded – undo
221 227
 			$date_local = $date['date_local'];
222 228
 			unset($date['date_local']);
223 229
 
224
-			foreach ($date as $holiday)
225
-				$holidays[] = $holiday . ' (' . $date_local . ')';
230
+			foreach ($date as $holiday) {
231
+							$holidays[] = $holiday . ' (' . $date_local . ')';
232
+			}
226 233
 		}
227 234
 
228 235
 		echo implode(', ', $holidays);
@@ -245,17 +252,19 @@  discard block
 block discarded – undo
245 252
 	global $context, $settings, $txt, $scripturl, $modSettings;
246 253
 
247 254
 	// If the grid doesn't exist, no point in proceeding.
248
-	if (!isset($context['calendar_grid_' . $grid_name]))
249
-		return false;
255
+	if (!isset($context['calendar_grid_' . $grid_name])) {
256
+			return false;
257
+	}
250 258
 
251 259
 	// A handy little pointer variable.
252 260
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
253 261
 
254 262
 	// Some conditions for whether or not we should show the week links *here*.
255
-	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false)))
256
-		$show_week_links = true;
257
-	else
258
-		$show_week_links = false;
263
+	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) {
264
+			$show_week_links = true;
265
+	} else {
266
+			$show_week_links = false;
267
+	}
259 268
 
260 269
 	// Assuming that we've not disabled it, show the title block!
261 270
 	if (empty($calendar_data['disable_title']))
@@ -294,8 +303,9 @@  discard block
 block discarded – undo
294 303
 	}
295 304
 
296 305
 	// Show the controls on main grids
297
-	if ($is_mini === false)
298
-		template_calendar_top($calendar_data);
306
+	if ($is_mini === false) {
307
+			template_calendar_top($calendar_data);
308
+	}
299 309
 
300 310
 	// Finally, the main calendar table.
301 311
 	echo '<table class="calendar_table">';
@@ -306,8 +316,9 @@  discard block
 block discarded – undo
306 316
 		echo '<tr>';
307 317
 
308 318
 		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
309
-		if ($show_week_links === true)
310
-			echo '<th>&nbsp;</th>';
319
+		if ($show_week_links === true) {
320
+					echo '<th>&nbsp;</th>';
321
+		}
311 322
 
312 323
 		// Now, loop through each actual day of the week.
313 324
 		foreach ($calendar_data['week_days'] as $day)
@@ -354,27 +365,29 @@  discard block
 block discarded – undo
354 365
 				// Additional classes are given for events, holidays, and birthdays.
355 366
 				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
356 367
 				{
357
-					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3)))
358
-						$classes[] = 'events';
359
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3)))
360
-						$classes[] = 'events';
368
+					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) {
369
+											$classes[] = 'events';
370
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) {
371
+											$classes[] = 'events';
372
+					}
361 373
 				}
362 374
 				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
363 375
 				{
364
-					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3)))
365
-						$classes[] = 'holidays';
366
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3)))
367
-						$classes[] = 'holidays';
376
+					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) {
377
+											$classes[] = 'holidays';
378
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) {
379
+											$classes[] = 'holidays';
380
+					}
368 381
 				}
369 382
 				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
370 383
 				{
371
-					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3)))
372
-						$classes[] = 'birthdays';
373
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3)))
374
-						$classes[] = 'birthdays';
384
+					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) {
385
+											$classes[] = 'birthdays';
386
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) {
387
+											$classes[] = 'birthdays';
388
+					}
375 389
 				}
376
-			}
377
-			else
390
+			} else
378 391
 			{
379 392
 				// Default Classes (either compact or comfortable and disabled).
380 393
 				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
@@ -392,17 +405,19 @@  discard block
 block discarded – undo
392 405
 				$title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : '';
393 406
 
394 407
 				// The actual day number - be it a link, or just plain old text!
395
-				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
396
-					echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
397
-				else
398
-					echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
408
+				if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
409
+									echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
410
+				} else {
411
+									echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
412
+				}
399 413
 
400 414
 				// A lot of stuff, we're not showing on mini-calendars to conserve space.
401 415
 				if ($is_mini === false)
402 416
 				{
403 417
 					// Holidays are always fun, let's show them!
404
-					if (!empty($day['holidays']))
405
-						echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
418
+					if (!empty($day['holidays'])) {
419
+											echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
420
+					}
406 421
 
407 422
 					// Happy Birthday Dear, Member!
408 423
 					if (!empty($day['birthdays']))
@@ -420,14 +435,16 @@  discard block
 block discarded – undo
420 435
 							echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', ';
421 436
 
422 437
 							// 9...10! Let's stop there.
423
-							if ($birthday_count == 10 && $use_js_hide)
424
-								// !!TODO - Inline CSS and JavaScript should be moved.
438
+							if ($birthday_count == 10 && $use_js_hide) {
439
+															// !!TODO - Inline CSS and JavaScript should be moved.
425 440
 								echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').style.display = \'\'; document.getElementById(\'bdhidelink_', $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" style="display: none;">, ';
441
+							}
426 442
 
427 443
 							++$birthday_count;
428 444
 						}
429
-						if ($use_js_hide)
430
-							echo '</span>';
445
+						if ($use_js_hide) {
446
+													echo '</span>';
447
+						}
431 448
 
432 449
 						echo '</div>';
433 450
 					}
@@ -437,8 +454,9 @@  discard block
 block discarded – undo
437 454
 					{
438 455
 						// Sort events by start time (all day events will be listed first)
439 456
 						uasort($day['events'], function($a, $b) {
440
-						    if ($a['start_timestamp'] == $b['start_timestamp'])
441
-						        return 0;
457
+						    if ($a['start_timestamp'] == $b['start_timestamp']) {
458
+						    						        return 0;
459
+						    }
442 460
 						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
443 461
 						});
444 462
 
@@ -454,17 +472,19 @@  discard block
 block discarded – undo
454 472
 
455 473
 							echo '<div class="event_wrapper', $event['starts_today'] == true ? ' event_starts_today' : '', $event['ends_today'] == true ? ' event_ends_today' : '', $event['allday'] == true ? ' allday' : '', $event['is_selected'] ? ' sel_event' : '', '">', $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
456 474
 
457
-							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
458
-								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
459
-							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
460
-								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
461
-							elseif (!empty($event['allday']))
462
-								echo $txt['calendar_allday'];
475
+							if (!empty($event['start_time_local']) && $event['starts_today'] == true) {
476
+															echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
477
+							} elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) {
478
+															echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
479
+							} elseif (!empty($event['allday'])) {
480
+															echo $txt['calendar_allday'];
481
+							}
463 482
 
464 483
 							echo '</span>';
465 484
 
466
-							if (!empty($event['location']))
467
-								echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
485
+							if (!empty($event['location'])) {
486
+															echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
487
+							}
468 488
 
469 489
 							if ($event['can_edit'] || $event['can_export'])
470 490
 							{
@@ -501,10 +521,11 @@  discard block
 block discarded – undo
501 521
 			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
502 522
 			elseif ($is_mini === false)
503 523
 			{
504
-				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
505
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
506
-				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
507
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
524
+				if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) {
525
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
526
+				} elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) {
527
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
528
+				}
508 529
 			}
509 530
 
510 531
 			// Close this day and increase var count.
@@ -530,8 +551,9 @@  discard block
 block discarded – undo
530 551
 	global $context, $settings, $txt, $scripturl, $modSettings;
531 552
 
532 553
 	// We might have no reason to proceed, if the variable isn't there.
533
-	if (!isset($context['calendar_grid_' . $grid_name]))
534
-		return false;
554
+	if (!isset($context['calendar_grid_' . $grid_name])) {
555
+			return false;
556
+	}
535 557
 
536 558
 	// Handy pointer.
537 559
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -567,8 +589,9 @@  discard block
 block discarded – undo
567 589
 					}
568 590
 
569 591
 					// The Month Title + Week Number...
570
-					if (!empty($calendar_data['week_title']))
571
-							echo $calendar_data['week_title'];
592
+					if (!empty($calendar_data['week_title'])) {
593
+												echo $calendar_data['week_title'];
594
+					}
572 595
 
573 596
 					echo '
574 597
 					</h3>
@@ -607,10 +630,11 @@  discard block
 block discarded – undo
607 630
 						<tr class="days_wrapper">
608 631
 							<td class="', implode(' ', $classes), ' act_day">';
609 632
 							// Should the day number be a link?
610
-							if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
611
-								echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
612
-							else
613
-								echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
633
+							if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
634
+															echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
635
+							} else {
636
+															echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
637
+							}
614 638
 
615 639
 							echo '</td>
616 640
 							<td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', ' event_col" data-css-prefix="' . $txt['events'] . ' ', (empty($day['events']) && empty($context['can_post'])) ? $txt['none'] : '', '">';
@@ -619,8 +643,9 @@  discard block
 block discarded – undo
619 643
 							{
620 644
 								// Sort events by start time (all day events will be listed first)
621 645
 								uasort($day['events'], function($a, $b) {
622
-								    if ($a['start_timestamp'] == $b['start_timestamp'])
623
-								        return 0;
646
+								    if ($a['start_timestamp'] == $b['start_timestamp']) {
647
+								    								        return 0;
648
+								    }
624 649
 								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
625 650
 								});
626 651
 
@@ -632,15 +657,17 @@  discard block
 block discarded – undo
632 657
 
633 658
 									echo $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
634 659
 
635
-									if (!empty($event['start_time_local']))
636
-										echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
637
-									else
638
-										echo $txt['calendar_allday'];
660
+									if (!empty($event['start_time_local'])) {
661
+																			echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
662
+									} else {
663
+																			echo $txt['calendar_allday'];
664
+									}
639 665
 
640 666
 									echo '</span>';
641 667
 
642
-									if (!empty($event['location']))
643
-										echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
668
+									if (!empty($event['location'])) {
669
+																			echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
670
+									}
644 671
 
645 672
 									if (!empty($event_icons_needed))
646 673
 									{
@@ -677,8 +704,7 @@  discard block
 block discarded – undo
677 704
 									</div>
678 705
 									<br class="clear">';
679 706
 								}
680
-							}
681
-							else
707
+							} else
682 708
 							{
683 709
 								if (!empty($context['can_post']))
684 710
 								{
@@ -691,8 +717,9 @@  discard block
 block discarded – undo
691 717
 							echo '</td>
692 718
 							<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
693 719
 							// Show any holidays!
694
-							if (!empty($day['holidays']))
695
-								echo implode('<br>', $day['holidays']);
720
+							if (!empty($day['holidays'])) {
721
+															echo implode('<br>', $day['holidays']);
722
+							}
696 723
 
697 724
 							echo '</td>
698 725
 							<td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">';
@@ -750,8 +777,7 @@  discard block
 block discarded – undo
750 777
 				<input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="input_text date_input end" data-type="date">
751 778
 				<input type="submit" class="button_submit" style="float:none" id="view_button" value="', $txt['view'], '">
752 779
 			</form>';
753
-	}
754
-	else
780
+	} else
755 781
 	{
756 782
 		echo'
757 783
 			<form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '">
@@ -793,8 +819,9 @@  discard block
 block discarded – undo
793 819
 	echo '
794 820
 		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);smc_saveEntities(\'postevent\', [\'evtitle\']);" style="margin: 0;">';
795 821
 
796
-	if (!empty($context['event']['new']))
797
-		echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
822
+	if (!empty($context['event']['new'])) {
823
+			echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
824
+	}
798 825
 
799 826
 	// Start the main table.
800 827
 	echo '
@@ -844,9 +871,10 @@  discard block
 block discarded – undo
844 871
 		{
845 872
 			echo '
846 873
 								<optgroup label="', $category['name'], '">';
847
-			foreach ($category['boards'] as $board)
848
-				echo '
874
+			foreach ($category['boards'] as $board) {
875
+							echo '
849 876
 									<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
877
+			}
850 878
 			echo '
851 879
 								</optgroup>';
852 880
 		}
@@ -882,9 +910,10 @@  discard block
 block discarded – undo
882 910
 							<span class="label">', $txt['calendar_timezone'], '</span>
883 911
 							<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
884 912
 
885
-	foreach ($context['all_timezones'] as $tz => $tzname)
886
-		echo '
913
+	foreach ($context['all_timezones'] as $tz => $tzname) {
914
+			echo '
887 915
 								<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
916
+	}
888 917
 
889 918
 	echo '
890 919
 							</select>
@@ -899,9 +928,10 @@  discard block
 block discarded – undo
899 928
 	echo '
900 929
 				<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">';
901 930
 	// Delete button?
902
-	if (empty($context['event']['new']))
903
-		echo '
931
+	if (empty($context['event']['new'])) {
932
+			echo '
904 933
 				<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button_submit you_sure">';
934
+	}
905 935
 
906 936
 	echo '
907 937
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -945,9 +975,10 @@  discard block
 block discarded – undo
945 975
 
946 976
 		foreach ($context['clockicons'] as $t => $v)
947 977
 		{
948
-			foreach ($v as $i)
949
-				echo '
978
+			foreach ($v as $i) {
979
+							echo '
950 980
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
981
+			}
951 982
 		}
952 983
 
953 984
 		echo '
@@ -972,13 +1003,14 @@  discard block
 block discarded – undo
972 1003
 
973 1004
 		foreach ($context['clockicons'] as $t => $v)
974 1005
 		{
975
-			foreach ($v as $i)
976
-				echo '
1006
+			foreach ($v as $i) {
1007
+							echo '
977 1008
 			if (', $t, ' >= ', $i, ')
978 1009
 			{
979 1010
 				turnon.push("', $t, '_', $i, '");
980 1011
 				', $t, ' -= ', $i, ';
981 1012
 			}';
1013
+			}
982 1014
 		}
983 1015
 
984 1016
 		echo '
@@ -1042,9 +1074,10 @@  discard block
 block discarded – undo
1042 1074
 
1043 1075
 	foreach ($context['clockicons'] as $t => $v)
1044 1076
 	{
1045
-		foreach ($v as $i)
1046
-			echo '
1077
+		foreach ($v as $i) {
1078
+					echo '
1047 1079
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1080
+		}
1048 1081
 	}
1049 1082
 
1050 1083
 	echo '
@@ -1061,13 +1094,14 @@  discard block
 block discarded – undo
1061 1094
 
1062 1095
 	foreach ($context['clockicons'] as $t => $v)
1063 1096
 	{
1064
-		foreach ($v as $i)
1065
-			echo '
1097
+		foreach ($v as $i) {
1098
+					echo '
1066 1099
 		if (', $t, ' >= ', $i, ')
1067 1100
 		{
1068 1101
 			turnon.push("', $t, '_', $i, '");
1069 1102
 			', $t, ' -= ', $i, ';
1070 1103
 		}';
1104
+		}
1071 1105
 	}
1072 1106
 
1073 1107
 	echo '
@@ -1126,9 +1160,10 @@  discard block
 block discarded – undo
1126 1160
 
1127 1161
 	foreach ($context['clockicons'] as $t => $v)
1128 1162
 	{
1129
-		foreach ($v as $i)
1130
-			echo '
1163
+		foreach ($v as $i) {
1164
+					echo '
1131 1165
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1166
+		}
1132 1167
 	}
1133 1168
 
1134 1169
 	echo '
@@ -1149,13 +1184,14 @@  discard block
 block discarded – undo
1149 1184
 
1150 1185
 	foreach ($context['clockicons'] as $t => $v)
1151 1186
 	{
1152
-		foreach ($v as $i)
1153
-		echo '
1187
+		foreach ($v as $i) {
1188
+				echo '
1154 1189
 		if (', $t, ' >= ', $i, ')
1155 1190
 		{
1156 1191
 			turnon.push("', $t, '_', $i, '");
1157 1192
 			', $t, ' -= ', $i, ';
1158 1193
 		}';
1194
+		}
1159 1195
 	}
1160 1196
 
1161 1197
 	echo '
Please login to merge, or discard this patch.
Sources/ManageMaintenance.php 1 patch
Braces   +266 added lines, -197 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Main dispatcher, the maintenance access point.
@@ -96,14 +97,16 @@  discard block
 block discarded – undo
96 97
 	call_integration_hook('integrate_manage_maintenance', array(&$subActions));
97 98
 
98 99
 	// Yep, sub-action time!
99
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
100
-		$subAction = $_REQUEST['sa'];
101
-	else
102
-		$subAction = 'routine';
100
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
101
+			$subAction = $_REQUEST['sa'];
102
+	} else {
103
+			$subAction = 'routine';
104
+	}
103 105
 
104 106
 	// Doing something special?
105
-	if (isset($_REQUEST['activity']) && isset($subActions[$subAction]['activities'][$_REQUEST['activity']]))
106
-		$activity = $_REQUEST['activity'];
107
+	if (isset($_REQUEST['activity']) && isset($subActions[$subAction]['activities'][$_REQUEST['activity']])) {
108
+			$activity = $_REQUEST['activity'];
109
+	}
107 110
 
108 111
 	// Set a few things.
109 112
 	$context['page_title'] = $txt['maintain_title'];
@@ -114,12 +117,14 @@  discard block
 block discarded – undo
114 117
 	call_helper($subActions[$subAction]['function']);
115 118
 
116 119
 	// Any special activity?
117
-	if (isset($activity))
118
-		call_helper($subActions[$subAction]['activities'][$activity]);
120
+	if (isset($activity)) {
121
+			call_helper($subActions[$subAction]['activities'][$activity]);
122
+	}
119 123
 
120 124
 	//converted to UTF-8? show a small maintenance info
121
-	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8')
122
-		$context['maintenance_finished'] = $txt['utf8_title'];
125
+	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') {
126
+			$context['maintenance_finished'] = $txt['utf8_title'];
127
+	}
123 128
 
124 129
 	// Create a maintenance token.  Kinda hard to do it any other way.
125 130
 	createToken('admin-maint');
@@ -141,19 +146,22 @@  discard block
 block discarded – undo
141 146
 		db_extend('packages');
142 147
 
143 148
 		$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
144
-		foreach ($colData as $column)
145
-			if ($column['name'] == 'body')
149
+		foreach ($colData as $column) {
150
+					if ($column['name'] == 'body')
146 151
 				$body_type = $column['type'];
152
+		}
147 153
 
148 154
 		$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
149 155
 		$context['convert_to_suggest'] = ($body_type != 'text' && !empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] < 65536);
150 156
 	}
151 157
 
152
-	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8')
153
-		$context['maintenance_finished'] = $txt['utf8_title'];
154
-	if (isset($_GET['done']) && $_GET['done'] == 'convertentities')
155
-		$context['maintenance_finished'] = $txt['entity_convert_title'];
156
-}
158
+	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') {
159
+			$context['maintenance_finished'] = $txt['utf8_title'];
160
+	}
161
+	if (isset($_GET['done']) && $_GET['done'] == 'convertentities') {
162
+			$context['maintenance_finished'] = $txt['entity_convert_title'];
163
+	}
164
+	}
157 165
 
158 166
 /**
159 167
  * Supporting function for the routine maintenance area.
@@ -162,9 +170,10 @@  discard block
 block discarded – undo
162 170
 {
163 171
 	global $context, $txt;
164 172
 
165
-	if (isset($_GET['done']) && $_GET['done'] == 'recount')
166
-		$context['maintenance_finished'] = $txt['maintain_recount'];
167
-}
173
+	if (isset($_GET['done']) && $_GET['done'] == 'recount') {
174
+			$context['maintenance_finished'] = $txt['maintain_recount'];
175
+	}
176
+	}
168 177
 
169 178
 /**
170 179
  * Supporting function for the members maintenance area.
@@ -195,8 +204,9 @@  discard block
 block discarded – undo
195 204
 	}
196 205
 	$smcFunc['db_free_result']($result);
197 206
 
198
-	if (isset($_GET['done']) && $_GET['done'] == 'recountposts')
199
-		$context['maintenance_finished'] = $txt['maintain_recountposts'];
207
+	if (isset($_GET['done']) && $_GET['done'] == 'recountposts') {
208
+			$context['maintenance_finished'] = $txt['maintain_recountposts'];
209
+	}
200 210
 
201 211
 	loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
202 212
 }
@@ -222,11 +232,12 @@  discard block
 block discarded – undo
222 232
 	$context['categories'] = array();
223 233
 	while ($row = $smcFunc['db_fetch_assoc']($result))
224 234
 	{
225
-		if (!isset($context['categories'][$row['id_cat']]))
226
-			$context['categories'][$row['id_cat']] = array(
235
+		if (!isset($context['categories'][$row['id_cat']])) {
236
+					$context['categories'][$row['id_cat']] = array(
227 237
 				'name' => $row['cat_name'],
228 238
 				'boards' => array()
229 239
 			);
240
+		}
230 241
 
231 242
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
232 243
 			'id' => $row['id_board'],
@@ -239,11 +250,12 @@  discard block
 block discarded – undo
239 250
 	require_once($sourcedir . '/Subs-Boards.php');
240 251
 	sortCategories($context['categories']);
241 252
 
242
-	if (isset($_GET['done']) && $_GET['done'] == 'purgeold')
243
-		$context['maintenance_finished'] = $txt['maintain_old'];
244
-	elseif (isset($_GET['done']) && $_GET['done'] == 'massmove')
245
-		$context['maintenance_finished'] = $txt['move_topics_maintenance'];
246
-}
253
+	if (isset($_GET['done']) && $_GET['done'] == 'purgeold') {
254
+			$context['maintenance_finished'] = $txt['maintain_old'];
255
+	} elseif (isset($_GET['done']) && $_GET['done'] == 'massmove') {
256
+			$context['maintenance_finished'] = $txt['move_topics_maintenance'];
257
+	}
258
+	}
247 259
 
248 260
 /**
249 261
  * Find and fix all errors on the forum.
@@ -351,15 +363,17 @@  discard block
 block discarded – undo
351 363
 	// Show me your badge!
352 364
 	isAllowedTo('admin_forum');
353 365
 
354
-	if ($db_type != 'mysql')
355
-		return;
366
+	if ($db_type != 'mysql') {
367
+			return;
368
+	}
356 369
 
357 370
 	db_extend('packages');
358 371
 
359 372
 	$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
360
-	foreach ($colData as $column)
361
-		if ($column['name'] == 'body')
373
+	foreach ($colData as $column) {
374
+			if ($column['name'] == 'body')
362 375
 			$body_type = $column['type'];
376
+	}
363 377
 
364 378
 	$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
365 379
 
@@ -369,33 +383,36 @@  discard block
 block discarded – undo
369 383
 		validateToken('admin-maint');
370 384
 
371 385
 		// Make it longer so we can do their limit.
372
-		if ($body_type == 'text')
373
-			$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext'));
386
+		if ($body_type == 'text') {
387
+					$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext'));
388
+		}
374 389
 		// Shorten the column so we can have a bit (literally per record) less space occupied
375
-		else
376
-			$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text'));
390
+		else {
391
+					$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text'));
392
+		}
377 393
 
378 394
 		// 3rd party integrations may be interested in knowning about this.
379 395
 		call_integration_hook('integrate_convert_msgbody', array($body_type));
380 396
 
381 397
 		$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
382
-		foreach ($colData as $column)
383
-			if ($column['name'] == 'body')
398
+		foreach ($colData as $column) {
399
+					if ($column['name'] == 'body')
384 400
 				$body_type = $column['type'];
401
+		}
385 402
 
386 403
 		$context['maintenance_finished'] = $txt[$context['convert_to'] . '_title'];
387 404
 		$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
388 405
 		$context['convert_to_suggest'] = ($body_type != 'text' && !empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] < 65536);
389 406
 
390 407
 		return;
391
-	}
392
-	elseif ($body_type != 'text' && (!isset($_POST['do_conversion']) || isset($_POST['cont'])))
408
+	} elseif ($body_type != 'text' && (!isset($_POST['do_conversion']) || isset($_POST['cont'])))
393 409
 	{
394 410
 		checkSession();
395
-		if (empty($_REQUEST['start']))
396
-			validateToken('admin-maint');
397
-		else
398
-			validateToken('admin-convertMsg');
411
+		if (empty($_REQUEST['start'])) {
412
+					validateToken('admin-maint');
413
+		} else {
414
+					validateToken('admin-convertMsg');
415
+		}
399 416
 
400 417
 		$context['page_title'] = $txt['not_done_title'];
401 418
 		$context['continue_post_data'] = '';
@@ -427,8 +444,9 @@  discard block
 block discarded – undo
427 444
 					'increment' => $increment - 1,
428 445
 				)
429 446
 			);
430
-			while ($row = $smcFunc['db_fetch_assoc']($request))
431
-				$id_msg_exceeding[] = $row['id_msg'];
447
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
448
+							$id_msg_exceeding[] = $row['id_msg'];
449
+			}
432 450
 			$smcFunc['db_free_result']($request);
433 451
 
434 452
 			$_REQUEST['start'] += $increment;
@@ -457,9 +475,9 @@  discard block
 block discarded – undo
457 475
 			{
458 476
 				$query_msg = array_slice($id_msg_exceeding, 0, 100);
459 477
 				$context['exceeding_messages_morethan'] = sprintf($txt['exceeding_messages_morethan'], count($id_msg_exceeding));
478
+			} else {
479
+							$query_msg = $id_msg_exceeding;
460 480
 			}
461
-			else
462
-				$query_msg = $id_msg_exceeding;
463 481
 
464 482
 			$context['exceeding_messages'] = array();
465 483
 			$request = $smcFunc['db_query']('', '
@@ -470,8 +488,9 @@  discard block
 block discarded – undo
470 488
 					'messages' => $query_msg,
471 489
 				)
472 490
 			);
473
-			while ($row = $smcFunc['db_fetch_assoc']($request))
474
-				$context['exceeding_messages'][] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
491
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
492
+							$context['exceeding_messages'][] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
493
+			}
475 494
 			$smcFunc['db_free_result']($request);
476 495
 		}
477 496
 	}
@@ -495,8 +514,9 @@  discard block
 block discarded – undo
495 514
 	isAllowedTo('admin_forum');
496 515
 
497 516
 	// Check to see if UTF-8 is currently the default character set.
498
-	if ($modSettings['global_character_set'] !== 'UTF-8' || !isset($db_character_set) || $db_character_set !== 'utf8')
499
-		fatal_lang_error('entity_convert_only_utf8');
517
+	if ($modSettings['global_character_set'] !== 'UTF-8' || !isset($db_character_set) || $db_character_set !== 'utf8') {
518
+			fatal_lang_error('entity_convert_only_utf8');
519
+	}
500 520
 
501 521
 	// Some starting values.
502 522
 	$context['table'] = empty($_REQUEST['table']) ? 0 : (int) $_REQUEST['table'];
@@ -558,8 +578,9 @@  discard block
 block discarded – undo
558 578
 		// Make sure we keep stuff unique!
559 579
 		$primary_keys = array();
560 580
 
561
-		if (function_exists('apache_reset_timeout'))
562
-			@apache_reset_timeout();
581
+		if (function_exists('apache_reset_timeout')) {
582
+					@apache_reset_timeout();
583
+		}
563 584
 
564 585
 		// Get a list of text columns.
565 586
 		$columns = array();
@@ -570,9 +591,10 @@  discard block
 block discarded – undo
570 591
 				'cur_table' => $cur_table,
571 592
 			)
572 593
 		);
573
-		while ($column_info = $smcFunc['db_fetch_assoc']($request))
574
-			if (strpos($column_info['Type'], 'text') !== false || strpos($column_info['Type'], 'char') !== false)
594
+		while ($column_info = $smcFunc['db_fetch_assoc']($request)) {
595
+					if (strpos($column_info['Type'], 'text') !== false || strpos($column_info['Type'], 'char') !== false)
575 596
 				$columns[] = strtolower($column_info['Field']);
597
+		}
576 598
 
577 599
 		// Get the column with the (first) primary key.
578 600
 		$request = $smcFunc['db_query']('', '
@@ -586,8 +608,9 @@  discard block
 block discarded – undo
586 608
 		{
587 609
 			if ($row['Key_name'] === 'PRIMARY')
588 610
 			{
589
-				if (empty($primary_key) || ($row['Seq_in_index'] == 1 && !in_array(strtolower($row['Column_name']), $columns)))
590
-					$primary_key = $row['Column_name'];
611
+				if (empty($primary_key) || ($row['Seq_in_index'] == 1 && !in_array(strtolower($row['Column_name']), $columns))) {
612
+									$primary_key = $row['Column_name'];
613
+				}
591 614
 
592 615
 				$primary_keys[] = $row['Column_name'];
593 616
 			}
@@ -596,8 +619,9 @@  discard block
 block discarded – undo
596 619
 
597 620
 		// No primary key, no glory.
598 621
 		// Same for columns. Just to be sure we've work to do!
599
-		if (empty($primary_key) || empty($columns))
600
-			continue;
622
+		if (empty($primary_key) || empty($columns)) {
623
+					continue;
624
+		}
601 625
 
602 626
 		// Get the maximum value for the primary key.
603 627
 		$request = $smcFunc['db_query']('', '
@@ -611,8 +635,9 @@  discard block
 block discarded – undo
611 635
 		list($max_value) = $smcFunc['db_fetch_row']($request);
612 636
 		$smcFunc['db_free_result']($request);
613 637
 
614
-		if (empty($max_value))
615
-			continue;
638
+		if (empty($max_value)) {
639
+					continue;
640
+		}
616 641
 
617 642
 		while ($context['start'] <= $max_value)
618 643
 		{
@@ -636,10 +661,11 @@  discard block
 block discarded – undo
636 661
 			{
637 662
 				$insertion_variables = array();
638 663
 				$changes = array();
639
-				foreach ($row as $column_name => $column_value)
640
-					if ($column_name !== $primary_key && strpos($column_value, '&#') !== false)
664
+				foreach ($row as $column_name => $column_value) {
665
+									if ($column_name !== $primary_key && strpos($column_value, '&#') !== false)
641 666
 					{
642 667
 						$changes[] = $column_name . ' = {string:changes_' . $column_name . '}';
668
+				}
643 669
 						$insertion_variables['changes_' . $column_name] = preg_replace_callback('~&#(\d{1,7}|x[0-9a-fA-F]{1,6});~', 'fixchar__callback', $column_value);
644 670
 					}
645 671
 
@@ -651,8 +677,8 @@  discard block
 block discarded – undo
651 677
 				}
652 678
 
653 679
 				// Update the row.
654
-				if (!empty($changes))
655
-					$smcFunc['db_query']('', '
680
+				if (!empty($changes)) {
681
+									$smcFunc['db_query']('', '
656 682
 						UPDATE {db_prefix}' . $cur_table . '
657 683
 						SET
658 684
 							' . implode(',
@@ -660,6 +686,7 @@  discard block
 block discarded – undo
660 686
 						WHERE ' . implode(' AND ', $where),
661 687
 						$insertion_variables
662 688
 					);
689
+				}
663 690
 			}
664 691
 			$smcFunc['db_free_result']($request);
665 692
 			$context['start'] += 500;
@@ -704,10 +731,11 @@  discard block
 block discarded – undo
704 731
 
705 732
 	checkSession('request');
706 733
 
707
-	if (!isset($_SESSION['optimized_tables']))
708
-		validateToken('admin-maint');
709
-	else
710
-		validateToken('admin-optimize', 'post', false);
734
+	if (!isset($_SESSION['optimized_tables'])) {
735
+			validateToken('admin-maint');
736
+	} else {
737
+			validateToken('admin-optimize', 'post', false);
738
+	}
711 739
 
712 740
 	ignore_user_abort(true);
713 741
 	db_extend();
@@ -723,13 +751,15 @@  discard block
 block discarded – undo
723 751
 	// Get a list of tables, as well as how many there are.
724 752
 	$temp_tables = $smcFunc['db_list_tables'](false, $real_prefix . '%');
725 753
 	$tables = array();
726
-	foreach ($temp_tables as $table)
727
-		$tables[] = array('table_name' => $table);
754
+	foreach ($temp_tables as $table) {
755
+			$tables[] = array('table_name' => $table);
756
+	}
728 757
 
729 758
 	// If there aren't any tables then I believe that would mean the world has exploded...
730 759
 	$context['num_tables'] = count($tables);
731
-	if ($context['num_tables'] == 0)
732
-		fatal_error('You appear to be running SMF in a flat file mode... fantastic!', false);
760
+	if ($context['num_tables'] == 0) {
761
+			fatal_error('You appear to be running SMF in a flat file mode... fantastic!', false);
762
+	}
733 763
 
734 764
 	$_REQUEST['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
735 765
 
@@ -740,8 +770,9 @@  discard block
 block discarded – undo
740 770
 	$_SESSION['optimized_tables'] = !empty($_SESSION['optimized_tables']) ? $_SESSION['optimized_tables'] : array();
741 771
 	for ($key = $_REQUEST['start']; $context['num_tables'] - 1; $key++)
742 772
 	{
743
-		if (empty($tables[$key]))
744
-			break;
773
+		if (empty($tables[$key])) {
774
+					break;
775
+		}
745 776
 
746 777
 		// Continue?
747 778
 		if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 10)
@@ -755,8 +786,9 @@  discard block
 block discarded – undo
755 786
 			createToken('admin-optimize');
756 787
 			$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-optimize_token_var'] . '" value="' . $context['admin-optimize_token'] . '">';
757 788
 
758
-			if (function_exists('apache_reset_timeout'))
759
-				apache_reset_timeout();
789
+			if (function_exists('apache_reset_timeout')) {
790
+							apache_reset_timeout();
791
+			}
760 792
 
761 793
 			return;
762 794
 		}
@@ -764,11 +796,12 @@  discard block
 block discarded – undo
764 796
 		// Optimize the table!  We use backticks here because it might be a custom table.
765 797
 		$data_freed = $smcFunc['db_optimize_table']($tables[$key]['table_name']);
766 798
 
767
-		if ($data_freed > 0)
768
-			$_SESSION['optimized_tables'][] = array(
799
+		if ($data_freed > 0) {
800
+					$_SESSION['optimized_tables'][] = array(
769 801
 				'name' => $tables[$key]['table_name'],
770 802
 				'data_freed' => $data_freed,
771 803
 			);
804
+		}
772 805
 	}
773 806
 
774 807
 	// Number of tables, etc...
@@ -803,10 +836,11 @@  discard block
 block discarded – undo
803 836
 	checkSession('request');
804 837
 
805 838
 	// validate the request or the loop
806
-	if (!isset($_REQUEST['step']))
807
-		validateToken('admin-maint');
808
-	else
809
-		validateToken('admin-boardrecount');
839
+	if (!isset($_REQUEST['step'])) {
840
+			validateToken('admin-maint');
841
+	} else {
842
+			validateToken('admin-boardrecount');
843
+	}
810 844
 
811 845
 	$context['page_title'] = $txt['not_done_title'];
812 846
 	$context['continue_post_data'] = '';
@@ -827,8 +861,9 @@  discard block
 block discarded – undo
827 861
 	$smcFunc['db_free_result']($request);
828 862
 
829 863
 	$increment = min(max(50, ceil($max_topics / 4)), 2000);
830
-	if (empty($_REQUEST['start']))
831
-		$_REQUEST['start'] = 0;
864
+	if (empty($_REQUEST['start'])) {
865
+			$_REQUEST['start'] = 0;
866
+	}
832 867
 
833 868
 	$total_steps = 8;
834 869
 
@@ -855,8 +890,8 @@  discard block
 block discarded – undo
855 890
 					'max_id' => $_REQUEST['start'] + $increment,
856 891
 				)
857 892
 			);
858
-			while ($row = $smcFunc['db_fetch_assoc']($request))
859
-				$smcFunc['db_query']('', '
893
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
894
+							$smcFunc['db_query']('', '
860 895
 					UPDATE {db_prefix}topics
861 896
 					SET num_replies = {int:num_replies}
862 897
 					WHERE id_topic = {int:id_topic}',
@@ -865,6 +900,7 @@  discard block
 block discarded – undo
865 900
 						'id_topic' => $row['id_topic'],
866 901
 					)
867 902
 				);
903
+			}
868 904
 			$smcFunc['db_free_result']($request);
869 905
 
870 906
 			// Recount unapproved messages
@@ -883,8 +919,8 @@  discard block
 block discarded – undo
883 919
 					'max_id' => $_REQUEST['start'] + $increment,
884 920
 				)
885 921
 			);
886
-			while ($row = $smcFunc['db_fetch_assoc']($request))
887
-				$smcFunc['db_query']('', '
922
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
923
+							$smcFunc['db_query']('', '
888 924
 					UPDATE {db_prefix}topics
889 925
 					SET unapproved_posts = {int:unapproved_posts}
890 926
 					WHERE id_topic = {int:id_topic}',
@@ -893,6 +929,7 @@  discard block
 block discarded – undo
893 929
 						'id_topic' => $row['id_topic'],
894 930
 					)
895 931
 				);
932
+			}
896 933
 			$smcFunc['db_free_result']($request);
897 934
 
898 935
 			$_REQUEST['start'] += $increment;
@@ -915,8 +952,8 @@  discard block
 block discarded – undo
915 952
 	// Update the post count of each board.
916 953
 	if ($_REQUEST['step'] <= 1)
917 954
 	{
918
-		if (empty($_REQUEST['start']))
919
-			$smcFunc['db_query']('', '
955
+		if (empty($_REQUEST['start'])) {
956
+					$smcFunc['db_query']('', '
920 957
 				UPDATE {db_prefix}boards
921 958
 				SET num_posts = {int:num_posts}
922 959
 				WHERE redirect = {string:redirect}',
@@ -925,6 +962,7 @@  discard block
 block discarded – undo
925 962
 					'redirect' => '',
926 963
 				)
927 964
 			);
965
+		}
928 966
 
929 967
 		while ($_REQUEST['start'] < $max_topics)
930 968
 		{
@@ -941,8 +979,8 @@  discard block
 block discarded – undo
941 979
 					'is_approved' => 1,
942 980
 				)
943 981
 			);
944
-			while ($row = $smcFunc['db_fetch_assoc']($request))
945
-				$smcFunc['db_query']('', '
982
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
983
+							$smcFunc['db_query']('', '
946 984
 					UPDATE {db_prefix}boards
947 985
 					SET num_posts = num_posts + {int:real_num_posts}
948 986
 					WHERE id_board = {int:id_board}',
@@ -951,6 +989,7 @@  discard block
 block discarded – undo
951 989
 						'real_num_posts' => $row['real_num_posts'],
952 990
 					)
953 991
 				);
992
+			}
954 993
 			$smcFunc['db_free_result']($request);
955 994
 
956 995
 			$_REQUEST['start'] += $increment;
@@ -973,14 +1012,15 @@  discard block
 block discarded – undo
973 1012
 	// Update the topic count of each board.
974 1013
 	if ($_REQUEST['step'] <= 2)
975 1014
 	{
976
-		if (empty($_REQUEST['start']))
977
-			$smcFunc['db_query']('', '
1015
+		if (empty($_REQUEST['start'])) {
1016
+					$smcFunc['db_query']('', '
978 1017
 				UPDATE {db_prefix}boards
979 1018
 				SET num_topics = {int:num_topics}',
980 1019
 				array(
981 1020
 					'num_topics' => 0,
982 1021
 				)
983 1022
 			);
1023
+		}
984 1024
 
985 1025
 		while ($_REQUEST['start'] < $max_topics)
986 1026
 		{
@@ -997,8 +1037,8 @@  discard block
 block discarded – undo
997 1037
 					'id_topic_max' => $_REQUEST['start'] + $increment,
998 1038
 				)
999 1039
 			);
1000
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1001
-				$smcFunc['db_query']('', '
1040
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1041
+							$smcFunc['db_query']('', '
1002 1042
 					UPDATE {db_prefix}boards
1003 1043
 					SET num_topics = num_topics + {int:real_num_topics}
1004 1044
 					WHERE id_board = {int:id_board}',
@@ -1007,6 +1047,7 @@  discard block
 block discarded – undo
1007 1047
 						'real_num_topics' => $row['real_num_topics'],
1008 1048
 					)
1009 1049
 				);
1050
+			}
1010 1051
 			$smcFunc['db_free_result']($request);
1011 1052
 
1012 1053
 			$_REQUEST['start'] += $increment;
@@ -1029,14 +1070,15 @@  discard block
 block discarded – undo
1029 1070
 	// Update the unapproved post count of each board.
1030 1071
 	if ($_REQUEST['step'] <= 3)
1031 1072
 	{
1032
-		if (empty($_REQUEST['start']))
1033
-			$smcFunc['db_query']('', '
1073
+		if (empty($_REQUEST['start'])) {
1074
+					$smcFunc['db_query']('', '
1034 1075
 				UPDATE {db_prefix}boards
1035 1076
 				SET unapproved_posts = {int:unapproved_posts}',
1036 1077
 				array(
1037 1078
 					'unapproved_posts' => 0,
1038 1079
 				)
1039 1080
 			);
1081
+		}
1040 1082
 
1041 1083
 		while ($_REQUEST['start'] < $max_topics)
1042 1084
 		{
@@ -1053,8 +1095,8 @@  discard block
 block discarded – undo
1053 1095
 					'is_approved' => 0,
1054 1096
 				)
1055 1097
 			);
1056
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1057
-				$smcFunc['db_query']('', '
1098
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1099
+							$smcFunc['db_query']('', '
1058 1100
 					UPDATE {db_prefix}boards
1059 1101
 					SET unapproved_posts = unapproved_posts + {int:unapproved_posts}
1060 1102
 					WHERE id_board = {int:id_board}',
@@ -1063,6 +1105,7 @@  discard block
 block discarded – undo
1063 1105
 						'unapproved_posts' => $row['real_unapproved_posts'],
1064 1106
 					)
1065 1107
 				);
1108
+			}
1066 1109
 			$smcFunc['db_free_result']($request);
1067 1110
 
1068 1111
 			$_REQUEST['start'] += $increment;
@@ -1085,14 +1128,15 @@  discard block
 block discarded – undo
1085 1128
 	// Update the unapproved topic count of each board.
1086 1129
 	if ($_REQUEST['step'] <= 4)
1087 1130
 	{
1088
-		if (empty($_REQUEST['start']))
1089
-			$smcFunc['db_query']('', '
1131
+		if (empty($_REQUEST['start'])) {
1132
+					$smcFunc['db_query']('', '
1090 1133
 				UPDATE {db_prefix}boards
1091 1134
 				SET unapproved_topics = {int:unapproved_topics}',
1092 1135
 				array(
1093 1136
 					'unapproved_topics' => 0,
1094 1137
 				)
1095 1138
 			);
1139
+		}
1096 1140
 
1097 1141
 		while ($_REQUEST['start'] < $max_topics)
1098 1142
 		{
@@ -1109,8 +1153,8 @@  discard block
 block discarded – undo
1109 1153
 					'id_topic_max' => $_REQUEST['start'] + $increment,
1110 1154
 				)
1111 1155
 			);
1112
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1113
-				$smcFunc['db_query']('', '
1156
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1157
+							$smcFunc['db_query']('', '
1114 1158
 					UPDATE {db_prefix}boards
1115 1159
 					SET unapproved_topics = unapproved_topics + {int:real_unapproved_topics}
1116 1160
 					WHERE id_board = {int:id_board}',
@@ -1119,6 +1163,7 @@  discard block
 block discarded – undo
1119 1163
 						'real_unapproved_topics' => $row['real_unapproved_topics'],
1120 1164
 					)
1121 1165
 				);
1166
+			}
1122 1167
 			$smcFunc['db_free_result']($request);
1123 1168
 
1124 1169
 			$_REQUEST['start'] += $increment;
@@ -1152,8 +1197,9 @@  discard block
 block discarded – undo
1152 1197
 				'is_not_deleted' => 0,
1153 1198
 			)
1154 1199
 		);
1155
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1156
-			updateMemberData($row['id_member'], array('instant_messages' => $row['real_num']));
1200
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1201
+					updateMemberData($row['id_member'], array('instant_messages' => $row['real_num']));
1202
+		}
1157 1203
 		$smcFunc['db_free_result']($request);
1158 1204
 
1159 1205
 		$request = $smcFunc['db_query']('', '
@@ -1168,8 +1214,9 @@  discard block
 block discarded – undo
1168 1214
 				'is_not_read' => 0,
1169 1215
 			)
1170 1216
 		);
1171
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1172
-			updateMemberData($row['id_member'], array('unread_messages' => $row['real_num']));
1217
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1218
+					updateMemberData($row['id_member'], array('unread_messages' => $row['real_num']));
1219
+		}
1173 1220
 		$smcFunc['db_free_result']($request);
1174 1221
 
1175 1222
 		if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 3)
@@ -1201,12 +1248,13 @@  discard block
 block discarded – undo
1201 1248
 				)
1202 1249
 			);
1203 1250
 			$boards = array();
1204
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1205
-				$boards[$row['id_board']][] = $row['id_msg'];
1251
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1252
+							$boards[$row['id_board']][] = $row['id_msg'];
1253
+			}
1206 1254
 			$smcFunc['db_free_result']($request);
1207 1255
 
1208
-			foreach ($boards as $board_id => $messages)
1209
-				$smcFunc['db_query']('', '
1256
+			foreach ($boards as $board_id => $messages) {
1257
+							$smcFunc['db_query']('', '
1210 1258
 					UPDATE {db_prefix}messages
1211 1259
 					SET id_board = {int:id_board}
1212 1260
 					WHERE id_msg IN ({array_int:id_msg_array})',
@@ -1215,6 +1263,7 @@  discard block
 block discarded – undo
1215 1263
 						'id_board' => $board_id,
1216 1264
 					)
1217 1265
 				);
1266
+			}
1218 1267
 
1219 1268
 			$_REQUEST['start'] += $increment;
1220 1269
 
@@ -1244,8 +1293,9 @@  discard block
 block discarded – undo
1244 1293
 		)
1245 1294
 	);
1246 1295
 	$realBoardCounts = array();
1247
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1248
-		$realBoardCounts[$row['id_board']] = $row['local_last_msg'];
1296
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1297
+			$realBoardCounts[$row['id_board']] = $row['local_last_msg'];
1298
+	}
1249 1299
 	$smcFunc['db_free_result']($request);
1250 1300
 
1251 1301
 	$request = $smcFunc['db_query']('', '
@@ -1265,18 +1315,20 @@  discard block
 block discarded – undo
1265 1315
 	krsort($resort_me);
1266 1316
 
1267 1317
 	$lastModifiedMsg = array();
1268
-	foreach ($resort_me as $rows)
1269
-		foreach ($rows as $row)
1318
+	foreach ($resort_me as $rows) {
1319
+			foreach ($rows as $row)
1270 1320
 		{
1271 1321
 			// The latest message is the latest of the current board and its children.
1272 1322
 			if (isset($lastModifiedMsg[$row['id_board']]))
1273 1323
 				$curLastModifiedMsg = max($row['local_last_msg'], $lastModifiedMsg[$row['id_board']]);
1274
-			else
1275
-				$curLastModifiedMsg = $row['local_last_msg'];
1324
+	}
1325
+			else {
1326
+							$curLastModifiedMsg = $row['local_last_msg'];
1327
+			}
1276 1328
 
1277 1329
 			// If what is and what should be the latest message differ, an update is necessary.
1278
-			if ($row['local_last_msg'] != $row['id_last_msg'] || $curLastModifiedMsg != $row['id_msg_updated'])
1279
-				$smcFunc['db_query']('', '
1330
+			if ($row['local_last_msg'] != $row['id_last_msg'] || $curLastModifiedMsg != $row['id_msg_updated']) {
1331
+							$smcFunc['db_query']('', '
1280 1332
 					UPDATE {db_prefix}boards
1281 1333
 					SET id_last_msg = {int:id_last_msg}, id_msg_updated = {int:id_msg_updated}
1282 1334
 					WHERE id_board = {int:id_board}',
@@ -1286,12 +1338,14 @@  discard block
 block discarded – undo
1286 1338
 						'id_board' => $row['id_board'],
1287 1339
 					)
1288 1340
 				);
1341
+			}
1289 1342
 
1290 1343
 			// Parent boards inherit the latest modified message of their children.
1291
-			if (isset($lastModifiedMsg[$row['id_parent']]))
1292
-				$lastModifiedMsg[$row['id_parent']] = max($row['local_last_msg'], $lastModifiedMsg[$row['id_parent']]);
1293
-			else
1294
-				$lastModifiedMsg[$row['id_parent']] = $row['local_last_msg'];
1344
+			if (isset($lastModifiedMsg[$row['id_parent']])) {
1345
+							$lastModifiedMsg[$row['id_parent']] = max($row['local_last_msg'], $lastModifiedMsg[$row['id_parent']]);
1346
+			} else {
1347
+							$lastModifiedMsg[$row['id_parent']] = $row['local_last_msg'];
1348
+			}
1295 1349
 		}
1296 1350
 
1297 1351
 	// Update all the basic statistics.
@@ -1363,8 +1417,9 @@  discard block
 block discarded – undo
1363 1417
 	require_once($sourcedir . '/Subs-Auth.php');
1364 1418
 	$members = findMembers($_POST['to']);
1365 1419
 
1366
-	if (empty($members))
1367
-		fatal_lang_error('reattribute_cannot_find_member');
1420
+	if (empty($members)) {
1421
+			fatal_lang_error('reattribute_cannot_find_member');
1422
+	}
1368 1423
 
1369 1424
 	$memID = array_shift($members);
1370 1425
 	$memID = $memID['id'];
@@ -1394,8 +1449,9 @@  discard block
 block discarded – undo
1394 1449
 		validateToken('admin-maint');
1395 1450
 
1396 1451
 		$groups = array();
1397
-		foreach ($_POST['groups'] as $id => $dummy)
1398
-			$groups[] = (int) $id;
1452
+		foreach ($_POST['groups'] as $id => $dummy) {
1453
+					$groups[] = (int) $id;
1454
+		}
1399 1455
 		$time_limit = (time() - ($_POST['maxdays'] * 24 * 3600));
1400 1456
 		$where_vars = array(
1401 1457
 			'time_limit' => $time_limit,
@@ -1404,9 +1460,9 @@  discard block
 block discarded – undo
1404 1460
 		{
1405 1461
 			$where = 'mem.date_registered < {int:time_limit} AND mem.is_activated = {int:is_activated}';
1406 1462
 			$where_vars['is_activated'] = 0;
1463
+		} else {
1464
+					$where = 'mem.last_login < {int:time_limit} AND (mem.last_login != 0 OR mem.date_registered < {int:time_limit})';
1407 1465
 		}
1408
-		else
1409
-			$where = 'mem.last_login < {int:time_limit} AND (mem.last_login != 0 OR mem.date_registered < {int:time_limit})';
1410 1466
 
1411 1467
 		// Need to get *all* groups then work out which (if any) we avoid.
1412 1468
 		$request = $smcFunc['db_query']('', '
@@ -1425,8 +1481,7 @@  discard block
 block discarded – undo
1425 1481
 				{
1426 1482
 					$where .= ' AND mem.id_post_group != {int:id_post_group_' . $row['id_group'] . '}';
1427 1483
 					$where_vars['id_post_group_' . $row['id_group']] = $row['id_group'];
1428
-				}
1429
-				else
1484
+				} else
1430 1485
 				{
1431 1486
 					$where .= ' AND mem.id_group != {int:id_group_' . $row['id_group'] . '} AND FIND_IN_SET({int:id_group_' . $row['id_group'] . '}, mem.additional_groups) = 0';
1432 1487
 					$where_vars['id_group_' . $row['id_group']] = $row['id_group'];
@@ -1453,8 +1508,9 @@  discard block
 block discarded – undo
1453 1508
 		$members = array();
1454 1509
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1455 1510
 		{
1456
-			if (!$row['is_mod'] || !in_array(3, $groups))
1457
-				$members[] = $row['id_member'];
1511
+			if (!$row['is_mod'] || !in_array(3, $groups)) {
1512
+							$members[] = $row['id_member'];
1513
+			}
1458 1514
 		}
1459 1515
 		$smcFunc['db_free_result']($request);
1460 1516
 
@@ -1501,8 +1557,9 @@  discard block
 block discarded – undo
1501 1557
 		)
1502 1558
 	);
1503 1559
 
1504
-	while ($row = $smcFunc['db_fetch_row']($request))
1505
-		$drafts[] = (int) $row[0];
1560
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1561
+			$drafts[] = (int) $row[0];
1562
+	}
1506 1563
 	$smcFunc['db_free_result']($request);
1507 1564
 
1508 1565
 	// If we have old drafts, remove them
@@ -1545,8 +1602,9 @@  discard block
 block discarded – undo
1545 1602
 	$sticky = isset($_POST['move_type_sticky']) || isset($_GET['sticky']);
1546 1603
 
1547 1604
 	// No boards then this is your stop.
1548
-	if (empty($id_board_from) || empty($id_board_to))
1549
-		return;
1605
+	if (empty($id_board_from) || empty($id_board_to)) {
1606
+			return;
1607
+	}
1550 1608
 
1551 1609
 	// The big WHERE clause
1552 1610
 	$conditions = 'WHERE t.id_board = {int:id_board_from}
@@ -1594,18 +1652,20 @@  discard block
 block discarded – undo
1594 1652
 		);
1595 1653
 		list ($total_topics) = $smcFunc['db_fetch_row']($request);
1596 1654
 		$smcFunc['db_free_result']($request);
1655
+	} else {
1656
+			$total_topics = (int) $_REQUEST['totaltopics'];
1597 1657
 	}
1598
-	else
1599
-		$total_topics = (int) $_REQUEST['totaltopics'];
1600 1658
 
1601 1659
 	// Seems like we need this here.
1602 1660
 	$context['continue_get_data'] = '?action=admin;area=maintain;sa=topics;activity=massmove;id_board_from=' . $id_board_from . ';id_board_to=' . $id_board_to . ';totaltopics=' . $total_topics . ';max_days=' . $max_days;
1603 1661
 
1604
-	if ($locked)
1605
-		$context['continue_get_data'] .= ';locked';
1662
+	if ($locked) {
1663
+			$context['continue_get_data'] .= ';locked';
1664
+	}
1606 1665
 
1607
-	if ($sticky)
1608
-		$context['continue_get_data'] .= ';sticky';
1666
+	if ($sticky) {
1667
+			$context['continue_get_data'] .= ';sticky';
1668
+	}
1609 1669
 
1610 1670
 	$context['continue_get_data'] .= ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1611 1671
 
@@ -1626,8 +1686,9 @@  discard block
 block discarded – undo
1626 1686
 
1627 1687
 			// Get the ids.
1628 1688
 			$topics = array();
1629
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1630
-				$topics[] = $row['id_topic'];
1689
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1690
+							$topics[] = $row['id_topic'];
1691
+			}
1631 1692
 
1632 1693
 			// Just return if we don't have any topics left to move.
1633 1694
 			if (empty($topics))
@@ -1718,9 +1779,9 @@  discard block
 block discarded – undo
1718 1779
 		// save it so we don't do this again for this task
1719 1780
 		list ($_SESSION['total_members']) = $smcFunc['db_fetch_row']($request);
1720 1781
 		$smcFunc['db_free_result']($request);
1782
+	} else {
1783
+			validateToken('admin-recountposts');
1721 1784
 	}
1722
-	else
1723
-		validateToken('admin-recountposts');
1724 1785
 
1725 1786
 	// Lets get a group of members and determine their post count (from the boards that have post count enabled of course).
1726 1787
 	$request = $smcFunc['db_query']('', '
@@ -1766,8 +1827,9 @@  discard block
 block discarded – undo
1766 1827
 		createToken('admin-recountposts');
1767 1828
 		$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-recountposts_token_var'] . '" value="' . $context['admin-recountposts_token'] . '">';
1768 1829
 
1769
-		if (function_exists('apache_reset_timeout'))
1770
-			apache_reset_timeout();
1830
+		if (function_exists('apache_reset_timeout')) {
1831
+					apache_reset_timeout();
1832
+		}
1771 1833
 		return;
1772 1834
 	}
1773 1835
 
@@ -1853,10 +1915,9 @@  discard block
 block discarded – undo
1853 1915
 		checkSession('request');
1854 1916
 		validateToken('admin-hook', 'request');
1855 1917
 
1856
-		if ($_REQUEST['do'] == 'remove')
1857
-			remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
1858
-
1859
-		else
1918
+		if ($_REQUEST['do'] == 'remove') {
1919
+					remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
1920
+		} else
1860 1921
 		{
1861 1922
 			$function_remove = urldecode($_REQUEST['function']) . (($_REQUEST['do'] == 'disable') ? '' : '!');
1862 1923
 			$function_add = urldecode($_REQUEST['function']) . (($_REQUEST['do'] == 'disable') ? '!' : '');
@@ -1906,11 +1967,11 @@  discard block
 block discarded – undo
1906 1967
 						// Show a nice icon to indicate this is an instance.
1907 1968
 						$instance = (!empty($data['instance']) ? '<span class="generic_icons news" title="' . $txt['hooks_field_function_method'] . '"></span> ' : '');
1908 1969
 
1909
-						if (!empty($data['included_file']))
1910
-							return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file'];
1911
-
1912
-						else
1913
-							return $instance . $data['real_function'];
1970
+						if (!empty($data['included_file'])) {
1971
+													return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file'];
1972
+						} else {
1973
+													return $instance . $data['real_function'];
1974
+						}
1914 1975
 					},
1915 1976
 				),
1916 1977
 				'sort' =>  array(
@@ -1975,11 +2036,12 @@  discard block
 block discarded – undo
1975 2036
 		'data' => array(
1976 2037
 			'function' => function($data) use ($txt, $scripturl, $context)
1977 2038
 			{
1978
-				if (!$data['hook_exists'])
1979
-					return '
2039
+				if (!$data['hook_exists']) {
2040
+									return '
1980 2041
 					<a href="' . $scripturl . '?action=admin;area=maintain;sa=hooks;do=remove;hook=' . $data['hook_name'] . ';function=' . urlencode($data['function_name']) . $context['filter_url'] . ';' . $context['admin-hook_token_var'] . '=' . $context['admin-hook_token'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" data-confirm="' . $txt['quickmod_confirm'] . '" class="you_sure">
1981 2042
 						<span class="generic_icons delete" title="' . $txt['hooks_button_remove'] . '"></span>
1982 2043
 					</a>';
2044
+				}
1983 2045
 			},
1984 2046
 			'class' => 'centertext',
1985 2047
 		),
@@ -2014,10 +2076,11 @@  discard block
 block discarded – undo
2014 2076
 		{
2015 2077
 			if ($file != '.' && $file != '..')
2016 2078
 			{
2017
-				if (is_dir($dir_path . '/' . $file))
2018
-					$files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
2019
-				else
2020
-					$files[] = array('dir' => $dir_path, 'name' => $file);
2079
+				if (is_dir($dir_path . '/' . $file)) {
2080
+									$files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
2081
+				} else {
2082
+									$files[] = array('dir' => $dir_path, 'name' => $file);
2083
+				}
2021 2084
 			}
2022 2085
 		}
2023 2086
 	}
@@ -2066,16 +2129,16 @@  discard block
 block discarded – undo
2066 2129
 							// I need to know if there is at least one function called in this file.
2067 2130
 							$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2068 2131
 							unset($temp_hooks[$hook][$rawFunc]);
2069
-						}
2070
-						elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($hookParsedData['pureFunc']) . '(') !== false)
2132
+						} elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($hookParsedData['pureFunc']) . '(') !== false)
2071 2133
 						{
2072 2134
 							$hook_status[$hook][$hookParsedData['pureFunc']] = $hookParsedData;
2073 2135
 							$hook_status[$hook][$hookParsedData['pureFunc']]['exists'] = true;
2074 2136
 							$hook_status[$hook][$hookParsedData['pureFunc']]['in_file'] = (!empty($file['name']) ? $file['name'] : (!empty($hookParsedData['hookFile']) ? $hookParsedData['hookFile'] : ''));
2075 2137
 
2076 2138
 							// Does the hook has its own file?
2077
-							if (!empty($hookParsedData['hookFile']))
2078
-								$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2139
+							if (!empty($hookParsedData['hookFile'])) {
2140
+															$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2141
+							}
2079 2142
 
2080 2143
 							// I want to remember all the functions called within this file (to check later if they are enabled or disabled and decide if the integrare_*_include of that file can be disabled too)
2081 2144
 							$temp_data['function'][$file['name']][$hookParsedData['pureFunc']] = $hookParsedData['enabled'];
@@ -2102,15 +2165,17 @@  discard block
 block discarded – undo
2102 2165
 	$sort = array();
2103 2166
 	$hooks_filters = array();
2104 2167
 
2105
-	foreach ($hooks as $hook => $functions)
2106
-		$hooks_filters[] = '<option' . ($context['current_filter'] == $hook ? ' selected ' : '') . ' value="' . $hook . '">' . $hook . '</option>';
2168
+	foreach ($hooks as $hook => $functions) {
2169
+			$hooks_filters[] = '<option' . ($context['current_filter'] == $hook ? ' selected ' : '') . ' value="' . $hook . '">' . $hook . '</option>';
2170
+	}
2107 2171
 
2108
-	if (!empty($hooks_filters))
2109
-		$context['insert_after_template'] .= '
2172
+	if (!empty($hooks_filters)) {
2173
+			$context['insert_after_template'] .= '
2110 2174
 		<script>
2111 2175
 			var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\');
2112 2176
 			hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;" onchange="window.location=(\'' . $scripturl . '?action=admin;area=maintain;sa=hooks\' + (this.value ? \';filter=\' + this.value : \'\'));"><option value="">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>') . ';
2113 2177
 		</script>';
2178
+	}
2114 2179
 
2115 2180
 	$temp_data = array();
2116 2181
 	$id = 0;
@@ -2152,10 +2217,11 @@  discard block
 block discarded – undo
2152 2217
 
2153 2218
 	foreach ($temp_data as $data)
2154 2219
 	{
2155
-		if (++$counter < $start)
2156
-			continue;
2157
-		elseif ($counter == $start + $per_page)
2158
-			break;
2220
+		if (++$counter < $start) {
2221
+					continue;
2222
+		} elseif ($counter == $start + $per_page) {
2223
+					break;
2224
+		}
2159 2225
 
2160 2226
 		$hooks_data[] = $data;
2161 2227
 	}
@@ -2177,13 +2243,15 @@  discard block
 block discarded – undo
2177 2243
 	$hooks_count = 0;
2178 2244
 
2179 2245
 	$context['filter'] = false;
2180
-	if (isset($_GET['filter']))
2181
-		$context['filter'] = $_GET['filter'];
2246
+	if (isset($_GET['filter'])) {
2247
+			$context['filter'] = $_GET['filter'];
2248
+	}
2182 2249
 
2183 2250
 	foreach ($hooks as $hook => $functions)
2184 2251
 	{
2185
-		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
2186
-			$hooks_count += count($functions);
2252
+		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook)) {
2253
+					$hooks_count += count($functions);
2254
+		}
2187 2255
 	}
2188 2256
 
2189 2257
 	return $hooks_count;
@@ -2204,8 +2272,9 @@  discard block
 block discarded – undo
2204 2272
 		$integration_hooks = array();
2205 2273
 		foreach ($modSettings as $key => $value)
2206 2274
 		{
2207
-			if (!empty($value) && substr($key, 0, 10) === 'integrate_')
2208
-				$integration_hooks[$key] = explode(',', $value);
2275
+			if (!empty($value) && substr($key, 0, 10) === 'integrate_') {
2276
+							$integration_hooks[$key] = explode(',', $value);
2277
+			}
2209 2278
 		}
2210 2279
 	}
2211 2280
 
@@ -2236,8 +2305,9 @@  discard block
 block discarded – undo
2236 2305
 	);
2237 2306
 
2238 2307
 	// Meh...
2239
-	if (empty($rawData))
2240
-		return $hookData;
2308
+	if (empty($rawData)) {
2309
+			return $hookData;
2310
+	}
2241 2311
 
2242 2312
 	// For convenience purposes only!
2243 2313
 	$modFunc = $rawData;
@@ -2248,11 +2318,11 @@  discard block
 block discarded – undo
2248 2318
 		list ($hookData['hookFile'], $modFunc) = explode('|', $modFunc);
2249 2319
 
2250 2320
 		// Does the file exists? who knows!
2251
-		if (empty($settings['theme_dir']))
2252
-			$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
2253
-
2254
-		else
2255
-			$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2321
+		if (empty($settings['theme_dir'])) {
2322
+					$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
2323
+		} else {
2324
+					$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2325
+		}
2256 2326
 
2257 2327
 		$hookData['fileExists'] = file_exists($hookData['absPath']);
2258 2328
 		$hookData['hookFile'] = basename($hookData['hookFile']);
@@ -2277,11 +2347,10 @@  discard block
 block discarded – undo
2277 2347
 	{
2278 2348
 		list ($hookData['class'], $hookData['method']) = explode('::', $modFunc);
2279 2349
 		$hookData['pureFunc'] = $hookData['method'];
2350
+	} else {
2351
+			$hookData['pureFunc'] = $modFunc;
2280 2352
 	}
2281 2353
 
2282
-	else
2283
-		$hookData['pureFunc'] = $modFunc;
2284
-
2285 2354
 	return $hookData;
2286 2355
 }
2287 2356
 
Please login to merge, or discard this patch.
Sources/ScheduledTasks.php 1 patch
Braces   +282 added lines, -205 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc, $modSettings;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -452,16 +477,17 @@  discard block
 block discarded – undo
452 477
 
453 478
 	// Check the database version - for some buggy MySQL version.
454 479
 	$server_version = $smcFunc['db_server_info']();
455
-	if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
456
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
457
-	elseif (!empty($modSettings['db_mysql_group_by_fix']))
458
-		$smcFunc['db_query']('', '
480
+	if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
481
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
482
+	} elseif (!empty($modSettings['db_mysql_group_by_fix'])) {
483
+			$smcFunc['db_query']('', '
459 484
 			DELETE FROM {db_prefix}settings
460 485
 			WHERE variable = {string:mysql_fix}',
461 486
 			array(
462 487
 				'mysql_fix' => 'db_mysql_group_by_fix',
463 488
 			)
464 489
 		);
490
+	}
465 491
 
466 492
 	// Clean up some old login history information.
467 493
 	$smcFunc['db_query']('', '
@@ -519,15 +545,17 @@  discard block
 block discarded – undo
519 545
 
520 546
 		// Store this useful data!
521 547
 		$boards[$row['id_board']] = $row['id_board'];
522
-		if ($row['id_topic'])
523
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
524
-		else
525
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
548
+		if ($row['id_topic']) {
549
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
550
+		} else {
551
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
552
+		}
526 553
 	}
527 554
 	$smcFunc['db_free_result']($request);
528 555
 
529
-	if (empty($boards))
530
-		return true;
556
+	if (empty($boards)) {
557
+			return true;
558
+	}
531 559
 
532 560
 	// Just get the board names.
533 561
 	$request = $smcFunc['db_query']('', '
@@ -539,12 +567,14 @@  discard block
 block discarded – undo
539 567
 		)
540 568
 	);
541 569
 	$boards = array();
542
-	while ($row = $smcFunc['db_fetch_assoc']($request))
543
-		$boards[$row['id_board']] = $row['name'];
570
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
571
+			$boards[$row['id_board']] = $row['name'];
572
+	}
544 573
 	$smcFunc['db_free_result']($request);
545 574
 
546
-	if (empty($boards))
547
-		return true;
575
+	if (empty($boards)) {
576
+			return true;
577
+	}
548 578
 
549 579
 	// Get the actual topics...
550 580
 	$request = $smcFunc['db_query']('', '
@@ -564,52 +594,57 @@  discard block
 block discarded – undo
564 594
 	$types = array();
565 595
 	while ($row = $smcFunc['db_fetch_assoc']($request))
566 596
 	{
567
-		if (!isset($types[$row['note_type']][$row['id_board']]))
568
-			$types[$row['note_type']][$row['id_board']] = array(
597
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
598
+					$types[$row['note_type']][$row['id_board']] = array(
569 599
 				'lines' => array(),
570 600
 				'name' => $row['board_name'],
571 601
 				'id' => $row['id_board'],
572 602
 			);
603
+		}
573 604
 
574 605
 		if ($row['note_type'] == 'reply')
575 606
 		{
576
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
577
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
578
-			else
579
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
607
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
608
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
609
+			} else {
610
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
580 611
 					'id' => $row['id_topic'],
581 612
 					'subject' => un_htmlspecialchars($row['subject']),
582 613
 					'count' => 1,
583 614
 				);
584
-		}
585
-		elseif ($row['note_type'] == 'topic')
615
+			}
616
+		} elseif ($row['note_type'] == 'topic')
586 617
 		{
587
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
588
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
618
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
619
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
589 620
 					'id' => $row['id_topic'],
590 621
 					'subject' => un_htmlspecialchars($row['subject']),
591 622
 				);
592
-		}
593
-		else
623
+			}
624
+		} else
594 625
 		{
595
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
596
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
626
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
627
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
597 628
 					'id' => $row['id_topic'],
598 629
 					'subject' => un_htmlspecialchars($row['subject']),
599 630
 					'starter' => $row['id_member_started'],
600 631
 				);
632
+			}
601 633
 		}
602 634
 
603 635
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
604
-		if (!empty($notify['topics'][$row['id_topic']]))
605
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
606
-		if (!empty($notify['boards'][$row['id_board']]))
607
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
636
+		if (!empty($notify['topics'][$row['id_topic']])) {
637
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
638
+		}
639
+		if (!empty($notify['boards'][$row['id_board']])) {
640
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
641
+		}
608 642
 	}
609 643
 	$smcFunc['db_free_result']($request);
610 644
 
611
-	if (empty($types))
612
-		return true;
645
+	if (empty($types)) {
646
+			return true;
647
+	}
613 648
 
614 649
 	// Let's load all the languages into a cache thingy.
615 650
 	$langtxt = array();
@@ -650,8 +685,9 @@  discard block
 block discarded – undo
650 685
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
651 686
 
652 687
 		// Did they not elect to choose this?
653
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
654
-			continue;
688
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
689
+					continue;
690
+		}
655 691
 
656 692
 		// Right character set!
657 693
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -667,39 +703,43 @@  discard block
 block discarded – undo
667 703
 		if (isset($types['topic']))
668 704
 		{
669 705
 			$titled = false;
670
-			foreach ($types['topic'] as $id => $board)
671
-				foreach ($board['lines'] as $topic)
706
+			foreach ($types['topic'] as $id => $board) {
707
+							foreach ($board['lines'] as $topic)
672 708
 					if (in_array($mid, $topic['members']))
673 709
 					{
674 710
 						if (!$titled)
675 711
 						{
676 712
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
713
+			}
677 714
 							$titled = true;
678 715
 						}
679 716
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
680 717
 					}
681
-			if ($titled)
682
-				$email['body'] .= "\n";
718
+			if ($titled) {
719
+							$email['body'] .= "\n";
720
+			}
683 721
 		}
684 722
 
685 723
 		// What about replies?
686 724
 		if (isset($types['reply']))
687 725
 		{
688 726
 			$titled = false;
689
-			foreach ($types['reply'] as $id => $board)
690
-				foreach ($board['lines'] as $topic)
727
+			foreach ($types['reply'] as $id => $board) {
728
+							foreach ($board['lines'] as $topic)
691 729
 					if (in_array($mid, $topic['members']))
692 730
 					{
693 731
 						if (!$titled)
694 732
 						{
695 733
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
734
+			}
696 735
 							$titled = true;
697 736
 						}
698 737
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
699 738
 					}
700 739
 
701
-			if ($titled)
702
-				$email['body'] .= "\n";
740
+			if ($titled) {
741
+							$email['body'] .= "\n";
742
+			}
703 743
 		}
704 744
 
705 745
 		// Finally, moderation actions!
@@ -708,24 +748,27 @@  discard block
 block discarded – undo
708 748
 			$titled = false;
709 749
 			foreach ($types as $note_type => $type)
710 750
 			{
711
-				if ($note_type == 'topic' || $note_type == 'reply')
712
-					continue;
751
+				if ($note_type == 'topic' || $note_type == 'reply') {
752
+									continue;
753
+				}
713 754
 
714
-				foreach ($type as $id => $board)
715
-					foreach ($board['lines'] as $topic)
755
+				foreach ($type as $id => $board) {
756
+									foreach ($board['lines'] as $topic)
716 757
 						if (in_array($mid, $topic['members']))
717 758
 						{
718 759
 							if (!$titled)
719 760
 							{
720 761
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
762
+				}
721 763
 								$titled = true;
722 764
 							}
723 765
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
724 766
 						}
725 767
 			}
726 768
 		}
727
-		if ($titled)
728
-			$email['body'] .= "\n";
769
+		if ($titled) {
770
+					$email['body'] .= "\n";
771
+		}
729 772
 
730 773
 		// Then just say our goodbyes!
731 774
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -753,8 +796,7 @@  discard block
 block discarded – undo
753 796
 				'not_daily' => 0,
754 797
 			)
755 798
 		);
756
-	}
757
-	else
799
+	} else
758 800
 	{
759 801
 		// Clear any only weekly ones, and stop us from sending daily again.
760 802
 		$smcFunc['db_query']('', '
@@ -816,16 +858,19 @@  discard block
 block discarded – undo
816 858
 	global $modSettings, $smcFunc, $sourcedir;
817 859
 
818 860
 	// Are we intending another script to be sending out the queue?
819
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
820
-		return false;
861
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
862
+			return false;
863
+	}
821 864
 
822 865
 	// By default send 5 at once.
823
-	if (!$number)
824
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
866
+	if (!$number) {
867
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
868
+	}
825 869
 
826 870
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
827
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
828
-		return false;
871
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
872
+			return false;
873
+	}
829 874
 
830 875
 	// By default move the next sending on by 10 seconds, and require an affected row.
831 876
 	if (!$override_limit)
@@ -842,8 +887,9 @@  discard block
 block discarded – undo
842 887
 				'last_send' => $modSettings['mail_next_send'],
843 888
 			)
844 889
 		);
845
-		if ($smcFunc['db_affected_rows']() == 0)
846
-			return false;
890
+		if ($smcFunc['db_affected_rows']() == 0) {
891
+					return false;
892
+		}
847 893
 		$modSettings['mail_next_send'] = time() + $delay;
848 894
 	}
849 895
 
@@ -864,8 +910,9 @@  discard block
 block discarded – undo
864 910
 			$mn += $number;
865 911
 		}
866 912
 		// No more I'm afraid, return!
867
-		else
868
-			return false;
913
+		else {
914
+					return false;
915
+		}
869 916
 
870 917
 		// Reflect that we're about to send some, do it now to be safe.
871 918
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -900,14 +947,15 @@  discard block
 block discarded – undo
900 947
 	$smcFunc['db_free_result']($request);
901 948
 
902 949
 	// Delete, delete, delete!!!
903
-	if (!empty($ids))
904
-		$smcFunc['db_query']('', '
950
+	if (!empty($ids)) {
951
+			$smcFunc['db_query']('', '
905 952
 			DELETE FROM {db_prefix}mail_queue
906 953
 			WHERE id_mail IN ({array_int:mail_list})',
907 954
 			array(
908 955
 				'mail_list' => $ids,
909 956
 			)
910 957
 		);
958
+	}
911 959
 
912 960
 	// Don't believe we have any left?
913 961
 	if (count($ids) < $number)
@@ -925,11 +973,13 @@  discard block
 block discarded – undo
925 973
 		);
926 974
 	}
927 975
 
928
-	if (empty($ids))
929
-		return false;
976
+	if (empty($ids)) {
977
+			return false;
978
+	}
930 979
 
931
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
932
-		require_once($sourcedir . '/Subs-Post.php');
980
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
981
+			require_once($sourcedir . '/Subs-Post.php');
982
+	}
933 983
 
934 984
 	// Send each email, yea!
935 985
 	$failed_emails = array();
@@ -949,15 +999,17 @@  discard block
 block discarded – undo
949 999
 
950 1000
 			// Try to stop a timeout, this would be bad...
951 1001
 			@set_time_limit(300);
952
-			if (function_exists('apache_reset_timeout'))
953
-				@apache_reset_timeout();
1002
+			if (function_exists('apache_reset_timeout')) {
1003
+							@apache_reset_timeout();
1004
+			}
1005
+		} else {
1006
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
954 1007
 		}
955
-		else
956
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
957 1008
 
958 1009
 		// Hopefully it sent?
959
-		if (!$result)
960
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1010
+		if (!$result) {
1011
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1012
+		}
961 1013
 	}
962 1014
 
963 1015
 	// Any emails that didn't send?
@@ -972,8 +1024,8 @@  discard block
 block discarded – undo
972 1024
 		);
973 1025
 
974 1026
 		// If we have failed to many times, tell mail to wait a bit and try again.
975
-		if ($modSettings['mail_failed_attempts'] > 5)
976
-			$smcFunc['db_query']('', '
1027
+		if ($modSettings['mail_failed_attempts'] > 5) {
1028
+					$smcFunc['db_query']('', '
977 1029
 				UPDATE {db_prefix}settings
978 1030
 				SET value = {string:next_mail_send}
979 1031
 				WHERE variable = {literal:mail_next_send}
@@ -982,6 +1034,7 @@  discard block
 block discarded – undo
982 1034
 					'next_mail_send' => time() + 60,
983 1035
 					'last_send' => $modSettings['mail_next_send'],
984 1036
 			));
1037
+		}
985 1038
 
986 1039
 		// Add our email back to the queue, manually.
987 1040
 		$smcFunc['db_insert']('insert',
@@ -994,8 +1047,8 @@  discard block
 block discarded – undo
994 1047
 		return false;
995 1048
 	}
996 1049
 	// We where unable to send the email, clear our failed attempts.
997
-	elseif (!empty($modSettings['mail_failed_attempts']))
998
-		$smcFunc['db_query']('', '
1050
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1051
+			$smcFunc['db_query']('', '
999 1052
 			UPDATE {db_prefix}settings
1000 1053
 			SET value = {string:zero}
1001 1054
 			WHERE variable = {string:mail_failed_attempts}',
@@ -1003,6 +1056,7 @@  discard block
 block discarded – undo
1003 1056
 				'zero' => '0',
1004 1057
 				'mail_failed_attempts' => 'mail_failed_attempts',
1005 1058
 		));
1059
+	}
1006 1060
 
1007 1061
 	// Had something to send...
1008 1062
 	return true;
@@ -1019,16 +1073,18 @@  discard block
 block discarded – undo
1019 1073
 	global $modSettings, $smcFunc;
1020 1074
 
1021 1075
 	$task_query = '';
1022
-	if (!is_array($tasks))
1023
-		$tasks = array($tasks);
1076
+	if (!is_array($tasks)) {
1077
+			$tasks = array($tasks);
1078
+	}
1024 1079
 
1025 1080
 	// Actually have something passed?
1026 1081
 	if (!empty($tasks))
1027 1082
 	{
1028
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1029
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1030
-		else
1031
-			$task_query = ' AND task IN ({array_string:tasks})';
1083
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1084
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1085
+		} else {
1086
+					$task_query = ' AND task IN ({array_string:tasks})';
1087
+		}
1032 1088
 	}
1033 1089
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1034 1090
 
@@ -1049,20 +1105,22 @@  discard block
 block discarded – undo
1049 1105
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1050 1106
 
1051 1107
 		// Only bother moving the task if it's out of place or we're forcing it!
1052
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1053
-			$tasks[$row['id_task']] = $next_time;
1054
-		else
1055
-			$next_time = $row['next_time'];
1108
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1109
+					$tasks[$row['id_task']] = $next_time;
1110
+		} else {
1111
+					$next_time = $row['next_time'];
1112
+		}
1056 1113
 
1057 1114
 		// If this is sooner than the current next task, make this the next task.
1058
-		if ($next_time < $nextTaskTime)
1059
-			$nextTaskTime = $next_time;
1115
+		if ($next_time < $nextTaskTime) {
1116
+					$nextTaskTime = $next_time;
1117
+		}
1060 1118
 	}
1061 1119
 	$smcFunc['db_free_result']($request);
1062 1120
 
1063 1121
 	// Now make the changes!
1064
-	foreach ($tasks as $id => $time)
1065
-		$smcFunc['db_query']('', '
1122
+	foreach ($tasks as $id => $time) {
1123
+			$smcFunc['db_query']('', '
1066 1124
 			UPDATE {db_prefix}scheduled_tasks
1067 1125
 			SET next_time = {int:next_time}
1068 1126
 			WHERE id_task = {int:id_task}',
@@ -1071,11 +1129,13 @@  discard block
 block discarded – undo
1071 1129
 				'id_task' => $id,
1072 1130
 			)
1073 1131
 		);
1132
+	}
1074 1133
 
1075 1134
 	// If the next task is now different update.
1076
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1077
-		updateSettings(array('next_task_time' => $nextTaskTime));
1078
-}
1135
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1136
+			updateSettings(array('next_task_time' => $nextTaskTime));
1137
+	}
1138
+	}
1079 1139
 
1080 1140
 /**
1081 1141
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1088,8 +1148,9 @@  discard block
 block discarded – undo
1088 1148
 function next_time($regularity, $unit, $offset)
1089 1149
 {
1090 1150
 	// Just in case!
1091
-	if ($regularity == 0)
1092
-		$regularity = 2;
1151
+	if ($regularity == 0) {
1152
+			$regularity = 2;
1153
+	}
1093 1154
 
1094 1155
 	$curMin = date('i', time());
1095 1156
 
@@ -1099,15 +1160,16 @@  discard block
 block discarded – undo
1099 1160
 		$off = date('i', $offset);
1100 1161
 
1101 1162
 		// If it's now just pretend it ain't,
1102
-		if ($off == $curMin)
1103
-			$next_time = time() + $regularity;
1104
-		else
1163
+		if ($off == $curMin) {
1164
+					$next_time = time() + $regularity;
1165
+		} else
1105 1166
 		{
1106 1167
 			// Make sure that the offset is always in the past.
1107 1168
 			$off = $off > $curMin ? $off - 60 : $off;
1108 1169
 
1109
-			while ($off <= $curMin)
1110
-				$off += $regularity;
1170
+			while ($off <= $curMin) {
1171
+							$off += $regularity;
1172
+			}
1111 1173
 
1112 1174
 			// Now we know when the time should be!
1113 1175
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1127,11 +1189,13 @@  discard block
 block discarded – undo
1127 1189
 		// Default we'll jump in hours.
1128 1190
 		$applyOffset = 3600;
1129 1191
 		// 24 hours = 1 day.
1130
-		if ($unit == 'd')
1131
-			$applyOffset = 86400;
1192
+		if ($unit == 'd') {
1193
+					$applyOffset = 86400;
1194
+		}
1132 1195
 		// Otherwise a week.
1133
-		if ($unit == 'w')
1134
-			$applyOffset = 604800;
1196
+		if ($unit == 'w') {
1197
+					$applyOffset = 604800;
1198
+		}
1135 1199
 
1136 1200
 		$applyOffset *= $regularity;
1137 1201
 
@@ -1168,8 +1232,9 @@  discard block
 block discarded – undo
1168 1232
 		$settings[$row['variable']] = $row['value'];
1169 1233
 
1170 1234
 		// Is this the default theme?
1171
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1172
-			$settings['default_' . $row['variable']] = $row['value'];
1235
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1236
+					$settings['default_' . $row['variable']] = $row['value'];
1237
+		}
1173 1238
 	}
1174 1239
 	$smcFunc['db_free_result']($result);
1175 1240
 
@@ -1179,12 +1244,14 @@  discard block
 block discarded – undo
1179 1244
 		$settings['template_dirs'] = array($settings['theme_dir']);
1180 1245
 
1181 1246
 		// Based on theme (if there is one).
1182
-		if (!empty($settings['base_theme_dir']))
1183
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1247
+		if (!empty($settings['base_theme_dir'])) {
1248
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1249
+		}
1184 1250
 
1185 1251
 		// Lastly the default theme.
1186
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1187
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1252
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1253
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1254
+		}
1188 1255
 	}
1189 1256
 
1190 1257
 	// Assume we want this.
@@ -1330,8 +1397,9 @@  discard block
 block discarded – undo
1330 1397
 	// Ok should we prune the logs?
1331 1398
 	if (!empty($modSettings['pruningOptions']))
1332 1399
 	{
1333
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1334
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1400
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1401
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1402
+		}
1335 1403
 
1336 1404
 		if (!empty($modSettings['pruneErrorLog']))
1337 1405
 		{
@@ -1397,8 +1465,9 @@  discard block
 block discarded – undo
1397 1465
 				)
1398 1466
 			);
1399 1467
 
1400
-			while ($row = $smcFunc['db_fetch_row']($result))
1401
-				$reports[] = $row[0];
1468
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1469
+							$reports[] = $row[0];
1470
+			}
1402 1471
 
1403 1472
 			$smcFunc['db_free_result']($result);
1404 1473
 
@@ -1560,8 +1629,9 @@  discard block
 block discarded – undo
1560 1629
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1561 1630
 
1562 1631
 		// Send the actual email.
1563
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1564
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1632
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1633
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1634
+		}
1565 1635
 
1566 1636
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1567 1637
 		{
@@ -1584,18 +1654,19 @@  discard block
 block discarded – undo
1584 1654
 	}
1585 1655
 
1586 1656
 	// Insert the alerts if any
1587
-	if (!empty($alert_rows))
1588
-		$smcFunc['db_insert']('',
1657
+	if (!empty($alert_rows)) {
1658
+			$smcFunc['db_insert']('',
1589 1659
 			'{db_prefix}user_alerts',
1590 1660
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1591 1661
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1592 1662
 			$alert_rows,
1593 1663
 			array()
1594 1664
 		);
1665
+	}
1595 1666
 
1596 1667
 	// Mark the reminder as sent.
1597
-	if (!empty($subs_reminded))
1598
-		$smcFunc['db_query']('', '
1668
+	if (!empty($subs_reminded)) {
1669
+			$smcFunc['db_query']('', '
1599 1670
 			UPDATE {db_prefix}log_subscribed
1600 1671
 			SET reminder_sent = {int:reminder_sent}
1601 1672
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1604,6 +1675,7 @@  discard block
 block discarded – undo
1604 1675
 				'reminder_sent' => 1,
1605 1676
 			)
1606 1677
 		);
1678
+	}
1607 1679
 
1608 1680
 	return true;
1609 1681
 }
@@ -1619,13 +1691,13 @@  discard block
 block discarded – undo
1619 1691
 	// We need to know where this thing is going.
1620 1692
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1621 1693
 	{
1622
-		if (!is_array($modSettings['attachmentUploadDir']))
1623
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1694
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1695
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1696
+		}
1624 1697
 
1625 1698
 		// Just use the current path for temp files.
1626 1699
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1627
-	}
1628
-	else
1700
+	} else
1629 1701
 	{
1630 1702
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1631 1703
 	}
@@ -1644,14 +1716,16 @@  discard block
 block discarded – undo
1644 1716
 
1645 1717
 		while ($file = readdir($dir))
1646 1718
 		{
1647
-			if ($file == '.' || $file == '..')
1648
-				continue;
1719
+			if ($file == '.' || $file == '..') {
1720
+							continue;
1721
+			}
1649 1722
 
1650 1723
 			if (strpos($file, 'post_tmp_') !== false)
1651 1724
 			{
1652 1725
 				// Temp file is more than 5 hours old!
1653
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1654
-					@unlink($attach_dir . '/' . $file);
1726
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1727
+									@unlink($attach_dir . '/' . $file);
1728
+				}
1655 1729
 			}
1656 1730
 		}
1657 1731
 		closedir($dir);
@@ -1684,8 +1758,9 @@  discard block
 block discarded – undo
1684 1758
 		)
1685 1759
 	);
1686 1760
 
1687
-	while ($row = $smcFunc['db_fetch_row']($request))
1688
-		$topics[] = $row[0];
1761
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1762
+			$topics[] = $row[0];
1763
+	}
1689 1764
 	$smcFunc['db_free_result']($request);
1690 1765
 
1691 1766
 	// Zap, your gone
@@ -1705,8 +1780,9 @@  discard block
 block discarded – undo
1705 1780
 {
1706 1781
 	global $smcFunc, $sourcedir, $modSettings;
1707 1782
 
1708
-	if (empty($modSettings['drafts_keep_days']))
1709
-		return true;
1783
+	if (empty($modSettings['drafts_keep_days'])) {
1784
+			return true;
1785
+	}
1710 1786
 
1711 1787
 	// init
1712 1788
 	$drafts = array();
@@ -1724,8 +1800,9 @@  discard block
 block discarded – undo
1724 1800
 		)
1725 1801
 	);
1726 1802
 
1727
-	while ($row = $smcFunc['db_fetch_row']($request))
1728
-		$drafts[] = (int) $row[0];
1803
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1804
+			$drafts[] = (int) $row[0];
1805
+	}
1729 1806
 	$smcFunc['db_free_result']($request);
1730 1807
 
1731 1808
 	// If we have old one, remove them
Please login to merge, or discard this patch.
other/upgrade-helper.php 1 patch
Braces   +90 added lines, -64 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * This file contains helper functions for upgrade.php
14 14
  */
15 15
 
16
-if (!defined('SMF_VERSION'))
16
+if (!defined('SMF_VERSION')) {
17 17
 	die('No direct access!');
18
+}
18 19
 
19 20
 /**
20 21
  * Clean the cache using the SMF 2.1 CacheAPI.
@@ -45,8 +46,9 @@  discard block
 block discarded – undo
45 46
 	global $smcFunc;
46 47
 	static $member_groups = array();
47 48
 
48
-	if (!empty($member_groups))
49
-		return $member_groups;
49
+	if (!empty($member_groups)) {
50
+			return $member_groups;
51
+	}
50 52
 
51 53
 	$request = $smcFunc['db_query']('', '
52 54
 		SELECT group_name, id_group
@@ -71,8 +73,9 @@  discard block
 block discarded – undo
71 73
 			)
72 74
 		);
73 75
 	}
74
-	while ($row = $smcFunc['db_fetch_row']($request))
75
-		$member_groups[trim($row[0])] = $row[1];
76
+	while ($row = $smcFunc['db_fetch_row']($request)) {
77
+			$member_groups[trim($row[0])] = $row[1];
78
+	}
76 79
 	$smcFunc['db_free_result']($request);
77 80
 
78 81
 	return $member_groups;
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 {
89 92
 	global $upcontext, $boarddir, $sourcedir;
90 93
 
91
-	if (empty($files))
92
-		return true;
94
+	if (empty($files)) {
95
+			return true;
96
+	}
93 97
 
94 98
 	$failure = false;
95 99
 	// On linux, it's easy - just use is_writable!
@@ -104,14 +108,16 @@  discard block
 block discarded – undo
104 108
 				@chmod($file, 0755);
105 109
 
106 110
 				// Well, 755 hopefully worked... if not, try 777.
107
-				if (!is_writable($file) && !@chmod($file, 0777))
108
-					$failure = true;
111
+				if (!is_writable($file) && !@chmod($file, 0777)) {
112
+									$failure = true;
113
+				}
109 114
 				// Otherwise remove it as it's good!
110
-				else
111
-					unset($files[$k]);
115
+				else {
116
+									unset($files[$k]);
117
+				}
118
+			} else {
119
+							unset($files[$k]);
112 120
 			}
113
-			else
114
-				unset($files[$k]);
115 121
 		}
116 122
 	}
117 123
 	// Windows is trickier.  Let's try opening for r+...
@@ -122,30 +128,35 @@  discard block
 block discarded – undo
122 128
 		foreach ($files as $k => $file)
123 129
 		{
124 130
 			// Folders can't be opened for write... but the index.php in them can ;).
125
-			if (is_dir($file))
126
-				$file .= '/index.php';
131
+			if (is_dir($file)) {
132
+							$file .= '/index.php';
133
+			}
127 134
 
128 135
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
129 136
 			@chmod($file, 0777);
130 137
 			$fp = @fopen($file, 'r+');
131 138
 
132 139
 			// Hmm, okay, try just for write in that case...
133
-			if (!$fp)
134
-				$fp = @fopen($file, 'w');
140
+			if (!$fp) {
141
+							$fp = @fopen($file, 'w');
142
+			}
135 143
 
136
-			if (!$fp)
137
-				$failure = true;
138
-			else
139
-				unset($files[$k]);
144
+			if (!$fp) {
145
+							$failure = true;
146
+			} else {
147
+							unset($files[$k]);
148
+			}
140 149
 			@fclose($fp);
141 150
 		}
142 151
 	}
143 152
 
144
-	if (empty($files))
145
-		return true;
153
+	if (empty($files)) {
154
+			return true;
155
+	}
146 156
 
147
-	if (!isset($_SERVER))
148
-		return !$failure;
157
+	if (!isset($_SERVER)) {
158
+			return !$failure;
159
+	}
149 160
 
150 161
 	// What still needs to be done?
151 162
 	$upcontext['chmod']['files'] = $files;
@@ -197,36 +208,40 @@  discard block
 block discarded – undo
197 208
 
198 209
 		if (!isset($ftp) || $ftp->error !== false)
199 210
 		{
200
-			if (!isset($ftp))
201
-				$ftp = new ftp_connection(null);
211
+			if (!isset($ftp)) {
212
+							$ftp = new ftp_connection(null);
213
+			}
202 214
 			// Save the error so we can mess with listing...
203
-			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
204
-				$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
215
+			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) {
216
+							$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
217
+			}
205 218
 
206 219
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
207 220
 
208
-			if ($found_path || !isset($upcontext['chmod']['path']))
209
-				$upcontext['chmod']['path'] = $detect_path;
221
+			if ($found_path || !isset($upcontext['chmod']['path'])) {
222
+							$upcontext['chmod']['path'] = $detect_path;
223
+			}
210 224
 
211
-			if (!isset($upcontext['chmod']['username']))
212
-				$upcontext['chmod']['username'] = $username;
225
+			if (!isset($upcontext['chmod']['username'])) {
226
+							$upcontext['chmod']['username'] = $username;
227
+			}
213 228
 
214 229
 			// Don't forget the login token.
215 230
 			$upcontext += createToken('login');
216 231
 
217 232
 			return false;
218
-		}
219
-		else
233
+		} else
220 234
 		{
221 235
 			// We want to do a relative path for FTP.
222 236
 			if (!in_array($upcontext['chmod']['path'], array('', '/')))
223 237
 			{
224 238
 				$ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
225
-				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
226
-					$ftp_root = substr($ftp_root, 0, -1);
239
+				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) {
240
+									$ftp_root = substr($ftp_root, 0, -1);
241
+				}
242
+			} else {
243
+							$ftp_root = $boarddir;
227 244
 			}
228
-			else
229
-				$ftp_root = $boarddir;
230 245
 
231 246
 			// Save the info for next time!
232 247
 			$_SESSION['installer_temp_ftp'] = array(
@@ -240,10 +255,12 @@  discard block
 block discarded – undo
240 255
 
241 256
 			foreach ($files as $k => $file)
242 257
 			{
243
-				if (!is_writable($file))
244
-					$ftp->chmod($file, 0755);
245
-				if (!is_writable($file))
246
-					$ftp->chmod($file, 0777);
258
+				if (!is_writable($file)) {
259
+									$ftp->chmod($file, 0755);
260
+				}
261
+				if (!is_writable($file)) {
262
+									$ftp->chmod($file, 0777);
263
+				}
247 264
 
248 265
 				// Assuming that didn't work calculate the path without the boarddir.
249 266
 				if (!is_writable($file))
@@ -252,19 +269,23 @@  discard block
 block discarded – undo
252 269
 					{
253 270
 						$ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
254 271
 						$ftp->chmod($ftp_file, 0755);
255
-						if (!is_writable($file))
256
-							$ftp->chmod($ftp_file, 0777);
272
+						if (!is_writable($file)) {
273
+													$ftp->chmod($ftp_file, 0777);
274
+						}
257 275
 						// Sometimes an extra slash can help...
258 276
 						$ftp_file = '/' . $ftp_file;
259
-						if (!is_writable($file))
260
-							$ftp->chmod($ftp_file, 0755);
261
-						if (!is_writable($file))
262
-							$ftp->chmod($ftp_file, 0777);
277
+						if (!is_writable($file)) {
278
+													$ftp->chmod($ftp_file, 0755);
279
+						}
280
+						if (!is_writable($file)) {
281
+													$ftp->chmod($ftp_file, 0777);
282
+						}
263 283
 					}
264 284
 				}
265 285
 
266
-				if (is_writable($file))
267
-					unset($files[$k]);
286
+				if (is_writable($file)) {
287
+									unset($files[$k]);
288
+				}
268 289
 			}
269 290
 
270 291
 			$ftp->close();
@@ -274,8 +295,9 @@  discard block
 block discarded – undo
274 295
 	// What remains?
275 296
 	$upcontext['chmod']['files'] = $files;
276 297
 
277
-	if (empty($files))
278
-		return true;
298
+	if (empty($files)) {
299
+			return true;
300
+	}
279 301
 
280 302
 	return false;
281 303
 }
@@ -288,8 +310,9 @@  discard block
 block discarded – undo
288 310
  */
289 311
 function quickFileWritable($file)
290 312
 {
291
-	if (is_writable($file))
292
-		return true;
313
+	if (is_writable($file)) {
314
+			return true;
315
+	}
293 316
 
294 317
 	@chmod($file, 0755);
295 318
 
@@ -299,10 +322,11 @@  discard block
 block discarded – undo
299 322
 	foreach ($chmod_values as $val)
300 323
 	{
301 324
 		// If it's writable, break out of the loop
302
-		if (is_writable($file))
303
-			break;
304
-		else
305
-			@chmod($file, $val);
325
+		if (is_writable($file)) {
326
+					break;
327
+		} else {
328
+					@chmod($file, $val);
329
+		}
306 330
 	}
307 331
 
308 332
 	return is_writable($file);
@@ -329,14 +353,16 @@  discard block
 block discarded – undo
329 353
 {
330 354
 	static $fp = null;
331 355
 
332
-	if ($fp === null)
333
-		$fp = fopen('php://stderr', 'wb');
356
+	if ($fp === null) {
357
+			$fp = fopen('php://stderr', 'wb');
358
+	}
334 359
 
335 360
 	fwrite($fp, $message . "\n");
336 361
 
337
-	if ($fatal)
338
-		exit;
339
-}
362
+	if ($fatal) {
363
+			exit;
364
+	}
365
+	}
340 366
 
341 367
 /**
342 368
  * Throws a graphical error message.
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +252 added lines, -185 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -58,9 +59,11 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource'            => 'smf_is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['persist']))
63
-		$db_server = 'p:' . $db_server;
64
+	if (!empty($db_options['persist'])) {
65
+			$db_server = 'p:' . $db_server;
66
+	}
64 67
 
65 68
 	$connection = mysqli_init();
66 69
 	
@@ -69,31 +72,35 @@  discard block
 block discarded – undo
69 72
 	$success = false;
70 73
 	
71 74
 	if ($connection) {
72
-		if (!empty($db_options['port']))
73
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
74
-		else
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
75
+		if (!empty($db_options['port'])) {
76
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
77
+		} else {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
79
+		}
76 80
 	}
77 81
 
78 82
 	// Something's wrong, show an error if its fatal (which we assume it is)
79 83
 	if ($success === false)
80 84
 	{
81
-		if (!empty($db_options['non_fatal']))
82
-			return null;
83
-		else
84
-			display_db_error();
85
+		if (!empty($db_options['non_fatal'])) {
86
+					return null;
87
+		} else {
88
+					display_db_error();
89
+		}
85 90
 	}
86 91
 
87 92
 	// Select the database, unless told not to
88
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
89
-		display_db_error();
93
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
94
+			display_db_error();
95
+	}
90 96
 
91 97
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
92
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
93
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
98
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
99
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
94 100
 		array(),
95 101
 		false
96 102
 	);
103
+	}
97 104
 
98 105
 	return $connection;
99 106
 }
@@ -164,37 +171,46 @@  discard block
 block discarded – undo
164 171
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 172
 
166 173
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
174
+	if (!is_object($connection)) {
175
+			display_db_error();
176
+	}
169 177
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
178
+	if ($matches[1] === 'db_prefix') {
179
+			return $db_prefix;
180
+	}
172 181
 
173
-	if ($matches[1] === 'query_see_board')
174
-		return $user_info['query_see_board'];
182
+	if ($matches[1] === 'query_see_board') {
183
+			return $user_info['query_see_board'];
184
+	}
175 185
 
176
-	if ($matches[1] === 'query_wanna_see_board')
177
-		return $user_info['query_wanna_see_board'];
186
+	if ($matches[1] === 'query_wanna_see_board') {
187
+			return $user_info['query_wanna_see_board'];
188
+	}
178 189
 
179
-	if ($matches[1] === 'empty')
180
-		return '\'\'';
190
+	if ($matches[1] === 'empty') {
191
+			return '\'\'';
192
+	}
181 193
 
182
-	if (!isset($matches[2]))
183
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
194
+	if (!isset($matches[2])) {
195
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
196
+	}
184 197
 
185
-	if ($matches[1] === 'literal')
186
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
198
+	if ($matches[1] === 'literal') {
199
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
200
+	}
187 201
 
188
-	if (!isset($values[$matches[2]]))
189
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
202
+	if (!isset($values[$matches[2]])) {
203
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
204
+	}
190 205
 
191 206
 	$replacement = $values[$matches[2]];
192 207
 
193 208
 	switch ($matches[1])
194 209
 	{
195 210
 		case 'int':
196
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
197
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
212
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			}
198 214
 			return (string) (int) $replacement;
199 215
 		break;
200 216
 
@@ -206,56 +222,63 @@  discard block
 block discarded – undo
206 222
 		case 'array_int':
207 223
 			if (is_array($replacement))
208 224
 			{
209
-				if (empty($replacement))
210
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+				if (empty($replacement)) {
226
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227
+				}
211 228
 
212 229
 				foreach ($replacement as $key => $value)
213 230
 				{
214
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
215
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
232
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+					}
216 234
 
217 235
 					$replacement[$key] = (string) (int) $value;
218 236
 				}
219 237
 
220 238
 				return implode(', ', $replacement);
239
+			} else {
240
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221 241
 			}
222
-			else
223
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224 242
 
225 243
 		break;
226 244
 
227 245
 		case 'array_string':
228 246
 			if (is_array($replacement))
229 247
 			{
230
-				if (empty($replacement))
231
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
248
+				if (empty($replacement)) {
249
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+				}
232 251
 
233
-				foreach ($replacement as $key => $value)
234
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
252
+				foreach ($replacement as $key => $value) {
253
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
254
+				}
235 255
 
236 256
 				return implode(', ', $replacement);
257
+			} else {
258
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237 259
 			}
238
-			else
239
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
240 260
 		break;
241 261
 
242 262
 		case 'date':
243
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
244
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
245
-			else
246
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
263
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
264
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
265
+			} else {
266
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
267
+			}
247 268
 		break;
248 269
 
249 270
 		case 'time':
250
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
251
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
252
-			else
253
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
272
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
273
+			} else {
274
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
275
+			}
254 276
 		break;
255 277
 
256 278
 		case 'float':
257
-			if (!is_numeric($replacement))
258
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
279
+			if (!is_numeric($replacement)) {
280
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
281
+			}
259 282
 			return (string) (float) $replacement;
260 283
 		break;
261 284
 
@@ -269,32 +292,37 @@  discard block
 block discarded – undo
269 292
 		break;
270 293
 
271 294
 		case 'inet':
272
-			if ($replacement == 'null' || $replacement == '')
273
-				return 'null';
274
-			if (!isValidIP($replacement))
275
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295
+			if ($replacement == 'null' || $replacement == '') {
296
+							return 'null';
297
+			}
298
+			if (!isValidIP($replacement)) {
299
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
300
+			}
276 301
 			//we don't use the native support of mysql > 5.6.2
277 302
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
278 303
 
279 304
 		case 'array_inet':
280 305
 			if (is_array($replacement))
281 306
 			{
282
-				if (empty($replacement))
283
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+				if (empty($replacement)) {
308
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
309
+				}
284 310
 
285 311
 				foreach ($replacement as $key => $value)
286 312
 				{
287
-					if ($replacement == 'null' || $replacement == '')
288
-						$replacement[$key] = 'null';
289
-					if (!isValidIP($value))
290
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
313
+					if ($replacement == 'null' || $replacement == '') {
314
+											$replacement[$key] = 'null';
315
+					}
316
+					if (!isValidIP($value)) {
317
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+					}
291 319
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
292 320
 				}
293 321
 
294 322
 				return implode(', ', $replacement);
323
+			} else {
324
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295 325
 			}
296
-			else
297
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
298 326
 		break;
299 327
 
300 328
 		default:
@@ -370,22 +398,25 @@  discard block
 block discarded – undo
370 398
 		// Are we in SSI mode?  If so try that username and password first
371 399
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
372 400
 		{
373
-			if (empty($db_persist))
374
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
375
-			else
376
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
401
+			if (empty($db_persist)) {
402
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
403
+			} else {
404
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
405
+			}
377 406
 		}
378 407
 		// Fall back to the regular username and password if need be
379 408
 		if (!$db_connection)
380 409
 		{
381
-			if (empty($db_persist))
382
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
383
-			else
384
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
410
+			if (empty($db_persist)) {
411
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
412
+			} else {
413
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
414
+			}
385 415
 		}
386 416
 
387
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
388
-			$db_connection = false;
417
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
418
+					$db_connection = false;
419
+		}
389 420
 
390 421
 		$connection = $db_connection;
391 422
 	}
@@ -393,18 +424,20 @@  discard block
 block discarded – undo
393 424
 	// One more query....
394 425
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
395 426
 
396
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
397
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
427
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
428
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
429
+	}
398 430
 
399 431
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
400 432
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
401 433
 	{
402 434
 		// Add before LIMIT
403
-		if ($pos = strpos($db_string, 'LIMIT '))
404
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
405
-		else
406
-			// Append it.
435
+		if ($pos = strpos($db_string, 'LIMIT ')) {
436
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
437
+		} else {
438
+					// Append it.
407 439
 			$db_string .= "\n\t\t\tORDER BY null";
440
+		}
408 441
 	}
409 442
 
410 443
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -426,8 +459,9 @@  discard block
 block discarded – undo
426 459
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
427 460
 
428 461
 		// Initialize $db_cache if not already initialized.
429
-		if (!isset($db_cache))
430
-			$db_cache = array();
462
+		if (!isset($db_cache)) {
463
+					$db_cache = array();
464
+		}
431 465
 
432 466
 		if (!empty($_SESSION['debug_redirect']))
433 467
 		{
@@ -453,17 +487,18 @@  discard block
 block discarded – undo
453 487
 		while (true)
454 488
 		{
455 489
 			$pos = strpos($db_string, '\'', $pos + 1);
456
-			if ($pos === false)
457
-				break;
490
+			if ($pos === false) {
491
+							break;
492
+			}
458 493
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
459 494
 
460 495
 			while (true)
461 496
 			{
462 497
 				$pos1 = strpos($db_string, '\'', $pos + 1);
463 498
 				$pos2 = strpos($db_string, '\\', $pos + 1);
464
-				if ($pos1 === false)
465
-					break;
466
-				elseif ($pos2 === false || $pos2 > $pos1)
499
+				if ($pos1 === false) {
500
+									break;
501
+				} elseif ($pos2 === false || $pos2 > $pos1)
467 502
 				{
468 503
 					$pos = $pos1;
469 504
 					break;
@@ -479,29 +514,35 @@  discard block
 block discarded – undo
479 514
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
480 515
 
481 516
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
482
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
483
-			$fail = true;
517
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
518
+					$fail = true;
519
+		}
484 520
 		// Trying to change passwords, slow us down, or something?
485
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
486
-			$fail = true;
487
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
488
-			$fail = true;
521
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
522
+					$fail = true;
523
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
524
+					$fail = true;
525
+		}
489 526
 
490
-		if (!empty($fail) && function_exists('log_error'))
491
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
527
+		if (!empty($fail) && function_exists('log_error')) {
528
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
529
+		}
492 530
 	}
493 531
 
494
-	if (empty($db_unbuffered))
495
-		$ret = @mysqli_query($connection, $db_string);
496
-	else
497
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
532
+	if (empty($db_unbuffered)) {
533
+			$ret = @mysqli_query($connection, $db_string);
534
+	} else {
535
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
536
+	}
498 537
 
499
-	if ($ret === false && empty($db_values['db_error_skip']))
500
-		$ret = smf_db_error($db_string, $connection);
538
+	if ($ret === false && empty($db_values['db_error_skip'])) {
539
+			$ret = smf_db_error($db_string, $connection);
540
+	}
501 541
 
502 542
 	// Debugging.
503
-	if (isset($db_show_debug) && $db_show_debug === true)
504
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
543
+	if (isset($db_show_debug) && $db_show_debug === true) {
544
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
545
+	}
505 546
 
506 547
 	return $ret;
507 548
 }
@@ -548,12 +589,13 @@  discard block
 block discarded – undo
548 589
 	// Decide which connection to use
549 590
 	$connection = $connection === null ? $db_connection : $connection;
550 591
 
551
-	if ($type == 'begin')
552
-		return @mysqli_query($connection, 'BEGIN');
553
-	elseif ($type == 'rollback')
554
-		return @mysqli_query($connection, 'ROLLBACK');
555
-	elseif ($type == 'commit')
556
-		return @mysqli_query($connection, 'COMMIT');
592
+	if ($type == 'begin') {
593
+			return @mysqli_query($connection, 'BEGIN');
594
+	} elseif ($type == 'rollback') {
595
+			return @mysqli_query($connection, 'ROLLBACK');
596
+	} elseif ($type == 'commit') {
597
+			return @mysqli_query($connection, 'COMMIT');
598
+	}
557 599
 
558 600
 	return false;
559 601
 }
@@ -593,8 +635,9 @@  discard block
 block discarded – undo
593 635
 	//    2013: Lost connection to server during query.
594 636
 
595 637
 	// Log the error.
596
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
597
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
638
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
639
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
640
+	}
598 641
 
599 642
 	// Database error auto fixing ;).
600 643
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -603,8 +646,9 @@  discard block
 block discarded – undo
603 646
 		$old_cache = @$modSettings['cache_enable'];
604 647
 		$modSettings['cache_enable'] = '1';
605 648
 
606
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
607
-			$db_last_error = max(@$db_last_error, $temp);
649
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
650
+					$db_last_error = max(@$db_last_error, $temp);
651
+		}
608 652
 
609 653
 		if (@$db_last_error < time() - 3600 * 24 * 3)
610 654
 		{
@@ -620,8 +664,9 @@  discard block
 block discarded – undo
620 664
 					foreach ($tables as $table)
621 665
 					{
622 666
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
623
-						if (trim($table) != '')
624
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
667
+						if (trim($table) != '') {
668
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
669
+						}
625 670
 					}
626 671
 				}
627 672
 
@@ -630,8 +675,9 @@  discard block
 block discarded – undo
630 675
 			// Table crashed.  Let's try to fix it.
631 676
 			elseif ($query_errno == 1016)
632 677
 			{
633
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
634
-					$fix_tables = array('`' . $match[1] . '`');
678
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
679
+									$fix_tables = array('`' . $match[1] . '`');
680
+				}
635 681
 			}
636 682
 			// Indexes crashed.  Should be easy to fix!
637 683
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -650,13 +696,15 @@  discard block
 block discarded – undo
650 696
 
651 697
 			// Make a note of the REPAIR...
652 698
 			cache_put_data('db_last_error', time(), 600);
653
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
654
-				updateSettingsFile(array('db_last_error' => time()));
699
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
700
+							updateSettingsFile(array('db_last_error' => time()));
701
+			}
655 702
 
656 703
 			// Attempt to find and repair the broken table.
657
-			foreach ($fix_tables as $table)
658
-				$smcFunc['db_query']('', "
704
+			foreach ($fix_tables as $table) {
705
+							$smcFunc['db_query']('', "
659 706
 					REPAIR TABLE $table", false, false);
707
+			}
660 708
 
661 709
 			// And send off an email!
662 710
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -665,11 +713,12 @@  discard block
 block discarded – undo
665 713
 
666 714
 			// Try the query again...?
667 715
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
668
-			if ($ret !== false)
669
-				return $ret;
716
+			if ($ret !== false) {
717
+							return $ret;
718
+			}
719
+		} else {
720
+					$modSettings['cache_enable'] = $old_cache;
670 721
 		}
671
-		else
672
-			$modSettings['cache_enable'] = $old_cache;
673 722
 
674 723
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
675 724
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -679,22 +728,25 @@  discard block
 block discarded – undo
679 728
 				// Are we in SSI mode?  If so try that username and password first
680 729
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
681 730
 				{
682
-					if (empty($db_persist))
683
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
684
-					else
685
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
731
+					if (empty($db_persist)) {
732
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
733
+					} else {
734
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
735
+					}
686 736
 				}
687 737
 				// Fall back to the regular username and password if need be
688 738
 				if (!$db_connection)
689 739
 				{
690
-					if (empty($db_persist))
691
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
692
-					else
693
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
740
+					if (empty($db_persist)) {
741
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
742
+					} else {
743
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
744
+					}
694 745
 				}
695 746
 
696
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
697
-					$db_connection = false;
747
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
748
+									$db_connection = false;
749
+				}
698 750
 			}
699 751
 
700 752
 			if ($db_connection)
@@ -705,24 +757,27 @@  discard block
 block discarded – undo
705 757
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
706 758
 
707 759
 					$new_errno = mysqli_errno($db_connection);
708
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
709
-						break;
760
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
761
+											break;
762
+					}
710 763
 				}
711 764
 
712 765
 				// If it failed again, shucks to be you... we're not trying it over and over.
713
-				if ($ret !== false)
714
-					return $ret;
766
+				if ($ret !== false) {
767
+									return $ret;
768
+				}
715 769
 			}
716 770
 		}
717 771
 		// Are they out of space, perhaps?
718 772
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
719 773
 		{
720
-			if (!isset($txt))
721
-				$query_error .= ' - check database storage space.';
722
-			else
774
+			if (!isset($txt)) {
775
+							$query_error .= ' - check database storage space.';
776
+			} else
723 777
 			{
724
-				if (!isset($txt['mysql_error_space']))
725
-					loadLanguage('Errors');
778
+				if (!isset($txt['mysql_error_space'])) {
779
+									loadLanguage('Errors');
780
+				}
726 781
 
727 782
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
728 783
 			}
@@ -730,15 +785,17 @@  discard block
 block discarded – undo
730 785
 	}
731 786
 
732 787
 	// Nothing's defined yet... just die with it.
733
-	if (empty($context) || empty($txt))
734
-		die($query_error);
788
+	if (empty($context) || empty($txt)) {
789
+			die($query_error);
790
+	}
735 791
 
736 792
 	// Show an error message, if possible.
737 793
 	$context['error_title'] = $txt['database_error'];
738
-	if (allowedTo('admin_forum'))
739
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
740
-	else
741
-		$context['error_message'] = $txt['try_again'];
794
+	if (allowedTo('admin_forum')) {
795
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
796
+	} else {
797
+			$context['error_message'] = $txt['try_again'];
798
+	}
742 799
 
743 800
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
744 801
 	{
@@ -768,25 +825,28 @@  discard block
 block discarded – undo
768 825
 	$connection = $connection === null ? $db_connection : $connection;
769 826
 
770 827
 	// With nothing to insert, simply return.
771
-	if (empty($data))
772
-		return;
828
+	if (empty($data)) {
829
+			return;
830
+	}
773 831
 
774 832
 	// Replace the prefix holder with the actual prefix.
775 833
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
776 834
 
777 835
 	// Inserting data as a single row can be done as a single array.
778
-	if (!is_array($data[array_rand($data)]))
779
-		$data = array($data);
836
+	if (!is_array($data[array_rand($data)])) {
837
+			$data = array($data);
838
+	}
780 839
 
781 840
 	// Create the mold for a single row insert.
782 841
 	$insertData = '(';
783 842
 	foreach ($columns as $columnName => $type)
784 843
 	{
785 844
 		// Are we restricting the length?
786
-		if (strpos($type, 'string-') !== false)
787
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
788
-		else
789
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
845
+		if (strpos($type, 'string-') !== false) {
846
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
847
+		} else {
848
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
849
+		}
790 850
 	}
791 851
 	$insertData = substr($insertData, 0, -2) . ')';
792 852
 
@@ -795,8 +855,9 @@  discard block
 block discarded – undo
795 855
 
796 856
 	// Here's where the variables are injected to the query.
797 857
 	$insertRows = array();
798
-	foreach ($data as $dataRow)
799
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
858
+	foreach ($data as $dataRow) {
859
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
860
+	}
800 861
 
801 862
 	// Determine the method of insertion.
802 863
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -816,15 +877,16 @@  discard block
 block discarded – undo
816 877
 	
817 878
 	if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
818 879
 	{
819
-		if ($returnmode == 1)
820
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
821
-		else if ($returnmode == 2)
880
+		if ($returnmode == 1) {
881
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
882
+		} else if ($returnmode == 2)
822 883
 		{
823 884
 			$return_var = array();
824 885
 			$count = count($insertRows);
825 886
 			$start = smf_db_insert_id($table, $keys[0]);
826
-			for ($i = 0; $i < $count; $i++ )
827
-				$return_var[] = $start + $i;
887
+			for ($i = 0; $i < $count; $i++ ) {
888
+							$return_var[] = $start + $i;
889
+			}
828 890
 		}
829 891
 		return $return_var;
830 892
 	}
@@ -842,8 +904,9 @@  discard block
 block discarded – undo
842 904
  */
843 905
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
844 906
 {
845
-	if (empty($log_message))
846
-		$log_message = $error_message;
907
+	if (empty($log_message)) {
908
+			$log_message = $error_message;
909
+	}
847 910
 
848 911
 	foreach (debug_backtrace() as $step)
849 912
 	{
@@ -862,12 +925,14 @@  discard block
 block discarded – undo
862 925
 	}
863 926
 
864 927
 	// A special case - we want the file and line numbers for debugging.
865
-	if ($error_type == 'return')
866
-		return array($file, $line);
928
+	if ($error_type == 'return') {
929
+			return array($file, $line);
930
+	}
867 931
 
868 932
 	// Is always a critical error.
869
-	if (function_exists('log_error'))
870
-		log_error($log_message, 'critical', $file, $line);
933
+	if (function_exists('log_error')) {
934
+			log_error($log_message, 'critical', $file, $line);
935
+	}
871 936
 
872 937
 	if (function_exists('fatal_error'))
873 938
 	{
@@ -875,12 +940,12 @@  discard block
 block discarded – undo
875 940
 
876 941
 		// Cannot continue...
877 942
 		exit;
943
+	} elseif ($error_type) {
944
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
945
+	} else {
946
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
947
+	}
878 948
 	}
879
-	elseif ($error_type)
880
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
881
-	else
882
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
883
-}
884 949
 
885 950
 /**
886 951
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -897,10 +962,11 @@  discard block
 block discarded – undo
897 962
 		'\\' => '\\\\',
898 963
 	);
899 964
 
900
-	if ($translate_human_wildcards)
901
-		$replacements += array(
965
+	if ($translate_human_wildcards) {
966
+			$replacements += array(
902 967
 			'*' => '%',
903 968
 		);
969
+	}
904 970
 
905 971
 	return strtr($string, $replacements);
906 972
 }
@@ -914,8 +980,9 @@  discard block
 block discarded – undo
914 980
  */
915 981
 function smf_is_resource($result)
916 982
 {
917
-	if ($result instanceof mysqli_result)
918
-		return true;
983
+	if ($result instanceof mysqli_result) {
984
+			return true;
985
+	}
919 986
 
920 987
 	return false;
921 988
 }
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +214 added lines, -159 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc'])) {
39
+			$smcFunc += array(
39 40
 			'db_query' => 'smf_db_query',
40 41
 			'db_quote' => 'smf_db_quote',
41 42
 			'db_insert' => 'smf_db_insert',
@@ -59,11 +60,13 @@  discard block
 block discarded – undo
59 60
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
60 61
 			'db_is_resource' => 'is_resource',
61 62
 		);
63
+	}
62 64
 
63
-	if (!empty($db_options['persist']))
64
-		$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
65
-	else
66
-		$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
65
+	if (!empty($db_options['persist'])) {
66
+			$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67
+	} else {
68
+			$connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
69
+	}
67 70
 
68 71
 	// Something's wrong, show an error if its fatal (which we assume it is)
69 72
 	if (!$connection)
@@ -71,8 +74,7 @@  discard block
 block discarded – undo
71 74
 		if (!empty($db_options['non_fatal']))
72 75
 		{
73 76
 			return null;
74
-		}
75
-		else
77
+		} else
76 78
 		{
77 79
 			display_db_error();
78 80
 		}
@@ -123,34 +125,42 @@  discard block
 block discarded – undo
123 125
 
124 126
 	list ($values, $connection) = $db_callback;
125 127
 
126
-	if ($matches[1] === 'db_prefix')
127
-		return $db_prefix;
128
+	if ($matches[1] === 'db_prefix') {
129
+			return $db_prefix;
130
+	}
128 131
 
129
-	if ($matches[1] === 'query_see_board')
130
-		return $user_info['query_see_board'];
132
+	if ($matches[1] === 'query_see_board') {
133
+			return $user_info['query_see_board'];
134
+	}
131 135
 
132
-	if ($matches[1] === 'query_wanna_see_board')
133
-		return $user_info['query_wanna_see_board'];
136
+	if ($matches[1] === 'query_wanna_see_board') {
137
+			return $user_info['query_wanna_see_board'];
138
+	}
134 139
 
135
-	if ($matches[1] === 'empty')
136
-		return '\'\'';
140
+	if ($matches[1] === 'empty') {
141
+			return '\'\'';
142
+	}
137 143
 
138
-	if (!isset($matches[2]))
139
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
144
+	if (!isset($matches[2])) {
145
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
146
+	}
140 147
 
141
-	if ($matches[1] === 'literal')
142
-		return '\'' . pg_escape_string($matches[2]) . '\'';
148
+	if ($matches[1] === 'literal') {
149
+			return '\'' . pg_escape_string($matches[2]) . '\'';
150
+	}
143 151
 
144
-	if (!isset($values[$matches[2]]))
145
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
152
+	if (!isset($values[$matches[2]])) {
153
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
154
+	}
146 155
 
147 156
 	$replacement = $values[$matches[2]];
148 157
 
149 158
 	switch ($matches[1])
150 159
 	{
151 160
 		case 'int':
152
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
153
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
161
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
162
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
163
+			}
154 164
 			return (string) (int) $replacement;
155 165
 		break;
156 166
 
@@ -162,56 +172,63 @@  discard block
 block discarded – undo
162 172
 		case 'array_int':
163 173
 			if (is_array($replacement))
164 174
 			{
165
-				if (empty($replacement))
166
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
175
+				if (empty($replacement)) {
176
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177
+				}
167 178
 
168 179
 				foreach ($replacement as $key => $value)
169 180
 				{
170
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
171
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
182
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+					}
172 184
 
173 185
 					$replacement[$key] = (string) (int) $value;
174 186
 				}
175 187
 
176 188
 				return implode(', ', $replacement);
189
+			} else {
190
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177 191
 			}
178
-			else
179
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
180 192
 
181 193
 		break;
182 194
 
183 195
 		case 'array_string':
184 196
 			if (is_array($replacement))
185 197
 			{
186
-				if (empty($replacement))
187
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198
+				if (empty($replacement)) {
199
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
200
+				}
188 201
 
189
-				foreach ($replacement as $key => $value)
190
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
202
+				foreach ($replacement as $key => $value) {
203
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
204
+				}
191 205
 
192 206
 				return implode(', ', $replacement);
207
+			} else {
208
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
193 209
 			}
194
-			else
195
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
196 210
 		break;
197 211
 
198 212
 		case 'date':
199
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
200
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
201
-			else
202
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
214
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
215
+			} else {
216
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
217
+			}
203 218
 		break;
204 219
 
205 220
 		case 'time':
206
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
207
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
208
-			else
209
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
222
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
223
+			} else {
224
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225
+			}
210 226
 		break;
211 227
 
212 228
 		case 'float':
213
-			if (!is_numeric($replacement))
214
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
229
+			if (!is_numeric($replacement)) {
230
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+			}
215 232
 			return (string) (float) $replacement;
216 233
 		break;
217 234
 
@@ -224,31 +241,36 @@  discard block
 block discarded – undo
224 241
 		break;
225 242
 
226 243
 		case 'inet':
227
-			if ($replacement == 'null' || $replacement == '')
228
-				return 'null';
229
-			if (inet_pton($replacement) === false)
230
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
244
+			if ($replacement == 'null' || $replacement == '') {
245
+							return 'null';
246
+			}
247
+			if (inet_pton($replacement) === false) {
248
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+			}
231 250
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
232 251
 
233 252
 		case 'array_inet':
234 253
 			if (is_array($replacement))
235 254
 			{
236
-				if (empty($replacement))
237
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
+				if (empty($replacement)) {
256
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257
+				}
238 258
 
239 259
 				foreach ($replacement as $key => $value)
240 260
 				{
241
-					if ($replacement == 'null' || $replacement == '')
242
-						$replacement[$key] = 'null';
243
-					if (!isValidIP($value))
244
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
261
+					if ($replacement == 'null' || $replacement == '') {
262
+											$replacement[$key] = 'null';
263
+					}
264
+					if (!isValidIP($value)) {
265
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+					}
245 267
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
246 268
 				}
247 269
 
248 270
 				return implode(', ', $replacement);
271
+			} else {
272
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249 273
 			}
250
-			else
251
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252 274
 		break;
253 275
 
254 276
 		default:
@@ -335,14 +357,16 @@  discard block
 block discarded – undo
335 357
 		),
336 358
 	);
337 359
 
338
-	if (isset($replacements[$identifier]))
339
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
360
+	if (isset($replacements[$identifier])) {
361
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
362
+	}
340 363
 
341 364
 	// Limits need to be a little different.
342 365
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
343 366
 
344
-	if (trim($db_string) == '')
345
-		return false;
367
+	if (trim($db_string) == '') {
368
+			return false;
369
+	}
346 370
 
347 371
 	// Comments that are allowed in a query are preg_removed.
348 372
 	static $allowed_comments_from = array(
@@ -362,8 +386,9 @@  discard block
 block discarded – undo
362 386
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
363 387
 	$db_replace_result = 0;
364 388
 
365
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
366
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
389
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
390
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
391
+	}
367 392
 
368 393
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
369 394
 	{
@@ -384,8 +409,9 @@  discard block
 block discarded – undo
384 409
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
385 410
 
386 411
 		// Initialize $db_cache if not already initialized.
387
-		if (!isset($db_cache))
388
-			$db_cache = array();
412
+		if (!isset($db_cache)) {
413
+					$db_cache = array();
414
+		}
389 415
 
390 416
 		if (!empty($_SESSION['debug_redirect']))
391 417
 		{
@@ -411,17 +437,18 @@  discard block
 block discarded – undo
411 437
 		while (true)
412 438
 		{
413 439
 			$pos = strpos($db_string, '\'', $pos + 1);
414
-			if ($pos === false)
415
-				break;
440
+			if ($pos === false) {
441
+							break;
442
+			}
416 443
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
417 444
 
418 445
 			while (true)
419 446
 			{
420 447
 				$pos1 = strpos($db_string, '\'', $pos + 1);
421 448
 				$pos2 = strpos($db_string, '\\', $pos + 1);
422
-				if ($pos1 === false)
423
-					break;
424
-				elseif ($pos2 === false || $pos2 > $pos1)
449
+				if ($pos1 === false) {
450
+									break;
451
+				} elseif ($pos2 === false || $pos2 > $pos1)
425 452
 				{
426 453
 					$pos = $pos1;
427 454
 					break;
@@ -437,26 +464,31 @@  discard block
 block discarded – undo
437 464
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
438 465
 
439 466
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
440
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
441
-			$fail = true;
467
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
468
+					$fail = true;
469
+		}
442 470
 		// Trying to change passwords, slow us down, or something?
443
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
444
-			$fail = true;
445
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
446
-			$fail = true;
471
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
472
+					$fail = true;
473
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
474
+					$fail = true;
475
+		}
447 476
 
448
-		if (!empty($fail) && function_exists('log_error'))
449
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
477
+		if (!empty($fail) && function_exists('log_error')) {
478
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
479
+		}
450 480
 	}
451 481
 
452 482
 	$db_last_result = @pg_query($connection, $db_string);
453 483
 
454
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
455
-		$db_last_result = smf_db_error($db_string, $connection);
484
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
485
+			$db_last_result = smf_db_error($db_string, $connection);
486
+	}
456 487
 
457 488
 	// Debugging.
458
-	if (isset($db_show_debug) && $db_show_debug === true)
459
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
489
+	if (isset($db_show_debug) && $db_show_debug === true) {
490
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
491
+	}
460 492
 
461 493
 	return $db_last_result;
462 494
 }
@@ -469,10 +501,11 @@  discard block
 block discarded – undo
469 501
 {
470 502
 	global $db_last_result, $db_replace_result;
471 503
 
472
-	if ($db_replace_result)
473
-		return $db_replace_result;
474
-	elseif ($result === null && !$db_last_result)
475
-		return 0;
504
+	if ($db_replace_result) {
505
+			return $db_replace_result;
506
+	} elseif ($result === null && !$db_last_result) {
507
+			return 0;
508
+	}
476 509
 
477 510
 	return pg_affected_rows($result === null ? $db_last_result : $result);
478 511
 }
@@ -496,8 +529,9 @@  discard block
 block discarded – undo
496 529
 		array(
497 530
 		)
498 531
 	);
499
-	if (!$request)
500
-		return false;
532
+	if (!$request) {
533
+			return false;
534
+	}
501 535
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
502 536
 	$smcFunc['db_free_result']($request);
503 537
 
@@ -518,12 +552,13 @@  discard block
 block discarded – undo
518 552
 	// Decide which connection to use
519 553
 	$connection = $connection === null ? $db_connection : $connection;
520 554
 
521
-	if ($type == 'begin')
522
-		return @pg_query($connection, 'BEGIN');
523
-	elseif ($type == 'rollback')
524
-		return @pg_query($connection, 'ROLLBACK');
525
-	elseif ($type == 'commit')
526
-		return @pg_query($connection, 'COMMIT');
555
+	if ($type == 'begin') {
556
+			return @pg_query($connection, 'BEGIN');
557
+	} elseif ($type == 'rollback') {
558
+			return @pg_query($connection, 'ROLLBACK');
559
+	} elseif ($type == 'commit') {
560
+			return @pg_query($connection, 'COMMIT');
561
+	}
527 562
 
528 563
 	return false;
529 564
 }
@@ -551,19 +586,22 @@  discard block
 block discarded – undo
551 586
 	$query_error = @pg_last_error($connection);
552 587
 
553 588
 	// Log the error.
554
-	if (function_exists('log_error'))
555
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
589
+	if (function_exists('log_error')) {
590
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
591
+	}
556 592
 
557 593
 	// Nothing's defined yet... just die with it.
558
-	if (empty($context) || empty($txt))
559
-		die($query_error);
594
+	if (empty($context) || empty($txt)) {
595
+			die($query_error);
596
+	}
560 597
 
561 598
 	// Show an error message, if possible.
562 599
 	$context['error_title'] = $txt['database_error'];
563
-	if (allowedTo('admin_forum'))
564
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
565
-	else
566
-		$context['error_message'] = $txt['try_again'];
600
+	if (allowedTo('admin_forum')) {
601
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
602
+	} else {
603
+			$context['error_message'] = $txt['try_again'];
604
+	}
567 605
 
568 606
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
569 607
 	{
@@ -585,12 +623,14 @@  discard block
 block discarded – undo
585 623
 {
586 624
 	global $db_row_count;
587 625
 
588
-	if ($counter !== false)
589
-		return pg_fetch_row($request, $counter);
626
+	if ($counter !== false) {
627
+			return pg_fetch_row($request, $counter);
628
+	}
590 629
 
591 630
 	// Reset the row counter...
592
-	if (!isset($db_row_count[(int) $request]))
593
-		$db_row_count[(int) $request] = 0;
631
+	if (!isset($db_row_count[(int) $request])) {
632
+			$db_row_count[(int) $request] = 0;
633
+	}
594 634
 
595 635
 	// Return the right row.
596 636
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -607,12 +647,14 @@  discard block
 block discarded – undo
607 647
 {
608 648
 	global $db_row_count;
609 649
 
610
-	if ($counter !== false)
611
-		return pg_fetch_assoc($request, $counter);
650
+	if ($counter !== false) {
651
+			return pg_fetch_assoc($request, $counter);
652
+	}
612 653
 
613 654
 	// Reset the row counter...
614
-	if (!isset($db_row_count[(int) $request]))
615
-		$db_row_count[(int) $request] = 0;
655
+	if (!isset($db_row_count[(int) $request])) {
656
+			$db_row_count[(int) $request] = 0;
657
+	}
616 658
 
617 659
 	// Return the right row.
618 660
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -665,11 +707,13 @@  discard block
 block discarded – undo
665 707
 
666 708
 	$replace = '';
667 709
 
668
-	if (empty($data))
669
-		return;
710
+	if (empty($data)) {
711
+			return;
712
+	}
670 713
 
671
-	if (!is_array($data[array_rand($data)]))
672
-		$data = array($data);
714
+	if (!is_array($data[array_rand($data)])) {
715
+			$data = array($data);
716
+	}
673 717
 
674 718
 	// Replace the prefix holder with the actual prefix.
675 719
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -688,11 +732,13 @@  discard block
 block discarded – undo
688 732
 			//pg 9.5 got replace support
689 733
 			$pg_version = $smcFunc['db_get_version']();
690 734
 			// if we got a Beta Version
691
-			if (stripos($pg_version, 'beta') !== false)
692
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
735
+			if (stripos($pg_version, 'beta') !== false) {
736
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
737
+			}
693 738
 			// or RC
694
-			if (stripos($pg_version, 'rc') !== false)
695
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
739
+			if (stripos($pg_version, 'rc') !== false) {
740
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
741
+			}
696 742
 
697 743
 			$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
698 744
 		}
@@ -711,8 +757,7 @@  discard block
 block discarded – undo
711 757
 					$key_str .= ($count_pk > 0 ? ',' : '');
712 758
 					$key_str .= $columnName;
713 759
 					$count_pk++;
714
-				}
715
-				else //normal field
760
+				} else //normal field
716 761
 				{
717 762
 					$col_str .= ($count > 0 ? ',' : '');
718 763
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
@@ -720,20 +765,21 @@  discard block
 block discarded – undo
720 765
 				}
721 766
 			}
722 767
 			$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
723
-		}
724
-		else
768
+		} else
725 769
 		{
726 770
 			foreach ($columns as $columnName => $type)
727 771
 			{
728 772
 				// Are we restricting the length?
729
-				if (strpos($type, 'string-') !== false)
730
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
731
-				else
732
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
773
+				if (strpos($type, 'string-') !== false) {
774
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
775
+				} else {
776
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
777
+				}
733 778
 
734 779
 				// A key? That's what we were looking for.
735
-				if (in_array($columnName, $keys))
736
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
780
+				if (in_array($columnName, $keys)) {
781
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
782
+				}
737 783
 				$count++;
738 784
 			}
739 785
 
@@ -769,10 +815,11 @@  discard block
 block discarded – undo
769 815
 		foreach ($columns as $columnName => $type)
770 816
 		{
771 817
 			// Are we restricting the length?
772
-			if (strpos($type, 'string-') !== false)
773
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
774
-			else
775
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
818
+			if (strpos($type, 'string-') !== false) {
819
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
820
+			} else {
821
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
822
+			}
776 823
 		}
777 824
 		$insertData = substr($insertData, 0, -2) . ')';
778 825
 
@@ -781,8 +828,9 @@  discard block
 block discarded – undo
781 828
 
782 829
 		// Here's where the variables are injected to the query.
783 830
 		$insertRows = array();
784
-		foreach ($data as $dataRow)
785
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
831
+		foreach ($data as $dataRow) {
832
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
833
+		}
786 834
 
787 835
 		// Do the insert.
788 836
 		$request = $smcFunc['db_query']('', '
@@ -799,19 +847,21 @@  discard block
 block discarded – undo
799 847
 
800 848
 		if ($with_returning && $request !== false)
801 849
 		{
802
-			if ($returnmode === 2)
803
-				$return_var = array();
850
+			if ($returnmode === 2) {
851
+							$return_var = array();
852
+			}
804 853
 
805 854
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
806 855
 			{
807
-				if (is_numeric($row[0])) // try to emulate mysql limitation
856
+				if (is_numeric($row[0])) {
857
+					// try to emulate mysql limitation
808 858
 				{
809 859
 					if ($returnmode === 1)
810 860
 						$return_var = $row[0];
811
-					elseif ($returnmode === 2)
812
-						$return_var[] = $row[0];
813
-				}
814
-				else
861
+				} elseif ($returnmode === 2) {
862
+											$return_var[] = $row[0];
863
+					}
864
+				} else
815 865
 				{
816 866
 					$with_returning = false;
817 867
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -820,9 +870,10 @@  discard block
 block discarded – undo
820 870
 		}
821 871
 	}
822 872
 	
823
-	if ($with_returning && !empty($return_var))
824
-		return $return_var; 
825
-}
873
+	if ($with_returning && !empty($return_var)) {
874
+			return $return_var;
875
+	}
876
+	}
826 877
 
827 878
 /**
828 879
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -859,8 +910,9 @@  discard block
 block discarded – undo
859 910
  */
860 911
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
861 912
 {
862
-	if (empty($log_message))
863
-		$log_message = $error_message;
913
+	if (empty($log_message)) {
914
+			$log_message = $error_message;
915
+	}
864 916
 
865 917
 	foreach (debug_backtrace() as $step)
866 918
 	{
@@ -879,12 +931,14 @@  discard block
 block discarded – undo
879 931
 	}
880 932
 
881 933
 	// A special case - we want the file and line numbers for debugging.
882
-	if ($error_type == 'return')
883
-		return array($file, $line);
934
+	if ($error_type == 'return') {
935
+			return array($file, $line);
936
+	}
884 937
 
885 938
 	// Is always a critical error.
886
-	if (function_exists('log_error'))
887
-		log_error($log_message, 'critical', $file, $line);
939
+	if (function_exists('log_error')) {
940
+			log_error($log_message, 'critical', $file, $line);
941
+	}
888 942
 
889 943
 	if (function_exists('fatal_error'))
890 944
 	{
@@ -892,12 +946,12 @@  discard block
 block discarded – undo
892 946
 
893 947
 		// Cannot continue...
894 948
 		exit;
949
+	} elseif ($error_type) {
950
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
951
+	} else {
952
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
953
+	}
895 954
 	}
896
-	elseif ($error_type)
897
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
898
-	else
899
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
900
-}
901 955
 
902 956
 /**
903 957
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -914,10 +968,11 @@  discard block
 block discarded – undo
914 968
 		'\\' => '\\\\',
915 969
 	);
916 970
 
917
-	if ($translate_human_wildcards)
918
-		$replacements += array(
971
+	if ($translate_human_wildcards) {
972
+			$replacements += array(
919 973
 			'*' => '%',
920 974
 		);
975
+	}
921 976
 
922 977
 	return strtr($string, $replacements);
923 978
 }
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 1 patch
Braces   +297 added lines, -224 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -54,21 +57,25 @@  discard block
 block discarded – undo
54 57
 
55 58
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
56 59
 	{
57
-			if (!is_array($modSettings['attachment_basedirectories']))
58
-				$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
60
+			if (!is_array($modSettings['attachment_basedirectories'])) {
61
+							$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
62
+			}
59 63
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
64
+	} else {
65
+			$base_dir = 0;
60 66
 	}
61
-	else
62
-		$base_dir = 0;
63 67
 
64 68
 	if ($modSettings['automanage_attachments'] == 1)
65 69
 	{
66
-		if (!isset($modSettings['last_attachments_directory']))
67
-			$modSettings['last_attachments_directory'] = array();
68
-		if (!is_array($modSettings['last_attachments_directory']))
69
-			$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
70
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
71
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
70
+		if (!isset($modSettings['last_attachments_directory'])) {
71
+					$modSettings['last_attachments_directory'] = array();
72
+		}
73
+		if (!is_array($modSettings['last_attachments_directory'])) {
74
+					$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
75
+		}
76
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
77
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
78
+		}
72 79
 	}
73 80
 
74 81
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -97,12 +104,14 @@  discard block
 block discarded – undo
97 104
 			$updir = '';
98 105
 	}
99 106
 
100
-	if (!is_array($modSettings['attachmentUploadDir']))
101
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
102
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
103
-		$outputCreation = automanage_attachments_create_directory($updir);
104
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
105
-		$outputCreation = true;
107
+	if (!is_array($modSettings['attachmentUploadDir'])) {
108
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
109
+	}
110
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
111
+			$outputCreation = automanage_attachments_create_directory($updir);
112
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
113
+			$outputCreation = true;
114
+	}
106 115
 
107 116
 	if ($outputCreation)
108 117
 	{
@@ -139,8 +148,9 @@  discard block
 block discarded – undo
139 148
 		$count = count($tree);
140 149
 
141 150
 		$directory = attachments_init_dir($tree, $count);
142
-		if ($directory === false)
143
-			return false;
151
+		if ($directory === false) {
152
+					return false;
153
+		}
144 154
 	}
145 155
 
146 156
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -168,8 +178,9 @@  discard block
 block discarded – undo
168 178
 	}
169 179
 
170 180
 	// Everything seems fine...let's create the .htaccess
171
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
172
-		secureDirectory($updir, true);
181
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
182
+			secureDirectory($updir, true);
183
+	}
173 184
 
174 185
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
175 186
 	$updir = rtrim($updir, $sep);
@@ -201,8 +212,9 @@  discard block
 block discarded – undo
201 212
 {
202 213
 	global $modSettings, $boarddir;
203 214
 
204
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
205
-		return;
215
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
216
+			return;
217
+	}
206 218
 
207 219
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
208 220
 	// Just to be sure: I don't want directory separators at the end
@@ -214,13 +226,14 @@  discard block
 block discarded – undo
214 226
 	{
215 227
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
216 228
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
229
+	} else {
230
+			$base_dir = 0;
217 231
 	}
218
-	else
219
-		$base_dir = 0;
220 232
 
221 233
 	// Get the last attachment directory for that base directory
222
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
223
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
234
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
235
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
236
+	}
224 237
 	// And increment it.
225 238
 	$modSettings['last_attachments_directory'][$base_dir]++;
226 239
 
@@ -235,10 +248,10 @@  discard block
 block discarded – undo
235 248
 		$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
236 249
 
237 250
 		return true;
251
+	} else {
252
+			return false;
253
+	}
238 254
 	}
239
-	else
240
-		return false;
241
-}
242 255
 
243 256
 /**
244 257
  * Split a path into a list of all directories and subdirectories
@@ -256,12 +269,13 @@  discard block
 block discarded – undo
256 269
 			* in Windows we need to explode for both \ and /
257 270
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
258 271
 	*/
259
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
260
-		$tree = preg_split('#[\\\/]#', $directory);
261
-	else
272
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
273
+			$tree = preg_split('#[\\\/]#', $directory);
274
+	} else
262 275
 	{
263
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
264
-			return false;
276
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
277
+					return false;
278
+		}
265 279
 
266 280
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
267 281
 	}
@@ -285,10 +299,11 @@  discard block
 block discarded – undo
285 299
 		 //Better be sure that the first part of the path is actually a drive letter...
286 300
 		 //...even if, I should check this in the admin page...isn't it?
287 301
 		 //...NHAAA Let's leave space for users' complains! :P
288
-		if (preg_match('/^[a-z]:$/i', $tree[0]))
289
-			$directory = array_shift($tree);
290
-		else
291
-			return false;
302
+		if (preg_match('/^[a-z]:$/i', $tree[0])) {
303
+					$directory = array_shift($tree);
304
+		} else {
305
+					return false;
306
+		}
292 307
 
293 308
 		$count--;
294 309
 	}
@@ -303,18 +318,20 @@  discard block
 block discarded – undo
303 318
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
304 319
 
305 320
 	// Make sure we're uploading to the right place.
306
-	if (!empty($modSettings['automanage_attachments']))
307
-		automanage_attachments_check_directory();
321
+	if (!empty($modSettings['automanage_attachments'])) {
322
+			automanage_attachments_check_directory();
323
+	}
308 324
 
309
-	if (!is_array($modSettings['attachmentUploadDir']))
310
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
325
+	if (!is_array($modSettings['attachmentUploadDir'])) {
326
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
327
+	}
311 328
 
312 329
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
313 330
 
314 331
 	// Is the attachments folder actualy there?
315
-	if (!empty($context['dir_creation_error']))
316
-		$initial_error = $context['dir_creation_error'];
317
-	elseif (!is_dir($context['attach_dir']))
332
+	if (!empty($context['dir_creation_error'])) {
333
+			$initial_error = $context['dir_creation_error'];
334
+	} elseif (!is_dir($context['attach_dir']))
318 335
 	{
319 336
 		$initial_error = 'attach_folder_warning';
320 337
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -337,12 +354,12 @@  discard block
 block discarded – undo
337 354
 			);
338 355
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
339 356
 			$smcFunc['db_free_result']($request);
340
-		}
341
-		else
342
-			$context['attachments'] = array(
357
+		} else {
358
+					$context['attachments'] = array(
343 359
 				'quantity' => 0,
344 360
 				'total_size' => 0,
345 361
 			);
362
+		}
346 363
 	}
347 364
 
348 365
 	// Hmm. There are still files in session.
@@ -352,39 +369,44 @@  discard block
 block discarded – undo
352 369
 		// Let's try to keep them. But...
353 370
 		$ignore_temp = true;
354 371
 		// If new files are being added. We can't ignore those
355
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
356
-			if (!empty($dummy))
372
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
373
+					if (!empty($dummy))
357 374
 			{
358 375
 				$ignore_temp = false;
376
+		}
359 377
 				break;
360 378
 			}
361 379
 
362 380
 		// Need to make space for the new files. So, bye bye.
363 381
 		if (!$ignore_temp)
364 382
 		{
365
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
366
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
383
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
384
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
367 385
 					unlink($attachment['tmp_name']);
386
+			}
368 387
 
369 388
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
370 389
 			$_SESSION['temp_attachments'] = array();
371 390
 		}
372 391
 	}
373 392
 
374
-	if (!isset($_FILES['attachment']['name']))
375
-		$_FILES['attachment']['tmp_name'] = array();
393
+	if (!isset($_FILES['attachment']['name'])) {
394
+			$_FILES['attachment']['tmp_name'] = array();
395
+	}
376 396
 
377
-	if (!isset($_SESSION['temp_attachments']))
378
-		$_SESSION['temp_attachments'] = array();
397
+	if (!isset($_SESSION['temp_attachments'])) {
398
+			$_SESSION['temp_attachments'] = array();
399
+	}
379 400
 
380 401
 	// Remember where we are at. If it's anywhere at all.
381
-	if (!$ignore_temp)
382
-		$_SESSION['temp_attachments']['post'] = array(
402
+	if (!$ignore_temp) {
403
+			$_SESSION['temp_attachments']['post'] = array(
383 404
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
384 405
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
385 406
 			'topic' => !empty($topic) ? $topic : 0,
386 407
 			'board' => !empty($board) ? $board : 0,
387 408
 		);
409
+	}
388 410
 
389 411
 	// If we have an initial error, lets just display it.
390 412
 	if (!empty($initial_error))
@@ -392,9 +414,10 @@  discard block
 block discarded – undo
392 414
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
393 415
 
394 416
 		// And delete the files 'cos they ain't going nowhere.
395
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
396
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
417
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
418
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
397 419
 				unlink($_FILES['attachment']['tmp_name'][$n]);
420
+		}
398 421
 
399 422
 		$_FILES['attachment']['tmp_name'] = array();
400 423
 	}
@@ -402,21 +425,24 @@  discard block
 block discarded – undo
402 425
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
403 426
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
404 427
 	{
405
-		if ($_FILES['attachment']['name'][$n] == '')
406
-			continue;
428
+		if ($_FILES['attachment']['name'][$n] == '') {
429
+					continue;
430
+		}
407 431
 
408 432
 		// First, let's first check for PHP upload errors.
409 433
 		$errors = array();
410 434
 		if (!empty($_FILES['attachment']['error'][$n]))
411 435
 		{
412
-			if ($_FILES['attachment']['error'][$n] == 2)
413
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
414
-			elseif ($_FILES['attachment']['error'][$n] == 6)
415
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
416
-			else
417
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
418
-			if (empty($errors))
419
-				$errors[] = 'attach_php_error';
436
+			if ($_FILES['attachment']['error'][$n] == 2) {
437
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
438
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
439
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
440
+			} else {
441
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
442
+			}
443
+			if (empty($errors)) {
444
+							$errors[] = 'attach_php_error';
445
+			}
420 446
 		}
421 447
 
422 448
 		// Try to move and rename the file before doing any more checks on it.
@@ -426,8 +452,9 @@  discard block
 block discarded – undo
426 452
 		{
427 453
 			// The reported MIME type of the attachment might not be reliable.
428 454
 			// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
429
-			if (function_exists('mime_content_type'))
430
-				$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
455
+			if (function_exists('mime_content_type')) {
456
+							$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
457
+			}
431 458
 
432 459
 			$_SESSION['temp_attachments'][$attachID] = array(
433 460
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -439,16 +466,16 @@  discard block
 block discarded – undo
439 466
 			);
440 467
 
441 468
 			// Move the file to the attachments folder with a temp name for now.
442
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
443
-				smf_chmod($destName, 0644);
444
-			else
469
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
470
+							smf_chmod($destName, 0644);
471
+			} else
445 472
 			{
446 473
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
447
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
448
-					unlink($_FILES['attachment']['tmp_name'][$n]);
474
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
475
+									unlink($_FILES['attachment']['tmp_name'][$n]);
476
+				}
449 477
 			}
450
-		}
451
-		else
478
+		} else
452 479
 		{
453 480
 			$_SESSION['temp_attachments'][$attachID] = array(
454 481
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -456,12 +483,14 @@  discard block
 block discarded – undo
456 483
 				'errors' => $errors,
457 484
 			);
458 485
 
459
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
460
-				unlink($_FILES['attachment']['tmp_name'][$n]);
486
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
487
+							unlink($_FILES['attachment']['tmp_name'][$n]);
488
+			}
461 489
 		}
462 490
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
463
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
464
-			attachmentChecks($attachID);
491
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
492
+					attachmentChecks($attachID);
493
+		}
465 494
 	}
466 495
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
467 496
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -488,21 +517,20 @@  discard block
 block discarded – undo
488 517
 	global $modSettings, $context, $sourcedir, $smcFunc;
489 518
 
490 519
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
491
-	if (empty($_SESSION['temp_attachments'][$attachID]))
492
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
493
-
494
-	elseif (empty($attachID))
495
-		$error = '$attachID';
496
-
497
-	elseif (empty($context['attachments']))
498
-		$error = '$context[\'attachments\']';
499
-
500
-	elseif (empty($context['attach_dir']))
501
-		$error = '$context[\'attach_dir\']';
520
+	if (empty($_SESSION['temp_attachments'][$attachID])) {
521
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
522
+	} elseif (empty($attachID)) {
523
+			$error = '$attachID';
524
+	} elseif (empty($context['attachments'])) {
525
+			$error = '$context[\'attachments\']';
526
+	} elseif (empty($context['attach_dir'])) {
527
+			$error = '$context[\'attach_dir\']';
528
+	}
502 529
 
503 530
 	// Let's get their attention.
504
-	if (!empty($error))
505
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
531
+	if (!empty($error)) {
532
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
533
+	}
506 534
 
507 535
 	// Just in case this slipped by the first checks, we stop it here and now
508 536
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -531,8 +559,9 @@  discard block
 block discarded – undo
531 559
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
532 560
 			if (!(empty($size)) && ($size[2] != $old_format))
533 561
 			{
534
-				if (isset($context['validImageTypes'][$size[2]]))
535
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
562
+				if (isset($context['validImageTypes'][$size[2]])) {
563
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
564
+				}
536 565
 			}
537 566
 		}
538 567
 	}
@@ -586,42 +615,48 @@  discard block
 block discarded – undo
586 615
 				// Or, let the user know that it ain't gonna happen.
587 616
 				else
588 617
 				{
589
-					if (isset($context['dir_creation_error']))
590
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
591
-					else
592
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
618
+					if (isset($context['dir_creation_error'])) {
619
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
620
+					} else {
621
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
622
+					}
593 623
 				}
624
+			} else {
625
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
594 626
 			}
595
-			else
596
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
597 627
 		}
598 628
 	}
599 629
 
600 630
 	// Is the file too big?
601 631
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
602
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
632
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
634
+	}
604 635
 
605 636
 	// Check the total upload size for this post...
606
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
607
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
637
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
638
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
639
+	}
608 640
 
609 641
 	// Have we reached the maximum number of files we are allowed?
610 642
 	$context['attachments']['quantity']++;
611 643
 
612 644
 	// Set a max limit if none exists
613
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
614
-		$modSettings['attachmentNumPerPostLimit'] = 50;
645
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
646
+			$modSettings['attachmentNumPerPostLimit'] = 50;
647
+	}
615 648
 
616
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
617
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
649
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
650
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
651
+	}
618 652
 
619 653
 	// File extension check
620 654
 	if (!empty($modSettings['attachmentCheckExtensions']))
621 655
 	{
622 656
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
623
-		foreach ($allowed as $k => $dummy)
624
-			$allowed[$k] = trim($dummy);
657
+		foreach ($allowed as $k => $dummy) {
658
+					$allowed[$k] = trim($dummy);
659
+		}
625 660
 
626 661
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
627 662
 		{
@@ -633,10 +668,12 @@  discard block
 block discarded – undo
633 668
 	// Undo the math if there's an error
634 669
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
635 670
 	{
636
-		if (isset($context['dir_size']))
637
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
638
-		if (isset($context['dir_files']))
639
-			$context['dir_files']--;
671
+		if (isset($context['dir_size'])) {
672
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
673
+		}
674
+		if (isset($context['dir_files'])) {
675
+					$context['dir_files']--;
676
+		}
640 677
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
641 678
 		$context['attachments']['quantity']--;
642 679
 		return false;
@@ -668,12 +705,14 @@  discard block
 block discarded – undo
668 705
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
669 706
 	{
670 707
 		// Got a proper mime type?
671
-		if (!empty($size['mime']))
672
-			$attachmentOptions['mime_type'] = $size['mime'];
708
+		if (!empty($size['mime'])) {
709
+					$attachmentOptions['mime_type'] = $size['mime'];
710
+		}
673 711
 
674 712
 		// Otherwise a valid one?
675
-		elseif (isset($context['validImageTypes'][$size[2]]))
676
-			$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
713
+		elseif (isset($context['validImageTypes'][$size[2]])) {
714
+					$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
715
+		}
677 716
 	}
678 717
 
679 718
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -685,15 +724,17 @@  discard block
 block discarded – undo
685 724
 	}
686 725
 
687 726
 	// Get the hash if no hash has been given yet.
688
-	if (empty($attachmentOptions['file_hash']))
689
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
727
+	if (empty($attachmentOptions['file_hash'])) {
728
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
729
+	}
690 730
 
691 731
 	// Assuming no-one set the extension let's take a look at it.
692 732
 	if (empty($attachmentOptions['fileext']))
693 733
 	{
694 734
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
695
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
696
-			$attachmentOptions['fileext'] = '';
735
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
736
+					$attachmentOptions['fileext'] = '';
737
+		}
697 738
 	}
698 739
 
699 740
 	// Last chance to change stuff!
@@ -702,8 +743,9 @@  discard block
 block discarded – undo
702 743
 	// Make sure the folder is valid...
703 744
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true);
704 745
 	$folders = array_keys($tmp);
705
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
706
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
746
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
747
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
748
+	}
707 749
 
708 750
 	$attachmentOptions['id'] = $smcFunc['db_insert']('',
709 751
 		'{db_prefix}attachments',
@@ -734,8 +776,8 @@  discard block
 block discarded – undo
734 776
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
735 777
 
736 778
 	// If it's not approved then add to the approval queue.
737
-	if (!$attachmentOptions['approved'])
738
-		$smcFunc['db_insert']('',
779
+	if (!$attachmentOptions['approved']) {
780
+			$smcFunc['db_insert']('',
739 781
 			'{db_prefix}approval_queue',
740 782
 			array(
741 783
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -745,9 +787,11 @@  discard block
 block discarded – undo
745 787
 			),
746 788
 			array()
747 789
 		);
790
+	}
748 791
 
749
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
750
-		return true;
792
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
793
+			return true;
794
+	}
751 795
 
752 796
 	// Like thumbnails, do we?
753 797
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -758,13 +802,15 @@  discard block
 block discarded – undo
758 802
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
759 803
 			list ($thumb_width, $thumb_height) = $size;
760 804
 
761
-			if (!empty($size['mime']))
762
-				$thumb_mime = $size['mime'];
763
-			elseif (isset($context['validImageTypes'][$size[2]]))
764
-				$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
805
+			if (!empty($size['mime'])) {
806
+							$thumb_mime = $size['mime'];
807
+			} elseif (isset($context['validImageTypes'][$size[2]])) {
808
+							$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
809
+			}
765 810
 			// Lord only knows how this happened...
766
-			else
767
-				$thumb_mime = '';
811
+			else {
812
+							$thumb_mime = '';
813
+			}
768 814
 
769 815
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
770 816
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -844,15 +890,17 @@  discard block
 block discarded – undo
844 890
 	global $smcFunc;
845 891
 
846 892
 	// Oh, come on!
847
-	if (empty($attachIDs) || empty($msgID))
848
-		return false;
893
+	if (empty($attachIDs) || empty($msgID)) {
894
+			return false;
895
+	}
849 896
 
850 897
 	// "I see what is right and approve, but I do what is wrong."
851 898
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
852 899
 
853 900
 	// One last check
854
-	if (empty($attachIDs))
855
-		return false;
901
+	if (empty($attachIDs)) {
902
+			return false;
903
+	}
856 904
 
857 905
 	// Perform.
858 906
 	$smcFunc['db_query']('', '
@@ -882,8 +930,9 @@  discard block
 block discarded – undo
882 930
 	$externalParse = false;
883 931
 
884 932
 	// Meh...
885
-	if (empty($attachID))
886
-		return 'attachments_no_data_loaded';
933
+	if (empty($attachID)) {
934
+			return 'attachments_no_data_loaded';
935
+	}
887 936
 
888 937
 	// Make it easy.
889 938
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -892,20 +941,23 @@  discard block
 block discarded – undo
892 941
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
893 942
 
894 943
 	// "I am innocent of the blood of this just person: see ye to it."
895
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
896
-		return $externalParse;
944
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
945
+			return $externalParse;
946
+	}
897 947
 
898 948
 	//Are attachments enable?
899
-	if (empty($modSettings['attachmentEnable']))
900
-		return 'attachments_not_enable';
949
+	if (empty($modSettings['attachmentEnable'])) {
950
+			return 'attachments_not_enable';
951
+	}
901 952
 
902 953
 	// Previewing much? no msg ID has been set yet.
903 954
 	if (!empty($context['preview_message']))
904 955
 	{
905 956
 		$allAttachments = getAttachsByMsg(0);
906 957
 
907
-		if (empty($allAttachments[0][$attachID]))
908
-			return 'attachments_no_data_loaded';
958
+		if (empty($allAttachments[0][$attachID])) {
959
+					return 'attachments_no_data_loaded';
960
+		}
909 961
 
910 962
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
911 963
 
@@ -917,57 +969,66 @@  discard block
 block discarded – undo
917 969
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
918 970
 
919 971
 		// Fix the thumbnail too, if the image has one.
920
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
921
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
973
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
974
+		}
922 975
 
923 976
 		return $attachContext;
924 977
 	}
925 978
 
926 979
 	// There is always the chance someone else has already done our dirty work...
927 980
 	// If so, all pertinent checks were already done. Hopefully...
928
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
929
-		return $context['current_attachments'][$attachID];
981
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
982
+			return $context['current_attachments'][$attachID];
983
+	}
930 984
 
931 985
 	// If we are lucky enough to be in $board's scope then check it!
932
-	if (!empty($board) && !allowedTo('view_attachments', $board))
933
-		return 'attachments_not_allowed_to_see';
986
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
987
+			return 'attachments_not_allowed_to_see';
988
+	}
934 989
 
935 990
 	// Get the message info associated with this particular attach ID.
936 991
 	$attachInfo = getAttachMsgInfo($attachID);
937 992
 
938 993
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
939
-	if (empty($attachInfo) || empty($attachInfo['msg']))
940
-		return 'attachments_no_msg_associated';
994
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
995
+			return 'attachments_no_msg_associated';
996
+	}
941 997
 
942 998
 	// Hold it! got the info now check if you can see this attachment.
943
-	if (!allowedTo('view_attachments', $attachInfo['board']))
944
-		return 'attachments_not_allowed_to_see';
999
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
1000
+			return 'attachments_not_allowed_to_see';
1001
+	}
945 1002
 
946 1003
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
947 1004
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
948 1005
 
949 1006
 	// No point in keep going further.
950
-	if (!allowedTo('view_attachments', $attachContext['board']))
951
-		return 'attachments_not_allowed_to_see';
1007
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1008
+			return 'attachments_not_allowed_to_see';
1009
+	}
952 1010
 
953 1011
 	// Load this particular attach's context.
954
-	if (!empty($attachContext))
955
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	if (!empty($attachContext)) {
1013
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1014
+	}
956 1015
 
957 1016
 	// One last check, you know, gotta be paranoid...
958
-	else
959
-		return 'attachments_no_data_loaded';
1017
+	else {
1018
+			return 'attachments_no_data_loaded';
1019
+	}
960 1020
 
961 1021
 	// This is the last "if" I promise!
962
-	if (empty($attachLoaded))
963
-		return 'attachments_no_data_loaded';
964
-
965
-	else
966
-		$attachContext = $attachLoaded[$attachID];
1022
+	if (empty($attachLoaded)) {
1023
+			return 'attachments_no_data_loaded';
1024
+	} else {
1025
+			$attachContext = $attachLoaded[$attachID];
1026
+	}
967 1027
 
968 1028
 	// You may or may not want to show this under the post.
969
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
970
-		$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1030
+			$context['show_attach_under_post'][$attachID] = $attachID;
1031
+	}
971 1032
 
972 1033
 	// Last minute changes?
973 1034
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -987,8 +1048,9 @@  discard block
 block discarded – undo
987 1048
 {
988 1049
 	global $smcFunc, $modSettings;
989 1050
 
990
-	if (empty($attachIDs))
991
-		return array();
1051
+	if (empty($attachIDs)) {
1052
+			return array();
1053
+	}
992 1054
 
993 1055
 	$return = array();
994 1056
 
@@ -1004,11 +1066,12 @@  discard block
 block discarded – undo
1004 1066
 		)
1005 1067
 	);
1006 1068
 
1007
-	if ($smcFunc['db_num_rows']($request) != 1)
1008
-		return array();
1069
+	if ($smcFunc['db_num_rows']($request) != 1) {
1070
+			return array();
1071
+	}
1009 1072
 
1010
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1011
-		$return[$row['id_attach']] = array(
1073
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1074
+			$return[$row['id_attach']] = array(
1012 1075
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1013 1076
 			'size' => $row['size'],
1014 1077
 			'attachID' => $row['id_attach'],
@@ -1017,6 +1080,7 @@  discard block
 block discarded – undo
1017 1080
 			'mime_type' => $row['mime_type'],
1018 1081
 			'thumb' => $row['id_thumb'],
1019 1082
 		);
1083
+	}
1020 1084
 	$smcFunc['db_free_result']($request);
1021 1085
 
1022 1086
 	return $return;
@@ -1033,8 +1097,9 @@  discard block
 block discarded – undo
1033 1097
 {
1034 1098
 	global $smcFunc;
1035 1099
 
1036
-	if (empty($attachID))
1037
-		return array();
1100
+	if (empty($attachID)) {
1101
+			return array();
1102
+	}
1038 1103
 
1039 1104
 	$request = $smcFunc['db_query']('', '
1040 1105
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1047,8 +1112,9 @@  discard block
 block discarded – undo
1047 1112
 		)
1048 1113
 	);
1049 1114
 
1050
-	if ($smcFunc['db_num_rows']($request) != 1)
1051
-		return array();
1115
+	if ($smcFunc['db_num_rows']($request) != 1) {
1116
+			return array();
1117
+	}
1052 1118
 
1053 1119
 	$row = $smcFunc['db_fetch_assoc']($request);
1054 1120
 	$smcFunc['db_free_result']($request);
@@ -1089,8 +1155,9 @@  discard block
 block discarded – undo
1089 1155
 		$temp = array();
1090 1156
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1091 1157
 		{
1092
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1093
-				continue;
1158
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1159
+							continue;
1160
+			}
1094 1161
 
1095 1162
 			$temp[$row['id_attach']] = $row;
1096 1163
 		}
@@ -1119,8 +1186,9 @@  discard block
 block discarded – undo
1119 1186
 {
1120 1187
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1121 1188
 
1122
-	if (empty($attachments) || empty($attachments[$id_msg]))
1123
-		return array();
1189
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1190
+			return array();
1191
+	}
1124 1192
 
1125 1193
 	// Set up the attachment info - based on code by Meriadoc.
1126 1194
 	$attachmentData = array();
@@ -1144,11 +1212,13 @@  discard block
 block discarded – undo
1144 1212
 			);
1145 1213
 
1146 1214
 			// If something is unapproved we'll note it so we can sort them.
1147
-			if (!$attachment['approved'])
1148
-				$have_unapproved = true;
1215
+			if (!$attachment['approved']) {
1216
+							$have_unapproved = true;
1217
+			}
1149 1218
 
1150
-			if (!$attachmentData[$i]['is_image'])
1151
-				continue;
1219
+			if (!$attachmentData[$i]['is_image']) {
1220
+							continue;
1221
+			}
1152 1222
 
1153 1223
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1154 1224
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1169,12 +1239,12 @@  discard block
 block discarded – undo
1169 1239
 						// So what folder are we putting this image in?
1170 1240
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1171 1241
 						{
1172
-							if (!is_array($modSettings['attachmentUploadDir']))
1173
-								$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1242
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1243
+															$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1244
+							}
1174 1245
 							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
1175 1246
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1176
-						}
1177
-						else
1247
+						} else
1178 1248
 						{
1179 1249
 							$path = $modSettings['attachmentUploadDir'];
1180 1250
 							$id_folder_thumb = 1;
@@ -1189,10 +1259,11 @@  discard block
 block discarded – undo
1189 1259
 						$thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : '';
1190 1260
 
1191 1261
 						// Figure out the mime type.
1192
-						if (!empty($size['mime']))
1193
-							$thumb_mime = $size['mime'];
1194
-						else
1195
-							$thumb_mime = 'image/' . $thumb_ext;
1262
+						if (!empty($size['mime'])) {
1263
+													$thumb_mime = $size['mime'];
1264
+						} else {
1265
+													$thumb_mime = 'image/' . $thumb_ext;
1266
+						}
1196 1267
 
1197 1268
 						$thumb_filename = $attachment['filename'] . '_thumb';
1198 1269
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1239,11 +1310,12 @@  discard block
 block discarded – undo
1239 1310
 				}
1240 1311
 			}
1241 1312
 
1242
-			if (!empty($attachment['id_thumb']))
1243
-				$attachmentData[$i]['thumbnail'] = array(
1313
+			if (!empty($attachment['id_thumb'])) {
1314
+							$attachmentData[$i]['thumbnail'] = array(
1244 1315
 					'id' => $attachment['id_thumb'],
1245 1316
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1246 1317
 				);
1318
+			}
1247 1319
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1248 1320
 
1249 1321
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1253,30 +1325,31 @@  discard block
 block discarded – undo
1253 1325
 				{
1254 1326
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1255 1327
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1256
-				}
1257
-				elseif (!empty($modSettings['max_image_width']))
1328
+				} elseif (!empty($modSettings['max_image_width']))
1258 1329
 				{
1259 1330
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1260 1331
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1261 1332
 				}
1262
-			}
1263
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1333
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1264 1334
 			{
1265 1335
 				// If the image is too large to show inline, make it a popup.
1266
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1267
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1268
-				else
1269
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1336
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1337
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1338
+				} else {
1339
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1340
+				}
1270 1341
 			}
1271 1342
 
1272
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1273
-				$attachmentData[$i]['downloads']++;
1343
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1344
+							$attachmentData[$i]['downloads']++;
1345
+			}
1274 1346
 		}
1275 1347
 	}
1276 1348
 
1277 1349
 	// Do we need to instigate a sort?
1278
-	if ($have_unapproved)
1279
-		usort($attachmentData, 'approved_attach_sort');
1350
+	if ($have_unapproved) {
1351
+			usort($attachmentData, 'approved_attach_sort');
1352
+	}
1280 1353
 
1281 1354
 	return $attachmentData;
1282 1355
 }
Please login to merge, or discard this patch.
Sources/News.php 1 patch
Braces   +220 added lines, -181 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Outputs xml data representing recent information or a profile.
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	global $query_this_board, $smcFunc, $forum_version;
38 39
 
39 40
 	// If it's not enabled, die.
40
-	if (empty($modSettings['xmlnews_enable']))
41
-		obExit(false);
41
+	if (empty($modSettings['xmlnews_enable'])) {
42
+			obExit(false);
43
+	}
42 44
 
43 45
 	loadLanguage('Stats');
44 46
 
@@ -63,8 +65,9 @@  discard block
 block discarded – undo
63 65
 	if (!empty($_REQUEST['c']) && empty($board))
64 66
 	{
65 67
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
66
-		foreach ($_REQUEST['c'] as $i => $c)
67
-			$_REQUEST['c'][$i] = (int) $c;
68
+		foreach ($_REQUEST['c'] as $i => $c) {
69
+					$_REQUEST['c'][$i] = (int) $c;
70
+		}
68 71
 
69 72
 		if (count($_REQUEST['c']) == 1)
70 73
 		{
@@ -100,18 +103,20 @@  discard block
 block discarded – undo
100 103
 		}
101 104
 		$smcFunc['db_free_result']($request);
102 105
 
103
-		if (!empty($boards))
104
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
106
+		if (!empty($boards)) {
107
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
108
+		}
105 109
 
106 110
 		// Try to limit the number of messages we look through.
107
-		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15)
108
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
109
-	}
110
-	elseif (!empty($_REQUEST['boards']))
111
+		if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) {
112
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5);
113
+		}
114
+	} elseif (!empty($_REQUEST['boards']))
111 115
 	{
112 116
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
113
-		foreach ($_REQUEST['boards'] as $i => $b)
114
-			$_REQUEST['boards'][$i] = (int) $b;
117
+		foreach ($_REQUEST['boards'] as $i => $b) {
118
+					$_REQUEST['boards'][$i] = (int) $b;
119
+		}
115 120
 
116 121
 		$request = $smcFunc['db_query']('', '
117 122
 			SELECT b.id_board, b.num_posts, b.name
@@ -127,29 +132,32 @@  discard block
 block discarded – undo
127 132
 
128 133
 		// Either the board specified doesn't exist or you have no access.
129 134
 		$num_boards = $smcFunc['db_num_rows']($request);
130
-		if ($num_boards == 0)
131
-			fatal_lang_error('no_board');
135
+		if ($num_boards == 0) {
136
+					fatal_lang_error('no_board');
137
+		}
132 138
 
133 139
 		$total_posts = 0;
134 140
 		$boards = array();
135 141
 		while ($row = $smcFunc['db_fetch_assoc']($request))
136 142
 		{
137
-			if ($num_boards == 1)
138
-				$feed_meta['title'] = ' - ' . strip_tags($row['name']);
143
+			if ($num_boards == 1) {
144
+							$feed_meta['title'] = ' - ' . strip_tags($row['name']);
145
+			}
139 146
 
140 147
 			$boards[] = $row['id_board'];
141 148
 			$total_posts += $row['num_posts'];
142 149
 		}
143 150
 		$smcFunc['db_free_result']($request);
144 151
 
145
-		if (!empty($boards))
146
-			$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
152
+		if (!empty($boards)) {
153
+					$query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')';
154
+		}
147 155
 
148 156
 		// The more boards, the more we're going to look through...
149
-		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12)
150
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
151
-	}
152
-	elseif (!empty($board))
157
+		if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) {
158
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5);
159
+		}
160
+	} elseif (!empty($board))
153 161
 	{
154 162
 		$request = $smcFunc['db_query']('', '
155 163
 			SELECT num_posts
@@ -168,10 +176,10 @@  discard block
 block discarded – undo
168 176
 		$query_this_board = 'b.id_board = ' . $board;
169 177
 
170 178
 		// Try to look through just a few messages, if at all possible.
171
-		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10)
172
-			$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
173
-	}
174
-	else
179
+		if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) {
180
+					$context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5);
181
+		}
182
+	} else
175 183
 	{
176 184
 		$query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
177 185
 			AND b.id_board != ' . $modSettings['recycle_board'] : '');
@@ -194,30 +202,35 @@  discard block
 block discarded – undo
194 202
 	// Easy adding of sub actions
195 203
  	call_integration_hook('integrate_xmlfeeds', array(&$subActions));
196 204
 
197
-	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']]))
198
-		$_GET['sa'] = 'recent';
205
+	if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) {
206
+			$_GET['sa'] = 'recent';
207
+	}
199 208
 
200 209
 	// We only want some information, not all of it.
201 210
 	$cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']);
202
-	foreach (array('board', 'boards', 'c') as $var)
203
-		if (isset($_REQUEST[$var]))
211
+	foreach (array('board', 'boards', 'c') as $var) {
212
+			if (isset($_REQUEST[$var]))
204 213
 			$cachekey[] = $_REQUEST[$var];
214
+	}
205 215
 	$cachekey = md5(json_encode($cachekey) . (!empty($query_this_board) ? $query_this_board : ''));
206 216
 	$cache_t = microtime();
207 217
 
208 218
 	// Get the associative array representing the xml.
209
-	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3))
210
-		$xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
219
+	if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) {
220
+			$xml = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240);
221
+	}
211 222
 	if (empty($xml))
212 223
 	{
213 224
 		$call = call_helper($subActions[$_GET['sa']][0], true);
214 225
 
215
-		if (!empty($call))
216
-			$xml = call_user_func($call, $xml_format);
226
+		if (!empty($call)) {
227
+					$xml = call_user_func($call, $xml_format);
228
+		}
217 229
 
218 230
 		if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3)
219
-		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2))))
220
-			cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240);
231
+		|| (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) {
232
+					cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml, 240);
233
+		}
221 234
 	}
222 235
 
223 236
 	$feed_meta['title'] = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_meta['title']) ? $feed_meta['title'] : '');
@@ -272,32 +285,36 @@  discard block
 block discarded – undo
272 285
 	$ns_string = '';
273 286
 	if (!empty($namespaces[$xml_format]))
274 287
 	{
275
-		foreach ($namespaces[$xml_format] as $nsprefix => $nsurl)
276
-			$ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"';
288
+		foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) {
289
+					$ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"';
290
+		}
277 291
 	}
278 292
 
279 293
 	$extraFeedTags_string = '';
280 294
 	if (!empty($extraFeedTags[$xml_format]))
281 295
 	{
282
-		foreach ($extraFeedTags[$xml_format] as $extraTag)
283
-			$extraFeedTags_string .= "\n\t\t" . $extraTag;
296
+		foreach ($extraFeedTags[$xml_format] as $extraTag) {
297
+					$extraFeedTags_string .= "\n\t\t" . $extraTag;
298
+		}
284 299
 	}
285 300
 
286 301
 	// This is an xml file....
287 302
 	ob_end_clean();
288
-	if (!empty($modSettings['enableCompressedOutput']))
289
-		@ob_start('ob_gzhandler');
290
-	else
291
-		ob_start();
303
+	if (!empty($modSettings['enableCompressedOutput'])) {
304
+			@ob_start('ob_gzhandler');
305
+	} else {
306
+			ob_start();
307
+	}
292 308
 
293
-	if ($xml_format == 'smf' || isset($_REQUEST['debug']))
294
-		header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
295
-	elseif ($xml_format == 'rss' || $xml_format == 'rss2')
296
-		header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
297
-	elseif ($xml_format == 'atom')
298
-		header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
299
-	elseif ($xml_format == 'rdf')
300
-		header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
309
+	if ($xml_format == 'smf' || isset($_REQUEST['debug'])) {
310
+			header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
311
+	} elseif ($xml_format == 'rss' || $xml_format == 'rss2') {
312
+			header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
313
+	} elseif ($xml_format == 'atom') {
314
+			header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
315
+	} elseif ($xml_format == 'rdf') {
316
+			header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
317
+	}
301 318
 
302 319
 	// First, output the xml header.
303 320
 	echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>';
@@ -305,10 +322,11 @@  discard block
 block discarded – undo
305 322
 	// Are we outputting an rss feed or one with more information?
306 323
 	if ($xml_format == 'rss' || $xml_format == 'rss2')
307 324
 	{
308
-		if ($xml_format == 'rss2')
309
-			foreach ($_REQUEST as $var => $val)
325
+		if ($xml_format == 'rss2') {
326
+					foreach ($_REQUEST as $var => $val)
310 327
 				if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
311 328
 					$url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val);
329
+		}
312 330
 
313 331
 		// Start with an RSS 2.0 header.
314 332
 		echo '
@@ -327,9 +345,10 @@  discard block
 block discarded – undo
327 345
 		<copyright>' . $feed_meta['rights'] . '</copyright>' : '';
328 346
 
329 347
 		// RSS2 calls for this.
330
-		if ($xml_format == 'rss2')
331
-			echo '
348
+		if ($xml_format == 'rss2') {
349
+					echo '
332 350
 		<atom:link rel="self" type="application/rss+xml" href="', $scripturl, !empty($url_parts) ? '?' . implode(';', $url_parts) : '', '" />';
351
+		}
333 352
 
334 353
 		echo $extraFeedTags_string;
335 354
 
@@ -340,12 +359,12 @@  discard block
 block discarded – undo
340 359
 		echo '
341 360
 	</channel>
342 361
 </rss>';
343
-	}
344
-	elseif ($xml_format == 'atom')
362
+	} elseif ($xml_format == 'atom')
345 363
 	{
346
-		foreach ($_REQUEST as $var => $val)
347
-			if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
364
+		foreach ($_REQUEST as $var => $val) {
365
+					if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit')))
348 366
 				$url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val);
367
+		}
349 368
 
350 369
 		echo '
351 370
 <feed', $ns_string, '>
@@ -371,8 +390,7 @@  discard block
 block discarded – undo
371 390
 
372 391
 		echo '
373 392
 </feed>';
374
-	}
375
-	elseif ($xml_format == 'rdf')
393
+	} elseif ($xml_format == 'rdf')
376 394
 	{
377 395
 		echo '
378 396
 <rdf:RDF', $ns_string, '>
@@ -437,13 +455,15 @@  discard block
 block discarded – undo
437 455
 {
438 456
 	global $modSettings, $context, $scripturl;
439 457
 
440
-	if (substr($val, 0, strlen($scripturl)) != $scripturl)
441
-		return $val;
458
+	if (substr($val, 0, strlen($scripturl)) != $scripturl) {
459
+			return $val;
460
+	}
442 461
 
443 462
 	call_integration_hook('integrate_fix_url', array(&$val));
444 463
 
445
-	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd']))
446
-		return $val;
464
+	if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) {
465
+			return $val;
466
+	}
447 467
 
448 468
 	$val = preg_replace_callback('~\b' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function($m) use ($scripturl)
449 469
 		{
@@ -466,8 +486,9 @@  discard block
 block discarded – undo
466 486
 	global $smcFunc;
467 487
 
468 488
 	// Do we even need to do this?
469
-	if (strpbrk($data, '<>&') == false && $force !== true)
470
-		return $data;
489
+	if (strpbrk($data, '<>&') == false && $force !== true) {
490
+			return $data;
491
+	}
471 492
 
472 493
 	$cdata = '<![CDATA[';
473 494
 
@@ -477,49 +498,55 @@  discard block
 block discarded – undo
477 498
 			$smcFunc['strpos']($data, '&', $pos),
478 499
 			$smcFunc['strpos']($data, ']', $pos),
479 500
 		);
480
-		if ($ns != '')
481
-			$positions[] = $smcFunc['strpos']($data, '<', $pos);
501
+		if ($ns != '') {
502
+					$positions[] = $smcFunc['strpos']($data, '<', $pos);
503
+		}
482 504
 		foreach ($positions as $k => $dummy)
483 505
 		{
484
-			if ($dummy === false)
485
-				unset($positions[$k]);
506
+			if ($dummy === false) {
507
+							unset($positions[$k]);
508
+			}
486 509
 		}
487 510
 
488 511
 		$old = $pos;
489 512
 		$pos = empty($positions) ? $n : min($positions);
490 513
 
491
-		if ($pos - $old > 0)
492
-			$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
493
-		if ($pos >= $n)
494
-			break;
514
+		if ($pos - $old > 0) {
515
+					$cdata .= $smcFunc['substr']($data, $old, $pos - $old);
516
+		}
517
+		if ($pos >= $n) {
518
+					break;
519
+		}
495 520
 
496 521
 		if ($smcFunc['substr']($data, $pos, 1) == '<')
497 522
 		{
498 523
 			$pos2 = $smcFunc['strpos']($data, '>', $pos);
499
-			if ($pos2 === false)
500
-				$pos2 = $n;
501
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '/')
502
-				$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
503
-			else
504
-				$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
524
+			if ($pos2 === false) {
525
+							$pos2 = $n;
526
+			}
527
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '/') {
528
+							$cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA[';
529
+			} else {
530
+							$cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '<![CDATA[';
531
+			}
505 532
 			$pos = $pos2 + 1;
506
-		}
507
-		elseif ($smcFunc['substr']($data, $pos, 1) == ']')
533
+		} elseif ($smcFunc['substr']($data, $pos, 1) == ']')
508 534
 		{
509 535
 			$cdata .= ']]>&#093;<![CDATA[';
510 536
 			$pos++;
511
-		}
512
-		elseif ($smcFunc['substr']($data, $pos, 1) == '&')
537
+		} elseif ($smcFunc['substr']($data, $pos, 1) == '&')
513 538
 		{
514 539
 			$pos2 = $smcFunc['strpos']($data, ';', $pos);
515
-			if ($pos2 === false)
516
-				$pos2 = $n;
540
+			if ($pos2 === false) {
541
+							$pos2 = $n;
542
+			}
517 543
 			$ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1);
518 544
 
519
-			if ($smcFunc['substr']($data, $pos + 1, 1) == '#')
520
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
521
-			elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot')))
522
-				$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
545
+			if ($smcFunc['substr']($data, $pos + 1, 1) == '#') {
546
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
547
+			} elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) {
548
+							$cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA[';
549
+			}
523 550
 
524 551
 			$pos = $pos2 + 1;
525 552
 		}
@@ -558,8 +585,9 @@  discard block
 block discarded – undo
558 585
 		'gender',
559 586
 		'blurb',
560 587
 	);
561
-	if ($xml_format != 'atom')
562
-		$keysToCdata[] = 'category';
588
+	if ($xml_format != 'atom') {
589
+			$keysToCdata[] = 'category';
590
+	}
563 591
 
564 592
 	if (!empty($forceCdataKeys))
565 593
 	{
@@ -576,8 +604,9 @@  discard block
 block discarded – undo
576 604
 		$attrs = isset($element['attributes']) ? $element['attributes'] : null;
577 605
 
578 606
 		// Skip it, it's been set to null.
579
-		if ($key === null || ($val === null && $attrs === null))
580
-			continue;
607
+		if ($key === null || ($val === null && $attrs === null)) {
608
+					continue;
609
+		}
581 610
 
582 611
 		$forceCdata = in_array($key, $forceCdataKeys);
583 612
 		$ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : '';
@@ -590,16 +619,16 @@  discard block
 block discarded – undo
590 619
 
591 620
 		if (!empty($attrs))
592 621
 		{
593
-			foreach ($attrs as $attr_key => $attr_value)
594
-				echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"';
622
+			foreach ($attrs as $attr_key => $attr_value) {
623
+							echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"';
624
+			}
595 625
 		}
596 626
 
597 627
 		// If it's empty, simply output an empty element.
598 628
 		if (empty($val))
599 629
 		{
600 630
 			echo ' />';
601
-		}
602
-		else
631
+		} else
603 632
 		{
604 633
 			echo '>';
605 634
 
@@ -611,11 +640,13 @@  discard block
 block discarded – undo
611 640
 				echo "\n", str_repeat("\t", $i);
612 641
 			}
613 642
 			// A string with returns in it.... show this as a multiline element.
614
-			elseif (strpos($val, "\n") !== false)
615
-				echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i);
643
+			elseif (strpos($val, "\n") !== false) {
644
+							echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i);
645
+			}
616 646
 			// A simple string.
617
-			else
618
-				echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val);
647
+			else {
648
+							echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val);
649
+			}
619 650
 
620 651
 			// Ending tag.
621 652
 			echo '</', $key, '>';
@@ -635,8 +666,9 @@  discard block
 block discarded – undo
635 666
 {
636 667
 	global $scripturl, $smcFunc;
637 668
 
638
-	if (!allowedTo('view_mlist'))
639
-		return array();
669
+	if (!allowedTo('view_mlist')) {
670
+			return array();
671
+	}
640 672
 
641 673
 	// Find the most recent members.
642 674
 	$request = $smcFunc['db_query']('', '
@@ -652,8 +684,8 @@  discard block
 block discarded – undo
652 684
 	while ($row = $smcFunc['db_fetch_assoc']($request))
653 685
 	{
654 686
 		// Make the data look rss-ish.
655
-		if ($xml_format == 'rss' || $xml_format == 'rss2')
656
-			$data[] = array(
687
+		if ($xml_format == 'rss' || $xml_format == 'rss2') {
688
+					$data[] = array(
657 689
 				'tag' => 'item',
658 690
 				'content' => array(
659 691
 					array(
@@ -678,8 +710,8 @@  discard block
 block discarded – undo
678 710
 					),
679 711
 				),
680 712
 			);
681
-		elseif ($xml_format == 'rdf')
682
-			$data[] = array(
713
+		} elseif ($xml_format == 'rdf') {
714
+					$data[] = array(
683 715
 				'tag' => 'item',
684 716
 				'attributes' => array('rdf:about' => $scripturl . '?action=profile;u=' . $row['id_member']),
685 717
 				'content' => array(
@@ -697,8 +729,8 @@  discard block
 block discarded – undo
697 729
 					),
698 730
 				),
699 731
 			);
700
-		elseif ($xml_format == 'atom')
701
-			$data[] = array(
732
+		} elseif ($xml_format == 'atom') {
733
+					$data[] = array(
702 734
 				'tag' => 'entry',
703 735
 				'content' => array(
704 736
 					array(
@@ -727,9 +759,10 @@  discard block
 block discarded – undo
727 759
 					),
728 760
 				),
729 761
 			);
762
+		}
730 763
 		// More logical format for the data, but harder to apply.
731
-		else
732
-			$data[] = array(
764
+		else {
765
+					$data[] = array(
733 766
 				'tag' => 'member',
734 767
 				'content' => array(
735 768
 					array(
@@ -750,6 +783,7 @@  discard block
 block discarded – undo
750 783
 					),
751 784
 				),
752 785
 			);
786
+		}
753 787
 	}
754 788
 	$smcFunc['db_free_result']($request);
755 789
 
@@ -810,22 +844,24 @@  discard block
 block discarded – undo
810 844
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
811 845
 		{
812 846
 			$smcFunc['db_free_result']($request);
813
-			if (empty($_REQUEST['boards']) && empty($board))
814
-				unset($context['optimize_msg']['lowest']);
815
-			else
816
-				$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
847
+			if (empty($_REQUEST['boards']) && empty($board)) {
848
+							unset($context['optimize_msg']['lowest']);
849
+			} else {
850
+							$context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg';
851
+			}
817 852
 			$context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg';
818 853
 			$loops++;
854
+		} else {
855
+					$done = true;
819 856
 		}
820
-		else
821
-			$done = true;
822 857
 	}
823 858
 	$data = array();
824 859
 	while ($row = $smcFunc['db_fetch_assoc']($request))
825 860
 	{
826 861
 		// Limit the length of the message, if the option is set.
827
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
828
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
862
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
863
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
864
+		}
829 865
 
830 866
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
831 867
 
@@ -852,8 +888,9 @@  discard block
 block discarded – undo
852 888
 			while ($attach = $smcFunc['db_fetch_assoc']($attach_request))
853 889
 			{
854 890
 				// Include approved attachments only
855
-				if ($attach['approved'])
856
-					$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
891
+				if ($attach['approved']) {
892
+									$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
893
+				}
857 894
 			}
858 895
 			$smcFunc['db_free_result']($attach_request);
859 896
 
@@ -861,16 +898,17 @@  discard block
 block discarded – undo
861 898
 			if (!empty($loaded_attachments))
862 899
 			{
863 900
 				uasort($loaded_attachments, function($a, $b) {
864
-					if ($a['filesize'] == $b['filesize'])
865
-					        return 0;
901
+					if ($a['filesize'] == $b['filesize']) {
902
+										        return 0;
903
+					}
866 904
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
867 905
 				});
906
+			} else {
907
+							$loaded_attachments = null;
868 908
 			}
869
-			else
870
-				$loaded_attachments = null;
909
+		} else {
910
+					$loaded_attachments = null;
871 911
 		}
872
-		else
873
-			$loaded_attachments = null;
874 912
 
875 913
 		// Being news, this actually makes sense in rss format.
876 914
 		if ($xml_format == 'rss' || $xml_format == 'rss2')
@@ -884,9 +922,9 @@  discard block
 block discarded – undo
884 922
 					'length' => $attachment['filesize'],
885 923
 					'type' => $attachment['mime_type'],
886 924
 				);
925
+			} else {
926
+							$enclosure = null;
887 927
 			}
888
-			else
889
-				$enclosure = null;
890 928
 
891 929
 			$data[] = array(
892 930
 				'tag' => 'item',
@@ -929,8 +967,7 @@  discard block
 block discarded – undo
929 967
 					),
930 968
 				),
931 969
 			);
932
-		}
933
-		elseif ($xml_format == 'rdf')
970
+		} elseif ($xml_format == 'rdf')
934 971
 		{
935 972
 			$data[] = array(
936 973
 				'tag' => 'item',
@@ -954,8 +991,7 @@  discard block
 block discarded – undo
954 991
 					),
955 992
 				),
956 993
 			);
957
-		}
958
-		elseif ($xml_format == 'atom')
994
+		} elseif ($xml_format == 'atom')
959 995
 		{
960 996
 			// Only one attachment allowed
961 997
 			if (!empty($loaded_attachments))
@@ -967,9 +1003,9 @@  discard block
 block discarded – undo
967 1003
 					'length' => $attachment['filesize'],
968 1004
 					'type' => $attachment['mime_type'],
969 1005
 				);
1006
+			} else {
1007
+							$enclosure = null;
970 1008
 			}
971
-			else
972
-				$enclosure = null;
973 1009
 
974 1010
 			$data[] = array(
975 1011
 				'tag' => 'entry',
@@ -1069,9 +1105,9 @@  discard block
 block discarded – undo
1069 1105
 						)
1070 1106
 					);
1071 1107
 				}
1108
+			} else {
1109
+							$attachments = null;
1072 1110
 			}
1073
-			else
1074
-				$attachments = null;
1075 1111
 
1076 1112
 			$data[] = array(
1077 1113
 				'tag' => 'article',
@@ -1189,22 +1225,25 @@  discard block
 block discarded – undo
1189 1225
 		if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit'])
1190 1226
 		{
1191 1227
 			$smcFunc['db_free_result']($request);
1192
-			if (empty($_REQUEST['boards']) && empty($board))
1193
-				unset($context['optimize_msg']['lowest']);
1194
-			else
1195
-				$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
1228
+			if (empty($_REQUEST['boards']) && empty($board)) {
1229
+							unset($context['optimize_msg']['lowest']);
1230
+			} else {
1231
+							$context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2';
1232
+			}
1196 1233
 			$loops++;
1234
+		} else {
1235
+					$done = true;
1197 1236
 		}
1198
-		else
1199
-			$done = true;
1200 1237
 	}
1201 1238
 	$messages = array();
1202
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1203
-		$messages[] = $row['id_msg'];
1239
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1240
+			$messages[] = $row['id_msg'];
1241
+	}
1204 1242
 	$smcFunc['db_free_result']($request);
1205 1243
 
1206
-	if (empty($messages))
1207
-		return array();
1244
+	if (empty($messages)) {
1245
+			return array();
1246
+	}
1208 1247
 
1209 1248
 	// Find the most recent posts this user can see.
1210 1249
 	$request = $smcFunc['db_query']('', '
@@ -1234,8 +1273,9 @@  discard block
 block discarded – undo
1234 1273
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1235 1274
 	{
1236 1275
 		// Limit the length of the message, if the option is set.
1237
-		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen'])
1238
-			$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
1276
+		if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) {
1277
+					$row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...';
1278
+		}
1239 1279
 
1240 1280
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
1241 1281
 
@@ -1262,8 +1302,9 @@  discard block
 block discarded – undo
1262 1302
 			while ($attach = $smcFunc['db_fetch_assoc']($attach_request))
1263 1303
 			{
1264 1304
 				// Include approved attachments only
1265
-				if ($attach['approved'])
1266
-					$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
1305
+				if ($attach['approved']) {
1306
+									$loaded_attachments['attachment_' . $attach['id_attach']] = $attach;
1307
+				}
1267 1308
 			}
1268 1309
 			$smcFunc['db_free_result']($attach_request);
1269 1310
 
@@ -1271,16 +1312,17 @@  discard block
 block discarded – undo
1271 1312
 			if (!empty($loaded_attachments))
1272 1313
 			{
1273 1314
 				uasort($loaded_attachments, function($a, $b) {
1274
-					if ($a['filesize'] == $b['filesize'])
1275
-					        return 0;
1315
+					if ($a['filesize'] == $b['filesize']) {
1316
+										        return 0;
1317
+					}
1276 1318
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
1277 1319
 				});
1320
+			} else {
1321
+							$loaded_attachments = null;
1278 1322
 			}
1279
-			else
1280
-				$loaded_attachments = null;
1323
+		} else {
1324
+					$loaded_attachments = null;
1281 1325
 		}
1282
-		else
1283
-			$loaded_attachments = null;
1284 1326
 
1285 1327
 		// Doesn't work as well as news, but it kinda does..
1286 1328
 		if ($xml_format == 'rss' || $xml_format == 'rss2')
@@ -1294,9 +1336,9 @@  discard block
 block discarded – undo
1294 1336
 					'length' => $attachment['filesize'],
1295 1337
 					'type' => $attachment['mime_type'],
1296 1338
 				);
1339
+			} else {
1340
+							$enclosure = null;
1297 1341
 			}
1298
-			else
1299
-				$enclosure = null;
1300 1342
 
1301 1343
 			$data[] = array(
1302 1344
 				'tag' => 'item',
@@ -1339,8 +1381,7 @@  discard block
 block discarded – undo
1339 1381
 					),
1340 1382
 				),
1341 1383
 			);
1342
-		}
1343
-		elseif ($xml_format == 'rdf')
1384
+		} elseif ($xml_format == 'rdf')
1344 1385
 		{
1345 1386
 			$data[] = array(
1346 1387
 				'tag' => 'item',
@@ -1364,8 +1405,7 @@  discard block
 block discarded – undo
1364 1405
 					),
1365 1406
 				),
1366 1407
 			);
1367
-		}
1368
-		elseif ($xml_format == 'atom')
1408
+		} elseif ($xml_format == 'atom')
1369 1409
 		{
1370 1410
 			// Only one attachment allowed
1371 1411
 			if (!empty($loaded_attachments))
@@ -1377,9 +1417,9 @@  discard block
 block discarded – undo
1377 1417
 					'length' => $attachment['filesize'],
1378 1418
 					'type' => $attachment['mime_type'],
1379 1419
 				);
1420
+			} else {
1421
+							$enclosure = null;
1380 1422
 			}
1381
-			else
1382
-				$enclosure = null;
1383 1423
 
1384 1424
 			$data[] = array(
1385 1425
 				'tag' => 'entry',
@@ -1479,9 +1519,9 @@  discard block
 block discarded – undo
1479 1519
 						)
1480 1520
 					);
1481 1521
 				}
1522
+			} else {
1523
+							$attachments = null;
1482 1524
 			}
1483
-			else
1484
-				$attachments = null;
1485 1525
 
1486 1526
 			$data[] = array(
1487 1527
 				'tag' => 'recent-post',
@@ -1600,14 +1640,16 @@  discard block
 block discarded – undo
1600 1640
 	global $scripturl, $memberContext, $user_profile, $user_info;
1601 1641
 
1602 1642
 	// You must input a valid user....
1603
-	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u']))
1604
-		return array();
1643
+	if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) {
1644
+			return array();
1645
+	}
1605 1646
 
1606 1647
 	// Make sure the id is a number and not "I like trying to hack the database".
1607 1648
 	$_GET['u'] = (int) $_GET['u'];
1608 1649
 	// Load the member's contextual information!
1609
-	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view'))
1610
-		return array();
1650
+	if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) {
1651
+			return array();
1652
+	}
1611 1653
 
1612 1654
 	// Okay, I admit it, I'm lazy.  Stupid $_GET['u'] is long and hard to type.
1613 1655
 	$profile = &$memberContext[$_GET['u']];
@@ -1643,8 +1685,7 @@  discard block
 block discarded – undo
1643 1685
 				),
1644 1686
 			)
1645 1687
 		);
1646
-	}
1647
-	elseif ($xml_format == 'rdf')
1688
+	} elseif ($xml_format == 'rdf')
1648 1689
 	{
1649 1690
 		$data[] = array(
1650 1691
 			'tag' => 'item',
@@ -1668,8 +1709,7 @@  discard block
 block discarded – undo
1668 1709
 				),
1669 1710
 			)
1670 1711
 		);
1671
-	}
1672
-	elseif ($xml_format == 'atom')
1712
+	} elseif ($xml_format == 'atom')
1673 1713
 	{
1674 1714
 		$data[] = array(
1675 1715
 			'tag' => 'entry',
@@ -1722,8 +1762,7 @@  discard block
 block discarded – undo
1722 1762
 				),
1723 1763
 			)
1724 1764
 		);
1725
-	}
1726
-	else
1765
+	} else
1727 1766
 	{
1728 1767
 		$data = array(
1729 1768
 			array(
Please login to merge, or discard this patch.
Sources/Drafts.php 1 patch
Braces   +75 added lines, -53 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 loadLanguage('Drafts');
21 22
 
@@ -33,8 +34,9 @@  discard block
 block discarded – undo
33 34
 	global $context, $user_info, $smcFunc, $modSettings, $board;
34 35
 
35 36
 	// can you be, should you be ... here?
36
-	if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft']))
37
-		return false;
37
+	if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) {
38
+			return false;
39
+	}
38 40
 
39 41
 	// read in what they sent us, if anything
40 42
 	$id_draft = (int) $_POST['id_draft'];
@@ -46,14 +48,16 @@  discard block
 block discarded – undo
46 48
 		$context['draft_saved_on'] = $draft_info['poster_time'];
47 49
 
48 50
 		// since we were called from the autosave function, send something back
49
-		if (!empty($id_draft))
50
-			XmlDraft($id_draft);
51
+		if (!empty($id_draft)) {
52
+					XmlDraft($id_draft);
53
+		}
51 54
 
52 55
 		return true;
53 56
 	}
54 57
 
55
-	if (!isset($_POST['message']))
56
-		$_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : '';
58
+	if (!isset($_POST['message'])) {
59
+			$_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : '';
60
+	}
57 61
 
58 62
 	// prepare any data from the form
59 63
 	$topic_id = empty($_REQUEST['topic']) ? 0 : (int) $_REQUEST['topic'];
@@ -66,8 +70,9 @@  discard block
 block discarded – undo
66 70
 
67 71
 	// message and subject still need a bit more work
68 72
 	preparsecode($draft['body']);
69
-	if ($smcFunc['strlen']($draft['subject']) > 100)
70
-		$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
73
+	if ($smcFunc['strlen']($draft['subject']) > 100) {
74
+			$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
75
+	}
71 76
 
72 77
 	// Modifying an existing draft, like hitting the save draft button or autosave enabled?
73 78
 	if (!empty($id_draft) && !empty($draft_info))
@@ -148,9 +153,9 @@  discard block
 block discarded – undo
148 153
 		{
149 154
 			$context['draft_saved'] = true;
150 155
 			$context['id_draft'] = $id_draft;
156
+		} else {
157
+					$post_errors[] = 'draft_not_saved';
151 158
 		}
152
-		else
153
-			$post_errors[] = 'draft_not_saved';
154 159
 
155 160
 		// cleanup
156 161
 		unset($_POST['save_draft']);
@@ -180,8 +185,9 @@  discard block
 block discarded – undo
180 185
 	global $context, $user_info, $smcFunc, $modSettings;
181 186
 
182 187
 	// PM survey says ... can you stay or must you go
183
-	if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft']))
184
-		return false;
188
+	if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) {
189
+			return false;
190
+	}
185 191
 
186 192
 	// read in what you sent us
187 193
 	$id_pm_draft = (int) $_POST['id_pm_draft'];
@@ -193,8 +199,9 @@  discard block
 block discarded – undo
193 199
 		$context['draft_saved_on'] = $draft_info['poster_time'];
194 200
 
195 201
 		// Send something back to the javascript caller
196
-		if (!empty($id_draft))
197
-			XmlDraft($id_draft);
202
+		if (!empty($id_draft)) {
203
+					XmlDraft($id_draft);
204
+		}
198 205
 
199 206
 		return true;
200 207
 	}
@@ -204,9 +211,9 @@  discard block
 block discarded – undo
204 211
 	{
205 212
 		$recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array();
206 213
 		$recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array();
214
+	} elseif (!empty($draft_info['to_list']) && empty($recipientList)) {
215
+			$recipientList = smf_json_decode($draft_info['to_list'], true);
207 216
 	}
208
-	elseif (!empty($draft_info['to_list']) && empty($recipientList))
209
-		$recipientList = smf_json_decode($draft_info['to_list'], true);
210 217
 
211 218
 	// prepare the data we got from the form
212 219
 	$reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to'];
@@ -215,8 +222,9 @@  discard block
 block discarded – undo
215 222
 
216 223
 	// message and subject always need a bit more work
217 224
 	preparsecode($draft['body']);
218
-	if ($smcFunc['strlen']($draft['subject']) > 100)
219
-		$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
225
+	if ($smcFunc['strlen']($draft['subject']) > 100) {
226
+			$draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100);
227
+	}
220 228
 
221 229
 	// Modifying an existing PM draft?
222 230
 	if (!empty($id_pm_draft) && !empty($draft_info))
@@ -280,9 +288,9 @@  discard block
 block discarded – undo
280 288
 		{
281 289
 			$context['draft_saved'] = true;
282 290
 			$context['id_pm_draft'] = $id_pm_draft;
291
+		} else {
292
+					$post_errors[] = 'draft_not_saved';
283 293
 		}
284
-		else
285
-			$post_errors[] = 'draft_not_saved';
286 294
 	}
287 295
 
288 296
 	// if we were called from the autosave function, send something back
@@ -315,8 +323,9 @@  discard block
 block discarded – undo
315 323
 	$type = (int) $type;
316 324
 
317 325
 	// nothing to read, nothing to do
318
-	if (empty($id_draft))
319
-		return false;
326
+	if (empty($id_draft)) {
327
+			return false;
328
+	}
320 329
 
321 330
 	// load in this draft from the DB
322 331
 	$request = $smcFunc['db_query']('', '
@@ -337,8 +346,9 @@  discard block
 block discarded – undo
337 346
 	);
338 347
 
339 348
 	// no results?
340
-	if (!$smcFunc['db_num_rows']($request))
341
-		return false;
349
+	if (!$smcFunc['db_num_rows']($request)) {
350
+			return false;
351
+	}
342 352
 
343 353
 	// load up the data
344 354
 	$draft_info = $smcFunc['db_fetch_assoc']($request);
@@ -358,8 +368,7 @@  discard block
 block discarded – undo
358 368
 			$context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : '';
359 369
 			$context['board'] = !empty($draft_info['id_board']) ? $draft_info['id_board'] : '';
360 370
 			$context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0;
361
-		}
362
-		elseif ($type === 1)
371
+		} elseif ($type === 1)
363 372
 		{
364 373
 			// one of those pm drafts? then set it up like we have an error
365 374
 			$_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : '';
@@ -395,12 +404,14 @@  discard block
 block discarded – undo
395 404
 	global $user_info, $smcFunc;
396 405
 
397 406
 	// Only a single draft.
398
-	if (is_numeric($id_draft))
399
-		$id_draft = array($id_draft);
407
+	if (is_numeric($id_draft)) {
408
+			$id_draft = array($id_draft);
409
+	}
400 410
 
401 411
 	// can't delete nothing
402
-	if (empty($id_draft) || ($check && empty($user_info['id'])))
403
-		return false;
412
+	if (empty($id_draft) || ($check && empty($user_info['id']))) {
413
+			return false;
414
+	}
404 415
 
405 416
 	$smcFunc['db_query']('', '
406 417
 		DELETE FROM {db_prefix}user_drafts
@@ -429,14 +440,16 @@  discard block
 block discarded – undo
429 440
 	global $smcFunc, $scripturl, $context, $txt, $modSettings;
430 441
 
431 442
 	// Permissions
432
-	if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id))
433
-		return false;
443
+	if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) {
444
+			return false;
445
+	}
434 446
 
435 447
 	$context['drafts'] = array();
436 448
 
437 449
 	// has a specific draft has been selected?  Load it up if there is not a message already in the editor
438
-	if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message']))
439
-		ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true);
450
+	if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) {
451
+			ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true);
452
+	}
440 453
 
441 454
 	// load the drafts this user has available
442 455
 	$request = $smcFunc['db_query']('', '
@@ -459,8 +472,9 @@  discard block
 block discarded – undo
459 472
 	// add them to the draft array for display
460 473
 	while ($row = $smcFunc['db_fetch_assoc']($request))
461 474
 	{
462
-		if (empty($row['subject']))
463
-			$row['subject'] = $txt['no_subject'];
475
+		if (empty($row['subject'])) {
476
+					$row['subject'] = $txt['no_subject'];
477
+		}
464 478
 
465 479
 		// Post drafts
466 480
 		if ($draft_type === 0)
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 	}
546 560
 
547 561
 	// Default to 10.
548
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
549
-		$_REQUEST['viewscount'] = 10;
562
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
563
+			$_REQUEST['viewscount'] = 10;
564
+	}
550 565
 
551 566
 	// Get the count of applicable drafts on the boards they can (still) see ...
552 567
 	// @todo .. should we just let them see their drafts even if they have lost board access ?
@@ -611,12 +626,14 @@  discard block
 block discarded – undo
611 626
 	while ($row = $smcFunc['db_fetch_assoc']($request))
612 627
 	{
613 628
 		// Censor....
614
-		if (empty($row['body']))
615
-			$row['body'] = '';
629
+		if (empty($row['body'])) {
630
+					$row['body'] = '';
631
+		}
616 632
 
617 633
 		$row['subject'] = $smcFunc['htmltrim']($row['subject']);
618
-		if (empty($row['subject']))
619
-			$row['subject'] = $txt['no_subject'];
634
+		if (empty($row['subject'])) {
635
+					$row['subject'] = $txt['no_subject'];
636
+		}
620 637
 
621 638
 		censorText($row['body']);
622 639
 		censorText($row['subject']);
@@ -648,8 +665,9 @@  discard block
 block discarded – undo
648 665
 	$smcFunc['db_free_result']($request);
649 666
 
650 667
 	// If the drafts were retrieved in reverse order, get them right again.
651
-	if ($reverse)
652
-		$context['drafts'] = array_reverse($context['drafts'], true);
668
+	if ($reverse) {
669
+			$context['drafts'] = array_reverse($context['drafts'], true);
670
+	}
653 671
 
654 672
 	// Menu tab
655 673
 	$context[$context['profile_menu_name']]['tab_data'] = array(
@@ -707,8 +725,9 @@  discard block
 block discarded – undo
707 725
 	}
708 726
 
709 727
 	// Default to 10.
710
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
711
-		$_REQUEST['viewscount'] = 10;
728
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
729
+			$_REQUEST['viewscount'] = 10;
730
+	}
712 731
 
713 732
 	// Get the count of applicable drafts
714 733
 	$request = $smcFunc['db_query']('', '
@@ -767,12 +786,14 @@  discard block
 block discarded – undo
767 786
 	while ($row = $smcFunc['db_fetch_assoc']($request))
768 787
 	{
769 788
 		// Censor....
770
-		if (empty($row['body']))
771
-			$row['body'] = '';
789
+		if (empty($row['body'])) {
790
+					$row['body'] = '';
791
+		}
772 792
 
773 793
 		$row['subject'] = $smcFunc['htmltrim']($row['subject']);
774
-		if (empty($row['subject']))
775
-			$row['subject'] = $txt['no_subject'];
794
+		if (empty($row['subject'])) {
795
+					$row['subject'] = $txt['no_subject'];
796
+		}
776 797
 
777 798
 		censorText($row['body']);
778 799
 		censorText($row['subject']);
@@ -827,8 +848,9 @@  discard block
 block discarded – undo
827 848
 	$smcFunc['db_free_result']($request);
828 849
 
829 850
 	// if the drafts were retrieved in reverse order, then put them in the right order again.
830
-	if ($reverse)
831
-		$context['drafts'] = array_reverse($context['drafts'], true);
851
+	if ($reverse) {
852
+			$context['drafts'] = array_reverse($context['drafts'], true);
853
+	}
832 854
 
833 855
 	// off to the template we go
834 856
 	$context['page_title'] = $txt['drafts'];
Please login to merge, or discard this patch.