Completed
Branch release-2.1 (3c29ac)
by Mathias
08:54
created
Sources/Class-BrowserDetect.php 1 patch
Braces   +88 added lines, -60 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('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * Class browser_detector
@@ -55,20 +56,25 @@  discard block
 block discarded – undo
55 56
 		$this->_browsers['needs_size_fix'] = false;
56 57
 
57 58
 		// One at a time, one at a time, and in this order too
58
-		if ($this->isOpera())
59
-			$this->setupOpera();
59
+		if ($this->isOpera()) {
60
+					$this->setupOpera();
61
+		}
60 62
 		// Meh...
61
-		elseif ($this->isEdge())
62
-			$this->setupEdge();
63
+		elseif ($this->isEdge()) {
64
+					$this->setupEdge();
65
+		}
63 66
 		// Them webkits need to be set up too
64
-		elseif ($this->isWebkit())
65
-			$this->setupWebkit();
67
+		elseif ($this->isWebkit()) {
68
+					$this->setupWebkit();
69
+		}
66 70
 		// We may have work to do on Firefox...
67
-		elseif ($this->isFirefox())
68
-			$this->setupFirefox();
71
+		elseif ($this->isFirefox()) {
72
+					$this->setupFirefox();
73
+		}
69 74
 		// Old friend, old frenemy
70
-		elseif ($this->isIe())
71
-			$this->setupIe();
75
+		elseif ($this->isIe()) {
76
+					$this->setupIe();
77
+		}
72 78
 
73 79
 		// Just a few mobile checks
74 80
 		$this->isOperaMini();
@@ -84,11 +90,12 @@  discard block
 block discarded – undo
84 90
 			$this->_browsers['possibly_robot'] = !empty($user_info['possibly_robot']);
85 91
 
86 92
 			// Robots shouldn't be logging in or registering.  So, they aren't a bot.  Better to be wrong than sorry (or people won't be able to log in!), anyway.
87
-			if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register', 'signup'))) || !$user_info['is_guest'])
88
-				$this->_browsers['possibly_robot'] = false;
93
+			if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register', 'signup'))) || !$user_info['is_guest']) {
94
+							$this->_browsers['possibly_robot'] = false;
95
+			}
96
+		} else {
97
+					$this->_browsers['possibly_robot'] = false;
89 98
 		}
90
-		else
91
-			$this->_browsers['possibly_robot'] = false;
92 99
 
93 100
 		// Fill out the historical array as needed to support old mods that don't use isBrowser
94 101
 		$this->fillInformation();
@@ -106,8 +113,9 @@  discard block
 block discarded – undo
106 113
 	*/
107 114
 	function isOpera()
108 115
 	{
109
-		if (!isset($this->_browsers['is_opera']))
110
-			$this->_browsers['is_opera'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false;
116
+		if (!isset($this->_browsers['is_opera'])) {
117
+					$this->_browsers['is_opera'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false;
118
+		}
111 119
 		return $this->_browsers['is_opera'];
112 120
 	}
113 121
 
@@ -118,8 +126,9 @@  discard block
 block discarded – undo
118 126
 	function isIe()
119 127
 	{
120 128
 		// I'm IE, Yes I'm the real IE; All you other IEs are just imitating.
121
-		if (!isset($this->_browsers['is_ie']))
122
-			$this->_browsers['is_ie'] = !$this->isOpera() && !$this->isGecko() && !$this->isWebTv() && preg_match('~MSIE \d+~', $_SERVER['HTTP_USER_AGENT']) === 1;
129
+		if (!isset($this->_browsers['is_ie'])) {
130
+					$this->_browsers['is_ie'] = !$this->isOpera() && !$this->isGecko() && !$this->isWebTv() && preg_match('~MSIE \d+~', $_SERVER['HTTP_USER_AGENT']) === 1;
131
+		}
123 132
 		return $this->_browsers['is_ie'];
124 133
 	}
125 134
 
@@ -131,8 +140,9 @@  discard block
 block discarded – undo
131 140
 	{
132 141
 		// IE11 is a bit different than earlier versions
133 142
 		// The isGecko() part is to ensure we get this right...
134
-		if (!isset($this->_browsers['is_ie11']))
135
-			$this->_browsers['is_ie11'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false && $this->isGecko();
143
+		if (!isset($this->_browsers['is_ie11'])) {
144
+					$this->_browsers['is_ie11'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false && $this->isGecko();
145
+		}
136 146
 		return $this->_browsers['is_ie11'];
137 147
  	}
138 148
 
@@ -142,8 +152,9 @@  discard block
 block discarded – undo
142 152
 	*/
143 153
 	function isEdge()
144 154
 	{
145
-		if (!isset($this->_browsers['is_edge']))
146
-			$this->_browsers['is_edge'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Edge') !== false;
155
+		if (!isset($this->_browsers['is_edge'])) {
156
+					$this->_browsers['is_edge'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Edge') !== false;
157
+		}
147 158
 		return $this->_browsers['is_edge'];
148 159
 	}
149 160
 
@@ -153,8 +164,9 @@  discard block
 block discarded – undo
153 164
 	*/
154 165
 	function isWebkit()
155 166
 	{
156
-		if (!isset($this->_browsers['is_webkit']))
157
-			$this->_browsers['is_webkit'] = strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') !== false;
167
+		if (!isset($this->_browsers['is_webkit'])) {
168
+					$this->_browsers['is_webkit'] = strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') !== false;
169
+		}
158 170
 		return $this->_browsers['is_webkit'];
159 171
 	}
160 172
 
@@ -164,8 +176,9 @@  discard block
 block discarded – undo
164 176
 	*/
165 177
 	function isFirefox()
166 178
 	{
167
-		if (!isset($this->_browsers['is_firefox']))
168
-			$this->_browsers['is_firefox'] = preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)/~', $_SERVER['HTTP_USER_AGENT']) === 1 && $this->isGecko();
179
+		if (!isset($this->_browsers['is_firefox'])) {
180
+					$this->_browsers['is_firefox'] = preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)/~', $_SERVER['HTTP_USER_AGENT']) === 1 && $this->isGecko();
181
+		}
169 182
 		return $this->_browsers['is_firefox'];
170 183
 	}
171 184
 
@@ -175,8 +188,9 @@  discard block
 block discarded – undo
175 188
 	*/
176 189
 	function isWebTv()
177 190
 	{
178
-		if (!isset($this->_browsers['is_web_tv']))
179
-			$this->_browsers['is_web_tv'] = strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') !== false;
191
+		if (!isset($this->_browsers['is_web_tv'])) {
192
+					$this->_browsers['is_web_tv'] = strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') !== false;
193
+		}
180 194
 		return $this->_browsers['is_web_tv'];
181 195
 	}
182 196
 
@@ -186,8 +200,9 @@  discard block
 block discarded – undo
186 200
 	*/
187 201
 	function isKonqueror()
188 202
 	{
189
-		if (!isset($this->_browsers['is_konqueror']))
190
-			$this->_browsers['is_konqueror'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false;
203
+		if (!isset($this->_browsers['is_konqueror'])) {
204
+					$this->_browsers['is_konqueror'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false;
205
+		}
191 206
 		return $this->_browsers['is_konqueror'];
192 207
 	}
193 208
 
@@ -197,8 +212,9 @@  discard block
 block discarded – undo
197 212
 	*/
198 213
 	function isGecko()
199 214
 	{
200
-		if (!isset($this->_browsers['is_gecko']))
201
-			$this->_browsers['is_gecko'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false && !$this->isWebkit() && !$this->isKonqueror();
215
+		if (!isset($this->_browsers['is_gecko'])) {
216
+					$this->_browsers['is_gecko'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false && !$this->isWebkit() && !$this->isKonqueror();
217
+		}
202 218
 		return $this->_browsers['is_gecko'];
203 219
 	}
204 220
 
@@ -208,10 +224,12 @@  discard block
 block discarded – undo
208 224
 	*/
209 225
 	function isOperaMini()
210 226
 	{
211
-		if (!isset($this->_browsers['is_opera_mini']))
212
-			$this->_browsers['is_opera_mini'] = (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) || stripos($_SERVER['HTTP_USER_AGENT'], 'opera mini') !== false);
213
-		if ($this->_browsers['is_opera_mini'])
214
-			$this->_is_mobile = true;
227
+		if (!isset($this->_browsers['is_opera_mini'])) {
228
+					$this->_browsers['is_opera_mini'] = (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) || stripos($_SERVER['HTTP_USER_AGENT'], 'opera mini') !== false);
229
+		}
230
+		if ($this->_browsers['is_opera_mini']) {
231
+					$this->_is_mobile = true;
232
+		}
215 233
 		return $this->_browsers['is_opera_mini'];
216 234
 	}
217 235
 
@@ -221,10 +239,12 @@  discard block
 block discarded – undo
221 239
 	*/
222 240
 	function isOperaMobi()
223 241
 	{
224
-		if (!isset($this->_browsers['is_opera_mobi']))
225
-			$this->_browsers['is_opera_mobi'] = stripos($_SERVER['HTTP_USER_AGENT'], 'opera mobi') !== false;
226
-		if ($this->_browsers['is_opera_mobi'])
227
-			$this->_is_mobile = true;
242
+		if (!isset($this->_browsers['is_opera_mobi'])) {
243
+					$this->_browsers['is_opera_mobi'] = stripos($_SERVER['HTTP_USER_AGENT'], 'opera mobi') !== false;
244
+		}
245
+		if ($this->_browsers['is_opera_mobi']) {
246
+					$this->_is_mobile = true;
247
+		}
228 248
 		return $this->_browsers['is_opera_mini'];
229 249
 	}
230 250
 
@@ -244,8 +264,9 @@  discard block
 block discarded – undo
244 264
 		);
245 265
 
246 266
 		// blackberry, playbook, iphone, nokia, android and ipods set a mobile flag
247
-		if ($this->_browsers['is_iphone'] || $this->_browsers['is_blackberry'] || $this->_browsers['is_android'] || $this->_browsers['is_nokia'])
248
-			$this->_is_mobile = true;
267
+		if ($this->_browsers['is_iphone'] || $this->_browsers['is_blackberry'] || $this->_browsers['is_android'] || $this->_browsers['is_nokia']) {
268
+					$this->_is_mobile = true;
269
+		}
249 270
 
250 271
 		// @todo what to do with the blaPad? ... for now leave it detected as Safari ...
251 272
 		$this->_browsers['is_safari'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false && !$this->_browsers['is_chrome'] && !$this->_browsers['is_iphone'];
@@ -254,15 +275,17 @@  discard block
 block discarded – undo
254 275
 		// if Chrome, get the major version
255 276
 		if ($this->_browsers['is_chrome'])
256 277
 		{
257
-			if (preg_match('~chrome[/]([0-9][0-9]?[.])~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1)
258
-				$this->_browsers['is_chrome' . (int) $match[1]] = true;
278
+			if (preg_match('~chrome[/]([0-9][0-9]?[.])~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1) {
279
+							$this->_browsers['is_chrome' . (int) $match[1]] = true;
280
+			}
259 281
 		}
260 282
 
261 283
 		// or if Safari get its major version
262 284
 		if ($this->_browsers['is_safari'])
263 285
 		{
264
-			if (preg_match('~version/?(.*)safari.*~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1)
265
-				$this->_browsers['is_safari' . (int) trim($match[1])] = true;
286
+			if (preg_match('~version/?(.*)safari.*~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1) {
287
+							$this->_browsers['is_safari' . (int) trim($match[1])] = true;
288
+			}
266 289
 		}
267 290
 	}
268 291
 
@@ -291,8 +314,9 @@  discard block
 block discarded – undo
291 314
 			$this->_browsers['is_ie' . ((int) $trident_match[1] + 4)] = true;
292 315
 
293 316
 			// If trident is set, see the (if any) msie tag in the user agent matches ... if not its in some compatibility view
294
-			if (isset($msie_match[1]) && ($msie_match[1] < $trident_match[1] + 4))
295
-				$this->_browsers['is_ie_compat_view'] = true;
317
+			if (isset($msie_match[1]) && ($msie_match[1] < $trident_match[1] + 4)) {
318
+							$this->_browsers['is_ie_compat_view'] = true;
319
+			}
296 320
 		}
297 321
 
298 322
 		// Detect true IE6 and IE7 and not IE in compat mode.
@@ -326,8 +350,9 @@  discard block
 block discarded – undo
326 350
 	 */
327 351
 	private function setupFirefox()
328 352
 	{
329
-		if (preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)[\/ \(]([^ ;\)]+)~', $_SERVER['HTTP_USER_AGENT'], $match) === 1)
330
-			$this->_browsers['is_firefox' . (int) $match[1]] = true;
353
+		if (preg_match('~(?:Firefox|Ice[wW]easel|IceCat|Shiretoko|Minefield)[\/ \(]([^ ;\)]+)~', $_SERVER['HTTP_USER_AGENT'], $match) === 1) {
354
+					$this->_browsers['is_firefox' . (int) $match[1]] = true;
355
+		}
331 356
 	}
332 357
 
333 358
 	/**
@@ -338,11 +363,13 @@  discard block
 block discarded – undo
338 363
 	private function setupOpera()
339 364
 	{
340 365
 		// Opera 10+ uses the version tag at the end of the string
341
-		if (preg_match('~\sVersion/([0-9]+)\.[0-9]+(?:\s*|$)~', $_SERVER['HTTP_USER_AGENT'], $match))
342
-			$this->_browsers['is_opera' . (int) $match[1]] = true;
366
+		if (preg_match('~\sVersion/([0-9]+)\.[0-9]+(?:\s*|$)~', $_SERVER['HTTP_USER_AGENT'], $match)) {
367
+					$this->_browsers['is_opera' . (int) $match[1]] = true;
368
+		}
343 369
 		// Opera pre 10 is supposed to uses the Opera tag alone, as do some spoofers
344
-		elseif (preg_match('~Opera[ /]([0-9]+)(?!\\.[89])~', $_SERVER['HTTP_USER_AGENT'], $match))
345
-			$this->_browsers['is_opera' . (int) $match[1]] = true;
370
+		elseif (preg_match('~Opera[ /]([0-9]+)(?!\\.[89])~', $_SERVER['HTTP_USER_AGENT'], $match)) {
371
+					$this->_browsers['is_opera' . (int) $match[1]] = true;
372
+		}
346 373
 
347 374
 		// Needs size fix?
348 375
 		$this->_browsers['needs_size_fix'] = !empty($this->_browsers['is_opera6']);
@@ -353,8 +380,9 @@  discard block
 block discarded – undo
353 380
 	 */
354 381
 	private function setupEdge()
355 382
 	{
356
-		if (preg_match('~Edge[\/]([0-9][0-9]?[\.][0-9][0-9])~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1)
357
-			$this->_browsers['is_edge' . (int) $match[1]] = true;
383
+		if (preg_match('~Edge[\/]([0-9][0-9]?[\.][0-9][0-9])~i', $_SERVER['HTTP_USER_AGENT'], $match) === 1) {
384
+					$this->_browsers['is_edge' . (int) $match[1]] = true;
385
+		}
358 386
 	}
359 387
 
360 388
 	/**
@@ -367,9 +395,9 @@  discard block
 block discarded – undo
367 395
 	{
368 396
 		global $context;
369 397
 
370
-		if ($this->_is_mobile)
371
-			$context['browser_body_id'] = 'mobile';
372
-		else
398
+		if ($this->_is_mobile) {
399
+					$context['browser_body_id'] = 'mobile';
400
+		} else
373 401
 		{
374 402
 			// add in any specific detection conversions here if you want a special body id e.g. 'is_opera9' => 'opera9'
375 403
 			$browser_priority = array(
Please login to merge, or discard this patch.
Sources/Calendar.php 1 patch
Braces   +94 added lines, -71 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
  * Show the calendar.
@@ -47,12 +48,14 @@  discard block
 block discarded – undo
47 48
 		'post' => 'CalendarPost',
48 49
 	);
49 50
 
50
-	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']]))
51
-		return call_helper($subActions[$_GET['sa']]);
51
+	if (isset($_GET['sa']) && isset($subActions[$_GET['sa']])) {
52
+			return call_helper($subActions[$_GET['sa']]);
53
+	}
52 54
 
53 55
 	// You can't do anything if the calendar is off.
54
-	if (empty($modSettings['cal_enabled']))
55
-		fatal_lang_error('calendar_off', false);
56
+	if (empty($modSettings['cal_enabled'])) {
57
+			fatal_lang_error('calendar_off', false);
58
+	}
56 59
 
57 60
 	// This is gonna be needed...
58 61
 	loadTemplate('Calendar');
@@ -97,8 +100,9 @@  discard block
 block discarded – undo
97 100
 	$context['view_week'] = isset($_GET['viewweek']);
98 101
 
99 102
 	// Don't let search engines index weekly calendar pages.
100
-	if ($context['view_week'])
101
-		$context['robot_no_index'] = true;
103
+	if ($context['view_week']) {
104
+			$context['robot_no_index'] = true;
105
+	}
102 106
 
103 107
 	// Get the current day of month...
104 108
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -112,17 +116,20 @@  discard block
 block discarded – undo
112 116
 	);
113 117
 
114 118
 	// Make sure the year and month are in valid ranges.
115
-	if ($curPage['month'] < 1 || $curPage['month'] > 12)
116
-		fatal_lang_error('invalid_month', false);
117
-	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear'])
118
-		fatal_lang_error('invalid_year', false);
119
+	if ($curPage['month'] < 1 || $curPage['month'] > 12) {
120
+			fatal_lang_error('invalid_month', false);
121
+	}
122
+	if ($curPage['year'] < $modSettings['cal_minyear'] || $curPage['year'] > $modSettings['cal_maxyear']) {
123
+			fatal_lang_error('invalid_year', false);
124
+	}
119 125
 	// If we have a day clean that too.
120 126
 	if ($context['view_week'])
121 127
 	{
122 128
 		// Note $isValid is -1 < PHP 5.1
123 129
 		$isValid = mktime(0, 0, 0, $curPage['month'], $curPage['day'], $curPage['year']);
124
-		if ($curPage['day'] > 31 || !$isValid || $isValid == -1)
125
-			fatal_lang_error('invalid_day', false);
130
+		if ($curPage['day'] > 31 || !$isValid || $isValid == -1) {
131
+					fatal_lang_error('invalid_day', false);
132
+		}
126 133
 	}
127 134
 
128 135
 	// Load all the context information needed to show the calendar grid.
@@ -144,21 +151,24 @@  discard block
 block discarded – undo
144 151
 	);
145 152
 
146 153
 	// Load up the main view.
147
-	if ($context['view_week'])
148
-		$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
149
-	else
150
-		$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
154
+	if ($context['view_week']) {
155
+			$context['calendar_grid_main'] = getCalendarWeek($curPage['month'], $curPage['year'], $curPage['day'], $calendarOptions);
156
+	} else {
157
+			$context['calendar_grid_main'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
158
+	}
151 159
 
152 160
 	// Load up the previous and next months.
153 161
 	$context['calendar_grid_current'] = getCalendarGrid($curPage['month'], $curPage['year'], $calendarOptions);
154 162
 
155 163
 	// Only show previous month if it isn't pre-January of the min-year
156
-	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1)
157
-		$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
164
+	if ($context['calendar_grid_current']['previous_calendar']['year'] > $modSettings['cal_minyear'] || $curPage['month'] != 1) {
165
+			$context['calendar_grid_prev'] = getCalendarGrid($context['calendar_grid_current']['previous_calendar']['month'], $context['calendar_grid_current']['previous_calendar']['year'], $calendarOptions, true);
166
+	}
158 167
 
159 168
 	// Only show next month if it isn't post-December of the max-year
160
-	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12)
161
-		$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
169
+	if ($context['calendar_grid_current']['next_calendar']['year'] < $modSettings['cal_maxyear'] || $curPage['month'] != 12) {
170
+			$context['calendar_grid_next'] = getCalendarGrid($context['calendar_grid_current']['next_calendar']['month'], $context['calendar_grid_current']['next_calendar']['year'], $calendarOptions);
171
+	}
162 172
 
163 173
 	// Basic template stuff.
164 174
 	$context['allow_calendar_event'] = allowedTo('calendar_post');
@@ -191,17 +201,19 @@  discard block
 block discarded – undo
191 201
 		'name' => $txt['months'][$context['current_month']] . ' ' . $context['current_year']
192 202
 	);
193 203
 	// If applicable, add the current week to the linktree.
194
-	if ($context['view_week'])
195
-		$context['linktree'][] = array(
204
+	if ($context['view_week']) {
205
+			$context['linktree'][] = array(
196 206
 			'url' => $scripturl . '?action=calendar;viewweek;year=' . $context['current_year'] . ';month=' . $context['current_month'] . ';day=' . $context['current_day'],
197 207
 			'name' => $context['calendar_grid_main']['week_title'],
198 208
 		);
209
+	}
199 210
 
200 211
 	// Build the calendar button array.
201 212
 	$context['calendar_buttons'] = array();
202 213
 
203
-	if ($context['can_post'])
204
-		$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
214
+	if ($context['can_post']) {
215
+			$context['calendar_buttons']['post_event'] = array('text' => 'calendar_post_event', 'image' => 'calendarpe.png', 'url' => $scripturl . '?action=calendar;sa=post;month=' . $context['current_month'] . ';year=' . $context['current_year'] . ';' . $context['session_var'] . '=' . $context['session_id']);
216
+	}
205 217
 
206 218
 	// Allow mods to add additional buttons here
207 219
 	call_integration_hook('integrate_calendar_buttons');
@@ -229,8 +241,9 @@  discard block
 block discarded – undo
229 241
 	require_once($sourcedir . '/Subs-Calendar.php');
230 242
 
231 243
 	// Cast this for safety...
232
-	if (isset($_REQUEST['eventid']))
233
-		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
244
+	if (isset($_REQUEST['eventid'])) {
245
+			$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
246
+	}
234 247
 
235 248
 	// Submitting?
236 249
 	if (isset($_POST[$context['session_var']], $_REQUEST['eventid']))
@@ -238,12 +251,14 @@  discard block
 block discarded – undo
238 251
 		checkSession();
239 252
 
240 253
 		// Validate the post...
241
-		if (!isset($_POST['link_to_board']))
242
-			validateEventPost();
254
+		if (!isset($_POST['link_to_board'])) {
255
+					validateEventPost();
256
+		}
243 257
 
244 258
 		// If you're not allowed to edit any events, you have to be the poster.
245
-		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any'))
246
-			isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
259
+		if ($_REQUEST['eventid'] > 0 && !allowedTo('calendar_edit_any')) {
260
+					isAllowedTo('calendar_edit_' . (!empty($user_info['id']) && getEventPoster($_REQUEST['eventid']) == $user_info['id'] ? 'own' : 'any'));
261
+		}
247 262
 
248 263
 		// New - and directing?
249 264
 		if (isset($_POST['link_to_board']) || empty($modSettings['cal_allow_unlinked']))
@@ -267,8 +282,9 @@  discard block
 block discarded – undo
267 282
 		}
268 283
 
269 284
 		// Deleting...
270
-		elseif (isset($_REQUEST['deleteevent']))
271
-			removeEvent($_REQUEST['eventid']);
285
+		elseif (isset($_REQUEST['deleteevent'])) {
286
+					removeEvent($_REQUEST['eventid']);
287
+		}
272 288
 
273 289
 		// ... or just update it?
274 290
 		else
@@ -315,13 +331,13 @@  discard block
 block discarded – undo
315 331
 			'span' => 1,
316 332
 		);
317 333
 		$context['event']['last_day'] = (int) strftime('%d', mktime(0, 0, 0, $context['event']['month'] == 12 ? 1 : $context['event']['month'] + 1, 0, $context['event']['month'] == 12 ? $context['event']['year'] + 1 : $context['event']['year']));
318
-	}
319
-	else
334
+	} else
320 335
 	{
321 336
 		$context['event'] = getEventProperties($_REQUEST['eventid']);
322 337
 
323
-		if ($context['event'] === false)
324
-			fatal_lang_error('no_access', false);
338
+		if ($context['event'] === false) {
339
+					fatal_lang_error('no_access', false);
340
+		}
325 341
 
326 342
 		// If it has a board, then they should be editing it within the topic.
327 343
 		if (!empty($context['event']['topic']['id']) && !empty($context['event']['topic']['first_msg']))
@@ -332,10 +348,11 @@  discard block
 block discarded – undo
332 348
 		}
333 349
 
334 350
 		// Make sure the user is allowed to edit this event.
335
-		if ($context['event']['member'] != $user_info['id'])
336
-			isAllowedTo('calendar_edit_any');
337
-		elseif (!allowedTo('calendar_edit_any'))
338
-			isAllowedTo('calendar_edit_own');
351
+		if ($context['event']['member'] != $user_info['id']) {
352
+					isAllowedTo('calendar_edit_any');
353
+		} elseif (!allowedTo('calendar_edit_any')) {
354
+					isAllowedTo('calendar_edit_own');
355
+		}
339 356
 	}
340 357
 
341 358
 	// Get list of boards that can be posted in.
@@ -344,8 +361,7 @@  discard block
 block discarded – undo
344 361
 	{
345 362
 		// You can post new events but can't link them to anything...
346 363
 		$context['event']['categories'] = array();
347
-	}
348
-	else
364
+	} else
349 365
 	{
350 366
 		// Load the list of boards and categories in the context.
351 367
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -383,12 +399,14 @@  discard block
 block discarded – undo
383 399
 	global $smcFunc, $sourcedir, $forum_version, $modSettings, $webmaster_email, $mbname;
384 400
 
385 401
 	// You can't export if the calendar export feature is off.
386
-	if (empty($modSettings['cal_export']))
387
-		fatal_lang_error('calendar_export_off', false);
402
+	if (empty($modSettings['cal_export'])) {
403
+			fatal_lang_error('calendar_export_off', false);
404
+	}
388 405
 
389 406
 	// Goes without saying that this is required.
390
-	if (!isset($_REQUEST['eventid']))
391
-		fatal_lang_error('no_access', false);
407
+	if (!isset($_REQUEST['eventid'])) {
408
+			fatal_lang_error('no_access', false);
409
+	}
392 410
 
393 411
 	// This is kinda wanted.
394 412
 	require_once($sourcedir . '/Subs-Calendar.php');
@@ -396,15 +414,17 @@  discard block
 block discarded – undo
396 414
 	// Load up the event in question and check it exists.
397 415
 	$event = getEventProperties($_REQUEST['eventid']);
398 416
 
399
-	if ($event === false)
400
-		fatal_lang_error('no_access', false);
417
+	if ($event === false) {
418
+			fatal_lang_error('no_access', false);
419
+	}
401 420
 
402 421
 	// Check the title isn't too long - iCal requires some formatting if so.
403 422
 	$title = str_split($event['title'], 30);
404 423
 	foreach ($title as $id => $line)
405 424
 	{
406
-		if ($id != 0)
407
-			$title[$id] = ' ' . $title[$id];
425
+		if ($id != 0) {
426
+					$title[$id] = ' ' . $title[$id];
427
+		}
408 428
 		$title[$id] .= "\n";
409 429
 	}
410 430
 
@@ -433,12 +453,14 @@  discard block
 block discarded – undo
433 453
 	$filecontents .= 'DTSTART;VALUE=DATE:' . $datestart . "\n";
434 454
 
435 455
 	// more than one day
436
-	if ($event['span'] > 1)
437
-		$filecontents .= 'DTEND;VALUE=DATE:' . $dateend . "\n";
456
+	if ($event['span'] > 1) {
457
+			$filecontents .= 'DTEND;VALUE=DATE:' . $dateend . "\n";
458
+	}
438 459
 
439 460
 	// event has changed? advance the sequence for this UID
440
-	if ($event['sequence'] > 0)
441
-		$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
461
+	if ($event['sequence'] > 0) {
462
+			$filecontents .= 'SEQUENCE:' . $event['sequence'] . "\n";
463
+	}
442 464
 
443 465
 	$filecontents .= 'SUMMARY:' . implode('', $title);
444 466
 	$filecontents .= 'UID:' . $event['eventid'] . '@' . str_replace(' ', '-', $mbname) . "\n";
@@ -447,23 +469,26 @@  discard block
 block discarded – undo
447 469
 
448 470
 	// Send some standard headers.
449 471
 	ob_end_clean();
450
-	if (!empty($modSettings['enableCompressedOutput']))
451
-		@ob_start('ob_gzhandler');
452
-	else
453
-		ob_start();
472
+	if (!empty($modSettings['enableCompressedOutput'])) {
473
+			@ob_start('ob_gzhandler');
474
+	} else {
475
+			ob_start();
476
+	}
454 477
 
455 478
 	// Send the file headers
456 479
 	header('Pragma: ');
457 480
 	header('Cache-Control: no-cache');
458
-	if (!isBrowser('gecko'))
459
-		header('Content-Transfer-Encoding: binary');
481
+	if (!isBrowser('gecko')) {
482
+			header('Content-Transfer-Encoding: binary');
483
+	}
460 484
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
461 485
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . 'GMT');
462 486
 	header('Accept-Ranges: bytes');
463 487
 	header('Connection: close');
464 488
 	header('Content-Disposition: attachment; filename="' . $event['title'] . '.ics"');
465
-	if (empty($modSettings['enableCompressedOutput']))
466
-		header('Content-Length: ' . $smcFunc['strlen']($filecontents));
489
+	if (empty($modSettings['enableCompressedOutput'])) {
490
+			header('Content-Length: ' . $smcFunc['strlen']($filecontents));
491
+	}
467 492
 
468 493
 	// This is a calendar item!
469 494
 	header('Content-Type: text/calendar');
@@ -502,20 +527,17 @@  discard block
 block discarded – undo
502 527
 		$context['sub_template'] = 'bcd';
503 528
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;bcd', 'name' => 'BCD');
504 529
 		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjI6ImgxIjthOjI6e2k6MDtpOjI7aToxO2k6MTt9czoyOiJoMiI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjI6Im0xIjthOjM6e2k6MDtpOjQ7aToxO2k6MjtpOjI7aToxO31zOjI6Im0yIjthOjQ6e2k6MDtpOjg7aToxO2k6NDtpOjI7aToyO2k6MztpOjE7fXM6MjoiczEiO2E6Mzp7aTowO2k6NDtpOjE7aToyO2k6MjtpOjE7fXM6MjoiczIiO2E6NDp7aTowO2k6ODtpOjE7aTo0O2k6MjtpOjI7aTozO2k6MTt9fQ=='));
505
-	}
506
-	elseif (!$omfg && !isset($_REQUEST['time']))
530
+	} elseif (!$omfg && !isset($_REQUEST['time']))
507 531
 	{
508 532
 		$context['sub_template'] = 'hms';
509 533
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock', 'name' => 'Binary');
510 534
 		$context['clockicons'] = safe_unserialize(base64_decode('YTozOntzOjE6ImgiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czoxOiJtIjthOjY6e2k6MDtpOjMyO2k6MTtpOjE2O2k6MjtpOjg7aTozO2k6NDtpOjQ7aToyO2k6NTtpOjE7fXM6MToicyI7YTo2OntpOjA7aTozMjtpOjE7aToxNjtpOjI7aTo4O2k6MztpOjQ7aTo0O2k6MjtpOjU7aToxO319'));
511
-	}
512
-	elseif ($omfg)
535
+	} elseif ($omfg)
513 536
 	{
514 537
 		$context['sub_template'] = 'omfg';
515 538
 		$context['linktree'][] = array('url' => $scripturl . '?action=clock;omfg', 'name' => 'OMFG');
516 539
 		$context['clockicons'] = safe_unserialize(base64_decode('YTo2OntzOjQ6InllYXIiO2E6Nzp7aTowO2k6NjQ7aToxO2k6MzI7aToyO2k6MTY7aTozO2k6ODtpOjQ7aTo0O2k6NTtpOjI7aTo2O2k6MTt9czo1OiJtb250aCI7YTo0OntpOjA7aTo4O2k6MTtpOjQ7aToyO2k6MjtpOjM7aToxO31zOjM6ImRheSI7YTo1OntpOjA7aToxNjtpOjE7aTo4O2k6MjtpOjQ7aTozO2k6MjtpOjQ7aToxO31zOjQ6ImhvdXIiO2E6NTp7aTowO2k6MTY7aToxO2k6ODtpOjI7aTo0O2k6MztpOjI7aTo0O2k6MTt9czozOiJtaW4iO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9czozOiJzZWMiO2E6Njp7aTowO2k6MzI7aToxO2k6MTY7aToyO2k6ODtpOjM7aTo0O2k6NDtpOjI7aTo1O2k6MTt9fQ=='));
517
-	}
518
-	elseif (isset($_REQUEST['time']))
540
+	} elseif (isset($_REQUEST['time']))
519 541
 	{
520 542
 		$context['sub_template'] = 'thetime';
521 543
 		$time = getdate($_REQUEST['time'] == 'now' ? time() : (int) $_REQUEST['time']);
@@ -575,12 +597,13 @@  discard block
 block discarded – undo
575 597
 			),
576 598
 		);
577 599
 
578
-		foreach ($context['clockicons'] as $t => $vs)
579
-			foreach ($vs as $v => $dumb)
600
+		foreach ($context['clockicons'] as $t => $vs) {
601
+					foreach ($vs as $v => $dumb)
580 602
 			{
581 603
 				if ($$t >= $v)
582 604
 				{
583 605
 					$$t -= $v;
606
+		}
584 607
 					$context['clockicons'][$t][$v] = true;
585 608
 				}
586 609
 			}
Please login to merge, or discard this patch.
Sources/ReportToMod.php 1 patch
Braces   +71 added lines, -51 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  * @version 2.1 Beta 3
13 13
  */
14 14
 
15
-if (!defined('SMF'))
15
+if (!defined('SMF')) {
16 16
 	die('No direct access...');
17
+}
17 18
 
18 19
 /**
19 20
  * Report a post or profile to the moderator... ask for a comment.
@@ -35,10 +36,11 @@  discard block
 block discarded – undo
35 36
 
36 37
 	// You can't use this if it's off or you are not allowed to do it.
37 38
 	// If we don't have the ID of something to report, we'll die with a no_access error below
38
-	if (isset($_REQUEST['msg']))
39
-		isAllowedTo('report_any');
40
-	elseif (isset($_REQUEST['u']))
41
-		isAllowedTo('report_user');
39
+	if (isset($_REQUEST['msg'])) {
40
+			isAllowedTo('report_any');
41
+	} elseif (isset($_REQUEST['u'])) {
42
+			isAllowedTo('report_user');
43
+	}
42 44
 
43 45
 	// Previewing or modifying?
44 46
 	if (isset($_POST['preview']) && !isset($_POST['save']))
@@ -56,19 +58,23 @@  discard block
 block discarded – undo
56 58
 	}
57 59
 
58 60
 	// If they're posting, it should be processed by ReportToModerator2.
59
-	if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']) && !isset($_POST['preview']))
60
-		ReportToModerator2();
61
+	if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']) && !isset($_POST['preview'])) {
62
+			ReportToModerator2();
63
+	}
61 64
 
62 65
 	// We need a message ID or user ID to check!
63
-	if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']) && empty($_REQUEST['u']))
64
-		fatal_lang_error('no_access', false);
66
+	if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']) && empty($_REQUEST['u'])) {
67
+			fatal_lang_error('no_access', false);
68
+	}
65 69
 
66 70
 	// For compatibility, accept mid, but we should be using msg. (not the flavor kind!)
67
-	if (!empty($_REQUEST['msg']) || !empty($_REQUEST['mid']))
68
-		$_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg'];
71
+	if (!empty($_REQUEST['msg']) || !empty($_REQUEST['mid'])) {
72
+			$_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg'];
73
+	}
69 74
 	// msg and mid empty - assume we're reporting a user
70
-	elseif (!empty($_REQUEST['u']))
71
-		$_REQUEST['u'] = (int) $_REQUEST['u'];
75
+	elseif (!empty($_REQUEST['u'])) {
76
+			$_REQUEST['u'] = (int) $_REQUEST['u'];
77
+	}
72 78
 
73 79
 	// Set up some form values
74 80
 	$context['report_type'] = isset($_REQUEST['msg']) ? 'msg' : 'u';
@@ -89,8 +95,9 @@  discard block
 block discarded – undo
89 95
 				'id_msg' => $_REQUEST['msg'],
90 96
 			)
91 97
 		);
92
-		if ($smcFunc['db_num_rows']($result) == 0)
93
-			fatal_lang_error('no_board', false);
98
+		if ($smcFunc['db_num_rows']($result) == 0) {
99
+					fatal_lang_error('no_board', false);
100
+		}
94 101
 		list ($_REQUEST['msg'], $member, $starter) = $smcFunc['db_fetch_row']($result);
95 102
 		$smcFunc['db_free_result']($result);
96 103
 
@@ -101,8 +108,7 @@  discard block
 block discarded – undo
101 108
 
102 109
 		// The submit URL is different for users than it is for posts
103 110
 		$context['submit_url'] = $scripturl . '?action=reporttm;msg=' . $_REQUEST['msg'] . ';topic=' . $topic;
104
-	}
105
-	else
111
+	} else
106 112
 	{
107 113
 		// Check the user's ID
108 114
 		$result = $smcFunc['db_query']('', '
@@ -114,8 +120,9 @@  discard block
 block discarded – undo
114 120
 			)
115 121
 		);
116 122
 
117
-		if ($smcFunc['db_num_rows']($result) == 0)
118
-			fatal_lang_error('no_user', false);
123
+		if ($smcFunc['db_num_rows']($result) == 0) {
124
+					fatal_lang_error('no_user', false);
125
+		}
119 126
 		list($_REQUEST['u'], $display_name, $username) = $smcFunc['db_fetch_row']($result);
120 127
 
121 128
 		$context['current_user'] = $_REQUEST['u'];
@@ -170,10 +177,11 @@  discard block
 block discarded – undo
170 177
 	is_not_guest();
171 178
 
172 179
 	// You must have the proper permissions!
173
-	if (isset($_REQUEST['msg']))
174
-		isAllowedTo('report_any');
175
-	else
176
-		isAllowedTo('report_user');
180
+	if (isset($_REQUEST['msg'])) {
181
+			isAllowedTo('report_any');
182
+	} else {
183
+			isAllowedTo('report_user');
184
+	}
177 185
 
178 186
 	// Make sure they aren't spamming.
179 187
 	spamProtection('reporttm');
@@ -187,17 +195,20 @@  discard block
 block discarded – undo
187 195
 	$post_errors = array();
188 196
 
189 197
 	// Check their session.
190
-	if (checkSession('post', '', false) != '')
191
-		$post_errors[] = 'session_timeout';
198
+	if (checkSession('post', '', false) != '') {
199
+			$post_errors[] = 'session_timeout';
200
+	}
192 201
 
193 202
 	// Make sure we have a comment and it's clean.
194
-	if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '')
195
-		$post_errors[] = 'no_comment';
203
+	if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '') {
204
+			$post_errors[] = 'no_comment';
205
+	}
196 206
 
197 207
 	$poster_comment = strtr($smcFunc['htmlspecialchars']($_POST['comment']), array("\r" => '', "\t" => ''));
198 208
 
199
-	if ($smcFunc['strlen']($poster_comment) > 254)
200
-		$post_errors[] = 'post_too_long';
209
+	if ($smcFunc['strlen']($poster_comment) > 254) {
210
+			$post_errors[] = 'post_too_long';
211
+	}
201 212
 
202 213
 	// Any errors?
203 214
 	if (!empty($post_errors))
@@ -205,8 +216,9 @@  discard block
 block discarded – undo
205 216
 		loadLanguage('Errors');
206 217
 
207 218
 		$context['post_errors'] = array();
208
-		foreach ($post_errors as $post_error)
209
-			$context['post_errors'][$post_error] = $txt['error_' . $post_error];
219
+		foreach ($post_errors as $post_error) {
220
+					$context['post_errors'][$post_error] = $txt['error_' . $post_error];
221
+		}
210 222
 
211 223
 		return ReportToModerator();
212 224
 	}
@@ -215,8 +227,7 @@  discard block
 block discarded – undo
215 227
 	{
216 228
 		// Handle this elsewhere to keep things from getting too long
217 229
 		reportPost($_POST['msg'], $poster_comment);
218
-	}
219
-	else
230
+	} else
220 231
 	{
221 232
 		reportUser($_POST['u'], $poster_comment);
222 233
 	}
@@ -247,8 +258,9 @@  discard block
 block discarded – undo
247 258
 			'id_msg' => $_POST['msg'],
248 259
 		)
249 260
 	);
250
-	if ($smcFunc['db_num_rows']($request) == 0)
251
-		fatal_lang_error('no_board', false);
261
+	if ($smcFunc['db_num_rows']($request) == 0) {
262
+			fatal_lang_error('no_board', false);
263
+	}
252 264
 	$message = $smcFunc['db_fetch_assoc']($request);
253 265
 	$smcFunc['db_free_result']($request);
254 266
 
@@ -268,18 +280,20 @@  discard block
 block discarded – undo
268 280
 			'ignored' => 1,
269 281
 		)
270 282
 	);
271
-	if ($smcFunc['db_num_rows']($request) != 0)
272
-		list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request);
283
+	if ($smcFunc['db_num_rows']($request) != 0) {
284
+			list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request);
285
+	}
273 286
 
274 287
 	$smcFunc['db_free_result']($request);
275 288
 
276 289
 	// If we're just going to ignore these, then who gives a monkeys...
277
-	if (!empty($ignore))
278
-		redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']);
290
+	if (!empty($ignore)) {
291
+			redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']);
292
+	}
279 293
 
280 294
 	// Already reported? My god, we could be dealing with a real rogue here...
281
-	if (!empty($id_report))
282
-		$smcFunc['db_query']('', '
295
+	if (!empty($id_report)) {
296
+			$smcFunc['db_query']('', '
283 297
 			UPDATE {db_prefix}log_reported
284 298
 			SET num_reports = num_reports + 1, time_updated = {int:current_time}
285 299
 			WHERE id_report = {int:id_report}',
@@ -288,11 +302,13 @@  discard block
 block discarded – undo
288 302
 				'id_report' => $id_report,
289 303
 			)
290 304
 		);
305
+	}
291 306
 	// Otherwise, we shall make one!
292 307
 	else
293 308
 	{
294
-		if (empty($message['real_name']))
295
-			$message['real_name'] = $message['poster_name'];
309
+		if (empty($message['real_name'])) {
310
+					$message['real_name'] = $message['poster_name'];
311
+		}
296 312
 
297 313
 		$smcFunc['db_insert']('',
298 314
 			'{db_prefix}log_reported',
@@ -371,8 +387,9 @@  discard block
 block discarded – undo
371 387
 			'id_member' => $_POST['u']
372 388
 		)
373 389
 	);
374
-	if ($smcFunc['db_num_rows']($request) == 0)
375
-		fatal_lang_error('no_user', false);
390
+	if ($smcFunc['db_num_rows']($request) == 0) {
391
+			fatal_lang_error('no_user', false);
392
+	}
376 393
 	$user = $smcFunc['db_fetch_assoc']($request);
377 394
 	$smcFunc['db_free_result']($request);
378 395
 
@@ -393,18 +410,20 @@  discard block
 block discarded – undo
393 410
 			'ignored' => 1,
394 411
 		)
395 412
 	);
396
-	if ($smcFunc['db_num_rows']($request) != 0)
397
-		list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request);
413
+	if ($smcFunc['db_num_rows']($request) != 0) {
414
+			list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request);
415
+	}
398 416
 
399 417
 	$smcFunc['db_free_result']($request);
400 418
 
401 419
 	// If we're just going to ignore these, then who gives a monkeys...
402
-	if (!empty($ignore))
403
-		redirectexit('action=profile;u=' . $_POST['u']);
420
+	if (!empty($ignore)) {
421
+			redirectexit('action=profile;u=' . $_POST['u']);
422
+	}
404 423
 
405 424
 	// Already reported? My god, we could be dealing with a real rogue here...
406
-	if (!empty($id_report))
407
-		$smcFunc['db_query']('', '
425
+	if (!empty($id_report)) {
426
+			$smcFunc['db_query']('', '
408 427
 			UPDATE {db_prefix}log_reported
409 428
 			SET num_reports = num_reports + 1, time_updated = {int:current_time}
410 429
 			WHERE id_report = {int:id_report}',
@@ -413,6 +432,7 @@  discard block
 block discarded – undo
413 432
 				'id_report' => $id_report,
414 433
 			)
415 434
 		);
435
+	}
416 436
 	// Otherwise, we shall make one!
417 437
 	else
418 438
 	{
Please login to merge, or discard this patch.
Sources/Subs-Package.php 1 patch
Braces   +853 added lines, -669 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
  * @version 2.1 Beta 3
17 17
  */
18 18
 
19
-if (!defined('SMF'))
19
+if (!defined('SMF')) {
20 20
 	die('No direct access...');
21
+}
21 22
 
22 23
 /**
23 24
  * Reads a .tar.gz file, filename, in and extracts file(s) from it.
@@ -67,47 +68,53 @@  discard block
 block discarded – undo
67 68
 	loadLanguage('Packages');
68 69
 
69 70
 	// This function sorta needs gzinflate!
70
-	if (!function_exists('gzinflate'))
71
-		fatal_lang_error('package_no_zlib', 'critical');
71
+	if (!function_exists('gzinflate')) {
72
+			fatal_lang_error('package_no_zlib', 'critical');
73
+	}
72 74
 
73 75
 	if (substr($gzfilename, 0, 7) == 'http://' || substr($gzfilename, 0, 8) == 'https://')
74 76
 	{
75 77
 		$data = fetch_web_data($gzfilename);
76 78
 
77
-		if ($data === false)
78
-			return false;
79
-	}
80
-	else
79
+		if ($data === false) {
80
+					return false;
81
+		}
82
+	} else
81 83
 	{
82 84
 		$data = @file_get_contents($gzfilename);
83 85
 
84
-		if ($data === false)
85
-			return false;
86
+		if ($data === false) {
87
+					return false;
88
+		}
86 89
 	}
87 90
 
88 91
 	umask(0);
89
-	if (!$single_file && $destination !== null && !file_exists($destination))
90
-		mktree($destination, 0777);
92
+	if (!$single_file && $destination !== null && !file_exists($destination)) {
93
+			mktree($destination, 0777);
94
+	}
91 95
 
92 96
 	// No signature?
93
-	if (strlen($data) < 2)
94
-		return false;
97
+	if (strlen($data) < 2) {
98
+			return false;
99
+	}
95 100
 
96 101
 	$id = unpack('H2a/H2b', substr($data, 0, 2));
97 102
 	if (strtolower($id['a'] . $id['b']) != '1f8b')
98 103
 	{
99 104
 		// Okay, this ain't no tar.gz, but maybe it's a zip file.
100
-		if (substr($data, 0, 2) == 'PK')
101
-			return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract);
102
-		else
103
-			return false;
105
+		if (substr($data, 0, 2) == 'PK') {
106
+					return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract);
107
+		} else {
108
+					return false;
109
+		}
104 110
 	}
105 111
 
106 112
 	$flags = unpack('Ct/Cf', substr($data, 2, 2));
107 113
 
108 114
 	// Not deflate!
109
-	if ($flags['t'] != 8)
110
-		return false;
115
+	if ($flags['t'] != 8) {
116
+			return false;
117
+	}
111 118
 	$flags = $flags['f'];
112 119
 
113 120
 	$offset = 10;
@@ -117,18 +124,21 @@  discard block
 block discarded – undo
117 124
 	// @todo Might be mussed.
118 125
 	if ($flags & 12)
119 126
 	{
120
-		while ($flags & 8 && $data{$offset++} != "\0")
121
-			continue;
122
-		while ($flags & 4 && $data{$offset++} != "\0")
123
-			continue;
127
+		while ($flags & 8 && $data{$offset++} != "\0") {
128
+					continue;
129
+		}
130
+		while ($flags & 4 && $data{$offset++} != "\0") {
131
+					continue;
132
+		}
124 133
 	}
125 134
 
126 135
 	$crc = unpack('Vcrc32/Visize', substr($data, strlen($data) - 8, 8));
127 136
 	$data = @gzinflate(substr($data, $offset, strlen($data) - 8 - $offset));
128 137
 
129 138
 	// smf_crc32 and crc32 may not return the same results, so we accept either.
130
-	if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data))
131
-		return false;
139
+	if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) {
140
+			return false;
141
+	}
132 142
 
133 143
 	$blocks = strlen($data) / 512 - 1;
134 144
 	$offset = 0;
@@ -149,83 +159,98 @@  discard block
 block discarded – undo
149 159
 
150 160
 		foreach ($current as $k => $v)
151 161
 		{
152
-			if (in_array($k, $octdec))
153
-				$current[$k] = octdec(trim($v));
154
-			else
155
-				$current[$k] = trim($v);
162
+			if (in_array($k, $octdec)) {
163
+							$current[$k] = octdec(trim($v));
164
+			} else {
165
+							$current[$k] = trim($v);
166
+			}
156 167
 		}
157 168
 
158
-		if ($current['type'] == 5 && substr($current['filename'], -1) != '/')
159
-			$current['filename'] .= '/';
169
+		if ($current['type'] == 5 && substr($current['filename'], -1) != '/') {
170
+					$current['filename'] .= '/';
171
+		}
160 172
 
161 173
 		$checksum = 256;
162
-		for ($i = 0; $i < 148; $i++)
163
-			$checksum += ord($header{$i});
164
-		for ($i = 156; $i < 512; $i++)
165
-			$checksum += ord($header{$i});
174
+		for ($i = 0; $i < 148; $i++) {
175
+					$checksum += ord($header{$i});
176
+		}
177
+		for ($i = 156; $i < 512; $i++) {
178
+					$checksum += ord($header{$i});
179
+		}
166 180
 
167
-		if ($current['checksum'] != $checksum)
168
-			break;
181
+		if ($current['checksum'] != $checksum) {
182
+					break;
183
+		}
169 184
 
170 185
 		$size = ceil($current['size'] / 512);
171 186
 		$current['data'] = substr($data, ++$offset << 9, $current['size']);
172 187
 		$offset += $size;
173 188
 
174 189
 		// Not a directory and doesn't exist already...
175
-		if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename']))
176
-			$write_this = true;
190
+		if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) {
191
+					$write_this = true;
192
+		}
177 193
 		// File exists... check if it is newer.
178
-		elseif (substr($current['filename'], -1, 1) != '/')
179
-			$write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime'];
194
+		elseif (substr($current['filename'], -1, 1) != '/') {
195
+					$write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime'];
196
+		}
180 197
 		// Folder... create.
181 198
 		elseif ($destination !== null && !$single_file)
182 199
 		{
183 200
 			// Protect from accidental parent directory writing...
184 201
 			$current['filename'] = strtr($current['filename'], array('../' => '', '/..' => ''));
185 202
 
186
-			if (!file_exists($destination . '/' . $current['filename']))
187
-				mktree($destination . '/' . $current['filename'], 0777);
203
+			if (!file_exists($destination . '/' . $current['filename'])) {
204
+							mktree($destination . '/' . $current['filename'], 0777);
205
+			}
188 206
 			$write_this = false;
207
+		} else {
208
+					$write_this = false;
189 209
 		}
190
-		else
191
-			$write_this = false;
192 210
 
193 211
 		if ($write_this && $destination !== null)
194 212
 		{
195
-			if (strpos($current['filename'], '/') !== false && !$single_file)
196
-				mktree($destination . '/' . dirname($current['filename']), 0777);
213
+			if (strpos($current['filename'], '/') !== false && !$single_file) {
214
+							mktree($destination . '/' . dirname($current['filename']), 0777);
215
+			}
197 216
 
198 217
 			// Is this the file we're looking for?
199
-			if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename'])))
200
-				return $current['data'];
218
+			if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) {
219
+							return $current['data'];
220
+			}
201 221
 			// If we're looking for another file, keep going.
202
-			elseif ($single_file)
203
-				continue;
222
+			elseif ($single_file) {
223
+							continue;
224
+			}
204 225
 			// Looking for restricted files?
205
-			elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract))
206
-				continue;
226
+			elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) {
227
+							continue;
228
+			}
207 229
 
208 230
 			package_put_contents($destination . '/' . $current['filename'], $current['data']);
209 231
 		}
210 232
 
211
-		if (substr($current['filename'], -1, 1) != '/')
212
-			$return[] = array(
233
+		if (substr($current['filename'], -1, 1) != '/') {
234
+					$return[] = array(
213 235
 				'filename' => $current['filename'],
214 236
 				'md5' => md5($current['data']),
215 237
 				'preview' => substr($current['data'], 0, 100),
216 238
 				'size' => $current['size'],
217 239
 				'skipped' => false
218 240
 			);
241
+		}
219 242
 	}
220 243
 
221
-	if ($destination !== null && !$single_file)
222
-		package_flush_cache();
244
+	if ($destination !== null && !$single_file) {
245
+			package_flush_cache();
246
+	}
223 247
 
224
-	if ($single_file)
225
-		return false;
226
-	else
227
-		return $return;
228
-}
248
+	if ($single_file) {
249
+			return false;
250
+	} else {
251
+			return $return;
252
+	}
253
+	}
229 254
 
230 255
 /**
231 256
  * Extract zip data. A functional copy of {@list read_zip_data()}.
@@ -254,65 +279,74 @@  discard block
 block discarded – undo
254 279
 			{
255 280
 				$i = $iterator->getSubPathname();
256 281
 				// If this is a file, and it doesn't exist.... happy days!
257
-				if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i))
258
-					$write_this = true;
282
+				if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) {
283
+									$write_this = true;
284
+				}
259 285
 				// If the file exists, we may not want to overwrite it.
260
-				elseif (substr($i, -1) != '/')
261
-					$write_this = $overwrite;
262
-				else
263
-					$write_this = false;
286
+				elseif (substr($i, -1) != '/') {
287
+									$write_this = $overwrite;
288
+				} else {
289
+									$write_this = false;
290
+				}
264 291
 
265 292
 				// Get the actual compressed data.
266
-				if (!$file_info->isDir())
267
-					$file_data = file_get_contents($file_info);
268
-				elseif ($destination !== null && !$single_file)
293
+				if (!$file_info->isDir()) {
294
+									$file_data = file_get_contents($file_info);
295
+				} elseif ($destination !== null && !$single_file)
269 296
 				{
270 297
 					// Folder... create.
271
-					if (!file_exists($destination . '/' . $i))
272
-						mktree($destination . '/' . $i, 0777);
298
+					if (!file_exists($destination . '/' . $i)) {
299
+											mktree($destination . '/' . $i, 0777);
300
+					}
273 301
 					$file_data = null;
302
+				} else {
303
+									$file_data = null;
274 304
 				}
275
-				else
276
-					$file_data = null;
277 305
 
278 306
 				// Okay!  We can write this file, looks good from here...
279 307
 				if ($write_this && $destination !== null)
280 308
 				{
281
-					if (!$single_file && !is_dir($destination . '/' . dirname($i)))
282
-						mktree($destination . '/' . dirname($i), 0777);
309
+					if (!$single_file && !is_dir($destination . '/' . dirname($i))) {
310
+											mktree($destination . '/' . dirname($i), 0777);
311
+					}
283 312
 
284 313
 					// If we're looking for a specific file, and this is it... ka-bam, baby.
285
-					if ($single_file && ($destination == $i || $destination == '*/' . basename($i)))
286
-						return $file_data;
314
+					if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) {
315
+											return $file_data;
316
+					}
287 317
 					// Oh?  Another file.  Fine.  You don't like this file, do you?  I know how it is.  Yeah... just go away.  No, don't apologize.  I know this file's just not *good enough* for you.
288
-					elseif ($single_file)
289
-						continue;
318
+					elseif ($single_file) {
319
+											continue;
320
+					}
290 321
 					// Don't really want this?
291
-					elseif ($files_to_extract !== null && !in_array($i, $files_to_extract))
292
-						continue;
322
+					elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) {
323
+											continue;
324
+					}
293 325
 
294 326
 					package_put_contents($destination . '/' . $i, $file_data);
295 327
 				}
296 328
 
297
-				if (substr($i, -1, 1) != '/')
298
-					$return[] = array(
329
+				if (substr($i, -1, 1) != '/') {
330
+									$return[] = array(
299 331
 						'filename' => $i,
300 332
 						'md5' => md5($file_data),
301 333
 						'preview' => substr($file_data, 0, 100),
302 334
 						'size' => strlen($file_data),
303 335
 						'skipped' => false
304 336
 					);
337
+				}
305 338
 			}
306 339
 
307
-		if ($destination !== null && !$single_file)
308
-			package_flush_cache();
340
+		if ($destination !== null && !$single_file) {
341
+					package_flush_cache();
342
+		}
309 343
 
310
-		if ($single_file)
311
-			return false;
312
-		else
313
-			return $return;
314
-	}
315
-	catch (Exception $e)
344
+		if ($single_file) {
345
+					return false;
346
+		} else {
347
+					return $return;
348
+		}
349
+	} catch (Exception $e)
316 350
 	{
317 351
 		return false;
318 352
 	}
@@ -334,13 +368,15 @@  discard block
 block discarded – undo
334 368
 function read_zip_data($data, $destination, $single_file = false, $overwrite = false, $files_to_extract = null)
335 369
 {
336 370
 	umask(0);
337
-	if ($destination !== null && !file_exists($destination) && !$single_file)
338
-		mktree($destination, 0777);
371
+	if ($destination !== null && !file_exists($destination) && !$single_file) {
372
+			mktree($destination, 0777);
373
+	}
339 374
 
340 375
 	// Look for the end of directory signature 0x06054b50
341 376
 	$data_ecr = explode("\x50\x4b\x05\x06", $data);
342
-	if (!isset($data_ecr[1]))
343
-		return false;
377
+	if (!isset($data_ecr[1])) {
378
+			return false;
379
+	}
344 380
 
345 381
 	$return = array();
346 382
 
@@ -355,8 +391,9 @@  discard block
 block discarded – undo
355 391
 	array_shift($file_sections);
356 392
 
357 393
 	// sections and count from the signature must match or the zip file is bad
358
-	if (count($file_sections) != $zip_info['files'])
359
-		return false;
394
+	if (count($file_sections) != $zip_info['files']) {
395
+			return false;
396
+	}
360 397
 
361 398
 	// go though each file in the archive
362 399
 	foreach ($file_sections as $data)
@@ -378,68 +415,79 @@  discard block
 block discarded – undo
378 415
 		}
379 416
 
380 417
 		// If this is a file, and it doesn't exist.... happy days!
381
-		if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename']))
382
-			$write_this = true;
418
+		if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) {
419
+					$write_this = true;
420
+		}
383 421
 		// If the file exists, we may not want to overwrite it.
384
-		elseif (substr($file_info['filename'], -1) != '/')
385
-			$write_this = $overwrite;
422
+		elseif (substr($file_info['filename'], -1) != '/') {
423
+					$write_this = $overwrite;
424
+		}
386 425
 		// This is a directory, so we're gonna want to create it. (probably...)
387 426
 		elseif ($destination !== null && !$single_file)
388 427
 		{
389 428
 			// Just a little accident prevention, don't mind me.
390 429
 			$file_info['filename'] = strtr($file_info['filename'], array('../' => '', '/..' => ''));
391 430
 
392
-			if (!file_exists($destination . '/' . $file_info['filename']))
393
-				mktree($destination . '/' . $file_info['filename'], 0777);
431
+			if (!file_exists($destination . '/' . $file_info['filename'])) {
432
+							mktree($destination . '/' . $file_info['filename'], 0777);
433
+			}
394 434
 			$write_this = false;
435
+		} else {
436
+					$write_this = false;
395 437
 		}
396
-		else
397
-			$write_this = false;
398 438
 
399 439
 		// Get the actual compressed data.
400 440
 		$file_info['data'] = substr($data, 26 + $file_info['filename_length'] + $file_info['extrafield_length']);
401 441
 
402 442
 		// Only inflate it if we need to ;)
403
-		if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size']))
404
-			$file_info['data'] = gzinflate($file_info['data']);
443
+		if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) {
444
+					$file_info['data'] = gzinflate($file_info['data']);
445
+		}
405 446
 
406 447
 		// Okay!  We can write this file, looks good from here...
407 448
 		if ($write_this && $destination !== null)
408 449
 		{
409
-			if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir'])))
410
-				mktree($file_info['dir'], 0777);
450
+			if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) {
451
+							mktree($file_info['dir'], 0777);
452
+			}
411 453
 
412 454
 			// If we're looking for a specific file, and this is it... ka-bam, baby.
413
-			if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename'])))
414
-				return $file_info['data'];
455
+			if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) {
456
+							return $file_info['data'];
457
+			}
415 458
 			// Oh?  Another file.  Fine.  You don't like this file, do you?  I know how it is.  Yeah... just go away.  No, don't apologize.  I know this file's just not *good enough* for you.
416
-			elseif ($single_file)
417
-				continue;
459
+			elseif ($single_file) {
460
+							continue;
461
+			}
418 462
 			// Don't really want this?
419
-			elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract))
420
-				continue;
463
+			elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) {
464
+							continue;
465
+			}
421 466
 
422 467
 			package_put_contents($destination . '/' . $file_info['filename'], $file_info['data']);
423 468
 		}
