Completed
Pull Request — release-2.1 (#3931)
by Fran
07:05
created
Sources/CacheAPI-sqlite.php 2 patches
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * SQLite Cache API class
@@ -153,8 +154,7 @@  discard block
 block discarded – undo
153 154
 		if (is_null($dir) || !is_writable($dir))
154 155
 		{
155 156
 			$this->cachedir = $cachedir_sqlite;
156
-		}
157
-		else
157
+		} else
158 158
 		{
159 159
 			$this->cachedir = $dir;
160 160
 		}
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@
 block discarded – undo
143 143
 	 *
144 144
 	 * @param string $dir A valid path
145 145
 	 *
146
-	 * @return boolean If this was successful or not.
146
+	 * @return boolean|null If this was successful or not.
147 147
 	 */
148 148
 	public function setCachedir($dir = null)
149 149
 	{
Please login to merge, or discard this patch.
proxy.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@
 block discarded – undo
110 110
 
111 111
 		// Right, image not cached? Simply redirect, then.
112 112
 		if (!$this->checkRequest())
113
-		    redirectexit($request);
113
+			redirectexit($request);
114 114
 
115 115
 		// Make sure we're serving an image
116 116
 		$contentParts = explode('/', !empty($cached['content_type']) ? $cached['content_type'] : '');
Please login to merge, or discard this patch.
Braces   +33 added lines, -22 removed lines patch added patch discarded remove patch
@@ -63,26 +63,31 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	public function checkRequest()
65 65
 	{
66
-		if (!$this->enabled)
67
-			return false;
66
+		if (!$this->enabled) {
67
+					return false;
68
+		}
68 69
 
69 70
 		// Try to create the image cache directory if it doesn't exist
70
-		if (!file_exists($this->cache))
71
-			if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
71
+		if (!file_exists($this->cache)) {
72
+					if (!mkdir($this->cache) || !copy(dirname($this->cache) . '/index.php', $this->cache . '/index.php'))
72 73
 				return false;
74
+		}
73 75
 
74
-		if (empty($_GET['hash']) || empty($_GET['request']))
75
-			return false;
76
+		if (empty($_GET['hash']) || empty($_GET['request'])) {
77
+					return false;
78
+		}
76 79
 
77 80
 		$hash = $_GET['hash'];
78 81
 		$request = $_GET['request'];
79 82
 
80
-		if (md5($request . $this->secret) != $hash)
81
-			return false;
83
+		if (md5($request . $this->secret) != $hash) {
84
+					return false;
85
+		}
82 86
 
83 87
 		// Attempt to cache the request if it doesn't exist
84
-		if (!$this->isCached($request))
85
-			return $this->cacheImage($request);
88
+		if (!$this->isCached($request)) {
89
+					return $this->cacheImage($request);
90
+		}
86 91
 
87 92
 		return true;
88 93
 	}
@@ -103,19 +108,22 @@  discard block
 block discarded – undo
103 108
 		if (!$cached || time() - $cached['time'] > (5 * 86400))
104 109
 		{
105 110
 			@unlink($cached_file);
106
-			if ($this->checkRequest())
107
-				$this->serve();
111
+			if ($this->checkRequest()) {
112
+							$this->serve();
113
+			}
108 114
 			redirectexit($request);
109 115
 		}
110 116
 
111 117
 		// Right, image not cached? Simply redirect, then.
112
-		if (!$this->checkRequest())
113
-		    redirectexit($request);
118
+		if (!$this->checkRequest()) {
119
+				    redirectexit($request);
120
+		}
114 121
 
115 122
 		// Make sure we're serving an image
116 123
 		$contentParts = explode('/', !empty($cached['content_type']) ? $cached['content_type'] : '');
117
-		if ($contentParts[0] != 'image')
118
-			exit;
124
+		if ($contentParts[0] != 'image') {
125
+					exit;
126
+		}
119 127
 
120 128
 		header('Content-type: ' . $cached['content_type']);
121 129
 		header('Content-length: ' . $cached['size']);
@@ -161,19 +169,22 @@  discard block
 block discarded – undo
161 169
 		$request = $curl->get_url_data($request);
162 170
 		$response = $request->result();
163 171
 
164
-		if (empty($response))
165
-			return false;
172
+		if (empty($response)) {
173
+					return false;
174
+		}
166 175
 
167 176
 		$headers = $response['headers'];
168 177
 
169 178
 		// Make sure the url is returning an image
170 179
 		$contentParts = explode('/', !empty($headers['content-type']) ? $headers['content-type'] : '');
171
-		if ($contentParts[0] != 'image')
172
-			return false;
180
+		if ($contentParts[0] != 'image') {
181
+					return false;
182
+		}
173 183
 
174 184
 		// Validate the filesize
175
-		if ($response['size'] > ($this->maxSize * 1024))
176
-			return false;
185
+		if ($response['size'] > ($this->maxSize * 1024)) {
186
+					return false;
187
+		}
177 188
 
178 189
 		return file_put_contents($dest, json_encode(array(
179 190
 			'content_type' => $headers['content-type'],
Please login to merge, or discard this patch.
Themes/default/Calendar.template.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
  * Display a list of upcoming events, birthdays, and holidays.
69 69
  *
70 70
  * @param string $grid_name The grid name
71
- * @return void|bool Returns false if the grid doesn't exist.
71
+ * @return false|null Returns false if the grid doesn't exist.
72 72
  */
73 73
 function template_show_upcoming_list($grid_name)
74 74
 {
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
  *
239 239
  * @param string $grid_name The grid name
240 240
  * @param bool $is_mini Is this a mini grid?
241
- * @return void|bool Returns false if the grid doesn't exist.
241
+ * @return false|null Returns false if the grid doesn't exist.
242 242
  */
243 243
 function template_show_month_grid($grid_name, $is_mini = false)
244 244
 {
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
  * Shows a weekly grid
524 524
  *
525 525
  * @param string $grid_name The name of the grid
526
- * @return void|bool Returns false if the grid doesn't exist
526
+ * @return false|null Returns false if the grid doesn't exist
527 527
  */
528 528
 function template_show_week_grid($grid_name)
529 529
 {
Please login to merge, or discard this 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.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -437,9 +437,9 @@  discard block
 block discarded – undo
437 437
 					{
438 438
 						// Sort events by start time (all day events will be listed first)
439 439
 						uasort($day['events'], function($a, $b) {
440
-						    if ($a['start_timestamp'] == $b['start_timestamp'])
441
-						        return 0;
442
-						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
440
+							if ($a['start_timestamp'] == $b['start_timestamp'])
441
+								return 0;
442
+							return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
443 443
 						});
444 444
 
445 445
 						echo '
@@ -619,9 +619,9 @@  discard block
 block discarded – undo
619 619
 							{
620 620
 								// Sort events by start time (all day events will be listed first)
621 621
 								uasort($day['events'], function($a, $b) {
622
-								    if ($a['start_timestamp'] == $b['start_timestamp'])
623
-								        return 0;
624
-								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
622
+									if ($a['start_timestamp'] == $b['start_timestamp'])
623
+										return 0;
624
+									return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
625 625
 								});
626 626
 
627 627
 								foreach ($day['events'] as $event)
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +217 added lines, -157 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
  * Get all birthdays within the given time range.
@@ -61,10 +62,11 @@  discard block
 block discarded – undo
61 62
 	$bday = array();
62 63
 	while ($row = $smcFunc['db_fetch_assoc']($result))
63 64
 	{
64
-		if ($year_low != $year_high)
65
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
66
-		else
67
-			$age_year = $year_low;
65
+		if ($year_low != $year_high) {
66
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
67
+		} else {
68
+					$age_year = $year_low;
69
+		}
68 70
 
69 71
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
70 72
 			'id' => $row['id_member'],
@@ -78,8 +80,9 @@  discard block
 block discarded – undo
78 80
 	ksort($bday);
79 81
 
80 82
 	// Set is_last, so the themes know when to stop placing separators.
81
-	foreach ($bday as $mday => $array)
82
-		$bday[$mday][count($array) - 1]['is_last'] = true;
83
+	foreach ($bday as $mday => $array) {
84
+			$bday[$mday][count($array) - 1]['is_last'] = true;
85
+	}
83 86
 
84 87
 	return $bday;
85 88
 }
@@ -127,8 +130,9 @@  discard block
 block discarded – undo
127 130
 	while ($row = $smcFunc['db_fetch_assoc']($result))
128 131
 	{
129 132
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
130
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
131
-			continue;
133
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
134
+					continue;
135
+		}
132 136
 
133 137
 		// Force a censor of the title - as often these are used by others.
134 138
 		censorText($row['title'], $use_permissions ? false : true);
@@ -137,8 +141,9 @@  discard block
 block discarded – undo
137 141
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
138 142
 
139 143
 		// Sanity check
140
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
141
-			continue;
144
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
145
+					continue;
146
+		}
142 147
 
143 148
 		// Get set up for the loop
144 149
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz));
@@ -202,8 +207,8 @@  discard block
 block discarded – undo
202 207
 			);
203 208
 
204 209
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
205
-			if ($use_permissions)
206
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
210
+			if ($use_permissions) {
211
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
207 212
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
208 213
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
209 214
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -211,9 +216,10 @@  discard block
 block discarded – undo
211 216
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
212 217
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
213 218
 				));
219
+			}
214 220
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
215
-			else
216
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
221
+			else {
222
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
217 223
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
218 224
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
219 225
 					'can_edit' => false,
@@ -223,6 +229,7 @@  discard block
 block discarded – undo
223 229
 					'poster' => $row['id_member'],
224 230
 					'allowed_groups' => explode(',', $row['member_groups']),
225 231
 				));
232
+			}
226 233
 
227 234
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
228 235
 		}
@@ -232,8 +239,9 @@  discard block
 block discarded – undo
232 239
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
233 240
 	if ($use_permissions)
234 241
 	{
235
-		foreach ($events as $mday => $array)
236
-			$events[$mday][count($array) - 1]['is_last'] = true;
242
+		foreach ($events as $mday => $array) {
243
+					$events[$mday][count($array) - 1]['is_last'] = true;
244
+		}
237 245
 	}
238 246
 
239 247
 	ksort($events);
@@ -253,11 +261,12 @@  discard block
 block discarded – undo
253 261
 	global $smcFunc;
254 262
 
255 263
 	// Get the lowest and highest dates for "all years".
256
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
257
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
264
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
265
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
258 266
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
259
-	else
260
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
267
+	} else {
268
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
269
+	}
261 270
 
262 271
 	// Find some holidays... ;).
263 272
 	$result = $smcFunc['db_query']('', '
@@ -277,10 +286,11 @@  discard block
 block discarded – undo
277 286
 	$holidays = array();
278 287
 	while ($row = $smcFunc['db_fetch_assoc']($result))
279 288
 	{
280
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
281
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
282
-		else
283
-			$event_year = substr($low_date, 0, 4);
289
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
290
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
291
+		} else {
292
+					$event_year = substr($low_date, 0, 4);
293
+		}
284 294
 
285 295
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
286 296
 	}
@@ -306,10 +316,12 @@  discard block
 block discarded – undo
306 316
 	isAllowedTo('calendar_post');
307 317
 
308 318
 	// No board?  No topic?!?
309
-	if (empty($board))
310
-		fatal_lang_error('missing_board_id', false);
311
-	if (empty($topic))
312
-		fatal_lang_error('missing_topic_id', false);
319
+	if (empty($board)) {
320
+			fatal_lang_error('missing_board_id', false);
321
+	}
322
+	if (empty($topic)) {
323
+			fatal_lang_error('missing_topic_id', false);
324
+	}
313 325
 
314 326
 	// Administrator, Moderator, or owner.  Period.
315 327
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -327,12 +339,14 @@  discard block
 block discarded – undo
327 339
 		if ($row = $smcFunc['db_fetch_assoc']($result))
328 340
 		{
329 341
 			// Not the owner of the topic.
330
-			if ($row['id_member_started'] != $user_info['id'])
331
-				fatal_lang_error('not_your_topic', 'user');
342
+			if ($row['id_member_started'] != $user_info['id']) {
343
+							fatal_lang_error('not_your_topic', 'user');
344
+			}
332 345
 		}
333 346
 		// Topic/Board doesn't exist.....
334
-		else
335
-			fatal_lang_error('calendar_no_topic', 'general');
347
+		else {
348
+					fatal_lang_error('calendar_no_topic', 'general');
349
+		}
336 350
 		$smcFunc['db_free_result']($result);
337 351
 	}
338 352
 }
@@ -420,14 +434,16 @@  discard block
 block discarded – undo
420 434
 	if (!empty($calendarOptions['start_day']))
421 435
 	{
422 436
 		$nShift -= $calendarOptions['start_day'];
423
-		if ($nShift < 0)
424
-			$nShift = 7 + $nShift;
437
+		if ($nShift < 0) {
438
+					$nShift = 7 + $nShift;
439
+		}
425 440
 	}
426 441
 
427 442
 	// Number of rows required to fit the month.
428 443
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
429
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
430
-		$nRows++;
444
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
445
+			$nRows++;
446
+	}
431 447
 
432 448
 	// Fetch the arrays for birthdays, posted events, and holidays.
433 449
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -440,8 +456,9 @@  discard block
 block discarded – undo
440 456
 	{
441 457
 		$calendarGrid['week_days'][] = $count;
442 458
 		$count++;
443
-		if ($count == 7)
444
-			$count = 0;
459
+		if ($count == 7) {
460
+					$count = 0;
461
+		}
445 462
 	}
446 463
 
447 464
 	// Iterate through each week.
@@ -458,8 +475,9 @@  discard block
 block discarded – undo
458 475
 		{
459 476
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
460 477
 
461
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
462
-				$nDay = 0;
478
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
479
+							$nDay = 0;
480
+			}
463 481
 
464 482
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
465 483
 
@@ -477,8 +495,9 @@  discard block
 block discarded – undo
477 495
 	}
478 496
 
479 497
 	// What is the last day of the month?
480
-	if ($is_previous === true)
481
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
498
+	if ($is_previous === true) {
499
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
500
+	}
482 501
 
483 502
 	// We'll use the shift in the template.
484 503
 	$calendarGrid['shift'] = $nShift;
@@ -512,8 +531,9 @@  discard block
 block discarded – undo
512 531
 	{
513 532
 		// Here we offset accordingly to get things to the real start of a week.
514 533
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
515
-		if ($date_diff < 0)
516
-			$date_diff += 7;
534
+		if ($date_diff < 0) {
535
+					$date_diff += 7;
536
+		}
517 537
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
518 538
 		$day = (int) strftime('%d', $new_timestamp);
519 539
 		$month = (int) strftime('%m', $new_timestamp);
@@ -643,18 +663,20 @@  discard block
 block discarded – undo
643 663
 	{
644 664
 		foreach ($date_events as $event_key => $event_val)
645 665
 		{
646
-			if (in_array($event_val['id'], $temp))
647
-				unset($calendarGrid['events'][$date][$event_key]);
648
-			else
649
-				$temp[] = $event_val['id'];
666
+			if (in_array($event_val['id'], $temp)) {
667
+							unset($calendarGrid['events'][$date][$event_key]);
668
+			} else {
669
+							$temp[] = $event_val['id'];
670
+			}
650 671
 		}
651 672
 	}
652 673
 
653 674
 	// Give birthdays and holidays a friendly format, without the year
654
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
655
-		$date_format = '%b %d';
656
-	else
657
-		$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
675
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
676
+			$date_format = '%b %d';
677
+	} else {
678
+			$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
679
+	}
658 680
 
659 681
 	foreach (array('birthdays', 'holidays') as $type)
660 682
 	{
@@ -762,8 +784,9 @@  discard block
 block discarded – undo
762 784
 	// Holidays between now and now + days.
763 785
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
764 786
 	{
765
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
766
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
787
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
788
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
789
+		}
767 790
 	}
768 791
 
769 792
 	// Happy Birthday, guys and gals!
@@ -772,8 +795,9 @@  discard block
 block discarded – undo
772 795
 		$loop_date = strftime('%Y-%m-%d', $i);
773 796
 		if (isset($cached_data['birthdays'][$loop_date]))
774 797
 		{
775
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
776
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
798
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
799
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
800
+			}
777 801
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
778 802
 		}
779 803
 	}
@@ -785,8 +809,9 @@  discard block
 block discarded – undo
785 809
 		$loop_date = strftime('%Y-%m-%d', $i);
786 810
 
787 811
 		// No events today? Check the next day.
788
-		if (empty($cached_data['events'][$loop_date]))
789
-			continue;
812
+		if (empty($cached_data['events'][$loop_date])) {
813
+					continue;
814
+		}
790 815
 
791 816
 		// Loop through all events to add a few last-minute values.
792 817
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -799,9 +824,9 @@  discard block
 block discarded – undo
799 824
 			{
800 825
 				unset($cached_data['events'][$loop_date][$ev]);
801 826
 				continue;
827
+			} else {
828
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
802 829
 			}
803
-			else
804
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
805 830
 
806 831
 			// Might be set to true afterwards, depending on the permissions.
807 832
 			$this_event['can_edit'] = false;
@@ -809,15 +834,18 @@  discard block
 block discarded – undo
809 834
 			$this_event['date'] = $loop_date;
810 835
 		}
811 836
 
812
-		if (!empty($cached_data['events'][$loop_date]))
813
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
837
+		if (!empty($cached_data['events'][$loop_date])) {
838
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
839
+		}
814 840
 	}
815 841
 
816 842
 	// Mark the last item so that a list separator can be used in the template.
817
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
818
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
819
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
820
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
843
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
844
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
845
+	}
846
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
847
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
848
+	}
821 849
 
822 850
 	return array(
823 851
 		'data' => $return_data,
@@ -865,37 +893,46 @@  discard block
 block discarded – undo
865 893
 		if (isset($_POST['start_date']))
866 894
 		{
867 895
 			$d = date_parse($_POST['start_date']);
868
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
869
-				fatal_lang_error('invalid_date', false);
870
-			if (empty($d['year']))
871
-				fatal_lang_error('event_year_missing', false);
872
-			if (empty($d['month']))
873
-				fatal_lang_error('event_month_missing', false);
874
-		}
875
-		elseif (isset($_POST['start_datetime']))
896
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
897
+							fatal_lang_error('invalid_date', false);
898
+			}
899
+			if (empty($d['year'])) {
900
+							fatal_lang_error('event_year_missing', false);
901
+			}
902
+			if (empty($d['month'])) {
903
+							fatal_lang_error('event_month_missing', false);
904
+			}
905
+		} elseif (isset($_POST['start_datetime']))
876 906
 		{
877 907
 			$d = date_parse($_POST['start_datetime']);
878
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
879
-				fatal_lang_error('invalid_date', false);
880
-			if (empty($d['year']))
881
-				fatal_lang_error('event_year_missing', false);
882
-			if (empty($d['month']))
883
-				fatal_lang_error('event_month_missing', false);
908
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
909
+							fatal_lang_error('invalid_date', false);
910
+			}
911
+			if (empty($d['year'])) {
912
+							fatal_lang_error('event_year_missing', false);
913
+			}
914
+			if (empty($d['month'])) {
915
+							fatal_lang_error('event_month_missing', false);
916
+			}
884 917
 		}
885 918
 		// The 2.0 way
886 919
 		else
