Completed
Push — release-2.1 ( 43ad68...be71e6 )
by Colin
14:58 queued 07:23
created
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();">' . $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.' : 'https://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
 	/**
@@ -408,8 +428,9 @@  discard block
 block discarded – undo
408 428
 		global $smcFunc;
409 429
 
410 430
 		// Assume we have this?
411
-		if (empty($_POST['subscr_id']))
412
-			return false;
431
+		if (empty($_POST['subscr_id'])) {
432
+					return false;
433
+		}
413 434
 
414 435
 		// Do we have this in the database?
415 436
 		$request = $smcFunc['db_query']('', '
@@ -438,11 +459,12 @@  discard block
 block discarded – undo
438 459
 						'payer_email' => $_POST['payer_email'],
439 460
 					)
440 461
 				);
441
-				if ($smcFunc['db_num_rows']($request) === 0)
442
-					return false;
462
+				if ($smcFunc['db_num_rows']($request) === 0) {
463
+									return false;
464
+				}
465
+			} else {
466
+							return false;
443 467
 			}
444
-			else
445
-				return false;
446 468
 		}
447 469
 		list ($member_id, $subscription_id) = $smcFunc['db_fetch_row']($request);
448 470
 		$_POST['item_number'] = $member_id . '+' . $subscription_id;
Please login to merge, or discard this patch.
Sources/Subs-Charset.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * Converts the given UTF-8 string into lowercase.
Please login to merge, or discard this patch.
Sources/Subs-Menu.php 1 patch
Braces   +75 added lines, -57 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Create a menu.
@@ -64,22 +65,26 @@  discard block
 block discarded – undo
64 65
 	$menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action'];
65 66
 
66 67
 	// Allow extend *any* menu with a single hook
67
-	if (!empty($menu_context['current_action']))
68
-		call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
68
+	if (!empty($menu_context['current_action'])) {
69
+			call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
70
+	}
69 71
 
70 72
 	// What is the current area selected?
71
-	if (isset($menuOptions['current_area']) || isset($_GET['area']))
72
-		$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
73
+	if (isset($menuOptions['current_area']) || isset($_GET['area'])) {
74
+			$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
75
+	}
73 76
 
74 77
 	// Build a list of additional parameters that should go in the URL.
75 78
 	$menu_context['extra_parameters'] = '';
76
-	if (!empty($menuOptions['extra_url_parameters']))
77
-		foreach ($menuOptions['extra_url_parameters'] as $key => $value)
79
+	if (!empty($menuOptions['extra_url_parameters'])) {
80
+			foreach ($menuOptions['extra_url_parameters'] as $key => $value)
78 81
 			$menu_context['extra_parameters'] .= ';' . $key . '=' . $value;
82
+	}
79 83
 
80 84
 	// Only include the session ID in the URL if it's strictly necessary.
81
-	if (empty($menuOptions['disable_url_session_check']))
82
-		$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
85
+	if (empty($menuOptions['disable_url_session_check'])) {
86
+			$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
87
+	}
83 88
 
84 89
 	$include_data = array();
85 90
 
@@ -87,8 +92,9 @@  discard block
 block discarded – undo
87 92
 	foreach ($menuData as $section_id => $section)
88 93
 	{
89 94
 		// Is this enabled - or has as permission check - which fails?
90
-		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission'])))
91
-			continue;
95
+		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) {
96
+					continue;
97
+		}
92 98
 
93 99
 		// Now we cycle through the sections to pick the right area.
94 100
 		foreach ($section['areas'] as $area_id => $area)
@@ -110,59 +116,57 @@  discard block
 block discarded – undo
110 116
 					if (empty($area['hidden']))
111 117
 					{
112 118
 						// First time this section?
113
-						if (!isset($menu_context['sections'][$section_id]))
114
-							$menu_context['sections'][$section_id]['title'] = $section['title'];
119
+						if (!isset($menu_context['sections'][$section_id])) {
120
+													$menu_context['sections'][$section_id]['title'] = $section['title'];
121
+						}
115 122
 
116 123
 						$menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]);
117 124
 						// We'll need the ID as well...
118 125
 						$menu_context['sections'][$section_id]['id'] = $section_id;
119 126
 						// Does it have a custom URL?
120
-						if (isset($area['custom_url']))
121
-							$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
127
+						if (isset($area['custom_url'])) {
128
+													$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
129
+						}
122 130
 
123 131
 						// Does this area have its own icon?
124 132
 						if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa')
125 133
 						{
126 134
 							$menu_context['sections'][$section_id]['areas'][$area_id] = $smcFunc['json_decode'](base64_decode('eyJsYWJlbCI6Ik9vbXBhIExvb21wYSIsInVybCI6Imh0dHBzOlwvXC9lbi53aWtpcGVkaWEub3JnXC93aWtpXC9Pb21wYV9Mb29tcGFzPyIsImljb24iOiI8aW1nIHNyYz1cImh0dHBzOlwvXC93d3cuc2ltcGxlbWFjaGluZXMub3JnXC9pbWFnZXNcL29vbXBhLmdpZlwiIGFsdD1cIkknbSBhbiBPb21wYSBMb29tcGFcIiBcLz4ifQ=='), true);
127
-						}
128
-						elseif (isset($area['icon']))
135
+						} elseif (isset($area['icon']))
129 136
 						{
130 137
 							if (file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon']))
131 138
 							{
132 139
 								$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">';
133
-							}
134
-							elseif (file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon']))
140
+							} elseif (file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon']))
135 141
 							{
136 142
 								$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">';
143
+							} else {
144
+															$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
137 145
 							}
138
-							else
139
-								$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
146
+						} else {
147
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
140 148
 						}
141
-						else
142
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
143 149
 
144 150
 						if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon']))
145 151
 						{
146 152
 							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class'];
147
-						}
148
-						elseif (isset($area['icon']))
153
+						} elseif (isset($area['icon']))
149 154
 						{
150 155
 							if (substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif')
151 156
 							{
152 157
 								if (file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon']))
153 158
 								{
154 159
 									$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon'];
155
-								}
156
-								elseif (file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon']))
160
+								} elseif (file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon']))
157 161
 								{
158 162
 									$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon'];
159 163
 								}
160 164
 							}
161 165
 
162 166
 							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']);
167
+						} else {
168
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
163 169
 						}
164
-						else
165
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
166 170
 
167 171
 						// This is a shortcut for Font-Icon users so they don't have to re-do whole CSS.
168 172
 						$menu_context['sections'][$section_id]['areas'][$area_id]['plain_class'] = !empty($area['icon']) ? $area['icon'] : '';
@@ -179,35 +183,41 @@  discard block
 block discarded – undo
179 183
 							{
180 184
 								if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled'])))
181 185
 								{
182
-									if ($first_sa == null)
183
-										$first_sa = $sa;
186
+									if ($first_sa == null) {
187
+																			$first_sa = $sa;
188
+									}
184 189
 
185 190
 									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]);
186 191
 									// Custom URL?
187
-									if (isset($sub['url']))
188
-										$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
192
+									if (isset($sub['url'])) {
193
+																			$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
194
+									}
189 195
 
190 196
 									// A bit complicated - but is this set?
191 197
 									if ($menu_context['current_area'] == $area_id)
192 198
 									{
193 199
 										// Save which is the first...
194
-										if (empty($first_sa))
195
-											$first_sa = $sa;
200
+										if (empty($first_sa)) {
201
+																					$first_sa = $sa;
202
+										}
196 203
 
197 204
 										// Is this the current subsection?
198
-										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa)
199
-											$menu_context['current_subsection'] = $sa;
205
+										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) {
206
+																					$menu_context['current_subsection'] = $sa;
207
+										}
200 208
 										// Otherwise is it the default?
201
-										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2]))
202
-											$menu_context['current_subsection'] = $sa;
209
+										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) {
210
+																					$menu_context['current_subsection'] = $sa;
211
+										}
203 212
 									}
204 213
 
205 214
 									// Let's assume this is the last, for now.
206 215
 									$last_sa = $sa;
207 216
 								}
208 217
 								// Mark it as disabled...
209
-								else
210
-									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
218
+								else {
219
+																	$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
220
+								}
211 221
 							}
212 222
 
213 223
 							// Set which one is first, last and selected in the group.
@@ -216,8 +226,9 @@  discard block
 block discarded – undo
216 226
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true;
217 227
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true;
218 228
 
219
-								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection']))
220
-									$menu_context['current_subsection'] = $first_sa;
229
+								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) {
230
+																	$menu_context['current_subsection'] = $first_sa;
231
+								}
221 232
 							}
222 233
 						}
223 234
 					}
@@ -251,23 +262,26 @@  discard block
 block discarded – undo
251 262
 	$menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action'];
252 263
 
253 264
 	// If we didn't find the area we were looking for go to a default one.
254
-	if (isset($backup_area) && empty($found_section))
255
-		$menu_context['current_area'] = $backup_area;
265
+	if (isset($backup_area) && empty($found_section)) {
266
+			$menu_context['current_area'] = $backup_area;
267
+	}
256 268
 
257 269
 	// If there are sections quickly goes through all the sections to check if the base menu has an url
258 270
 	if (!empty($menu_context['current_section']))
259 271
 	{
260 272
 		$menu_context['sections'][$menu_context['current_section']]['selected'] = true;
261 273
 		$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true;
262
-		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]))
263
-			$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
274
+		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) {
275
+					$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
276
+		}
264 277
 
265
-		foreach ($menu_context['sections'] as $section_id => $section)
266
-			foreach ($section['areas'] as $area_id => $area)
278
+		foreach ($menu_context['sections'] as $section_id => $section) {
279
+					foreach ($section['areas'] as $area_id => $area)
267 280
 			{
268 281
 				if (!isset($menu_context['sections'][$section_id]['url']))
269 282
 				{
270 283
 					$menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id;
284
+		}
271 285
 					break;
272 286
 				}
273 287
 			}
@@ -278,8 +292,9 @@  discard block
 block discarded – undo
278 292
 	{
279 293
 		// Never happened!
280 294
 		$context['max_menu_id']--;
281
-		if ($context['max_menu_id'] == 0)
282
-			unset($context['max_menu_id']);
295
+		if ($context['max_menu_id'] == 0) {
296
+					unset($context['max_menu_id']);
297
+		}
283 298
 
284 299
 		return false;
285 300
 	}
@@ -290,8 +305,9 @@  discard block
 block discarded – undo
290 305
 	$context['template_layers'][] = $menu_context['layer_name'];
291 306
 
292 307
 	// Check we had something - for sanity sake.
293
-	if (empty($include_data))
294
-		return false;
308
+	if (empty($include_data)) {
309
+			return false;
310
+	}
295 311
 
296 312
 	// Finally - return information on the selected item.
297 313
 	$include_data += array(
@@ -314,12 +330,14 @@  discard block
 block discarded – undo
314 330
 	global $context;
315 331
 
316 332
 	$menu_name = $menu_id == 'last' && isset($context['max_menu_id']) && isset($context['menu_data_' . $context['max_menu_id']]) ? 'menu_data_' . $context['max_menu_id'] : 'menu_data_' . $menu_id;
317
-	if (!isset($context[$menu_name]))
318
-		return false;
333
+	if (!isset($context[$menu_name])) {
334
+			return false;
335
+	}
319 336
 
320 337
 	$layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']);
321
-	if ($layer_index !== false)
322
-		unset($context['template_layers'][$layer_index]);
338
+	if ($layer_index !== false) {
339
+			unset($context['template_layers'][$layer_index]);
340
+	}
323 341
 
324 342
 	unset($context[$menu_name]);
325 343
 }
Please login to merge, or discard this patch.
Sources/ManageMembers.php 1 patch
Braces   +158 added lines, -116 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main entrance point for the Manage Members screen.
@@ -62,16 +63,18 @@  discard block
 block discarded – undo
62 63
 	$context['activation_numbers'] = array();
63 64
 	$context['awaiting_activation'] = 0;
64 65
 	$context['awaiting_approval'] = 0;
65
-	while ($row = $smcFunc['db_fetch_assoc']($request))
66
-		$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
66
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
67
+			$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
68
+	}
67 69
 	$smcFunc['db_free_result']($request);
68 70
 
69 71
 	foreach ($context['activation_numbers'] as $activation_type => $total_members)
70 72
 	{
71
-		if (in_array($activation_type, array(0, 2)))
72
-			$context['awaiting_activation'] += $total_members;
73
-		elseif (in_array($activation_type, array(3, 4, 5)))
74
-			$context['awaiting_approval'] += $total_members;
73
+		if (in_array($activation_type, array(0, 2))) {
74
+					$context['awaiting_activation'] += $total_members;
75
+		} elseif (in_array($activation_type, array(3, 4, 5))) {
76
+					$context['awaiting_approval'] += $total_members;
77
+		}
75 78
 	}
76 79
 
77 80
 	// For the page header... do we show activation?
@@ -124,8 +127,9 @@  discard block
 block discarded – undo
124 127
 	}
125 128
 	if (!$context['show_approve'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'approve'))
126 129
 	{
127
-		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate'))
128
-			$context['tabs']['search']['is_last'] = true;
130
+		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) {
131
+					$context['tabs']['search']['is_last'] = true;
132
+		}
129 133
 		unset($context['tabs']['approve']);
130 134
 	}
131 135
 
@@ -157,8 +161,9 @@  discard block
 block discarded – undo
157 161
 		foreach ($_POST['delete'] as $key => $value)
158 162
 		{
159 163
 			// Don't delete yourself, idiot.
160
-			if ($value != $user_info['id'])
161
-				$delete[$key] = (int) $value;
164
+			if ($value != $user_info['id']) {
165
+							$delete[$key] = (int) $value;
166
+			}
162 167
 		}
163 168
 
164 169
 		if (!empty($delete))
@@ -194,17 +199,18 @@  discard block
 block discarded – undo
194 199
 		);
195 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
196 201
 		{
197
-			if ($row['min_posts'] == -1)
198
-				$context['membergroups'][] = array(
202
+			if ($row['min_posts'] == -1) {
203
+							$context['membergroups'][] = array(
199 204
 					'id' => $row['id_group'],
200 205
 					'name' => $row['group_name'],
201 206
 					'can_be_additional' => true
202 207
 				);
203
-			else
204
-				$context['postgroups'][] = array(
208
+			} else {
209
+							$context['postgroups'][] = array(
205 210
 					'id' => $row['id_group'],
206 211
 					'name' => $row['group_name']
207 212
 				);
213
+			}
208 214
 		}
209 215
 		$smcFunc['db_free_result']($request);
210 216
 
@@ -268,14 +274,15 @@  discard block
 block discarded – undo
268 274
 		call_integration_hook('integrate_view_members_params', array(&$params));
269 275
 
270 276
 		$search_params = array();
271
-		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types']))
272
-			$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
273
-		elseif (!empty($_POST))
277
+		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) {
278
+					$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
279
+		} elseif (!empty($_POST))
274 280
 		{
275 281
 			$search_params['types'] = $_POST['types'];
276
-			foreach ($params as $param_name => $param_info)
277
-				if (isset($_POST[$param_name]))
282
+			foreach ($params as $param_name => $param_info) {
283
+							if (isset($_POST[$param_name]))
278 284
 					$search_params[$param_name] = $_POST[$param_name];
285
+			}
279 286
 		}
280 287
 
281 288
 		$search_url_params = isset($search_params) ? base64_encode($smcFunc['json_encode']($search_params)) : null;
@@ -288,18 +295,21 @@  discard block
 block discarded – undo
288 295
 		foreach ($params as $param_name => $param_info)
289 296
 		{
290 297
 			// Not filled in?
291
-			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '')
292
-				continue;
298
+			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') {
299
+							continue;
300
+			}
293 301
 
294 302
 			// Make sure numeric values are really numeric.
295
-			if (in_array($param_info['type'], array('int', 'age')))
296
-				$search_params[$param_name] = (int) $search_params[$param_name];
303
+			if (in_array($param_info['type'], array('int', 'age'))) {
304
+							$search_params[$param_name] = (int) $search_params[$param_name];
305
+			}
297 306
 			// Date values have to match the specified format.
298 307
 			elseif ($param_info['type'] == 'date')
299 308
 			{
300 309
 				// Check if this date format is valid.
301
-				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0)
302
-					continue;
310
+				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) {
311
+									continue;
312
+				}
303 313
 
304 314
 				$search_params[$param_name] = strtotime($search_params[$param_name]);
305 315
 			}
@@ -308,8 +318,9 @@  discard block
 block discarded – undo
308 318
 			if (!empty($param_info['range']))
309 319
 			{
310 320
 				// Default to '=', just in case...
311
-				if (empty($range_trans[$search_params['types'][$param_name]]))
312
-					$search_params['types'][$param_name] = '=';
321
+				if (empty($range_trans[$search_params['types'][$param_name]])) {
322
+									$search_params['types'][$param_name] = '=';
323
+				}
313 324
 
314 325
 				// Handle special case 'age'.
315 326
 				if ($param_info['type'] == 'age')
@@ -337,29 +348,30 @@  discard block
 block discarded – undo
337 348
 				elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=')
338 349
 				{
339 350
 					$query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400);
351
+				} else {
352
+									$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
340 353
 				}
341
-				else
342
-					$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
343 354
 			}
344 355
 			// Checkboxes.
345 356
 			elseif ($param_info['type'] == 'checkbox')
346 357
 			{
347 358
 				// Each checkbox or no checkbox at all is checked -> ignore.
348
-				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values']))
349
-					continue;
359
+				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) {
360
+									continue;
361
+				}
350 362
 
351 363
 				$query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})';
352 364
 				$where_params[$param_name . '_check'] = $search_params[$param_name];
353
-			}
354
-			else
365
+			} else
355 366
 			{
356 367
 				// Replace the wildcard characters ('*' and '?') into MySQL ones.
357 368
 				$parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')));
358 369
 
359
-				if ($smcFunc['db_case_sensitive'])
360
-					$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
361
-				else
362
-					$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
370
+				if ($smcFunc['db_case_sensitive']) {
371
+									$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
372
+				} else {
373
+									$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
374
+				}
363 375
 				$where_params[$param_name . '_normal'] = '%' . $parameter . '%';
364 376
 			}
365 377
 		}
@@ -375,16 +387,18 @@  discard block
 block discarded – undo
375 387
 		}
376 388
 
377 389
 		// Additional membergroups (these are only relevant if not all primary groups where selected!).
378
-		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1])))
379
-			foreach ($search_params['membergroups'][2] as $mg)
390
+		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) {
391
+					foreach ($search_params['membergroups'][2] as $mg)
380 392
 			{
381 393
 				$mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0';
394
+		}
382 395
 				$where_params['add_group_' . $mg] = $mg;
383 396
 			}
384 397
 
385 398
 		// Combine the one or two membergroup parts into one query part linked with an OR.
386
-		if (!empty($mg_query_parts))
387
-			$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
399
+		if (!empty($mg_query_parts)) {
400
+					$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
401
+		}
388 402
 
389 403
 		// Get all selected post count related membergroups.
390 404
 		if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups']))
@@ -396,9 +410,9 @@  discard block
 block discarded – undo
396 410
 		// Construct the where part of the query.
397 411
 		$where = empty($query_parts) ? '1=1' : implode('
398 412
 			AND ', $query_parts);
413
+	} else {
414
+			$search_url_params = null;
399 415
 	}
400
-	else
401
-		$search_url_params = null;
402 416
 
403 417
 	// Construct the additional URL part with the query info in it.
404 418
 	$context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : '';
@@ -521,28 +535,32 @@  discard block
 block discarded – undo
521 535
 					'function' => function($rowData) use ($txt)
522 536
 					{
523 537
 						// Calculate number of days since last online.
524
-						if (empty($rowData['last_login']))
525
-							$difference = $txt['never'];
526
-						else
538
+						if (empty($rowData['last_login'])) {
539
+													$difference = $txt['never'];
540
+						} else
527 541
 						{
528 542
 							$num_days_difference = jeffsdatediff($rowData['last_login']);
529 543
 
530 544
 							// Today.
531
-							if (empty($num_days_difference))
532
-								$difference = $txt['viewmembers_today'];
545
+							if (empty($num_days_difference)) {
546
+															$difference = $txt['viewmembers_today'];
547
+							}
533 548
 
534 549
 							// Yesterday.
535
-							elseif ($num_days_difference == 1)
536
-								$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
550
+							elseif ($num_days_difference == 1) {
551
+															$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
552
+							}
537 553
 
538 554
 							// X days ago.
539
-							else
540
-								$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
555
+							else {
556
+															$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
557
+							}
541 558
 						}
542 559
 
543 560
 						// Show it in italics if they're not activated...
544
-						if ($rowData['is_activated'] % 10 != 1)
545
-							$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
561
+						if ($rowData['is_activated'] % 10 != 1) {
562
+													$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
563
+						}
546 564
 
547 565
 						return $difference;
548 566
 					},
@@ -594,8 +612,9 @@  discard block
 block discarded – undo
594 612
 	);
595 613
 
596 614
 	// Without enough permissions, don't show 'delete members' checkboxes.
597
-	if (!allowedTo('profile_remove_any'))
598
-		unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
615
+	if (!allowedTo('profile_remove_any')) {
616
+			unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
617
+	}
599 618
 
600 619
 	require_once($sourcedir . '/Subs-List.php');
601 620
 	createList($listOptions);
@@ -638,17 +657,18 @@  discard block
 block discarded – undo
638 657
 	);
639 658
 	while ($row = $smcFunc['db_fetch_assoc']($request))
640 659
 	{
641
-		if ($row['min_posts'] == -1)
642
-			$context['membergroups'][] = array(
660
+		if ($row['min_posts'] == -1) {
661
+					$context['membergroups'][] = array(
643 662
 				'id' => $row['id_group'],
644 663
 				'name' => $row['group_name'],
645 664
 				'can_be_additional' => true
646 665
 			);
647
-		else
648
-			$context['postgroups'][] = array(
666
+		} else {
667
+					$context['postgroups'][] = array(
649 668
 				'id' => $row['id_group'],
650 669
 				'name' => $row['group_name']
651 670
 			);
671
+		}
652 672
 	}
653 673
 	$smcFunc['db_free_result']($request);
654 674
 
@@ -675,8 +695,9 @@  discard block
 block discarded – undo
675 695
 	$context['page_title'] = $txt['admin_members'];
676 696
 	$context['sub_template'] = 'admin_browse';
677 697
 	$context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
678
-	if (isset($context['tabs'][$context['browse_type']]))
679
-		$context['tabs'][$context['browse_type']]['is_selected'] = true;
698
+	if (isset($context['tabs'][$context['browse_type']])) {
699
+			$context['tabs'][$context['browse_type']]['is_selected'] = true;
700
+	}
680 701
 
681 702
 	// Allowed filters are those we can have, in theory.
682 703
 	$context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2);
@@ -687,18 +708,20 @@  discard block
 block discarded – undo
687 708
 	foreach ($context['activation_numbers'] as $type => $amount)
688 709
 	{
689 710
 		// We have some of these...
690
-		if (in_array($type, $context['allowed_filters']) && $amount > 0)
691
-			$context['available_filters'][] = array(
711
+		if (in_array($type, $context['allowed_filters']) && $amount > 0) {
712
+					$context['available_filters'][] = array(
692 713
 				'type' => $type,
693 714
 				'amount' => $amount,
694 715
 				'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?',
695 716
 				'selected' => $type == $context['current_filter']
696 717
 			);
718
+		}
697 719
 	}
698 720
 
699 721
 	// If the filter was not sent, set it to whatever has people in it!
700
-	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount']))
701
-		$context['current_filter'] = $context['available_filters'][0]['type'];
722
+	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) {
723
+			$context['current_filter'] = $context['available_filters'][0]['type'];
724
+	}
702 725
 
703 726
 	// This little variable is used to determine if we should flag where we are looking.
704 727
 	$context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1;
@@ -713,44 +736,47 @@  discard block
 block discarded – undo
713 736
 	);
714 737
 
715 738
 	// Are we showing duplicate information?
716
-	if (isset($_GET['showdupes']))
717
-		$_SESSION['showdupes'] = (int) $_GET['showdupes'];
739
+	if (isset($_GET['showdupes'])) {
740
+			$_SESSION['showdupes'] = (int) $_GET['showdupes'];
741
+	}
718 742
 	$context['show_duplicates'] = !empty($_SESSION['showdupes']);
719 743
 
720 744
 	// Determine which actions we should allow on this page.
721 745
 	if ($context['browse_type'] == 'approve')
722 746
 	{
723 747
 		// If we are approving deleted accounts we have a slightly different list... actually a mirror ;)
724
-		if ($context['current_filter'] == 4)
725
-			$context['allowed_actions'] = array(
748
+		if ($context['current_filter'] == 4) {
749
+					$context['allowed_actions'] = array(
726 750
 				'reject' => $txt['admin_browse_w_approve_deletion'],
727 751
 				'ok' => $txt['admin_browse_w_reject'],
728 752
 			);
729
-		else
730
-			$context['allowed_actions'] = array(
753
+		} else {
754
+					$context['allowed_actions'] = array(
731 755
 				'ok' => $txt['admin_browse_w_approve'],
732 756
 				'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'],
733 757
 				'require_activation' => $txt['admin_browse_w_approve_require_activate'],
734 758
 				'reject' => $txt['admin_browse_w_reject'],
735 759
 				'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'],
736 760
 			);
737
-	}
738
-	elseif ($context['browse_type'] == 'activate')
739
-		$context['allowed_actions'] = array(
761
+		}
762
+	} elseif ($context['browse_type'] == 'activate') {
763
+			$context['allowed_actions'] = array(
740 764
 			'ok' => $txt['admin_browse_w_activate'],
741 765
 			'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'],
742 766
 			'delete' => $txt['admin_browse_w_delete'],
743 767
 			'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'],
744 768
 			'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'],
745 769
 		);
770
+	}
746 771
 
747 772
 	// Create an option list for actions allowed to be done with selected members.
748 773
 	$allowed_actions = '
749 774
 			<option selected value="">' . $txt['admin_browse_with_selected'] . ':</option>
750 775
 			<option value="" disabled>-----------------------------</option>';
751
-	foreach ($context['allowed_actions'] as $key => $desc)
752
-		$allowed_actions .= '
776
+	foreach ($context['allowed_actions'] as $key => $desc) {
777
+			$allowed_actions .= '
753 778
 			<option value="' . $key . '">' . $desc . '</option>';
779
+	}
754 780
 
755 781
 	// Setup the Javascript function for selecting an action for the list.
756 782
 	$javascript = '
@@ -762,15 +788,16 @@  discard block
 block discarded – undo
762 788
 			var message = "";';
763 789
 
764 790
 	// We have special messages for approving deletion of accounts - it's surprisingly logical - honest.
765
-	if ($context['current_filter'] == 4)
766
-		$javascript .= '
791
+	if ($context['current_filter'] == 4) {
792
+			$javascript .= '
767 793
 			if (document.forms.postForm.todo.value.indexOf("reject") != -1)
768 794
 				message = "' . $txt['admin_browse_w_delete'] . '";
769 795
 			else
770 796
 				message = "' . $txt['admin_browse_w_reject'] . '";';
797
+	}
771 798
 	// Otherwise a nice standard message.
772
-	else
773
-		$javascript .= '
799
+	else {
800
+			$javascript .= '
774 801
 			if (document.forms.postForm.todo.value.indexOf("delete") != -1)
775 802
 				message = "' . $txt['admin_browse_w_delete'] . '";
776 803
 			else if (document.forms.postForm.todo.value.indexOf("reject") != -1)
@@ -779,6 +806,7 @@  discard block
 block discarded – undo
779 806
 				message = "' . $txt['admin_browse_w_remind'] . '";
780 807
 			else
781 808
 				message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";';
809
+	}
782 810
 	$javascript .= '
783 811
 			if (confirm(message + " ' . $txt['admin_browse_warn'] . '"))
784 812
 				document.forms.postForm.submit();
@@ -911,10 +939,11 @@  discard block
 block discarded – undo
911 939
 						$member_links = array();
912 940
 						foreach ($rowData['duplicate_members'] as $member)
913 941
 						{
914
-							if ($member['id'])
915
-								$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
916
-							else
917
-								$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
942
+							if ($member['id']) {
943
+															$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
944
+							} else {
945
+															$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
946
+							}
918 947
 						}
919 948
 						return implode(', ', $member_links);
920 949
 					},
@@ -963,14 +992,16 @@  discard block
 block discarded – undo
963 992
 	);
964 993
 
965 994
 	// Pick what column to actually include if we're showing duplicates.
966
-	if ($context['show_duplicates'])
967
-		unset($listOptions['columns']['email']);
968
-	else
969
-		unset($listOptions['columns']['duplicates']);
995
+	if ($context['show_duplicates']) {
996
+			unset($listOptions['columns']['email']);
997
+	} else {
998
+			unset($listOptions['columns']['duplicates']);
999
+	}
970 1000
 
971 1001
 	// Only show hostname on duplicates as it takes a lot of time.
972
-	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup']))
973
-		unset($listOptions['columns']['hostname']);
1002
+	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) {
1003
+			unset($listOptions['columns']['hostname']);
1004
+	}
974 1005
 
975 1006
 	// Is there any need to show filters?
976 1007
 	if (isset($context['available_filters']) && count($context['available_filters']) > 1)
@@ -978,9 +1009,10 @@  discard block
 block discarded – undo
978 1009
 		$filterOptions = '
979 1010
 			<strong>' . $txt['admin_browse_filter_by'] . ':</strong>
980 1011
 			<select name="filter" onchange="this.form.submit();">';
981
-		foreach ($context['available_filters'] as $filter)
982
-			$filterOptions .= '
1012
+		foreach ($context['available_filters'] as $filter) {
1013
+					$filterOptions .= '
983 1014
 				<option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>';
1015
+		}
984 1016
 		$filterOptions .= '
985 1017
 			</select>
986 1018
 			<noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button"></noscript>';
@@ -992,12 +1024,13 @@  discard block
 block discarded – undo
992 1024
 	}
993 1025
 
994 1026
 	// What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at.
995
-	if (!empty($context['show_filter']) && !empty($context['available_filters']))
996
-		$listOptions['additional_rows'][] = array(
1027
+	if (!empty($context['show_filter']) && !empty($context['available_filters'])) {
1028
+			$listOptions['additional_rows'][] = array(
997 1029
 			'position' => 'above_column_headers',
998 1030
 			'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'],
999 1031
 			'class' => 'smalltext floatright',
1000 1032
 		);
1033
+	}
1001 1034
 
1002 1035
 	// Now that we have all the options, create the list.
1003 1036
 	require_once($sourcedir . '/Subs-List.php');
@@ -1027,12 +1060,14 @@  discard block
 block discarded – undo
1027 1060
 	$current_filter = (int) $_REQUEST['orig_filter'];
1028 1061
 
1029 1062
 	// If we are applying a filter do just that - then redirect.
1030
-	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
1031
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1063
+	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) {
1064
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1065
+	}
1032 1066
 
1033 1067
 	// Nothing to do?
1034
-	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
1035
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1068
+	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) {
1069
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1070
+	}
1036 1071
 
1037 1072
 	// Are we dealing with members who have been waiting for > set amount of time?
1038 1073
 	if (isset($_POST['time_passed']))
@@ -1045,8 +1080,9 @@  discard block
 block discarded – undo
1045 1080
 	else
1046 1081
 	{
1047 1082
 		$members = array();
1048
-		foreach ($_POST['todoAction'] as $id)
1049
-			$members[] = (int) $id;
1083
+		foreach ($_POST['todoAction'] as $id) {
1084
+					$members[] = (int) $id;
1085
+		}
1050 1086
 		$condition = '
1051 1087
 			AND id_member IN ({array_int:members})';
1052 1088
 	}
@@ -1067,8 +1103,9 @@  discard block
 block discarded – undo
1067 1103
 	$member_count = $smcFunc['db_num_rows']($request);
1068 1104
 
1069 1105
 	// If no results then just return!
1070
-	if ($member_count == 0)
1071
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1106
+	if ($member_count == 0) {
1107
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1108
+	}
1072 1109
 
1073 1110
 	$member_info = array();
1074 1111
 	$members = array();
@@ -1107,8 +1144,9 @@  discard block
 block discarded – undo
1107 1144
 		// Do we have to let the integration code know about the activations?
1108 1145
 		if (!empty($modSettings['integrate_activate']))
1109 1146
 		{
1110
-			foreach ($member_info as $member)
1111
-				call_integration_hook('integrate_activate', array($member['username']));
1147
+			foreach ($member_info as $member) {
1148
+							call_integration_hook('integrate_activate', array($member['username']));
1149
+			}
1112 1150
 		}
1113 1151
 
1114 1152
 		// Check for email.
@@ -1238,20 +1276,23 @@  discard block
 block discarded – undo
1238 1276
 		$log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member';
1239 1277
 
1240 1278
 		require_once($sourcedir . '/Logging.php');
1241
-		foreach ($member_info as $member)
1242
-			logAction($log_action, array('member' => $member['id']), 'admin');
1279
+		foreach ($member_info as $member) {
1280
+					logAction($log_action, array('member' => $member['id']), 'admin');
1281
+		}
1243 1282
 	}
1244 1283
 
1245 1284
 	// Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
1246
-	if (in_array($current_filter, array(3, 4, 5)))
1247
-		updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1285
+	if (in_array($current_filter, array(3, 4, 5))) {
1286
+			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1287
+	}
1248 1288
 
1249 1289
 	// Update the member's stats. (but, we know the member didn't change their name.)
1250 1290
 	updateStats('member', false);
1251 1291
 
1252 1292
 	// If they haven't been deleted, update the post group statistics on them...
1253
-	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
1254
-		updateStats('postgroups', $members);
1293
+	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) {
1294
+			updateStats('postgroups', $members);
1295
+	}
1255 1296
 
1256 1297
 	redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1257 1298
 }
@@ -1276,10 +1317,11 @@  discard block
 block discarded – undo
1276 1317
 	$dis = time() - $old;
1277 1318
 
1278 1319
 	// Before midnight?
1279
-	if ($dis < $sinceMidnight)
1280
-		return 0;
1281
-	else
1282
-		$dis -= $sinceMidnight;
1320
+	if ($dis < $sinceMidnight) {
1321
+			return 0;
1322
+	} else {
1323
+			$dis -= $sinceMidnight;
1324
+	}
1283 1325
 
1284 1326
 	// Divide out the seconds in a day to get the number of days.
1285 1327
 	return ceil($dis / (24 * 60 * 60));
Please login to merge, or discard this patch.
Sources/Subs-Post.php 1 patch
Braces   +531 added lines, -395 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Takes a message and parses it, returning nothing.
@@ -31,8 +32,9 @@  discard block
 block discarded – undo
31 32
 	global $user_info, $modSettings, $context, $sourcedir;
32 33
 
33 34
 	// This line makes all languages *theoretically* work even with the wrong charset ;).
34
-	if (empty($context['utf8']))
35
-		$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
35
+	if (empty($context['utf8'])) {
36
+			$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
37
+	}
36 38
 
37 39
 	// Clean up after nobbc ;).
38 40
 	$message = preg_replace_callback('~\[nobbc\](.+?)\[/nobbc\]~is', function($a)
@@ -47,17 +49,19 @@  discard block
 block discarded – undo
47 49
 	$message = preg_replace('~\.{100,}~', '...', $message);
48 50
 
49 51
 	// Trim off trailing quotes - these often happen by accident.
50
-	while (substr($message, -7) == '[quote]')
51
-		$message = substr($message, 0, -7);
52
-	while (substr($message, 0, 8) == '[/quote]')
53
-		$message = substr($message, 8);
52
+	while (substr($message, -7) == '[quote]') {
53
+			$message = substr($message, 0, -7);
54
+	}
55
+	while (substr($message, 0, 8) == '[/quote]') {
56
+			$message = substr($message, 8);
57
+	}
54 58
 
55 59
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
56 60
 	$in_tag = false;
57 61
 	$had_tag = false;
58 62
 	$codeopen = 0;
59
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
60
-		foreach ($matches[0] as $index => $dummy)
63
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
64
+			foreach ($matches[0] as $index => $dummy)
61 65
 		{
62 66
 			// Closing?
63 67
 			if (!empty($matches[2][$index]))
@@ -65,6 +69,7 @@  discard block
 block discarded – undo
65 69
 				// If it's closing and we're not in a tag we need to open it...
66 70
 				if (!$in_tag)
67 71
 					$codeopen = true;
72
+	}
68 73
 				// Either way we ain't in one any more.
69 74
 				$in_tag = false;
70 75
 			}
@@ -73,17 +78,20 @@  discard block
 block discarded – undo
73 78
 			{
74 79
 				$had_tag = true;
75 80
 				// If we're in a tag don't do nought!
76
-				if (!$in_tag)
77
-					$in_tag = true;
81
+				if (!$in_tag) {
82
+									$in_tag = true;
83
+				}
78 84
 			}
79 85
 		}
80 86
 
81 87
 	// If we have an open tag, close it.
82
-	if ($in_tag)
83
-		$message .= '[/code]';
88
+	if ($in_tag) {
89
+			$message .= '[/code]';
90
+	}
84 91
 	// Open any ones that need to be open, only if we've never had a tag.
85
-	if ($codeopen && !$had_tag)
86
-		$message = '[code]' . $message;
92
+	if ($codeopen && !$had_tag) {
93
+			$message = '[code]' . $message;
94
+	}
87 95
 
88 96
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
89 97
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -109,23 +117,26 @@  discard block
 block discarded – undo
109 117
 	fixTags($message);
110 118
 
111 119
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
112
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
113
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
114
-	else
115
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
120
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
121
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
122
+	} else {
123
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
124
+	}
116 125
 
117 126
 	if (!$previewing && strpos($message, '[html]') !== false)
118 127
 	{
119
-		if (allowedTo('admin_forum'))
120
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
128
+		if (allowedTo('admin_forum')) {
129
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
121 130
 				return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => '&#13;', '  ' => ' &#32;', '[' => '&#91;', ']' => '&#93;')) . '[/html]';
131
+		}
122 132
 			}, $message);
123 133
 
124 134
 		// We should edit them out, or else if an admin edits the message they will get shown...
125 135
 		else
126 136
 		{
127
-			while (strpos($message, '[html]') !== false)
128
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			while (strpos($message, '[html]') !== false) {
138
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
139
+			}
129 140
 		}
130 141
 	}
131 142
 
@@ -147,10 +158,12 @@  discard block
 block discarded – undo
147 158
 
148 159
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
149 160
 	$list_close = substr_count($message, '[/list]');
150
-	if ($list_close - $list_open > 0)
151
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
152
-	if ($list_open - $list_close > 0)
153
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
161
+	if ($list_close - $list_open > 0) {
162
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
163
+	}
164
+	if ($list_open - $list_close > 0) {
165
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
166
+	}
154 167
 
155 168
 	$mistake_fixes = array(
156 169
 		// Find [table]s not followed by [tr].
@@ -199,8 +212,9 @@  discard block
 block discarded – undo
199 212
 	);
200 213
 
201 214
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
202
-	for ($j = 0; $j < 3; $j++)
203
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	for ($j = 0; $j < 3; $j++) {
216
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
217
+	}
204 218
 
205 219
 	// Remove empty bbc from the sections outside the code tags
206 220
 	$allowedEmpty = array(
@@ -210,24 +224,28 @@  discard block
 block discarded – undo
210 224
 
211 225
 	require_once($sourcedir . '/Subs.php');
212 226
 
213
-	foreach (($codes = parse_bbc(false)) as $code)
214
-		if (!in_array($code['tag'], $allowedEmpty))
227
+	foreach (($codes = parse_bbc(false)) as $code) {
228
+			if (!in_array($code['tag'], $allowedEmpty))
215 229
 			$alltags[] = $code['tag'];
230
+	}
216 231
 
217 232
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
218 233
 
219
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
220
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
234
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
235
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
236
+	}
221 237
 
222 238
 	// Restore code blocks
223
-	if (!empty($code_tags))
224
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
239
+	if (!empty($code_tags)) {
240
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
241
+	}
225 242
 
226 243
 	// Restore white space entities
227
-	if (!$previewing)
228
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
229
-	else
230
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	if (!$previewing) {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	} else {
247
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
248
+	}
231 249
 
232 250
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
233 251
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -270,8 +288,9 @@  discard block
 block discarded – undo
270 288
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
271 289
 	}, $message);
272 290
 
273
-	if (!empty($code_tags))
274
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
291
+	if (!empty($code_tags)) {
292
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
293
+	}
275 294
 
276 295
 	// Change breaks back to \n's and &nsbp; back to spaces.
277 296
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -352,8 +371,9 @@  discard block
 block discarded – undo
352 371
 	);
353 372
 
354 373
 	// Fix each type of tag.
355
-	foreach ($fixArray as $param)
356
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
374
+	foreach ($fixArray as $param) {
375
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
376
+	}
357 377
 
358 378
 	// Now fix possible security problems with images loading links automatically...
359 379
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -389,16 +409,19 @@  discard block
 block discarded – undo
389 409
 					$desired_height = $height;
390 410
 				}
391 411
 				// Scale it to the width...
392
-				elseif (empty($desired_width) && !empty($height))
393
-					$desired_width = (int) (($desired_height * $width) / $height);
412
+				elseif (empty($desired_width) && !empty($height)) {
413
+									$desired_width = (int) (($desired_height * $width) / $height);
414
+				}
394 415
 				// Scale if to the height.
395
-				elseif (!empty($width))
396
-					$desired_height = (int) (($desired_width * $height) / $width);
416
+				elseif (!empty($width)) {
417
+									$desired_height = (int) (($desired_width * $height) / $width);
418
+				}
397 419
 			}
398 420
 
399 421
 			// If the width and height are fine, just continue along...
400
-			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
401
-				continue;
422
+			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
423
+							continue;
424
+			}
402 425
 
403 426
 			// Too bad, it's too wide.  Make it as wide as the maximum.
404 427
 			if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
@@ -418,8 +441,9 @@  discard block
 block discarded – undo
418 441
 		}
419 442
 
420 443
 		// If any img tags were actually changed...
421
-		if (!empty($replaces))
422
-			$message = strtr($message, $replaces);
444
+		if (!empty($replaces)) {
445
+					$message = strtr($message, $replaces);
446
+		}
423 447
 	}
424 448
 }
425 449
 
@@ -438,10 +462,11 @@  discard block
 block discarded – undo
438 462
 {
439 463
 	global $boardurl, $scripturl;
440 464
 
441
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
442
-		$domain_url = $match[1];
443
-	else
444
-		$domain_url = $boardurl . '/';
465
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
466
+			$domain_url = $match[1];
467
+	} else {
468
+			$domain_url = $boardurl . '/';
469
+	}
445 470
 
446 471
 	$replaces = array();
447 472
 
@@ -449,11 +474,11 @@  discard block
 block discarded – undo
449 474
 	{
450 475
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
451 476
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
477
+	} elseif ($hasEqualSign) {
478
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
479
+	} else {
480
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
452 481
 	}
453
-	elseif ($hasEqualSign)
454
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
455
-	else
456
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
457 482
 
458 483
 	foreach ($matches[0] as $k => $dummy)
459 484
 	{
@@ -466,49 +491,53 @@  discard block
 block discarded – undo
466 491
 		foreach ($protocols as $protocol)
467 492
 		{
468 493
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
469
-			if ($found)
470
-				break;
494
+			if ($found) {
495
+							break;
496
+			}
471 497
 		}
472 498
 
473 499
 		if (!$found && $protocols[0] == 'http')
474 500
 		{
475
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
476
-				$replace = $domain_url . $replace;
477
-			elseif (substr($replace, 0, 1) == '?')
478
-				$replace = $scripturl . $replace;
479
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
501
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
502
+							$replace = $domain_url . $replace;
503
+			} elseif (substr($replace, 0, 1) == '?') {
504
+							$replace = $scripturl . $replace;
505
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
480 506
 			{
481 507
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
482 508
 				$this_tag = 'iurl';
483 509
 				$this_close = 'iurl';
510
+			} elseif (substr($replace, 0, 2) != '//') {
511
+							$replace = $protocols[0] . '://' . $replace;
484 512
 			}
485
-			elseif (substr($replace, 0, 2) != '//')
486
-				$replace = $protocols[0] . '://' . $replace;
487
-		}
488
-		elseif (!$found && $protocols[0] == 'ftp')
489
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
490
-		elseif (!$found)
491
-			$replace = $protocols[0] . '://' . $replace;
492
-
493
-		if ($hasEqualSign && $embeddedUrl)
494
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
495
-		elseif ($hasEqualSign)
496
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
497
-		elseif ($embeddedUrl)
498
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
499
-		else
500
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
513
+		} elseif (!$found && $protocols[0] == 'ftp') {
514
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
515
+		} elseif (!$found) {
516
+					$replace = $protocols[0] . '://' . $replace;
517
+		}
518
+
519
+		if ($hasEqualSign && $embeddedUrl) {
520
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
521
+		} elseif ($hasEqualSign) {
522
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
523
+		} elseif ($embeddedUrl) {
524
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
525
+		} else {
526
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
527
+		}
501 528
 	}
502 529
 
503 530
 	foreach ($replaces as $k => $v)
504 531
 	{
505
-		if ($k == $v)
506
-			unset($replaces[$k]);
532
+		if ($k == $v) {
533
+					unset($replaces[$k]);
534
+		}
507 535
 	}
508 536
 
509
-	if (!empty($replaces))
510
-		$message = strtr($message, $replaces);
511
-}
537
+	if (!empty($replaces)) {
538
+			$message = strtr($message, $replaces);
539
+	}
540
+	}
512 541
 
513 542
 /**
514 543
  * This function sends an email to the specified recipient(s).
@@ -552,8 +581,9 @@  discard block
 block discarded – undo
552 581
 	}
553 582
 
554 583
 	// Nothing left? Nothing else to do
555
-	if (empty($to_array))
556
-		return true;
584
+	if (empty($to_array)) {
585
+			return true;
586
+	}
557 587
 
558 588
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
559 589
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -570,15 +600,17 @@  discard block
 block discarded – undo
570 600
 		}
571 601
 
572 602
 		// Call this function recursively for the hotmail addresses.
573
-		if (!empty($hotmail_to))
574
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
603
+		if (!empty($hotmail_to)) {
604
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
605
+		}
575 606
 
576 607
 		// The remaining addresses no longer need the fix.
577 608
 		$hotmail_fix = false;
578 609
 
579 610
 		// No other addresses left? Return instantly.
580
-		if (empty($to_array))
581
-			return $mail_result;
611
+		if (empty($to_array)) {
612
+					return $mail_result;
613
+		}
582 614
 	}
583 615
 
584 616
 	// Get rid of entities.
@@ -603,13 +635,15 @@  discard block
 block discarded – undo
603 635
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
604 636
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
605 637
 
606
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
607
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
638
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
639
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
640
+	}
608 641
 	$headers .= 'X-Mailer: SMF' . $line_break;
609 642
 
610 643
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
611
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
612
-		return false;
644
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
645
+			return false;
646
+	}
613 647
 
614 648
 	// Save the original message...
615 649
 	$orig_message = $message;
@@ -658,17 +692,19 @@  discard block
 block discarded – undo
658 692
 	}
659 693
 
660 694
 	// Are we using the mail queue, if so this is where we butt in...
661
-	if ($priority != 0)
662
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
695
+	if ($priority != 0) {
696
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
697
+	}
663 698
 
664 699
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
665 700
 	elseif (!empty($modSettings['mail_limit']))
666 701
 	{
667 702
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
668
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
669
-			$new_queue_stat = time() . '|' . 1;
670
-		else
671
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
703
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
704
+					$new_queue_stat = time() . '|' . 1;
705
+		} else {
706
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
707
+		}
672 708
 
673 709
 		updateSettings(array('mail_recent' => $new_queue_stat));
674 710
 	}
@@ -693,12 +729,13 @@  discard block
 block discarded – undo
693 729
 
694 730
 			// Wait, wait, I'm still sending here!
695 731
 			@set_time_limit(300);
696
-			if (function_exists('apache_reset_timeout'))
697
-				@apache_reset_timeout();
732
+			if (function_exists('apache_reset_timeout')) {
733
+							@apache_reset_timeout();
734
+			}
698 735
 		}
736
+	} else {
737
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
699 738
 	}
700
-	else
701
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
702 739
 
703 740
 	// Everything go smoothly?
704 741
 	return $mail_result;
@@ -724,8 +761,9 @@  discard block
 block discarded – undo
724 761
 	static $cur_insert = array();
725 762
 	static $cur_insert_len = 0;
726 763
 
727
-	if ($cur_insert_len == 0)
728
-		$cur_insert = array();
764
+	if ($cur_insert_len == 0) {
765
+			$cur_insert = array();
766
+	}
729 767
 
730 768
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
731 769
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -800,8 +838,9 @@  discard block
 block discarded – undo
800 838
 	}
801 839
 
802 840
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
803
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
804
-		return AddMailQueue(true);
841
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
842
+			return AddMailQueue(true);
843
+	}
805 844
 
806 845
 	return true;
807 846
 }
@@ -832,23 +871,26 @@  discard block
 block discarded – undo
832 871
 		'sent' => array()
833 872
 	);
834 873
 
835
-	if ($from === null)
836
-		$from = array(
874
+	if ($from === null) {
875
+			$from = array(
837 876
 			'id' => $user_info['id'],
838 877
 			'name' => $user_info['name'],
839 878
 			'username' => $user_info['username']
840 879
 		);
880
+	}
841 881
 
842 882
 	// This is the one that will go in their inbox.
843 883
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
844 884
 	preparsecode($htmlmessage);
845 885
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
846
-	if ($smcFunc['strlen']($htmlsubject) > 100)
847
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
886
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
887
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
888
+	}
848 889
 
849 890
 	// Make sure is an array
850
-	if (!is_array($recipients))
851
-		$recipients = array($recipients);
891
+	if (!is_array($recipients)) {
892
+			$recipients = array($recipients);
893
+	}
852 894
 
853 895
 	// Integrated PMs
854 896
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -876,21 +918,23 @@  discard block
 block discarded – undo
876 918
 				'usernames' => array_keys($usernames),
877 919
 			)
878 920
 		);
879
-		while ($row = $smcFunc['db_fetch_assoc']($request))
880
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
921
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
922
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
881 923
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
924
+		}
882 925
 		$smcFunc['db_free_result']($request);
883 926
 
884 927
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
885
-		foreach ($recipients as $rec_type => $rec)
886
-			foreach ($rec as $id => $member)
928
+		foreach ($recipients as $rec_type => $rec) {
929
+					foreach ($rec as $id => $member)
887 930
 			{
888 931
 				if (is_numeric($recipients[$rec_type][$id]))
889 932
 					continue;
933
+		}
890 934
 
891
-				if (!empty($usernames[$member]))
892
-					$recipients[$rec_type][$id] = $usernames[$member];
893
-				else
935
+				if (!empty($usernames[$member])) {
936
+									$recipients[$rec_type][$id] = $usernames[$member];
937
+				} else
894 938
 				{
895 939
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
896 940
 					unset($recipients[$rec_type][$id]);
@@ -928,8 +972,9 @@  discard block
 block discarded – undo
928 972
 		$delete = false;
929 973
 		foreach ($criteria as $criterium)
930 974
 		{
931
-			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
932
-				$delete = true;
975
+			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) {
976
+							$delete = true;
977
+			}
933 978
 			// If we're adding and one criteria don't match then we stop!
934 979
 			elseif (!$row['is_or'])
935 980
 			{
@@ -937,8 +982,9 @@  discard block
 block discarded – undo
937 982
 				break;
938 983
 			}
939 984
 		}
940
-		if ($delete)
941
-			$deletes[$row['id_member']] = 1;
985
+		if ($delete) {
986
+					$deletes[$row['id_member']] = 1;
987
+		}
942 988
 	}
943 989
 	$smcFunc['db_free_result']($request);
944 990
 
@@ -953,8 +999,9 @@  discard block
 block discarded – undo
953 999
 			array(
954 1000
 			)
955 1001
 		);
956
-		while ($row = $smcFunc['db_fetch_assoc']($request))
957
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
1002
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1003
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
1004
+		}
958 1005
 		$smcFunc['db_free_result']($request);
959 1006
 	}
960 1007
 
@@ -962,8 +1009,9 @@  discard block
 block discarded – undo
962 1009
 	require_once($sourcedir . '/Subs-Members.php');
963 1010
 	$pmReadGroups = groupsAllowedTo('pm_read');
964 1011
 
965
-	if (empty($modSettings['permission_enable_deny']))
966
-		$pmReadGroups['denied'] = array();
1012
+	if (empty($modSettings['permission_enable_deny'])) {
1013
+			$pmReadGroups['denied'] = array();
1014
+	}
967 1015
 
968 1016
 	// Load their alert preferences
969 1017
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -995,8 +1043,9 @@  discard block
 block discarded – undo
995 1043
 	while ($row = $smcFunc['db_fetch_assoc']($request))
996 1044
 	{
997 1045
 		// Don't do anything for members to be deleted!
998
-		if (isset($deletes[$row['id_member']]))
999
-			continue;
1046
+		if (isset($deletes[$row['id_member']])) {
1047
+					continue;
1048
+		}
1000 1049
 
1001 1050
 		// Load the preferences for this member (if any)
1002 1051
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -1017,8 +1066,9 @@  discard block
 block discarded – undo
1017 1066
 		{
1018 1067
 			foreach ($groups as $id)
1019 1068
 			{
1020
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
1021
-					$message_limit = $message_limit_cache[$id];
1069
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1070
+									$message_limit = $message_limit_cache[$id];
1071
+				}
1022 1072
 			}
1023 1073
 
1024 1074
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1066,8 +1116,9 @@  discard block
 block discarded – undo
1066 1116
 	$smcFunc['db_free_result']($request);
1067 1117
 
1068 1118
 	// Only 'send' the message if there are any recipients left.
1069
-	if (empty($all_to))
1070
-		return $log;
1119
+	if (empty($all_to)) {
1120
+			return $log;
1121
+	}
1071 1122
 
1072 1123
 	// Insert the message itself and then grab the last insert id.
1073 1124
 	$id_pm = $smcFunc['db_insert']('',
@@ -1088,8 +1139,8 @@  discard block
 block discarded – undo
1088 1139
 	if (!empty($id_pm))
1089 1140
 	{
1090 1141
 		// If this is new we need to set it part of it's own conversation.
1091
-		if (empty($pm_head))
1092
-			$smcFunc['db_query']('', '
1142
+		if (empty($pm_head)) {
1143
+					$smcFunc['db_query']('', '
1093 1144
 				UPDATE {db_prefix}personal_messages
1094 1145
 				SET id_pm_head = {int:id_pm_head}
1095 1146
 				WHERE id_pm = {int:id_pm_head}',
@@ -1097,6 +1148,7 @@  discard block
 block discarded – undo
1097 1148
 					'id_pm_head' => $id_pm,
1098 1149
 				)
1099 1150
 			);
1151
+		}
1100 1152
 
1101 1153
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1102 1154
 		$smcFunc['db_query']('', '
@@ -1112,8 +1164,9 @@  discard block
 block discarded – undo
1112 1164
 		foreach ($all_to as $to)
1113 1165
 		{
1114 1166
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1115
-			if (!in_array($to, $recipients['bcc']))
1116
-				$to_list[] = $to;
1167
+			if (!in_array($to, $recipients['bcc'])) {
1168
+							$to_list[] = $to;
1169
+			}
1117 1170
 		}
1118 1171
 
1119 1172
 		$smcFunc['db_insert']('insert',
@@ -1131,9 +1184,9 @@  discard block
 block discarded – undo
1131 1184
 	{
1132 1185
 		censorText($message);
1133 1186
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1187
+	} else {
1188
+			$message = '';
1134 1189
 	}
1135
-	else
1136
-		$message = '';
1137 1190
 
1138 1191
 	$to_names = array();
1139 1192
 	if (count($to_list) > 1)
@@ -1146,8 +1199,9 @@  discard block
 block discarded – undo
1146 1199
 				'to_members' => $to_list,
1147 1200
 			)
1148 1201
 		);
1149
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1150
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1202
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1203
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1204
+		}
1151 1205
 		$smcFunc['db_free_result']($request);
1152 1206
 	}
1153 1207
 	$replacements = array(
@@ -1175,11 +1229,13 @@  discard block
 block discarded – undo
1175 1229
 	loadLanguage('index+PersonalMessage');
1176 1230
 
1177 1231
 	// Add one to their unread and read message counts.
1178
-	foreach ($all_to as $k => $id)
1179
-		if (isset($deletes[$id]))
1232
+	foreach ($all_to as $k => $id) {
1233
+			if (isset($deletes[$id]))
1180 1234
 			unset($all_to[$k]);
1181
-	if (!empty($all_to))
1182
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1235
+	}
1236
+	if (!empty($all_to)) {
1237
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1238
+	}
1183 1239
 
1184 1240
 	return $log;
1185 1241
 }
@@ -1209,15 +1265,17 @@  discard block
 block discarded – undo
1209 1265
 		// Let's, for now, assume there are only &#021;'ish characters.
1210 1266
 		$simple = true;
1211 1267
 
1212
-		foreach ($matches[1] as $entity)
1213
-			if ($entity > 128)
1268
+		foreach ($matches[1] as $entity) {
1269
+					if ($entity > 128)
1214 1270
 				$simple = false;
1271
+		}
1215 1272
 		unset($matches);
1216 1273
 
1217
-		if ($simple)
1218
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1274
+		if ($simple) {
1275
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1219 1276
 			{
1220 1277
 				return chr("$m[1]");
1278
+		}
1221 1279
 			}, $string);
1222 1280
 		else
1223 1281
 		{
@@ -1225,8 +1283,9 @@  discard block
 block discarded – undo
1225 1283
 			if (!$context['utf8'] && function_exists('iconv'))
1226 1284
 			{
1227 1285
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1228
-				if ($newstring)
1229
-					$string = $newstring;
1286
+				if ($newstring) {
1287
+									$string = $newstring;
1288
+				}
1230 1289
 			}
1231 1290
 
1232 1291
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1242,23 +1301,25 @@  discard block
 block discarded – undo
1242 1301
 		if (!$context['utf8'] && function_exists('iconv'))
1243 1302
 		{
1244 1303
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1245
-			if ($newstring)
1246
-				$string = $newstring;
1304
+			if ($newstring) {
1305
+							$string = $newstring;
1306
+			}
1247 1307
 		}
1248 1308
 
1249 1309
 		$entityConvert = function($m)
1250 1310
 		{
1251 1311
 			$c = $m[1];
1252
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1253
-				return $c;
1254
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1255
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1256
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1257
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1258
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1259
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1260
-			else
1261
-				return "";
1312
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1313
+							return $c;
1314
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1315
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1316
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1317
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1318
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1319
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1320
+			} else {
1321
+							return "";
1322
+			}
1262 1323
 		};
1263 1324
 
1264 1325
 		// Convert all 'special' characters to HTML entities.
@@ -1272,19 +1333,20 @@  discard block
 block discarded – undo
1272 1333
 		$string = base64_encode($string);
1273 1334
 
1274 1335
 		// Show the characterset and the transfer-encoding for header strings.
1275
-		if ($with_charset)
1276
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1336
+		if ($with_charset) {
1337
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1338
+		}
1277 1339
 
1278 1340
 		// Break it up in lines (mail body).
1279
-		else
1280
-			$string = chunk_split($string, 76, $line_break);
1341
+		else {
1342
+					$string = chunk_split($string, 76, $line_break);
1343
+		}
1281 1344
 
1282 1345
 		return array($charset, $string, 'base64');
1346
+	} else {
1347
+			return array($charset, $string, '7bit');
1348
+	}
1283 1349
 	}
1284
-
1285
-	else
1286
-		return array($charset, $string, '7bit');
1287
-}
1288 1350
 
1289 1351
 /**
1290 1352
  * Sends mail, like mail() but over SMTP.
@@ -1308,8 +1370,9 @@  discard block
 block discarded – undo
1308 1370
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1309 1371
 	{
1310 1372
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1311
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1312
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1373
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1374
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1375
+		}
1313 1376
 
1314 1377
 		if ($socket)
1315 1378
 		{
@@ -1330,8 +1393,9 @@  discard block
 block discarded – undo
1330 1393
 		// Maybe we can still save this?  The port might be wrong.
1331 1394
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1332 1395
 		{
1333
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1334
-				log_error($txt['smtp_port_ssl']);
1396
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1397
+							log_error($txt['smtp_port_ssl']);
1398
+			}
1335 1399
 		}
1336 1400
 
1337 1401
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1343,20 +1407,23 @@  discard block
 block discarded – undo
1343 1407
 	}
1344 1408
 
1345 1409
 	// Wait for a response of 220, without "-" continuer.
1346
-	if (!server_parse(null, $socket, '220'))
1347
-		return false;
1410
+	if (!server_parse(null, $socket, '220')) {
1411
+			return false;
1412
+	}
1348 1413
 
1349 1414
 	// Try and determine the servers name, fall back to the mail servers if not found
1350 1415
 	$helo = false;
1351
-	if (function_exists('gethostname') && gethostname() !== false)
1352
-		$helo = gethostname();
1353
-	elseif (function_exists('php_uname'))
1354
-		$helo = php_uname('n');
1355
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1356
-		$helo = $_SERVER['SERVER_NAME'];
1416
+	if (function_exists('gethostname') && gethostname() !== false) {
1417
+			$helo = gethostname();
1418
+	} elseif (function_exists('php_uname')) {
1419
+			$helo = php_uname('n');
1420
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1421
+			$helo = $_SERVER['SERVER_NAME'];
1422
+	}
1357 1423
 
1358
-	if (empty($helo))
1359
-		$helo = $modSettings['smtp_host'];
1424
+	if (empty($helo)) {
1425
+			$helo = $modSettings['smtp_host'];
1426
+	}
1360 1427
 
1361 1428
 	// SMTP = 1, SMTP - STARTTLS = 2
1362 1429
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1368,33 +1435,39 @@  discard block
 block discarded – undo
1368 1435
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1369 1436
 			{
1370 1437
 				// Send STARTTLS to enable encryption
1371
-				if (!server_parse('STARTTLS', $socket, '220'))
1372
-					return false;
1438
+				if (!server_parse('STARTTLS', $socket, '220')) {
1439
+									return false;
1440
+				}
1373 1441
 				// Enable the encryption
1374
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1375
-					return false;
1442
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1443
+									return false;
1444
+				}
1376 1445
 				// Send the EHLO command again
1377
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1378
-					return false;
1446
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1447
+									return false;
1448
+				}
1379 1449
 			}
1380 1450
 
1381
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1382
-				return false;
1451
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1452
+							return false;
1453
+			}
1383 1454
 			// Send the username and password, encoded.
1384
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1385
-				return false;
1455
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1456
+							return false;
1457
+			}
1386 1458
 			// The password is already encoded ;)
1387
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1388
-				return false;
1459
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1460
+							return false;
1461
+			}
1462
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1463
+					return false;
1389 1464
 		}
1390
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1391
-			return false;
1392
-	}
1393
-	else
1465
+	} else
1394 1466
 	{
1395 1467
 		// Just say "helo".
1396
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1397
-			return false;
1468
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1469
+					return false;
1470
+		}
1398 1471
 	}
1399 1472
 
1400 1473
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1407,31 +1480,38 @@  discard block
 block discarded – undo
1407 1480
 		// Reset the connection to send another email.
1408 1481
 		if ($i != 0)
1409 1482
 		{
1410
-			if (!server_parse('RSET', $socket, '250'))
1411
-				return false;
1483
+			if (!server_parse('RSET', $socket, '250')) {
1484
+							return false;
1485
+			}
1412 1486
 		}
1413 1487
 
1414 1488
 		// From, to, and then start the data...
1415
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1416
-			return false;
1417
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1418
-			return false;
1419
-		if (!server_parse('DATA', $socket, '354'))
1420
-			return false;
1489
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1490
+					return false;
1491
+		}
1492
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1493
+					return false;
1494
+		}
1495
+		if (!server_parse('DATA', $socket, '354')) {
1496
+					return false;
1497
+		}
1421 1498
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1422
-		if (strlen($mail_to) > 0)
1423
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1499
+		if (strlen($mail_to) > 0) {
1500
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1501
+		}
1424 1502
 		fputs($socket, $headers . "\r\n\r\n");
1425 1503
 		fputs($socket, $message . "\r\n");
1426 1504
 
1427 1505
 		// Send a ., or in other words "end of data".
1428
-		if (!server_parse('.', $socket, '250'))
1429
-			return false;
1506
+		if (!server_parse('.', $socket, '250')) {
1507
+					return false;
1508
+		}
1430 1509
 
1431 1510
 		// Almost done, almost done... don't stop me just yet!
1432 1511
 		@set_time_limit(300);
1433
-		if (function_exists('apache_reset_timeout'))
1434
-			@apache_reset_timeout();
1512
+		if (function_exists('apache_reset_timeout')) {
1513
+					@apache_reset_timeout();
1514
+		}
1435 1515
 	}
1436 1516
 	fputs($socket, 'QUIT' . "\r\n");
1437 1517
 	fclose($socket);
@@ -1455,8 +1535,9 @@  discard block
 block discarded – undo
1455 1535
 {
1456 1536
 	global $txt;
1457 1537
 
1458
-	if ($message !== null)
1459
-		fputs($socket, $message . "\r\n");
1538
+	if ($message !== null) {
1539
+			fputs($socket, $message . "\r\n");
1540
+	}
1460 1541
 
1461 1542
 	// No response yet.
1462 1543
 	$server_response = '';
@@ -1472,8 +1553,9 @@  discard block
 block discarded – undo
1472 1553
 		$response .= $server_response;
1473 1554
 	}
1474 1555
 
1475
-	if ($code === null)
1476
-		return substr($server_response, 0, 3);
1556
+	if ($code === null) {
1557
+			return substr($server_response, 0, 3);
1558
+	}
1477 1559
 
1478 1560
 	if (substr($server_response, 0, 3) != $code)
1479 1561
 	{
@@ -1503,8 +1585,9 @@  discard block
 block discarded – undo
1503 1585
 	// Create a pspell or enchant dictionary resource
1504 1586
 	$dict = spell_init();
1505 1587
 
1506
-	if (!isset($_POST['spellstring']) || !$dict)
1507
-		die;
1588
+	if (!isset($_POST['spellstring']) || !$dict) {
1589
+			die;
1590
+	}
1508 1591
 
1509 1592
 	// Construct a bit of Javascript code.
1510 1593
 	$context['spell_js'] = '
@@ -1522,8 +1605,9 @@  discard block
 block discarded – undo
1522 1605
 		$check_word = explode('|', $alphas[$i]);
1523 1606
 
1524 1607
 		// If the word is a known word, or spelled right...
1525
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1526
-			continue;
1608
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1609
+					continue;
1610
+		}
1527 1611
 
1528 1612
 		// Find the word, and move up the "last occurrence" to here.
1529 1613
 		$found_words = true;
@@ -1537,20 +1621,23 @@  discard block
 block discarded – undo
1537 1621
 		if (!empty($suggestions))
1538 1622
 		{
1539 1623
 			// But first check they aren't going to be censored - no naughty words!
1540
-			foreach ($suggestions as $k => $word)
1541
-				if ($suggestions[$k] != censorText($word))
1624
+			foreach ($suggestions as $k => $word) {
1625
+							if ($suggestions[$k] != censorText($word))
1542 1626
 					unset($suggestions[$k]);
1627
+			}
1543 1628
 
1544
-			if (!empty($suggestions))
1545
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1629
+			if (!empty($suggestions)) {
1630
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1631
+			}
1546 1632
 		}
1547 1633
 
1548 1634
 		$context['spell_js'] .= ']),';
1549 1635
 	}
1550 1636
 
1551 1637
 	// If words were found, take off the last comma.
1552
-	if ($found_words)
1553
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1638
+	if ($found_words) {
1639
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1640
+	}
1554 1641
 
1555 1642
 	$context['spell_js'] .= '
1556 1643
 		);';
@@ -1585,11 +1672,13 @@  discard block
 block discarded – undo
1585 1672
 	global $user_info, $smcFunc;
1586 1673
 
1587 1674
 	// Can't do it if there's no topics.
1588
-	if (empty($topics))
1589
-		return;
1675
+	if (empty($topics)) {
1676
+			return;
1677
+	}
1590 1678
 	// It must be an array - it must!
1591
-	if (!is_array($topics))
1592
-		$topics = array($topics);
1679
+	if (!is_array($topics)) {
1680
+			$topics = array($topics);
1681
+	}
1593 1682
 
1594 1683
 	// Get the subject and body...
1595 1684
 	$result = $smcFunc['db_query']('', '
@@ -1637,14 +1726,15 @@  discard block
 block discarded – undo
1637 1726
 	}
1638 1727
 	$smcFunc['db_free_result']($result);
1639 1728
 
1640
-	if (!empty($task_rows))
1641
-		$smcFunc['db_insert']('',
1729
+	if (!empty($task_rows)) {
1730
+			$smcFunc['db_insert']('',
1642 1731
 			'{db_prefix}background_tasks',
1643 1732
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1644 1733
 			$task_rows,
1645 1734
 			array('id_task')
1646 1735
 		);
1647
-}
1736
+	}
1737
+	}
1648 1738
 
1649 1739
 /**
1650 1740
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1682,9 +1772,9 @@  discard block
 block discarded – undo
1682 1772
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1683 1773
 
1684 1774
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1685
-	if (!$modSettings['postmod_active'])
1686
-		$topicOptions['is_approved'] = true;
1687
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1775
+	if (!$modSettings['postmod_active']) {
1776
+			$topicOptions['is_approved'] = true;
1777
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1688 1778
 	{
1689 1779
 		$request = $smcFunc['db_query']('', '
1690 1780
 			SELECT approved
@@ -1707,8 +1797,7 @@  discard block
 block discarded – undo
1707 1797
 			$posterOptions['id'] = 0;
1708 1798
 			$posterOptions['name'] = $txt['guest_title'];
1709 1799
 			$posterOptions['email'] = '';
1710
-		}
1711
-		elseif ($posterOptions['id'] != $user_info['id'])
1800
+		} elseif ($posterOptions['id'] != $user_info['id'])
1712 1801
 		{
1713 1802
 			$request = $smcFunc['db_query']('', '
1714 1803
 				SELECT member_name, email_address
@@ -1726,12 +1815,11 @@  discard block
 block discarded – undo
1726 1815
 				$posterOptions['id'] = 0;
1727 1816
 				$posterOptions['name'] = $txt['guest_title'];
1728 1817
 				$posterOptions['email'] = '';
1818
+			} else {
1819
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1729 1820
 			}
1730
-			else
1731
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1732 1821
 			$smcFunc['db_free_result']($request);
1733
-		}
1734
-		else
1822
+		} else
1735 1823
 		{
1736 1824
 			$posterOptions['name'] = $user_info['name'];
1737 1825
 			$posterOptions['email'] = $user_info['email'];
@@ -1741,8 +1829,9 @@  discard block
 block discarded – undo
1741 1829
 	if (!empty($modSettings['enable_mentions']))
1742 1830
 	{
1743 1831
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1744
-		if (!empty($msgOptions['mentioned_members']))
1745
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1832
+		if (!empty($msgOptions['mentioned_members'])) {
1833
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1834
+		}
1746 1835
 	}
1747 1836
 
1748 1837
 	// It's do or die time: forget any user aborts!
@@ -1775,12 +1864,13 @@  discard block
 block discarded – undo
1775 1864
 	);
1776 1865
 
1777 1866
 	// Something went wrong creating the message...
1778
-	if (empty($msgOptions['id']))
1779
-		return false;
1867
+	if (empty($msgOptions['id'])) {
1868
+			return false;
1869
+	}
1780 1870
 
1781 1871
 	// Fix the attachments.
1782
-	if (!empty($msgOptions['attachments']))
1783
-		$smcFunc['db_query']('', '
1872
+	if (!empty($msgOptions['attachments'])) {
1873
+			$smcFunc['db_query']('', '
1784 1874
 			UPDATE {db_prefix}attachments
1785 1875
 			SET id_msg = {int:id_msg}
1786 1876
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1789,6 +1879,7 @@  discard block
 block discarded – undo
1789 1879
 				'id_msg' => $msgOptions['id'],
1790 1880
 			)
1791 1881
 		);
1882
+	}
1792 1883
 
1793 1884
 	// What if we want to export new posts out to a CMS?
1794 1885
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1865,20 +1956,23 @@  discard block
 block discarded – undo
1865 1956
 			'id_topic' => $topicOptions['id'],
1866 1957
 			'counter_increment' => 1,
1867 1958
 		);
1868
-		if ($msgOptions['approved'])
1869
-			$topics_columns = array(
1959
+		if ($msgOptions['approved']) {
1960
+					$topics_columns = array(
1870 1961
 				'id_member_updated = {int:poster_id}',
1871 1962
 				'id_last_msg = {int:id_msg}',
1872 1963
 				'num_replies = num_replies + {int:counter_increment}',
1873 1964
 			);
1874
-		else
1875
-			$topics_columns = array(
1965
+		} else {
1966
+					$topics_columns = array(
1876 1967
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1877 1968
 			);
1878
-		if ($topicOptions['lock_mode'] !== null)
1879
-			$topics_columns[] = 'locked = {int:locked}';
1880
-		if ($topicOptions['sticky_mode'] !== null)
1881
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1969
+		}
1970
+		if ($topicOptions['lock_mode'] !== null) {
1971
+					$topics_columns[] = 'locked = {int:locked}';
1972
+		}
1973
+		if ($topicOptions['sticky_mode'] !== null) {
1974
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1975
+		}
1882 1976
 
1883 1977
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1884 1978
 
@@ -1907,8 +2001,8 @@  discard block
 block discarded – undo
1907 2001
 	);
1908 2002
 
1909 2003
 	// Increase the number of posts and topics on the board.
1910
-	if ($msgOptions['approved'])
1911
-		$smcFunc['db_query']('', '
2004
+	if ($msgOptions['approved']) {
2005
+			$smcFunc['db_query']('', '
1912 2006
 			UPDATE {db_prefix}boards
1913 2007
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1914 2008
 			WHERE id_board = {int:id_board}',
@@ -1916,7 +2010,7 @@  discard block
 block discarded – undo
1916 2010
 				'id_board' => $topicOptions['board'],
1917 2011
 			)
1918 2012
 		);
1919
-	else
2013
+	} else
1920 2014
 	{
1921 2015
 		$smcFunc['db_query']('', '
1922 2016
 			UPDATE {db_prefix}boards
@@ -1986,8 +2080,8 @@  discard block
 block discarded – undo
1986 2080
 		}
1987 2081
 	}
1988 2082
 
1989
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1990
-		$smcFunc['db_insert']('',
2083
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2084
+			$smcFunc['db_insert']('',
1991 2085
 			'{db_prefix}background_tasks',
1992 2086
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1993 2087
 			array(
@@ -1999,19 +2093,22 @@  discard block
 block discarded – undo
1999 2093
 			),
2000 2094
 			array('id_task')
2001 2095
 		);
2096
+	}
2002 2097
 
2003 2098
 	// If there's a custom search index, it may need updating...
2004 2099
 	require_once($sourcedir . '/Search.php');
2005 2100
 	$searchAPI = findSearchAPI();
2006
-	if (is_callable(array($searchAPI, 'postCreated')))
2007
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2101
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2102
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2103
+	}
2008 2104
 
2009 2105
 	// Increase the post counter for the user that created the post.
2010 2106
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
2011 2107
 	{
2012 2108
 		// Are you the one that happened to create this post?
2013
-		if ($user_info['id'] == $posterOptions['id'])
2014
-			$user_info['posts']++;
2109
+		if ($user_info['id'] == $posterOptions['id']) {
2110
+					$user_info['posts']++;
2111
+		}
2015 2112
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
2016 2113
 	}
2017 2114
 
@@ -2019,19 +2116,21 @@  discard block
 block discarded – undo
2019 2116
 	$_SESSION['last_read_topic'] = 0;
2020 2117
 
2021 2118
 	// Better safe than sorry.
2022
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
2023
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2119
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2120
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2121
+	}
2024 2122
 
2025 2123
 	// Update all the stats so everyone knows about this new topic and message.
2026 2124
 	updateStats('message', true, $msgOptions['id']);
2027 2125
 
2028 2126
 	// Update the last message on the board assuming it's approved AND the topic is.
2029
-	if ($msgOptions['approved'])
2030
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2127
+	if ($msgOptions['approved']) {
2128
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2129
+	}
2031 2130
 
2032 2131
 	// Queue createPost background notification
2033
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
2034
-		$smcFunc['db_insert']('',
2132
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2133
+			$smcFunc['db_insert']('',
2035 2134
 			'{db_prefix}background_tasks',
2036 2135
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2037 2136
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
@@ -2042,6 +2141,7 @@  discard block
 block discarded – undo
2042 2141
 			)), 0),
2043 2142
 			array('id_task')
2044 2143
 		);
2144
+	}
2045 2145
 
2046 2146
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2047 2147
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2068,14 +2168,18 @@  discard block
 block discarded – undo
2068 2168
 
2069 2169
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2070 2170
 	$messages_columns = array();
2071
-	if (isset($posterOptions['name']))
2072
-		$messages_columns['poster_name'] = $posterOptions['name'];
2073
-	if (isset($posterOptions['email']))
2074
-		$messages_columns['poster_email'] = $posterOptions['email'];
2075
-	if (isset($msgOptions['icon']))
2076
-		$messages_columns['icon'] = $msgOptions['icon'];
2077
-	if (isset($msgOptions['subject']))
2078
-		$messages_columns['subject'] = $msgOptions['subject'];
2171
+	if (isset($posterOptions['name'])) {
2172
+			$messages_columns['poster_name'] = $posterOptions['name'];
2173
+	}
2174
+	if (isset($posterOptions['email'])) {
2175
+			$messages_columns['poster_email'] = $posterOptions['email'];
2176
+	}
2177
+	if (isset($msgOptions['icon'])) {
2178
+			$messages_columns['icon'] = $msgOptions['icon'];
2179
+	}
2180
+	if (isset($msgOptions['subject'])) {
2181
+			$messages_columns['subject'] = $msgOptions['subject'];
2182
+	}
2079 2183
 	if (isset($msgOptions['body']))
2080 2184
 	{
2081 2185
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2102,8 +2206,9 @@  discard block
 block discarded – undo
2102 2206
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2103 2207
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2104 2208
 	}
2105
-	if (isset($msgOptions['smileys_enabled']))
2106
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2209
+	if (isset($msgOptions['smileys_enabled'])) {
2210
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2211
+	}
2107 2212
 
2108 2213
 	// Which columns need to be ints?
2109 2214
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2121,23 +2226,27 @@  discard block
 block discarded – undo
2121 2226
 		{
2122 2227
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2123 2228
 
2124
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2125
-				foreach ($match[1] as $i => $oldID)
2229
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2230
+							foreach ($match[1] as $i => $oldID)
2126 2231
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2232
+			}
2127 2233
 
2128
-			if (empty($modSettings['search_custom_index_config']))
2129
-				unset($msgOptions['old_body']);
2234
+			if (empty($modSettings['search_custom_index_config'])) {
2235
+							unset($msgOptions['old_body']);
2236
+			}
2130 2237
 		}
2131 2238
 
2132 2239
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2133 2240
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2134 2241
 
2135 2242
 		// Remove the poster.
2136
-		if (isset($mentions[$user_info['id']]))
2137
-			unset($mentions[$user_info['id']]);
2243
+		if (isset($mentions[$user_info['id']])) {
2244
+					unset($mentions[$user_info['id']]);
2245
+		}
2138 2246
 
2139
-		if (isset($oldmentions[$user_info['id']]))
2140
-			unset($oldmentions[$user_info['id']]);
2247
+		if (isset($oldmentions[$user_info['id']])) {
2248
+					unset($oldmentions[$user_info['id']]);
2249
+		}
2141 2250
 
2142 2251
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2143 2252
 		{
@@ -2167,8 +2276,9 @@  discard block
 block discarded – undo
2167 2276
 	}
2168 2277
 
2169 2278
 	// Nothing to do?
2170
-	if (empty($messages_columns))
2171
-		return true;
2279
+	if (empty($messages_columns)) {
2280
+			return true;
2281
+	}
2172 2282
 
2173 2283
 	// Change the post.
2174 2284
 	$smcFunc['db_query']('', '
@@ -2229,8 +2339,9 @@  discard block
 block discarded – undo
2229 2339
 	// If there's a custom search index, it needs to be modified...
2230 2340
 	require_once($sourcedir . '/Search.php');
2231 2341
 	$searchAPI = findSearchAPI();
2232
-	if (is_callable(array($searchAPI, 'postModified')))
2233
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2342
+	if (is_callable(array($searchAPI, 'postModified'))) {
2343
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2344
+	}
2234 2345
 
2235 2346
 	if (isset($msgOptions['subject']))
2236 2347
 	{
@@ -2244,14 +2355,16 @@  discard block
 block discarded – undo
2244 2355
 				'id_first_msg' => $msgOptions['id'],
2245 2356
 			)
2246 2357
 		);
2247
-		if ($smcFunc['db_num_rows']($request) == 1)
2248
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2358
+		if ($smcFunc['db_num_rows']($request) == 1) {
2359
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2360
+		}
2249 2361
 		$smcFunc['db_free_result']($request);
2250 2362
 	}
2251 2363
 
2252 2364
 	// Finally, if we are setting the approved state we need to do much more work :(
2253
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2254
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2365
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2366
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2367
+	}
2255 2368
 
2256 2369
 	return true;
2257 2370
 }
@@ -2268,11 +2381,13 @@  discard block
 block discarded – undo
2268 2381
 {
2269 2382
 	global $smcFunc;
2270 2383
 
2271
-	if (!is_array($msgs))
2272
-		$msgs = array($msgs);
2384
+	if (!is_array($msgs)) {
2385
+			$msgs = array($msgs);
2386
+	}
2273 2387
 
2274
-	if (empty($msgs))
2275
-		return false;
2388
+	if (empty($msgs)) {
2389
+			return false;
2390
+	}
2276 2391
 
2277 2392
 	// May as well start at the beginning, working out *what* we need to change.
2278 2393
 	$request = $smcFunc['db_query']('', '
@@ -2304,20 +2419,22 @@  discard block
 block discarded – undo
2304 2419
 		$topics[] = $row['id_topic'];
2305 2420
 
2306 2421
 		// Ensure our change array exists already.
2307
-		if (!isset($topic_changes[$row['id_topic']]))
2308
-			$topic_changes[$row['id_topic']] = array(
2422
+		if (!isset($topic_changes[$row['id_topic']])) {
2423
+					$topic_changes[$row['id_topic']] = array(
2309 2424
 				'id_last_msg' => $row['id_last_msg'],
2310 2425
 				'approved' => $row['topic_approved'],
2311 2426
 				'replies' => 0,
2312 2427
 				'unapproved_posts' => 0,
2313 2428
 			);
2314
-		if (!isset($board_changes[$row['id_board']]))
2315
-			$board_changes[$row['id_board']] = array(
2429
+		}
2430
+		if (!isset($board_changes[$row['id_board']])) {
2431
+					$board_changes[$row['id_board']] = array(
2316 2432
 				'posts' => 0,
2317 2433
 				'topics' => 0,
2318 2434
 				'unapproved_posts' => 0,
2319 2435
 				'unapproved_topics' => 0,
2320 2436
 			);
2437
+		}
2321 2438
 
2322 2439
 		// If it's the first message then the topic state changes!
2323 2440
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2338,14 +2455,13 @@  discard block
 block discarded – undo
2338 2455
 				'poster' => $row['id_member'],
2339 2456
 				'new_topic' => true,
2340 2457
 			);
2341
-		}
2342
-		else
2458
+		} else
2343 2459
 		{
2344 2460
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2345 2461
 
2346 2462
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2347
-			if ($row['id_msg'] > $row['id_last_msg'])
2348
-				$notification_posts[$row['id_topic']] = array(
2463
+			if ($row['id_msg'] > $row['id_last_msg']) {
2464
+							$notification_posts[$row['id_topic']] = array(
2349 2465
 					'id' => $row['id_msg'],
2350 2466
 					'body' => $row['body'],
2351 2467
 					'subject' => $row['subject'],
@@ -2356,28 +2472,33 @@  discard block
 block discarded – undo
2356 2472
 					'new_topic' => false,
2357 2473
 					'msg' => $row['id_msg'],
2358 2474
 				);
2475
+			}
2359 2476
 		}
2360 2477
 
2361 2478
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2362
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2363
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2479
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2480
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2481
+		}
2364 2482
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2365
-		elseif (!$approve)
2366
-			// Default to the first message and then we'll override in a bit ;)
2483
+		elseif (!$approve) {
2484
+					// Default to the first message and then we'll override in a bit ;)
2367 2485
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2486
+		}
2368 2487
 
2369 2488
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2370 2489
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2371 2490
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2372 2491
 
2373 2492
 		// Post count for the user?
2374
-		if ($row['id_member'] && empty($row['count_posts']))
2375
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2493
+		if ($row['id_member'] && empty($row['count_posts'])) {
2494
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2495
+		}
2376 2496
 	}
2377 2497
 	$smcFunc['db_free_result']($request);
2378 2498
 
2379
-	if (empty($msgs))
2380
-		return;
2499
+	if (empty($msgs)) {
2500
+			return;
2501
+	}
2381 2502
 
2382 2503
 	// Now we have the differences make the changes, first the easy one.
2383 2504
 	$smcFunc['db_query']('', '
@@ -2404,14 +2525,15 @@  discard block
 block discarded – undo
2404 2525
 				'approved' => 1,
2405 2526
 			)
2406 2527
 		);
2407
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2408
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2528
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2529
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2530
+		}
2409 2531
 		$smcFunc['db_free_result']($request);
2410 2532
 	}
2411 2533
 
2412 2534
 	// ... next the topics...
2413
-	foreach ($topic_changes as $id => $changes)
2414
-		$smcFunc['db_query']('', '
2535
+	foreach ($topic_changes as $id => $changes) {
2536
+			$smcFunc['db_query']('', '
2415 2537
 			UPDATE {db_prefix}topics
2416 2538
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2417 2539
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2424,10 +2546,11 @@  discard block
 block discarded – undo
2424 2546
 				'id_topic' => $id,
2425 2547
 			)
2426 2548
 		);
2549
+	}
2427 2550
 
2428 2551
 	// ... finally the boards...
2429
-	foreach ($board_changes as $id => $changes)
2430
-		$smcFunc['db_query']('', '
2552
+	foreach ($board_changes as $id => $changes) {
2553
+			$smcFunc['db_query']('', '
2431 2554
 			UPDATE {db_prefix}boards
2432 2555
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2433 2556
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2440,13 +2563,14 @@  discard block
 block discarded – undo
2440 2563
 				'id_board' => $id,
2441 2564
 			)
2442 2565
 		);
2566
+	}
2443 2567
 
2444 2568
 	// Finally, least importantly, notifications!
2445 2569
 	if ($approve)
2446 2570
 	{
2447 2571
 		$task_rows = array();
2448
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2449
-			$task_rows[] = array(
2572
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2573
+					$task_rows[] = array(
2450 2574
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
2451 2575
 					'msgOptions' => array(
2452 2576
 						'id' => $topic['msg'],
@@ -2464,14 +2588,16 @@  discard block
 block discarded – undo
2464 2588
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2465 2589
 				)), 0
2466 2590
 			);
2591
+		}
2467 2592
 
2468
-		if ($notify)
2469
-			$smcFunc['db_insert']('',
2593
+		if ($notify) {
2594
+					$smcFunc['db_insert']('',
2470 2595
 				'{db_prefix}background_tasks',
2471 2596
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2472 2597
 				$task_rows,
2473 2598
 				array('id_task')
2474 2599
 			);
2600
+		}
2475 2601
 
2476 2602
 		$smcFunc['db_query']('', '
2477 2603
 			DELETE FROM {db_prefix}approval_queue
@@ -2487,8 +2613,9 @@  discard block
 block discarded – undo
2487 2613
 	else
2488 2614
 	{
2489 2615
 		$msgInserts = array();
2490
-		foreach ($msgs as $msg)
2491
-			$msgInserts[] = array($msg);
2616
+		foreach ($msgs as $msg) {
2617
+					$msgInserts[] = array($msg);
2618
+		}
2492 2619
 
2493 2620
 		$smcFunc['db_insert']('ignore',
2494 2621
 			'{db_prefix}approval_queue',
@@ -2502,9 +2629,10 @@  discard block
 block discarded – undo
2502 2629
 	updateLastMessages(array_keys($board_changes));
2503 2630
 
2504 2631
 	// Post count for the members?
2505
-	if (!empty($member_post_changes))
2506
-		foreach ($member_post_changes as $id_member => $count_change)
2632
+	if (!empty($member_post_changes)) {
2633
+			foreach ($member_post_changes as $id_member => $count_change)
2507 2634
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2635
+	}
2508 2636
 
2509 2637
 	return true;
2510 2638
 }
@@ -2521,11 +2649,13 @@  discard block
 block discarded – undo
2521 2649
 {
2522 2650
 	global $smcFunc;
2523 2651
 
2524
-	if (!is_array($topics))
2525
-		$topics = array($topics);
2652
+	if (!is_array($topics)) {
2653
+			$topics = array($topics);
2654
+	}
2526 2655
 
2527
-	if (empty($topics))
2528
-		return false;
2656
+	if (empty($topics)) {
2657
+			return false;
2658
+	}
2529 2659
 
2530 2660
 	$approve_type = $approve ? 0 : 1;
2531 2661
 
@@ -2541,8 +2671,9 @@  discard block
 block discarded – undo
2541 2671
 		)
2542 2672
 	);
2543 2673
 	$msgs = array();
2544
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2545
-		$msgs[] = $row['id_msg'];
2674
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2675
+			$msgs[] = $row['id_msg'];
2676
+	}
2546 2677
 	$smcFunc['db_free_result']($request);
2547 2678
 
2548 2679
 	return approvePosts($msgs, $approve);
@@ -2565,11 +2696,13 @@  discard block
 block discarded – undo
2565 2696
 	global $board_info, $board, $smcFunc;
2566 2697
 
2567 2698
 	// Please - let's be sane.
2568
-	if (empty($setboards))
2569
-		return false;
2699
+	if (empty($setboards)) {
2700
+			return false;
2701
+	}
2570 2702
 
2571
-	if (!is_array($setboards))
2572
-		$setboards = array($setboards);
2703
+	if (!is_array($setboards)) {
2704
+			$setboards = array($setboards);
2705
+	}
2573 2706
 
2574 2707
 	// If we don't know the id_msg we need to find it.
2575 2708
 	if (!$id_msg)
@@ -2587,15 +2720,16 @@  discard block
 block discarded – undo
2587 2720
 			)
2588 2721
 		);
2589 2722
 		$lastMsg = array();
2590
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2591
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2723
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2724
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2725
+		}
2592 2726
 		$smcFunc['db_free_result']($request);
2593
-	}
2594
-	else
2727
+	} else
2595 2728
 	{
2596 2729
 		// Just to note - there should only be one board passed if we are doing this.
2597
-		foreach ($setboards as $id_board)
2598
-			$lastMsg[$id_board] = $id_msg;
2730
+		foreach ($setboards as $id_board) {
2731
+					$lastMsg[$id_board] = $id_msg;
2732
+		}
2599 2733
 	}
2600 2734
 
2601 2735
 	$parent_boards = array();
@@ -2610,10 +2744,11 @@  discard block
 block discarded – undo
2610 2744
 			$lastModified[$id_board] = 0;
2611 2745
 		}
2612 2746
 
2613
-		if (!empty($board) && $id_board == $board)
2614
-			$parents = $board_info['parent_boards'];
2615
-		else
2616
-			$parents = getBoardParents($id_board);
2747
+		if (!empty($board) && $id_board == $board) {
2748
+					$parents = $board_info['parent_boards'];
2749
+		} else {
2750
+					$parents = getBoardParents($id_board);
2751
+		}
2617 2752
 
2618 2753
 		// Ignore any parents on the top child level.
2619 2754
 		// @todo Why?
@@ -2622,10 +2757,11 @@  discard block
 block discarded – undo
2622 2757
 			if ($parent['level'] != 0)
2623 2758
 			{
2624 2759
 				// If we're already doing this one as a board, is this a higher last modified?
2625
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2626
-					$lastModified[$id] = $lastModified[$id_board];
2627
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2628
-					$parent_boards[$id] = $lastModified[$id_board];
2760
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2761
+									$lastModified[$id] = $lastModified[$id_board];
2762
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2763
+									$parent_boards[$id] = $lastModified[$id_board];
2764
+				}
2629 2765
 			}
2630 2766
 		}
2631 2767
 	}
@@ -2638,23 +2774,24 @@  discard block
 block discarded – undo
2638 2774
 	// Finally, to save on queries make the changes...
2639 2775
 	foreach ($parent_boards as $id => $msg)
2640 2776
 	{
2641
-		if (!isset($parent_updates[$msg]))
2642
-			$parent_updates[$msg] = array($id);
2643
-		else
2644
-			$parent_updates[$msg][] = $id;
2777
+		if (!isset($parent_updates[$msg])) {
2778
+					$parent_updates[$msg] = array($id);
2779
+		} else {
2780
+					$parent_updates[$msg][] = $id;
2781
+		}
2645 2782
 	}
2646 2783
 
2647 2784
 	foreach ($lastMsg as $id => $msg)
2648 2785
 	{
2649
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2650
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2786
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2787
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2651 2788
 				'id' => $msg,
2652 2789
 				'updated' => $lastModified[$id],
2653 2790
 				'boards' => array($id)
2654 2791
 			);
2655
-
2656
-		else
2657
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2792
+		} else {
2793
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2794
+		}
2658 2795
 	}
2659 2796
 
2660 2797
 	// Now commit the changes!
@@ -2746,11 +2883,13 @@  discard block
 block discarded – undo
2746 2883
 	global $txt, $mbname, $scripturl, $settings;
2747 2884
 
2748 2885
 	// First things first, load up the email templates language file, if we need to.
2749
-	if ($loadLang)
2750
-		loadLanguage('EmailTemplates', $lang);
2886
+	if ($loadLang) {
2887
+			loadLanguage('EmailTemplates', $lang);
2888
+	}
2751 2889
 
2752
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2753
-		fatal_lang_error('email_no_template', 'template', array($template));
2890
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2891
+			fatal_lang_error('email_no_template', 'template', array($template));
2892
+	}
2754 2893
 
2755 2894
 	$ret = array(
2756 2895
 		'subject' => $txt[$template . '_subject'],
@@ -2800,17 +2939,18 @@  discard block
 block discarded – undo
2800 2939
 function user_info_callback($matches)
2801 2940
 {
2802 2941
 	global $user_info;
2803
-	if (empty($matches[1]))
2804
-		return '';
2942
+	if (empty($matches[1])) {
2943
+			return '';
2944
+	}
2805 2945
 
2806 2946
 	$use_ref = true;
2807 2947
 	$ref = &$user_info;
2808 2948
 
2809 2949
 	foreach (explode('.', $matches[1]) as $index)
2810 2950
 	{
2811
-		if ($use_ref && isset($ref[$index]))
2812
-			$ref = &$ref[$index];
2813
-		else
2951
+		if ($use_ref && isset($ref[$index])) {
2952
+					$ref = &$ref[$index];
2953
+		} else
2814 2954
 		{
2815 2955
 			$use_ref = false;
2816 2956
 			break;
@@ -2847,8 +2987,7 @@  discard block
 block discarded – undo
2847 2987
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2848 2988
 		{
2849 2989
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2850
-		}
2851
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2990
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2852 2991
 		{
2853 2992
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2854 2993
 		}
@@ -2858,8 +2997,7 @@  discard block
 block discarded – undo
2858 2997
 		{
2859 2998
 			$context['provider'] = 'enchant';
2860 2999
 			return $enchant_link;
2861
-		}
2862
-		else
3000
+		} else
2863 3001
 		{
2864 3002
 			// Free up any resources used...
2865 3003
 			@enchant_broker_free($context['enchant_broker']);
@@ -2880,8 +3018,9 @@  discard block
 block discarded – undo
2880 3018
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2881 3019
 
2882 3020
 		// Most people don't have anything but English installed... So we use English as a last resort.
2883
-		if (!$pspell_link)
2884
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3021
+		if (!$pspell_link) {
3022
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3023
+		}
2885 3024
 
2886 3025
 		error_reporting($old);
2887 3026
 		ob_end_clean();
@@ -2921,8 +3060,7 @@  discard block
 block discarded – undo
2921 3060
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2922 3061
 		}
2923 3062
 		return enchant_dict_check($dict, $word);
2924
-	}
2925
-	elseif ($context['provider'] == 'pspell')
3063
+	} elseif ($context['provider'] == 'pspell')
2926 3064
 	{
2927 3065
 		return pspell_check($dict, $word);
2928 3066
 	}
@@ -2958,13 +3096,11 @@  discard block
 block discarded – undo
2958 3096
 			}
2959 3097
 
2960 3098
 			return $suggestions;
2961
-		}
2962
-		else
3099
+		} else
2963 3100
 		{
2964 3101
 			return enchant_dict_suggest($dict, $word);
2965 3102
 		}
2966
-	}
2967
-	elseif ($context['provider'] == 'pspell')
3103
+	} elseif ($context['provider'] == 'pspell')
2968 3104
 	{
2969 3105
 		return pspell_suggest($dict, $word);
2970 3106
 	}
Please login to merge, or discard this patch.
Sources/Likes.php 1 patch
Braces   +103 added lines, -75 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Class Likes
@@ -106,8 +107,9 @@  discard block
 block discarded – undo
106 107
 		$this->_extra = isset($_GET['extra']) ? $_GET['extra'] : false;
107 108
 
108 109
 		// We do not want to output debug information here.
109
-		if ($this->_js)
110
-			$db_show_debug = false;
110
+		if ($this->_js) {
111
+					$db_show_debug = false;
112
+		}
111 113
 	}
112 114
 
113 115
 	/**
@@ -141,8 +143,9 @@  discard block
 block discarded – undo
141 143
 			$call = $this->_sa;
142 144
 
143 145
 			// Guest can only view likes.
144
-			if ($call != 'view')
145
-				is_not_guest();
146
+			if ($call != 'view') {
147
+							is_not_guest();
148
+			}
146 149
 
147 150
 			checkSession('get');
148 151
 
@@ -180,15 +183,17 @@  discard block
 block discarded – undo
180 183
 		global $smcFunc, $modSettings;
181 184
 
182 185
 		// This feature is currently disable.
183
-		if (empty($modSettings['enable_likes']))
184
-			return $this->_error = 'like_disable';
186
+		if (empty($modSettings['enable_likes'])) {
187
+					return $this->_error = 'like_disable';
188
+		}
185 189
 
186 190
 		// Zerothly, they did indicate some kind of content to like, right?
187 191
 		preg_match('~^([a-z0-9\-\_]{1,6})~i', $this->_type, $matches);
188 192
 		$this->_type = isset($matches[1]) ? $matches[1] : '';
189 193
 
190
-		if ($this->_type == '' || $this->_content <= 0)
191
-			return $this->_error = 'cannot_';
194
+		if ($this->_type == '' || $this->_content <= 0) {
195
+					return $this->_error = 'cannot_';
196
+		}
192 197
 
193 198
 		// First we need to verify if the user can see the type of content or not. This is set up to be extensible,
194 199
 		// so we'll check for the one type we do know about, and if it's not that, we'll defer to any hooks.
@@ -207,12 +212,14 @@  discard block
 block discarded – undo
207 212
 					'msg' => $this->_content,
208 213
 				)
209 214
 			);
210
-			if ($smcFunc['db_num_rows']($request) == 1)
211
-				list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request);
215
+			if ($smcFunc['db_num_rows']($request) == 1) {
216
+							list ($this->_idTopic, $topicOwner) = $smcFunc['db_fetch_row']($request);
217
+			}
212 218
 
213 219
 			$smcFunc['db_free_result']($request);
214
-			if (empty($this->_idTopic))
215
-				return $this->_error = 'cannot_';
220
+			if (empty($this->_idTopic)) {
221
+							return $this->_error = 'cannot_';
222
+			}
216 223
 
217 224
 			// So we know what topic it's in and more importantly we know the user can see it.
218 225
 			// If we're not viewing, we need some info set up.
@@ -221,9 +228,7 @@  discard block
 block discarded – undo
221 228
 			$this->_validLikes['redirect'] = 'topic=' . $this->_idTopic . '.msg' . $this->_content . '#msg' . $this->_content;
222 229
 
223 230
 			$this->_validLikes['can_like'] = ($this->_user['id'] == $topicOwner ? 'cannot_like_content' : (allowedTo('likes_like') ? true : 'cannot_like_content'));
224
-		}
225
-
226
-		else
231
+		} else
227 232
 		{
228 233
 			// Modders: This will give you whatever the user offers up in terms of liking, e.g. $this->_type=msg, $this->_content=1
229 234
 			// When you hook this, check $this->_type first. If it is not something your mod worries about, return false.
@@ -241,8 +246,9 @@  discard block
 block discarded – undo
241 246
 					if ($result !== false)
242 247
 					{
243 248
 						// Match the type with what we already have.
244
-						if (!isset($result['type']) || $result['type'] != $this->_type)
245
-							return $this->_error = 'not_valid_like_type';
249
+						if (!isset($result['type']) || $result['type'] != $this->_type) {
250
+													return $this->_error = 'not_valid_like_type';
251
+						}
246 252
 
247 253
 						// Fill out the rest.
248 254
 						$this->_type = $result['type'];
@@ -253,13 +259,15 @@  discard block
 block discarded – undo
253 259
 				}
254 260
 			}
255 261
 
256
-			if (!$found)
257
-				return $this->_error = 'cannot_';
262
+			if (!$found) {
263
+							return $this->_error = 'cannot_';
264
+			}
258 265
 		}
259 266
 
260 267
 		// Does the user can like this? Viewing a list of likes doesn't require this permission.
261
-			if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like']))
262
-				return $this->_error = $this->_validLikes['can_like'];
268
+			if ($this->_sa != 'view' && isset($this->_validLikes['can_like']) && is_string($this->_validLikes['can_like'])) {
269
+							return $this->_error = $this->_validLikes['can_like'];
270
+			}
263 271
 	}
264 272
 
265 273
 	/**
@@ -284,8 +292,9 @@  discard block
 block discarded – undo
284 292
 		);
285 293
 
286 294
 		// Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name.
287
-		if ($this->_sa == __FUNCTION__)
288
-			$this->_data = __FUNCTION__;
295
+		if ($this->_sa == __FUNCTION__) {
296
+					$this->_data = __FUNCTION__;
297
+		}
289 298
 	}
290 299
 
291 300
 	/**
@@ -315,8 +324,8 @@  discard block
 block discarded – undo
315 324
 
316 325
 		// Add a background task to process sending alerts.
317 326
 		// Mod author, you can add your own background task for your own custom like event using the "integrate_issue_like" hook or your callback, both are immediately called after this.
318
-		if ($this->_type == 'msg')
319
-			$smcFunc['db_insert']('insert',
327
+		if ($this->_type == 'msg') {
328
+					$smcFunc['db_insert']('insert',
320 329
 				'{db_prefix}background_tasks',
321 330
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
322 331
 				array('$sourcedir/tasks/Likes-Notify.php', 'Likes_Notify_Background', $smcFunc['json_encode'](array(
@@ -328,10 +337,12 @@  discard block
 block discarded – undo
328 337
 				)), 0),
329 338
 				array('id_task')
330 339
 			);
340
+		}
331 341
 
332 342
 		// Are we calling this directly? if so, set a proper data for the response. Do note that __METHOD__ returns both the class name and the function name.
333
-		if ($this->_sa == __FUNCTION__)
334
-			$this->_data = __FUNCTION__;
343
+		if ($this->_sa == __FUNCTION__) {
344
+					$this->_data = __FUNCTION__;
345
+		}
335 346
 	}
336 347
 
337 348
 	/**
@@ -357,8 +368,9 @@  discard block
 block discarded – undo
357 368
 		$smcFunc['db_free_result']($request);
358 369
 
359 370
 		// If you want to call this directly, fill out _data property too.
360
-		if ($this->_sa == __FUNCTION__)
361
-			$this->_data = $this->_numLikes;
371
+		if ($this->_sa == __FUNCTION__) {
372
+					$this->_data = $this->_numLikes;
373
+		}
362 374
 	}
363 375
 
364 376
 	/**
@@ -371,8 +383,9 @@  discard block
 block discarded – undo
371 383
 		global $smcFunc;
372 384
 
373 385
 		// Safety first!
374
-		if (empty($this->_type) || empty($this->_content))
375
-			return $this->_error = 'cannot_';
386
+		if (empty($this->_type) || empty($this->_content)) {
387
+					return $this->_error = 'cannot_';
388
+		}
376 389
 
377 390
 		// Do we already like this?
378 391
 		$request = $smcFunc['db_query']('', '
@@ -390,26 +403,28 @@  discard block
 block discarded – undo
390 403
 		$this->_alreadyLiked = (bool) $smcFunc['db_num_rows']($request) != 0;
391 404
 		$smcFunc['db_free_result']($request);
392 405
 
393
-		if ($this->_alreadyLiked)
394
-			$this->delete();
395
-
396
-		else
397
-			$this->insert();
406
+		if ($this->_alreadyLiked) {
407
+					$this->delete();
408
+		} else {
409
+					$this->insert();
410
+		}
398 411
 
399 412
 		// Now, how many people like this content now? We *could* just +1 / -1 the relevant container but that has proven to become unstable.
400 413
 		$this->_count();
401 414
 
402 415
 		// Update the likes count for messages.
403
-		if ($this->_type == 'msg')
404
-			$this->msgIssueLike();
416
+		if ($this->_type == 'msg') {
417
+					$this->msgIssueLike();
418
+		}
405 419
 
406 420
 		// Any callbacks?
407 421
 		elseif (!empty($this->_validLikes['callback']))
408 422
 		{
409 423
 			$call = call_helper($this->_validLikes['callback'], true);
410 424
 
411
-			if (!empty($call))
412
-				call_user_func_array($call, array($this));
425
+			if (!empty($call)) {
426
+							call_user_func_array($call, array($this));
427
+			}
413 428
 		}
414 429
 
415 430
 		// Sometimes there might be other things that need updating after we do this like.
@@ -418,8 +433,9 @@  discard block
 block discarded – undo
418 433
 		// Now some clean up. This is provided here for any like handlers that want to do any cache flushing.
419 434
 		// This way a like handler doesn't need to explicitly declare anything in integrate_issue_like, but do so
420 435
 		// in integrate_valid_likes where it absolutely has to exist.
421
-		if (!empty($this->_validLikes['flush_cache']))
422
-			cache_put_data($this->_validLikes['flush_cache'], null);
436
+		if (!empty($this->_validLikes['flush_cache'])) {
437
+					cache_put_data($this->_validLikes['flush_cache'], null);
438
+		}
423 439
 
424 440
 		// All done, start building the data to pass as response.
425 441
 		$this->_data = array(
@@ -442,8 +458,9 @@  discard block
 block discarded – undo
442 458
 	{
443 459
 		global $smcFunc;
444 460
 
445
-		if ($this->_type !== 'msg')
446
-			return;
461
+		if ($this->_type !== 'msg') {
462
+					return;
463
+		}
447 464
 
448 465
 		$smcFunc['db_query']('', '
449 466
 			UPDATE {db_prefix}messages
@@ -484,8 +501,9 @@  discard block
 block discarded – undo
484 501
 				'like_type' => $this->_type,
485 502
 			)
486 503
 		);
487
-		while ($row = $smcFunc['db_fetch_assoc']($request))
488
-			$context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']);
504
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
505
+					$context['likers'][$row['id_member']] = array('timestamp' => $row['like_time']);
506
+		}
489 507
 
490 508
 		// Now to get member data, including avatars and so on.
491 509
 		$members = array_keys($context['likers']);
@@ -493,8 +511,9 @@  discard block
 block discarded – undo
493 511
 		if (count($loaded) != count($members))
494 512
 		{
495 513
 			$members = array_diff($members, $loaded);
496
-			foreach ($members as $not_loaded)
497
-				unset ($context['likers'][$not_loaded]);
514
+			foreach ($members as $not_loaded) {
515
+							unset ($context['likers'][$not_loaded]);
516
+			}
498 517
 		}
499 518
 
500 519
 		foreach ($context['likers'] as $liker => $dummy)
@@ -536,12 +555,14 @@  discard block
 block discarded – undo
536 555
 		global $context, $txt;
537 556
 
538 557
 		// Don't do anything if someone else has already take care of the response.
539
-		if (!$this->_setResponse)
540
-			return;
558
+		if (!$this->_setResponse) {
559
+					return;
560
+		}
541 561
 
542 562
 		// Want a json response huh?
543
-		if ($this->_validLikes['json'])
544
-			return $this->jsonResponse();
563
+		if ($this->_validLikes['json']) {
564
+					return $this->jsonResponse();
565
+		}
545 566
 
546 567
 		// Set everything up for display.
547 568
 		loadTemplate('Likes');
@@ -551,8 +572,9 @@  discard block
 block discarded – undo
551 572
 		if ($this->_error)
552 573
 		{
553 574
 			// If this is a generic error, set it up good.
554
-			if ($this->_error == 'cannot_')
555
-				$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
575
+			if ($this->_error == 'cannot_') {
576
+							$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
577
+			}
556 578
 
557 579
 			// Is this request coming from an ajax call?
558 580
 			if ($this->_js)
@@ -562,8 +584,9 @@  discard block
 block discarded – undo
562 584
 			}
563 585
 
564 586
 			// Nope?  then just do a redirect to whatever URL was provided.
565
-			else
566
-				redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : '');
587
+			else {
588
+							redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] . ';error=' . $this->_error : '');
589
+			}
567 590
 
568 591
 			return;
569 592
 		}
@@ -572,8 +595,9 @@  discard block
 block discarded – undo
572 595
 		else
573 596
 		{
574 597
 			// Not an ajax request so send the user back to the previous location or the main page.
575
-			if (!$this->_js)
576
-				redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : '');
598
+			if (!$this->_js) {
599
+							redirectexit(!empty($this->_validLikes['redirect']) ? $this->_validLikes['redirect'] : '');
600
+			}
577 601
 
578 602
 			// These fine gentlemen all share the same template.
579 603
 			$generic = array('delete', 'insert', '_count');
@@ -606,8 +630,9 @@  discard block
 block discarded – undo
606 630
 		// If there is an error, send it.
607 631
 		if ($this->_error)
608 632
 		{
609
-			if ($this->_error == 'cannot_')
610
-				$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
633
+			if ($this->_error == 'cannot_') {
634
+							$this->_error = $this->_sa == 'view' ? 'cannot_view_likes' : 'cannot_like_content';
635
+			}
611 636
 
612 637
 			$print['error'] = $this->_error;
613 638
 		}
@@ -643,33 +668,36 @@  discard block
 block discarded – undo
643 668
 	<body style="background-color: #444455; color: white; font-style: italic; font-family: serif;">
644 669
 		<div style="margin-top: 12%; font-size: 1.1em; line-height: 1.4; text-align: center;">';
645 670
 
646
-	if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2'))
647
-		$_GET['verse'] = '4:16';
671
+	if (!isset($_GET['verse']) || ($_GET['verse'] != '2:18' && $_GET['verse'] != '22:1-2')) {
672
+			$_GET['verse'] = '4:16';
673
+	}
648 674
 
649
-	if ($_GET['verse'] == '2:18')
650
-		echo '
675
+	if ($_GET['verse'] == '2:18') {
676
+			echo '
651 677
 			Woe, it was that his name wasn\'t <em>known</em>, that he came in mystery, and was recognized by none.&nbsp;And it became to be in those days <em>something</em>.&nbsp; Something not yet <em id="unknown" name="[Unknown]">unknown</em> to mankind.&nbsp; And thus what was to be known the <em>secret project</em> began into its existence.&nbsp; Henceforth the opposition was only <em>weary</em> and <em>fearful</em>, for now their match was at arms against them.';
652
-	elseif ($_GET['verse'] == '4:16')
653
-		echo '
678
+	} elseif ($_GET['verse'] == '4:16') {
679
+			echo '
654 680
 			And it came to pass that the <em>unbelievers</em> dwindled in number and saw rise of many <em>proselytizers</em>, and the opposition found fear in the face of the <em>x</em> and the <em>j</em> while those who stood with the <em>something</em> grew stronger and came together.&nbsp; Still, this was only the <em>beginning</em>, and what lay in the future was <em id="unknown" name="[Unknown]">unknown</em> to all, even those on the right side.';
655
-	elseif ($_GET['verse'] == '22:1-2')
656
-		echo '
681
+	} elseif ($_GET['verse'] == '22:1-2') {
682
+			echo '
657 683
 			<p>Now <em>behold</em>, that which was once the secret project was <em id="unknown" name="[Unknown]">unknown</em> no longer.&nbsp; Alas, it needed more than <em>only one</em>, but yet even thought otherwise.&nbsp; It became that the opposition <em>rumored</em> and lied, but still to no avail.&nbsp; Their match, though not <em>perfect</em>, had them outdone.</p>
658 684
 			<p style="margin: 2ex 1ex 0 1ex; font-size: 1.05em; line-height: 1.5; text-align: center;">Let it continue.&nbsp; <em>The end</em>.</p>';
685
+	}
659 686
 
660 687
 	echo '
661 688
 		</div>
662 689
 		<div style="margin-top: 2ex; font-size: 2em; text-align: right;">';
663 690
 
664
-	if ($_GET['verse'] == '2:18')
665
-		echo '
691
+	if ($_GET['verse'] == '2:18') {
692
+			echo '
666 693
 			from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=4:16" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 2:18</span>';
667
-	elseif ($_GET['verse'] == '4:16')
668
-		echo '
694
+	} elseif ($_GET['verse'] == '4:16') {
695
+			echo '
669 696
 			from <span style="font-family: Georgia, serif;"><strong><a href="', $scripturl, '?action=about:unknown;verse=22:1-2" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 4:16</span>';
670
-	elseif ($_GET['verse'] == '22:1-2')
671
-		echo '
697
+	} elseif ($_GET['verse'] == '22:1-2') {
698
+			echo '
672 699
 			from <span style="font-family: Georgia, serif;"><strong>The Book of Unknown</strong>, 22:1-2</span>';
700
+	}
673 701
 
674 702
 	echo '
675 703
 		</div>
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +224 added lines, -163 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get all birthdays within the given time range.
@@ -60,8 +61,7 @@  discard block
 block discarded – undo
60 61
 				'max_year' => $year_high,
61 62
 			)
62 63
 		);
63
-	}
64
-	else
64
+	} else
65 65
 	{
66 66
 		$result = $smcFunc['db_query']('birthday_array', '
67 67
 			SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate
@@ -91,10 +91,11 @@  discard block
 block discarded – undo
91 91
 	$bday = array();
92 92
 	while ($row = $smcFunc['db_fetch_assoc']($result))
93 93
 	{
94
-		if ($year_low != $year_high)
95
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
-		else
97
-			$age_year = $year_low;
94
+		if ($year_low != $year_high) {
95
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
+		} else {
97
+					$age_year = $year_low;
98
+		}
98 99
 
99 100
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
100 101
 			'id' => $row['id_member'],
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 	ksort($bday);
109 110
 
110 111
 	// Set is_last, so the themes know when to stop placing separators.
111
-	foreach ($bday as $mday => $array)
112
-		$bday[$mday][count($array) - 1]['is_last'] = true;
112
+	foreach ($bday as $mday => $array) {
113
+			$bday[$mday][count($array) - 1]['is_last'] = true;
114
+	}
113 115
 
114 116
 	return $bday;
115 117
 }
@@ -133,8 +135,9 @@  discard block
 block discarded – undo
133 135
 	static $timezone_array = array();
134 136
 	require_once($sourcedir . '/Subs.php');
135 137
 
136
-	if (empty($timezone_array['default']))
137
-		$timezone_array['default'] = timezone_open(date_default_timezone_get());
138
+	if (empty($timezone_array['default'])) {
139
+			$timezone_array['default'] = timezone_open(date_default_timezone_get());
140
+	}
138 141
 
139 142
 	$low_object = date_create($low_date);
140 143
 	$high_object = date_create($high_date);
@@ -161,8 +164,9 @@  discard block
 block discarded – undo
161 164
 	while ($row = $smcFunc['db_fetch_assoc']($result))
162 165
 	{
163 166
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
164
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
165
-			continue;
167
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
168
+					continue;
169
+		}
166 170
 
167 171
 		// Force a censor of the title - as often these are used by others.
168 172
 		censorText($row['title'], $use_permissions ? false : true);
@@ -170,12 +174,14 @@  discard block
 block discarded – undo
170 174
 		// Get the various time and date properties for this event
171 175
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
172 176
 
173
-		if (empty($timezone_array[$tz]))
174
-			$timezone_array[$tz] = timezone_open($tz);
177
+		if (empty($timezone_array[$tz])) {
178
+					$timezone_array[$tz] = timezone_open($tz);
179
+		}
175 180
 
176 181
 		// Sanity check
177
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
178
-			continue;
182
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
183
+					continue;
184
+		}
179 185
 
180 186
 		// Get set up for the loop
181 187
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), $timezone_array[$tz]);
@@ -239,8 +245,8 @@  discard block
 block discarded – undo
239 245
 			);
240 246
 
241 247
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
242
-			if ($use_permissions)
243
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
248
+			if ($use_permissions) {
249
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
244 250
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
245 251
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
246 252
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -248,9 +254,10 @@  discard block
 block discarded – undo
248 254
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
249 255
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
250 256
 				));
257
+			}
251 258
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
252
-			else
253
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
259
+			else {
260
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
254 261
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
255 262
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
256 263
 					'can_edit' => false,
@@ -260,6 +267,7 @@  discard block
 block discarded – undo
260 267
 					'poster' => $row['id_member'],
261 268
 					'allowed_groups' => explode(',', $row['member_groups']),
262 269
 				));
270
+			}
263 271
 
264 272
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
265 273
 		}
@@ -269,8 +277,9 @@  discard block
 block discarded – undo
269 277
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
270 278
 	if ($use_permissions)
271 279
 	{
272
-		foreach ($events as $mday => $array)
273
-			$events[$mday][count($array) - 1]['is_last'] = true;
280
+		foreach ($events as $mday => $array) {
281
+					$events[$mday][count($array) - 1]['is_last'] = true;
282
+		}
274 283
 	}
275 284
 
276 285
 	ksort($events);
@@ -290,11 +299,12 @@  discard block
 block discarded – undo
290 299
 	global $smcFunc;
291 300
 
292 301
 	// Get the lowest and highest dates for "all years".
293
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
294
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
302
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
303
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
295 304
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
296
-	else
297
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
305
+	} else {
306
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
307
+	}
298 308
 
299 309
 	// Find some holidays... ;).
300 310
 	$result = $smcFunc['db_query']('', '
@@ -314,10 +324,11 @@  discard block
 block discarded – undo
314 324
 	$holidays = array();
315 325
 	while ($row = $smcFunc['db_fetch_assoc']($result))
316 326
 	{
317
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
318
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
319
-		else
320
-			$event_year = substr($low_date, 0, 4);
327
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
328
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
329
+		} else {
330
+					$event_year = substr($low_date, 0, 4);
331
+		}
321 332
 
322 333
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
323 334
 	}
@@ -343,10 +354,12 @@  discard block
 block discarded – undo
343 354
 	isAllowedTo('calendar_post');
344 355
 
345 356
 	// No board?  No topic?!?
346
-	if (empty($board))
347
-		fatal_lang_error('missing_board_id', false);
348
-	if (empty($topic))
349
-		fatal_lang_error('missing_topic_id', false);
357
+	if (empty($board)) {
358
+			fatal_lang_error('missing_board_id', false);
359
+	}
360
+	if (empty($topic)) {
361
+			fatal_lang_error('missing_topic_id', false);
362
+	}
350 363
 
351 364
 	// Administrator, Moderator, or owner.  Period.
352 365
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -364,12 +377,14 @@  discard block
 block discarded – undo
364 377
 		if ($row = $smcFunc['db_fetch_assoc']($result))
365 378
 		{
366 379
 			// Not the owner of the topic.
367
-			if ($row['id_member_started'] != $user_info['id'])
368
-				fatal_lang_error('not_your_topic', 'user');
380
+			if ($row['id_member_started'] != $user_info['id']) {
381
+							fatal_lang_error('not_your_topic', 'user');
382
+			}
369 383
 		}
370 384
 		// Topic/Board doesn't exist.....
371
-		else
372
-			fatal_lang_error('calendar_no_topic', 'general');
385
+		else {
386
+					fatal_lang_error('calendar_no_topic', 'general');
387
+		}
373 388
 		$smcFunc['db_free_result']($result);
374 389
 	}
375 390
 }
@@ -457,14 +472,16 @@  discard block
 block discarded – undo
457 472
 	if (!empty($calendarOptions['start_day']))
458 473
 	{
459 474
 		$nShift -= $calendarOptions['start_day'];
460
-		if ($nShift < 0)
461
-			$nShift = 7 + $nShift;
475
+		if ($nShift < 0) {
476
+					$nShift = 7 + $nShift;
477
+		}
462 478
 	}
463 479
 
464 480
 	// Number of rows required to fit the month.
465 481
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
466
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
467
-		$nRows++;
482
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
483
+			$nRows++;
484
+	}
468 485
 
469 486
 	// Fetch the arrays for birthdays, posted events, and holidays.
470 487
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -477,8 +494,9 @@  discard block
 block discarded – undo
477 494
 	{
478 495
 		$calendarGrid['week_days'][] = $count;
479 496
 		$count++;
480
-		if ($count == 7)
481
-			$count = 0;
497
+		if ($count == 7) {
498
+					$count = 0;
499
+		}
482 500
 	}
483 501
 
484 502
 	// Iterate through each week.
@@ -495,8 +513,9 @@  discard block
 block discarded – undo
495 513
 		{
496 514
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
497 515
 
498
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
499
-				$nDay = 0;
516
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
517
+							$nDay = 0;
518
+			}
500 519
 
501 520
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
502 521
 
@@ -514,8 +533,9 @@  discard block
 block discarded – undo
514 533
 	}
515 534
 
516 535
 	// What is the last day of the month?
517
-	if ($is_previous === true)
518
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
536
+	if ($is_previous === true) {
537
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
538
+	}
519 539
 
520 540
 	// We'll use the shift in the template.
521 541
 	$calendarGrid['shift'] = $nShift;
@@ -549,8 +569,9 @@  discard block
 block discarded – undo
549 569
 	{
550 570
 		// Here we offset accordingly to get things to the real start of a week.
551 571
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
552
-		if ($date_diff < 0)
553
-			$date_diff += 7;
572
+		if ($date_diff < 0) {
573
+					$date_diff += 7;
574
+		}
554 575
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
555 576
 		$day = (int) strftime('%d', $new_timestamp);
556 577
 		$month = (int) strftime('%m', $new_timestamp);
@@ -680,18 +701,20 @@  discard block
 block discarded – undo
680 701
 	{
681 702
 		foreach ($date_events as $event_key => $event_val)
682 703
 		{
683
-			if (in_array($event_val['id'], $temp))
684
-				unset($calendarGrid['events'][$date][$event_key]);
685
-			else
686
-				$temp[] = $event_val['id'];
704
+			if (in_array($event_val['id'], $temp)) {
705
+							unset($calendarGrid['events'][$date][$event_key]);
706
+			} else {
707
+							$temp[] = $event_val['id'];
708
+			}
687 709
 		}
688 710
 	}
689 711
 
690 712
 	// Give birthdays and holidays a friendly format, without the year
691
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
692
-		$date_format = '%b %d';
693
-	else
694
-		$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
713
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
714
+			$date_format = '%b %d';
715
+	} else {
716
+			$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
717
+	}
695 718
 
696 719
 	foreach (array('birthdays', 'holidays') as $type)
697 720
 	{
@@ -790,8 +813,9 @@  discard block
 block discarded – undo
790 813
 		// Holidays between now and now + days.
791 814
 		for ($i = $now; $i < $now + $days_for_index; $i += 86400)
792 815
 		{
793
-			if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
794
-				$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
816
+			if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
817
+							$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
818
+			}
795 819
 		}
796 820
 	}
797 821
 
@@ -803,8 +827,9 @@  discard block
 block discarded – undo
803 827
 			$loop_date = strftime('%Y-%m-%d', $i);
804 828
 			if (isset($cached_data['birthdays'][$loop_date]))
805 829
 			{
806
-				foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
807
-					$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
830
+				foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
831
+									$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
832
+				}
808 833
 				$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
809 834
 			}
810 835
 		}
@@ -819,8 +844,9 @@  discard block
 block discarded – undo
819 844
 			$loop_date = strftime('%Y-%m-%d', $i);
820 845
 
821 846
 			// No events today? Check the next day.
822
-			if (empty($cached_data['events'][$loop_date]))
823
-				continue;
847
+			if (empty($cached_data['events'][$loop_date])) {
848
+							continue;
849
+			}
824 850
 
825 851
 			// Loop through all events to add a few last-minute values.
826 852
 			foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -833,9 +859,9 @@  discard block
 block discarded – undo
833 859
 				{
834 860
 					unset($cached_data['events'][$loop_date][$ev]);
835 861
 					continue;
862
+				} else {
863
+									$duplicates[$this_event['topic'] . $this_event['title']] = true;
836 864
 				}
837
-				else
838
-					$duplicates[$this_event['topic'] . $this_event['title']] = true;
839 865
 
840 866
 				// Might be set to true afterwards, depending on the permissions.
841 867
 				$this_event['can_edit'] = false;
@@ -843,16 +869,19 @@  discard block
 block discarded – undo
843 869
 				$this_event['date'] = $loop_date;
844 870
 			}
845 871
 
846
-			if (!empty($cached_data['events'][$loop_date]))
847
-				$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
872
+			if (!empty($cached_data['events'][$loop_date])) {
873
+							$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
874
+			}
848 875
 		}
849 876
 	}
850 877
 
851 878
 	// Mark the last item so that a list separator can be used in the template.
852
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
853
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
854
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
855
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
879
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
880
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
881
+	}
882
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
883
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
884
+	}
856 885
 
857 886
 	return array(
858 887
 		'data' => $return_data,
@@ -900,37 +929,46 @@  discard block
 block discarded – undo
900 929
 		if (isset($_POST['start_date']))
901 930
 		{
902 931
 			$d = date_parse($_POST['start_date']);
903
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
904
-				fatal_lang_error('invalid_date', false);
905
-			if (empty($d['year']))
906
-				fatal_lang_error('event_year_missing', false);
907
-			if (empty($d['month']))
908
-				fatal_lang_error('event_month_missing', false);
909
-		}
910
-		elseif (isset($_POST['start_datetime']))
932
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
933
+							fatal_lang_error('invalid_date', false);
934
+			}
935
+			if (empty($d['year'])) {
936
+							fatal_lang_error('event_year_missing', false);
937
+			}
938
+			if (empty($d['month'])) {
939
+							fatal_lang_error('event_month_missing', false);
940
+			}
941
+		} elseif (isset($_POST['start_datetime']))
911 942
 		{
912 943
 			$d = date_parse($_POST['start_datetime']);
913
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
914
-				fatal_lang_error('invalid_date', false);
915
-			if (empty($d['year']))
916
-				fatal_lang_error('event_year_missing', false);
917
-			if (empty($d['month']))
918
-				fatal_lang_error('event_month_missing', false);
944
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
945
+							fatal_lang_error('invalid_date', false);
946
+			}
947
+			if (empty($d['year'])) {
948
+							fatal_lang_error('event_year_missing', false);
949
+			}
950
+			if (empty($d['month'])) {
951
+							fatal_lang_error('event_month_missing', false);
952
+			}
919 953
 		}
920 954
 		// The 2.0 way
921 955
 		else
922 956
 		{
923 957
 			// No month?  No year?
924
-			if (!isset($_POST['month']))
925
-				fatal_lang_error('event_month_missing', false);
926
-			if (!isset($_POST['year']))
927
-				fatal_lang_error('event_year_missing', false);
958
+			if (!isset($_POST['month'])) {
959
+							fatal_lang_error('event_month_missing', false);
960
+			}
961
+			if (!isset($_POST['year'])) {
962
+							fatal_lang_error('event_year_missing', false);
963
+			}
928 964
 
929 965
 			// Check the month and year...
930
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
931
-				fatal_lang_error('invalid_month', false);
932
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
933
-				fatal_lang_error('invalid_year', false);
966
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
967
+							fatal_lang_error('invalid_month', false);
968
+			}
969
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
970
+							fatal_lang_error('invalid_year', false);
971
+			}
934 972
 		}
935 973
 	}
936 974
 
@@ -940,8 +978,9 @@  discard block
 block discarded – undo
940 978
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
941 979
 	if (isset($_POST['span']))
942 980
 	{
943
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
944
-			fatal_lang_error('invalid_days_numb', false);
981
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
982
+					fatal_lang_error('invalid_days_numb', false);
983
+		}
945 984
 	}
946 985
 
947 986
 	// There is no need to validate the following values if we are just deleting the event.
@@ -951,24 +990,29 @@  discard block
 block discarded – undo
951 990
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
952 991
 		{
953 992
 			// No day?
954
-			if (!isset($_POST['day']))
955
-				fatal_lang_error('event_day_missing', false);
993
+			if (!isset($_POST['day'])) {
994
+							fatal_lang_error('event_day_missing', false);
995
+			}
956 996
 
957 997
 			// Bad day?
958
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
959
-				fatal_lang_error('invalid_date', false);
998
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
999
+							fatal_lang_error('invalid_date', false);
1000
+			}
960 1001
 		}
961 1002
 
962
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
963
-			fatal_lang_error('event_title_missing', false);
964
-		elseif (!isset($_POST['evtitle']))
965
-			$_POST['evtitle'] = $_POST['subject'];
1003
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
1004
+					fatal_lang_error('event_title_missing', false);
1005
+		} elseif (!isset($_POST['evtitle'])) {
1006
+					$_POST['evtitle'] = $_POST['subject'];
1007
+		}
966 1008
 
967 1009
 		// No title?
968
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
969
-			fatal_lang_error('no_event_title', false);
970
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
971
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
1010
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
1011
+					fatal_lang_error('no_event_title', false);
1012
+		}
1013
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
1014
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
1015
+		}
972 1016
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
973 1017
 	}
974 1018
 }
@@ -995,8 +1039,9 @@  discard block
 block discarded – undo
995 1039
 	);
996 1040
 
997 1041
 	// No results, return false.
998
-	if ($smcFunc['db_num_rows'] === 0)
999
-		return false;
1042
+	if ($smcFunc['db_num_rows'] === 0) {
1043
+			return false;
1044
+	}
1000 1045
 
1001 1046
 	// Grab the results and return.
1002 1047
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -1130,8 +1175,9 @@  discard block
 block discarded – undo
1130 1175
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
1131 1176
 
1132 1177
 	$column_clauses = array();
1133
-	foreach ($event_columns as $col => $crit)
1134
-		$column_clauses[] = $col . ' = ' . $crit;
1178
+	foreach ($event_columns as $col => $crit) {
1179
+			$column_clauses[] = $col . ' = ' . $crit;
1180
+	}
1135 1181
 
1136 1182
 	$smcFunc['db_query']('', '
1137 1183
 		UPDATE {db_prefix}calendar
@@ -1216,8 +1262,9 @@  discard block
 block discarded – undo
1216 1262
 	);
1217 1263
 
1218 1264
 	// If nothing returned, we are in poo, poo.
1219
-	if ($smcFunc['db_num_rows']($request) === 0)
1220
-		return false;
1265
+	if ($smcFunc['db_num_rows']($request) === 0) {
1266
+			return false;
1267
+	}
1221 1268
 
1222 1269
 	$row = $smcFunc['db_fetch_assoc']($request);
1223 1270
 	$smcFunc['db_free_result']($request);
@@ -1225,8 +1272,9 @@  discard block
 block discarded – undo
1225 1272
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1226 1273
 
1227 1274
 	// Sanity check
1228
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1229
-		return false;
1275
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1276
+			return false;
1277
+	}
1230 1278
 
1231 1279
 	$return_value = array(
1232 1280
 		'boards' => array(),
@@ -1363,24 +1411,27 @@  discard block
 block discarded – undo
1363 1411
 
1364 1412
 	// Set $span, in case we need it
1365 1413
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1366
-	if ($span > 0)
1367
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1414
+	if ($span > 0) {
1415
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1416
+	}
1368 1417
 
1369 1418
 	// Define the timezone for this event, falling back to the default if not provided
1370
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1371
-		$tz = $eventOptions['tz'];
1372
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1373
-		$tz = $_POST['tz'];
1374
-	else
1375
-		$tz = getUserTimezone();
1419
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1420
+			$tz = $eventOptions['tz'];
1421
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1422
+			$tz = $_POST['tz'];
1423
+	} else {
1424
+			$tz = getUserTimezone();
1425
+	}
1376 1426
 
1377 1427
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1378
-	if (isset($eventOptions['allday']))
1379
-		$allday = $eventOptions['allday'];
1380
-	elseif (empty($_POST['allday']))
1381
-		$allday = false;
1382
-	else
1383
-		$allday = true;
1428
+	if (isset($eventOptions['allday'])) {
1429
+			$allday = $eventOptions['allday'];
1430
+	} elseif (empty($_POST['allday'])) {
1431
+			$allday = false;
1432
+	} else {
1433
+			$allday = true;
1434
+	}
1384 1435
 
1385 1436
 	// Input might come as individual parameters...
1386 1437
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1407,10 +1458,12 @@  discard block
 block discarded – undo
1407 1458
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1408 1459
 
1409 1460
 	// If the date and time were given in separate strings, combine them
1410
-	if (empty($start_string) && isset($start_date_string))
1411
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1412
-	if (empty($end_string) && isset($end_date_string))
1413
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1461
+	if (empty($start_string) && isset($start_date_string)) {
1462
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1463
+	}
1464
+	if (empty($end_string) && isset($end_date_string)) {
1465
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1466
+	}
1414 1467
 
1415 1468
 	// If some form of string input was given, override individually defined options with it
1416 1469
 	if (isset($start_string))
@@ -1501,10 +1554,11 @@  discard block
 block discarded – undo
1501 1554
 	if ($start_object >= $end_object)
1502 1555
 	{
1503 1556
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1504
-		if ($span > 0)
1505
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1506
-		else
1507
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1557
+		if ($span > 0) {
1558
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1559
+		} else {
1560
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1561
+		}
1508 1562
 	}
1509 1563
 
1510 1564
 	// Is $end_object too late?
@@ -1517,9 +1571,9 @@  discard block
 block discarded – undo
1517 1571
 			{
1518 1572
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1519 1573
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1574
+			} else {
1575
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1520 1576
 			}
1521
-			else
1522
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1523 1577
 		}
1524 1578
 	}
1525 1579
 
@@ -1532,8 +1586,7 @@  discard block
 block discarded – undo
1532 1586
 		$start_time = null;
1533 1587
 		$end_time = null;
1534 1588
 		$tz = null;
1535
-	}
1536
-	else
1589
+	} else
1537 1590
 	{
1538 1591
 		$start_time = date_format($start_object, 'H:i:s');
1539 1592
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1559,19 +1612,21 @@  discard block
 block discarded – undo
1559 1612
 	// First, try to create a better date format, ignoring the "time" elements.
1560 1613
 	if (empty($date_format))
1561 1614
 	{
1562
-		if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1563
-			$date_format = '%F';
1564
-		else
1565
-			$date_format = $matches[0];
1615
+		if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1616
+					$date_format = '%F';
1617
+		} else {
1618
+					$date_format = $matches[0];
1619
+		}
1566 1620
 	}
1567 1621
 
1568 1622
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1569 1623
 	if (empty($time_format))
1570 1624
 	{
1571
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1572
-			$time_format = '%k:%M';
1573
-		else
1574
-			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1625
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1626
+					$time_format = '%k:%M';
1627
+		} else {
1628
+					$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1629
+		}
1575 1630
 	}
1576 1631
 
1577 1632
 	// Should this be an all day event?
@@ -1581,11 +1636,13 @@  discard block
 block discarded – undo
1581 1636
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1582 1637
 
1583 1638
 	// We need to have a defined timezone in the steps below
1584
-	if (empty($row['timezone']))
1585
-		$row['timezone'] = getUserTimezone();
1639
+	if (empty($row['timezone'])) {
1640
+			$row['timezone'] = getUserTimezone();
1641
+	}
1586 1642
 
1587
-	if (empty($timezone_array[$row['timezone']]))
1588
-		$timezone_array[$row['timezone']] = timezone_open($row['timezone']);
1643
+	if (empty($timezone_array[$row['timezone']])) {
1644
+			$timezone_array[$row['timezone']] = timezone_open($row['timezone']);
1645
+	}
1589 1646
 
1590 1647
 	// Get most of the standard date information for the start and end datetimes
1591 1648
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1633,8 +1690,9 @@  discard block
 block discarded – undo
1633 1690
 	global $smcFunc, $context, $user_info, $modSettings, $user_settings;
1634 1691
 	static $member_cache = array();
1635 1692
 
1636
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1637
-		$id_member = $context['user']['id'];
1693
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1694
+			$id_member = $context['user']['id'];
1695
+	}
1638 1696
 
1639 1697
 	//check if the cache got the data
1640 1698
 	if (isset($id_member) && isset($member_cache[$id_member]))
@@ -1663,11 +1721,13 @@  discard block
 block discarded – undo
1663 1721
 		$smcFunc['db_free_result']($request);
1664 1722
 	}
1665 1723
 
1666
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1667
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1724
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1725
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1726
+	}
1668 1727
 
1669
-	if (isset($id_member))
1670
-		$member_cache[$id_member] = $timezone;
1728
+	if (isset($id_member)) {
1729
+			$member_cache[$id_member] = $timezone;
1730
+	}
1671 1731
 
1672 1732
 	return $timezone;
1673 1733
 }
@@ -1696,8 +1756,9 @@  discard block
 block discarded – undo
1696 1756
 		)
1697 1757
 	);
1698 1758
 	$holidays = array();
1699
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1700
-		$holidays[] = $row;
1759
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1760
+			$holidays[] = $row;
1761
+	}
1701 1762
 	$smcFunc['db_free_result']($request);
1702 1763
 
1703 1764
 	return $holidays;
Please login to merge, or discard this patch.
Sources/Class-CacheAPI.php 1 patch
Braces   +20 added lines, -15 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * Interface cache_api_interface
@@ -182,8 +183,9 @@  discard block
 block discarded – undo
182 183
 	{
183 184
 		global $cache_enable;
184 185
 
185
-		if ($test)
186
-			return true;
186
+		if ($test) {
187
+					return true;
188
+		}
187 189
 		return !empty($cache_enable);
188 190
 	}
189 191
 
@@ -202,18 +204,20 @@  discard block
 block discarded – undo
202 204
 		global $boardurl, $cachedir;
203 205
 
204 206
 		// Find a valid good file to do mtime checks on.
205
-		if (file_exists($cachedir . '/' . 'index.php'))
206
-			$filemtime = $cachedir . '/' . 'index.php';
207
-		elseif (is_dir($cachedir . '/'))
208
-			$filemtime = $cachedir . '/';
209
-		else
210
-			$filemtime = $boardurl . '/index.php';
207
+		if (file_exists($cachedir . '/' . 'index.php')) {
208
+					$filemtime = $cachedir . '/' . 'index.php';
209
+		} elseif (is_dir($cachedir . '/')) {
210
+					$filemtime = $cachedir . '/';
211
+		} else {
212
+					$filemtime = $boardurl . '/index.php';
213
+		}
211 214
 
212 215
 		// Set the default if no prefix was specified.
213
-		if (empty($prefix))
214
-			$this->prefix = md5($boardurl . filemtime($filemtime)) . '-SMF-';
215
-		else
216
-			$this->prefix = $prefix;
216
+		if (empty($prefix)) {
217
+					$this->prefix = md5($boardurl . filemtime($filemtime)) . '-SMF-';
218
+		} else {
219
+					$this->prefix = $prefix;
220
+		}
217 221
 
218 222
 		return true;
219 223
 	}
@@ -276,8 +280,9 @@  discard block
 block discarded – undo
276 280
 
277 281
 		// Invalidate cache, to be sure!
278 282
 		// ... as long as index.php can be modified, anyway.
279
-		if (is_writable($cachedir . '/' . 'index.php'))
280
-			@touch($cachedir . '/' . 'index.php');
283
+		if (is_writable($cachedir . '/' . 'index.php')) {
284
+					@touch($cachedir . '/' . 'index.php');
285
+		}
281 286
 
282 287
 		return true;
283 288
 	}
Please login to merge, or discard this patch.
Sources/Modlog.php 1 patch
Braces   +99 added lines, -75 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Prepares the information from the moderation log for viewing.
@@ -32,14 +33,16 @@  discard block
 block discarded – undo
32 33
 
33 34
 	// Are we looking at the moderation log or the administration log.
34 35
 	$context['log_type'] = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 3 : 1;
35
-	if ($context['log_type'] == 3)
36
-		isAllowedTo('admin_forum');
36
+	if ($context['log_type'] == 3) {
37
+			isAllowedTo('admin_forum');
38
+	}
37 39
 
38 40
 	// These change dependant on whether we are viewing the moderation or admin log.
39
-	if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin')
40
-		$context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type'];
41
-	else
42
-		$context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type'];
41
+	if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin') {
42
+			$context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type'];
43
+	} else {
44
+			$context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type'];
45
+	}
43 46
 
44 47
 	$context['can_delete'] = allowedTo('admin_forum');
45 48
 
@@ -67,8 +70,7 @@  discard block
 block discarded – undo
67 70
 		$log_type = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 'admin' : 'moderate';
68 71
 		logAction('clearlog_' . $log_type, array(), $log_type);
69 72
 
70
-	}
71
-	elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete'])
73
+	} elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete'])
72 74
 	{
73 75
 		checkSession();
74 76
 		validateToken('mod-ml');
@@ -114,15 +116,17 @@  discard block
 block discarded – undo
114 116
 		'ip' => array('sql' => 'lm.ip', 'label' => $txt['modlog_ip'])
115 117
 	);
116 118
 
117
-	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search']))
118
-		$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
119
-	else
120
-		$search_params_string = $search_params['string'];
119
+	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) {
120
+			$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
121
+	} else {
122
+			$search_params_string = $search_params['string'];
123
+	}
121 124
 
122
-	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']]))
123
-		$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
124
-	else
125
-		$search_params_type = $search_params['type'];
125
+	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) {
126
+			$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
127
+	} else {
128
+			$search_params_type = $search_params['type'];
129
+	}
126 130
 
127 131
 	$search_params_column = $searchTypes[$search_params_type]['sql'];
128 132
 	$search_params = array(
@@ -301,15 +305,16 @@  discard block
 block discarded – undo
301 305
 	$context['default_list'] = 'moderation_log_list';
302 306
 
303 307
 	// If a hook has changed this, respect it.
304
-	if (!empty($moderation_menu_name))
305
-		$context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name;
306
-	elseif (isset($context['moderation_menu_name']))
307
-		$context[$context['moderation_menu_name']]['tab_data'] = array(
308
+	if (!empty($moderation_menu_name)) {
309
+			$context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name;
310
+	} elseif (isset($context['moderation_menu_name'])) {
311
+			$context[$context['moderation_menu_name']]['tab_data'] = array(
308 312
 			'title' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log'],
309 313
 			'help' => $context['log_type'] == 3 ? 'adminlog' : 'modlog',
310 314
 			'description' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log_desc']
311 315
 		);
312
-}
316
+	}
317
+	}
313 318
 
314 319
 /**
315 320
  * Get the number of mod log entries.
@@ -413,30 +418,35 @@  discard block
 block discarded – undo
413 418
 		// Add on some of the column stuff info
414 419
 		if (!empty($row['id_board']))
415 420
 		{
416
-			if ($row['action'] == 'move')
417
-				$row['extra']['board_to'] = $row['id_board'];
418
-			else
419
-				$row['extra']['board'] = $row['id_board'];
421
+			if ($row['action'] == 'move') {
422
+							$row['extra']['board_to'] = $row['id_board'];
423
+			} else {
424
+							$row['extra']['board'] = $row['id_board'];
425
+			}
420 426
 		}
421 427
 
422
-		if (!empty($row['id_topic']))
423
-			$row['extra']['topic'] = $row['id_topic'];
424
-		if (!empty($row['id_msg']))
425
-			$row['extra']['message'] = $row['id_msg'];
428
+		if (!empty($row['id_topic'])) {
429
+					$row['extra']['topic'] = $row['id_topic'];
430
+		}
431
+		if (!empty($row['id_msg'])) {
432
+					$row['extra']['message'] = $row['id_msg'];
433
+		}
426 434
 
427 435
 		// Is this associated with a topic?
428
-		if (isset($row['extra']['topic']))
429
-			$topics[(int) $row['extra']['topic']][] = $row['id_action'];
430
-		if (isset($row['extra']['new_topic']))
431
-			$topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
436
+		if (isset($row['extra']['topic'])) {
437
+					$topics[(int) $row['extra']['topic']][] = $row['id_action'];
438
+		}
439
+		if (isset($row['extra']['new_topic'])) {
440
+					$topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
441
+		}
432 442
 
433 443
 		// How about a member?
434 444
 		if (isset($row['extra']['member']))
435 445
 		{
436 446
 			// Guests don't have names!
437
-			if (empty($row['extra']['member']))
438
-				$row['extra']['member'] = $txt['modlog_parameter_guest'];
439
-			else
447
+			if (empty($row['extra']['member'])) {
448
+							$row['extra']['member'] = $txt['modlog_parameter_guest'];
449
+			} else
440 450
 			{
441 451
 				// Try to find it...
442 452
 				$members[(int) $row['extra']['member']][] = $row['id_action'];
@@ -444,35 +454,42 @@  discard block
 block discarded – undo
444 454
 		}
445 455
 
446 456
 		// Associated with a board?
447
-		if (isset($row['extra']['board_to']))
448
-			$boards[(int) $row['extra']['board_to']][] = $row['id_action'];
449
-		if (isset($row['extra']['board_from']))
450
-			$boards[(int) $row['extra']['board_from']][] = $row['id_action'];
451
-		if (isset($row['extra']['board']))
452
-			$boards[(int) $row['extra']['board']][] = $row['id_action'];
457
+		if (isset($row['extra']['board_to'])) {
458
+					$boards[(int) $row['extra']['board_to']][] = $row['id_action'];
459
+		}
460
+		if (isset($row['extra']['board_from'])) {
461
+					$boards[(int) $row['extra']['board_from']][] = $row['id_action'];
462
+		}
463
+		if (isset($row['extra']['board'])) {
464
+					$boards[(int) $row['extra']['board']][] = $row['id_action'];
465
+		}
453 466
 
454 467
 		// A message?
455
-		if (isset($row['extra']['message']))
456
-			$messages[(int) $row['extra']['message']][] = $row['id_action'];
468
+		if (isset($row['extra']['message'])) {
469
+					$messages[(int) $row['extra']['message']][] = $row['id_action'];
470
+		}
457 471
 
458 472
 		// IP Info?
459
-		if (isset($row['extra']['ip_range']))
460
-			if ($seeIP)
473
+		if (isset($row['extra']['ip_range'])) {
474
+					if ($seeIP)
461 475
 				$row['extra']['ip_range'] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['extra']['ip_range'] . '">' . $row['extra']['ip_range'] . '</a>';
462
-			else
463
-				$row['extra']['ip_range'] = $txt['logged'];
476
+		} else {
477
+							$row['extra']['ip_range'] = $txt['logged'];
478
+			}
464 479
 
465 480
 		// Email?
466
-		if (isset($row['extra']['email']))
467
-			$row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
481
+		if (isset($row['extra']['email'])) {
482
+					$row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
483
+		}
468 484
 
469 485
 		// Bans are complex.
470 486
 		if ($row['action'] == 'ban' || $row['action'] == 'banremove')
471 487
 		{
472 488
 			$row['action_text'] = $txt['modlog_ac_ban' . ($row['action'] == 'banremove' ? '_remove' : '')];
473
-			foreach (array('member', 'email', 'ip_range', 'hostname') as $type)
474
-				if (isset($row['extra'][$type]))
489
+			foreach (array('member', 'email', 'ip_range', 'hostname') as $type) {
490
+							if (isset($row['extra'][$type]))
475 491
 					$row['action_text'] .= $txt['modlog_ac_ban_trigger_' . $type];
492
+			}
476 493
 		}
477 494
 
478 495
 		// The array to go to the template. Note here that action is set to a "default" value of the action doesn't match anything in the descriptions. Allows easy adding of logging events with basic details.
@@ -508,12 +525,13 @@  discard block
 block discarded – undo
508 525
 			foreach ($boards[$row['id_board']] as $action)
509 526
 			{
510 527
 				// Make the board number into a link - dealing with moving too.
511
-				if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board'])
512
-					$entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
513
-				elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board'])
514
-					$entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
515
-				elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board'])
516
-					$entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
528
+				if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board']) {
529
+									$entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
530
+				} elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board']) {
531
+									$entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
532
+				} elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board']) {
533
+									$entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
534
+				}
517 535
 			}
518 536
 		}
519 537
 		$smcFunc['db_free_result']($request);
@@ -547,10 +565,11 @@  discard block
 block discarded – undo
547 565
 				);
548 566
 
549 567
 				// Make the topic number into a link - dealing with splitting too.
550
-				if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic'])
551
-					$this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
552
-				elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic'])
553
-					$this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
568
+				if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic']) {
569
+									$this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
570
+				} elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic']) {
571
+									$this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
572
+				}
554 573
 			}
555 574
 		}
556 575
 		$smcFunc['db_free_result']($request);
@@ -583,8 +602,9 @@  discard block
 block discarded – undo
583 602
 				);
584 603
 
585 604
 				// Make the message number into a link.
586
-				if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg'])
587
-					$this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
605
+				if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg']) {
606
+									$this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
607
+				}
588 608
 			}
589 609
 		}
590 610
 		$smcFunc['db_free_result']($request);
@@ -624,25 +644,29 @@  discard block
 block discarded – undo
624 644
 	foreach ($entries as $k => $entry)
625 645
 	{
626 646
 		// Make any message info links so its easier to go find that message.
627
-		if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id'])))
628
-			$entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
647
+		if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id']))) {
648
+					$entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
649
+		}
629 650
 
630 651
 		// Mark up any deleted members, topics and boards.
631
-		foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type)
632
-			if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type]))
652
+		foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type) {
653
+					if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type]))
633 654
 				$entries[$k]['extra'][$type] = sprintf($txt['modlog_id'], $entry['extra'][$type]);
655
+		}
634 656
 
635 657
 		if (isset($entry['extra']['report']))
636 658
 		{
637 659
 			// Member profile reports go in a different area
638
-			if (stristr($entry['action'], 'user_report'))
639
-				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
640
-			else
641
-				$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
660
+			if (stristr($entry['action'], 'user_report')) {
661
+							$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
662
+			} else {
663
+							$entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>';
664
+			}
642 665
 		}
643 666
 
644
-		if (empty($entries[$k]['action_text']))
645
-			$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
667
+		if (empty($entries[$k]['action_text'])) {
668
+					$entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
669
+		}
646 670
 		$entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i',
647 671
 			function ($matches) use ($entries, $k)
648 672
 			{
Please login to merge, or discard this patch.