424 469
 
425
-		if (substr($file_info['filename'], -1, 1) != '/')
426
-			$return[] = array(
470
+		if (substr($file_info['filename'], -1, 1) != '/') {
471
+					$return[] = array(
427 472
 				'filename' => $file_info['filename'],
428 473
 				'md5' => md5($file_info['data']),
429 474
 				'preview' => substr($file_info['data'], 0, 100),
430 475
 				'size' => $file_info['size'],
431 476
 				'skipped' => false
432 477
 			);
478
+		}
433 479
 	}
434 480
 
435
-	if ($destination !== null && !$single_file)
436
-		package_flush_cache();
481
+	if ($destination !== null && !$single_file) {
482
+			package_flush_cache();
483
+	}
437 484
 
438
-	if ($single_file)
439
-		return false;
440
-	else
441
-		return $return;
442
-}
485
+	if ($single_file) {
486
+			return false;
487
+	} else {
488
+			return $return;
489
+	}
490
+	}
443 491
 
444 492
 /**
445 493
  * Checks the existence of a remote file since file_exists() does not do remote.
@@ -451,14 +499,16 @@  discard block
 block discarded – undo
451 499
 {
452 500
 	$a_url = parse_url($url);
453 501
 
454
-	if (!isset($a_url['scheme']))
455
-		return false;
502
+	if (!isset($a_url['scheme'])) {
503
+			return false;
504
+	}
456 505
 
457 506
 	// Attempt to connect...
458 507
 	$temp = '';
459 508
 	$fid = fsockopen($a_url['host'], !isset($a_url['port']) ? 80 : $a_url['port'], $temp, $temp, 8);
460
-	if (!$fid)
461
-		return false;
509
+	if (!$fid) {
510
+			return false;
511
+	}
462 512
 
463 513
 	fputs($fid, 'HEAD ' . $a_url['path'] . ' HTTP/1.0' . "\r\n" . 'Host: ' . $a_url['host'] . "\r\n\r\n");
464 514
 	$head = fread($fid, 1024);
@@ -493,8 +543,9 @@  discard block
 block discarded – undo
493 543
 	while ($row = $smcFunc['db_fetch_assoc']($request))
494 544
 	{
495 545
 		// Already found this? If so don't add it twice!
496
-		if (in_array($row['package_id'], $found))
497
-			continue;
546
+		if (in_array($row['package_id'], $found)) {
547
+					continue;
548
+		}
498 549
 
499 550
 		$found[] = $row['package_id'];
500 551
 
@@ -529,19 +580,21 @@  discard block
 block discarded – undo
529 580
 	global $sourcedir, $packagesdir, $smcFunc;
530 581
 
531 582
 	// Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.)
532
-	if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false)
533
-		$packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true);
534
-	else
583
+	if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) {
584
+			$packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true);
585
+	} else
535 586
 	{
536
-		if (!file_exists($packagesdir . '/' . $gzfilename))
537
-			return 'package_get_error_not_found';
587
+		if (!file_exists($packagesdir . '/' . $gzfilename)) {
588
+					return 'package_get_error_not_found';
589
+		}
538 590
 
539
-		if (is_file($packagesdir . '/' . $gzfilename))
540
-			$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true);
541
-		elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml'))
542
-			$packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml');
543
-		else
544
-			return 'package_get_error_missing_xml';
591
+		if (is_file($packagesdir . '/' . $gzfilename)) {
592
+					$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true);
593
+		} elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) {
594
+					$packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml');
595
+		} else {
596
+					return 'package_get_error_missing_xml';
597
+		}
545 598
 	}
546 599
 
547 600
 	// Nothing?
@@ -549,10 +602,11 @@  discard block
 block discarded – undo
549 602
 	{
550 603
 		// Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function
551 604
 		$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/theme_info.xml', true);
552
-		if (!empty($packageInfo))
553
-			return 'package_get_error_is_theme';
554
-		else
555
-			return 'package_get_error_is_zero';
605
+		if (!empty($packageInfo)) {
606
+					return 'package_get_error_is_theme';
607
+		} else {
608
+					return 'package_get_error_is_zero';
609
+		}
556 610
 	}
557 611
 
558 612
 	// Parse package-info.xml into an xmlArray.
@@ -560,8 +614,9 @@  discard block
 block discarded – undo
560 614
 	$packageInfo = new xmlArray($packageInfo);
561 615
 
562 616
 	// @todo Error message of some sort?
563
-	if (!$packageInfo->exists('package-info[0]'))
564
-		return 'package_get_error_packageinfo_corrupt';
617
+	if (!$packageInfo->exists('package-info[0]')) {
618
+			return 'package_get_error_packageinfo_corrupt';
619
+	}
565 620
 
566 621
 	$packageInfo = $packageInfo->path('package-info[0]');
567 622
 
@@ -580,8 +635,9 @@  discard block
 block discarded – undo
580 635
 		}
581 636
 	}
582 637
 
583
-	if (!isset($package['type']))
584
-		$package['type'] = 'modification';
638
+	if (!isset($package['type'])) {
639
+			$package['type'] = 'modification';
640
+	}
585 641
 
586 642
 	return $package;
587 643
 }
@@ -634,15 +690,14 @@  discard block
 block discarded – undo
634 690
 					{
635 691
 						$ftp_file = strtr($file, array($_SESSION['pack_ftp']['root'] => ''));
636 692
 						$package_ftp->chmod($ftp_file, $perms);
693
+					} else {
694
+											smf_chmod($file, $perms);
637 695
 					}
638
-					else
639
-						smf_chmod($file, $perms);
640 696
 
641 697
 					$new_permissions = @fileperms($file);
642 698
 					$result = $new_permissions == $perms ? 'success' : 'failure';
643 699
 					unset($_SESSION['pack_ftp']['original_perms'][$file]);
644
-				}
645
-				elseif ($do_change)
700
+				} elseif ($do_change)
646 701
 				{
647 702
 					$new_permissions = '';
648 703
 					$result = 'skipped';
@@ -758,8 +813,7 @@  discard block
 block discarded – undo
758 813
 
759 814
 			$context['sub_template'] = 'show_list';
760 815
 			$context['default_list'] = 'restore_file_permissions';
761
-		}
762
-		else
816
+		} else
763 817
 		{
764 818
 			unset($listOptions['columns']['result']);
765 819
 		}
@@ -769,12 +823,14 @@  discard block
 block discarded – undo
769 823
 		createList($listOptions);
770 824
 
771 825
 		// If we just restored permissions then whereever we are, we are now done and dusted.
772
-		if (!empty($_POST['restore_perms']))
773
-			obExit();
826
+		if (!empty($_POST['restore_perms'])) {
827
+					obExit();
828
+		}
774 829
 	}
775 830
 	// Otherwise, it's entirely irrelevant?
776
-	elseif ($restore_write_status)
777
-		return true;
831
+	elseif ($restore_write_status) {
832
+			return true;
833
+	}
778 834
 
779 835
 	// This is where we report what we got up to.
780 836
 	$return_data = array(
@@ -812,11 +868,12 @@  discard block
 block discarded – undo
812 868
 			if (!in_array($_POST['ftp_path'], array('', '/')))
813 869
 			{
814 870
 				$ftp_root = strtr($boarddir, array($_POST['ftp_path'] => ''));
815
-				if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/'))
816
-					$ftp_root = substr($ftp_root, 0, -1);
871
+				if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) {
872
+									$ftp_root = substr($ftp_root, 0, -1);
873
+				}
874
+			} else {
875
+							$ftp_root = $boarddir;
817 876
 			}
818
-			else
819
-				$ftp_root = $boarddir;
820 877
 
821 878
 			$_SESSION['pack_ftp'] = array(
822 879
 				'server' => $_POST['ftp_server'],
@@ -828,8 +885,9 @@  discard block
 block discarded – undo
828 885
 				'connected' => true,
829 886
 			);
830 887
 
831
-			if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path'])
832
-				updateSettings(array('package_path' => $_POST['ftp_path']));
888
+			if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) {
889
+							updateSettings(array('package_path' => $_POST['ftp_path']));
890
+			}
833 891
 
834 892
 			// This is now the primary connection.
835 893
 			$package_ftp = $ftp;
@@ -842,12 +900,13 @@  discard block
 block discarded – undo
842 900
 		foreach ($chmodFiles as $k => $file)
843 901
 		{
844 902
 			// Sometimes this can somehow happen maybe?
845
-			if (empty($file))
846
-				unset($chmodFiles[$k]);
903
+			if (empty($file)) {
904
+							unset($chmodFiles[$k]);
905
+			}
847 906
 			// Already writable?
848
-			elseif (@is_writable($file))
849
-				$return_data['files']['writable'][] = $file;
850
-			else
907
+			elseif (@is_writable($file)) {
908
+							$return_data['files']['writable'][] = $file;
909
+			} else
851 910
 			{
852 911
 				// Now try to change that.
853 912
 				$return_data['files'][package_chmod($file, 'writable', true) ? 'writable' : 'notwritable'][] = $file;
@@ -864,19 +923,21 @@  discard block
 block discarded – undo
864 923
 			{
865 924
 				require_once($sourcedir . '/Class-Package.php');
866 925
 				$ftp = new ftp_connection(null);
926
+			} elseif ($ftp->error !== false && !isset($ftp_error)) {
927
+							$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
867 928
 			}
868
-			elseif ($ftp->error !== false && !isset($ftp_error))
869
-				$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
870 929
 
871 930
 			list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
872 931
 
873
-			if ($found_path)
874
-				$_POST['ftp_path'] = $detect_path;
875
-			elseif (!isset($_POST['ftp_path']))
876
-				$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
932
+			if ($found_path) {
933
+							$_POST['ftp_path'] = $detect_path;
934
+			} elseif (!isset($_POST['ftp_path'])) {
935
+							$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
936
+			}
877 937
 
878
-			if (!isset($_POST['ftp_username']))
879
-				$_POST['ftp_username'] = $username;
938
+			if (!isset($_POST['ftp_username'])) {
939
+							$_POST['ftp_username'] = $username;
940
+			}
880 941
 		}
881 942
 
882 943
 		$context['package_ftp'] = array(
@@ -889,8 +950,9 @@  discard block
 block discarded – undo
889 950
 		);
890 951
 
891 952
 		// Which files failed?
892
-		if (!isset($context['notwritable_files']))
893
-			$context['notwritable_files'] = array();
953
+		if (!isset($context['notwritable_files'])) {
954
+					$context['notwritable_files'] = array();
955
+		}
894 956
 		$context['notwritable_files'] = array_merge($context['notwritable_files'], $return_data['files']['notwritable']);
895 957
 
896 958
 		// Sent here to die?
@@ -923,40 +985,48 @@  discard block
 block discarded – undo
923 985
 		foreach ($files as $k => $file)
924 986
 		{
925 987
 			// If this file doesn't exist, then we actually want to look at the directory, no?
926
-			if (!file_exists($file))
927
-				$file = dirname($file);
988
+			if (!file_exists($file)) {
989
+							$file = dirname($file);
990
+			}
928 991
 
929 992
 			// This looks odd, but it's an attempt to work around PHP suExec.
930
-			if (!@is_writable($file))
931
-				smf_chmod($file, 0755);
932
-			if (!@is_writable($file))
933
-				smf_chmod($file, 0777);
934
-			if (!@is_writable(dirname($file)))
935
-				smf_chmod($file, 0755);
936
-			if (!@is_writable(dirname($file)))
937
-				smf_chmod($file, 0777);
993
+			if (!@is_writable($file)) {
994
+							smf_chmod($file, 0755);
995
+			}
996
+			if (!@is_writable($file)) {
997
+							smf_chmod($file, 0777);
998
+			}
999
+			if (!@is_writable(dirname($file))) {
1000
+							smf_chmod($file, 0755);
1001
+			}
1002
+			if (!@is_writable(dirname($file))) {
1003
+							smf_chmod($file, 0777);
1004
+			}
938 1005
 
939 1006
 			$fp = is_dir($file) ? @opendir($file) : @fopen($file, 'rb');
940 1007
 			if (@is_writable($file) && $fp)
941 1008
 			{
942 1009
 				unset($files[$k]);
943
-				if (!is_dir($file))
944
-					fclose($fp);
945
-				else
946
-					closedir($fp);
1010
+				if (!is_dir($file)) {
1011
+									fclose($fp);
1012
+				} else {
1013
+									closedir($fp);
1014
+				}
947 1015
 			}
948 1016
 		}
949 1017
 
950 1018
 		// No FTP required!
951
-		if (empty($files))
952
-			return array();
1019
+		if (empty($files)) {
1020
+					return array();
1021
+		}
953 1022
 	}
954 1023
 
955 1024
 	// They've opted to not use FTP, and try anyway.
956 1025
 	if (isset($_SESSION['pack_ftp']) && $_SESSION['pack_ftp'] == false)
957 1026
 	{
958
-		if ($files === null)
959
-			return array();
1027
+		if ($files === null) {
1028
+					return array();
1029
+		}
960 1030
 
961 1031
 		foreach ($files as $k => $file)
962 1032
 		{
@@ -968,26 +1038,29 @@  discard block
 block discarded – undo
968 1038
 				smf_chmod($file, 0755);
969 1039
 			}
970 1040
 
971
-			if (!@is_writable($file))
972
-				smf_chmod($file, 0777);
973
-			if (!@is_writable(dirname($file)))
974
-				smf_chmod(dirname($file), 0777);
1041
+			if (!@is_writable($file)) {
1042
+							smf_chmod($file, 0777);
1043
+			}
1044
+			if (!@is_writable(dirname($file))) {
1045
+							smf_chmod(dirname($file), 0777);
1046
+			}
975 1047
 
976
-			if (@is_writable($file))
977
-				unset($files[$k]);
1048
+			if (@is_writable($file)) {
1049
+							unset($files[$k]);
1050
+			}
978 1051
 		}
979 1052
 
980 1053
 		return $files;
981
-	}
982
-	elseif (isset($_SESSION['pack_ftp']))
1054
+	} elseif (isset($_SESSION['pack_ftp']))
983 1055
 	{
984 1056
 		// Load the file containing the ftp_connection class.
985 1057
 		require_once($sourcedir . '/Class-Package.php');
986 1058
 
987 1059
 		$package_ftp = new ftp_connection($_SESSION['pack_ftp']['server'], $_SESSION['pack_ftp']['port'], $_SESSION['pack_ftp']['username'], package_crypt($_SESSION['pack_ftp']['password']));
988 1060
 
989
-		if ($files === null)
990
-			return array();
1061
+		if ($files === null) {
1062
+					return array();
1063
+		}
991 1064
 
992 1065
 		foreach ($files as $k => $file)
993 1066
 		{
@@ -1001,13 +1074,16 @@  discard block
 block discarded – undo
1001 1074
 				$package_ftp->chmod($ftp_file, 0755);
1002 1075
 			}
1003 1076
 
1004
-			if (!@is_writable($file))
1005
-				$package_ftp->chmod($ftp_file, 0777);
1006
-			if (!@is_writable(dirname($file)))
1007
-				$package_ftp->chmod(dirname($ftp_file), 0777);
1077
+			if (!@is_writable($file)) {
1078
+							$package_ftp->chmod($ftp_file, 0777);
1079
+			}
1080
+			if (!@is_writable(dirname($file))) {
1081
+							$package_ftp->chmod(dirname($ftp_file), 0777);
1082
+			}
1008 1083
 
1009
-			if (@is_writable($file))
1010
-				unset($files[$k]);
1084
+			if (@is_writable($file)) {
1085
+							unset($files[$k]);
1086
+			}
1011 1087
 		}
1012 1088
 
1013 1089
 		return $files;
@@ -1019,8 +1095,7 @@  discard block
 block discarded – undo
1019 1095
 
1020 1096
 		$files = packageRequireFTP($destination_url, $files, $return);
1021 1097
 		return $files;
1022
-	}
1023
-	elseif (isset($_POST['ftp_username']))
1098
+	} elseif (isset($_POST['ftp_username']))
1024 1099
 	{
1025 1100
 		require_once($sourcedir . '/Class-Package.php');
1026 1101
 		$ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
@@ -1042,19 +1117,21 @@  discard block
 block discarded – undo
1042 1117
 		{
1043 1118
 			require_once($sourcedir . '/Class-Package.php');
1044 1119
 			$ftp = new ftp_connection(null);
1120
+		} elseif ($ftp->error !== false && !isset($ftp_error)) {
1121
+					$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
1045 1122
 		}
1046
-		elseif ($ftp->error !== false && !isset($ftp_error))
1047
-			$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
1048 1123
 
1049 1124
 		list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
1050 1125
 
1051
-		if ($found_path)
1052
-			$_POST['ftp_path'] = $detect_path;
1053
-		elseif (!isset($_POST['ftp_path']))
1054
-			$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
1126
+		if ($found_path) {
1127
+					$_POST['ftp_path'] = $detect_path;
1128
+		} elseif (!isset($_POST['ftp_path'])) {
1129
+					$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
1130
+		}
1055 1131
 
1056
-		if (!isset($_POST['ftp_username']))
1057
-			$_POST['ftp_username'] = $username;
1132
+		if (!isset($_POST['ftp_username'])) {
1133
+					$_POST['ftp_username'] = $username;
1134
+		}
1058 1135
 
1059 1136
 		$context['package_ftp'] = array(
1060 1137
 			'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'),
@@ -1066,23 +1143,24 @@  discard block
 block discarded – undo
1066 1143
 		);
1067 1144
 
1068 1145
 		// If we're returning dump out here.
1069
-		if ($return)
1070
-			return $files;
1146
+		if ($return) {
1147
+					return $files;
1148
+		}
1071 1149
 
1072 1150
 		$context['page_title'] = $txt['package_ftp_necessary'];
1073 1151
 		$context['sub_template'] = 'ftp_required';
1074 1152
 		obExit();
1075
-	}
1076
-	else
1153
+	} else
1077 1154
 	{
1078 1155
 		if (!in_array($_POST['ftp_path'], array('', '/')))
1079 1156
 		{
1080 1157
 			$ftp_root = strtr($boarddir, array($_POST['ftp_path'] => ''));
1081
-			if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/'))
1082
-				$ftp_root = substr($ftp_root, 0, -1);
1158
+			if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) {
1159
+							$ftp_root = substr($ftp_root, 0, -1);
1160
+			}
1161
+		} else {
1162
+					$ftp_root = $boarddir;
1083 1163
 		}
1084
-		else
1085
-			$ftp_root = $boarddir;
1086 1164
 
1087 1165
 		$_SESSION['pack_ftp'] = array(
1088 1166
 			'server' => $_POST['ftp_server'],
@@ -1093,8 +1171,9 @@  discard block
 block discarded – undo
1093 1171
 			'root' => $ftp_root,
1094 1172
 		);
1095 1173
 
1096
-		if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path'])
1097
-			updateSettings(array('package_path' => $_POST['ftp_path']));
1174
+		if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) {
1175
+					updateSettings(array('package_path' => $_POST['ftp_path']));
1176
+		}
1098 1177
 
1099 1178
 		$files = packageRequireFTP($destination_url, $files, $return);
1100 1179
 	}
@@ -1122,16 +1201,18 @@  discard block
 block discarded – undo
1122 1201
 	global $packagesdir, $forum_version, $context, $temp_path, $language, $smcFunc;
1123 1202
 
1124 1203
 	// Mayday!  That action doesn't exist!!
1125
-	if (empty($packageXML) || !$packageXML->exists($method))
1126
-		return array();
1204
+	if (empty($packageXML) || !$packageXML->exists($method)) {
1205
+			return array();
1206
+	}
1127 1207
 
1128 1208
 	// We haven't found the package script yet...
1129 1209
 	$script = false;
1130 1210
 	$the_version = strtr($forum_version, array('SMF ' => ''));
1131 1211
 
1132 1212
 	// Emulation support...
1133
-	if (!empty($_SESSION['version_emulate']))
1134
-		$the_version = $_SESSION['version_emulate'];
1213
+	if (!empty($_SESSION['version_emulate'])) {
1214
+			$the_version = $_SESSION['version_emulate'];
1215
+	}
1135 1216
 
1136 1217
 	// Single package emulation
1137 1218
 	if (!empty($_REQUEST['ve']) && !empty($_REQUEST['package']))
@@ -1139,8 +1220,9 @@  discard block
 block discarded – undo
1139 1220
 		$the_version = $_REQUEST['ve'];
1140 1221
 		$_SESSION['single_version_emulate'][$_REQUEST['package']] = $the_version;
1141 1222
 	}
1142
-	if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']])))
1143
-		$the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']];
1223
+	if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) {
1224
+			$the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']];
1225
+	}
1144 1226
 
1145 1227
 	// Get all the versions of this method and find the right one.
1146 1228
 	$these_methods = $packageXML->set($method);
@@ -1150,16 +1232,18 @@  discard block
 block discarded – undo
1150 1232
 		if ($this_method->exists('@for'))
1151 1233
 		{
1152 1234
 			// Don't keep going if this won't work for this version of SMF.
1153
-			if (!matchPackageVersion($the_version, $this_method->fetch('@for')))
1154
-				continue;
1235
+			if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) {
1236
+							continue;
1237
+			}
1155 1238
 		}
1156 1239
 
1157 1240
 		// Upgrades may go from a certain old version of the mod.
1158 1241
 		if ($method == 'upgrade' && $this_method->exists('@from'))
1159 1242
 		{
1160 1243
 			// Well, this is for the wrong old version...
1161
-			if (!matchPackageVersion($previous_version, $this_method->fetch('@from')))
1162
-				continue;
1244
+			if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) {
1245
+							continue;
1246
+			}
1163 1247
 		}
1164 1248
 
1165 1249
 		// We've found it!
@@ -1168,8 +1252,9 @@  discard block
 block discarded – undo
1168 1252
 	}
1169 1253
 
1170 1254
 	// Bad news, a matching script wasn't found!
1171
-	if ($script === false)
1172
-		return array();
1255
+	if ($script === false) {
1256
+			return array();
1257
+	}
1173 1258
 
1174 1259
 	// Find all the actions in this method - in theory, these should only be allowed actions. (* means all.)
1175 1260
 	$actions = $script->set('*');
@@ -1198,12 +1283,12 @@  discard block
 block discarded – undo
1198 1283
 					if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language)	|| (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language))
1199 1284
 					{
1200 1285
 						// In case the user put the blocks in the wrong order.
1201
-						if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default')
1202
-							$context[$type][] = 'default';
1286
+						if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') {
1287
+													$context[$type][] = 'default';
1288
+						}
1203 1289
 
1204 1290
 						$context[$type]['selected'] = $smcFunc['htmlspecialchars']($action->fetch('@lang'));
1205
-					}
1206
-					else
1291
+					} else
1207 1292
 					{
1208 1293
 						// We don't want this now, but we'll allow the user to select to read it.
1209 1294
 						$context[$type][] = $smcFunc['htmlspecialchars']($action->fetch('@lang'));
@@ -1218,9 +1303,9 @@  discard block
 block discarded – undo
1218 1303
 					{
1219 1304
 						$context[$type][] = 'default';
1220 1305
 						continue;
1306
+					} else {
1307
+											$context[$type]['selected'] = 'default';
1221 1308
 					}
1222
-					else
1223
-						$context[$type]['selected'] = 'default';
1224 1309
 				}
1225 1310
 			}
1226 1311
 
@@ -1230,9 +1315,9 @@  discard block
 block discarded – undo
1230 1315
 				$filename = $temp_path . '$auto_' . $temp_auto++ . (in_array($actionType, array('readme', 'redirect', 'license')) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod'));
1231 1316
 				package_put_contents($filename, $action->fetch('.'));
1232 1317
 				$filename = strtr($filename, array($temp_path => ''));
1318
+			} else {
1319
+							$filename = $action->fetch('.');
1233 1320
 			}
1234
-			else
1235
-				$filename = $action->fetch('.');
1236 1321
 
1237 1322
 			$return[] = array(
1238 1323
 				'type' => $actionType,
@@ -1247,8 +1332,7 @@  discard block
 block discarded – undo
1247 1332
 			);
1248 1333
 
1249 1334
 			continue;
1250
-		}
1251
-		elseif ($actionType == 'hook')
1335
+		} elseif ($actionType == 'hook')
1252 1336
 		{
1253 1337
 			$return[] = array(
1254 1338
 				'type' => $actionType,
@@ -1260,16 +1344,16 @@  discard block
 block discarded – undo
1260 1344
 				'description' => '',
1261 1345
 			);
1262 1346
 			continue;
1263
-		}
1264
-		elseif ($actionType == 'credits')
1347
+		} elseif ($actionType == 'credits')
1265 1348
 		{
1266 1349
 			// quick check of any supplied url
1267 1350
 			$url = $action->exists('@url') ? $action->fetch('@url') : '';
1268 1351
 			if (strlen(trim($url)) > 0 && substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')
1269 1352
 			{
1270 1353
 				$url = 'http://' . $url;
1271
-				if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://'))
1272
-					$url = '';
1354
+				if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) {
1355
+									$url = '';
1356
+				}
1273 1357
 			}
1274 1358
 
1275 1359
 			$return[] = array(
@@ -1281,8 +1365,7 @@  discard block
 block discarded – undo
1281 1365
 				'title' => $action->fetch('.'),
1282 1366
 			);
1283 1367
 			continue;
1284
-		}
1285
-		elseif ($actionType == 'requires')
1368
+		} elseif ($actionType == 'requires')
1286 1369
 		{
1287 1370
 			$return[] = array(
1288 1371
 				'type' => $actionType,
@@ -1291,14 +1374,12 @@  discard block
 block discarded – undo
1291 1374
 				'description' => '',
1292 1375
 			);
1293 1376
 			continue;
1294
-		}
1295
-		elseif ($actionType == 'error')
1377
+		} elseif ($actionType == 'error')
1296 1378
 		{
1297 1379
 			$return[] = array(
1298 1380
 				'type' => 'error',
1299 1381
 			);
1300
-		}
1301
-		elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir')))
1382
+		} elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir')))
1302 1383
 		{
1303 1384
 			$this_action = &$return[];
1304 1385
 			$this_action = array(
@@ -1312,8 +1393,7 @@  discard block
 block discarded – undo
1312 1393
 			{
1313 1394
 				$this_action['unparsed_destination'] = $action->fetch('@destination');
1314 1395
 				$this_action['destination'] = parse_path($action->fetch('@destination')) . '/' . basename($this_action['filename']);
1315
-			}
1316
-			else
1396
+			} else
1317 1397
 			{
1318 1398
 				$this_action['unparsed_filename'] = $this_action['filename'];
1319 1399
 				$this_action['filename'] = parse_path($this_action['filename']);
@@ -1322,10 +1402,11 @@  discard block
 block discarded – undo
1322 1402
 			// If we're moving or requiring (copying) a file.
1323 1403
 			if (substr($actionType, 0, 4) == 'move' || substr($actionType, 0, 7) == 'require')
1324 1404
 			{
1325
-				if ($action->exists('@from'))
1326
-					$this_action['source'] = parse_path($action->fetch('@from'));
1327
-				else
1328
-					$this_action['source'] = $temp_path . $this_action['filename'];
1405
+				if ($action->exists('@from')) {
1406
+									$this_action['source'] = parse_path($action->fetch('@from'));
1407
+				} else {
1408
+									$this_action['source'] = $temp_path . $this_action['filename'];
1409
+				}
1329 1410
 			}
1330 1411
 
1331 1412
 			// Check if these things can be done. (chmod's etc.)
@@ -1334,22 +1415,23 @@  discard block
 block discarded – undo
1334 1415
 				if (!mktree($this_action['destination'], false))
1335 1416
 				{
1336 1417
 					$temp = $this_action['destination'];
1337
-					while (!file_exists($temp) && strlen($temp) > 1)
1338
-						$temp = dirname($temp);
1418
+					while (!file_exists($temp) && strlen($temp) > 1) {
1419
+											$temp = dirname($temp);
1420
+					}
1339 1421
 
1340 1422
 					$return[] = array(
1341 1423
 						'type' => 'chmod',
1342 1424
 						'filename' => $temp
1343 1425
 					);
1344 1426
 				}
1345
-			}
1346
-			elseif ($actionType == 'create-file')
1427
+			} elseif ($actionType == 'create-file')
1347 1428
 			{
1348 1429
 				if (!mktree(dirname($this_action['destination']), false))
1349 1430
 				{
1350 1431
 					$temp = dirname($this_action['destination']);
1351
-					while (!file_exists($temp) && strlen($temp) > 1)
1352
-						$temp = dirname($temp);
1432
+					while (!file_exists($temp) && strlen($temp) > 1) {
1433
+											$temp = dirname($temp);
1434
+					}
1353 1435
 
1354 1436
 					$return[] = array(
1355 1437
 						'type' => 'chmod',
@@ -1357,36 +1439,38 @@  discard block
 block discarded – undo
1357 1439
 					);
1358 1440
 				}
1359 1441
 
1360
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1361
-					$return[] = array(
1442
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1443
+									$return[] = array(
1362 1444
 						'type' => 'chmod',
1363 1445
 						'filename' => $this_action['destination']
1364 1446
 					);
1365
-			}
1366
-			elseif ($actionType == 'require-dir')
1447
+				}
1448
+			} elseif ($actionType == 'require-dir')
1367 1449
 			{
1368 1450
 				if (!mktree($this_action['destination'], false))
1369 1451
 				{
1370 1452
 					$temp = $this_action['destination'];
1371
-					while (!file_exists($temp) && strlen($temp) > 1)
1372
-						$temp = dirname($temp);
1453
+					while (!file_exists($temp) && strlen($temp) > 1) {
1454
+											$temp = dirname($temp);
1455
+					}
1373 1456
 
1374 1457
 					$return[] = array(
1375 1458
 						'type' => 'chmod',
1376 1459
 						'filename' => $temp
1377 1460
 					);
1378 1461
 				}
1379
-			}
1380
-			elseif ($actionType == 'require-file')
1462
+			} elseif ($actionType == 'require-file')
1381 1463
 			{
1382
-				if ($action->exists('@theme'))
1383
-					$this_action['theme_action'] = $action->fetch('@theme');
1464
+				if ($action->exists('@theme')) {
1465
+									$this_action['theme_action'] = $action->fetch('@theme');
1466
+				}
1384 1467
 
1385 1468
 				if (!mktree(dirname($this_action['destination']), false))
1386 1469
 				{
1387 1470
 					$temp = dirname($this_action['destination']);
1388
-					while (!file_exists($temp) && strlen($temp) > 1)
1389
-						$temp = dirname($temp);
1471
+					while (!file_exists($temp) && strlen($temp) > 1) {
1472
+											$temp = dirname($temp);
1473
+					}
1390 1474
 
1391 1475
 					$return[] = array(
1392 1476
 						'type' => 'chmod',
@@ -1394,19 +1478,20 @@  discard block
 block discarded – undo
1394 1478
 					);
1395 1479
 				}
1396 1480
 
1397
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1398
-					$return[] = array(
1481
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1482
+									$return[] = array(
1399 1483
 						'type' => 'chmod',
1400 1484
 						'filename' => $this_action['destination']
1401 1485
 					);
1402
-			}
1403
-			elseif ($actionType == 'move-dir' || $actionType == 'move-file')
1486
+				}
1487
+			} elseif ($actionType == 'move-dir' || $actionType == 'move-file')
1404 1488
 			{
1405 1489
 				if (!mktree(dirname($this_action['destination']), false))
1406 1490
 				{
1407 1491
 					$temp = dirname($this_action['destination']);
1408
-					while (!file_exists($temp) && strlen($temp) > 1)
1409
-						$temp = dirname($temp);
1492
+					while (!file_exists($temp) && strlen($temp) > 1) {
1493
+											$temp = dirname($temp);
1494
+					}
1410 1495
 
1411 1496
 					$return[] = array(
1412 1497
 						'type' => 'chmod',
@@ -1414,30 +1499,30 @@  discard block
 block discarded – undo
1414 1499
 					);
1415 1500
 				}
1416 1501
 
1417
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1418
-					$return[] = array(
1502
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1503
+									$return[] = array(
1419 1504
 						'type' => 'chmod',
1420 1505
 						'filename' => $this_action['destination']
1421 1506
 					);
1422
-			}
1423
-			elseif ($actionType == 'remove-dir')
1507
+				}
1508
+			} elseif ($actionType == 'remove-dir')
1424 1509
 			{
1425
-				if (!is_writable($this_action['filename']) && file_exists($this_action['filename']))
1426
-					$return[] = array(
1510
+				if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) {
1511
+									$return[] = array(
1427 1512
 						'type' => 'chmod',
1428 1513
 						'filename' => $this_action['filename']
1429 1514
 					);
1430
-			}
1431
-			elseif ($actionType == 'remove-file')
1515
+				}
1516
+			} elseif ($actionType == 'remove-file')
1432 1517
 			{
1433
-				if (!is_writable($this_action['filename']) && file_exists($this_action['filename']))
1434
-					$return[] = array(
1518
+				if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) {
1519
+									$return[] = array(
1435 1520
 						'type' => 'chmod',
1436 1521
 						'filename' => $this_action['filename']
1437 1522
 					);
1523
+				}
1438 1524
 			}
1439
-		}
1440
-		else
1525
+		} else
1441 1526
 		{
1442 1527
 			$return[] = array(
1443 1528
 				'type' => 'error',
@@ -1448,8 +1533,9 @@  discard block
 block discarded – undo
1448 1533
 	}
1449 1534
 
1450 1535
 	// Only testing - just return a list of things to be done.
1451
-	if ($testing_only)
1452
-		return $return;
1536
+	if ($testing_only) {
1537
+			return $return;
1538
+	}
1453 1539
 
1454 1540
 	umask(0);
1455 1541
 
@@ -1457,78 +1543,81 @@  discard block
 block discarded – undo
1457 1543
 	$not_done = array(array('type' => '!'));
1458 1544
 	foreach ($return as $action)
1459 1545
 	{
1460
-		if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits')))
1461
-			$not_done[] = $action;
1546
+		if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) {
1547
+					$not_done[] = $action;
1548
+		}
1462 1549
 
1463 1550
 		if ($action['type'] == 'create-dir')
1464 1551
 		{
1465
-			if (!mktree($action['destination'], 0755) || !is_writable($action['destination']))
1466
-				$failure |= !mktree($action['destination'], 0777);
1467
-		}
1468
-		elseif ($action['type'] == 'create-file')
1552
+			if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) {
1553
+							$failure |= !mktree($action['destination'], 0777);
1554
+			}
1555
+		} elseif ($action['type'] == 'create-file')
1469 1556
 		{
1470
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1471
-				$failure |= !mktree(dirname($action['destination']), 0777);
1557
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1558
+							$failure |= !mktree(dirname($action['destination']), 0777);
1559
+			}
1472 1560
 
1473 1561
 			// Create an empty file.
1474 1562
 			package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only);
1475 1563
 
1476
-			if (!file_exists($action['destination']))
1477
-				$failure = true;
1478
-		}
1479
-		elseif ($action['type'] == 'require-dir')
1564
+			if (!file_exists($action['destination'])) {
1565
+							$failure = true;
1566
+			}
1567
+		} elseif ($action['type'] == 'require-dir')
1480 1568
 		{
1481 1569
 			copytree($action['source'], $action['destination']);
1482 1570
 			// Any other theme folders?
1483
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']]))
1484
-				foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1571
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) {
1572
+							foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1485 1573
 					copytree($action['source'], $theme_destination);
1486
-		}
1487
-		elseif ($action['type'] == 'require-file')
1574
+			}
1575
+		} elseif ($action['type'] == 'require-file')
1488 1576
 		{
1489
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1490
-				$failure |= !mktree(dirname($action['destination']), 0777);
1577
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1578
+							$failure |= !mktree(dirname($action['destination']), 0777);
1579
+			}
1491 1580
 
1492 1581
 			package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only);
1493 1582
 
1494 1583
 			$failure |= !copy($action['source'], $action['destination']);
1495 1584
 
1496 1585
 			// Any other theme files?
1497
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']]))
1498
-				foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1586
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) {
1587
+							foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1499 1588
 				{
1500 1589
 					if (!mktree(dirname($theme_destination), 0755) || !is_writable(dirname($theme_destination)))
1501 1590
 						$failure |= !mktree(dirname($theme_destination), 0777);
1591
+			}
1502 1592
 
1503 1593
 					package_put_contents($theme_destination, package_get_contents($action['source']), $testing_only);
1504 1594
 
1505 1595
 					$failure |= !copy($action['source'], $theme_destination);
1506 1596
 				}
1507
-		}
1508
-		elseif ($action['type'] == 'move-file')
1597
+		} elseif ($action['type'] == 'move-file')
1509 1598
 		{
1510
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1511
-				$failure |= !mktree(dirname($action['destination']), 0777);
1599
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1600
+							$failure |= !mktree(dirname($action['destination']), 0777);
1601
+			}
1512 1602
 
1513 1603
 			$failure |= !rename($action['source'], $action['destination']);
1514
-		}
1515
-		elseif ($action['type'] == 'move-dir')
1604
+		} elseif ($action['type'] == 'move-dir')
1516 1605
 		{
1517
-			if (!mktree($action['destination'], 0755) || !is_writable($action['destination']))
1518
-				$failure |= !mktree($action['destination'], 0777);
1606
+			if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) {
1607
+							$failure |= !mktree($action['destination'], 0777);
1608
+			}
1519 1609
 
1520 1610
 			$failure |= !rename($action['source'], $action['destination']);
1521
-		}
1522
-		elseif ($action['type'] == 'remove-dir')
1611
+		} elseif ($action['type'] == 'remove-dir')
1523 1612
 		{
1524 1613
 			deltree($action['filename']);
1525 1614
 
1526 1615
 			// Any other theme folders?
1527
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']]))
1528
-				foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1616
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) {
1617
+							foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1529 1618
 					deltree($theme_destination);
1530
-		}
1531
-		elseif ($action['type'] == 'remove-file')
1619
+			}
1620
+		} elseif ($action['type'] == 'remove-file')
1532 1621
 		{
1533 1622
 			// Make sure the file exists before deleting it.
1534 1623
 			if (file_exists($action['filename']))
@@ -1537,16 +1626,18 @@  discard block
 block discarded – undo
1537 1626
 				$failure |= !unlink($action['filename']);
1538 1627
 			}
1539 1628
 			// The file that was supposed to be deleted couldn't be found.
1540
-			else
1541
-				$failure = true;
1629
+			else {
1630
+							$failure = true;
1631
+			}
1542 1632
 
1543 1633
 			// Any other theme folders?
1544
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']]))
1545
-				foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1634
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) {
1635
+							foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1546 1636
 					if (file_exists($theme_destination))
1547 1637
 						$failure |= !unlink($theme_destination);
1548
-					else
1549
-						$failure = true;
1638
+			} else {
1639
+											$failure = true;
1640
+					}
1550 1641
 		}
1551 1642
 	}
1552 1643
 
@@ -1568,8 +1659,9 @@  discard block
 block discarded – undo
1568 1659
 {
1569 1660
 	static $near_version = 0;
1570 1661
 
1571
-	if ($reset)
1572
-		$near_version = 0;
1662
+	if ($reset) {
1663
+			$near_version = 0;
1664
+	}
1573 1665
 
1574 1666
 	// Normalize the $versions while we remove our previous Doh!
1575 1667
 	$versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions)));
@@ -1578,16 +1670,19 @@  discard block
 block discarded – undo
1578 1670
 	foreach ($versions as $for)
1579 1671
 	{
1580 1672
 		// Adjust for those wild cards
1581
-		if (strpos($for, '*') !== false)
1582
-			$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1673
+		if (strpos($for, '*') !== false) {
1674
+					$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1675
+		}
1583 1676
 
1584 1677
 		// If we have a range, grab the lower value, done this way so it looks normal-er to the user e.g. 2.0 vs 2.0.99
1585
-		if (strpos($for, '-') !== false)
1586
-			list ($for, $higher) = explode('-', $for);
1678
+		if (strpos($for, '-') !== false) {
1679
+					list ($for, $higher) = explode('-', $for);
1680
+		}
1587 1681
 
1588 1682
 		// Do the compare, if the for is greater, than what we have but not greater than what we are running .....
1589
-		if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1)
1590
-			$near_version = $for;
1683
+		if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) {
1684
+					$near_version = $for;
1685
+		}
1591 1686
 	}
1592 1687
 
1593 1688
 	return !empty($near_version) ? $near_version : false;
@@ -1610,15 +1705,17 @@  discard block
 block discarded – undo
1610 1705
 	$versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions)));
1611 1706
 
1612 1707
 	// Perhaps we do accept anything?
1613
-	if (in_array('all', $versions))
1614
-		return true;
1708
+	if (in_array('all', $versions)) {
1709
+			return true;
1710
+	}
1615 1711
 
1616 1712
 	// Loop through each version.
1617 1713
 	foreach ($versions as $for)
1618 1714
 	{
1619 1715
 		// Wild card spotted?
1620
-		if (strpos($for, '*') !== false)
1621
-			$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1716
+		if (strpos($for, '*') !== false) {
1717
+					$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1718
+		}
1622 1719
 
1623 1720
 		// Do we have a range?
1624 1721
 		if (strpos($for, '-') !== false)
@@ -1626,12 +1723,14 @@  discard block
 block discarded – undo
1626 1723
 			list ($lower, $upper) = explode('-', $for);
1627 1724
 
1628 1725
 			// Compare the version against lower and upper bounds.
1629
-			if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1)
1630
-				return true;
1726
+			if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) {
1727
+							return true;
1728
+			}
1631 1729
 		}
1632 1730
 		// Otherwise check if they are equal...
1633
-		elseif (compareVersions($version, $for) === 0)
1634
-			return true;
1731
+		elseif (compareVersions($version, $for) === 0) {
1732
+					return true;
1733
+		}
1635 1734
 	}
1636 1735
 
1637 1736
 	return false;
@@ -1671,12 +1770,14 @@  discard block
 block discarded – undo
1671 1770
 	}
1672 1771
 
1673 1772
 	// Are they the same, perhaps?
1674
-	if ($versions[1] === $versions[2])
1675
-		return 0;
1773
+	if ($versions[1] === $versions[2]) {
1774
+			return 0;
1775
+	}
1676 1776
 
1677 1777
 	// Get version numbering categories...
1678
-	if (!isset($categories))
1679
-		$categories = array_keys($versions[1]);
1778
+	if (!isset($categories)) {
1779
+			$categories = array_keys($versions[1]);
1780
+	}
1680 1781
 
1681 1782
 	// Loop through each category.
1682 1783
 	foreach ($categories as $category)
@@ -1686,13 +1787,15 @@  discard block
 block discarded – undo
1686 1787
 		{
1687 1788
 			// Dev builds are a problematic exception.
1688 1789
 			// (stable) dev < (stable) but (unstable) dev = (unstable)
1689
-			if ($category == 'type')
1690
-				return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1);
1691
-			elseif ($category == 'dev')
1692
-				return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0);
1790
+			if ($category == 'type') {
1791
+							return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1);
1792
+			} elseif ($category == 'dev') {
1793
+							return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0);
1794
+			}
1693 1795
 			// Otherwise a simple comparison.
1694
-			else
1695
-				return $versions[1][$category] > $versions[2][$category] ? 1 : -1;
1796
+			else {
1797
+							return $versions[1][$category] > $versions[2][$category] ? 1 : -1;
1798
+			}
1696 1799
 		}
1697 1800
 	}
1698 1801
 
@@ -1726,11 +1829,13 @@  discard block
 block discarded – undo
1726 1829
 	);
1727 1830
 
1728 1831
 	// do we parse in a package directory?
1729
-	if (!empty($temp_path))
1730
-		$dirs['$package'] = $temp_path;
1832
+	if (!empty($temp_path)) {
1833
+			$dirs['$package'] = $temp_path;
1834
+	}
1731 1835
 
1732
-	if (strlen($path) == 0)
1733
-		trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR);
1836
+	if (strlen($path) == 0) {
1837
+			trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR);
1838
+	}
1734 1839
 
1735 1840
 	return strtr($path, $dirs);
1736 1841
 }
@@ -1746,8 +1851,9 @@  discard block
 block discarded – undo
1746 1851
 {
1747 1852
 	global $package_ftp;
1748 1853
 
1749
-	if (!file_exists($dir))
1750
-		return;
1854
+	if (!file_exists($dir)) {
1855
+			return;
1856
+	}
1751 1857
 
1752 1858
 	$current_dir = @opendir($dir);
1753 1859
 	if ($current_dir == false)
@@ -1755,8 +1861,9 @@  discard block
 block discarded – undo
1755 1861
 		if ($delete_dir && isset($package_ftp))
1756 1862
 		{
1757 1863
 			$ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
1758
-			if (!is_dir($dir))
1759
-				$package_ftp->chmod($ftp_file, 0777);
1864
+			if (!is_dir($dir)) {
1865
+							$package_ftp->chmod($ftp_file, 0777);
1866
+			}
1760 1867
 			$package_ftp->unlink($ftp_file);
1761 1868
 		}
1762 1869
 
@@ -1765,26 +1872,28 @@  discard block
 block discarded – undo
1765 1872
 
1766 1873
 	while ($entryname = readdir($current_dir))
1767 1874
 	{
1768
-		if (in_array($entryname, array('.', '..')))
1769
-			continue;
1875
+		if (in_array($entryname, array('.', '..'))) {
1876
+					continue;
1877
+		}
1770 1878
 
1771
-		if (is_dir($dir . '/' . $entryname))
1772
-			deltree($dir . '/' . $entryname);
1773
-		else
1879
+		if (is_dir($dir . '/' . $entryname)) {
1880
+					deltree($dir . '/' . $entryname);
1881
+		} else
1774 1882
 		{
1775 1883
 			// Here, 755 doesn't really matter since we're deleting it anyway.
1776 1884
 			if (isset($package_ftp))
1777 1885
 			{
1778 1886
 				$ftp_file = strtr($dir . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
1779 1887
 
1780
-				if (!is_writable($dir . '/' . $entryname))
1781
-					$package_ftp->chmod($ftp_file, 0777);
1888
+				if (!is_writable($dir . '/' . $entryname)) {
1889
+									$package_ftp->chmod($ftp_file, 0777);
1890
+				}
1782 1891
 				$package_ftp->unlink($ftp_file);
1783
-			}
1784
-			else
1892
+			} else
1785 1893
 			{
1786
-				if (!is_writable($dir . '/' . $entryname))
1787
-					smf_chmod($dir . '/' . $entryname, 0777);
1894
+				if (!is_writable($dir . '/' . $entryname)) {
1895
+									smf_chmod($dir . '/' . $entryname, 0777);
1896
+				}
1788 1897
 				unlink($dir . '/' . $entryname);
1789 1898
 			}
1790 1899
 		}
@@ -1797,14 +1906,15 @@  discard block
 block discarded – undo
1797 1906
 		if (isset($package_ftp))
1798 1907
 		{
1799 1908
 			$ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
1800
-			if (!is_writable($dir . '/' . $entryname))
1801
-				$package_ftp->chmod($ftp_file, 0777);
1909
+			if (!is_writable($dir . '/' . $entryname)) {
1910
+							$package_ftp->chmod($ftp_file, 0777);
1911
+			}
1802 1912
 			$package_ftp->unlink($ftp_file);
1803
-		}
1804
-		else
1913
+		} else
1805 1914
 		{
1806
-			if (!is_writable($dir))
1807
-				smf_chmod($dir, 0777);
1915
+			if (!is_writable($dir)) {
1916
+							smf_chmod($dir, 0777);
1917
+			}
1808 1918
 			@rmdir($dir);
1809 1919
 		}
1810 1920
 	}
@@ -1826,10 +1936,11 @@  discard block
 block discarded – undo
1826 1936
 	{
1827 1937
 		if (!is_writable($strPath) && $mode !== false)
1828 1938
 		{
1829
-			if (isset($package_ftp))
1830
-				$package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode);
1831
-			else
1832
-				smf_chmod($strPath, $mode);
1939
+			if (isset($package_ftp)) {
1940
+							$package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode);
1941
+			} else {
1942
+							smf_chmod($strPath, $mode);
1943
+			}
1833 1944
 		}
1834 1945
 
1835 1946
 		$test = @opendir($strPath);
@@ -1837,36 +1948,37 @@  discard block
 block discarded – undo
1837 1948
 		{
1838 1949
 			closedir($test);
1839 1950
 			return is_writable($strPath);
1951
+		} else {
1952
+					return false;
1840 1953
 		}
1841
-		else
1842
-			return false;
1843 1954
 	}
1844 1955
 	// Is this an invalid path and/or we can't make the directory?
1845
-	if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode))
1846
-		return false;
1956
+	if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) {
1957
+			return false;
1958
+	}
1847 1959
 
1848 1960
 	if (!is_writable(dirname($strPath)) && $mode !== false)
1849 1961
 	{
1850
-		if (isset($package_ftp))
1851
-			$package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode);
1852
-		else
1853
-			smf_chmod(dirname($strPath), $mode);
1962
+		if (isset($package_ftp)) {
1963
+					$package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode);
1964
+		} else {
1965
+					smf_chmod(dirname($strPath), $mode);
1966
+		}
1854 1967
 	}
1855 1968
 
1856
-	if ($mode !== false && isset($package_ftp))
1857
-		return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')));
1858
-	elseif ($mode === false)
1969
+	if ($mode !== false && isset($package_ftp)) {
1970
+			return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')));
1971
+	} elseif ($mode === false)
1859 1972
 	{
1860 1973
 		$test = @opendir(dirname($strPath));
1861 1974
 		if ($test)
1862 1975
 		{
1863 1976
 			closedir($test);
1864 1977
 			return true;
1978
+		} else {
1979
+					return false;
1865 1980
 		}
1866
-		else
1867
-			return false;
1868
-	}
1869
-	else
1981
+	} else
1870 1982
 	{
1871 1983
 		@mkdir($strPath, $mode);
1872 1984
 		$test = @opendir($strPath);
@@ -1874,9 +1986,9 @@  discard block
 block discarded – undo
1874 1986
 		{
1875 1987
 			closedir($test);
1876 1988
 			return true;
1989
+		} else {
1990
+					return false;
1877 1991
 		}
1878
-		else
1879
-			return false;
1880 1992
 	}
1881 1993
 }
1882 1994
 
@@ -1891,39 +2003,46 @@  discard block
 block discarded – undo
1891 2003
 {
1892 2004
 	global $package_ftp;
1893 2005
 
1894
-	if (!file_exists($destination) || !is_writable($destination))
1895
-		mktree($destination, 0755);
1896
-	if (!is_writable($destination))
1897
-		mktree($destination, 0777);
2006
+	if (!file_exists($destination) || !is_writable($destination)) {
2007
+			mktree($destination, 0755);
2008
+	}
2009
+	if (!is_writable($destination)) {
2010
+			mktree($destination, 0777);
2011
+	}
1898 2012
 
1899 2013
 	$current_dir = opendir($source);
1900
-	if ($current_dir == false)
1901
-		return;
2014
+	if ($current_dir == false) {
2015
+			return;
2016
+	}
1902 2017
 
1903 2018
 	while ($entryname = readdir($current_dir))
1904 2019
 	{
1905
-		if (in_array($entryname, array('.', '..')))
1906
-			continue;
2020
+		if (in_array($entryname, array('.', '..'))) {
2021
+					continue;
2022
+		}
1907 2023
 
1908
-		if (isset($package_ftp))
1909
-			$ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
2024
+		if (isset($package_ftp)) {
2025
+					$ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
2026
+		}
1910 2027
 
1911 2028
 		if (is_file($source . '/' . $entryname))
1912 2029
 		{
1913
-			if (isset($package_ftp) && !file_exists($destination . '/' . $entryname))
1914
-				$package_ftp->create_file($ftp_file);
1915
-			elseif (!file_exists($destination . '/' . $entryname))
1916
-				@touch($destination . '/' . $entryname);
2030
+			if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) {
2031
+							$package_ftp->create_file($ftp_file);
2032
+			} elseif (!file_exists($destination . '/' . $entryname)) {
2033
+							@touch($destination . '/' . $entryname);
2034
+			}
1917 2035
 		}
1918 2036
 
1919 2037
 		package_chmod($destination . '/' . $entryname);
1920 2038
 
1921
-		if (is_dir($source . '/' . $entryname))
1922
-			copytree($source . '/' . $entryname, $destination . '/' . $entryname);
1923
-		elseif (file_exists($destination . '/' . $entryname))
1924
-			package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname));
1925
-		else
1926
-			copy($source . '/' . $entryname, $destination . '/' . $entryname);
2039
+		if (is_dir($source . '/' . $entryname)) {
2040
+					copytree($source . '/' . $entryname, $destination . '/' . $entryname);
2041
+		} elseif (file_exists($destination . '/' . $entryname)) {
2042
+					package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname));
2043
+		} else {
2044
+					copy($source . '/' . $entryname, $destination . '/' . $entryname);
2045
+		}
1927 2046
 	}
1928 2047
 
1929 2048
 	closedir($current_dir);
@@ -1941,21 +2060,24 @@  discard block
 block discarded – undo
1941 2060
 	$data = array();
1942 2061
 
1943 2062
 	$dir = @dir($path . $sub_path);
1944
-	if (!$dir)
1945
-		return array();
2063
+	if (!$dir) {
2064
+			return array();
2065
+	}
1946 2066
 	while ($entry = $dir->read())
1947 2067
 	{
1948
-		if ($entry == '.' || $entry == '..')
1949
-			continue;
2068
+		if ($entry == '.' || $entry == '..') {
2069
+					continue;
2070
+		}
1950 2071
 
1951
-		if (is_dir($path . $sub_path . '/' . $entry))
1952
-			$data = array_merge($data, listtree($path, $sub_path . '/' . $entry));
1953
-		else
1954
-			$data[] = array(
2072
+		if (is_dir($path . $sub_path . '/' . $entry)) {
2073
+					$data = array_merge($data, listtree($path, $sub_path . '/' . $entry));
2074
+		} else {
2075
+					$data[] = array(
1955 2076
 				'filename' => $sub_path == '' ? $entry : $sub_path . '/' . $entry,
1956 2077
 				'size' => filesize($path . $sub_path . '/' . $entry),
1957 2078
 				'skipped' => false,
1958 2079
 			);
2080
+		}
1959 2081
 	}
1960 2082
 	$dir->close();
1961 2083
 
@@ -2010,8 +2132,9 @@  discard block
 block discarded – undo
2010 2132
 		{
2011 2133
 			// If this filename is relative, if so take a guess at what it should be.
2012 2134
 			$real_filename = $filename;
2013
-			if (strpos($filename, 'Themes') === 0)
2014
-				$real_filename = $boarddir . '/' . $filename;
2135
+			if (strpos($filename, 'Themes') === 0) {
2136
+							$real_filename = $boarddir . '/' . $filename;
2137
+			}
2015 2138
 
2016 2139
 			if (strpos($real_filename, $theme['theme_dir']) === 0)
2017 2140
 			{
@@ -2030,8 +2153,9 @@  discard block
 block discarded – undo
2030 2153
 		foreach ($theme_paths as $id => $theme)
2031 2154
 		{
2032 2155
 			// Default is getting done anyway, so no need for involvement here.
2033
-			if ($id == 1)
2034
-				continue;
2156
+			if ($id == 1) {
2157
+							continue;
2158
+			}
2035 2159
 
2036 2160
 			// For every template, do we want it? Yea, no, maybe?
2037 2161
 			foreach ($template_changes[1] as $index => $template_file)
@@ -2054,8 +2178,9 @@  discard block
 block discarded – undo
2054 2178
 		);
2055 2179
 
2056 2180
 		// Sometimes though, we have some additional files for other themes, if we have add them to the mix.
2057
-		if (isset($custom_themes_add[$files_to_change[1]]))
2058
-			$files_to_change += $custom_themes_add[$files_to_change[1]];
2181
+		if (isset($custom_themes_add[$files_to_change[1]])) {
2182
+					$files_to_change += $custom_themes_add[$files_to_change[1]];
2183
+		}
2059 2184
 
2060 2185
 		// Now, loop through all the files we're changing, and, well, change them ;)
2061 2186
 		foreach ($files_to_change as $theme => $working_file)
@@ -2089,11 +2214,13 @@  discard block
 block discarded – undo
2089 2214
 				continue;
2090 2215
 			}
2091 2216
 			// Okay, we're creating this file then...?
2092
-			elseif (!file_exists($working_file))
2093
-				$working_data = '';
2217
+			elseif (!file_exists($working_file)) {
2218
+							$working_data = '';
2219
+			}
2094 2220
 			// Phew, it exists!  Load 'er up!
2095
-			else
2096
-				$working_data = str_replace("\r", '', package_get_contents($working_file));
2221
+			else {
2222
+							$working_data = str_replace("\r", '', package_get_contents($working_file));
2223
+			}
2097 2224
 
2098 2225
 			$actions[] = array(
2099 2226
 				'type' => 'opened',
@@ -2114,8 +2241,8 @@  discard block
 block discarded – undo
2114 2241
 
2115 2242
 				// Grab all search items of this operation (in most cases just 1).
2116 2243
 				$searches = $operation->set('search');
2117
-				foreach ($searches as $i => $search)
2118
-					$actual_operation['searches'][] = array(
2244
+				foreach ($searches as $i => $search) {
2245
+									$actual_operation['searches'][] = array(
2119 2246
 						'position' => $search->exists('@position') && in_array(trim($search->fetch('@position')), array('before', 'after', 'replace', 'end')) ? trim($search->fetch('@position')) : 'replace',
2120 2247
 						'is_reg_exp' => $search->exists('@regexp') && trim($search->fetch('@regexp')) === 'true',
2121 2248
 						'loose_whitespace' => $search->exists('@whitespace') && trim($search->fetch('@whitespace')) === 'loose',
@@ -2124,6 +2251,7 @@  discard block
 block discarded – undo
2124 2251
 						'preg_search' => '',
2125 2252
 						'preg_replace' => '',
2126 2253
 					);
2254
+				}
2127 2255
 
2128 2256
 				// At least one search should be defined.
2129 2257
 				if (empty($actual_operation['searches']))
@@ -2148,30 +2276,32 @@  discard block
 block discarded – undo
2148 2276
 						// Reverse modification of regular expressions are not allowed.
2149 2277
 						if ($search['is_reg_exp'])
2150 2278
 						{
2151
-							if ($actual_operation['error'] === 'fatal')
2152
-								$actions[] = array(
2279
+							if ($actual_operation['error'] === 'fatal') {
2280
+															$actions[] = array(
2153 2281
 									'type' => 'failure',
2154 2282
 									'filename' => $working_file,
2155 2283
 									'search' => $search['search'],
2156 2284
 									'is_custom' => $theme > 1 ? $theme : 0,
2157 2285
 								);
2286
+							}
2158 2287
 
2159 2288
 							// Continue to the next operation.
2160 2289
 							continue 2;
2161 2290
 						}
2162 2291
 
2163 2292
 						// The replacement is now the search subject...
2164
-						if ($search['position'] === 'replace' || $search['position'] === 'end')
2165
-							$actual_operation['searches'][$i]['search'] = $search['add'];
2166
-						else
2293
+						if ($search['position'] === 'replace' || $search['position'] === 'end') {
2294
+													$actual_operation['searches'][$i]['search'] = $search['add'];
2295
+						} else
2167 2296
 						{
2168 2297
 							// Reversing a before/after modification becomes a replacement.
2169 2298
 							$actual_operation['searches'][$i]['position'] = 'replace';
2170 2299
 
2171
-							if ($search['position'] === 'before')
2172
-								$actual_operation['searches'][$i]['search'] .= $search['add'];
2173
-							elseif ($search['position'] === 'after')
2174
-								$actual_operation['searches'][$i]['search'] = $search['add'] . $search['search'];
2300
+							if ($search['position'] === 'before') {
2301
+															$actual_operation['searches'][$i]['search'] .= $search['add'];
2302
+							} elseif ($search['position'] === 'after') {
2303
+															$actual_operation['searches'][$i]['search'] = $search['add'] . $search['search'];
2304
+							}
2175 2305
 						}
2176 2306
 
2177 2307
 						// ...and the search subject is now the replacement.
@@ -2199,16 +2329,17 @@  discard block
 block discarded – undo
2199 2329
 				foreach ($actual_operation['searches'] as $i => $search)
2200 2330
 				{
2201 2331
 					// Not much needed if the search subject is already a regexp.
2202
-					if ($search['is_reg_exp'])
2203
-						$actual_operation['searches'][$i]['preg_search'] = $search['search'];
2204
-					else
2332
+					if ($search['is_reg_exp']) {
2333
+											$actual_operation['searches'][$i]['preg_search'] = $search['search'];
2334
+					} else
2205 2335
 					{
2206 2336
 						// Make the search subject fit into a regular expression.
2207 2337
 						$actual_operation['searches'][$i]['preg_search'] = preg_quote($search['search'], '~');
2208 2338
 
2209 2339
 						// Using 'loose', a random amount of tabs and spaces may be used.
2210
-						if ($search['loose_whitespace'])
2211
-							$actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']);
2340
+						if ($search['loose_whitespace']) {
2341
+													$actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']);
2342
+						}
2212 2343
 					}
2213 2344
 
2214 2345
 					// Shuzzup.  This is done so we can safely use a regular expression. ($0 is bad!!)
@@ -2234,8 +2365,7 @@  discard block
 block discarded – undo
2234 2365
 						if ($undo)
2235 2366
 						{
2236 2367
 							$actual_operation['searches'][$i]['preg_replace'] = '';
2237
-						}
2238
-						else
2368
+						} else
2239 2369
 						{
2240 2370
 							$actual_operation['searches'][$i]['preg_search'] = '(\\n\\?\\>)?$';
2241 2371
 							$actual_operation['searches'][$i]['preg_replace'] .= '$1';
@@ -2282,8 +2412,9 @@  discard block
 block discarded – undo
2282 2412
 					}
2283 2413
 
2284 2414
 					// Replace it into nothing? That's not an option...unless it's an undoing end.
2285
-					if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo))
2286
-						continue;
2415
+					if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) {
2416
+											continue;
2417
+					}
2287 2418
 
2288 2419
 					// Finally, we're doing some replacements.
2289 2420
 					$working_data = preg_replace('~' . $actual_operation['searches'][$i]['preg_search'] . '~s', $actual_operation['searches'][$i]['preg_replace'], $working_data, 1);
@@ -2308,22 +2439,25 @@  discard block
 block discarded – undo
2308 2439
 
2309 2440
 			package_chmod($working_file);
2310 2441
 
2311
-			if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file))))
2312
-				$actions[] = array(
2442
+			if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) {
2443
+							$actions[] = array(
2313 2444
 					'type' => 'chmod',
2314 2445
 					'filename' => $working_file
2315 2446
 				);
2447
+			}
2316 2448
 
2317
-			if (basename($working_file) == 'Settings_bak.php')
2318
-				continue;
2449
+			if (basename($working_file) == 'Settings_bak.php') {
2450
+							continue;
2451
+			}
2319 2452
 
2320 2453
 			if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2321 2454
 			{
2322 2455
 				// No, no, not Settings.php!
2323
-				if (basename($working_file) == 'Settings.php')
2324
-					@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2325
-				else
2326
-					@copy($working_file, $working_file . '~');
2456
+				if (basename($working_file) == 'Settings.php') {
2457
+									@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2458
+				} else {
2459
+									@copy($working_file, $working_file . '~');
2460
+				}
2327 2461
 			}
2328 2462
 
2329 2463
 			// Always call this, even if in testing, because it won't really be written in testing mode.
@@ -2390,8 +2524,9 @@  discard block
 block discarded – undo
2390 2524
 		if ($code_match[1] != 'edit file' && $code_match[1] != 'file')
2391 2525
 		{
2392 2526
 			// It's a step, let's add that to the current steps.
2393
-			if (isset($temp_changes[$step_counter]))
2394
-				$temp_changes[$step_counter]['changes'][] = $code_match[0];
2527
+			if (isset($temp_changes[$step_counter])) {
2528
+							$temp_changes[$step_counter]['changes'][] = $code_match[0];
2529
+			}
2395 2530
 			continue;
2396 2531
 		}
2397 2532
 
@@ -2408,11 +2543,13 @@  discard block
 block discarded – undo
2408 2543
 		foreach ($theme_paths as $id => $theme)
2409 2544
 		{
2410 2545
 			// If this filename is relative, if so take a guess at what it should be.
2411
-			if (strpos($filename, 'Themes') === 0)
2412
-				$filename = $boarddir . '/' . $filename;
2546
+			if (strpos($filename, 'Themes') === 0) {
2547
+							$filename = $boarddir . '/' . $filename;
2548
+			}
2413 2549
 
2414
-			if (strpos($filename, $theme['theme_dir']) === 0)
2415
-				$template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1);
2550
+			if (strpos($filename, $theme['theme_dir']) === 0) {
2551
+							$template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1);
2552
+			}
2416 2553
 		}
2417 2554
 	}
2418 2555
 
@@ -2427,8 +2564,9 @@  discard block
 block discarded – undo
2427 2564
 		foreach ($theme_paths as $id => $theme)
2428 2565
 		{
2429 2566
 			// Don't do default, it means nothing to me.
2430
-			if ($id == 1)
2431
-				continue;
2567
+			if ($id == 1) {
2568
+							continue;
2569
+			}
2432 2570
 
2433 2571
 			// Now, for each file do we need to edit it?
2434 2572
 			foreach ($template_changes[1] as $pos => $template_file)
@@ -2464,32 +2602,36 @@  discard block
 block discarded – undo
2464 2602
 				package_chmod($working_file);
2465 2603
 
2466 2604
 				// Don't even dare.
2467
-				if (basename($working_file) == 'Settings_bak.php')
2468
-					continue;
2605
+				if (basename($working_file) == 'Settings_bak.php') {
2606
+									continue;
2607
+				}
2469 2608
 
2470
-				if (!is_writable($working_file))
2471
-					$actions[] = array(
2609
+				if (!is_writable($working_file)) {
2610
+									$actions[] = array(
2472 2611
 						'type' => 'chmod',
2473 2612
 						'filename' => $working_file
2474 2613
 					);
2614
+				}
2475 2615
 
2476 2616
 				if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2477 2617
 				{
2478
-					if (basename($working_file) == 'Settings.php')
2479
-						@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2480
-					else
2481
-						@copy($working_file, $working_file . '~');
2618
+					if (basename($working_file) == 'Settings.php') {
2619
+											@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2620
+					} else {
2621
+											@copy($working_file, $working_file . '~');
2622
+					}
2482 2623
 				}
2483 2624
 
2484 2625
 				package_put_contents($working_file, $working_data, $testing);
2485 2626
 			}
2486 2627
 
2487
-			if ($working_file !== null)
2488
-				$actions[] = array(
2628
+			if ($working_file !== null) {
2629
+							$actions[] = array(
2489 2630
 					'type' => 'saved',
2490 2631
 					'filename' => $working_file,
2491 2632
 					'is_custom' => $is_custom,
2492 2633
 				);
2634
+			}
2493 2635
 
2494 2636
 			// Is this "now working on" file a theme specific one?
2495 2637
 			$is_custom = isset($theme_id_ref[$counter - 1]) ? $theme_id_ref[$counter - 1] : 0;
@@ -2508,10 +2650,11 @@  discard block
 block discarded – undo
2508 2650
 			{
2509 2651
 				$places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages');
2510 2652
 
2511
-				foreach ($places_to_check as $place)
2512
-					if (file_exists($place . '/' . $working_file))
2653
+				foreach ($places_to_check as $place) {
2654
+									if (file_exists($place . '/' . $working_file))
2513 2655
 					{
2514 2656
 						$working_file = $place . '/' . $working_file;
2657
+				}
2515 2658
 						break;
2516 2659
 					}
2517 2660
 			}
@@ -2525,8 +2668,7 @@  discard block
 block discarded – undo
2525 2668
 					'type' => 'opened',
2526 2669
 					'filename' => $working_file
2527 2670
 				);
2528
-			}
2529
-			else
2671
+			} else
2530 2672
 			{
2531 2673
 				$actions[] = array(
2532 2674
 					'type' => 'missing',
@@ -2562,11 +2704,13 @@  discard block
 block discarded – undo
2562 2704
 			$replace_with = $code_match[2];
2563 2705
 
2564 2706
 			// Add this afterward...
2565
-			if ($code_match[1] == 'add' || $code_match[1] == 'add after')
2566
-				$replace_with = $working_search . "\n" . $replace_with;
2707
+			if ($code_match[1] == 'add' || $code_match[1] == 'add after') {
2708
+							$replace_with = $working_search . "\n" . $replace_with;
2709
+			}
2567 2710
 			// Add this beforehand.
2568
-			elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above')
2569
-				$replace_with .= "\n" . $working_search;
2711
+			elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') {
2712
+							$replace_with .= "\n" . $working_search;
2713
+			}
2570 2714
 			// Otherwise.. replace with $replace_with ;).
2571 2715
 		}
2572 2716
 
@@ -2629,29 +2773,32 @@  discard block
 block discarded – undo
2629 2773
 	{
2630 2774
 		package_chmod($working_file);
2631 2775
 
2632
-		if (!is_writable($working_file))
2633
-			$actions[] = array(
2776
+		if (!is_writable($working_file)) {
2777
+					$actions[] = array(
2634 2778
 				'type' => 'chmod',
2635 2779
 				'filename' => $working_file
2636 2780
 			);
2781
+		}
2637 2782
 
2638 2783
 		if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2639 2784
 		{
2640
-			if (basename($working_file) == 'Settings.php')
2641
-				@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2642
-			else
2643
-				@copy($working_file, $working_file . '~');
2785
+			if (basename($working_file) == 'Settings.php') {
2786
+							@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2787
+			} else {
2788
+							@copy($working_file, $working_file . '~');
2789
+			}
2644 2790
 		}
2645 2791
 
2646 2792
 		package_put_contents($working_file, $working_data, $testing);
2647 2793
 	}
2648 2794
 
2649
-	if ($working_file !== null)
2650
-		$actions[] = array(
2795
+	if ($working_file !== null) {
2796
+			$actions[] = array(
2651 2797
 			'type' => 'saved',
2652 2798
 			'filename' => $working_file,
2653 2799
 			'is_custom' => $is_custom,
2654 2800
 		);
2801
+	}
2655 2802
 
2656 2803
 	$actions[] = array(
2657 2804
 		'type' => 'result',
@@ -2677,17 +2824,19 @@  discard block
 block discarded – undo
2677 2824
 		$mem_check = setMemoryLimit('128M');
2678 2825
 
2679 2826
 		// Windows doesn't seem to care about the memory_limit.
2680
-		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false)
2681
-			$package_cache = array();
2682
-		else
2683
-			$package_cache = false;
2827
+		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) {
2828
+					$package_cache = array();
2829
+		} else {
2830
+					$package_cache = false;
2831
+		}
2684 2832
 	}
2685 2833
 
2686
-	if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename]))
2687
-		return file_get_contents($filename);
2688
-	else
2689
-		return $package_cache[$filename];
2690
-}
2834
+	if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) {
2835
+			return file_get_contents($filename);
2836
+	} else {
2837
+			return $package_cache[$filename];
2838
+	}
2839
+	}
2691 2840
 
2692 2841
 /**
2693 2842
  * Writes data to a file, almost exactly like the file_put_contents() function.
@@ -2710,19 +2859,22 @@  discard block
 block discarded – undo
2710 2859
 		// Try to increase the memory limit - we don't want to run out of ram!
2711 2860
 		$mem_check = setMemoryLimit('128M');
2712 2861
 
2713
-		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false)
2714
-			$package_cache = array();
2715
-		else
2716
-			$package_cache = false;
2862
+		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) {
2863
+					$package_cache = array();
2864
+		} else {
2865
+					$package_cache = false;
2866
+		}
2717 2867
 	}
2718 2868
 
2719
-	if (isset($package_ftp))
2720
-		$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2869
+	if (isset($package_ftp)) {
2870
+			$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2871
+	}
2721 2872
 
2722
-	if (!file_exists($filename) && isset($package_ftp))
2723
-		$package_ftp->create_file($ftp_file);
2724
-	elseif (!file_exists($filename))
2725
-		@touch($filename);
2873
+	if (!file_exists($filename) && isset($package_ftp)) {
2874
+			$package_ftp->create_file($ftp_file);
2875
+	} elseif (!file_exists($filename)) {
2876
+			@touch($filename);
2877
+	}
2726 2878
 
2727 2879
 	package_chmod($filename);
2728 2880
 
@@ -2731,22 +2883,23 @@  discard block
 block discarded – undo
2731 2883
 		$fp = @fopen($filename, in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb');
2732 2884
 
2733 2885
 		// We should show an error message or attempt a rollback, no?
2734
-		if (!$fp)
2735
-			return false;
2886
+		if (!$fp) {
2887
+					return false;
2888
+		}
2736 2889
 
2737 2890
 		fwrite($fp, $data);
2738 2891
 		fclose($fp);
2739
-	}
2740
-	elseif (strpos($filename, 'Packages/') !== false || $package_cache === false)
2741
-		return strlen($data);
2742
-	else
2892
+	} elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) {
2893
+			return strlen($data);
2894
+	} else
2743 2895
 	{
2744 2896
 		$package_cache[$filename] = $data;
2745 2897
 
2746 2898
 		// Permission denied, eh?
2747 2899
 		$fp = @fopen($filename, 'r+');
2748
-		if (!$fp)
2749
-			return false;
2900
+		if (!$fp) {
2901
+					return false;
2902
+		}
2750 2903
 		fclose($fp);
2751 2904
 	}
2752 2905
 
@@ -2763,19 +2916,22 @@  discard block
 block discarded – undo
2763 2916
 	global $package_ftp, $package_cache;
2764 2917
 	static $text_filetypes = array('php', 'txt', '.js', 'css', 'vbs', 'tml', 'htm');
2765 2918
 
2766
-	if (empty($package_cache))
2767
-		return;
2919
+	if (empty($package_cache)) {
2920
+			return;
2921
+	}
2768 2922
 
2769 2923
 	// First, let's check permissions!
2770 2924
 	foreach ($package_cache as $filename => $data)
2771 2925
 	{
2772
-		if (isset($package_ftp))
2773
-			$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2926
+		if (isset($package_ftp)) {
2927
+					$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2928
+		}
2774 2929
 
2775
-		if (!file_exists($filename) && isset($package_ftp))
2776
-			$package_ftp->create_file($ftp_file);
2777
-		elseif (!file_exists($filename))
2778
-			@touch($filename);
2930
+		if (!file_exists($filename) && isset($package_ftp)) {
2931
+					$package_ftp->create_file($ftp_file);
2932
+		} elseif (!file_exists($filename)) {
2933
+					@touch($filename);
2934
+		}
2779 2935
 
2780 2936
 		$result = package_chmod($filename);
2781 2937
 
@@ -2822,8 +2978,9 @@  discard block
 block discarded – undo
2822 2978
 {
2823 2979
 	global $package_ftp;
2824 2980
 
2825
-	if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable')
2826
-		return true;
2981
+	if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') {
2982
+			return true;
2983
+	}
2827 2984
 
2828 2985
 	// Start off checking without FTP.
2829 2986
 	if (!isset($package_ftp) || $package_ftp === false)
@@ -2845,8 +3002,7 @@  discard block
 block discarded – undo
2845 3002
 
2846 3003
 				// Keep track of the writable status here.
2847 3004
 				$file_permissions = @fileperms($chmod_file);
2848
-			}
2849
-			else
3005
+			} else
2850 3006
 			{
2851 3007
 				// This looks odd, but it's an attempt to work around PHP suExec.
2852 3008
 				if (!file_exists($chmod_file) && $perm_state == 'writable')
@@ -2856,24 +3012,28 @@  discard block
 block discarded – undo
2856 3012
 					mktree(dirname($chmod_file), 0755);
2857 3013
 					@touch($chmod_file);
2858 3014
 					smf_chmod($chmod_file, 0755);
3015
+				} else {
3016
+									$file_permissions = @fileperms($chmod_file);
2859 3017
 				}
2860
-				else
2861
-					$file_permissions = @fileperms($chmod_file);
2862 3018
 			}
2863 3019
 
2864 3020
 			// This looks odd, but it's another attempt to work around PHP suExec.
2865
-			if ($perm_state != 'writable')
2866
-				smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644);
2867
-			else
3021
+			if ($perm_state != 'writable') {
3022
+							smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644);
3023
+			} else
2868 3024
 			{
2869
-				if (!@is_writable($chmod_file))
2870
-					smf_chmod($chmod_file, 0755);
2871
-				if (!@is_writable($chmod_file))
2872
-					smf_chmod($chmod_file, 0777);
2873
-				if (!@is_writable(dirname($chmod_file)))
2874
-					smf_chmod($chmod_file, 0755);
2875
-				if (!@is_writable(dirname($chmod_file)))
2876
-					smf_chmod($chmod_file, 0777);
3025
+				if (!@is_writable($chmod_file)) {
3026
+									smf_chmod($chmod_file, 0755);
3027
+				}
3028
+				if (!@is_writable($chmod_file)) {
3029
+									smf_chmod($chmod_file, 0777);
3030
+				}
3031
+				if (!@is_writable(dirname($chmod_file))) {
3032
+									smf_chmod($chmod_file, 0755);
3033
+				}
3034
+				if (!@is_writable(dirname($chmod_file))) {
3035
+									smf_chmod($chmod_file, 0777);
3036
+				}
2877 3037
 			}
2878 3038
 
2879 3039
 			// The ultimate writable test.
@@ -2882,20 +3042,22 @@  discard block
 block discarded – undo
2882 3042
 				$fp = is_dir($chmod_file) ? @opendir($chmod_file) : @fopen($chmod_file, 'rb');
2883 3043
 				if (@is_writable($chmod_file) && $fp)
2884 3044
 				{
2885
-					if (!is_dir($chmod_file))
2886
-						fclose($fp);
2887
-					else
2888
-						closedir($fp);
3045
+					if (!is_dir($chmod_file)) {
3046
+											fclose($fp);
3047
+					} else {
3048
+											closedir($fp);
3049
+					}
2889 3050
 
2890 3051
 					// It worked!
2891
-					if ($track_change)
2892
-						$_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions;
3052
+					if ($track_change) {
3053
+											$_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions;
3054
+					}
2893 3055
 
2894 3056
 					return true;
2895 3057
 				}
3058
+			} elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) {
3059
+							unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]);
2896 3060
 			}
2897
-			elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file]))
2898
-				unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]);
2899 3061
 		}
2900 3062
 
2901 3063
 		// If we're here we're a failure.
@@ -2914,31 +3076,33 @@  discard block
 block discarded – undo
2914 3076
 			mktree(dirname($filename), 0755);
2915 3077
 			$package_ftp->create_file($ftp_file);
2916 3078
 			$package_ftp->chmod($ftp_file, 0755);
3079
+		} else {
3080
+					$file_permissions = @fileperms($filename);
2917 3081
 		}
2918
-		else
2919
-			$file_permissions = @fileperms($filename);
2920 3082
 
2921 3083
 		if ($perm_state != 'writable')
2922 3084
 		{
2923 3085
 			$package_ftp->chmod($ftp_file, $perm_state == 'execute' ? 0755 : 0644);
2924
-		}
2925
-		else
3086
+		} else
2926 3087
 		{
2927
-			if (!@is_writable($filename))
2928
-				$package_ftp->chmod($ftp_file, 0777);
2929
-			if (!@is_writable(dirname($filename)))
2930
-				$package_ftp->chmod(dirname($ftp_file), 0777);
3088
+			if (!@is_writable($filename)) {
3089
+							$package_ftp->chmod($ftp_file, 0777);
3090
+			}
3091
+			if (!@is_writable(dirname($filename))) {
3092
+							$package_ftp->chmod(dirname($ftp_file), 0777);
3093
+			}
2931 3094
 		}
2932 3095
 
2933 3096
 		if (@is_writable($filename))
2934 3097
 		{
2935
-			if ($track_change)
2936
-				$_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions;
3098
+			if ($track_change) {
3099
+							$_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions;
3100
+			}
2937 3101
 
2938 3102
 			return true;
3103
+		} elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) {
3104
+					unset($_SESSION['pack_ftp']['original_perms'][$filename]);
2939 3105
 		}
2940
-		elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename]))
2941
-			unset($_SESSION['pack_ftp']['original_perms'][$filename]);
2942 3106
 	}
2943 3107
 
2944 3108
 	// Oh dear, we failed if we get here.
@@ -2956,11 +3120,13 @@  discard block
 block discarded – undo
2956 3120
 	$n = strlen($pass);
2957 3121
 
2958 3122
 	$salt = session_id();
2959
-	while (strlen($salt) < $n)
2960
-		$salt .= session_id();
3123
+	while (strlen($salt) < $n) {
3124
+			$salt .= session_id();
3125
+	}
2961 3126
 
2962
-	for ($i = 0; $i < $n; $i++)
2963
-		$pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32));
3127
+	for ($i = 0; $i < $n; $i++) {
3128
+			$pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32));
3129
+	}
2964 3130
 
2965 3131
 	return $pass;
2966 3132
 }
@@ -2979,8 +3145,9 @@  discard block
 block discarded – undo
2979 3145
 	$base_files = array('index.php', 'SSI.php', 'agreement.txt', 'cron.php', 'ssi_examples.php', 'ssi_examples.shtml', 'subscriptions.php');
2980 3146
 	foreach ($base_files as $file)
2981 3147
 	{
2982
-		if (file_exists($boarddir . '/' . $file))
2983
-			$files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file;
3148
+		if (file_exists($boarddir . '/' . $file)) {
3149
+					$files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file;
3150
+		}
2984 3151
 	}
2985 3152
 
2986 3153
 	$dirs = array(
@@ -2997,8 +3164,9 @@  discard block
 block discarded – undo
2997 3164
 			'theme_dir' => 'theme_dir',
2998 3165
 		)
2999 3166
 	);
3000
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3001
-		$dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/');
3167
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3168
+			$dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/');
3169
+	}
3002 3170
 	$smcFunc['db_free_result']($request);
3003 3171
 
3004 3172
 	try
@@ -3013,11 +3181,13 @@  discard block
 block discarded – undo
3013 3181
 
3014 3182
 			foreach ($iter as $entry => $dir)
3015 3183
 			{
3016
-				if ($dir->isDir())
3017
-					continue;
3184
+				if ($dir->isDir()) {
3185
+									continue;
3186
+				}
3018 3187
 
3019
-				if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0)
3020
-					continue;
3188
+				if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) {
3189
+									continue;
3190
+				}
3021 3191
 
3022 3192
 				$files[empty($_REQUEST['use_full_paths']) ? str_replace(realpath($boarddir), '', $entry) : $entry] = $entry;
3023 3193
 			}
@@ -3025,26 +3195,30 @@  discard block
 block discarded – undo
3025 3195
 		$obj = new ArrayObject($files);
3026 3196
 		$iterator = $obj->getIterator();
3027 3197
 
3028
-		if (!file_exists($packagesdir . '/backups'))
3029
-			mktree($packagesdir . '/backups', 0777);
3030
-		if (!is_writable($packagesdir . '/backups'))
3031
-			package_chmod($packagesdir . '/backups');
3198
+		if (!file_exists($packagesdir . '/backups')) {
3199
+					mktree($packagesdir . '/backups', 0777);
3200
+		}
3201
+		if (!is_writable($packagesdir . '/backups')) {
3202
+					package_chmod($packagesdir . '/backups');
3203
+		}
3032 3204
 		$output_file = $packagesdir . '/backups/' . strftime('%Y-%m-%d_') . preg_replace('~[$\\\\/:<>|?*"\']~', '', $id);
3033 3205
 		$output_ext = '.tar';
3034 3206
 
3035 3207
 		if (file_exists($output_file . $output_ext))
3036 3208
 		{
3037 3209
 			$i = 2;
3038
-			while (file_exists($output_file . '_' . $i . $output_ext))
3039
-				$i++;
3210
+			while (file_exists($output_file . '_' . $i . $output_ext)) {
3211
+							$i++;
3212
+			}
3040 3213
 			$output_file = $output_file . '_' . $i . $output_ext;
3214
+		} else {
3215
+					$output_file .= $output_ext;
3041 3216
 		}
3042
-		else
3043
-			$output_file .= $output_ext;
3044 3217
 
3045 3218
 		@set_time_limit(300);
3046
-		if (function_exists('apache_reset_timeout'))
3047
-			@apache_reset_timeout();
3219
+		if (function_exists('apache_reset_timeout')) {
3220
+					@apache_reset_timeout();
3221
+		}
3048 3222
 
3049 3223
 		$a = new PharData($output_file);
3050 3224
 		$a->buildFromIterator($iterator);
@@ -3056,8 +3230,7 @@  discard block
 block discarded – undo
3056 3230
 		 */