887 920
 		{
888 921
 			// No month?  No year?
889
-			if (!isset($_POST['month']))
890
-				fatal_lang_error('event_month_missing', false);
891
-			if (!isset($_POST['year']))
892
-				fatal_lang_error('event_year_missing', false);
922
+			if (!isset($_POST['month'])) {
923
+							fatal_lang_error('event_month_missing', false);
924
+			}
925
+			if (!isset($_POST['year'])) {
926
+							fatal_lang_error('event_year_missing', false);
927
+			}
893 928
 
894 929
 			// Check the month and year...
895
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
896
-				fatal_lang_error('invalid_month', false);
897
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
898
-				fatal_lang_error('invalid_year', false);
930
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
931
+							fatal_lang_error('invalid_month', false);
932
+			}
933
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
934
+							fatal_lang_error('invalid_year', false);
935
+			}
899 936
 		}
900 937
 	}
901 938
 
@@ -905,8 +942,9 @@  discard block
 block discarded – undo
905 942
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
906 943
 	if (isset($_POST['span']))
907 944
 	{
908
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
909
-			fatal_lang_error('invalid_days_numb', false);
945
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
946
+					fatal_lang_error('invalid_days_numb', false);
947
+		}
910 948
 	}
911 949
 
912 950
 	// There is no need to validate the following values if we are just deleting the event.
@@ -916,24 +954,29 @@  discard block
 block discarded – undo
916 954
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
917 955
 		{
918 956
 			// No day?
919
-			if (!isset($_POST['day']))
920
-				fatal_lang_error('event_day_missing', false);
957
+			if (!isset($_POST['day'])) {
958
+							fatal_lang_error('event_day_missing', false);
959
+			}
921 960
 
922 961
 			// Bad day?
923
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
924
-				fatal_lang_error('invalid_date', false);
962
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
963
+							fatal_lang_error('invalid_date', false);
964
+			}
925 965
 		}
926 966
 
927
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
928
-			fatal_lang_error('event_title_missing', false);
929
-		elseif (!isset($_POST['evtitle']))
930
-			$_POST['evtitle'] = $_POST['subject'];
967
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
968
+					fatal_lang_error('event_title_missing', false);
969
+		} elseif (!isset($_POST['evtitle'])) {
970
+					$_POST['evtitle'] = $_POST['subject'];
971
+		}
931 972
 
932 973
 		// No title?
933
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
934
-			fatal_lang_error('no_event_title', false);
935
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
936
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
974
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
975
+					fatal_lang_error('no_event_title', false);
976
+		}
977
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
978
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
979
+		}
937 980
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
938 981
 	}
939 982
 }
@@ -960,8 +1003,9 @@  discard block
 block discarded – undo
960 1003
 	);
961 1004
 
962 1005
 	// No results, return false.
963
-	if ($smcFunc['db_num_rows'] === 0)
964
-		return false;
1006
+	if ($smcFunc['db_num_rows'] === 0) {
1007
+			return false;
1008
+	}
965 1009
 
966 1010
 	// Grab the results and return.
967 1011
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -1095,8 +1139,9 @@  discard block
 block discarded – undo
1095 1139
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
1096 1140
 
1097 1141
 	$column_clauses = array();
1098
-	foreach ($event_columns as $col => $crit)
1099
-		$column_clauses[] = $col . ' = ' . $crit;
1142
+	foreach ($event_columns as $col => $crit) {
1143
+			$column_clauses[] = $col . ' = ' . $crit;
1144
+	}
1100 1145
 
1101 1146
 	$smcFunc['db_query']('', '
1102 1147
 		UPDATE {db_prefix}calendar
@@ -1181,8 +1226,9 @@  discard block
 block discarded – undo
1181 1226
 	);
1182 1227
 
1183 1228
 	// If nothing returned, we are in poo, poo.
1184
-	if ($smcFunc['db_num_rows']($request) === 0)
1185
-		return false;
1229
+	if ($smcFunc['db_num_rows']($request) === 0) {
1230
+			return false;
1231
+	}
1186 1232
 
1187 1233
 	$row = $smcFunc['db_fetch_assoc']($request);
1188 1234
 	$smcFunc['db_free_result']($request);
@@ -1190,8 +1236,9 @@  discard block
 block discarded – undo
1190 1236
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1191 1237
 
1192 1238
 	// Sanity check
1193
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1194
-		return false;
1239
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1240
+			return false;
1241
+	}
1195 1242
 
1196 1243
 	$return_value = array(
1197 1244
 		'boards' => array(),
@@ -1328,24 +1375,27 @@  discard block
 block discarded – undo
1328 1375
 
1329 1376
 	// Set $span, in case we need it
1330 1377
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1331
-	if ($span > 0)
1332
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1378
+	if ($span > 0) {
1379
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1380
+	}
1333 1381
 
1334 1382
 	// Define the timezone for this event, falling back to the default if not provided
1335
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1336
-		$tz = $eventOptions['tz'];
1337
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1338
-		$tz = $_POST['tz'];
1339
-	else
1340
-		$tz = getUserTimezone();
1383
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1384
+			$tz = $eventOptions['tz'];
1385
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1386
+			$tz = $_POST['tz'];
1387
+	} else {
1388
+			$tz = getUserTimezone();
1389
+	}
1341 1390
 
1342 1391
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1343
-	if (isset($eventOptions['allday']))
1344
-		$allday = $eventOptions['allday'];
1345
-	elseif (empty($_POST['allday']))
1346
-		$allday = false;
1347
-	else
1348
-		$allday = true;
1392
+	if (isset($eventOptions['allday'])) {
1393
+			$allday = $eventOptions['allday'];
1394
+	} elseif (empty($_POST['allday'])) {
1395
+			$allday = false;
1396
+	} else {
1397
+			$allday = true;
1398
+	}
1349 1399
 
1350 1400
 	// Input might come as individual parameters...
1351 1401
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1372,10 +1422,12 @@  discard block
 block discarded – undo
1372 1422
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1373 1423
 
1374 1424
 	// If the date and time were given in separate strings, combine them
1375
-	if (empty($start_string) && isset($start_date_string))
1376
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1377
-	if (empty($end_string) && isset($end_date_string))
1378
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1425
+	if (empty($start_string) && isset($start_date_string)) {
1426
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1427
+	}
1428
+	if (empty($end_string) && isset($end_date_string)) {
1429
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1430
+	}
1379 1431
 
1380 1432
 	// If some form of string input was given, override individually defined options with it
1381 1433
 	if (isset($start_string))
@@ -1466,10 +1518,11 @@  discard block
 block discarded – undo
1466 1518
 	if ($start_object >= $end_object)
1467 1519
 	{
1468 1520
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1469
-		if ($span > 0)
1470
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1471
-		else
1472
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1521
+		if ($span > 0) {
1522
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1523
+		} else {
1524
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1525
+		}
1473 1526
 	}
1474 1527
 
1475 1528
 	// Is $end_object too late?
@@ -1482,9 +1535,9 @@  discard block
 block discarded – undo
1482 1535
 			{
1483 1536
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1484 1537
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1538
+			} else {
1539
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1485 1540
 			}
1486
-			else
1487
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1488 1541
 		}
1489 1542
 	}
1490 1543
 
@@ -1497,8 +1550,7 @@  discard block
 block discarded – undo
1497 1550
 		$start_time = null;
1498 1551
 		$end_time = null;
1499 1552
 		$tz = null;
1500
-	}
1501
-	else
1553
+	} else
1502 1554
 	{
1503 1555
 		$start_time = date_format($start_object, 'H:i:s');
1504 1556
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1519,16 +1571,18 @@  discard block
 block discarded – undo
1519 1571
 	require_once($sourcedir . '/Subs.php');
1520 1572
 
1521 1573
 	// First, try to create a better date format, ignoring the "time" elements.
1522
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1523
-		$date_format = '%F';
1524
-	else
1525
-		$date_format = $matches[0];
1574
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1575
+			$date_format = '%F';
1576
+	} else {
1577
+			$date_format = $matches[0];
1578
+	}
1526 1579
 
1527 1580
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1528
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1529
-		$time_format = '%k:%M';
1530
-	else
1531
-		$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1581
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1582
+			$time_format = '%k:%M';
1583
+	} else {
1584
+			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1585
+	}
1532 1586
 
1533 1587
 	// Should this be an all day event?
1534 1588
 	$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
@@ -1537,8 +1591,9 @@  discard block
 block discarded – undo
1537 1591
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1538 1592
 
1539 1593
 	// We need to have a defined timezone in the steps below
1540
-	if (empty($row['timezone']))
1541
-		$row['timezone'] = getUserTimezone();
1594
+	if (empty($row['timezone'])) {
1595
+			$row['timezone'] = getUserTimezone();
1596
+	}
1542 1597
 
1543 1598
 	// Get most of the standard date information for the start and end datetimes
1544 1599
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1582,8 +1637,9 @@  discard block
 block discarded – undo
1582 1637
 		$tz_location = timezone_location_get(timezone_open($row['timezone']));
1583 1638
 
1584 1639
 		// Kazakstan
1585
-		if ($tz_location['country_code'] == 'KZ')
1586
-			$tz_abbrev = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tz_abbrev);
1640
+		if ($tz_location['country_code'] == 'KZ') {
1641
+					$tz_abbrev = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tz_abbrev);
1642
+		}
1587 1643
 
1588 1644
 		// Russia likes to experiment with time zones
1589 1645
 		if ($tz_location['country_code'] == 'RU')
@@ -1594,8 +1650,9 @@  discard block
 block discarded – undo
1594 1650
 		}
1595 1651
 
1596 1652
 		// Still no good? We'll just mark it as a UTC offset
1597
-		if (strspn($tz_abbrev, '+-') > 0)
1598
-			$tz_abbrev = 'UTC' . $tz_abbrev;
1653
+		if (strspn($tz_abbrev, '+-') > 0) {
1654
+					$tz_abbrev = 'UTC' . $tz_abbrev;
1655
+		}
1599 1656
 	}
1600 1657
 
1601 1658
 	return array($start, $end, $allday, $span, $tz, $tz_abbrev);
@@ -1611,8 +1668,9 @@  discard block
 block discarded – undo
1611 1668
 {
1612 1669
 	global $smcFunc, $context, $sourcedir, $user_info, $modSettings;
1613 1670
 
1614
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1615
-		$id_member = $context['user']['id'];
1671
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1672
+			$id_member = $context['user']['id'];
1673
+	}
1616 1674
 
1617 1675
 	if (isset($id_member))
1618 1676
 	{
@@ -1628,8 +1686,9 @@  discard block
 block discarded – undo
1628 1686
 		$smcFunc['db_free_result']($request);
1629 1687
 	}
1630 1688
 
1631
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1632
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1689
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1690
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1691
+	}
1633 1692
 
1634 1693
 	return $timezone;
1635 1694
 }
@@ -1658,8 +1717,9 @@  discard block
 block discarded – undo
1658 1717
 		)
1659 1718
 	);
1660 1719
 	$holidays = array();
1661
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1662
-		$holidays[] = $row;
1720
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1721
+			$holidays[] = $row;
1722
+	}
1663 1723
 	$smcFunc['db_free_result']($request);
1664 1724
 
1665 1725
 	return $holidays;
Please login to merge, or discard this patch.
other/upgrade.php 4 patches
Doc Comments   +14 added lines, -1 removed lines patch added patch discarded remove patch
@@ -388,6 +388,9 @@  discard block
 block discarded – undo
388 388
 }
389 389
 
390 390
 // Used to direct the user to another location.
391
+/**
392
+ * @param string $location
393
+ */
391 394
 function redirectLocation($location, $addForm = true)
392 395
 {
393 396
 	global $upgradeurl, $upcontext, $command_line;
@@ -1560,6 +1563,9 @@  discard block
 block discarded – undo
1560 1563
 	return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path));
1561 1564
 }
1562 1565
 
1566
+/**
1567
+ * @param string $filename
1568
+ */
1563 1569
 function parse_sql($filename)
1564 1570
 {
1565 1571
 	global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning;
@@ -1594,6 +1600,10 @@  discard block
 block discarded – undo
1594 1600
 
1595 1601
 	// Our custom error handler - does nothing but does stop public errors from XML!
1596 1602
 	set_error_handler(
1603
+
1604
+		/**
1605
+		 * @param string $errno
1606
+		 */
1597 1607
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1598 1608
 		{
1599 1609
 			if ($support_js)
@@ -1840,6 +1850,9 @@  discard block
 block discarded – undo
1840 1850
 	return true;
1841 1851
 }
1842 1852
 
1853
+/**
1854
+ * @param string $string
1855
+ */
1843 1856
 function upgrade_query($string, $unbuffered = false)
1844 1857
 {
1845 1858
 	global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings;
@@ -4495,7 +4508,7 @@  discard block
 block discarded – undo
4495 4508
  * @param int $setSize The amount of entries after which to update the database.
4496 4509
  *
4497 4510
  * newCol needs to be a varbinary(16) null able field
4498
- * @return bool
4511
+ * @return boolean|null
4499 4512
  */
4500 4513
 function MySQLConvertOldIp($targetTable, $oldCol, $newCol, $limit = 50000, $setSize = 100)
4501 4514
 {
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -1594,7 +1594,7 @@  discard block
 block discarded – undo
1594 1594
 
1595 1595
 	// Our custom error handler - does nothing but does stop public errors from XML!
1596 1596
 	set_error_handler(
1597
-		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1597
+		function($errno, $errstr, $errfile, $errline) use ($support_js)
1598 1598
 		{
1599 1599
 			if ($support_js)
1600 1600
 				return true;
@@ -2607,94 +2607,94 @@  discard block
 block discarded – undo
2607 2607
 		// Translation table for the character sets not native for MySQL.
2608 2608
 		$translation_tables = array(
2609 2609
 			'windows-1255' => array(
2610
-				'0x81' => '\'\'',		'0x8A' => '\'\'',		'0x8C' => '\'\'',
2611
-				'0x8D' => '\'\'',		'0x8E' => '\'\'',		'0x8F' => '\'\'',
2612
-				'0x90' => '\'\'',		'0x9A' => '\'\'',		'0x9C' => '\'\'',
2613
-				'0x9D' => '\'\'',		'0x9E' => '\'\'',		'0x9F' => '\'\'',
2614
-				'0xCA' => '\'\'',		'0xD9' => '\'\'',		'0xDA' => '\'\'',
2615
-				'0xDB' => '\'\'',		'0xDC' => '\'\'',		'0xDD' => '\'\'',
2616
-				'0xDE' => '\'\'',		'0xDF' => '\'\'',		'0xFB' => '0xD792',
2617
-				'0xFC' => '0xE282AC',		'0xFF' => '0xD6B2',		'0xC2' => '0xFF',
2618
-				'0x80' => '0xFC',		'0xE2' => '0xFB',		'0xA0' => '0xC2A0',
2619
-				'0xA1' => '0xC2A1',		'0xA2' => '0xC2A2',		'0xA3' => '0xC2A3',
2620
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2621
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2622
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2623
-				'0xAF' => '0xC2AF',		'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',
2624
-				'0xB2' => '0xC2B2',		'0xB3' => '0xC2B3',		'0xB4' => '0xC2B4',
2625
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2626
-				'0xB8' => '0xC2B8',		'0xB9' => '0xC2B9',		'0xBB' => '0xC2BB',
2627
-				'0xBC' => '0xC2BC',		'0xBD' => '0xC2BD',		'0xBE' => '0xC2BE',
2628
-				'0xBF' => '0xC2BF',		'0xD7' => '0xD7B3',		'0xD1' => '0xD781',
2629
-				'0xD4' => '0xD7B0',		'0xD5' => '0xD7B1',		'0xD6' => '0xD7B2',
2630
-				'0xE0' => '0xD790',		'0xEA' => '0xD79A',		'0xEC' => '0xD79C',
2631
-				'0xED' => '0xD79D',		'0xEE' => '0xD79E',		'0xEF' => '0xD79F',
2632
-				'0xF0' => '0xD7A0',		'0xF1' => '0xD7A1',		'0xF2' => '0xD7A2',
2633
-				'0xF3' => '0xD7A3',		'0xF5' => '0xD7A5',		'0xF6' => '0xD7A6',
2634
-				'0xF7' => '0xD7A7',		'0xF8' => '0xD7A8',		'0xF9' => '0xD7A9',
2635
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2636
-				'0x86' => '0xE280A0',	'0x87' => '0xE280A1',	'0x89' => '0xE280B0',
2637
-				'0x8B' => '0xE280B9',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2638
-				'0x95' => '0xE280A2',	'0x97' => '0xE28094',	'0x99' => '0xE284A2',
2639
-				'0xC0' => '0xD6B0',		'0xC1' => '0xD6B1',		'0xC3' => '0xD6B3',
2640
-				'0xC4' => '0xD6B4',		'0xC5' => '0xD6B5',		'0xC6' => '0xD6B6',
2641
-				'0xC7' => '0xD6B7',		'0xC8' => '0xD6B8',		'0xC9' => '0xD6B9',
2642
-				'0xCB' => '0xD6BB',		'0xCC' => '0xD6BC',		'0xCD' => '0xD6BD',
2643
-				'0xCE' => '0xD6BE',		'0xCF' => '0xD6BF',		'0xD0' => '0xD780',
2644
-				'0xD2' => '0xD782',		'0xE3' => '0xD793',		'0xE4' => '0xD794',
2645
-				'0xE5' => '0xD795',		'0xE7' => '0xD797',		'0xE9' => '0xD799',
2646
-				'0xFD' => '0xE2808E',	'0xFE' => '0xE2808F',	'0x92' => '0xE28099',
2647
-				'0x83' => '0xC692',		'0xD3' => '0xD783',		'0x88' => '0xCB86',
2648
-				'0x98' => '0xCB9C',		'0x91' => '0xE28098',	'0x96' => '0xE28093',
2649
-				'0xBA' => '0xC3B7',		'0x9B' => '0xE280BA',	'0xAA' => '0xC397',
2650
-				'0xA4' => '0xE282AA',	'0xE1' => '0xD791',		'0xE6' => '0xD796',
2651
-				'0xE8' => '0xD798',		'0xEB' => '0xD79B',		'0xF4' => '0xD7A4',
2610
+				'0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'',
2611
+				'0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'',
2612
+				'0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'',
2613
+				'0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'',
2614
+				'0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'',
2615
+				'0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'',
2616
+				'0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792',
2617
+				'0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF',
2618
+				'0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0',
2619
+				'0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3',
2620
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2621
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2622
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2623
+				'0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1',
2624
+				'0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4',
2625
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2626
+				'0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB',
2627
+				'0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE',
2628
+				'0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781',
2629
+				'0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2',
2630
+				'0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C',
2631
+				'0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F',
2632
+				'0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2',
2633
+				'0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6',
2634
+				'0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9',
2635
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2636
+				'0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0',
2637
+				'0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2638
+				'0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2',
2639
+				'0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3',
2640
+				'0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6',
2641
+				'0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9',
2642
+				'0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD',
2643
+				'0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780',
2644
+				'0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794',
2645
+				'0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799',
2646
+				'0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099',
2647
+				'0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86',
2648
+				'0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093',
2649
+				'0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397',
2650
+				'0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796',
2651
+				'0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4',
2652 2652
 				'0xFA' => '0xD7AA',
2653 2653
 			),
2654 2654
 			'windows-1253' => array(
2655
-				'0x81' => '\'\'',			'0x88' => '\'\'',			'0x8A' => '\'\'',
2656
-				'0x8C' => '\'\'',			'0x8D' => '\'\'',			'0x8E' => '\'\'',
2657
-				'0x8F' => '\'\'',			'0x90' => '\'\'',			'0x98' => '\'\'',
2658
-				'0x9A' => '\'\'',			'0x9C' => '\'\'',			'0x9D' => '\'\'',
2659
-				'0x9E' => '\'\'',			'0x9F' => '\'\'',			'0xAA' => '\'\'',
2660
-				'0xD2' => '0xE282AC',			'0xFF' => '0xCE92',			'0xCE' => '0xCE9E',
2661
-				'0xB8' => '0xCE88',		'0xBA' => '0xCE8A',		'0xBC' => '0xCE8C',
2662
-				'0xBE' => '0xCE8E',		'0xBF' => '0xCE8F',		'0xC0' => '0xCE90',
2663
-				'0xC8' => '0xCE98',		'0xCA' => '0xCE9A',		'0xCC' => '0xCE9C',
2664
-				'0xCD' => '0xCE9D',		'0xCF' => '0xCE9F',		'0xDA' => '0xCEAA',
2665
-				'0xE8' => '0xCEB8',		'0xEA' => '0xCEBA',		'0xEC' => '0xCEBC',
2666
-				'0xEE' => '0xCEBE',		'0xEF' => '0xCEBF',		'0xC2' => '0xFF',
2667
-				'0xBD' => '0xC2BD',		'0xED' => '0xCEBD',		'0xB2' => '0xC2B2',
2668
-				'0xA0' => '0xC2A0',		'0xA3' => '0xC2A3',		'0xA4' => '0xC2A4',
2669
-				'0xA5' => '0xC2A5',		'0xA6' => '0xC2A6',		'0xA7' => '0xC2A7',
2670
-				'0xA8' => '0xC2A8',		'0xA9' => '0xC2A9',		'0xAB' => '0xC2AB',
2671
-				'0xAC' => '0xC2AC',		'0xAD' => '0xC2AD',		'0xAE' => '0xC2AE',
2672
-				'0xB0' => '0xC2B0',		'0xB1' => '0xC2B1',		'0xB3' => '0xC2B3',
2673
-				'0xB5' => '0xC2B5',		'0xB6' => '0xC2B6',		'0xB7' => '0xC2B7',
2674
-				'0xBB' => '0xC2BB',		'0xE2' => '0xCEB2',		'0x80' => '0xD2',
2675
-				'0x82' => '0xE2809A',	'0x84' => '0xE2809E',	'0x85' => '0xE280A6',
2676
-				'0x86' => '0xE280A0',	'0xA1' => '0xCE85',		'0xA2' => '0xCE86',
2677
-				'0x87' => '0xE280A1',	'0x89' => '0xE280B0',	'0xB9' => '0xCE89',
2678
-				'0x8B' => '0xE280B9',	'0x91' => '0xE28098',	'0x99' => '0xE284A2',
2679
-				'0x92' => '0xE28099',	'0x93' => '0xE2809C',	'0x94' => '0xE2809D',
2680
-				'0x95' => '0xE280A2',	'0x96' => '0xE28093',	'0x97' => '0xE28094',
2681
-				'0x9B' => '0xE280BA',	'0xAF' => '0xE28095',	'0xB4' => '0xCE84',
2682
-				'0xC1' => '0xCE91',		'0xC3' => '0xCE93',		'0xC4' => '0xCE94',
2683
-				'0xC5' => '0xCE95',		'0xC6' => '0xCE96',		'0x83' => '0xC692',
2684
-				'0xC7' => '0xCE97',		'0xC9' => '0xCE99',		'0xCB' => '0xCE9B',
2685
-				'0xD0' => '0xCEA0',		'0xD1' => '0xCEA1',		'0xD3' => '0xCEA3',
2686
-				'0xD4' => '0xCEA4',		'0xD5' => '0xCEA5',		'0xD6' => '0xCEA6',
2687
-				'0xD7' => '0xCEA7',		'0xD8' => '0xCEA8',		'0xD9' => '0xCEA9',
2688
-				'0xDB' => '0xCEAB',		'0xDC' => '0xCEAC',		'0xDD' => '0xCEAD',
2689
-				'0xDE' => '0xCEAE',		'0xDF' => '0xCEAF',		'0xE0' => '0xCEB0',
2690
-				'0xE1' => '0xCEB1',		'0xE3' => '0xCEB3',		'0xE4' => '0xCEB4',
2691
-				'0xE5' => '0xCEB5',		'0xE6' => '0xCEB6',		'0xE7' => '0xCEB7',
2692
-				'0xE9' => '0xCEB9',		'0xEB' => '0xCEBB',		'0xF0' => '0xCF80',
2693
-				'0xF1' => '0xCF81',		'0xF2' => '0xCF82',		'0xF3' => '0xCF83',
2694
-				'0xF4' => '0xCF84',		'0xF5' => '0xCF85',		'0xF6' => '0xCF86',
2695
-				'0xF7' => '0xCF87',		'0xF8' => '0xCF88',		'0xF9' => '0xCF89',
2696
-				'0xFA' => '0xCF8A',		'0xFB' => '0xCF8B',		'0xFC' => '0xCF8C',
2697
-				'0xFD' => '0xCF8D',		'0xFE' => '0xCF8E',
2655
+				'0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'',
2656
+				'0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'',
2657
+				'0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'',
2658
+				'0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'',
2659
+				'0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'',
2660
+				'0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E',
2661
+				'0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C',
2662
+				'0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90',
2663
+				'0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C',
2664
+				'0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA',
2665
+				'0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC',
2666
+				'0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF',
2667
+				'0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2',
2668
+				'0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4',
2669
+				'0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7',
2670
+				'0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB',
2671
+				'0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE',
2672
+				'0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3',
2673
+				'0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7',
2674
+				'0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2',
2675
+				'0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6',
2676
+				'0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86',
2677
+				'0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89',
2678
+				'0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2',
2679
+				'0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D',
2680
+				'0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094',
2681
+				'0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84',
2682
+				'0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94',
2683
+				'0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692',
2684
+				'0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B',
2685
+				'0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3',
2686
+				'0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6',
2687
+				'0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9',
2688
+				'0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD',
2689
+				'0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0',
2690
+				'0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4',
2691
+				'0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7',
2692
+				'0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80',
2693
+				'0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83',
2694
+				'0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86',
2695
+				'0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89',
2696
+				'0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C',
2697
+				'0xFD' => '0xCF8D', '0xFE' => '0xCF8E',
2698 2698
 			),
2699 2699
 		);
2700 2700
 
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@
 block discarded – undo
82 82
 
83 83
 // The helper is crucial. Include it first thing.
84 84
 if (!file_exists($upgrade_path . '/upgrade-helper.php'))
85
-    die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
85
+	die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
86 86
 
87 87
 require_once($upgrade_path . '/upgrade-helper.php');
88 88
 
Please login to merge, or discard this patch.
Braces   +867 added lines, -635 removed lines patch added patch discarded remove patch
@@ -81,8 +81,9 @@  discard block
 block discarded – undo
81 81
 $upcontext['inactive_timeout'] = 10;
82 82
 
83 83
 // The helper is crucial. Include it first thing.
84
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
84
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
85 85
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
86
+}
86 87
 
87 88
 require_once($upgrade_path . '/upgrade-helper.php');
88 89
 
@@ -106,11 +107,14 @@  discard block
 block discarded – undo
106 107
 	ini_set('default_socket_timeout', 900);
107 108
 }
108 109
 // Clean the upgrade path if this is from the client.
109
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
110
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
110
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
111
+	for ($i = 1;
112
+}
113
+$i < $_SERVER['argc']; $i++)
111 114
 	{
112
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
113
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
115
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
116
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
117
+		}
114 118
 	}
115 119
 
116 120
 // Are we from the client?
@@ -118,16 +122,17 @@  discard block
 block discarded – undo
118 122
 {
119 123
 	$command_line = true;
120 124
 	$disable_security = true;
121
-}
122
-else
125
+} else {
123 126
 	$command_line = false;
127
+}
124 128
 
125 129
 // Load this now just because we can.
126 130
 require_once($upgrade_path . '/Settings.php');
127 131
 
128 132
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
129
-if (isset($language))
133
+if (isset($language)) {
130 134
 	$language = str_ireplace('-utf8', '', $language);
135
+}
131 136
 
132 137
 // Are we logged in?
133 138
 if (isset($upgradeData))
@@ -135,10 +140,12 @@  discard block
 block discarded – undo
135 140
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
136 141
 
137 142
 	// Check for sensible values.
138
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
139
-		$upcontext['user']['started'] = time();
140
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
141
-		$upcontext['user']['updated'] = 0;
143
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
144
+			$upcontext['user']['started'] = time();
145
+	}
146
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
147
+			$upcontext['user']['updated'] = 0;
148
+	}
142 149
 
143 150
 	$upcontext['started'] = $upcontext['user']['started'];
144 151
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -196,8 +203,9 @@  discard block
 block discarded – undo
196 203
 			'db_error_skip' => true,
197 204
 		)
198 205
 	);
199
-	while ($row = $smcFunc['db_fetch_assoc']($request))
200
-		$modSettings[$row['variable']] = $row['value'];
206
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
207
+			$modSettings[$row['variable']] = $row['value'];
208
+	}
201 209
 	$smcFunc['db_free_result']($request);
202 210
 }
203 211
 
@@ -207,10 +215,12 @@  discard block
 block discarded – undo
207 215
 	$modSettings['theme_url'] = 'Themes/default';
208 216
 	$modSettings['images_url'] = 'Themes/default/images';
209 217
 }
210
-if (!isset($settings['default_theme_url']))
218
+if (!isset($settings['default_theme_url'])) {
211 219
 	$settings['default_theme_url'] = $modSettings['theme_url'];
212
-if (!isset($settings['default_theme_dir']))
220
+}
221
+if (!isset($settings['default_theme_dir'])) {
213 222
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
223
+}
214 224
 
215 225
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
216 226
 // Default title...
@@ -228,13 +238,15 @@  discard block
 block discarded – undo
228 238
 	$support_js = $upcontext['upgrade_status']['js'];
229 239
 
230 240
 	// Only set this if the upgrader status says so.
231
-	if (empty($is_debug))
232
-		$is_debug = $upcontext['upgrade_status']['debug'];
241
+	if (empty($is_debug)) {
242
+			$is_debug = $upcontext['upgrade_status']['debug'];
243
+	}
233 244
 
234 245
 	// Load the language.
235
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
236
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
237
-}
246
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
247
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
248
+	}
249
+	}
238 250
 // Set the defaults.
239 251
 else
240 252
 {
@@ -252,15 +264,18 @@  discard block
 block discarded – undo
252 264
 }
253 265
 
254 266
 // If this isn't the first stage see whether they are logging in and resuming.
255
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
267
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
256 268
 	checkLogin();
269
+}
257 270
 
258
-if ($command_line)
271
+if ($command_line) {
259 272
 	cmdStep0();
273
+}
260 274
 
261 275
 // Don't error if we're using xml.
262
-if (isset($_GET['xml']))
276
+if (isset($_GET['xml'])) {
263 277
 	$upcontext['return_error'] = true;
278
+}
264 279
 
265 280
 // Loop through all the steps doing each one as required.
266 281
 $upcontext['overall_percent'] = 0;
@@ -281,10 +296,11 @@  discard block
 block discarded – undo
281 296
 		}
282 297
 
283 298
 		// Call the step and if it returns false that means pause!
284
-		if (function_exists($step[2]) && $step[2]() === false)
285
-			break;
286
-		elseif (function_exists($step[2]))
287
-			$upcontext['current_step']++;
299
+		if (function_exists($step[2]) && $step[2]() === false) {
300
+					break;
301
+		} elseif (function_exists($step[2])) {
302
+					$upcontext['current_step']++;
303
+		}
288 304
 	}
289 305
 	$upcontext['overall_percent'] += $step[3];
290 306
 }
@@ -323,17 +339,18 @@  discard block
 block discarded – undo
323 339
 		// This should not happen my dear... HELP ME DEVELOPERS!!
324 340
 		if (!empty($command_line))
325 341
 		{
326
-			if (function_exists('debug_print_backtrace'))
327
-				debug_print_backtrace();
342
+			if (function_exists('debug_print_backtrace')) {
343
+							debug_print_backtrace();
344
+			}
328 345
 
329 346
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
330 347
 			flush();
331 348
 			die();
332 349
 		}
333 350
 
334
-		if (!isset($_GET['xml']))
335
-			template_upgrade_above();
336
-		else
351
+		if (!isset($_GET['xml'])) {
352
+					template_upgrade_above();
353
+		} else
337 354
 		{
338 355
 			header('Content-Type: text/xml; charset=UTF-8');
339 356
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -355,21 +372,24 @@  discard block
 block discarded – undo
355 372
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
356 373
 
357 374
 			// Custom stuff to pass back?
358
-			if (!empty($upcontext['query_string']))
359
-				$upcontext['form_url'] .= $upcontext['query_string'];
375
+			if (!empty($upcontext['query_string'])) {
376
+							$upcontext['form_url'] .= $upcontext['query_string'];
377
+			}
360 378
 
361 379
 			call_user_func('template_' . $upcontext['sub_template']);
362 380
 		}
363 381
 
364 382
 		// Was there an error?
365
-		if (!empty($upcontext['forced_error_message']))
366
-			echo $upcontext['forced_error_message'];
383
+		if (!empty($upcontext['forced_error_message'])) {
384
+					echo $upcontext['forced_error_message'];
385
+		}
367 386
 
368 387
 		// Show the footer.
369
-		if (!isset($_GET['xml']))
370
-			template_upgrade_below();
371
-		else
372
-			template_xml_below();
388
+		if (!isset($_GET['xml'])) {
389
+					template_upgrade_below();
390
+		} else {
391
+					template_xml_below();
392
+		}
373 393
 	}
374 394
 
375 395
 
@@ -381,15 +401,19 @@  discard block
 block discarded – undo
381 401
 		$seconds = intval($active % 60);
382 402
 
383 403
 		$totalTime = '';
384
-		if ($hours > 0)
385
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
386
-		if ($minutes > 0)
387
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
388
-		if ($seconds > 0)
389
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
404
+		if ($hours > 0) {
405
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
406
+		}
407
+		if ($minutes > 0) {
408
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
409
+		}
410
+		if ($seconds > 0) {
411
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
412
+		}
390 413
 
391
-		if (!empty($totalTime))
392
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
414
+		if (!empty($totalTime)) {
415
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
416
+		}
393 417
 	}
394 418
 
395 419
 	// Bang - gone!
@@ -402,8 +426,9 @@  discard block
 block discarded – undo
402 426
 	global $upgradeurl, $upcontext, $command_line;
403 427
 
404 428
 	// Command line users can't be redirected.
405
-	if ($command_line)
406
-		upgradeExit(true);
429
+	if ($command_line) {
430
+			upgradeExit(true);
431
+	}
407 432
 
408 433
 	// Are we providing the core info?
409 434
 	if ($addForm)
@@ -426,19 +451,22 @@  discard block
 block discarded – undo
426 451
 	global $modSettings, $sourcedir, $smcFunc;
427 452
 
428 453
 	// Do the non-SSI stuff...
429
-	if (function_exists('set_magic_quotes_runtime'))
430
-		@set_magic_quotes_runtime(0);
454
+	if (function_exists('set_magic_quotes_runtime')) {
455
+			@set_magic_quotes_runtime(0);
456
+	}
431 457
 
432 458
 	error_reporting(E_ALL);
433 459
 	define('SMF', 1);
434 460
 
435 461
 	// Start the session.
436
-	if (@ini_get('session.save_handler') == 'user')
437
-		@ini_set('session.save_handler', 'files');
462
+	if (@ini_get('session.save_handler') == 'user') {
463
+			@ini_set('session.save_handler', 'files');
464
+	}
438 465
 	@session_start();
439 466
 
440
-	if (empty($smcFunc))
441
-		$smcFunc = array();
467
+	if (empty($smcFunc)) {
468
+			$smcFunc = array();
469
+	}
442 470
 
443 471
 	// We need this for authentication and some upgrade code
444 472
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -450,8 +478,9 @@  discard block
 block discarded – undo
450 478
 	initialize_inputs();
451 479
 
452 480
 	// Get the database going!
453
-	if (empty($db_type) || $db_type == 'mysqli')
454
-		$db_type = 'mysql';
481
+	if (empty($db_type) || $db_type == 'mysqli') {
482
+			$db_type = 'mysql';
483
+	}
455 484
 
456 485
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
457 486
 	{
@@ -461,17 +490,19 @@  discard block
 block discarded – undo
461 490
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
462 491
 
463 492
 		// Oh dear god!!
464
-		if ($db_connection === null)
465
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
493
+		if ($db_connection === null) {
494
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
495
+		}
466 496
 
467
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
468
-			$smcFunc['db_query']('', '
497
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
498
+					$smcFunc['db_query']('', '
469 499
 			SET NAMES {string:db_character_set}',
470 500
 			array(
471 501
 				'db_error_skip' => true,
472 502
 				'db_character_set' => $db_character_set,
473 503
 			)
474 504
 		);
505
+		}
475 506
 
476 507
 		// Load the modSettings data...
477 508
 		$request = $smcFunc['db_query']('', '
@@ -482,11 +513,11 @@  discard block
 block discarded – undo
482 513
 			)
483 514
 		);
484 515
 		$modSettings = array();
485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
486
-			$modSettings[$row['variable']] = $row['value'];
516
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
517
+					$modSettings[$row['variable']] = $row['value'];
518
+		}
487 519
 		$smcFunc['db_free_result']($request);
488
-	}
489
-	else
520
+	} else
490 521
 	{
491 522
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
492 523
 	}
@@ -500,9 +531,10 @@  discard block
 block discarded – undo
500 531
 		cleanRequest();
501 532
 	}
502 533
 
503
-	if (!isset($_GET['substep']))
504
-		$_GET['substep'] = 0;
505
-}
534
+	if (!isset($_GET['substep'])) {
535
+			$_GET['substep'] = 0;
536
+	}
537
+	}
506 538
 
507 539
 function initialize_inputs()
508 540
 {
@@ -532,8 +564,9 @@  discard block
 block discarded – undo
532 564
 		$dh = opendir(dirname(__FILE__));
533 565
 		while ($file = readdir($dh))
534 566
 		{
535
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
536
-				@unlink(dirname(__FILE__) . '/' . $file);
567
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
568
+							@unlink(dirname(__FILE__) . '/' . $file);
569
+			}
537 570
 		}
538 571
 		closedir($dh);
539 572
 
@@ -563,8 +596,9 @@  discard block
 block discarded – undo
563 596
 	{
564 597
 		$upcontext['remote_files_available'] = false;
565 598
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
566
-		if ($test)
567
-			$upcontext['remote_files_available'] = true;
599
+		if ($test) {
600
+					$upcontext['remote_files_available'] = true;
601
+		}
568 602
 		@fclose($test);
569 603
 	}
570 604
 
@@ -572,8 +606,9 @@  discard block
 block discarded – undo
572 606
 	$temp = 'upgrade_php?step';
573 607
 	while (strlen($temp) > 4)
574 608
 	{
575
-		if (isset($_GET[$temp]))
576
-			unset($_GET[$temp]);
609
+		if (isset($_GET[$temp])) {
610
+					unset($_GET[$temp]);
611
+		}
577 612
 		$temp = substr($temp, 1);
578 613
 	}
579 614
 
@@ -600,32 +635,39 @@  discard block
 block discarded – undo
600 635
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
601 636
 
602 637
 	// Need legacy scripts?