3057 3231
 		unset($a);
3058 3232
 		unlink($output_file);
3059
-	}
3060
-	catch (Exception $e)
3233
+	} catch (Exception $e)
3061 3234
 	{
3062 3235
 		log_error($e->getMessage(), 'backup');
3063 3236
 
@@ -3089,32 +3262,35 @@  discard block
 block discarded – undo
3089 3262
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
3090 3263
 
3091 3264
 	// An FTP url. We should try connecting and RETRieving it...
3092
-	if (empty($match[1]))
3093
-		return false;
3094
-	elseif ($match[1] == 'ftp')
3265
+	if (empty($match[1])) {
3266
+			return false;
3267
+	} elseif ($match[1] == 'ftp')
3095 3268
 	{
3096 3269
 		// Include the file containing the ftp_connection class.
3097 3270
 		require_once($sourcedir . '/Class-Package.php');
3098 3271
 
3099 3272
 		// Establish a connection and attempt to enable passive mode.
3100 3273
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
3101
-		if ($ftp->error !== false || !$ftp->passive())
3102
-			return false;
3274
+		if ($ftp->error !== false || !$ftp->passive()) {
3275
+					return false;
3276
+		}
3103 3277
 
3104 3278
 		// I want that one *points*!
3105 3279
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
3106 3280
 
3107 3281
 		// Since passive mode worked (or we would have returned already!) open the connection.
3108 3282
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
3109
-		if (!$fp)
3110
-			return false;
3283
+		if (!$fp) {
3284
+					return false;
3285
+		}
3111 3286
 
3112 3287
 		// The server should now say something in acknowledgement.
3113 3288
 		$ftp->check_response(150);
3114 3289
 
3115 3290
 		$data = '';
3116
-		while (!feof($fp))
3117
-			$data .= fread($fp, 4096);
3291
+		while (!feof($fp)) {
3292
+					$data .= fread($fp, 4096);
3293
+		}
3118 3294
 		fclose($fp);
3119 3295
 
3120 3296
 		// All done, right?  Good.
@@ -3131,22 +3307,25 @@  discard block
 block discarded – undo
3131 3307
 		$fetch_data->get_url_data($url, $post_data);
3132 3308
 
3133 3309
 		// no errors and a 200 result, then we have a good dataset, well we at least have data ;)
3134
-		if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
3135
-			$data = $fetch_data->result('body');
3136
-		else
3137
-			return false;
3310
+		if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
3311
+					$data = $fetch_data->result('body');
3312
+		} else {
3313
+					return false;
3314
+		}
3138 3315
 	}
3139 3316
 	// This is more likely; a standard HTTP URL.
3140 3317
 	elseif (isset($match[1]) && $match[1] == 'http')
3141 3318
 	{
3142
-		if ($keep_alive && $match[3] == $keep_alive_dom)
3143
-			$fp = $keep_alive_fp;
3319
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
3320
+					$fp = $keep_alive_fp;
3321
+		}
3144 3322
 		if (empty($fp))
3145 3323
 		{
3146 3324
 			// Open the socket on the port we want...
3147 3325
 			$fp = @fsockopen(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? ($match[2] ? 443 : 80) : $match[5], $err, $err, 5);
3148
-			if (!$fp)
3149
-				return false;
3326
+			if (!$fp) {
3327
+							return false;
3328
+			}
3150 3329
 		}
3151 3330
 
3152 3331
 		if ($keep_alive)
@@ -3161,20 +3340,21 @@  discard block
 block discarded – undo
3161 3340
 			fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
3162 3341
 			fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
3163 3342
 			fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n");
3164
-			if ($keep_alive)
3165
-				fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n");
3166
-			else
3167
-				fwrite($fp, 'Connection: close' . "\r\n\r\n");
3168
-		}
3169
-		else
3343
+			if ($keep_alive) {
3344
+							fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n");
3345
+			} else {
3346
+							fwrite($fp, 'Connection: close' . "\r\n\r\n");
3347
+			}
3348
+		} else
3170 3349
 		{
3171 3350
 			fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
3172 3351
 			fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
3173 3352
 			fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n");
3174
-			if ($keep_alive)
3175
-				fwrite($fp, 'Connection: Keep-Alive' . "\r\n");
3176
-			else
3177
-				fwrite($fp, 'Connection: close' . "\r\n");
3353
+			if ($keep_alive) {
3354
+							fwrite($fp, 'Connection: Keep-Alive' . "\r\n");
3355
+			} else {
3356
+							fwrite($fp, 'Connection: close' . "\r\n");
3357
+			}
3178 3358
 			fwrite($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n");
3179 3359
 			fwrite($fp, 'Content-Length: ' . strlen($post_data) . "\r\n\r\n");
3180 3360
 			fwrite($fp, $post_data);
@@ -3187,30 +3367,33 @@  discard block
 block discarded – undo
3187 3367
 		{
3188 3368
 			$header = '';
3189 3369
 			$location = '';
3190
-			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
3191
-				if (strpos($header, 'Location:') !== false)
3370
+			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
3371
+							if (strpos($header, 'Location:') !== false)
3192 3372
 					$location = trim(substr($header, strpos($header, ':') + 1));
3373
+			}
3193 3374
 
3194
-			if (empty($location))
3195
-				return false;
3196
-			else
3375
+			if (empty($location)) {
3376
+							return false;
3377
+			} else
3197 3378
 			{
3198
-				if (!$keep_alive)
3199
-					fclose($fp);
3379
+				if (!$keep_alive) {
3380
+									fclose($fp);
3381
+				}
3200 3382
 				return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
3201 3383
 			}
3202 3384
 		}
3203 3385
 
3204 3386
 		// Make sure we get a 200 OK.
3205
-		elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
3206
-			return false;
3387
+		elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
3388
+					return false;
3389
+		}
3207 3390
 