603
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
604
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
605
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
606
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
607
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
608
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
638
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
639
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
640
+	}
641
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
642
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
643
+	}
644
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
645
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
646
+	}
609 647
 
610 648
 	// We don't need "-utf8" files anymore...
611 649
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
612 650
 
613 651
 	// This needs to exist!
614
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
615
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
616
-	else
617
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
652
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
653
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
654
+	} else {
655
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
656
+	}
618 657
 
619
-	if (!$check)
620
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
658
+	if (!$check) {
659
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
621 660
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
661
+	}
622 662
 
623 663
 	// Do they meet the install requirements?
624
-	if (!php_version_check())
625
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
664
+	if (!php_version_check()) {
665
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
666
+	}
626 667
 
627
-	if (!db_version_check())
628
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
668
+	if (!db_version_check()) {
669
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
670
+	}
629 671
 
630 672
 	// Do some checks to make sure they have proper privileges
631 673
 	db_extend('packages');
@@ -640,14 +682,16 @@  discard block
 block discarded – undo
640 682
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
641 683
 
642 684
 	// Sorry... we need CREATE, ALTER and DROP
643
-	if (!$create || !$alter || !$drop)
644
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
685
+	if (!$create || !$alter || !$drop) {
686
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
687
+	}
645 688
 
646 689
 	// Do a quick version spot check.
647 690
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
648 691
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
649
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
650
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
692
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
693
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
694
+	}
651 695
 
652 696
 	// What absolutely needs to be writable?
653 697
 	$writable_files = array(
@@ -669,12 +713,13 @@  discard block
 block discarded – undo
669 713
 	quickFileWritable($custom_av_dir);
670 714
 
671 715
 	// Are we good now?
672
-	if (!is_writable($custom_av_dir))
673
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
674
-	elseif ($need_settings_update)
716
+	if (!is_writable($custom_av_dir)) {
717
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
718
+	} elseif ($need_settings_update)
675 719
 	{
676
-		if (!function_exists('cache_put_data'))
677
-			require_once($sourcedir . '/Load.php');
720
+		if (!function_exists('cache_put_data')) {
721
+					require_once($sourcedir . '/Load.php');
722
+		}
678 723
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
679 724
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
680 725
 	}
@@ -683,28 +728,33 @@  discard block
 block discarded – undo
683 728
 
684 729
 	// Check the cache directory.
685 730
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
686
-	if (!file_exists($cachedir_temp))
687
-		@mkdir($cachedir_temp);
688
-	if (!file_exists($cachedir_temp))
689
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
690
-
691
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
692
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
693
-	elseif (!isset($_GET['skiplang']))
731
+	if (!file_exists($cachedir_temp)) {
732
+			@mkdir($cachedir_temp);
733
+	}
734
+	if (!file_exists($cachedir_temp)) {
735
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
736
+	}
737
+
738
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
739
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
740
+	} elseif (!isset($_GET['skiplang']))
694 741
 	{
695 742
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
696 743
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
697 744
 
698
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
699
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
745
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
746
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
747
+		}
700 748
 	}
701 749
 
702
-	if (!makeFilesWritable($writable_files))
703
-		return false;
750
+	if (!makeFilesWritable($writable_files)) {
751
+			return false;
752
+	}
704 753
 
705 754
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
706
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
707
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
755
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
756
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
757
+	}
708 758
 
709 759
 	// Upgrade the agreement.
710 760
 	elseif (isset($modSettings['agreement']))
@@ -715,8 +765,8 @@  discard block
 block discarded – undo
715 765
 	}
716 766
 
717 767
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
718
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
719
-		$upcontext['warning'] = '
768
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
769
+			$upcontext['warning'] = '
720 770
 			It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br>
721 771
 			<ul>
722 772
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -724,10 +774,12 @@  discard block
 block discarded – undo
724 774
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
725 775
 			</ul>
726 776
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="http://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
777
+	}
727 778
 
728 779
 	// Either we're logged in or we're going to present the login.
729
-	if (checkLogin())
730
-		return true;
780
+	if (checkLogin()) {
781
+			return true;
782
+	}
731 783
 
732 784
 	$upcontext += createToken('login');
733 785
 
@@ -741,15 +793,17 @@  discard block
 block discarded – undo
741 793
 	global $smcFunc, $db_type, $support_js;
742 794
 
743 795
 	// Don't bother if the security is disabled.
744
-	if ($disable_security)
745
-		return true;
796
+	if ($disable_security) {
797
+			return true;
798
+	}
746 799
 
747 800
 	// Are we trying to login?
748 801
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
749 802
 	{
750 803
 		// If we've disabled security pick a suitable name!
751
-		if (empty($_POST['user']))
752
-			$_POST['user'] = 'Administrator';
804
+		if (empty($_POST['user'])) {
805
+					$_POST['user'] = 'Administrator';
806
+		}
753 807
 
754 808
 		// Before 2.0 these column names were different!
755 809
 		$oldDB = false;
@@ -764,16 +818,17 @@  discard block
 block discarded – undo
764 818
 					'db_error_skip' => true,
765 819
 				)
766 820
 			);
767
-			if ($smcFunc['db_num_rows']($request) != 0)
768
-				$oldDB = true;
821
+			if ($smcFunc['db_num_rows']($request) != 0) {
822
+							$oldDB = true;
823
+			}
769 824
 			$smcFunc['db_free_result']($request);
770 825
 		}
771 826
 
772 827
 		// Get what we believe to be their details.
773 828
 		if (!$disable_security)
774 829
 		{
775
-			if ($oldDB)
776
-				$request = $smcFunc['db_query']('', '
830
+			if ($oldDB) {
831
+							$request = $smcFunc['db_query']('', '
777 832
 					SELECT id_member, memberName AS member_name, passwd, id_group,
778 833
 					additionalGroups AS additional_groups, lngfile
779 834
 					FROM {db_prefix}members
@@ -783,8 +838,8 @@  discard block
 block discarded – undo
783 838
 						'db_error_skip' => true,
784 839
 					)
785 840
 				);
786
-			else
787
-				$request = $smcFunc['db_query']('', '
841
+			} else {
842
+							$request = $smcFunc['db_query']('', '
788 843
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
789 844
 					FROM {db_prefix}members
790 845
 					WHERE member_name = {string:member_name}',
@@ -793,6 +848,7 @@  discard block
 block discarded – undo
793 848
 						'db_error_skip' => true,
794 849
 					)
795 850
 				);
851
+			}
796 852
 			if ($smcFunc['db_num_rows']($request) != 0)
797 853
 			{
798 854
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -800,16 +856,17 @@  discard block
 block discarded – undo
800 856
 				$groups = explode(',', $addGroups);
801 857
 				$groups[] = $id_group;
802 858
 
803
-				foreach ($groups as $k => $v)
804
-					$groups[$k] = (int) $v;
859
+				foreach ($groups as $k => $v) {
860
+									$groups[$k] = (int) $v;
861
+				}
805 862
 
806 863
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
807 864
 
808 865
 				// We don't use "-utf8" anymore...
809 866
 				$user_language = str_ireplace('-utf8', '', $user_language);
867
+			} else {
868
+							$upcontext['username_incorrect'] = true;
810 869
 			}
811
-			else
812
-				$upcontext['username_incorrect'] = true;
813 870
 			$smcFunc['db_free_result']($request);
814 871
 		}
815 872
 		$upcontext['username'] = $_POST['user'];
@@ -819,13 +876,14 @@  discard block
 block discarded – undo
819 876
 		{
820 877
 			$upcontext['upgrade_status']['js'] = 1;
821 878
 			$support_js = 1;
879
+		} else {
880
+					$support_js = 0;
822 881
 		}
823
-		else
824
-			$support_js = 0;
825 882
 
826 883
 		// Note down the version we are coming from.
827
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
828
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
884
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
885
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
886
+		}
829 887
 
830 888
 		// Didn't get anywhere?
831 889
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -859,15 +917,15 @@  discard block
 block discarded – undo
859 917
 							'db_error_skip' => true,
860 918
 						)
861 919
 					);
862
-					if ($smcFunc['db_num_rows']($request) == 0)
863
-						return throw_error('You need to be an admin to perform an upgrade!');
920
+					if ($smcFunc['db_num_rows']($request) == 0) {
921
+											return throw_error('You need to be an admin to perform an upgrade!');
922
+					}
864 923
 					$smcFunc['db_free_result']($request);
865 924
 				}
866 925
 
867 926
 				$upcontext['user']['id'] = $id_member;
868 927
 				$upcontext['user']['name'] = $name;
869
-			}
870
-			else
928
+			} else
871 929
 			{
872 930
 				$upcontext['user']['id'] = 1;
873 931
 				$upcontext['user']['name'] = 'Administrator';
@@ -883,11 +941,11 @@  discard block
 block discarded – undo
883 941
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
884 942
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
885 943
 
886
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
887
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
888
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
889
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
890
-				else
944
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
945
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
946
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
947
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
948
+				} else
891 949
 				{
892 950
 					// Set this as the new language.
893 951
 					$upcontext['language'] = $user_language;
@@ -931,8 +989,9 @@  discard block
 block discarded – undo
931 989
 	unset($member_columns);
932 990
 
933 991
 	// If we've not submitted then we're done.
934
-	if (empty($_POST['upcont']))
935
-		return false;
992
+	if (empty($_POST['upcont'])) {
993
+			return false;
994
+	}
936 995
 
937 996
 	// Firstly, if they're enabling SM stat collection just do it.
938 997
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
@@ -947,25 +1006,26 @@  discard block
 block discarded – undo
947 1006
 			fwrite($fp, $out);
948 1007
 
949 1008
 			$return_data = '';
950
-			while (!feof($fp))
951
-				$return_data .= fgets($fp, 128);
1009
+			while (!feof($fp)) {
1010
+							$return_data .= fgets($fp, 128);
1011
+			}
952 1012
 
953 1013
 			fclose($fp);
954 1014
 
955 1015
 			// Get the unique site ID.
956 1016
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
957 1017
 
958
-			if (!empty($ID[1]))
959
-				$smcFunc['db_insert']('replace',
1018
+			if (!empty($ID[1])) {
1019
+							$smcFunc['db_insert']('replace',
960 1020
 					$db_prefix . 'settings',
961 1021
 					array('variable' => 'string', 'value' => 'string'),
962 1022
 					array('allow_sm_stats', $ID[1]),
963 1023
 					array('variable')
964 1024
 				);
1025
+			}
965 1026
 		}
966
-	}
967
-	else
968
-		$smcFunc['db_query']('', '
1027
+	} else {
1028
+			$smcFunc['db_query']('', '
969 1029
 			DELETE FROM {db_prefix}settings
970 1030
 			WHERE variable = {string:allow_sm_stats}',
971 1031
 			array(
@@ -973,6 +1033,7 @@  discard block
 block discarded – undo
973 1033
 				'db_error_skip' => true,
974 1034
 			)
975 1035
 		);
1036
+	}
976 1037
 
977 1038
 	// Deleting old karma stuff?
978 1039
 	if (!empty($_POST['delete_karma']))
@@ -987,20 +1048,22 @@  discard block
 block discarded – undo
987 1048
 		);
988 1049
 
989 1050
 		// Cleaning up old karma member settings.
990
-		if ($upcontext['karma_installed']['good'])
991
-			$smcFunc['db_query']('', '
1051
+		if ($upcontext['karma_installed']['good']) {
1052
+					$smcFunc['db_query']('', '
992 1053
 				ALTER TABLE {db_prefix}members
993 1054
 				DROP karma_good',
994 1055
 				array()
995 1056
 			);
1057
+		}
996 1058
 
997 1059
 		// Does karma bad was enable?
998
-		if ($upcontext['karma_installed']['bad'])
999
-			$smcFunc['db_query']('', '
1060
+		if ($upcontext['karma_installed']['bad']) {
1061
+					$smcFunc['db_query']('', '
1000 1062
 				ALTER TABLE {db_prefix}members
1001 1063
 				DROP karma_bad',
1002 1064
 				array()
1003 1065
 			);
1066
+		}
1004 1067
 
1005 1068
 		// Cleaning up old karma permissions.
1006 1069
 		$smcFunc['db_query']('', '
@@ -1013,26 +1076,29 @@  discard block
 block discarded – undo
1013 1076
 	}
1014 1077
 
1015 1078
 	// Emptying the error log?
1016
-	if (!empty($_POST['empty_error']))
1017
-		$smcFunc['db_query']('truncate_table', '
1079
+	if (!empty($_POST['empty_error'])) {
1080
+			$smcFunc['db_query']('truncate_table', '
1018 1081
 			TRUNCATE {db_prefix}log_errors',
1019 1082
 			array(
1020 1083
 			)
1021 1084
 		);
1085
+	}
1022 1086
 
1023 1087
 	$changes = array();
1024 1088
 
1025 1089
 	// Add proxy settings.
1026
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1027
-		$changes += array(
1090
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1091
+			$changes += array(
1028 1092
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1029 1093
 			'image_proxy_maxsize' => 5190,
1030 1094
 			'image_proxy_enabled' => 0,
1031 1095
 		);
1096
+	}
1032 1097
 
1033 1098
 	// If we're overriding the language follow it through.
1034
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1035
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1099
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1100
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1101
+	}
1036 1102
 
1037 1103
 	if (!empty($_POST['maint']))
1038 1104
 	{
@@ -1044,30 +1110,34 @@  discard block
 block discarded – undo
1044 1110
 		{
1045 1111
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1046 1112
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1047
-		}
1048
-		else
1113
+		} else
1049 1114
 		{
1050 1115
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1051 1116
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1052 1117
 		}
1053 1118
 	}
1054 1119
 
1055
-	if ($command_line)
1056
-		echo ' * Updating Settings.php...';
1120
+	if ($command_line) {
1121
+			echo ' * Updating Settings.php...';
1122
+	}
1057 1123
 
1058 1124
 	// Fix some old paths.
1059
-	if (substr($boarddir, 0, 1) == '.')
1060
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1125
+	if (substr($boarddir, 0, 1) == '.') {
1126
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1127
+	}
1061 1128
 
1062
-	if (substr($sourcedir, 0, 1) == '.')
1063
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1129
+	if (substr($sourcedir, 0, 1) == '.') {
1130
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1131
+	}
1064 1132
 
1065
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1066
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1133
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1134
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1135
+	}
1067 1136
 
1068 1137
 	// Not had the database type added before?
1069
-	if (empty($db_type))
1070
-		$changes['db_type'] = 'mysql';
1138
+	if (empty($db_type)) {
1139
+			$changes['db_type'] = 'mysql';
1140
+	}
1071 1141
 
1072 1142
 	// If they have a "host:port" setup for the host, split that into separate values
1073 1143
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1078,32 +1148,36 @@  discard block
 block discarded – undo
1078 1148
 		$changes['db_server'] = '\'' . $db_server . '\'';
1079 1149
 
1080 1150
 		// Only set this if we're not using the default port
1081
-		if ($db_port != ini_get('mysqli.default_port'))
1082
-			$changes['db_port'] = (int) $db_port;
1083
-	}
1084
-	elseif (!empty($db_port))
1151
+		if ($db_port != ini_get('mysqli.default_port')) {
1152
+					$changes['db_port'] = (int) $db_port;
1153
+		}
1154
+	} elseif (!empty($db_port))
1085 1155
 	{
1086 1156
 		// If db_port is set and is the same as the default, set it to ''
1087 1157
 		if ($db_type == 'mysql')
1088 1158
 		{
1089
-			if ($db_port == ini_get('mysqli.default_port'))
1090
-				$changes['db_port'] = '\'\'';
1091
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1092
-				$changes['db_port'] = '\'\'';
1159
+			if ($db_port == ini_get('mysqli.default_port')) {
1160
+							$changes['db_port'] = '\'\'';
1161
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1162
+							$changes['db_port'] = '\'\'';
1163
+			}
1093 1164
 		}
1094 1165
 	}
1095 1166
 
1096 1167
 	// Maybe we haven't had this option yet?
1097
-	if (empty($packagesdir))
1098
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1168
+	if (empty($packagesdir)) {
1169
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1170
+	}
1099 1171
 
1100 1172
 	// Add support for $tasksdir var.
1101
-	if (empty($tasksdir))
1102
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1173
+	if (empty($tasksdir)) {
1174
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1175
+	}
1103 1176
 
1104 1177
 	// Make sure we fix the language as well.
1105
-	if (stristr($language, '-utf8'))
1106
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1178
+	if (stristr($language, '-utf8')) {
1179
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1180
+	}
1107 1181
 
1108 1182
 	// @todo Maybe change the cookie name if going to 1.1, too?
1109 1183
 
@@ -1111,8 +1185,9 @@  discard block
 block discarded – undo
1111 1185
 	require_once($sourcedir . '/Subs-Admin.php');
1112 1186
 	updateSettingsFile($changes);
1113 1187
 
1114
-	if ($command_line)
1115
-		echo ' Successful.' . "\n";
1188
+	if ($command_line) {
1189
+			echo ' Successful.' . "\n";
1190
+	}
1116 1191
 
1117 1192
 	// Are we doing debug?
1118 1193
 	if (isset($_POST['debug']))
@@ -1122,8 +1197,9 @@  discard block
 block discarded – undo
1122 1197
 	}
1123 1198
 
1124 1199
 	// If we're not backing up then jump one.
1125
-	if (empty($_POST['backup']))
1126
-		$upcontext['current_step']++;
1200
+	if (empty($_POST['backup'])) {
1201
+			$upcontext['current_step']++;
1202
+	}
1127 1203
 
1128 1204
 	// If we've got here then let's proceed to the next step!
1129 1205
 	return true;
@@ -1138,8 +1214,9 @@  discard block
 block discarded – undo
1138 1214
 	$upcontext['page_title'] = 'Backup Database';
1139 1215
 
1140 1216
 	// Done it already - js wise?
1141
-	if (!empty($_POST['backup_done']))
1142
-		return true;
1217
+	if (!empty($_POST['backup_done'])) {
1218
+			return true;
1219
+	}
1143 1220
 
1144 1221
 	// Some useful stuff here.
1145 1222
 	db_extend();
@@ -1153,9 +1230,10 @@  discard block
 block discarded – undo
1153 1230
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1154 1231
 
1155 1232
 	$table_names = array();
1156
-	foreach ($tables as $table)
1157
-		if (substr($table, 0, 7) !== 'backup_')
1233
+	foreach ($tables as $table) {
1234
+			if (substr($table, 0, 7) !== 'backup_')
1158 1235
 			$table_names[] = $table;
1236
+	}
1159 1237
 
1160 1238
 	$upcontext['table_count'] = count($table_names);
1161 1239
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1165,12 +1243,14 @@  discard block
 block discarded – undo
1165 1243
 	$file_steps = $upcontext['table_count'];
1166 1244
 
1167 1245
 	// What ones have we already done?
1168
-	foreach ($table_names as $id => $table)
1169
-		if ($id < $_GET['substep'])
1246
+	foreach ($table_names as $id => $table) {
1247
+			if ($id < $_GET['substep'])
1170 1248
 			$upcontext['previous_tables'][] = $table;
1249
+	}
1171 1250
 
1172
-	if ($command_line)
1173
-		echo 'Backing Up Tables.';
1251
+	if ($command_line) {
1252
+			echo 'Backing Up Tables.';
1253
+	}
1174 1254
 
1175 1255
 	// If we don't support javascript we backup here.
1176 1256
 	if (!$support_js || isset($_GET['xml']))
@@ -1189,8 +1269,9 @@  discard block
 block discarded – undo