3208 3391
 		// Skip the headers...
3209 3392
 		while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
3210 3393
 		{
3211
-			if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
3212
-				$content_length = $match[1];
3213
-			elseif (preg_match('~connection:\s*close~i', $header) != 0)
3394
+			if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
3395
+							$content_length = $match[1];
3396
+			} elseif (preg_match('~connection:\s*close~i', $header) != 0)
3214 3397
 			{
3215 3398
 				$keep_alive_dom = null;
3216 3399
 				$keep_alive = false;
@@ -3222,19 +3405,20 @@  discard block
 block discarded – undo
3222 3405
 		$data = '';
3223 3406
 		if (isset($content_length))
3224 3407
 		{
3225
-			while (!feof($fp) && strlen($data) < $content_length)
3226
-				$data .= fread($fp, $content_length - strlen($data));
3227
-		}
3228
-		else
3408
+			while (!feof($fp) && strlen($data) < $content_length) {
3409
+							$data .= fread($fp, $content_length - strlen($data));
3410
+			}
3411
+		} else
3229 3412
 		{
3230
-			while (!feof($fp))
3231
-				$data .= fread($fp, 4096);
3413
+			while (!feof($fp)) {
3414
+							$data .= fread($fp, 4096);
3415
+			}
3232 3416
 		}
3233 3417
 
3234
-		if (!$keep_alive)
3235
-			fclose($fp);
3236
-	}
3237
-	else
3418
+		if (!$keep_alive) {
3419
+					fclose($fp);
3420
+		}
3421
+	} else
3238 3422
 	{
3239 3423
 		// Umm, this shouldn't happen?
3240 3424
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
Please login to merge, or discard this patch.
Sources/ManageSmileys.php 1 patch
Braces   +297 added lines, -211 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * This is the dispatcher of smileys administration.
@@ -91,8 +92,9 @@  discard block
 block discarded – undo
91 92
 	);
92 93
 
93 94
 	// Some settings may not be enabled, disallow these from the tabs as appropriate.
94
-	if (empty($modSettings['messageIcons_enable']))
95
-		$context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
95
+	if (empty($modSettings['messageIcons_enable'])) {
96
+			$context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true;
97
+	}
96 98
 	if (empty($modSettings['smiley_enable']))
97 99
 	{
98 100
 		$context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true;
@@ -125,8 +127,9 @@  discard block
 block discarded – undo
125 127
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
126 128
 
127 129
 	$smiley_context = array();
128
-	foreach ($smiley_sets as $i => $set)
129
-		$smiley_context[$set] = $set_names[$i];
130
+	foreach ($smiley_sets as $i => $set) {
131
+			$smiley_context[$set] = $set_names[$i];
132
+	}
130 133
 
131 134
 	// All the settings for the page...
132 135
 	$config_vars = array(
@@ -147,8 +150,9 @@  discard block
 block discarded – undo
147 150
 
148 151
 	call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars));
149 152
 
150
-	if ($return_config)
151
-		return $config_vars;
153
+	if ($return_config) {
154
+			return $config_vars;
155
+	}
152 156
 
153 157
 	// Setup the basics of the settings template.
154 158
 	require_once($sourcedir . '/ManageServer.php');
@@ -207,8 +211,9 @@  discard block
 block discarded – undo
207 211
 			foreach ($_POST['smiley_set'] as $id => $val)
208 212
 			{
209 213
 				// If this is the set you've marked as default, or the only one remaining, you can't delete it
210
-				if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id]))
211
-					unset($set_paths[$id], $set_names[$id]);
214
+				if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) {
215
+									unset($set_paths[$id], $set_names[$id]);
216
+				}
212 217
 			}
213 218
 
214 219
 			// Shortcut... array_merge() on a single array resets the numeric keys
@@ -222,8 +227,9 @@  discard block
 block discarded – undo
222 227
 			));
223 228
 		}
224 229
 		// Add a new smiley set.
225
-		elseif (!empty($_POST['add']))
226
-			$context['sub_action'] = 'modifyset';
230
+		elseif (!empty($_POST['add'])) {
231
+					$context['sub_action'] = 'modifyset';
232
+		}
227 233
 		// Create or modify a smiley set.
228 234
 		elseif (isset($_POST['set']))
229 235
 		{
@@ -233,8 +239,9 @@  discard block
 block discarded – undo
233 239
 			// Create a new smiley set.
234 240
 			if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path']))
235 241
 			{
236
-				if (in_array($_POST['smiley_sets_path'], $set_paths))
237
-					fatal_lang_error('smiley_set_already_exists');
242
+				if (in_array($_POST['smiley_sets_path'], $set_paths)) {
243
+									fatal_lang_error('smiley_set_already_exists');
244
+				}
238 245
 
239 246
 				updateSettings(array(
240 247
 					'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'],
@@ -246,12 +253,14 @@  discard block
 block discarded – undo
246 253
 			else
247 254
 			{
248 255
 				// Make sure the smiley set exists.
249
-				if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']]))
250
-					fatal_lang_error('smiley_set_not_found');
256
+				if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) {
257
+									fatal_lang_error('smiley_set_not_found');
258
+				}
251 259
 
252 260
 				// Make sure the path is not yet used by another smileyset.
253
-				if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']])
254
-					fatal_lang_error('smiley_set_path_already_used');
261
+				if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) {
262
+									fatal_lang_error('smiley_set_path_already_used');
263
+				}
255 264
 
256 265
 				$set_paths[$_POST['set']] = $_POST['smiley_sets_path'];
257 266
 				$set_names[$_POST['set']] = $_POST['smiley_sets_name'];
@@ -263,8 +272,9 @@  discard block
 block discarded – undo
263 272
 			}
264 273
 
265 274
 			// The user might have checked to also import smileys.
266
-			if (!empty($_POST['smiley_sets_import']))
267
-				ImportSmileys($_POST['smiley_sets_path']);
275
+			if (!empty($_POST['smiley_sets_import'])) {
276
+							ImportSmileys($_POST['smiley_sets_path']);
277
+			}
268 278
 		}
269 279
 		cache_put_data('parsing_smileys', null, 480);
270 280
 		cache_put_data('posting_smileys', null, 480);
@@ -273,13 +283,14 @@  discard block
 block discarded – undo
273 283
 	// Load all available smileysets...
274 284
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
275 285
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
276
-	foreach ($context['smiley_sets'] as $i => $set)
277
-		$context['smiley_sets'][$i] = array(
286
+	foreach ($context['smiley_sets'] as $i => $set) {
287
+			$context['smiley_sets'][$i] = array(
278 288
 			'id' => $i,
279 289
 			'path' => $smcFunc['htmlspecialchars']($set),
280 290
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
281 291
 			'selected' => $set == $modSettings['smiley_sets_default']
282 292
 		);
293
+	}
283 294
 
284 295
 	// Importing any smileys from an existing set?
285 296
 	if ($context['sub_action'] == 'import')
@@ -290,8 +301,9 @@  discard block
 block discarded – undo
290 301
 		$_GET['set'] = (int) $_GET['set'];
291 302
 
292 303
 		// Sanity check - then import.
293
-		if (isset($context['smiley_sets'][$_GET['set']]))
294
-			ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
304
+		if (isset($context['smiley_sets'][$_GET['set']])) {
305
+					ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path']));
306
+		}
295 307
 
296 308
 		// Force the process to continue.
297 309
 		$context['sub_action'] = 'modifyset';
@@ -301,15 +313,15 @@  discard block
 block discarded – undo
301 313
 	if ($context['sub_action'] == 'modifyset')
302 314
 	{
303 315
 		$_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set'];
304
-		if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']]))
305
-			$context['current_set'] = array(
316
+		if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) {
317
+					$context['current_set'] = array(
306 318
 				'id' => '-1',
307 319
 				'path' => '',
308 320
 				'name' => '',
309 321
 				'selected' => false,
310 322
 				'is_new' => true,
311 323
 			);
312
-		else
324
+		} else
313 325
 		{
314 326
 			$context['current_set'] = &$context['smiley_sets'][$_GET['set']];
315 327
 			$context['current_set']['is_new'] = false;
@@ -321,13 +333,15 @@  discard block
 block discarded – undo
321 333
 				$dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']);
322 334
 				while ($entry = $dir->read())
323 335
 				{
324
-					if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
325
-						$smileys[strtolower($entry)] = $entry;
336
+					if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
337
+											$smileys[strtolower($entry)] = $entry;
338
+					}
326 339
 				}
327 340
 				$dir->close();
328 341
 
329
-				if (empty($smileys))
330
-					fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name']));
342
+				if (empty($smileys)) {
343
+									fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name']));
344
+				}
331 345
 
332 346
 				// Exclude the smileys that are already in the database.
333 347
 				$request = $smcFunc['db_query']('', '
@@ -338,9 +352,10 @@  discard block
 block discarded – undo
338 352
 						'smiley_list' => $smileys,
339 353
 					)
340 354
 				);
341
-				while ($row = $smcFunc['db_fetch_assoc']($request))
342
-					if (isset($smileys[strtolower($row['filename'])]))
355
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
356
+									if (isset($smileys[strtolower($row['filename'])]))
343 357
 						unset($smileys[strtolower($row['filename'])]);
358
+				}
344 359
 				$smcFunc['db_free_result']($request);
345 360
 
346 361
 				$context['current_set']['can_import'] = count($smileys);
@@ -355,13 +370,14 @@  discard block
 block discarded – undo
355 370
 			$dir = dir($modSettings['smileys_dir']);
356 371
 			while ($entry = $dir->read())
357 372
 			{
358
-				if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry))
359
-					$context['smiley_set_dirs'][] = array(
373
+				if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) {
374
+									$context['smiley_set_dirs'][] = array(
360 375
 						'id' => $entry,
361 376
 						'path' => $modSettings['smileys_dir'] . '/' . $entry,
362 377
 						'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])),
363 378
 						'current' => $entry == $context['current_set']['path'],
364 379
 					);
380
+				}
365 381
 			}
366 382
 			$dir->close();
367 383
 		}
@@ -371,8 +387,9 @@  discard block
 block discarded – undo
371 387
 	createToken('admin-mss', 'request');
372 388
 
373 389
 	// In case we need to import smileys, we need to add the token in now.
374
-	if (isset($context['current_set']['import_url']))
375
-		$context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token'];
390
+	if (isset($context['current_set']['import_url'])) {
391
+			$context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token'];
392
+	}
376 393
 
377 394
 	$listOptions = array(
378 395
 		'id' => 'smiley_set_list',
@@ -510,21 +527,23 @@  discard block
 block discarded – undo
510 527
 		$cols['name'][] = $set_names[$i];
511 528
 	}
512 529
 	$sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC;
513
-	if (substr($sort, 0, 4) === 'name')
514
-		array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']);
515
-	elseif (substr($sort, 0, 4) === 'path')
516
-		array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']);
517
-	else
518
-		array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']);
530
+	if (substr($sort, 0, 4) === 'name') {
531
+			array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']);
532
+	} elseif (substr($sort, 0, 4) === 'path') {
533
+			array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']);
534
+	} else {
535
+			array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']);
536
+	}
519 537
 
520 538
 	$smiley_sets = array();
521
-	foreach ($cols['id'] as $i => $id)
522
-		$smiley_sets[] = array(
539
+	foreach ($cols['id'] as $i => $id) {
540
+			$smiley_sets[] = array(
523 541
 			'id' => $id,
524 542
 			'path' => $cols['path'][$i],
525 543
 			'name' => $cols['name'][$i],
526 544
 			'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default']
527 545
 		);
546
+	}
528 547
 
529 548
 	return $smiley_sets;
530 549
 }
@@ -553,13 +572,14 @@  discard block
 block discarded – undo
553 572
 	$context['smileys_dir_found'] = is_dir($context['smileys_dir']);
554 573
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
555 574
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
556
-	foreach ($context['smiley_sets'] as $i => $set)
557
-		$context['smiley_sets'][$i] = array(
575
+	foreach ($context['smiley_sets'] as $i => $set) {
576
+			$context['smiley_sets'][$i] = array(
558 577
 			'id' => $i,
559 578
 			'path' => $smcFunc['htmlspecialchars']($set),
560 579
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
561 580
 			'selected' => $set == $modSettings['smiley_sets_default']
562 581
 		);
582
+	}
563 583
 
564 584
 	// Submitting a form?
565 585
 	if (isset($_POST[$context['session_var']], $_POST['smiley_code']))
@@ -575,8 +595,9 @@  discard block
 block discarded – undo
575 595
 		$_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']);
576 596
 
577 597
 		// Make sure some code was entered.
578
-		if (empty($_POST['smiley_code']))
579
-			fatal_lang_error('smiley_has_no_code');
598
+		if (empty($_POST['smiley_code'])) {
599
+					fatal_lang_error('smiley_has_no_code');
600
+		}
580 601
 
581 602
 		// Check whether the new code has duplicates. It should be unique.
582 603
 		$request = $smcFunc['db_query']('', '
@@ -588,8 +609,9 @@  discard block
 block discarded – undo
588 609
 				'smiley_code' => $_POST['smiley_code'],
589 610
 			)
590 611
 		);
591
-		if ($smcFunc['db_num_rows']($request) > 0)
592
-			fatal_lang_error('smiley_not_unique');
612
+		if ($smcFunc['db_num_rows']($request) > 0) {
613
+					fatal_lang_error('smiley_not_unique');
614
+		}
593 615
 		$smcFunc['db_free_result']($request);
594 616
 
595 617
 		// If we are uploading - check all the smiley sets are writable!
@@ -598,38 +620,44 @@  discard block
 block discarded – undo
598 620
 			$writeErrors = array();
599 621
 			foreach ($context['smiley_sets'] as $set)
600 622
 			{
601
-				if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path'])))
602
-					$writeErrors[] = $set['path'];
623
+				if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) {
624
+									$writeErrors[] = $set['path'];
625
+				}
626
+			}
627
+			if (!empty($writeErrors)) {
628
+							fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
603 629
 			}
604
-			if (!empty($writeErrors))
605
-				fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors)));
606 630
 		}
607 631
 
608 632
 		// Uploading just one smiley for all of them?
609 633
 		if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '')
610 634
 		{
611
-			if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name'])))
612
-				fatal_lang_error('smileys_upload_error');
635
+			if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) {
636
+							fatal_lang_error('smileys_upload_error');
637
+			}
613 638
 
614 639
 			// Sorry, no spaces, dots, or anything else but letters allowed.
615 640
 			$_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']);
616 641
 
617 642
 			// We only allow image files - it's THAT simple - no messing around here...
618
-			if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes))
619
-				fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
643
+			if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) {
644
+							fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
645
+			}
620 646
 
621 647
 			// We only need the filename...
622 648
 			$destName = basename($_FILES['uploadSmiley']['name']);
623 649
 
624 650
 			// Make sure they aren't trying to upload a nasty file - for their own good here!
625
-			if (in_array(strtolower($destName), $disabledFiles))
626
-				fatal_lang_error('smileys_upload_error_illegal');
651
+			if (in_array(strtolower($destName), $disabledFiles)) {
652
+							fatal_lang_error('smileys_upload_error_illegal');
653
+			}
627 654
 