1189 1269
 			backupTable($table_names[$substep]);
1190 1270
 
1191 1271
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1192
-			if (isset($_GET['xml']))
1193
-				return upgradeExit();
1272
+			if (isset($_GET['xml'])) {
1273
+							return upgradeExit();
1274
+			}
1194 1275
 		}
1195 1276
 
1196 1277
 		if ($command_line)
@@ -1223,9 +1304,10 @@  discard block
 block discarded – undo
1223 1304
 
1224 1305
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1225 1306
 
1226
-	if ($command_line)
1227
-		echo ' done.';
1228
-}
1307
+	if ($command_line) {
1308
+			echo ' done.';
1309
+	}
1310
+	}
1229 1311
 
1230 1312
 // Step 2: Everything.
1231 1313
 function DatabaseChanges()
@@ -1234,8 +1316,9 @@  discard block
 block discarded – undo
1234 1316
 	global $upcontext, $support_js, $db_type;
1235 1317
 
1236 1318
 	// Have we just completed this?
1237
-	if (!empty($_POST['database_done']))
1238
-		return true;
1319
+	if (!empty($_POST['database_done'])) {
1320
+			return true;
1321
+	}
1239 1322
 
1240 1323
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1241 1324
 	$upcontext['page_title'] = 'Database Changes';
@@ -1250,15 +1333,16 @@  discard block
 block discarded – undo
1250 1333
 	);
1251 1334
 
1252 1335
 	// How many files are there in total?
1253
-	if (isset($_GET['filecount']))
1254
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1255
-	else
1336
+	if (isset($_GET['filecount'])) {
1337
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1338
+	} else
1256 1339
 	{
1257 1340
 		$upcontext['file_count'] = 0;
1258 1341
 		foreach ($files as $file)
1259 1342
 		{
1260
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1261
-				$upcontext['file_count']++;
1343
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1344
+							$upcontext['file_count']++;
1345
+			}
1262 1346
 		}
1263 1347
 	}
1264 1348
 
@@ -1268,9 +1352,9 @@  discard block
 block discarded – undo
1268 1352
 	$upcontext['cur_file_num'] = 0;
1269 1353
 	foreach ($files as $file)
1270 1354
 	{
1271
-		if ($did_not_do)
1272
-			$did_not_do--;
1273
-		else
1355
+		if ($did_not_do) {
1356
+					$did_not_do--;
1357
+		} else
1274 1358
 		{
1275 1359
 			$upcontext['cur_file_num']++;
1276 1360
 			$upcontext['cur_file_name'] = $file[0];
@@ -1297,12 +1381,13 @@  discard block
 block discarded – undo
1297 1381
 					// Flag to move on to the next.
1298 1382
 					$upcontext['completed_step'] = true;
1299 1383
 					// Did we complete the whole file?
1300
-					if ($nextFile)
1301
-						$upcontext['current_debug_item_num'] = -1;
1384
+					if ($nextFile) {
1385
+											$upcontext['current_debug_item_num'] = -1;
1386
+					}
1302 1387
 					return upgradeExit();
1388
+				} elseif ($support_js) {
1389
+									break;
1303 1390
 				}
1304
-				elseif ($support_js)
1305
-					break;
1306 1391
 			}
1307 1392
 			// Set the progress bar to be right as if we had - even if we hadn't...
1308 1393
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1327,8 +1412,9 @@  discard block
 block discarded – undo
1327 1412
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1328 1413
 
1329 1414
 	// Now it's nice to have some of the basic SMF source files.
1330
-	if (!isset($_GET['ssi']) && !$command_line)
1331
-		redirectLocation('&ssi=1');
1415
+	if (!isset($_GET['ssi']) && !$command_line) {
1416
+			redirectLocation('&ssi=1');
1417
+	}
1332 1418
 
1333 1419
 	$upcontext['sub_template'] = 'upgrade_complete';
1334 1420
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1344,14 +1430,16 @@  discard block
 block discarded – undo
1344 1430
 	// Are we in maintenance mode?
1345 1431
 	if (isset($upcontext['user']['main']))
1346 1432
 	{
1347
-		if ($command_line)
1348
-			echo ' * ';
1433
+		if ($command_line) {
1434
+					echo ' * ';
1435
+		}
1349 1436
 		$upcontext['removed_maintenance'] = true;
1350 1437
 		$changes['maintenance'] = $upcontext['user']['main'];
1351 1438
 	}
1352 1439
 	// Otherwise if somehow we are in 2 let's go to 1.
1353
-	elseif (!empty($maintenance) && $maintenance == 2)
1354
-		$changes['maintenance'] = 1;
1440
+	elseif (!empty($maintenance) && $maintenance == 2) {
1441
+			$changes['maintenance'] = 1;
1442
+	}
1355 1443
 
1356 1444
 	// Wipe this out...
1357 1445
 	$upcontext['user'] = array();
@@ -1366,9 +1454,9 @@  discard block
 block discarded – undo
1366 1454
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1367 1455
 
1368 1456
 	// Now is the perfect time to fetch the SM files.
1369
-	if ($command_line)
1370
-		cli_scheduled_fetchSMfiles();
1371
-	else
1457
+	if ($command_line) {
1458
+			cli_scheduled_fetchSMfiles();
1459
+	} else
1372 1460
 	{
1373 1461
 		require_once($sourcedir . '/ScheduledTasks.php');
1374 1462
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1376,8 +1464,9 @@  discard block
 block discarded – undo
1376 1464
 	}
1377 1465
 
1378 1466
 	// Log what we've done.
1379
-	if (empty($user_info['id']))
1380
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1467
+	if (empty($user_info['id'])) {
1468
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1469
+	}
1381 1470
 
1382 1471
 	// Log the action manually, so CLI still works.
1383 1472
 	$smcFunc['db_insert']('',
@@ -1396,8 +1485,9 @@  discard block
 block discarded – undo
1396 1485
 
1397 1486
 	// Save the current database version.
1398 1487
 	$server_version = $smcFunc['db_server_info']();
1399
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1400
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1488
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1489
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1490
+	}
1401 1491
 
1402 1492
 	if ($command_line)
1403 1493
 	{
@@ -1409,8 +1499,9 @@  discard block
 block discarded – undo
1409 1499
 
1410 1500
 	// Make sure it says we're done.
1411 1501
 	$upcontext['overall_percent'] = 100;
1412
-	if (isset($upcontext['step_progress']))
1413
-		unset($upcontext['step_progress']);
1502
+	if (isset($upcontext['step_progress'])) {
1503
+			unset($upcontext['step_progress']);
1504
+	}
1414 1505
 
1415 1506
 	$_GET['substep'] = 0;
1416 1507
 	return false;
@@ -1421,8 +1512,9 @@  discard block
 block discarded – undo
1421 1512
 {
1422 1513
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1423 1514
 
1424
-	if (empty($modSettings['time_format']))
1425
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1515
+	if (empty($modSettings['time_format'])) {
1516
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1517
+	}
1426 1518
 
1427 1519
 	// What files do we want to get
1428 1520
 	$request = $smcFunc['db_query']('', '
@@ -1456,8 +1548,9 @@  discard block
 block discarded – undo
1456 1548
 		$file_data = fetch_web_data($url);
1457 1549
 
1458 1550
 		// If we got an error - give up - the site might be down.
1459
-		if ($file_data === false)
1460
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1551
+		if ($file_data === false) {
1552
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1553
+		}
1461 1554
 
1462 1555
 		// Save the file to the database.
1463 1556
 		$smcFunc['db_query']('substring', '
@@ -1499,8 +1592,9 @@  discard block
 block discarded – undo
1499 1592
 	$themeData = array();
1500 1593
 	foreach ($values as $variable => $value)
1501 1594
 	{
1502
-		if (!isset($value) || $value === null)
1503
-			$value = 0;
1595
+		if (!isset($value) || $value === null) {
1596
+					$value = 0;
1597
+		}
1504 1598
 
1505 1599
 		$themeData[] = array(0, 1, $variable, $value);
1506 1600
 	}
@@ -1529,8 +1623,9 @@  discard block
 block discarded – undo
1529 1623
 
1530 1624
 	foreach ($values as $variable => $value)
1531 1625
 	{
1532
-		if (empty($modSettings[$value[0]]))
1533
-			continue;
1626
+		if (empty($modSettings[$value[0]])) {
1627
+					continue;
1628
+		}
1534 1629
 
1535 1630
 		$smcFunc['db_query']('', '
1536 1631
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1616,10 +1711,11 @@  discard block
 block discarded – undo
1616 1711
 	set_error_handler(
1617 1712
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1618 1713
 		{
1619
-			if ($support_js)
1620
-				return true;
1621
-			else
1622
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1714
+			if ($support_js) {
1715
+							return true;
1716
+			} else {
1717
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1718
+			}
1623 1719
 		}
1624 1720
 	);
1625 1721
 
@@ -1634,8 +1730,9 @@  discard block
 block discarded – undo
1634 1730
 				'db_error_skip' => true,
1635 1731
 			)
1636 1732
 		);
1637
-		if ($smcFunc['db_num_rows']($request) === 0)
1638
-			die('Unable to find members table!');
1733
+		if ($smcFunc['db_num_rows']($request) === 0) {
1734
+					die('Unable to find members table!');
1735
+		}
1639 1736
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1640 1737
 		$smcFunc['db_free_result']($request);
1641 1738
 
@@ -1650,17 +1747,20 @@  discard block
 block discarded – undo
1650 1747
 				)
1651 1748
 			);
1652 1749
 			// Got something?
1653
-			if ($smcFunc['db_num_rows']($request) !== 0)
1654
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1750
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1751
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1752
+			}
1655 1753
 			$smcFunc['db_free_result']($request);
1656 1754
 
1657 1755
 			// Excellent!
1658
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1659
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1756
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1757
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1758
+			}
1660 1759
 		}
1661 1760
 	}
1662
-	if (empty($db_collation))
1663
-		$db_collation = '';
1761
+	if (empty($db_collation)) {
1762
+			$db_collation = '';
1763
+	}
1664 1764
 
1665 1765
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1666 1766
 
@@ -1672,8 +1772,9 @@  discard block
 block discarded – undo
1672 1772
 	$last_step = '';
1673 1773
 
1674 1774
 	// Make sure all newly created tables will have the proper characters set.
1675
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1676
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1775
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1776
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1777
+	}
1677 1778
 
1678 1779
 	// Count the total number of steps within this file - for progress.
1679 1780
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1693,15 +1794,18 @@  discard block
 block discarded – undo
1693 1794
 		$do_current = $substep >= $_GET['substep'];
1694 1795
 
1695 1796
 		// Get rid of any comments in the beginning of the line...
1696
-		if (substr(trim($line), 0, 2) === '/*')
1697
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1797
+		if (substr(trim($line), 0, 2) === '/*') {
1798
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1799
+		}
1698 1800
 
1699 1801
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1700
-		if ($is_debug && !$support_js && $command_line)
1701
-			flush();
1802
+		if ($is_debug && !$support_js && $command_line) {
1803
+					flush();
1804
+		}
1702 1805
 
1703
-		if (trim($line) === '')
1704
-			continue;
1806
+		if (trim($line) === '') {
1807
+					continue;
1808
+		}
1705 1809
 
1706 1810
 		if (trim(substr($line, 0, 3)) === '---')
1707 1811
 		{
@@ -1711,8 +1815,9 @@  discard block
 block discarded – undo
1711 1815
 			if (trim($current_data) != '' && $type !== '}')
1712 1816
 			{
1713 1817
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1714
-				if ($command_line)
1715
-					echo $upcontext['error_message'];
1818
+				if ($command_line) {
1819
+									echo $upcontext['error_message'];
1820
+				}
1716 1821
 			}
1717 1822
 
1718 1823
 			if ($type == ' ')
@@ -1730,17 +1835,18 @@  discard block
 block discarded – undo
1730 1835
 				if ($do_current)
1731 1836
 				{
1732 1837
 					$upcontext['actioned_items'][] = $last_step;
1733
-					if ($command_line)
1734
-						echo ' * ';
1838
+					if ($command_line) {
1839
+											echo ' * ';
1840
+					}
1735 1841
 				}
1736
-			}
1737
-			elseif ($type == '#')
1842
+			} elseif ($type == '#')
1738 1843
 			{
1739 1844
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1740 1845
 
1741 1846
 				$upcontext['current_debug_item_num']++;
1742
-				if (trim($line) != '---#')
1743
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1847
+				if (trim($line) != '---#') {
1848
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1849
+				}
1744 1850
 
1745 1851
 				// Have we already done something?
1746 1852
 				if (isset($_GET['xml']) && $done_something)
@@ -1751,34 +1857,36 @@  discard block
 block discarded – undo
1751 1857
 
1752 1858
 				if ($do_current)
1753 1859
 				{
1754
-					if (trim($line) == '---#' && $command_line)
1755
-						echo ' done.', $endl;
1756
-					elseif ($command_line)
1757
-						echo ' +++ ', rtrim(substr($line, 4));
1758
-					elseif (trim($line) != '---#')
1860
+					if (trim($line) == '---#' && $command_line) {
1861
+											echo ' done.', $endl;
1862
+					} elseif ($command_line) {
1863
+											echo ' +++ ', rtrim(substr($line, 4));
1864
+					} elseif (trim($line) != '---#')
1759 1865
 					{
1760
-						if ($is_debug)
1761
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1866
+						if ($is_debug) {
1867
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1868
+						}
1762 1869
 					}
1763 1870
 				}
1764 1871
 
1765 1872
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1766 1873
 				{
1767
-					if ($command_line)
1768
-						echo ' * ';
1769
-					else
1770
-						$upcontext['actioned_items'][] = $last_step;
1874
+					if ($command_line) {
1875
+											echo ' * ';
1876
+					} else {
1877
+											$upcontext['actioned_items'][] = $last_step;
1878
+					}
1771 1879
 				}
1772 1880
 
1773 1881
 				// Small step - only if we're actually doing stuff.
1774
-				if ($do_current)
1775
-					nextSubstep(++$substep);
1776
-				else
1777
-					$substep++;
1778
-			}
1779
-			elseif ($type == '{')
1780
-				$current_type = 'code';
1781
-			elseif ($type == '}')
1882
+				if ($do_current) {
1883
+									nextSubstep(++$substep);
1884
+				} else {
1885
+									$substep++;
1886
+				}
1887
+			} elseif ($type == '{') {
1888
+							$current_type = 'code';
1889
+			} elseif ($type == '}')
1782 1890
 			{
1783 1891
 				$current_type = 'sql';
1784 1892
 
@@ -1791,8 +1899,9 @@  discard block
 block discarded – undo
1791 1899
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1792 1900
 				{
1793 1901
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1794
-					if ($command_line)
1795
-						echo $upcontext['error_message'];
1902
+					if ($command_line) {
1903
+											echo $upcontext['error_message'];
1904
+					}
1796 1905
 				}
1797 1906
 
1798 1907
 				// Done with code!
@@ -1872,8 +1981,9 @@  discard block
 block discarded – undo
1872 1981
 	$db_unbuffered = false;
1873 1982
 
1874 1983
 	// Failure?!
1875
-	if ($result !== false)
1876
-		return $result;
1984
+	if ($result !== false) {
1985
+			return $result;
1986
+	}
1877 1987
 
1878 1988
 	$db_error_message = $smcFunc['db_error']($db_connection);
1879 1989
 	// If MySQL we do something more clever.
@@ -1901,54 +2011,61 @@  discard block
 block discarded – undo
1901 2011
 			{
1902 2012
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1903 2013
 				$result = mysqli_query($db_connection, $string);
1904
-				if ($result !== false)
1905
-					return $result;
2014
+				if ($result !== false) {
2015
+									return $result;
2016
+				}
1906 2017
 			}
1907
-		}
1908
-		elseif ($mysqli_errno == 2013)
2018
+		} elseif ($mysqli_errno == 2013)
1909 2019
 		{
1910 2020
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1911 2021
 			mysqli_select_db($db_connection, $db_name);
1912 2022
 			if ($db_connection)
1913 2023
 			{
1914 2024
 				$result = mysqli_query($db_connection, $string);
1915
-				if ($result !== false)
1916
-					return $result;
2025
+				if ($result !== false) {
2026
+									return $result;
2027
+				}
1917 2028
 			}
1918 2029
 		}
1919 2030
 		// Duplicate column name... should be okay ;).
1920
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1921
-			return false;
2031
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2032
+					return false;
2033
+		}
1922 2034
 		// Duplicate insert... make sure it's the proper type of query ;).
1923
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1924
-			return false;
2035
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2036
+					return false;
2037
+		}
1925 2038
 		// Creating an index on a non-existent column.
1926
-		elseif ($mysqli_errno == 1072)
1927
-			return false;
1928
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1929
-			return false;
2039
+		elseif ($mysqli_errno == 1072) {
2040
+					return false;
2041
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2042
+					return false;
2043
+		}
1930 2044
 	}
1931 2045
 	// If a table already exists don't go potty.
1932 2046
 	else
1933 2047
 	{
1934 2048
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1935 2049
 		{
1936
-			if (strpos($db_error_message, 'exist') !== false)
1937
-				return true;
1938
-		}
1939
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2050
+			if (strpos($db_error_message, 'exist') !== false) {
2051
+							return true;
2052
+			}
2053
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1940 2054
 		{
1941
-			if (strpos($db_error_message, 'duplicate') !== false)
1942
-				return true;
2055
+			if (strpos($db_error_message, 'duplicate') !== false) {
2056
+							return true;
2057
+			}
1943 2058
 		}
1944 2059
 	}
1945 2060
 
1946 2061
 	// Get the query string so we pass everything.
1947 2062
 	$query_string = '';
1948
-	foreach ($_GET as $k => $v)
1949
-		$query_string .= ';' . $k . '=' . $v;
1950
-	if (strlen($query_string) != 0)
1951
-		$query_string = '?' . substr($query_string, 1);
2063
+	foreach ($_GET as $k => $v) {
2064
+			$query_string .= ';' . $k . '=' . $v;
2065
+	}
2066
+	if (strlen($query_string) != 0) {
2067
+			$query_string = '?' . substr($query_string, 1);
2068
+	}
1952 2069
 
1953 2070
 	if ($command_line)
1954 2071
 	{
@@ -2003,16 +2120,18 @@  discard block
 block discarded – undo
2003 2120
 			{
2004 2121
 				$found |= 1;
2005 2122
 				// Do some checks on the data if we have it set.
2006
-				if (isset($change['col_type']))
2007
-					$found &= $change['col_type'] === $column['type'];
2008
-				if (isset($change['null_allowed']))
2009
-					$found &= $column['null'] == $change['null_allowed'];
2010
-				if (isset($change['default']))
2011
-					$found &= $change['default'] === $column['default'];
2123
+				if (isset($change['col_type'])) {
2124
+									$found &= $change['col_type'] === $column['type'];
2125
+				}
2126
+				if (isset($change['null_allowed'])) {
2127
+									$found &= $column['null'] == $change['null_allowed'];
2128
+				}
2129
+				if (isset($change['default'])) {
2130
+									$found &= $change['default'] === $column['default'];
2131
+				}
2012 2132
 			}
2013 2133
 		}