628 655
 			// Check if the file already exists... and if not move it to EVERY smiley set directory.
629 656
 			$i = 0;
630 657
 			// Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?)
631
-			while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName))
632
-				$i++;
658
+			while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) {
659
+							$i++;
660
+			}
633 661
 
634 662
 			// Okay, we're going to put the smiley right here, since it's not there yet!
635 663
 			if (isset($context['smiley_sets'][$i]['path']))
@@ -644,8 +672,9 @@  discard block
 block discarded – undo
644 672
 					$currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName;
645 673
 
646 674
 					// The file is already there!  Don't overwrite it!
647
-					if (file_exists($currentPath))
648
-						continue;
675
+					if (file_exists($currentPath)) {
676
+											continue;
677
+					}
649 678
 
650 679
 					// Okay, so copy the first one we made to here.
651 680
 					copy($smileyLocation, $currentPath);
@@ -662,13 +691,15 @@  discard block
 block discarded – undo
662 691
 			$newName = '';
663 692
 			foreach ($_FILES as $name => $data)
664 693
 			{
665
-				if ($_FILES[$name]['name'] == '')
666
-					fatal_lang_error('smileys_upload_error_blank');
694
+				if ($_FILES[$name]['name'] == '') {
695
+									fatal_lang_error('smileys_upload_error_blank');
696
+				}
667 697
 
668
-				if (empty($newName))
669
-					$newName = basename($_FILES[$name]['name']);
670
-				elseif (basename($_FILES[$name]['name']) != $newName)
671
-					fatal_lang_error('smileys_upload_error_name');
698
+				if (empty($newName)) {
699
+									$newName = basename($_FILES[$name]['name']);
700
+				} elseif (basename($_FILES[$name]['name']) != $newName) {
701
+									fatal_lang_error('smileys_upload_error_name');
702
+				}
672 703
 			}
673 704
 
674 705
 			foreach ($context['smiley_sets'] as $i => $set)
@@ -676,31 +707,36 @@  discard block
 block discarded – undo
676 707
 				$set['name'] = un_htmlspecialchars($set['name']);
677 708
 				$set['path'] = un_htmlspecialchars($set['path']);
678 709
 
679
-				if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '')
680
-					continue;
710
+				if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') {
711
+									continue;
712
+				}
681 713
 
682 714
 				// Got one...
683
-				if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name'])))
684
-					fatal_lang_error('smileys_upload_error');
715
+				if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) {
716
+									fatal_lang_error('smileys_upload_error');
717
+				}
685 718
 
686 719
 				// Sorry, no spaces, dots, or anything else but letters allowed.
687 720
 				$_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']);
688 721
 
689 722
 				// We only allow image files - it's THAT simple - no messing around here...
690
-				if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes))
691
-					fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
723
+				if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) {
724
+									fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes)));
725
+				}
692 726
 
693 727
 				// We only need the filename...
694 728
 				$destName = basename($_FILES['individual_' . $set['name']]['name']);
695 729
 
696 730
 				// Make sure they aren't trying to upload a nasty file - for their own good here!
697
-				if (in_array(strtolower($destName), $disabledFiles))
698
-					fatal_lang_error('smileys_upload_error_illegal');
731
+				if (in_array(strtolower($destName), $disabledFiles)) {
732
+									fatal_lang_error('smileys_upload_error_illegal');
733
+				}
699 734
 
700 735
 				// If the file exists - ignore it.
701 736
 				$smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName;
702
-				if (file_exists($smileyLocation))
703
-					continue;
737
+				if (file_exists($smileyLocation)) {
738
+									continue;
739
+				}
704 740
 
705 741
 				// Finally - move the image!
706 742
 				move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation);
@@ -712,8 +748,9 @@  discard block
 block discarded – undo
712 748
 		}
713 749
 
714 750
 		// Also make sure a filename was given.
715
-		if (empty($_POST['smiley_filename']))
716
-			fatal_lang_error('smiley_has_no_filename');
751
+		if (empty($_POST['smiley_filename'])) {
752
+					fatal_lang_error('smiley_has_no_filename');
753
+		}
717 754
 
718 755
 		// Find the position on the right.
719 756
 		$smiley_order = '0';
@@ -732,8 +769,9 @@  discard block
 block discarded – undo
732 769
 			list ($smiley_order) = $smcFunc['db_fetch_row']($request);
733 770
 			$smcFunc['db_free_result']($request);
734 771
 
735
-			if (empty($smiley_order))
736
-				$smiley_order = '0';
772
+			if (empty($smiley_order)) {
773
+							$smiley_order = '0';
774
+			}
737 775
 		}
738 776
 		$smcFunc['db_insert']('',
739 777
 			'{db_prefix}smileys',
@@ -761,17 +799,19 @@  discard block
 block discarded – undo
761 799
 	{
762 800
 		foreach ($context['smiley_sets'] as $smiley_set)
763 801
 		{
764
-			if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
765
-				continue;
802
+			if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) {
803
+							continue;
804
+			}
766 805
 
767 806
 			$dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
768 807
 			while ($entry = $dir->read())
769 808
 			{
770
-				if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
771
-					$context['filenames'][strtolower($entry)] = array(
809
+				if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
810
+									$context['filenames'][strtolower($entry)] = array(
772 811
 						'id' => $smcFunc['htmlspecialchars']($entry),
773 812
 						'selected' => false,
774 813
 					);
814
+				}
775 815
 			}
776 816
 			$dir->close();
777 817
 		}
@@ -809,17 +849,19 @@  discard block
 block discarded – undo
809 849
 		// Changing the selected smileys?
810 850
 		if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys']))
811 851
 		{
812
-			foreach ($_POST['checked_smileys'] as $id => $smiley_id)
813
-				$_POST['checked_smileys'][$id] = (int) $smiley_id;
852
+			foreach ($_POST['checked_smileys'] as $id => $smiley_id) {
853
+							$_POST['checked_smileys'][$id] = (int) $smiley_id;
854
+			}
814 855
 
815
-			if ($_POST['smiley_action'] == 'delete')
816
-				$smcFunc['db_query']('', '
856
+			if ($_POST['smiley_action'] == 'delete') {
857
+							$smcFunc['db_query']('', '
817 858
 					DELETE FROM {db_prefix}smileys
818 859
 					WHERE id_smiley IN ({array_int:checked_smileys})',
819 860
 					array(
820 861
 						'checked_smileys' => $_POST['checked_smileys'],
821 862
 					)
822 863
 				);
864
+			}
823 865
 			// Changing the status of the smiley?
824 866
 			else
825 867
 			{
@@ -829,8 +871,8 @@  discard block
 block discarded – undo
829 871
 					'hidden' => 1,
830 872
 					'popup' => 2
831 873
 				);
832
-				if (isset($displayTypes[$_POST['smiley_action']]))
833
-					$smcFunc['db_query']('', '
874
+				if (isset($displayTypes[$_POST['smiley_action']])) {
875
+									$smcFunc['db_query']('', '
834 876
 						UPDATE {db_prefix}smileys
835 877
 						SET hidden = {int:display_type}
836 878
 						WHERE id_smiley IN ({array_int:checked_smileys})',
@@ -839,6 +881,7 @@  discard block
 block discarded – undo
839 881
 							'display_type' => $displayTypes[$_POST['smiley_action']],
840 882
 						)
841 883
 					);
884
+				}
842 885
 			}
843 886
 		}
844 887
 		// Create/modify a smiley.
@@ -864,12 +907,14 @@  discard block
 block discarded – undo
864 907
 				$_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location'];
865 908
 
866 909
 				// Make sure some code was entered.
867
-				if (empty($_POST['smiley_code']))
868
-					fatal_lang_error('smiley_has_no_code');
910
+				if (empty($_POST['smiley_code'])) {
911
+									fatal_lang_error('smiley_has_no_code');
912
+				}
869 913
 
870 914
 				// Also make sure a filename was given.
871
-				if (empty($_POST['smiley_filename']))
872
-					fatal_lang_error('smiley_has_no_filename');
915
+				if (empty($_POST['smiley_filename'])) {
916
+									fatal_lang_error('smiley_has_no_filename');
917
+				}
873 918
 
874 919
 				// Check whether the new code has duplicates. It should be unique.
875 920
 				$request = $smcFunc['db_query']('', '
@@ -883,8 +928,9 @@  discard block
 block discarded – undo
883 928
 						'smiley_code' => $_POST['smiley_code'],
884 929
 					)
885 930
 				);
886
-				if ($smcFunc['db_num_rows']($request) > 0)
887
-					fatal_lang_error('smiley_not_unique');
931
+				if ($smcFunc['db_num_rows']($request) > 0) {
932
+									fatal_lang_error('smiley_not_unique');
933
+				}
888 934
 				$smcFunc['db_free_result']($request);
889 935
 
890 936
 				$smcFunc['db_query']('', '
@@ -913,13 +959,14 @@  discard block
 block discarded – undo
913 959
 	// Load all known smiley sets.
914 960
 	$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
915 961
 	$set_names = explode("\n", $modSettings['smiley_sets_names']);
916
-	foreach ($context['smiley_sets'] as $i => $set)
917
-		$context['smiley_sets'][$i] = array(
962
+	foreach ($context['smiley_sets'] as $i => $set) {
963
+			$context['smiley_sets'][$i] = array(
918 964
 			'id' => $i,
919 965
 			'path' => $smcFunc['htmlspecialchars']($set),
920 966
 			'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
921 967
 			'selected' => $set == $modSettings['smiley_sets_default']
922 968
 		);
969
+	}
923 970
 
924 971
 	// Prepare overview of all (custom) smileys.
925 972
 	if ($context['sub_action'] == 'editsmileys')
@@ -935,9 +982,10 @@  discard block
 block discarded – undo
935 982
 		// Create a list of options for selecting smiley sets.
936 983
 		$smileyset_option_list = '
937 984
 			<select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">';
938
-		foreach ($context['smiley_sets'] as $smiley_set)
939
-			$smileyset_option_list .= '
985
+		foreach ($context['smiley_sets'] as $smiley_set) {
986
+					$smileyset_option_list .= '
940 987
 				<option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>';
988
+		}
941 989
 		$smileyset_option_list .= '
942 990
 			</select>';
943 991
 
@@ -999,12 +1047,13 @@  discard block
 block discarded – undo
999 1047
 					'data' => array(
1000 1048
 						'function' => function ($rowData) use ($txt)
1001 1049
 						{
1002
-							if (empty($rowData['hidden']))
1003
-								return $txt['smileys_location_form'];
1004
-							elseif ($rowData['hidden'] == 1)
1005
-								return $txt['smileys_location_hidden'];
1006
-							else
1007
-								return $txt['smileys_location_popup'];
1050
+							if (empty($rowData['hidden'])) {
1051
+															return $txt['smileys_location_form'];
1052
+							} elseif ($rowData['hidden'] == 1) {
1053
+															return $txt['smileys_location_hidden'];
1054
+							} else {
1055
+															return $txt['smileys_location_popup'];
1056
+							}
1008 1057
 						},
1009 1058
 					),
1010 1059
 					'sort' => array(
@@ -1019,19 +1068,22 @@  discard block
 block discarded – undo
1019 1068
 					'data' => array(
1020 1069
 						'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc)
1021 1070
 						{
1022
-							if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir']))
1023
-								return $smcFunc['htmlspecialchars']($rowData['description']);
1071
+							if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) {
1072
+															return $smcFunc['htmlspecialchars']($rowData['description']);
1073
+							}
1024 1074
 
1025 1075
 							// Check if there are smileys missing in some sets.
1026 1076
 							$missing_sets = array();
1027
-							foreach ($context['smiley_sets'] as $smiley_set)
1028
-								if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename'])))
1077
+							foreach ($context['smiley_sets'] as $smiley_set) {
1078
+															if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename'])))
1029 1079
 									$missing_sets[] = $smiley_set['path'];
1080
+							}
1030 1081
 
1031 1082
 							$description = $smcFunc['htmlspecialchars']($rowData['description']);
1032 1083
 
1033
-							if (!empty($missing_sets))
1034
-								$description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets));
1084
+							if (!empty($missing_sets)) {
1085
+															$description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets));
1086
+							}
1035 1087
 
1036 1088
 							return $description;
1037 1089
 						},
@@ -1147,13 +1199,14 @@  discard block
 block discarded – undo
1147 1199
 		$context['smileys_dir_found'] = is_dir($context['smileys_dir']);
1148 1200
 		$context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']);
1149 1201
 		$set_names = explode("\n", $modSettings['smiley_sets_names']);
1150
-		foreach ($context['smiley_sets'] as $i => $set)
1151
-			$context['smiley_sets'][$i] = array(
1202
+		foreach ($context['smiley_sets'] as $i => $set) {
1203
+					$context['smiley_sets'][$i] = array(
1152 1204
 				'id' => $i,
1153 1205
 				'path' => $smcFunc['htmlspecialchars']($set),
1154 1206
 				'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
1155 1207
 				'selected' => $set == $modSettings['smiley_sets_default']
1156 1208
 			);
1209
+		}
1157 1210
 
1158 1211
 		$context['selected_set'] = $modSettings['smiley_sets_default'];
1159 1212
 
@@ -1163,17 +1216,19 @@  discard block
 block discarded – undo
1163 1216
 		{
1164 1217
 			foreach ($context['smiley_sets'] as $smiley_set)
1165 1218
 			{
1166
-				if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])))
1167
-					continue;
1219
+				if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) {
1220
+									continue;
1221
+				}
1168 1222
 
1169 1223
 				$dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']));
1170 1224
 				while ($entry = $dir->read())
1171 1225
 				{
1172
-					if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
1173
-						$context['filenames'][strtolower($entry)] = array(
1226
+					if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
1227
+											$context['filenames'][strtolower($entry)] = array(
1174 1228
 							'id' => $smcFunc['htmlspecialchars']($entry),
1175 1229
 							'selected' => false,
1176 1230
 						);
1231
+					}
1177 1232
 				}
1178 1233
 				$dir->close();
1179 1234
 			}
@@ -1188,8 +1243,9 @@  discard block
 block discarded – undo
1188 1243
 				'current_smiley' => (int) $_REQUEST['smiley'],
1189 1244
 			)
1190 1245
 		);
1191
-		if ($smcFunc['db_num_rows']($request) != 1)
1192
-			fatal_lang_error('smiley_not_found');
1246
+		if ($smcFunc['db_num_rows']($request) != 1) {
1247
+					fatal_lang_error('smiley_not_found');
1248
+		}
1193 1249
 		$context['current_smiley'] = $smcFunc['db_fetch_assoc']($request);
1194 1250
 		$smcFunc['db_free_result']($request);
1195 1251
 
@@ -1197,8 +1253,9 @@  discard block
 block discarded – undo
1197 1253
 		$context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']);
1198 1254
 		$context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']);
1199 1255
 
1200
-		if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])]))
1201
-			$context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
1256
+		if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) {
1257
+					$context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true;
1258
+		}
1202 1259
 	}
1203 1260
 }
1204 1261
 
@@ -1223,8 +1280,9 @@  discard block
 block discarded – undo
1223 1280
 		)
1224 1281
 	);
1225 1282
 	$smileys = array();
1226
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1227
-		$smileys[] = $row;
1283
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1284
+			$smileys[] = $row;
1285
+	}
1228 1286
 	$smcFunc['db_free_result']($request);
1229 1287
 
1230 1288
 	return $smileys;
@@ -1264,8 +1322,9 @@  discard block
 block discarded – undo
1264 1322
 		$_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2;
1265 1323
 		$_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source'];
1266 1324
 
1267
-		if (empty($_GET['source']))
1268
-			fatal_lang_error('smiley_not_found');
1325
+		if (empty($_GET['source'])) {
1326
+					fatal_lang_error('smiley_not_found');
1327
+		}
1269 1328
 
1270 1329
 		if (!empty($_GET['after']))
1271 1330
 		{
@@ -1281,12 +1340,12 @@  discard block
 block discarded – undo
1281 1340
 					'after_smiley' => $_GET['after'],
1282 1341
 				)
1283 1342
 			);
1284
-			if ($smcFunc['db_num_rows']($request) != 1)
1285
-				fatal_lang_error('smiley_not_found');
1343
+			if ($smcFunc['db_num_rows']($request) != 1) {
1344
+							fatal_lang_error('smiley_not_found');
1345
+			}
1286 1346
 			list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request);
1287 1347
 			$smcFunc['db_free_result']($request);
1288
-		}
1289
-		else
1348
+		} else
1290 1349
 		{
1291 1350
 			$smiley_row = (int) $_GET['row'];
1292 1351
 			$smiley_order = -1;
@@ -1360,14 +1419,15 @@  discard block
 block discarded – undo
1360 1419
 	$context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move'];
1361 1420
 
1362 1421
 	// Make sure all rows are sequential.
1363
-	foreach (array_keys($context['smileys']) as $location)
1364
-		$context['smileys'][$location] = array(
1422
+	foreach (array_keys($context['smileys']) as $location) {
1423
+			$context['smileys'][$location] = array(
1365 1424
 			'id' => $location,
1366 1425
 			'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'],
1367 1426
 			'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'],
1368 1427
 			'last_row' => count($context['smileys'][$location]['rows']),
1369 1428
 			'rows' => array_values($context['smileys'][$location]['rows']),
1370 1429
 		);
1430
+	}
1371 1431
 
1372 1432
 	// Check & fix smileys that are not ordered properly in the database.
1373 1433
 	foreach (array_keys($context['smileys']) as $location)
@@ -1392,8 +1452,8 @@  discard block
 block discarded – undo
1392 1452
 				$context['smileys'][$location]['rows'][$id][0]['row'] = $id;
1393 1453
 			}
1394 1454
 			// Make sure the smiley order is always sequential.
1395
-			foreach ($smiley_row as $order_id => $smiley)
1396
-				if ($order_id != $smiley['order'])
1455
+			foreach ($smiley_row as $order_id => $smiley) {
1456
+							if ($order_id != $smiley['order'])
1397 1457
 					$smcFunc['db_query']('', '
1398 1458
 						UPDATE {db_prefix}smileys
1399 1459
 						SET smiley_order = {int:new_order}
@@ -1403,6 +1463,7 @@  discard block
 block discarded – undo
1403 1463
 							'current_smiley' => $smiley['id'],
1404 1464
 						)
1405 1465
 					);
1466
+			}
1406 1467
 		}
1407 1468
 	}
1408 1469
 
@@ -1436,19 +1497,20 @@  discard block
 block discarded – undo
1436 1497
 		$context['filename'] = $base_name;
1437 1498
 
1438 1499
 		// Check that the smiley is from simplemachines.org, for now... maybe add mirroring later.
1439
-		if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false)
1440
-			fatal_lang_error('not_on_simplemachines');
1500
+		if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) {
1501
+					fatal_lang_error('not_on_simplemachines');
1502
+		}
1441 1503
 
1442 1504
 		$destination = $packagesdir . '/' . $base_name;
1443 1505
 
1444
-		if (file_exists($destination))
1445
-			fatal_lang_error('package_upload_error_exists');
1506
+		if (file_exists($destination)) {
1507
+					fatal_lang_error('package_upload_error_exists');
1508
+		}
1446 1509
 
1447 1510
 		// Let's copy it to the Packages directory
1448 1511
 		file_put_contents($destination, fetch_web_data($_REQUEST['set_gz']));
1449 1512
 		$testing = true;
1450
-	}
1451
-	elseif (isset($_REQUEST['package']))
1513
+	} elseif (isset($_REQUEST['package']))
1452 1514
 	{
1453 1515
 		$base_name = basename($_REQUEST['package']);
1454 1516
 		$name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.'));
@@ -1458,12 +1520,14 @@  discard block
 block discarded – undo
1458 1520
 		$destination = $packagesdir . '/' . basename($_REQUEST['package']);
1459 1521
 	}
1460 1522
 
1461
-	if (!file_exists($destination))
1462
-		fatal_lang_error('package_no_file', false);
1523
+	if (!file_exists($destination)) {
1524
+			fatal_lang_error('package_no_file', false);
1525
+	}
1463 1526
 
1464 1527
 	// Make sure temp directory exists and is empty.
1465
-	if (file_exists($packagesdir . '/temp'))
1466
-		deltree($packagesdir . '/temp', false);
1528
+	if (file_exists($packagesdir . '/temp')) {
1529
+			deltree($packagesdir . '/temp', false);
1530
+	}
1467 1531
 
1468 1532
 	if (!mktree($packagesdir . '/temp', 0755))
1469 1533
 	{
@@ -1475,31 +1539,37 @@  discard block
 block discarded – undo
1475 1539
 			create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true));
1476 1540
 
1477 1541
 			deltree($packagesdir . '/temp', false);
1478
-			if (!mktree($packagesdir . '/temp', 0777))
1479
-				fatal_lang_error('package_cant_download', false);
1542
+			if (!mktree($packagesdir . '/temp', 0777)) {
1543
+							fatal_lang_error('package_cant_download', false);
1544
+			}
1480 1545
 		}
1481 1546
 	}
1482 1547
 
1483 1548
 	$extracted = read_tgz_file($destination, $packagesdir . '/temp');
1484
-	if (!$extracted)
1485
-		fatal_lang_error('packageget_unable', false, array('http://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name));
1486
-	if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml'))
1487
-		foreach ($extracted as $file)
1549
+	if (!$extracted) {
1550
+			fatal_lang_error('packageget_unable', false, array('http://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name));
1551
+	}
1552
+	if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) {
1553
+			foreach ($extracted as $file)
1488 1554
 			if (basename($file['filename']) == 'package-info.xml')
1489 1555
 			{
1490 1556
 				$base_path = dirname($file['filename']) . '/';
1557
+	}
1491 1558
 				break;
1492 1559
 			}
1493 1560
 
1494
-	if (!isset($base_path))
1495
-		$base_path = '';
1561
+	if (!isset($base_path)) {
1562
+			$base_path = '';
1563
+	}
1496 1564
 
1497
-	if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml'))
1498
-		fatal_lang_error('package_get_error_missing_xml', false);
1565
+	if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) {
1566
+			fatal_lang_error('package_get_error_missing_xml', false);
1567
+	}
1499 1568
 
1500 1569
 	$smileyInfo = getPackageInfo($context['filename']);
1501
-	if (!is_array($smileyInfo))
1502
-		fatal_lang_error($smileyInfo);
1570
+	if (!is_array($smileyInfo)) {
1571
+			fatal_lang_error($smileyInfo);
1572
+	}
1503 1573
 
1504 1574
 	// See if it is installed?
1505 1575
 	$request = $smcFunc['db_query']('', '
@@ -1515,8 +1585,9 @@  discard block
 block discarded – undo
1515 1585
 		)
1516 1586
 	);
1517 1587
 
1518
-	if ($smcFunc['db_num_rows']($request) > 0)
1519
-		fata_lang_error('package_installed_warning1');
1588
+	if ($smcFunc['db_num_rows']($request) > 0) {
1589
+			fata_lang_error('package_installed_warning1');
1590
+	}
1520 1591
 
1521 1592
 	// Everything is fine, now it's time to do something
1522 1593
 	$actions = parsePackageInfo($smileyInfo['xml'], true, 'install');
@@ -1533,23 +1604,23 @@  discard block
 block discarded – undo
1533 1604
 		{
1534 1605
 			$has_readme = true;
1535 1606
 			$type = 'package_' . $action['type'];
1536
-			if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename']))
1537
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r"));
1538
-			elseif (file_exists($action['filename']))
1539
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
1607
+			if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) {
1608
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r"));
1609
+			} elseif (file_exists($action['filename'])) {
1610
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
1611
+			}
1540 1612
 
1541 1613
 			if (!empty($action['parse_bbc']))
1542 1614
 			{
1543 1615
 				require_once($sourcedir . '/Subs-Post.php');
1544 1616
 				preparsecode($context[$type]);
1545 1617
 				$context[$type] = parse_bbc($context[$type]);
1618
+			} else {
1619
+							$context[$type] = nl2br($context[$type]);
1546 1620
 			}
1547
-			else
1548
-				$context[$type] = nl2br($context[$type]);
1549 1621
 
1550 1622
 			continue;
1551
-		}
1552
-		elseif ($action['type'] == 'require-dir')
1623
+		} elseif ($action['type'] == 'require-dir')
1553 1624
 		{
1554 1625
 			// Do this one...
1555 1626
 			$thisAction = array(
@@ -1568,12 +1639,12 @@  discard block
 block discarded – undo
1568 1639
 				);
1569 1640
 			}
1570 1641
 			// @todo None given?
1571
-			if (empty($thisAction['description']))
1572
-				$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
1642
+			if (empty($thisAction['description'])) {
1643
+							$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
1644
+			}
1573 1645
 
1574 1646
 			$context['actions'][] = $thisAction;
1575
-		}
1576
-		elseif ($action['type'] == 'credits')
1647
+		} elseif ($action['type'] == 'credits')
1577 1648
 		{
1578 1649
 			// Time to build the billboard
1579 1650
 			$credits_tag = array(
@@ -1632,12 +1703,14 @@  discard block
 block discarded – undo
1632 1703
 		cache_put_data('posting_smileys', null, 480);
1633 1704
 	}
1634 1705
 
1635
-	if (file_exists($packagesdir . '/temp'))
1636
-		deltree($packagesdir . '/temp');
1706
+	if (file_exists($packagesdir . '/temp')) {
1707
+			deltree($packagesdir . '/temp');
1708
+	}
1637 1709
 
1638
-	if (!$testing)
1639
-		redirectexit('action=admin;area=smileys');
1640
-}
1710
+	if (!$testing) {
1711
+			redirectexit('action=admin;area=smileys');
1712
+	}
1713
+	}
1641 1714
 