2014
-	}
2015
-	elseif ($change['type'] === 'index')
2134
+	} elseif ($change['type'] === 'index')
2016 2135
 	{
2017 2136
 		$request = upgrade_query('
2018 2137
 			SHOW INDEX
@@ -2021,9 +2140,10 @@  discard block
 block discarded – undo
2021 2140
 		{
2022 2141
 			$cur_index = array();
2023 2142
 
2024
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2025
-				if ($row['Key_name'] === $change['name'])
2143
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2144
+							if ($row['Key_name'] === $change['name'])
2026 2145
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2146
+			}
2027 2147
 
2028 2148
 			ksort($cur_index, SORT_NUMERIC);
2029 2149
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2033,14 +2153,17 @@  discard block
 block discarded – undo
2033 2153
 	}
2034 2154
 
2035 2155
 	// If we're trying to add and it's added, we're done.
2036
-	if ($found && in_array($change['method'], array('add', 'change')))
2037
-		return true;
2156
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2157
+			return true;
2158
+	}
2038 2159
 	// Otherwise if we're removing and it wasn't found we're also done.
2039
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2040
-		return true;
2160
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2161
+			return true;
2162
+	}
2041 2163
 	// Otherwise is it just a test?
2042
-	elseif ($is_test)
2043
-		return false;
2164
+	elseif ($is_test) {
2165
+			return false;
2166
+	}
2044 2167
 
2045 2168
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2046 2169
 	$running = false;
@@ -2051,8 +2174,9 @@  discard block
 block discarded – undo
2051 2174
 			SHOW FULL PROCESSLIST');
2052 2175
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2053 2176
 		{
2054
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2055
-				$found = true;
2177
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2178
+							$found = true;
2179
+			}
2056 2180
 		}
2057 2181
 
2058 2182
 		// Can't find it? Then we need to run it fools!
@@ -2064,8 +2188,9 @@  discard block
 block discarded – undo
2064 2188
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2065 2189
 				' . $change['text'], true) !== false;
2066 2190
 
2067
-			if (!$success)
2068
-				return false;
2191
+			if (!$success) {
2192
+							return false;
2193
+			}
2069 2194
 
2070 2195
 			// Return
2071 2196
 			$running = true;
@@ -2107,8 +2232,9 @@  discard block
 block discarded – undo
2107 2232
 			'db_error_skip' => true,
2108 2233
 		)
2109 2234
 	);
2110
-	if ($smcFunc['db_num_rows']($request) === 0)
2111
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2235
+	if ($smcFunc['db_num_rows']($request) === 0) {
2236
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2237
+	}
2112 2238
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2113 2239
 	$smcFunc['db_free_result']($request);
2114 2240
 
@@ -2130,18 +2256,19 @@  discard block
 block discarded – undo
2130 2256
 			)
2131 2257
 		);
2132 2258
 		// No results? Just forget it all together.
2133
-		if ($smcFunc['db_num_rows']($request) === 0)
2134
-			unset($table_row['Collation']);
2135
-		else
2136
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2259
+		if ($smcFunc['db_num_rows']($request) === 0) {
2260
+					unset($table_row['Collation']);
2261
+		} else {
2262
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2263
+		}
2137 2264
 		$smcFunc['db_free_result']($request);
2138 2265
 	}
2139 2266
 
2140 2267
 	if ($column_fix)
2141 2268
 	{
2142 2269
 		// Make sure there are no NULL's left.
2143
-		if ($null_fix)
2144
-			$smcFunc['db_query']('', '
2270
+		if ($null_fix) {
2271
+					$smcFunc['db_query']('', '
2145 2272
 				UPDATE {db_prefix}' . $change['table'] . '
2146 2273
 				SET ' . $change['column'] . ' = {string:default}
2147 2274
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2150,6 +2277,7 @@  discard block
 block discarded – undo
2150 2277
 					'db_error_skip' => true,
2151 2278
 				)
2152 2279
 			);
2280
+		}
2153 2281
 
2154 2282
 		// Do the actual alteration.
2155 2283
 		$smcFunc['db_query']('', '
@@ -2178,8 +2306,9 @@  discard block
 block discarded – undo
2178 2306
 	}
2179 2307
 
2180 2308
 	// Not a column we need to check on?
2181
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2182
-		return;
2309
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2310
+			return;
2311
+	}
2183 2312
 
2184 2313
 	// Break it up you (six|seven).
2185 2314
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2198,13 +2327,13 @@  discard block
 block discarded – undo
2198 2327
 				'new_name' => $temp[2],
2199 2328
 		));
2200 2329
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2201
-		if ($smcFunc['db_num_rows'] != 1)
2202
-			return;
2330
+		if ($smcFunc['db_num_rows'] != 1) {
2331
+					return;
2332
+		}
2203 2333
 
2204 2334
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2205 2335
 		$smcFunc['db_free_result']($request);
2206
-	}
2207
-	else
2336
+	} else
2208 2337
 	{
2209 2338
 		// Do this the old fashion, sure method way.
2210 2339
 		$request = $smcFunc['db_query']('', '
@@ -2215,21 +2344,24 @@  discard block
 block discarded – undo
2215 2344
 		));
2216 2345
 		// Mayday!
2217 2346
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2218
-		if ($smcFunc['db_num_rows'] == 0)
2219
-			return;
2347
+		if ($smcFunc['db_num_rows'] == 0) {
2348
+					return;
2349
+		}
2220 2350
 
2221 2351
 		// Oh where, oh where has my little field gone. Oh where can it be...
2222
-		while ($row = $smcFunc['db_query']($request))
2223
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2352
+		while ($row = $smcFunc['db_query']($request)) {
2353
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2224 2354
 			{
2225 2355
 				$current_type = $row['Type'];
2356
+		}
2226 2357
 				break;
2227 2358
 			}
2228 2359
 	}
2229 2360
 
2230 2361
 	// If this doesn't match, the column may of been altered for a reason.
2231
-	if (trim($current_type) != trim($temp[3]))
2232
-		$temp[3] = $current_type;
2362
+	if (trim($current_type) != trim($temp[3])) {
2363
+			$temp[3] = $current_type;
2364
+	}
2233 2365
 
2234 2366
 	// Piece this back together.
2235 2367
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2241,8 +2373,9 @@  discard block
 block discarded – undo
2241 2373
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2242 2374
 	global $step_progress, $is_debug, $upcontext;
2243 2375
 
2244
-	if ($_GET['substep'] < $substep)
2245
-		$_GET['substep'] = $substep;
2376
+	if ($_GET['substep'] < $substep) {
2377
+			$_GET['substep'] = $substep;
2378
+	}
2246 2379
 
2247 2380
 	if ($command_line)
2248 2381
 	{
@@ -2255,29 +2388,33 @@  discard block
 block discarded – undo
2255 2388
 	}
2256 2389
 
2257 2390
 	@set_time_limit(300);
2258
-	if (function_exists('apache_reset_timeout'))
2259
-		@apache_reset_timeout();
2391
+	if (function_exists('apache_reset_timeout')) {
2392
+			@apache_reset_timeout();
2393
+	}
2260 2394
 
2261
-	if (time() - $start_time <= $timeLimitThreshold)
2262
-		return;
2395
+	if (time() - $start_time <= $timeLimitThreshold) {
2396
+			return;
2397
+	}
2263 2398
 
2264 2399
 	// Do we have some custom step progress stuff?
2265 2400
 	if (!empty($step_progress))
2266 2401
 	{
2267 2402
 		$upcontext['substep_progress'] = 0;
2268 2403
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2269
-		if ($step_progress['current'] > $step_progress['total'])
2270
-			$upcontext['substep_progress'] = 99.9;
2271
-		else
2272
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2404
+		if ($step_progress['current'] > $step_progress['total']) {
2405
+					$upcontext['substep_progress'] = 99.9;
2406
+		} else {
2407
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2408
+		}
2273 2409
 
2274 2410
 		// Make it nicely rounded.
2275 2411
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2276 2412
 	}
2277 2413
 
2278 2414
 	// If this is XML we just exit right away!
2279
-	if (isset($_GET['xml']))
2280
-		return upgradeExit();
2415
+	if (isset($_GET['xml'])) {
2416
+			return upgradeExit();
2417
+	}
2281 2418
 
2282 2419
 	// We're going to pause after this!
2283 2420
 	$upcontext['pause'] = true;
@@ -2285,13 +2422,15 @@  discard block
 block discarded – undo
2285 2422
 	$upcontext['query_string'] = '';
2286 2423
 	foreach ($_GET as $k => $v)
2287 2424
 	{
2288
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2289
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2425
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2426
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2427
+		}
2290 2428
 	}
2291 2429
 
2292 2430
 	// Custom warning?
2293
-	if (!empty($custom_warning))
2294
-		$upcontext['custom_warning'] = $custom_warning;
2431
+	if (!empty($custom_warning)) {
2432
+			$upcontext['custom_warning'] = $custom_warning;
2433
+	}
2295 2434
 
2296 2435
 	upgradeExit();
2297 2436
 }
@@ -2306,25 +2445,26 @@  discard block
 block discarded – undo
2306 2445
 	ob_implicit_flush(true);
2307 2446
 	@set_time_limit(600);
2308 2447
 
2309
-	if (!isset($_SERVER['argv']))
2310
-		$_SERVER['argv'] = array();
2448
+	if (!isset($_SERVER['argv'])) {
2449
+			$_SERVER['argv'] = array();
2450
+	}
2311 2451
 	$_GET['maint'] = 1;
2312 2452
 
2313 2453
 	foreach ($_SERVER['argv'] as $i => $arg)
2314 2454
 	{
2315
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2316
-			$_GET['lang'] = $match[1];
2317
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2318
-			continue;
2319
-		elseif ($arg == '--no-maintenance')
2320
-			$_GET['maint'] = 0;
2321
-		elseif ($arg == '--debug')
2322
-			$is_debug = true;
2323
-		elseif ($arg == '--backup')
2324
-			$_POST['backup'] = 1;
2325
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2326
-			$_GET['conv'] = 1;
2327
-		elseif ($i != 0)
2455
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2456
+					$_GET['lang'] = $match[1];
2457
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2458
+					continue;
2459
+		} elseif ($arg == '--no-maintenance') {
2460
+					$_GET['maint'] = 0;
2461
+		} elseif ($arg == '--debug') {
2462
+					$is_debug = true;
2463
+		} elseif ($arg == '--backup') {
2464
+					$_POST['backup'] = 1;
2465
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2466
+					$_GET['conv'] = 1;
2467
+		} elseif ($i != 0)
2328 2468
 		{
2329 2469
 			echo 'SMF Command-line Upgrader
2330 2470
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2338,10 +2478,12 @@  discard block
 block discarded – undo
2338 2478
 		}
2339 2479
 	}
2340 2480
 
2341
-	if (!php_version_check())
2342
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2343
-	if (!db_version_check())
2344
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2481
+	if (!php_version_check()) {
2482
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2483
+	}
2484
+	if (!db_version_check()) {
2485
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2486
+	}
2345 2487
 
2346 2488
 	// Do some checks to make sure they have proper privileges
2347 2489
 	db_extend('packages');
@@ -2356,34 +2498,39 @@  discard block
 block discarded – undo
2356 2498
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2357 2499
 
2358 2500
 	// Sorry... we need CREATE, ALTER and DROP
2359
-	if (!$create || !$alter || !$drop)
2360
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2501
+	if (!$create || !$alter || !$drop) {
2502
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2503
+	}
2361 2504
 
2362 2505
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2363 2506
 		&& @file_exists($sourcedir . '/QueryString.php')
2364 2507
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2365
-	if (!$check && !isset($modSettings['smfVersion']))
2366
-		print_error('Error: Some files are missing or out-of-date.', true);
2508
+	if (!$check && !isset($modSettings['smfVersion'])) {
2509
+			print_error('Error: Some files are missing or out-of-date.', true);
2510
+	}
2367 2511
 
2368 2512
 	// Do a quick version spot check.
2369 2513
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2370 2514
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2371
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2372
-		print_error('Error: Some files have not yet been updated properly.');
2515
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2516
+			print_error('Error: Some files have not yet been updated properly.');
2517
+	}
2373 2518
 
2374 2519
 	// Make sure Settings.php is writable.
2375 2520
 		quickFileWritable($boarddir . '/Settings.php');
2376
-	if (!is_writable($boarddir . '/Settings.php'))
2377
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2521
+	if (!is_writable($boarddir . '/Settings.php')) {
2522
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2523
+	}
2378 2524
 
2379 2525
 	// Make sure Settings_bak.php is writable.
2380 2526
 		quickFileWritable($boarddir . '/Settings_bak.php');
2381
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2382
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2527
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2528
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2529
+	}
2383 2530
 
2384
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2385
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2386
-	elseif (isset($modSettings['agreement']))
2531
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2532
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2533
+	} elseif (isset($modSettings['agreement']))
2387 2534
 	{
2388 2535
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2389 2536
 		fwrite($fp, $modSettings['agreement']);
@@ -2393,31 +2540,36 @@  discard block
 block discarded – undo
2393 2540
 	// Make sure Themes is writable.
2394 2541
 	quickFileWritable($modSettings['theme_dir']);
2395 2542
 
2396
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2397
-		print_error('Error: Unable to obtain write access to "Themes".');
2543
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2544
+			print_error('Error: Unable to obtain write access to "Themes".');
2545
+	}
2398 2546
 
2399 2547
 	// Make sure cache directory exists and is writable!
2400 2548
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2401
-	if (!file_exists($cachedir_temp))
2402
-		@mkdir($cachedir_temp);
2549
+	if (!file_exists($cachedir_temp)) {
2550
+			@mkdir($cachedir_temp);
2551
+	}
2403 2552
 
2404 2553
 	// Make sure the cache temp dir is writable.
2405 2554
 	quickFileWritable($cachedir_temp);
2406 2555
 
2407
-	if (!is_writable($cachedir_temp))
2408
-		print_error('Error: Unable to obtain write access to "cache".', true);
2556
+	if (!is_writable($cachedir_temp)) {
2557
+			print_error('Error: Unable to obtain write access to "cache".', true);
2558
+	}
2409 2559
 
2410
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2411
-		print_error('Error: Unable to find language files!', true);
2412
-	else
2560
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2561
+			print_error('Error: Unable to find language files!', true);
2562
+	} else
2413 2563
 	{
2414 2564
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2415 2565
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2416 2566
 
2417
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2418
-			print_error('Error: Language files out of date.', true);
2419
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2420
-			print_error('Error: Install language is missing for selected language.', true);
2567
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2568
+					print_error('Error: Language files out of date.', true);
2569
+		}
2570
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2571
+					print_error('Error: Install language is missing for selected language.', true);
2572
+		}
2421 2573
 
2422 2574
 		// Otherwise include it!
2423 2575
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2446,8 +2598,7 @@  discard block
 block discarded – undo
2446 2598
 		);
2447 2599
 
2448 2600
 		return true;
2449
-	}
2450
-	else
2601
+	} else
2451 2602
 	{
2452 2603
 		$upcontext['page_title'] = 'Converting to UTF8';
2453 2604
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2491,8 +2642,9 @@  discard block
 block discarded – undo
2491 2642
 			)
2492 2643
 		);
2493 2644
 		$db_charsets = array();
2494
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2495
-			$db_charsets[] = $row['Charset'];
2645
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2646
+					$db_charsets[] = $row['Charset'];
2647
+		}
2496 2648
 
2497 2649
 		$smcFunc['db_free_result']($request);
2498 2650
 
@@ -2528,13 +2680,15 @@  discard block
 block discarded – undo
2528 2680
 		// If there's a fulltext index, we need to drop it first...
2529 2681
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2530 2682
 		{
2531
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2532
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2683
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2684
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2533 2685
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2686
+			}
2534 2687
 			$smcFunc['db_free_result']($request);
2535 2688
 
2536
-			if (isset($upcontext['fulltext_index']))
2537
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2689
+			if (isset($upcontext['fulltext_index'])) {
2690
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2691
+			}
2538 2692
 		}
2539 2693
 
2540 2694
 		// Drop it and make a note...
@@ -2724,8 +2878,9 @@  discard block
 block discarded – undo
2724 2878
 			$replace = '%field%';
2725 2879
 
2726 2880
 			// Build a huge REPLACE statement...
2727
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2728
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2881
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2882
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2883
+			}
2729 2884
 		}
2730 2885
 
2731 2886
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2759,8 +2914,9 @@  discard block
 block discarded – undo
2759 2914
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2760 2915
 
2761 2916
 			// Just to make sure it doesn't time out.
2762
-			if (function_exists('apache_reset_timeout'))
2763
-				@apache_reset_timeout();
2917
+			if (function_exists('apache_reset_timeout')) {
2918
+							@apache_reset_timeout();
2919
+			}
2764 2920
 
2765 2921
 			$table_charsets = array();
2766 2922
 
@@ -2781,8 +2937,9 @@  discard block
 block discarded – undo
2781 2937
 					{
2782 2938
 						list($charset) = explode('_', $collation);
2783 2939
 
2784
-						if (!isset($table_charsets[$charset]))
2785
-							$table_charsets[$charset] = array();
2940
+						if (!isset($table_charsets[$charset])) {
2941
+													$table_charsets[$charset] = array();
2942
+						}
2786 2943
 
2787 2944
 						$table_charsets[$charset][] = $column_info;
2788 2945
 					}
@@ -2822,10 +2979,11 @@  discard block
 block discarded – undo
2822 2979
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2823 2980
 				{
2824 2981
 					$update = '';
2825
-					foreach ($table_charsets as $charset => $columns)
2826
-						foreach ($columns as $column)
2982
+					foreach ($table_charsets as $charset => $columns) {
2983
+											foreach ($columns as $column)
2827 2984
 							$update .= '
2828 2985
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2986
+					}
2829 2987
 
2830 2988
 					$smcFunc['db_query']('', '
2831 2989
 						UPDATE {raw:table_name}
@@ -2850,8 +3008,9 @@  discard block
 block discarded – undo
2850 3008
 			// Now do the actual conversion (if still needed).
2851 3009
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2852 3010
 			{
2853
-				if ($command_line)
2854
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3011
+				if ($command_line) {
3012
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3013
+				}
2855 3014
 
2856 3015
 				$smcFunc['db_query']('', '
2857 3016
 					ALTER TABLE {raw:table_name}
@@ -2861,8 +3020,9 @@  discard block
 block discarded – undo
2861 3020
 					)
2862 3021
 				);
2863 3022
 
2864
-				if ($command_line)
2865
-					echo " done.\n";
3023
+				if ($command_line) {
3024
+									echo " done.\n";
3025
+				}
2866 3026
 			}
2867 3027
 		}
2868 3028
 
@@ -2892,8 +3052,8 @@  discard block
 block discarded – undo
2892 3052
 		);
2893 3053
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2894 3054
 		{
2895
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
2896
-				$smcFunc['db_query']('', '
3055
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3056
+							$smcFunc['db_query']('', '
2897 3057
 					UPDATE {db_prefix}log_actions
2898 3058
 					SET extra = {string:extra}
2899 3059
 					WHERE id_action = {int:current_action}',
@@ -2902,6 +3062,7 @@  discard block
 block discarded – undo
2902 3062
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2903 3063
 					)
2904 3064
 				);
3065
+			}
2905 3066
 		}
2906 3067
 		$smcFunc['db_free_result']($request);
2907 3068
 
@@ -2923,15 +3084,17 @@  discard block
 block discarded – undo
2923 3084
 	// First thing's first - did we already do this?
2924 3085
 	if (!empty($modSettings['json_done']))
2925 3086
 	{
2926
-		if ($command_line)
2927
-			return DeleteUpgrade();
2928
-		else
2929
-			return true;
3087
+		if ($command_line) {
3088
+					return DeleteUpgrade();
3089
+		} else {
3090
+					return true;
3091
+		}
2930 3092
 	}
2931 3093
 
2932 3094
 	// Done it already - js wise?
2933
-	if (!empty($_POST['json_done']))
2934
-		return true;
3095
+	if (!empty($_POST['json_done'])) {
3096
+			return true;
3097
+	}
2935 3098
 
2936 3099
 	// List of tables affected by this function
2937 3100
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2962,12 +3125,14 @@  discard block
 block discarded – undo
2962 3125
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2963 3126
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2964 3127
 
2965
-	foreach ($keys as $id => $table)
2966
-		if ($id < $_GET['substep'])
3128
+	foreach ($keys as $id => $table) {
3129
+			if ($id < $_GET['substep'])
2967 3130
 			$upcontext['previous_tables'][] = $table;
3131
+	}
2968 3132
 
2969
-	if ($command_line)
2970
-		echo 'Converting data from serialize() to json_encode().';
3133
+	if ($command_line) {
3134
+			echo 'Converting data from serialize() to json_encode().';
3135
+	}
2971 3136
 
2972 3137
 	if (!$support_js || isset($_GET['xml']))
2973 3138
 	{
@@ -3007,8 +3172,9 @@  discard block
 block discarded – undo
3007 3172
 
3008 3173
 				// Loop through and fix these...
3009 3174
 				$new_settings = array();
3010
-				if ($command_line)
3011
-					echo "\n" . 'Fixing some settings...';
3175
+				if ($command_line) {
3176
+									echo "\n" . 'Fixing some settings...';
3177
+				}
3012 3178
 
3013 3179
 				foreach ($serialized_settings as $var)
3014 3180
 				{
@@ -3016,22 +3182,24 @@  discard block
 block discarded – undo
3016 3182
 					{
3017 3183
 						// Attempt to unserialize the setting
3018 3184
 						$temp = @safe_unserialize($modSettings[$var]);
3019
-						if (!$temp && $command_line)
3020
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3021
-						elseif ($temp !== false)
3022
-							$new_settings[$var] = json_encode($temp);
3185
+						if (!$temp && $command_line) {
3186
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3187
+						} elseif ($temp !== false) {
3188
+													$new_settings[$var] = json_encode($temp);
3189
+						}
3023 3190
 					}
3024 3191
 				}
3025 3192
 
3026 3193
 				// Update everything at once
3027
-				if (!function_exists('cache_put_data'))
3028
-					require_once($sourcedir . '/Load.php');
3194
+				if (!function_exists('cache_put_data')) {
3195
+									require_once($sourcedir . '/Load.php');
3196
+				}
3029 3197
 				updateSettings($new_settings, true);
3030 3198
 
3031
-				if ($command_line)
3032
-					echo ' done.';
3033
-			}
3034
-			elseif ($table == 'themes')
3199
+				if ($command_line) {
3200
+									echo ' done.';
3201
+				}
3202
+			} elseif ($table == 'themes')
3035 3203
 			{
3036 3204
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3037 3205
 				$query = $smcFunc['db_query']('', '
@@ -3050,10 +3218,11 @@  discard block
 block discarded – undo
3050 3218
 
3051 3219
 						if ($command_line)
3052 3220
 						{
3053
-							if ($temp === false)
3054
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3055
-							else
3056
-								echo "\n" . 'Fixing admin preferences...';
3221
+							if ($temp === false) {
3222
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3223
+							} else {
3224
+															echo "\n" . 'Fixing admin preferences...';
3225
+							}
3057 3226
 						}
3058 3227
 
3059 3228
 						if ($temp !== false)
@@ -3075,15 +3244,15 @@  discard block
 block discarded – undo
3075 3244
 								)
3076 3245
 							);
3077 3246
 
3078
-							if ($command_line)
3079
-								echo ' done.';
3247
+							if ($command_line) {
3248
+															echo ' done.';
3249
+							}
3080 3250
 						}
3081 3251
 					}
3082 3252
 
3083 3253
 					$smcFunc['db_free_result']($query);
3084 3254
 				}
3085
-			}
3086
-			else
3255
+			} else
3087 3256
 			{
3088 3257
 				// First item is always the key...
3089 3258
 				$key = $info[0];
@@ -3094,8 +3263,7 @@  discard block
 block discarded – undo
3094 3263
 				{
3095 3264
 					$col_select = $info[1];
3096 3265
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3097
-				}
3098
-				else
3266
+				} else
3099 3267
 				{
3100 3268
 					$col_select = implode(', ', $info);
3101 3269
 				}
@@ -3128,8 +3296,7 @@  discard block
 block discarded – undo
3128 3296
 								if ($temp === false && $command_line)
3129 3297
 								{
3130 3298
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3131
-								}
3132
-								else
3299
+								} else
3133 3300
 								{
3134 3301
 									$row[$col] = json_encode($temp);
3135 3302
 
@@ -3154,16 +3321,18 @@  discard block
 block discarded – undo
3154 3321
 						}
3155 3322
 					}
3156 3323
 
3157
-					if ($command_line)
3158
-						echo ' done.';
3324
+					if ($command_line) {
3325
+											echo ' done.';
3326
+					}
3159 3327
 
3160 3328
 					// Free up some memory...
3161 3329
 					$smcFunc['db_free_result']($query);
3162 3330
 				}
3163 3331
 			}
3164 3332
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3165
-			if (isset($_GET['xml']))
3166
-				return upgradeExit();
3333
+			if (isset($_GET['xml'])) {
3334
+							return upgradeExit();
3335
+			}
3167 3336
 		}
3168 3337
 
3169 3338
 		if ($command_line)
@@ -3178,8 +3347,9 @@  discard block
 block discarded – undo
3178 3347
 
3179 3348
 		$_GET['substep'] = 0;
3180 3349
 		// Make sure we move on!
3181
-		if ($command_line)
3182
-			return DeleteUpgrade();
3350
+		if ($command_line) {
3351
+					return DeleteUpgrade();
3352
+		}
3183 3353
 
3184 3354
 		return true;
3185 3355
 	}
@@ -3199,14 +3369,16 @@  discard block
 block discarded – undo
3199 3369
 	global $upcontext, $txt, $settings;
3200 3370
 
3201 3371
 	// Don't call me twice!
3202
-	if (!empty($upcontext['chmod_called']))
3203
-		return;
3372
+	if (!empty($upcontext['chmod_called'])) {
3373
+			return;
3374
+	}
3204 3375
 
3205 3376
 	$upcontext['chmod_called'] = true;
3206 3377
 
3207 3378
 	// Nothing?
3208
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3209
-		return;
3379
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3380
+			return;
3381
+	}
3210 3382
 
3211 3383
 	// Was it a problem with Windows?
3212 3384
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3238,11 +3410,12 @@  discard block
 block discarded – undo
3238 3410
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
3239 3411
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3240 3412
 
3241
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3242
-		echo '
3413
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3414
+			echo '
3243 3415
 					content.write(\'<hr>\n\t\t\t\');
3244 3416
 					content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\');
3245 3417
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3418
+	}
3246 3419
 
3247 3420
 	echo '
3248 3421
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3250,17 +3423,19 @@  discard block
 block discarded – undo
3250 3423
 				}
3251 3424
 		</script>';
3252 3425
 
3253
-	if (!empty($upcontext['chmod']['ftp_error']))
3254
-		echo '
3426
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3427
+			echo '
3255 3428
 			<div class="error_message red">
3256 3429
 				The following error was encountered when trying to connect:<br><br>
3257 3430
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3258 3431
 			</div>
3259 3432
 			<br>';
3433
+	}
3260 3434
 
3261
-	if (empty($upcontext['chmod_in_form']))
3262
-		echo '
3435
+	if (empty($upcontext['chmod_in_form'])) {
3436
+			echo '
3263 3437
 	<form action="', $upcontext['form_url'], '" method="post">';
3438
+	}
3264 3439
 
3265 3440
 	echo '
3266 3441
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3295,10 +3470,11 @@  discard block
 block discarded – undo
3295 3470
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3296 3471
 	</div>';
3297 3472
 
3298
-	if (empty($upcontext['chmod_in_form']))
3299
-		echo '
3473
+	if (empty($upcontext['chmod_in_form'])) {
3474
+			echo '
3300 3475
 	</form>';
3301
-}
3476
+	}
3477
+	}
3302 3478
 
3303 3479
 function template_upgrade_above()
3304 3480
 {
@@ -3358,9 +3534,10 @@  discard block
 block discarded – undo
3358 3534
 				<h2>', $txt['upgrade_progress'], '</h2>
3359 3535
 				<ul>';
3360 3536
 
3361
-	foreach ($upcontext['steps'] as $num => $step)
3362
-		echo '
3537
+	foreach ($upcontext['steps'] as $num => $step) {
3538
+			echo '
3363 3539
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3540
+	}
3364 3541
 
3365 3542
 	echo '
3366 3543
 					</ul>
@@ -3373,8 +3550,8 @@  discard block
 block discarded – undo
3373 3550
 				</div>
3374 3551
 			</div>';
3375 3552
 
3376
-	if (isset($upcontext['step_progress']))
3377
-		echo '
3553
+	if (isset($upcontext['step_progress'])) {
3554
+			echo '
3378 3555
 				<br>
3379 3556
 				<br>
3380 3557
 				<div id="progress_bar_step">
@@ -3383,6 +3560,7 @@  discard block
 block discarded – undo
3383 3560
 						<span>', $txt['upgrade_step_progress'], '</span>
3384 3561
 					</div>
3385 3562
 				</div>';
3563
+	}
3386 3564
 
3387 3565
 	echo '
3388 3566
 				<div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
@@ -3413,32 +3591,36 @@  discard block
 block discarded – undo
3413 3591
 {
3414 3592
 	global $upcontext, $txt;
3415 3593
 
3416
-	if (!empty($upcontext['pause']))
3417
-		echo '
3594
+	if (!empty($upcontext['pause'])) {
3595
+			echo '
3418 3596
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3419 3597
 
3420 3598
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3421 3599
 								<h3>
3422 3600
 									', $txt['upgrade_paused_overload'], '
3423 3601
 								</h3>';
3602
+	}
3424 3603
 
3425
-	if (!empty($upcontext['custom_warning']))
3426
-		echo '
3604
+	if (!empty($upcontext['custom_warning'])) {
3605
+			echo '
3427 3606
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3428 3607
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3429 3608
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3430 3609
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3431 3610
 								</div>';
3611
+	}
3432 3612
 
3433 3613
 	echo '
3434 3614
 								<div class="righttext" style="margin: 1ex;">';
3435 3615
 
3436
-	if (!empty($upcontext['continue']))
3437
-		echo '
3616
+	if (!empty($upcontext['continue'])) {
3617
+			echo '
3438 3618
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3439
-	if (!empty($upcontext['skip']))
3440
-		echo '
3619
+	}
3620
+	if (!empty($upcontext['skip'])) {
3621
+			echo '
3441 3622
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3623
+	}
3442 3624
 
3443 3625
 	echo '
3444 3626
 								</div>
@@ -3488,11 +3670,12 @@  discard block
 block discarded – undo
3488 3670
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3489 3671
 	<smf>';
3490 3672
 
3491
-	if (!empty($upcontext['get_data']))
3492
-		foreach ($upcontext['get_data'] as $k => $v)
3673
+	if (!empty($upcontext['get_data'])) {
3674
+			foreach ($upcontext['get_data'] as $k => $v)
3493 3675
 			echo '
3494 3676
 		<get key="', $k, '">', $v, '</get>';
3495
-}
3677
+	}
3678
+	}
3496 3679
 
3497 3680
 function template_xml_below()
3498 3681
 {
@@ -3533,8 +3716,8 @@  discard block
 block discarded – undo
3533 3716
 	template_chmod();
3534 3717
 
3535 3718
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3536
-	if ($upcontext['is_large_forum'])
3537
-		echo '
3719
+	if ($upcontext['is_large_forum']) {
3720
+			echo '
3538 3721
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3539 3722
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3540 3723
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3542,10 +3725,11 @@  discard block
 block discarded – undo
3542 3725
 				', $txt['upgrade_warning_lots_data'], '
3543 3726
 			</div>
3544 3727
 		</div>';
3728
+	}
3545 3729
 
3546 3730
 	// A warning message?
3547
-	if (!empty($upcontext['warning']))
3548
-		echo '
3731
+	if (!empty($upcontext['warning'])) {
3732
+			echo '
3549 3733
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3550 3734
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3551 3735
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3553,6 +3737,7 @@  discard block
 block discarded – undo
3553 3737
 				', $upcontext['warning'], '
3554 3738
 			</div>
3555 3739
 		</div>';
3740
+	}
3556 3741
 
3557 3742
 	// Paths are incorrect?
3558 3743
 	echo '
@@ -3568,20 +3753,22 @@  discard block
 block discarded – undo
3568 3753
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3569 3754
 	{
3570 3755
 		$ago = time() - $upcontext['started'];
3571
-		if ($ago < 60)
3572
-			$ago = $ago . ' seconds';
3573
-		elseif ($ago < 3600)
3574
-			$ago = (int) ($ago / 60) . ' minutes';
3575
-		else
3576
-			$ago = (int) ($ago / 3600) . ' hours';
3756
+		if ($ago < 60) {
3757
+					$ago = $ago . ' seconds';
3758
+		} elseif ($ago < 3600) {
3759
+					$ago = (int) ($ago / 60) . ' minutes';
3760
+		} else {
3761
+					$ago = (int) ($ago / 3600) . ' hours';
3762
+		}
3577 3763
 
3578 3764
 		$active = time() - $upcontext['updated'];
3579
-		if ($active < 60)
3580
-			$updated = $active . ' seconds';
3581
-		elseif ($active < 3600)
3582
-			$updated = (int) ($active / 60) . ' minutes';
3583
-		else
3584
-			$updated = (int) ($active / 3600) . ' hours';
3765
+		if ($active < 60) {
3766
+					$updated = $active . ' seconds';
3767
+		} elseif ($active < 3600) {
3768
+					$updated = (int) ($active / 60) . ' minutes';
3769
+		} else {
3770
+					$updated = (int) ($active / 3600) . ' hours';
3771
+		}
3585 3772
 
3586 3773
 		echo '
3587 3774
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3590,16 +3777,18 @@  discard block
 block discarded – undo
3590 3777
 			<div style="padding-left: 6ex;">
3591 3778
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3592 3779
 
3593
-		if ($active < 600)
3594
-			echo '
3780
+		if ($active < 600) {
3781
+					echo '
3595 3782
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3783
+		}
3596 3784
 
3597
-		if ($active > $upcontext['inactive_timeout'])
3598
-			echo '
3785
+		if ($active > $upcontext['inactive_timeout']) {
3786
+					echo '
3599 3787
 				<br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
3600
-		else
3601
-			echo '
3788
+		} else {
3789
+					echo '
3602 3790
 				<br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3791
+		}
3603 3792
 
3604 3793
 		echo '
3605 3794
 			</div>
@@ -3615,9 +3804,10 @@  discard block
 block discarded – undo
3615 3804
 					<td>
3616 3805
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3617 3806
 
3618
-	if (!empty($upcontext['username_incorrect']))
3619
-		echo '
3807
+	if (!empty($upcontext['username_incorrect'])) {
3808
+			echo '
3620 3809
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3810
+	}
3621 3811
 
3622 3812
 	echo '
3623 3813
 					</td>
@@ -3628,9 +3818,10 @@  discard block
 block discarded – undo
3628 3818
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3629 3819
 						<input type="hidden" name="hash_passwrd" value="">';
3630 3820
 
3631
-	if (!empty($upcontext['password_failed']))
3632
-		echo '
3821
+	if (!empty($upcontext['password_failed'])) {
3822
+			echo '
3633 3823
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3824
+	}
3634 3825
 
3635 3826
 	echo '
3636 3827
 					</td>
@@ -3701,8 +3892,8 @@  discard block
 block discarded – undo
3701 3892
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3702 3893
 
3703 3894
 	// Warning message?
3704
-	if (!empty($upcontext['upgrade_options_warning']))
3705
-		echo '
3895
+	if (!empty($upcontext['upgrade_options_warning'])) {
3896
+			echo '
3706 3897
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3707 3898
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3708 3899
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3710,6 +3901,7 @@  discard block
 block discarded – undo
3710 3901
 				', $upcontext['upgrade_options_warning'], '
3711 3902
 			</div>
3712 3903
 		</div>';
3904
+	}
3713 3905
 
3714 3906
 	echo '
3715 3907
 				<table>
@@ -3752,8 +3944,8 @@  discard block
 block discarded – undo
3752 3944
 						</td>
3753 3945
 					</tr>';
3754 3946
 
3755
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3756
-		echo '
3947
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3948
+			echo '
3757 3949
 					<tr valign="top">
3758 3950
 						<td width="2%">
3759 3951
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3762,6 +3954,7 @@  discard block
 block discarded – undo
3762 3954
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3763 3955
 						</td>
3764 3956
 					</tr>';
3957
+	}
3765 3958
 
3766 3959
 	echo '
3767 3960
 					<tr valign="top">
@@ -3799,10 +3992,11 @@  discard block
 block discarded – undo
3799 3992
 			</div>';
3800 3993
 
3801 3994
 	// Dont any tables so far?
3802
-	if (!empty($upcontext['previous_tables']))
3803
-		foreach ($upcontext['previous_tables'] as $table)
3995
+	if (!empty($upcontext['previous_tables'])) {
3996
+			foreach ($upcontext['previous_tables'] as $table)
3804 3997
 			echo '
3805 3998
 			<br>Completed Table: &quot;', $table, '&quot;.';
3999
+	}
3806 4000
 
3807 4001
 	echo '
3808 4002
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3839,12 +4033,13 @@  discard block
 block discarded – undo
3839 4033
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3840 4034
 
3841 4035
 		// If debug flood the screen.
3842
-		if ($is_debug)
3843
-			echo '
4036
+		if ($is_debug) {
4037
+					echo '
3844 4038
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3845 4039
 
3846 4040
 				if (document.getElementById(\'debug_section\').scrollHeight)
3847 4041
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4042
+		}
3848 4043
 
3849 4044
 		echo '
3850 4045
 				// Get the next update...
@@ -3876,8 +4071,9 @@  discard block
 block discarded – undo
3876 4071
 {
3877 4072
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3878 4073
 
3879
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3880
-		$is_debug = true;
4074
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4075
+			$is_debug = true;
4076
+	}
3881 4077
 
3882 4078
 	echo '
3883 4079
 		<h3>Executing database changes</h3>
@@ -3892,8 +4088,9 @@  discard block
 block discarded – undo
3892 4088
 	{
3893 4089
 		foreach ($upcontext['actioned_items'] as $num => $item)
3894 4090
 		{
3895
-			if ($num != 0)
3896
-				echo ' Successful!';
4091
+			if ($num != 0) {
4092
+							echo ' Successful!';
4093
+			}
3897 4094
 			echo '<br>' . $item;
3898 4095
 		}
3899 4096
 		if (!empty($upcontext['changes_complete']))
@@ -3906,28 +4103,32 @@  discard block
 block discarded – undo
3906 4103
 				$seconds = intval($active % 60);
3907 4104
 
3908 4105
 				$totalTime = '';
3909
-				if ($hours > 0)
3910
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3911
-				if ($minutes > 0)
3912
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3913
-				if ($seconds > 0)
3914
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4106
+				if ($hours > 0) {
4107
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4108
+				}
4109
+				if ($minutes > 0) {
4110
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4111
+				}
4112
+				if ($seconds > 0) {
4113
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4114
+				}
3915 4115
 			}
3916 4116
 
3917
-			if ($is_debug && !empty($totalTime))
3918
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3919
-			else
3920
-				echo ' Successful!<br><br>';
4117
+			if ($is_debug && !empty($totalTime)) {
4118
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4119
+			} else {
4120
+							echo ' Successful!<br><br>';
4121
+			}
3921 4122
 
3922 4123
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3923 4124
 		}
3924
-	}
3925
-	else
4125
+	} else
3926 4126
 	{
3927 4127
 		// Tell them how many files we have in total.
3928
-		if ($upcontext['file_count'] > 1)
3929
-			echo '
4128
+		if ($upcontext['file_count'] > 1) {
4129
+					echo '
3930 4130
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4131
+		}
3931 4132
 
3932 4133
 		echo '
3933 4134
 		<h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -3943,19 +4144,23 @@  discard block
 block discarded – undo
3943 4144
 				$seconds = intval($active % 60);
3944 4145
 
3945 4146
 				$totalTime = '';
3946
-				if ($hours > 0)
3947
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3948
-				if ($minutes > 0)
3949
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3950
-				if ($seconds > 0)
3951
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4147
+				if ($hours > 0) {
4148
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4149
+				}
4150
+				if ($minutes > 0) {
4151
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4152
+				}
4153
+				if ($seconds > 0) {
4154
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4155
+				}
3952 4156
 			}