1642 1715
 /**
1643 1716
  * A function to import new smileys from an existing directory into the database.
@@ -1648,15 +1721,17 @@  discard block
 block discarded – undo
1648 1721
 {
1649 1722
 	global $modSettings, $smcFunc;
1650 1723
 
1651
-	if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath))
1652
-		fatal_lang_error('smiley_set_unable_to_import');
1724
+	if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) {
1725
+			fatal_lang_error('smiley_set_unable_to_import');
1726
+	}
1653 1727
 
1654 1728
 	$smileys = array();
1655 1729
 	$dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath);
1656 1730
 	while ($entry = $dir->read())
1657 1731
 	{
1658
-		if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png')))
1659
-			$smileys[strtolower($entry)] = $entry;
1732
+		if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) {
1733
+					$smileys[strtolower($entry)] = $entry;
1734
+		}
1660 1735
 	}
1661 1736
 	$dir->close();
1662 1737
 
@@ -1669,9 +1744,10 @@  discard block
 block discarded – undo
1669 1744
 			'smiley_list' => $smileys,
1670 1745
 		)
1671 1746
 	);
1672
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1673
-		if (isset($smileys[strtolower($row['filename'])]))
1747
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1748
+			if (isset($smileys[strtolower($row['filename'])]))
1674 1749
 			unset($smileys[strtolower($row['filename'])]);
1750
+	}
1675 1751
 	$smcFunc['db_free_result']($request);
1676 1752
 
1677 1753
 	$request = $smcFunc['db_query']('', '
@@ -1688,9 +1764,10 @@  discard block
 block discarded – undo
1688 1764
 	$smcFunc['db_free_result']($request);
1689 1765
 
1690 1766
 	$new_smileys = array();
1691
-	foreach ($smileys as $smiley)
1692
-		if (strlen($smiley) <= 48)
1767
+	foreach ($smileys as $smiley) {
1768
+			if (strlen($smiley) <= 48)
1693 1769
 			$new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order);
1770
+	}
1694 1771
 
1695 1772
 	if (!empty($new_smileys))
1696 1773
 	{
@@ -1755,8 +1832,9 @@  discard block
 block discarded – undo
1755 1832
 		if (isset($_POST['delete']) && !empty($_POST['checked_icons']))
1756 1833
 		{
1757 1834
 			$deleteIcons = array();
1758
-			foreach ($_POST['checked_icons'] as $icon)
1759
-				$deleteIcons[] = (int) $icon;
1835
+			foreach ($_POST['checked_icons'] as $icon) {
1836
+							$deleteIcons[] = (int) $icon;
1837
+			}
1760 1838
 
1761 1839
 			// Do the actual delete!
1762 1840
 			$smcFunc['db_query']('', '
@@ -1773,35 +1851,41 @@  discard block
 block discarded – undo
1773 1851
 			$_GET['icon'] = (int) $_GET['icon'];
1774 1852
 
1775 1853
 			// Do some preperation with the data... like check the icon exists *somewhere*
1776
-			if (strpos($_POST['icon_filename'], '.png') !== false)
1777
-				$_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
1778
-			if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png'))
1779
-				fatal_lang_error('icon_not_found');
1854
+			if (strpos($_POST['icon_filename'], '.png') !== false) {
1855
+							$_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4);
1856
+			}
1857
+			if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) {
1858
+							fatal_lang_error('icon_not_found');
1859
+			}
1780 1860
 			// There is a 16 character limit on message icons...
1781
-			elseif (strlen($_POST['icon_filename']) > 16)
1782
-				fatal_lang_error('icon_name_too_long');
1783
-			elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon']))
1784
-				fatal_lang_error('icon_after_itself');
1861
+			elseif (strlen($_POST['icon_filename']) > 16) {
1862
+							fatal_lang_error('icon_name_too_long');
1863
+			} elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) {
1864
+							fatal_lang_error('icon_after_itself');
1865
+			}
1785 1866
 
1786 1867
 			// First do the sorting... if this is an edit reduce the order of everything after it by one ;)
1787 1868
 			if ($_GET['icon'] != 0)
1788 1869
 			{
1789 1870
 				$oldOrder = $context['icons'][$_GET['icon']]['true_order'];
1790
-				foreach ($context['icons'] as $id => $data)
1791
-					if ($data['true_order'] > $oldOrder)
1871
+				foreach ($context['icons'] as $id => $data) {
1872
+									if ($data['true_order'] > $oldOrder)
1792 1873
 						$context['icons'][$id]['true_order']--;
1874
+				}
1793 1875
 			}
1794 1876
 
1795 1877
 			// If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql)
1796
-			if (empty($_GET['icon']) && empty($context['icons']))
1797
-				$_GET['icon'] = 1;
1878
+			if (empty($_GET['icon']) && empty($context['icons'])) {
1879
+							$_GET['icon'] = 1;
1880
+			}
1798 1881
 
1799 1882
 			// Get the new order.
1800 1883
 			$newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1;
1801 1884
 			// Do the same, but with the one that used to be after this icon, done to avoid conflict.
1802
-			foreach ($context['icons'] as $id => $data)
1803
-				if ($data['true_order'] >= $newOrder)
1885
+			foreach ($context['icons'] as $id => $data) {
1886
+							if ($data['true_order'] >= $newOrder)
1804 1887
 					$context['icons'][$id]['true_order']++;
1888
+			}
1805 1889
 
1806 1890
 			// Finally set the current icon's position!
1807 1891
 			$context['icons'][$_GET['icon']]['true_order'] = $newOrder;
@@ -1819,8 +1903,7 @@  discard block
 block discarded – undo
1819 1903
 				if ($id != 0)
1820 1904
 				{
1821 1905
 					$iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
1822
-				}
1823
-				else
1906
+				} else
1824 1907
 				{
1825 1908
 					$iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']);
1826 1909
 				}
@@ -1845,8 +1928,9 @@  discard block
 block discarded – undo
1845 1928
 		}
1846 1929
 
1847 1930
 		// Unless we're adding a new thing, we'll escape
1848
-		if (!isset($_POST['add']))
1849
-			redirectexit('action=admin;area=smileys;sa=editicons');
1931
+		if (!isset($_POST['add'])) {
1932
+					redirectexit('action=admin;area=smileys;sa=editicons');
1933
+		}
1850 1934
 	}
1851 1935
 
1852 1936
 	$context[$context['admin_menu_name']]['current_subsection'] = 'editicons';
@@ -1956,8 +2040,9 @@  discard block
 block discarded – undo
1956 2040
 		$context['new_icon'] = !isset($_GET['icon']);
1957 2041
 
1958 2042
 		// Get the properties of the current icon from the icon list.
1959
-		if (!$context['new_icon'])
1960
-			$context['icon'] = $context['icons'][$_GET['icon']];
2043
+		if (!$context['new_icon']) {
2044
+					$context['icon'] = $context['icons'][$_GET['icon']];
2045
+		}
1961 2046
 
1962 2047
 		// Get a list of boards needed for assigning this icon to a specific board.
1963 2048
 		$boardListOptions = array(
@@ -1991,8 +2076,9 @@  discard block
 block discarded – undo
1991 2076
 	);
1992 2077
 
1993 2078
 	$message_icons = array();
1994
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1995
-		$message_icons[] = $row;
2079
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2080
+			$message_icons[] = $row;
2081
+	}
1996 2082
 	$smcFunc['db_free_result']($request);
1997 2083
 
1998 2084
 	return $message_icons;
Please login to merge, or discard this patch.
Sources/Subs-Notify.php 1 patch
Braces   +17 added lines, -11 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('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * Fetches the list of preferences (or a single/subset of preferences) for
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 	// We want this as an array whether it is or not.
31 32
 	$members = is_array($members) ? $members : (array) $members;
32 33
 
33
-	if (!empty($prefs))
34
-		$prefs = is_array($prefs) ? $prefs : (array) $prefs;
34
+	if (!empty($prefs)) {
35
+			$prefs = is_array($prefs) ? $prefs : (array) $prefs;
36
+	}
35 37
 
36 38
 	$result = array();
37 39
 
@@ -56,9 +58,10 @@  discard block
 block discarded – undo
56 58
 	// We may want to keep the default values separate from a given user's. Or we might not.
57 59
 	if ($process_default && isset($result[0]))
58 60
 	{
59
-		foreach ($members as $member)
60
-			if (!isset($result[$member]))
61
+		foreach ($members as $member) {
62
+					if (!isset($result[$member]))
61 63
 				$result[$member] = $result[0];
64
+		}
62 65
 
63 66
 		unset ($result[0]);
64 67
 	}
@@ -76,12 +79,14 @@  discard block
 block discarded – undo
76 79
 {
77 80
 	global $smcFunc;
78 81
 
79
-	if (empty($prefs) || !is_int($memID))
80
-		return;
82
+	if (empty($prefs) || !is_int($memID)) {
83
+			return;
84
+	}
81 85
 
82 86
 	$update_rows = array();
83
-	foreach ($prefs as $k => $v)
84
-		$update_rows[] = array($memID, $k, $v);
87
+	foreach ($prefs as $k => $v) {
88
+			$update_rows[] = array($memID, $k, $v);
89
+	}
85 90
 
86 91
 	$smcFunc['db_insert']('replace',
87 92
 		'{db_prefix}user_alerts_prefs',
@@ -101,8 +106,9 @@  discard block
 block discarded – undo
101 106
 {
102 107
 	global $smcFunc;
103 108
 
104
-	if (empty($prefs) || empty($memID))
105
-		return;
109
+	if (empty($prefs) || empty($memID)) {
110
+			return;
111
+	}
106 112
 
107 113
 	$smcFunc['db_query']('', '
108 114
 		DELETE FROM {db_prefix}user_alerts_prefs
Please login to merge, or discard this patch.
Sources/ManageMaintenance.php 1 patch
Braces   +266 added lines, -197 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Main dispatcher, the maintenance access point.
@@ -96,14 +97,16 @@  discard block
 block discarded – undo
96 97
 	call_integration_hook('integrate_manage_maintenance', array(&$subActions));
97 98
 
98 99
 	// Yep, sub-action time!
99
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
100
-		$subAction = $_REQUEST['sa'];
101
-	else
102
-		$subAction = 'routine';
100
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
101
+			$subAction = $_REQUEST['sa'];
102
+	} else {
103
+			$subAction = 'routine';
104
+	}
103 105
 
104 106
 	// Doing something special?
105
-	if (isset($_REQUEST['activity']) && isset($subActions[$subAction]['activities'][$_REQUEST['activity']]))
106
-		$activity = $_REQUEST['activity'];
107
+	if (isset($_REQUEST['activity']) && isset($subActions[$subAction]['activities'][$_REQUEST['activity']])) {
108
+			$activity = $_REQUEST['activity'];
109
+	}
107 110
 
108 111
 	// Set a few things.
109 112
 	$context['page_title'] = $txt['maintain_title'];
@@ -114,12 +117,14 @@  discard block
 block discarded – undo
114 117
 	call_helper($subActions[$subAction]['function']);
115 118
 
116 119
 	// Any special activity?
117
-	if (isset($activity))
118
-		call_helper($subActions[$subAction]['activities'][$activity]);
120
+	if (isset($activity)) {
121
+			call_helper($subActions[$subAction]['activities'][$activity]);
122
+	}
119 123
 
120 124
 	//converted to UTF-8? show a small maintenance info
121
-	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8')
122
-		$context['maintenance_finished'] = $txt['utf8_title'];
125
+	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') {
126
+			$context['maintenance_finished'] = $txt['utf8_title'];
127
+	}
123 128
 
124 129
 	// Create a maintenance token.  Kinda hard to do it any other way.
125 130
 	createToken('admin-maint');
@@ -141,19 +146,22 @@  discard block
 block discarded – undo
141 146
 		db_extend('packages');
142 147
 
143 148
 		$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
144
-		foreach ($colData as $column)
145
-			if ($column['name'] == 'body')
149
+		foreach ($colData as $column) {
150
+					if ($column['name'] == 'body')
146 151
 				$body_type = $column['type'];
152
+		}
147 153
 
148 154
 		$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
149 155
 		$context['convert_to_suggest'] = ($body_type != 'text' && !empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] < 65536);
150 156
 	}
151 157
 
152
-	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8')
153
-		$context['maintenance_finished'] = $txt['utf8_title'];
154
-	if (isset($_GET['done']) && $_GET['done'] == 'convertentities')
155
-		$context['maintenance_finished'] = $txt['entity_convert_title'];
156
-}
158
+	if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') {
159
+			$context['maintenance_finished'] = $txt['utf8_title'];
160
+	}
161
+	if (isset($_GET['done']) && $_GET['done'] == 'convertentities') {
162
+			$context['maintenance_finished'] = $txt['entity_convert_title'];
163
+	}
164
+	}
157 165
 
158 166
 /**
159 167
  * Supporting function for the routine maintenance area.
@@ -162,9 +170,10 @@  discard block
 block discarded – undo
162 170
 {
163 171
 	global $context, $txt;
164 172
 
165
-	if (isset($_GET['done']) && $_GET['done'] == 'recount')
166
-		$context['maintenance_finished'] = $txt['maintain_recount'];
167
-}
173
+	if (isset($_GET['done']) && $_GET['done'] == 'recount') {
174
+			$context['maintenance_finished'] = $txt['maintain_recount'];
175
+	}
176
+	}
168 177
 
169 178
 /**
170 179
  * Supporting function for the members maintenance area.
@@ -195,8 +204,9 @@  discard block
 block discarded – undo
195 204
 	}
196 205
 	$smcFunc['db_free_result']($result);
197 206
 
198
-	if (isset($_GET['done']) && $_GET['done'] == 'recountposts')
199
-		$context['maintenance_finished'] = $txt['maintain_recountposts'];
207
+	if (isset($_GET['done']) && $_GET['done'] == 'recountposts') {
208
+			$context['maintenance_finished'] = $txt['maintain_recountposts'];
209
+	}
200 210
 
201 211
 	loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
202 212
 }
@@ -222,11 +232,12 @@  discard block
 block discarded – undo
222 232
 	$context['categories'] = array();
223 233
 	while ($row = $smcFunc['db_fetch_assoc']($result))
224 234
 	{
225
-		if (!isset($context['categories'][$row['id_cat']]))
226
-			$context['categories'][$row['id_cat']] = array(
235
+		if (!isset($context['categories'][$row['id_cat']])) {
236
+					$context['categories'][$row['id_cat']] = array(
227 237
 				'name' => $row['cat_name'],
228 238
 				'boards' => array()
229 239
 			);
240
+		}
230 241
 
231 242
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
232 243
 			'id' => $row['id_board'],
@@ -239,11 +250,12 @@  discard block
 block discarded – undo
239 250
 	require_once($sourcedir . '/Subs-Boards.php');
240 251
 	sortCategories($context['categories']);
241 252
 
242
-	if (isset($_GET['done']) && $_GET['done'] == 'purgeold')
243
-		$context['maintenance_finished'] = $txt['maintain_old'];
244
-	elseif (isset($_GET['done']) && $_GET['done'] == 'massmove')
245
-		$context['maintenance_finished'] = $txt['move_topics_maintenance'];
246
-}
253
+	if (isset($_GET['done']) && $_GET['done'] == 'purgeold') {
254
+			$context['maintenance_finished'] = $txt['maintain_old'];
255
+	} elseif (isset($_GET['done']) && $_GET['done'] == 'massmove') {
256
+			$context['maintenance_finished'] = $txt['move_topics_maintenance'];
257
+	}
258
+	}
247 259
 
248 260
 /**
249 261
  * Find and fix all errors on the forum.
@@ -351,15 +363,17 @@  discard block
 block discarded – undo
351 363
 	// Show me your badge!
352 364
 	isAllowedTo('admin_forum');
353 365
 
354
-	if ($db_type != 'mysql' && $db_type != 'mysqli')
355
-		return;
366
+	if ($db_type != 'mysql' && $db_type != 'mysqli') {
367
+			return;
368
+	}
356 369
 
357 370
 	db_extend('packages');
358 371
 
359 372
 	$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
360
-	foreach ($colData as $column)
361
-		if ($column['name'] == 'body')
373
+	foreach ($colData as $column) {
374
+			if ($column['name'] == 'body')
362 375
 			$body_type = $column['type'];
376
+	}
363 377
 
364 378
 	$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
365 379
 
@@ -369,19 +383,22 @@  discard block
 block discarded – undo
369 383
 		validateToken('admin-maint');
370 384
 
371 385
 		// Make it longer so we can do their limit.
372
-		if ($body_type == 'text')
373
-			$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext'));
386
+		if ($body_type == 'text') {
387
+					$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext'));
388
+		}
374 389
 		// Shorten the column so we can have a bit (literally per record) less space occupied
375
-		else
376
-			$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text'));
390
+		else {
391
+					$smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text'));
392
+		}
377 393
 
378 394
 		// 3rd party integrations may be interested in knowning about this.
379 395
 		call_integration_hook('integrate_convert_msgbody', array($body_type));
380 396
 
381 397
 		$colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
382
-		foreach ($colData as $column)
383
-			if ($column['name'] == 'body')
398
+		foreach ($colData as $column) {
399
+					if ($column['name'] == 'body')
384 400
 				$body_type = $column['type'];
401
+		}
385 402
 
386 403
 		$context['maintenance_finished'] = $txt[$context['convert_to'] . '_title'];
387 404
 		$context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text';
@@ -389,14 +406,14 @@  discard block
 block discarded – undo
389 406
 
390 407
 		return;
391 408
 		redirectexit('action=admin;area=maintain;sa=database');
392
-	}
393
-	elseif ($body_type != 'text' && (!isset($_POST['do_conversion']) || isset($_POST['cont'])))
409
+	} elseif ($body_type != 'text' && (!isset($_POST['do_conversion']) || isset($_POST['cont'])))
394 410
 	{
395 411
 		checkSession();
396
-		if (empty($_REQUEST['start']))
397
-			validateToken('admin-maint');
398
-		else
399
-			validateToken('admin-convertMsg');
412
+		if (empty($_REQUEST['start'])) {
413
+					validateToken('admin-maint');
414
+		} else {
415
+					validateToken('admin-convertMsg');
416
+		}
400 417
 
401 418
 		$context['page_title'] = $txt['not_done_title'];
402 419
 		$context['continue_post_data'] = '';
@@ -428,8 +445,9 @@  discard block
 block discarded – undo
428 445
 					'increment' => $increment - 1,
429 446
 				)
430 447
 			);
431
-			while ($row = $smcFunc['db_fetch_assoc']($request))
432
-				$id_msg_exceeding[] = $row['id_msg'];
448
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
449
+							$id_msg_exceeding[] = $row['id_msg'];
450
+			}
433 451
 			$smcFunc['db_free_result']($request);
434 452
 
435 453
 			$_REQUEST['start'] += $increment;
@@ -458,9 +476,9 @@  discard block
 block discarded – undo
458 476
 			{
459 477
 				$query_msg = array_slice($id_msg_exceeding, 0, 100);
460 478
 				$context['exceeding_messages_morethan'] = sprintf($txt['exceeding_messages_morethan'], count($id_msg_exceeding));
479
+			} else {
480
+							$query_msg = $id_msg_exceeding;
461 481
 			}
462
-			else
463
-				$query_msg = $id_msg_exceeding;
464 482
 
465 483
 			$context['exceeding_messages'] = array();
466 484
 			$request = $smcFunc['db_query']('', '
@@ -471,8 +489,9 @@  discard block
 block discarded – undo
471 489
 					'messages' => $query_msg,
472 490
 				)
473 491
 			);
474
-			while ($row = $smcFunc['db_fetch_assoc']($request))
475
-				$context['exceeding_messages'][] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
492
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
493
+							$context['exceeding_messages'][] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
494
+			}
476 495
 			$smcFunc['db_free_result']($request);
477 496
 		}
478 497
 	}
@@ -496,8 +515,9 @@  discard block
 block discarded – undo
496 515
 	isAllowedTo('admin_forum');
497 516
 
498 517
 	// Check to see if UTF-8 is currently the default character set.
499
-	if ($modSettings['global_character_set'] !== 'UTF-8' || !isset($db_character_set) || $db_character_set !== 'utf8')
500
-		fatal_lang_error('entity_convert_only_utf8');
518
+	if ($modSettings['global_character_set'] !== 'UTF-8' || !isset($db_character_set) || $db_character_set !== 'utf8') {
519
+			fatal_lang_error('entity_convert_only_utf8');
520
+	}
501 521
 
502 522
 	// Some starting values.
503 523
 	$context['table'] = empty($_REQUEST['table']) ? 0 : (int) $_REQUEST['table'];
@@ -559,8 +579,9 @@  discard block
 block discarded – undo
559 579
 		// Make sure we keep stuff unique!
560 580
 		$primary_keys = array();
561 581
 
562
-		if (function_exists('apache_reset_timeout'))
563
-			@apache_reset_timeout();
582
+		if (function_exists('apache_reset_timeout')) {
583
+					@apache_reset_timeout();
584
+		}
564 585
 
565 586
 		// Get a list of text columns.
566 587
 		$columns = array();
@@ -571,9 +592,10 @@  discard block
 block discarded – undo
571 592
 				'cur_table' => $cur_table,
572 593
 			)
573 594
 		);
574
-		while ($column_info = $smcFunc['db_fetch_assoc']($request))
575
-			if (strpos($column_info['Type'], 'text') !== false || strpos($column_info['Type'], 'char') !== false)
595
+		while ($column_info = $smcFunc['db_fetch_assoc']($request)) {
596
+					if (strpos($column_info['Type'], 'text') !== false || strpos($column_info['Type'], 'char') !== false)
576 597
 				$columns[] = strtolower($column_info['Field']);
598
+		}
577 599
 
578 600
 		// Get the column with the (first) primary key.
579 601
 		$request = $smcFunc['db_query']('', '
@@ -587,8 +609,9 @@  discard block
 block discarded – undo
587 609
 		{
588 610
 			if ($row['Key_name'] === 'PRIMARY')
589 611
 			{
590
-				if (empty($primary_key) || ($row['Seq_in_index'] == 1 && !in_array(strtolower($row['Column_name']), $columns)))
591
-					$primary_key = $row['Column_name'];
612
+				if (empty($primary_key) || ($row['Seq_in_index'] == 1 && !in_array(strtolower($row['Column_name']), $columns))) {
613
+									$primary_key = $row['Column_name'];
614
+				}
592 615
 
593 616
 				$primary_keys[] = $row['Column_name'];
594 617
 			}
@@ -597,8 +620,9 @@  discard block
 block discarded – undo
597 620
 
598 621
 		// No primary key, no glory.
599 622
 		// Same for columns. Just to be sure we've work to do!
600
-		if (empty($primary_key) || empty($columns))
601
-			continue;
623
+		if (empty($primary_key) || empty($columns)) {
624
+					continue;
625
+		}
602 626
 
603 627
 		// Get the maximum value for the primary key.
604 628
 		$request = $smcFunc['db_query']('', '
@@ -612,8 +636,9 @@  discard block
 block discarded – undo
612 636
 		list($max_value) = $smcFunc['db_fetch_row']($request);
613 637
 		$smcFunc['db_free_result']($request);
614 638
 
615
-		if (empty($max_value))
616
-			continue;
639
+		if (empty($max_value)) {
640
+					continue;
641
+		}
617 642
 
618 643
 		while ($context['start'] <= $max_value)
619 644
 		{
@@ -637,10 +662,11 @@  discard block
 block discarded – undo
637 662
 			{
638 663
 				$insertion_variables = array();
639 664
 				$changes = array();
640
-				foreach ($row as $column_name => $column_value)
641
-					if ($column_name !== $primary_key && strpos($column_value, '&#') !== false)
665
+				foreach ($row as $column_name => $column_value) {
666
+									if ($column_name !== $primary_key && strpos($column_value, '&#') !== false)
642 667
 					{
643 668
 						$changes[] = $column_name . ' = {string:changes_' . $column_name . '}';
669
+				}
644 670
 						$insertion_variables['changes_' . $column_name] = preg_replace_callback('~&#(\d{1,7}|x[0-9a-fA-F]{1,6});~', 'fixchar__callback', $column_value);
645 671
 					}
646 672
 
@@ -652,8 +678,8 @@  discard block
 block discarded – undo
652 678
 				}
653 679
 
654 680
 				// Update the row.
655
-				if (!empty($changes))
656
-					$smcFunc['db_query']('', '
681
+				if (!empty($changes)) {
682
+									$smcFunc['db_query']('', '
657 683
 						UPDATE {db_prefix}' . $cur_table . '
658 684
 						SET
659 685
 							' . implode(',
@@ -661,6 +687,7 @@  discard block
 block discarded – undo
661 687
 						WHERE ' . implode(' AND ', $where),
662 688
 						$insertion_variables
663 689
 					);
690
+				}
664 691
 			}
665 692
 			$smcFunc['db_free_result']($request);
666 693
 			$context['start'] += 500;
@@ -705,10 +732,11 @@  discard block
 block discarded – undo
705 732
 
706 733
 	checkSession('request');
707 734
 
708
-	if (!isset($_SESSION['optimized_tables']))
709
-		validateToken('admin-maint');
710
-	else
711
-		validateToken('admin-optimize', 'post', false);
735
+	if (!isset($_SESSION['optimized_tables'])) {
736
+			validateToken('admin-maint');
737
+	} else {
738
+			validateToken('admin-optimize', 'post', false);
739
+	}
712 740
 
713 741
 	ignore_user_abort(true);
714 742
 	db_extend();
@@ -727,13 +755,15 @@  discard block
 block discarded – undo
727 755
 	// Get a list of tables, as well as how many there are.
728 756
 	$temp_tables = $smcFunc['db_list_tables'](false, $real_prefix . '%');
729 757
 	$tables = array();
730
-	foreach ($temp_tables as $table)
731
-		$tables[] = array('table_name' => $table);
758
+	foreach ($temp_tables as $table) {
759
+			$tables[] = array('table_name' => $table);
760
+	}
732 761
 
733 762
 	// If there aren't any tables then I believe that would mean the world has exploded...
734 763
 	$context['num_tables'] = count($tables);
735
-	if ($context['num_tables'] == 0)
736
-		fatal_error('You appear to be running SMF in a flat file mode... fantastic!', false);
764
+	if ($context['num_tables'] == 0) {
765
+			fatal_error('You appear to be running SMF in a flat file mode... fantastic!', false);
766
+	}
737 767
 
738 768
 	$_REQUEST['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
739 769
 
@@ -744,8 +774,9 @@  discard block
 block discarded – undo
744 774
 	$_SESSION['optimized_tables'] = !empty($_SESSION['optimized_tables']) ? $_SESSION['optimized_tables'] : array();
745 775
 	for ($key=$_REQUEST['start']; $context['num_tables']-1; $key++)
746 776
 	{
747
-		if (empty($tables[$key]))
748
-			break;
777
+		if (empty($tables[$key])) {
778
+					break;
779
+		}
749 780
 
750 781
 		// Continue?
751 782
 		if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 10)
@@ -759,8 +790,9 @@  discard block
 block discarded – undo
759 790
 			createToken('admin-optimize');
760 791
 			$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-optimize_token_var'] . '" value="' . $context['admin-optimize_token'] . '">';
761 792
 
762
-			if (function_exists('apache_reset_timeout'))
763
-				apache_reset_timeout();
793
+			if (function_exists('apache_reset_timeout')) {
794
+							apache_reset_timeout();
795
+			}
764 796
 
765 797
 			return;
766 798
 		}
@@ -768,11 +800,12 @@  discard block
 block discarded – undo
768 800
 		// Optimize the table!  We use backticks here because it might be a custom table.
769 801
 		$data_freed = $smcFunc['db_optimize_table']($tables[$key]['table_name']);
770 802
 
771
-		if ($data_freed > 0)
772
-			$_SESSION['optimized_tables'][] = array(
803
+		if ($data_freed > 0) {
804
+					$_SESSION['optimized_tables'][] = array(
773 805
 				'name' => $tables[$key]['table_name'],
774 806
 				'data_freed' => $data_freed,
775 807
 			);
808
+		}
776 809
 	}
777 810
 
778 811
 	// Number of tables, etc...
@@ -807,10 +840,11 @@  discard block
 block discarded – undo
807 840
 	checkSession('request');
808 841
 
809 842
 	// validate the request or the loop
810
-	if (!isset($_REQUEST['step']))
811
-		validateToken('admin-maint');
812
-	else
813
-		validateToken('admin-boardrecount');
843
+	if (!isset($_REQUEST['step'])) {
844
+			validateToken('admin-maint');
845
+	} else {
846
+			validateToken('admin-boardrecount');
847
+	}
814 848
 
815 849
 	$context['page_title'] = $txt['not_done_title'];
816 850
 	$context['continue_post_data'] = '';
@@ -831,8 +865,9 @@  discard block
 block discarded – undo
831 865
 	$smcFunc['db_free_result']($request);
832 866
 
833 867
 	$increment = min(max(50, ceil($max_topics / 4)), 2000);
834
-	if (empty($_REQUEST['start']))
835
-		$_REQUEST['start'] = 0;
868
+	if (empty($_REQUEST['start'])) {
869
+			$_REQUEST['start'] = 0;
870
+	}
836 871
 
837 872
 	$total_steps = 8;
838 873
 
@@ -859,8 +894,8 @@  discard block
 block discarded – undo
859 894
 					'max_id' => $_REQUEST['start'] + $increment,
860 895
 				)
861 896
 			);
862
-			while ($row = $smcFunc['db_fetch_assoc']($request))
863
-				$smcFunc['db_query']('', '
897
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
898
+							$smcFunc['db_query']('', '
864 899
 					UPDATE {db_prefix}topics
865 900
 					SET num_replies = {int:num_replies}
866 901
 					WHERE id_topic = {int:id_topic}',
@@ -869,6 +904,7 @@  discard block
 block discarded – undo
869 904
 						'id_topic' => $row['id_topic'],
870 905
 					)
871 906
 				);
907
+			}
872 908
 			$smcFunc['db_free_result']($request);
873 909
 
874 910
 			// Recount unapproved messages
@@ -887,8 +923,8 @@  discard block
 block discarded – undo
887 923
 					'max_id' => $_REQUEST['start'] + $increment,
888 924
 				)
889 925
 			);
890
-			while ($row = $smcFunc['db_fetch_assoc']($request))
891
-				$smcFunc['db_query']('', '
926
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
927
+							$smcFunc['db_query']('', '
892 928
 					UPDATE {db_prefix}topics
893 929
 					SET unapproved_posts = {int:unapproved_posts}
894 930
 					WHERE id_topic = {int:id_topic}',
@@ -897,6 +933,7 @@  discard block
 block discarded – undo
897 933
 						'id_topic' => $row['id_topic'],
898 934
 					)
899 935
 				);
936
+			}
900 937
 			$smcFunc['db_free_result']($request);
901 938
 
902 939
 			$_REQUEST['start'] += $increment;
@@ -919,8 +956,8 @@  discard block
 block discarded – undo
919 956
 	// Update the post count of each board.
920 957
 	if ($_REQUEST['step'] <= 1)
921 958
 	{
922
-		if (empty($_REQUEST['start']))
923
-			$smcFunc['db_query']('', '
959
+		if (empty($_REQUEST['start'])) {
960
+					$smcFunc['db_query']('', '
924 961
 				UPDATE {db_prefix}boards
925 962
 				SET num_posts = {int:num_posts}
926 963
 				WHERE redirect = {string:redirect}',
@@ -929,6 +966,7 @@  discard block
 block discarded – undo
929 966
 					'redirect' => '',
930 967
 				)
931 968
 			);
969
+		}
932 970
 
933 971
 		while ($_REQUEST['start'] < $max_topics)
934 972
 		{
@@ -945,8 +983,8 @@  discard block
 block discarded – undo
945 983
 					'is_approved' => 1,
946 984
 				)
947 985
 			);
948
-			while ($row = $smcFunc['db_fetch_assoc']($request))
949
-				$smcFunc['db_query']('', '
986
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
987
+							$smcFunc['db_query']('', '
950 988
 					UPDATE {db_prefix}boards
951 989
 					SET num_posts = num_posts + {int:real_num_posts}
952 990
 					WHERE id_board = {int:id_board}',
@@ -955,6 +993,7 @@  discard block
 block discarded – undo
955 993
 						'real_num_posts' => $row['real_num_posts'],
956 994
 					)
957 995
 				);
996
+			}
958 997
 			$smcFunc['db_free_result']($request);
959 998
 
960 999
 			$_REQUEST['start'] += $increment;
@@ -977,14 +1016,15 @@  discard block
 block discarded – undo
977 1016
 	// Update the topic count of each board.
978 1017
 	if ($_REQUEST['step'] <= 2)
979 1018
 	{
980
-		if (empty($_REQUEST['start']))
981
-			$smcFunc['db_query']('', '
1019
+		if (empty($_REQUEST['start'])) {
1020
+					$smcFunc['db_query']('', '
982 1021
 				UPDATE {db_prefix}boards
983 1022
 				SET num_topics = {int:num_topics}',
984 1023
 				array(
985 1024
 					'num_topics' => 0,
986 1025
 				)
987 1026
 			);
1027
+		}
988 1028
 
989 1029
 		while ($_REQUEST['start'] < $max_topics)
990 1030
 		{
@@ -1001,8 +1041,8 @@  discard block
 block discarded – undo
1001 1041
 					'id_topic_max' => $_REQUEST['start'] + $increment,
1002 1042
 				)
1003 1043
 			);
1004
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1005
-				$smcFunc['db_query']('', '
1044
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1045
+							$smcFunc['db_query']('', '
1006 1046
 					UPDATE {db_prefix}boards
1007 1047
 					SET num_topics = num_topics + {int:real_num_topics}
1008 1048
 					WHERE id_board = {int:id_board}',
@@ -1011,6 +1051,7 @@  discard block
 block discarded – undo
1011 1051
 						'real_num_topics' => $row['real_num_topics'],
1012 1052
 					)
1013 1053
 				);
1054
+			}
1014 1055
 			$smcFunc['db_free_result']($request);
1015 1056
 
1016 1057
 			$_REQUEST['start'] += $increment;
@@ -1033,14 +1074,15 @@  discard block
 block discarded – undo
1033 1074
 	// Update the unapproved post count of each board.
1034 1075
 	if ($_REQUEST['step'] <= 3)
1035 1076
 	{
1036
-		if (empty($_REQUEST['start']))
1037
-			$smcFunc['db_query']('', '
1077
+		if (empty($_REQUEST['start'])) {
1078
+					$smcFunc['db_query']('', '
1038 1079
 				UPDATE {db_prefix}boards
1039 1080
 				SET unapproved_posts = {int:unapproved_posts}',
1040 1081
 				array(
1041 1082
 					'unapproved_posts' => 0,
1042 1083
 				)
1043 1084
 			);
1085
+		}
1044 1086
 
1045 1087
 		while ($_REQUEST['start'] < $max_topics)
1046 1088
 		{
@@ -1057,8 +1099,8 @@  discard block
 block discarded – undo
1057 1099
 					'is_approved' => 0,
1058 1100
 				)
1059 1101
 			);
1060
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1061
-				$smcFunc['db_query']('', '
1102
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1103
+							$smcFunc['db_query']('', '
1062 1104
 					UPDATE {db_prefix}boards
1063 1105
 					SET unapproved_posts = unapproved_posts + {int:unapproved_posts}
1064 1106
 					WHERE id_board = {int:id_board}',
@@ -1067,6 +1109,7 @@  discard block
 block discarded – undo
1067 1109
 						'unapproved_posts' => $row['real_unapproved_posts'],
1068 1110
 					)
1069 1111
 				);
1112
+			}
1070 1113
 			$smcFunc['db_free_result']($request);
1071 1114
 
1072 1115
 			$_REQUEST['start'] += $increment;
@@ -1089,14 +1132,15 @@  discard block
 block discarded – undo
1089 1132
 	// Update the unapproved topic count of each board.
1090 1133
 	if ($_REQUEST['step'] <= 4)
1091 1134
 	{
1092
-		if (empty($_REQUEST['start']))
1093
-			$smcFunc['db_query']('', '
1135
+		if (empty($_REQUEST['start'])) {
1136
+					$smcFunc['db_query']('', '
1094 1137
 				UPDATE {db_prefix}boards
1095 1138
 				SET unapproved_topics = {int:unapproved_topics}',
1096 1139
 				array(
1097 1140
 					'unapproved_topics' => 0,
1098 1141
 				)
1099 1142
 			);
1143
+		}
1100 1144
 
1101 1145
 		while ($_REQUEST['start'] < $max_topics)
1102 1146
 		{
@@ -1113,8 +1157,8 @@  discard block
 block discarded – undo
1113 1157
 					'id_topic_max' => $_REQUEST['start'] + $increment,
1114 1158
 				)
1115 1159
 			);
1116
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1117
-				$smcFunc['db_query']('', '
1160
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1161
+							$smcFunc['db_query']('', '
1118 1162
 					UPDATE {db_prefix}boards
1119 1163
 					SET unapproved_topics = unapproved_topics + {int:real_unapproved_topics}
1120 1164
 					WHERE id_board = {int:id_board}',
@@ -1123,6 +1167,7 @@  discard block
 block discarded – undo
1123 1167
 						'real_unapproved_topics' => $row['real_unapproved_topics'],
1124 1168
 					)
1125 1169
 				);
1170
+			}
1126 1171
 			$smcFunc['db_free_result']($request);
1127 1172
 
1128 1173
 			$_REQUEST['start'] += $increment;
@@ -1156,8 +1201,9 @@  discard block
 block discarded – undo
1156 1201
 				'is_not_deleted' => 0,
1157 1202
 			)
1158 1203
 		);
1159
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1160
-			updateMemberData($row['id_member'], array('instant_messages' => $row['real_num']));
1204
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1205
+					updateMemberData($row['id_member'], array('instant_messages' => $row['real_num']));
1206
+		}
1161 1207
 		$smcFunc['db_free_result']($request);
1162 1208
 
1163 1209
 		$request = $smcFunc['db_query']('', '
@@ -1172,8 +1218,9 @@  discard block
 block discarded – undo
1172 1218
 				'is_not_read' => 0,
1173 1219
 			)
1174 1220
 		);
1175
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1176
-			updateMemberData($row['id_member'], array('unread_messages' => $row['real_num']));
1221
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1222
+					updateMemberData($row['id_member'], array('unread_messages' => $row['real_num']));
1223
+		}
1177 1224
 		$smcFunc['db_free_result']($request);
1178 1225
 
1179 1226
 		if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 3)
@@ -1205,12 +1252,13 @@  discard block
 block discarded – undo
1205 1252
 				)
1206 1253
 			);
1207 1254
 			$boards = array();
1208
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1209
-				$boards[$row['id_board']][] = $row['id_msg'];
1255
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1256
+							$boards[$row['id_board']][] = $row['id_msg'];
1257
+			}
1210 1258
 			$smcFunc['db_free_result']($request);
1211 1259
 
1212
-			foreach ($boards as $board_id => $messages)
1213
-				$smcFunc['db_query']('', '
1260
+			foreach ($boards as $board_id => $messages) {
1261
+							$smcFunc['db_query']('', '
1214 1262
 					UPDATE {db_prefix}messages
1215 1263
 					SET id_board = {int:id_board}
1216 1264
 					WHERE id_msg IN ({array_int:id_msg_array})',
@@ -1219,6 +1267,7 @@  discard block
 block discarded – undo
1219 1267
 						'id_board' => $board_id,
1220 1268
 					)
1221 1269
 				);
1270
+			}
1222 1271
 
1223 1272
 			$_REQUEST['start'] += $increment;
1224 1273
 
@@ -1248,8 +1297,9 @@  discard block
 block discarded – undo
1248 1297
 		)
1249 1298
 	);
1250 1299
 	$realBoardCounts = array();
1251
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1252
-		$realBoardCounts[$row['id_board']] = $row['local_last_msg'];
1300
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1301
+			$realBoardCounts[$row['id_board']] = $row['local_last_msg'];
1302
+	}
1253 1303
 	$smcFunc['db_free_result']($request);
1254 1304
 
1255 1305
 	$request = $smcFunc['db_query']('', '
@@ -1269,18 +1319,20 @@  discard block
 block discarded – undo
1269 1319
 	krsort($resort_me);
1270 1320
 
1271 1321
 	$lastModifiedMsg = array();
1272
-	foreach ($resort_me as $rows)
1273
-		foreach ($rows as $row)
1322
+	foreach ($resort_me as $rows) {
1323
+			foreach ($rows as $row)
1274 1324
 		{
1275 1325
 			// The latest message is the latest of the current board and its children.
1276 1326
 			if (isset($lastModifiedMsg[$row['id_board']]))
1277 1327
 				$curLastModifiedMsg = max($row['local_last_msg'], $lastModifiedMsg[$row['id_board']]);
1278
-			else
1279
-				$curLastModifiedMsg = $row['local_last_msg'];
1328
+	}
1329
+			else {
1330
+							$curLastModifiedMsg = $row['local_last_msg'];
1331
+			}
1280 1332
 
1281 1333
 			// If what is and what should be the latest message differ, an update is necessary.
1282
-			if ($row['local_last_msg'] != $row['id_last_msg'] || $curLastModifiedMsg != $row['id_msg_updated'])
1283
-				$smcFunc['db_query']('', '
1334
+			if ($row['local_last_msg'] != $row['id_last_msg'] || $curLastModifiedMsg != $row['id_msg_updated']) {
1335
+							$smcFunc['db_query']('', '
1284 1336
 					UPDATE {db_prefix}boards
1285 1337
 					SET id_last_msg = {int:id_last_msg}, id_msg_updated = {int:id_msg_updated}
1286 1338
 					WHERE id_board = {int:id_board}',
@@ -1290,12 +1342,14 @@  discard block
 block discarded – undo
1290 1342
 						'id_board' => $row['id_board'],
1291 1343
 					)
1292 1344
 				);
1345
+			}
1293 1346
 
1294 1347
 			// Parent boards inherit the latest modified message of their children.
1295
-			if (isset($lastModifiedMsg[$row['id_parent']]))
1296
-				$lastModifiedMsg[$row['id_parent']] = max($row['local_last_msg'], $lastModifiedMsg[$row['id_parent']]);
1297
-			else
1298
-				$lastModifiedMsg[$row['id_parent']] = $row['local_last_msg'];
1348
+			if (isset($lastModifiedMsg[$row['id_parent']])) {
1349
+							$lastModifiedMsg[$row['id_parent']] = max($row['local_last_msg'], $lastModifiedMsg[$row['id_parent']]);
1350
+			} else {
1351
+							$lastModifiedMsg[$row['id_parent']] = $row['local_last_msg'];
1352
+			}
1299 1353
 		}
1300 1354
 
1301 1355
 	// Update all the basic statistics.
@@ -1367,8 +1421,9 @@  discard block
 block discarded – undo
1367 1421
 	require_once($sourcedir . '/Subs-Auth.php');
1368 1422
 	$members = findMembers($_POST['to']);
1369 1423
 
1370
-	if (empty($members))
1371
-		fatal_lang_error('reattribute_cannot_find_member');
1424
+	if (empty($members)) {
1425
+			fatal_lang_error('reattribute_cannot_find_member');
1426
+	}
1372 1427
 
1373 1428
 	$memID = array_shift($members);
1374 1429
 	$memID = $memID['id'];
@@ -1398,8 +1453,9 @@  discard block
 block discarded – undo
1398 1453
 		validateToken('admin-maint');
1399 1454
 
1400 1455
 		$groups = array();
1401
-		foreach ($_POST['groups'] as $id => $dummy)
1402
-			$groups[] = (int) $id;
1456
+		foreach ($_POST['groups'] as $id => $dummy) {
1457
+					$groups[] = (int) $id;
1458
+		}
1403 1459
 		$time_limit = (time() - ($_POST['maxdays'] * 24 * 3600));
1404 1460
 		$where_vars = array(
1405 1461
 			'time_limit' => $time_limit,
@@ -1408,9 +1464,9 @@  discard block
 block discarded – undo
1408 1464
 		{
1409 1465
 			$where = 'mem.date_registered < {int:time_limit} AND mem.is_activated = {int:is_activated}';
1410 1466
 			$where_vars['is_activated'] = 0;
1467
+		} else {
1468
+					$where = 'mem.last_login < {int:time_limit} AND (mem.last_login != 0 OR mem.date_registered < {int:time_limit})';
1411 1469
 		}
1412
-		else
1413
-			$where = 'mem.last_login < {int:time_limit} AND (mem.last_login != 0 OR mem.date_registered < {int:time_limit})';
1414 1470
 
1415 1471
 		// Need to get *all* groups then work out which (if any) we avoid.
1416 1472
 		$request = $smcFunc['db_query']('', '
@@ -1429,8 +1485,7 @@  discard block
 block discarded – undo
1429 1485
 				{
1430 1486
 					$where .= ' AND mem.id_post_group != {int:id_post_group_' . $row['id_group'] . '}';
1431 1487
 					$where_vars['id_post_group_' . $row['id_group']] = $row['id_group'];
1432
-				}
1433
-				else
1488
+				} else
1434 1489
 				{
1435 1490
 					$where .= ' AND mem.id_group != {int:id_group_' . $row['id_group'] . '} AND FIND_IN_SET({int:id_group_' . $row['id_group'] . '}, mem.additional_groups) = 0';
1436 1491
 					$where_vars['id_group_' . $row['id_group']] = $row['id_group'];
@@ -1457,8 +1512,9 @@  discard block
 block discarded – undo
1457 1512
 		$members = array();
1458 1513
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1459 1514
 		{
1460
-			if (!$row['is_mod'] || !in_array(3, $groups))
1461
-				$members[] = $row['id_member'];
1515
+			if (!$row['is_mod'] || !in_array(3, $groups)) {
1516
+							$members[] = $row['id_member'];
1517
+			}
1462 1518
 		}
1463 1519
 		$smcFunc['db_free_result']($request);
1464 1520
 
@@ -1505,8 +1561,9 @@  discard block
 block discarded – undo
1505 1561
 		)
1506 1562
 	);
1507 1563
 
1508
-	while ($row = $smcFunc['db_fetch_row']($request))
1509
-		$drafts[] = (int) $row[0];
1564
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1565
+			$drafts[] = (int) $row[0];
1566
+	}
1510 1567
 	$smcFunc['db_free_result']($request);
1511 1568
 
1512 1569
 	// If we have old drafts, remove them
@@ -1549,8 +1606,9 @@  discard block
 block discarded – undo
1549 1606
 	$sticky = isset($_POST['move_type_sticky']) || isset($_GET['sticky']);
1550 1607
 
1551 1608
 	// No boards then this is your stop.
1552
-	if (empty($id_board_from) || empty($id_board_to))
1553
-		return;
1609
+	if (empty($id_board_from) || empty($id_board_to)) {
1610
+			return;
1611
+	}
1554 1612
 
1555 1613
 	// The big WHERE clause
1556 1614
 	$conditions = 'WHERE t.id_board = {int:id_board_from}
@@ -1598,18 +1656,20 @@  discard block
 block discarded – undo
1598 1656
 		);
1599 1657
 		list ($total_topics) = $smcFunc['db_fetch_row']($request);
1600 1658
 		$smcFunc['db_free_result']($request);
1659
+	} else {
1660
+			$total_topics = (int) $_REQUEST['totaltopics'];
1601 1661
 	}
1602
-	else
1603
-		$total_topics = (int) $_REQUEST['totaltopics'];
1604 1662
 
1605 1663
 	// Seems like we need this here.
1606 1664
 	$context['continue_get_data'] = '?action=admin;area=maintain;sa=topics;activity=massmove;id_board_from=' . $id_board_from . ';id_board_to=' . $id_board_to . ';totaltopics=' . $total_topics . ';max_days=' . $max_days;
1607 1665
 
1608
-	if ($locked)
1609
-		$context['continue_get_data'] .= ';locked';
1666
+	if ($locked) {
1667
+			$context['continue_get_data'] .= ';locked';
1668
+	}
1610 1669
 
1611
-	if ($sticky)
1612
-		$context['continue_get_data'] .= ';sticky';
1670
+	if ($sticky) {
1671
+			$context['continue_get_data'] .= ';sticky';
1672
+	}
1613 1673
 
1614 1674
 	$context['continue_get_data'] .= ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1615 1675
 
@@ -1630,8 +1690,9 @@  discard block
 block discarded – undo
1630 1690
 
1631 1691
 			// Get the ids.
1632 1692
 			$topics = array();
1633
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1634
-				$topics[] = $row['id_topic'];
1693
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1694
+							$topics[] = $row['id_topic'];
1695
+			}
1635 1696
 
1636 1697
 			// Just return if we don't have any topics left to move.
1637 1698
 			if (empty($topics))
@@ -1722,9 +1783,9 @@  discard block
 block discarded – undo
1722 1783
 		// save it so we don't do this again for this task
1723 1784
 		list ($_SESSION['total_members']) = $smcFunc['db_fetch_row']($request);
1724 1785
 		$smcFunc['db_free_result']($request);
1786
+	} else {
1787
+			validateToken('admin-recountposts');
1725 1788
 	}
1726
-	else
1727
-		validateToken('admin-recountposts');
1728 1789
 
1729 1790
 	// Lets get a group of members and determine their post count (from the boards that have post count enabled of course).
1730 1791
 	$request = $smcFunc['db_query']('', '
@@ -1770,8 +1831,9 @@  discard block
 block discarded – undo
1770 1831
 		createToken('admin-recountposts');
1771 1832
 		$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-recountposts_token_var'] . '" value="' . $context['admin-recountposts_token'] . '">';
1772 1833
 
1773
-		if (function_exists('apache_reset_timeout'))
1774
-			apache_reset_timeout();
1834
+		if (function_exists('apache_reset_timeout')) {
1835
+					apache_reset_timeout();
1836
+		}
1775 1837
 		return;
1776 1838
 	}
1777 1839
 
@@ -1857,10 +1919,9 @@  discard block
 block discarded – undo
1857 1919
 		checkSession('request');
1858 1920
 		validateToken('admin-hook', 'request');
1859 1921
 
1860
-		if ($_REQUEST['do'] == 'remove')
1861
-			remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
1862
-
1863
-		else
1922
+		if ($_REQUEST['do'] == 'remove') {
1923
+					remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
1924
+		} else
1864 1925
 		{
1865 1926
 			$function_remove = urldecode($_REQUEST['function']) . (($_REQUEST['do'] == 'disable') ? '' : '!');
1866 1927
 			$function_add = urldecode($_REQUEST['function']) . (($_REQUEST['do'] == 'disable') ? '!' : '');
@@ -1910,11 +1971,11 @@  discard block
 block discarded – undo
1910 1971
 						// Show a nice icon to indicate this is an instance.
1911 1972
 						$instance = (!empty($data['instance']) ? '<span class="generic_icons news" title="'. $txt['hooks_field_function_method'] .'"></span> ' : '');
1912 1973
 
1913
-						if (!empty($data['included_file']))
1914
-							return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file'];
1915
-
1916
-						else
1917
-							return $instance . $data['real_function'];
1974
+						if (!empty($data['included_file'])) {
1975
+													return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file'];
1976
+						} else {
1977
+													return $instance . $data['real_function'];
1978
+						}
1918 1979
 					},
1919 1980
 				),
1920 1981
 				'sort' =>  array(
@@ -1979,11 +2040,12 @@  discard block
 block discarded – undo
1979 2040
 		'data' => array(
1980 2041
 			'function' => function ($data) use ($txt, $scripturl, $context)
1981 2042
 			{
1982
-				if (!$data['hook_exists'])
1983
-					return '
2043
+				if (!$data['hook_exists']) {
2044
+									return '
1984 2045
 					<a href="' . $scripturl . '?action=admin;area=maintain;sa=hooks;do=remove;hook=' . $data['hook_name'] . ';function=' . urlencode($data['function_name']) . $context['filter_url'] . ';' . $context['admin-hook_token_var'] . '=' . $context['admin-hook_token'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" data-confirm="' . $txt['quickmod_confirm'] . '" class="you_sure">
1985 2046
 						<span class="generic_icons delete" title="' . $txt['hooks_button_remove'] . '"></span>
1986 2047
 					</a>';
2048
+				}
1987 2049
 			},
1988 2050
 			'class' => 'centertext',
1989 2051
 		),
@@ -2018,10 +2080,11 @@  discard block
 block discarded – undo
2018 2080
 		{
2019 2081
 			if ($file != '.' && $file != '..')
2020 2082
 			{
2021
-				if (is_dir($dir_path . '/' . $file))
2022
-					$files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
2023
-				else
2024
-					$files[] = array('dir' => $dir_path, 'name' => $file);
2083
+				if (is_dir($dir_path . '/' . $file)) {
2084
+									$files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
2085
+				} else {
2086
+									$files[] = array('dir' => $dir_path, 'name' => $file);
2087
+				}
2025 2088
 			}
2026 2089
 		}
2027 2090
 	}
@@ -2070,16 +2133,16 @@  discard block
 block discarded – undo
2070 2133
 							// I need to know if there is at least one function called in this file.
2071 2134
 							$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2072 2135
 							unset($temp_hooks[$hook][$rawFunc]);
2073
-						}
2074
-						elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($hookParsedData['pureFunc']) . '(') !== false)
2136
+						} elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($hookParsedData['pureFunc']) . '(') !== false)
2075 2137
 						{
2076 2138
 							$hook_status[$hook][$hookParsedData['pureFunc']] = $hookParsedData;
2077 2139
 							$hook_status[$hook][$hookParsedData['pureFunc']]['exists'] = true;
2078 2140
 							$hook_status[$hook][$hookParsedData['pureFunc']]['in_file'] = (!empty($file['name']) ? $file['name'] : (!empty($hookParsedData['hookFile']) ? $hookParsedData['hookFile'] : ''));
2079 2141
 
2080 2142
 							// Does the hook has its own file?
2081
-							if (!empty($hookParsedData['hookFile']))
2082
-								$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2143
+							if (!empty($hookParsedData['hookFile'])) {
2144
+															$temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']);
2145
+							}
2083 2146
 
2084 2147
 							// I want to remember all the functions called within this file (to check later if they are enabled or disabled and decide if the integrare_*_include of that file can be disabled too)
2085 2148
 							$temp_data['function'][$file['name']][$hookParsedData['pureFunc']] = $hookParsedData['enabled'];
@@ -2106,15 +2169,17 @@  discard block
 block discarded – undo
2106 2169
 	$sort = array();
2107 2170
 	$hooks_filters = array();
2108 2171
 
2109
-	foreach ($hooks as $hook => $functions)
2110
-		$hooks_filters[] = '<option' . ($context['current_filter'] == $hook ? ' selected ' : '') . ' value="' . $hook . '">' . $hook . '</option>';
2172
+	foreach ($hooks as $hook => $functions) {
2173
+			$hooks_filters[] = '<option' . ($context['current_filter'] == $hook ? ' selected ' : '') . ' value="' . $hook . '">' . $hook . '</option>';
2174
+	}
2111 2175
 
2112
-	if (!empty($hooks_filters))
2113
-		$context['insert_after_template'] .= '
2176
+	if (!empty($hooks_filters)) {
2177
+			$context['insert_after_template'] .= '
2114 2178
 		<script>
2115 2179
 			var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\');
2116 2180
 			hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;" onchange="window.location=(\'' . $scripturl . '?action=admin;area=maintain;sa=hooks\' + (this.value ? \';filter=\' + this.value : \'\'));"><option value="">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>'). ';
2117 2181
 		</script>';
2182
+	}
2118 2183
 
2119 2184
 	$temp_data = array();
2120 2185
 	$id = 0;
@@ -2157,10 +2222,11 @@  discard block
 block discarded – undo
2157 2222
 
2158 2223
 	foreach ($temp_data as $data)
2159 2224
 	{
2160
-		if (++$counter < $start)
2161
-			continue;
2162
-		elseif ($counter == $start + $per_page)
2163
-			break;
2225
+		if (++$counter < $start) {
2226
+					continue;
2227
+		} elseif ($counter == $start + $per_page) {
2228
+					break;
2229
+		}
2164 2230
 
2165 2231
 		$hooks_data[] = $data;
2166 2232
 	}
@@ -2182,13 +2248,15 @@  discard block
 block discarded – undo
2182 2248
 	$hooks_count = 0;
2183 2249
 
2184 2250
 	$context['filter'] = false;
2185
-	if (isset($_GET['filter']))
2186
-		$context['filter'] = $_GET['filter'];
2251
+	if (isset($_GET['filter'])) {
2252
+			$context['filter'] = $_GET['filter'];
2253
+	}
2187 2254
 
2188 2255
 	foreach ($hooks as $hook => $functions)
2189 2256
 	{
2190
-		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
2191
-			$hooks_count += count($functions);
2257
+		if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook)) {
2258
+					$hooks_count += count($functions);
2259
+		}
2192 2260
 	}
2193 2261
 
2194 2262
 	return $hooks_count;
@@ -2209,8 +2277,9 @@  discard block
 block discarded – undo
2209 2277
 		$integration_hooks = array();
2210 2278
 		foreach ($modSettings as $key => $value)
2211 2279
 		{
2212
-			if (!empty($value) && substr($key, 0, 10) === 'integrate_')
2213
-				$integration_hooks[$key] = explode(',', $value);
2280
+			if (!empty($value) && substr($key, 0, 10) === 'integrate_') {
2281
+							$integration_hooks[$key] = explode(',', $value);
2282
+			}
2214 2283
 		}
2215 2284
 	}
2216 2285
 
@@ -2241,8 +2310,9 @@  discard block
 block discarded – undo
2241 2310
 	);
2242 2311
 
2243 2312
 	// Meh...
2244
-	if (empty($rawData))
2245
-		return $hookData;
2313
+	if (empty($rawData)) {
2314
+			return $hookData;
2315
+	}
2246 2316
 
2247 2317
 	// For convenience purposes only!
2248 2318
 	$modFunc = $rawData;
@@ -2253,11 +2323,11 @@  discard block
 block discarded – undo
2253 2323
 		list ($hookData['hookFile'], $modFunc) = explode('|', $modFunc);
2254 2324
 
2255 2325
 		// Does the file exists? who knows!
2256
-		if (empty($settings['theme_dir']))
2257
-			$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
2258
-
2259
-		else
2260
-			$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2326
+		if (empty($settings['theme_dir'])) {
2327
+					$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
2328
+		} else {
2329
+					$hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2330
+		}
2261 2331
 
2262 2332
 		$hookData['fileExists'] = file_exists($hookData['absPath']);
2263 2333
 		$hookData['hookFile'] = basename($hookData['hookFile']);
@@ -2282,11 +2352,10 @@  discard block
 block discarded – undo
2282 2352
 	{
2283 2353
 		list ($hookData['class'], $hookData['method']) = explode('::', $modFunc);
2284 2354
 		$hookData['pureFunc'] = $hookData['method'];
2355
+	} else {
2356
+			$hookData['pureFunc'] = $modFunc;
2285 2357
 	}
2286 2358
 
2287
-	else
2288
-		$hookData['pureFunc'] = $modFunc;
2289
-
2290 2359
 	return $hookData;
2291 2360
 }
2292 2361
 
Please login to merge, or discard this patch.
Sources/Subscriptions-PayPal.php 1 patch
Braces   +83 added lines, -61 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
 // This won't be dedicated without this - this must exist in each gateway!
15 15
 // SMF Payment Gateway: paypal
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Class for returning available form data for this gateway
@@ -118,8 +119,7 @@  discard block
 block discarded – undo
118 119
 		{
119 120
 			$return_data['hidden']['p3'] = 1;
120 121
 			$return_data['hidden']['t3'] = strtoupper(substr($period, 0, 1));
121
-		}
122
-		else
122
+		} else
123 123
 		{
124 124
 			preg_match('~(\d*)(\w)~', $sub_data['real_length'], $match);
125 125
 			$unit = $match[1];
@@ -130,14 +130,15 @@  discard block
 block discarded – undo
130 130
 		}
131 131
 
132 132
 		// If it's repeatable do some javascript to respect this idea.
133
-		if (!empty($sub_data['repeatable']))
134
-			$return_data['javascript'] = '
133
+		if (!empty($sub_data['repeatable'])) {
134
+					$return_data['javascript'] = '
135 135
 				document.write(\'<label for="do_paypal_recur"><input type="checkbox" name="do_paypal_recur" id="do_paypal_recur" checked onclick="switchPaypalRecur();" class="input_check">' . $txt['paid_make_recurring'] . '</label><br>\');
136 136
 
137 137
 				function switchPaypalRecur()
138 138
 				{
139 139
 					document.getElementById("paypal_cmd").value = document.getElementById("do_paypal_recur").checked ? "_xclick-subscriptions" : "_xclick";
140 140
 				}';
141
+		}
141 142
 
142 143
 		return $return_data;
143 144
 	}
@@ -160,20 +161,24 @@  discard block
 block discarded – undo
160 161
 		global $modSettings;
161 162
 
162 163
 		// Has the user set up an email address?
163
-		if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email'])))
164
-			return false;
164
+		if ((empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_email'])) || (!empty($modSettings['paidsubs_test']) && empty($modSettings['paypal_sandbox_email']))) {
165
+					return false;
166
+		}
165 167
 		// Check the correct transaction types are even here.
166
-		if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email'])))
167
-			return false;
168
+		if ((!isset($_POST['txn_type']) && !isset($_POST['payment_status'])) || (!isset($_POST['business']) && !isset($_POST['receiver_email']))) {
169
+					return false;
170
+		}
168 171
 		// Correct email address?
169
-		if (!isset($_POST['business']))
170
-			$_POST['business'] = $_POST['receiver_email'];
172
+		if (!isset($_POST['business'])) {
173
+					$_POST['business'] = $_POST['receiver_email'];
174
+		}
171 175
 
172 176
 		// Are we testing?
173
-		if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails'])))))
174
-			return false;
175
-		elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails']))))
176
-			return false;
177
+		if (empty($modSettings['paidsubs_test']) && strtolower($modSettings['paypal_sandbox_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) {
178
+					return false;
179
+		} elseif (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', $modSettings['paypal_additional_emails'])))) {
180
+					return false;
181
+		}
177 182
 		return true;
178 183
 	}
179 184
 
@@ -192,15 +197,17 @@  discard block
 block discarded – undo
192 197
 		global $modSettings, $txt;
193 198
 
194 199
 		// Put this to some default value.
195
-		if (!isset($_POST['txn_type']))
196
-			$_POST['txn_type'] = '';
200
+		if (!isset($_POST['txn_type'])) {
201
+					$_POST['txn_type'] = '';
202
+		}
197 203
 
198 204
 		// Build the request string - starting with the minimum requirement.
199 205
 		$requestString = 'cmd=_notify-validate';
200 206
 
201 207
 		// Now my dear, add all the posted bits in the order we got them
202
-		foreach ($_POST as $k => $v)
203
-			$requestString .= '&' . $k . '=' . urlencode($v);
208
+		foreach ($_POST as $k => $v) {
209
+					$requestString .= '&' . $k . '=' . urlencode($v);
210
+		}
204 211
 
205 212
 		// Can we use curl?
206 213
 		if (function_exists('curl_init') && $curl = curl_init((!empty($modSettings['paidsubs_test']) ? 'https://www.sandbox.' : 'http://www.') . 'paypal.com/cgi-bin/webscr'))
@@ -240,14 +247,16 @@  discard block
 block discarded – undo
240 247
 			$header .= 'Connection: close' . "\r\n\r\n";
241 248
 
242 249
 			// Open the connection.
243
-			if (!empty($modSettings['paidsubs_test']))
244
-				$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
245
-			else
246
-				$fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
250
+			if (!empty($modSettings['paidsubs_test'])) {
251
+							$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
252
+			} else {
253
+							$fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
254
+			}
247 255
 
248 256
 			// Did it work?
249
-			if (!$fp)
250
-				generateSubscriptionError($txt['paypal_could_not_connect']);
257
+			if (!$fp) {
258
+							generateSubscriptionError($txt['paypal_could_not_connect']);
259
+			}
251 260
 
252 261
 			// Put the data to the port.
253 262
 			fputs($fp, $header . $requestString);
@@ -256,8 +265,9 @@  discard block
 block discarded – undo
256 265
 			while (!feof($fp))
257 266
 			{
258 267
 				$this->return_data = fgets($fp, 1024);
259
-				if (strcmp(trim($this->return_data), 'VERIFIED') === 0)
260
-					break;
268
+				if (strcmp(trim($this->return_data), 'VERIFIED') === 0) {
269
+									break;
270
+				}
261 271
 			}
262 272
 
263 273
 			// Clean up.
@@ -265,28 +275,34 @@  discard block
 block discarded – undo
265 275
 		}
266 276
 
267 277
 		// If this isn't verified then give up...
268
-		if (strcmp(trim($this->return_data), 'VERIFIED') !== 0)
269
-			exit;
278
+		if (strcmp(trim($this->return_data), 'VERIFIED') !== 0) {
279
+					exit;
280
+		}
270 281
 
271 282
 		// Check that this is intended for us.
272
-		if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails'])))))
273
-			exit;
283
+		if (strtolower($modSettings['paypal_email']) != strtolower($_POST['business']) && (empty($modSettings['paypal_additional_emails']) || !in_array(strtolower($_POST['business']), explode(',', strtolower($modSettings['paypal_additional_emails']))))) {
284
+					exit;
285
+		}
274 286
 
275 287
 		// Is this a subscription - and if so is it a secondary payment that we need to process?
276 288
 		// If so, make sure we get it in the expected format. Seems PayPal sometimes sends it without urlencoding.
277
-		if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false)
278
-			$_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']);
279
-		if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false))
280
-			// Calculate the subscription it relates to!
289
+		if (!empty($_POST['item_number']) && strpos($_POST['item_number'], ' ') !== false) {
290
+					$_POST['item_number'] = str_replace(' ', '+', $_POST['item_number']);
291
+		}
292
+		if ($this->isSubscription() && (empty($_POST['item_number']) || strpos($_POST['item_number'], '+') === false)) {
293
+					// Calculate the subscription it relates to!
281 294
 			$this->_findSubscription();
295
+		}
282 296
 
283 297
 		// Verify the currency!
284
-		if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code']))
285
-			exit;
298
+		if (strtolower($_POST['mc_currency']) !== strtolower($modSettings['paid_currency_code'])) {
299
+					exit;
300
+		}
286 301
 
287 302
 		// Can't exist if it doesn't contain anything.
288
-		if (empty($_POST['item_number']))
289
-			exit;
303
+		if (empty($_POST['item_number'])) {
304
+					exit;
305
+		}
290 306
 
291 307
 		// Return the id_sub and id_member
292 308
 		return explode('+', $_POST['item_number']);
@@ -299,10 +315,11 @@  discard block
 block discarded – undo
299 315
 	 */