3953 4157
 
3954 4158
 			echo '
3955 4159
 			<br><span id="upgradeCompleted">';
3956 4160
 
3957
-			if (!empty($totalTime))
3958
-				echo 'Completed in ', $totalTime, '<br>';
4161
+			if (!empty($totalTime)) {
4162
+							echo 'Completed in ', $totalTime, '<br>';
4163
+			}
3959 4164
 
3960 4165
 			echo '</span>
3961 4166
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -3992,9 +4197,10 @@  discard block
 block discarded – undo
3992 4197
 			var getData = "";
3993 4198
 			var debugItems = ', $upcontext['debug_items'], ';';
3994 4199
 
3995
-		if ($is_debug)
3996
-			echo '
4200
+		if ($is_debug) {
4201
+					echo '
3997 4202
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4203
+		}
3998 4204
 
3999 4205
 		echo '
4000 4206
 			function getNextItem()
@@ -4034,9 +4240,10 @@  discard block
 block discarded – undo
4034 4240
 						document.getElementById("error_block").style.display = "";
4035 4241
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4036 4242
 
4037
-	if ($is_debug)
4038
-		echo '
4243
+	if ($is_debug) {
4244
+			echo '
4039 4245
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4246
+	}
4040 4247
 
4041 4248
 	echo '
4042 4249
 					}
@@ -4057,9 +4264,10 @@  discard block
 block discarded – undo
4057 4264
 						document.getElementById("error_block").style.display = "";
4058 4265
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4059 4266
 
4060
-	if ($is_debug)
4061
-		echo '
4267
+	if ($is_debug) {
4268
+			echo '
4062 4269
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4270
+	}
4063 4271
 
4064 4272
 	echo '
4065 4273
 					}
@@ -4118,8 +4326,8 @@  discard block
 block discarded – undo
4118 4326
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4119 4327
 				{';
4120 4328
 
4121
-		if ($is_debug)
4122
-			echo '
4329
+		if ($is_debug) {
4330
+					echo '
4123 4331
 					document.getElementById(\'debug_section\').style.display = "none";
4124 4332
 
4125 4333
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4137,6 +4345,7 @@  discard block
 block discarded – undo
4137 4345
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4138 4346
 
4139 4347
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4348
+		}
4140 4349
 
4141 4350
 		echo '
4142 4351
 
@@ -4144,9 +4353,10 @@  discard block
 block discarded – undo
4144 4353
 					document.getElementById(\'contbutt\').disabled = 0;
4145 4354
 					document.getElementById(\'database_done\').value = 1;';
4146 4355
 
4147
-		if ($upcontext['file_count'] > 1)
4148
-			echo '
4356
+		if ($upcontext['file_count'] > 1) {
4357
+					echo '
4149 4358
 					document.getElementById(\'info1\').style.display = "none";';
4359
+		}
4150 4360
 
4151 4361
 		echo '
4152 4362
 					document.getElementById(\'info2\').style.display = "none";
@@ -4159,9 +4369,10 @@  discard block
 block discarded – undo
4159 4369
 					lastItem = 0;
4160 4370
 					prevFile = curFile;';
4161 4371
 
4162
-		if ($is_debug)
4163
-			echo '
4372
+		if ($is_debug) {
4373
+					echo '
4164 4374
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4375
+		}
4165 4376
 
4166 4377
 		echo '
4167 4378
 					getNextItem();
@@ -4169,8 +4380,8 @@  discard block
 block discarded – undo
4169 4380
 				}';
4170 4381
 
4171 4382
 		// If debug scroll the screen.
4172
-		if ($is_debug)
4173
-			echo '
4383
+		if ($is_debug) {
4384
+					echo '
4174 4385
 				if (iLastSubStepProgress == -1)
4175 4386
 				{
4176 4387
 					// Give it consistent dots.
@@ -4189,6 +4400,7 @@  discard block
 block discarded – undo
4189 4400
 
4190 4401
 				if (document.getElementById(\'debug_section\').scrollHeight)
4191 4402
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4403
+		}
4192 4404
 
4193 4405
 		echo '
4194 4406
 				// Update the page.
@@ -4249,9 +4461,10 @@  discard block
 block discarded – undo
4249 4461
 			}';
4250 4462
 
4251 4463
 		// Start things off assuming we've not errored.
4252
-		if (empty($upcontext['error_message']))
4253
-			echo '
4464
+		if (empty($upcontext['error_message'])) {
4465
+					echo '
4254 4466
 			getNextItem();';
4467
+		}
4255 4468
 
4256 4469
 		echo '
4257 4470
 		</script>';
@@ -4268,18 +4481,21 @@  discard block
 block discarded – undo
4268 4481
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4269 4482
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4270 4483
 
4271
-	if (!empty($upcontext['error_message']))
4272
-		echo '
4484
+	if (!empty($upcontext['error_message'])) {
4485
+			echo '
4273 4486
 	<error>', $upcontext['error_message'], '</error>';
4487
+	}
4274 4488
 
4275
-	if (!empty($upcontext['error_string']))
4276
-		echo '
4489
+	if (!empty($upcontext['error_string'])) {
4490
+			echo '
4277 4491
 	<sql>', $upcontext['error_string'], '</sql>';
4492
+	}
4278 4493
 
4279
-	if ($is_debug)
4280
-		echo '
4494
+	if ($is_debug) {
4495
+			echo '
4281 4496
 	<curtime>', time(), '</curtime>';
4282
-}
4497
+	}
4498
+	}
4283 4499
 
4284 4500
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4285 4501
 function template_convert_utf8()
@@ -4296,18 +4512,20 @@  discard block
 block discarded – undo
4296 4512
 			<span id="debuginfo"></span>';
4297 4513
 
4298 4514
 	// Done any tables so far?
4299
-	if (!empty($upcontext['previous_tables']))
4300
-		foreach ($upcontext['previous_tables'] as $table)
4515
+	if (!empty($upcontext['previous_tables'])) {
4516
+			foreach ($upcontext['previous_tables'] as $table)
4301 4517
 			echo '
4302 4518
 			<br>Completed Table: &quot;', $table, '&quot;.';
4519
+	}
4303 4520
 
4304 4521
 	echo '
4305 4522
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4306 4523
 
4307 4524
 	// If we dropped their index, let's let them know
4308
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4309
-		echo '
4525
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4526
+			echo '
4310 4527
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4528
+	}
4311 4529
 
4312 4530
 	echo '
4313 4531
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>';
@@ -4343,9 +4561,10 @@  discard block
 block discarded – undo
4343 4561
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4344 4562
 
4345 4563
 		// If debug flood the screen.
4346
-		if ($is_debug)
4347
-			echo '
4564
+		if ($is_debug) {
4565
+					echo '
4348 4566
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4567
+		}
4349 4568
 
4350 4569
 		echo '
4351 4570
 				// Get the next update...
@@ -4387,19 +4606,21 @@  discard block
 block discarded – undo
4387 4606
 			<span id="debuginfo"></span>';
4388 4607
 
4389 4608
 	// Dont any tables so far?
4390
-	if (!empty($upcontext['previous_tables']))
4391
-		foreach ($upcontext['previous_tables'] as $table)
4609
+	if (!empty($upcontext['previous_tables'])) {
4610
+			foreach ($upcontext['previous_tables'] as $table)
4392 4611
 			echo '
4393 4612
 			<br>Completed Table: &quot;', $table, '&quot;.';
4613
+	}
4394 4614
 
4395 4615
 	echo '
4396 4616
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4397 4617
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>';
4398 4618
 
4399 4619
 	// Try to make sure substep was reset.
4400
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4401
-		echo '
4620
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4621
+			echo '
4402 4622
 			<input type="hidden" name="substep" id="substep" value="0">';
4623
+	}
4403 4624
 
4404 4625
 	// Continue please!
4405 4626
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4432,9 +4653,10 @@  discard block
 block discarded – undo
4432 4653
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4433 4654
 
4434 4655
 		// If debug flood the screen.
4435
-		if ($is_debug)
4436
-			echo '
4656
+		if ($is_debug) {
4657
+					echo '
4437 4658
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4659
+		}
4438 4660
 
4439 4661
 		echo '
4440 4662
 				// Get the next update...
@@ -4469,8 +4691,8 @@  discard block
 block discarded – undo
4469 4691
 	<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>
4470 4692
 	<form action="', $boardurl, '/index.php">';
4471 4693
 
4472
-	if (!empty($upcontext['can_delete_script']))
4473
-		echo '
4694
+	if (!empty($upcontext['can_delete_script'])) {
4695
+			echo '
4474 4696
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4475 4697
 			<script>
4476 4698
 				function doTheDelete(theCheck)
@@ -4482,6 +4704,7 @@  discard block
 block discarded – undo
4482 4704
 				}
4483 4705
 			</script>
4484 4706
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4707
+	}
4485 4708
 
4486 4709
 	$active = time() - $upcontext['started'];
4487 4710
 	$hours = floor($active / 3600);
@@ -4491,16 +4714,20 @@  discard block
 block discarded – undo
4491 4714
 	if ($is_debug)
4492 4715
 	{
4493 4716
 		$totalTime = '';
4494
-		if ($hours > 0)
4495
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4496
-		if ($minutes > 0)
4497
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4498
-		if ($seconds > 0)
4499
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4717
+		if ($hours > 0) {
4718
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4719
+		}
4720
+		if ($minutes > 0) {
4721
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4722
+		}
4723
+		if ($seconds > 0) {
4724
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4725
+		}
4500 4726
 	}
4501 4727
 
4502
-	if ($is_debug && !empty($totalTime))
4503
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4728
+	if ($is_debug && !empty($totalTime)) {
4729
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4730
+	}
4504 4731
 
4505 4732
 	echo '<br>
4506 4733
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="http://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4567,16 +4794,19 @@  discard block
 block discarded – undo
4567 4794
 				'empty' => '',
4568 4795
 				'limit' => $limit,
4569 4796
 		));
4570
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4571
-			$arIp[] = $row[$oldCol];
4797
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4798
+					$arIp[] = $row[$oldCol];
4799
+		}
4572 4800
 		$smcFunc['db_free_result']($request);
4573 4801
 
4574 4802
 		// Special case, null ip could keep us in a loop.
4575
-		if (is_null($arIp[0]))
4576
-			unset($arIp[0]);
4803
+		if (is_null($arIp[0])) {
4804
+					unset($arIp[0]);
4805
+		}
4577 4806
 
4578
-		if (empty($arIp))
4579
-			$is_done = true;
4807
+		if (empty($arIp)) {
4808
+					$is_done = true;
4809
+		}
4580 4810
 
4581 4811
 		$updates = array();
4582 4812
 		$cases = array();
@@ -4585,16 +4815,18 @@  discard block
 block discarded – undo
4585 4815
 		{
4586 4816
 			$arIp[$i] = trim($arIp[$i]);
4587 4817
 
4588
-			if (empty($arIp[$i]))
4589
-				continue;
4818
+			if (empty($arIp[$i])) {
4819
+							continue;
4820
+			}
4590 4821
 
4591 4822
 			$updates['ip' . $i] = $arIp[$i];
4592 4823
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4593 4824
 
4594 4825
 			if ($setSize > 0 && $i % $setSize === 0)
4595 4826
 			{
4596
-				if (count($updates) == 1)
4597
-					continue;
4827
+				if (count($updates) == 1) {
4828
+									continue;
4829
+				}
4598 4830
 
4599 4831
 				$updates['whereSet'] = array_values($updates);
4600 4832
 				$smcFunc['db_query']('', '
@@ -4628,8 +4860,7 @@  discard block
 block discarded – undo
4628 4860
 							'ip' => $ip
4629 4861
 					));
4630 4862
 				}
4631
-			}
4632
-			else
4863
+			} else
4633 4864
 			{
4634 4865
 				$updates['whereSet'] = array_values($updates);
4635 4866
 				$smcFunc['db_query']('', '
@@ -4643,9 +4874,9 @@  discard block
 block discarded – undo
4643 4874
 					$updates
4644 4875
 				);
4645 4876
 			}
4877
+		} else {
4878
+					$is_done = true;
4646 4879
 		}
4647
-		else
4648
-			$is_done = true;
4649 4880
 
4650 4881
 		$_GET['a'] += $limit;
4651 4882
 		$step_progress['current'] = $_GET['a'];
@@ -4671,10 +4902,11 @@  discard block
 block discarded – undo
4671 4902
  
4672 4903
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4673 4904
 
4674
-	if (isset($columns[$column]))
4675
-		return $columns[$column];
4676
-	else
4677
-		return null;
4678
-}
4905
+	if (isset($columns[$column])) {
4906
+			return $columns[$column];
4907
+	} else {
4908
+			return null;
4909
+	}
4910
+	}
4679 4911
 
4680 4912
 ?>
4681 4913
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 2 patches
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.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
 		$connection
816 816
 	);
817 817
 	
818
-	if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
818
+	if (!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0)
819 819
 	{
820 820
 		if ($returnmode == 1)
821 821
 			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 			$return_var = array();
825 825
 			$count = count($insertRows);
826 826
 			$start = smf_db_insert_id($table, $keys[0]);
827
-			for ($i = 0; $i < $count; $i++ )
827
+			for ($i = 0; $i < $count; $i++)
828 828
 				$return_var[] = $start + $i;
829 829
 		}
830 830
 		return $return_var;
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 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -497,6 +497,7 @@
 block discarded – undo
497 497
  * @param string $xml_format The format to use ('atom', 'rss', 'rss2' or empty for plain XML)
498 498
  * @param array $forceCdataKeys A list of keys on which to force cdata wrapping (used by mods, maybe)
499 499
  * @param array $nsKeys Key-value pairs of namespace prefixes to pass to cdata_parse() (used by mods, maybe)
500
+ * @param string $tag
500 501
  */
501 502
 function dumpTags($data, $i, $tag = null, $xml_format = '', $forceCdataKeys = array(), $nsKeys = array())
502 503
 {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
 			{
838 838
 				uasort($loaded_attachments, function($a, $b) {
839 839
 					if ($a['filesize'] == $b['filesize'])
840
-					        return 0;
840
+							return 0;
841 841
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
842 842
 				});
843 843
 			}
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 			{
1243 1243
 				uasort($loaded_attachments, function($a, $b) {
1244 1244
 					if ($a['filesize'] == $b['filesize'])
1245
-					        return 0;
1245
+							return 0;
1246 1246
 					return ($a['filesize'] < $b['filesize']) ? -1 : 1;
1247 1247
 				});
1248 1248
 			}
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -346,7 +346,7 @@
 block discarded – undo
346 346
 
347 347
 		foreach ($xml as $item)
348 348
 		{
349
-			$link = array_filter($item['content'], function ($e) { return ($e['tag'] == 'link'); });
349
+			$link = array_filter($item['content'], function($e) { return ($e['tag'] == 'link'); });
350 350
 			$link = array_pop($link);
351 351
 
352 352
 			echo '
Please login to merge, or discard this 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.
other/buildtools/check-smf-languages.php 1 patch
Braces   +15 added lines, -8 removed lines patch added patch discarded remove patch
@@ -17,25 +17,29 @@  discard block
 block discarded – undo
17 17
 );
18 18
 
19 19
 // No file? Thats bad.
20
-if (!isset($_SERVER['argv'], $_SERVER['argv'][1]))
20
+if (!isset($_SERVER['argv'], $_SERVER['argv'][1])) {
21 21
 	die('Error: No File specified' . "\n");
22
+}
22 23
 
23 24
 // The file has to exist.
24 25
 $currentFile = $_SERVER['argv'][1];
25
-if (!file_exists($currentFile))
26
+if (!file_exists($currentFile)) {
26 27
 	die('Error: File does not exist' . "\n");
28
+}
27 29
 
28 30
 // Is this ignored?
29
-foreach ($ignoreFiles as $if)
31
+foreach ($ignoreFiles as $if) {
30 32
 	if (preg_match('~' . $if . '~i', $currentFile))
31 33
 		die;
34
+}
32 35
 
33 36
 // Lets get the main index.php for $forum_version and $software_year.
34 37
 $upgradeFile = fopen('./other/upgrade.php', 'r');
35 38
 $upgradeContents = fread($upgradeFile, 500);
36 39
 
37
-if (!preg_match('~define\(\'SMF_LANG_VERSION\', \'([^\']+)\'\);~i', $upgradeContents, $versionResults))
40
+if (!preg_match('~define\(\'SMF_LANG_VERSION\', \'([^\']+)\'\);~i', $upgradeContents, $versionResults)) {
38 41
 	die('Error: Could not locate SMF_LANG_VERSION' . "\n");
42
+}
39 43
 $currentVersion = $versionResults[1];
40 44
 
41 45
 $file = fopen($currentFile, 'r');
@@ -44,15 +48,18 @@  discard block
 block discarded – undo
44 48
 
45 49
 // Just see if the basic match is there.
46 50
 $match = '// Version: ' . $currentVersion;
47
-if (!preg_match('~' . $match . '~i', $contents))
51
+if (!preg_match('~' . $match . '~i', $contents)) {
48 52
 	die('Error: The version is missing or incorrect in ' . $currentFile . "\n");
53
+}
49 54
 
50 55
 // Get the file prefix.
51 56
 preg_match('~([A-Za-z]+)\.english\.php~i', $currentFile, $fileMatch);
52
-if (empty($fileMatch))
57
+if (empty($fileMatch)) {
53 58
 	die('Error: Could not locate locate the file name in ' . $currentFile . "\n");
59
+}
54 60
 
55 61
 // Now match that prefix in a more strict mode.
56 62
 $match = '// Version: ' . $currentVersion . '; ' . $fileMatch[1];
57
-if (!preg_match('~' . $match . '~i', $contents))
58
-	die('Error: The version with file name is missing or incorrect in ' . $currentFile . "\n");
59 63
\ No newline at end of file
64
+if (!preg_match('~' . $match . '~i', $contents)) {
65
+	die('Error: The version with file name is missing or incorrect in ' . $currentFile . "\n");
66
+}
Please login to merge, or discard this patch.