300 316
 	public function isRefund()
301 317
 	{
302
-		if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed'))
303
-			return true;
304
-		else
305
-			return false;
318
+		if ($_POST['payment_status'] === 'Refunded' || $_POST['payment_status'] === 'Reversed' || $_POST['txn_type'] === 'Refunded' || ($_POST['txn_type'] === 'reversal' && $_POST['payment_status'] === 'Completed')) {
319
+					return true;
320
+		} else {
321
+					return false;
322
+		}
306 323
 	}
307 324
 
308 325
 	/**
@@ -312,10 +329,11 @@  discard block
 block discarded – undo
312 329
 	 */
313 330
 	public function isSubscription()
314 331
 	{
315
-		if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed')
316
-			return true;
317
-		else
318
-			return false;
332
+		if (substr($_POST['txn_type'], 0, 14) === 'subscr_payment' && $_POST['payment_status'] === 'Completed') {
333
+					return true;
334
+		} else {
335
+					return false;
336
+		}
319 337
 	}
320 338
 
321 339
 	/**
@@ -325,10 +343,11 @@  discard block
 block discarded – undo
325 343
 	 */
326 344
 	public function isPayment()
327 345
 	{
328
-		if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept')
329
-			return true;
330
-		else
331
-			return false;
346
+		if ($_POST['payment_status'] === 'Completed' && $_POST['txn_type'] === 'web_accept') {
347
+					return true;
348
+		} else {
349
+					return false;
350
+		}
332 351
 	}
333 352
 
334 353
 	/**
@@ -341,10 +360,11 @@  discard block
 block discarded – undo
341 360
 		// subscr_cancel is sent when the user cancels, subscr_eot is sent when the subscription reaches final payment
342 361
 		// Neither require us to *do* anything as per performCancel().
343 362
 		// subscr_eot, if sent, indicates an end of payments term.
344
-		if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot')
345
-			return true;
346
-		else
347
-			return false;
363
+		if (substr($_POST['txn_type'], 0, 13) === 'subscr_cancel' || substr($_POST['txn_type'], 0, 10) === 'subscr_eot') {
364
+					return true;
365
+		} else {
366
+					return false;
367
+		}
348 368
 	}
349 369
 
350 370
 	/**
@@ -409,8 +429,9 @@  discard block
 block discarded – undo
409 429
 		global $smcFunc;
410 430
 
411 431
 		// Assume we have this?
412
-		if (empty($_POST['subscr_id']))
413
-			return false;
432
+		if (empty($_POST['subscr_id'])) {
433
+					return false;
434
+		}
414 435
 
415 436
 		// Do we have this in the database?
416 437
 		$request = $smcFunc['db_query']('', '
@@ -439,11 +460,12 @@  discard block
 block discarded – undo
439 460
 						'payer_email' => $_POST['payer_email'],
440 461
 					)
441 462
 				);
442
-				if ($smcFunc['db_num_rows']($request) === 0)
443
-					return false;
463
+				if ($smcFunc['db_num_rows']($request) === 0) {
464
+									return false;
465
+				}
466
+			} else {
467
+							return false;
444 468
 			}
445
-			else
446
-				return false;
447 469
 		}
448 470
 		list ($member_id, $subscription_id) = $smcFunc['db_fetch_row']($request);
449 471
 		$_POST['item_number'] = $member_id . '+' . $subscription_id;
Please login to merge, or discard this patch.
Sources/Class-CurlFetchWeb.php 1 patch
Braces   +30 added lines, -24 removed lines patch added patch discarded remove patch
@@ -10,8 +10,9 @@  discard block
 block discarded – undo
10 10
  * @version 2.1 Beta 3
11 11
  */
12 12
 
13
-if (!defined('SMF'))
13
+if (!defined('SMF')) {
14 14
 	die('No direct access...');
15
+}
15 16
 
16 17
 /**
17 18
  * Class curl_fetch_web_data
@@ -87,10 +88,11 @@  discard block
 block discarded – undo
87 88
 	public function get_url_data($url, $post_data = array())
88 89
 	{
89 90
 		// POSTing some data perhaps?
90
-		if (!empty($post_data) && is_array($post_data))
91
-			$this->post_data = $this->build_post_data($post_data);
92
-		elseif (!empty($post_data))
93
-			$this->post_data = trim($post_data);
91
+		if (!empty($post_data) && is_array($post_data)) {
92
+					$this->post_data = $this->build_post_data($post_data);
93
+		} elseif (!empty($post_data)) {
94
+					$this->post_data = trim($post_data);
95
+		}
94 96
 
95 97
 		// set the options and get it
96 98
 		$this->set_options();
@@ -111,10 +113,11 @@  discard block
 block discarded – undo
111 113
 	private function curl_request($url, $redirect = false)
112 114
 	{
113 115
 		// we do have a url I hope
114
-		if ($url == '')
115
-			return false;
116
-		else
117
-			$this->options[CURLOPT_URL] = $url;
116
+		if ($url == '') {
117
+					return false;
118
+		} else {
119
+					$this->options[CURLOPT_URL] = $url;
120
+		}
118 121
 
119 122
 		// if we have not already been redirected, set it up so we can if needed
120 123
 		if (!$redirect)
@@ -194,10 +197,11 @@  discard block
 block discarded – undo
194 197
 		$max_result = count($this->response) - 1;
195 198
 
196 199
 		// just return a specifed area or the entire result?
197
-		if ($area == '')
198
-			return $this->response[$max_result];
199
-		else
200
-			return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result];
200
+		if ($area == '') {
201
+					return $this->response[$max_result];
202
+		} else {
203
+					return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result];
204
+		}
201 205
 	}
202 206
 
203 207
 	/**
@@ -210,9 +214,9 @@  discard block
 block discarded – undo
210 214
 	*/
211 215
 	public function result_raw($response_number = '')
212 216
 	{
213
-		if (!is_numeric($response_number))
214
-			return $this->response;
215
-		else
217
+		if (!is_numeric($response_number)) {
218
+					return $this->response;
219
+		} else
216 220
 		{
217 221
 			$response_number = min($response_number, count($this->response) - 1);
218 222
 			return $this->response[$response_number];
@@ -234,13 +238,14 @@  discard block
 block discarded – undo
234 238
 			$postvars = array();
235 239
 
236 240
 			// build the post data, drop ones with leading @'s since those can be used to send files, we don't support that.
237
-			foreach ($post_data as $name => $value)
238
-				$postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value);
241
+			foreach ($post_data as $name => $value) {
242
+							$postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value);
243
+			}
239 244
 
240 245
 			return implode('&', $postvars);
246
+		} else {
247
+					return $post_data;
241 248
 		}
242
-		else
243
-			return $post_data;
244 249
 
245 250
 	}
246 251
 
@@ -261,9 +266,9 @@  discard block
 block discarded – undo
261 266
 			$keys = array_merge(array_keys($this->default_options), array_keys($this->user_options));
262 267
 			$vals = array_merge($this->default_options, $this->user_options);
263 268
 			$this->options = array_combine($keys, $vals);
269
+		} else {
270
+					$this->options = $this->default_options;
264 271
 		}
265
-		else
266
-			$this->options = $this->default_options;
267 272
 
268 273
 		// POST data options, here we don't allow any overide
269 274
 		if (isset($this->post_data))
@@ -302,8 +307,9 @@  discard block
 block discarded – undo
302 307
 		$temp = explode(': ', $_header, 2);
303 308
 
304 309
 		// set proper headers only
305
-		if (isset($temp[0]) && isset($temp[1]))
306
-			$this->headers[strtolower($temp[0])] = strtolower(trim($temp[1]));
310
+		if (isset($temp[0]) && isset($temp[1])) {
311
+					$this->headers[strtolower($temp[0])] = strtolower(trim($temp[1]));
312
+		}
307 313
 
308 314
 		// return the length of what was passed unless you want a Failed writing header error ;)
309 315
 		return strlen($header);
Please login to merge, or discard this patch.