Completed
Pull Request — release-2.1 (#4340)
by
unknown
07:23
created
Sources/CacheAPI-smf.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -180,7 +180,7 @@
 block discarded – undo
180 180
 	 *
181 181
 	 * @access public
182 182
 	 * @param string $dir A valid path
183
-	 * @return boolean If this was successful or not.
183
+	 * @return boolean|null If this was successful or not.
184 184
 	 */
185 185
 	public function setCachedir($dir = null)
186 186
 	{
Please login to merge, or discard this patch.
Braces   +36 added lines, -26 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
  * Our Cache API class
@@ -43,8 +44,9 @@  discard block
 block discarded – undo
43 44
 	{
44 45
 		$supported = is_writable($this->cachedir);
45 46
 
46
-		if ($test)
47
-			return $supported;
47
+		if ($test) {
48
+					return $supported;
49
+		}
48 50
 		return parent::isSupported() && $supported;
49 51
 	}
50 52
 
@@ -61,11 +63,13 @@  discard block
 block discarded – undo
61 63
 		{
62 64
 			// Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds
63 65
 			// causing newer files to take effect a while later.
64
-			if (function_exists('opcache_invalidate'))
65
-				opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
66
+			if (function_exists('opcache_invalidate')) {
67
+							opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
68
+			}
66 69
 
67
-			if (function_exists('apc_delete_file'))
68
-				@apc_delete_file($cachedir . '/data_' . $key . '.php');
70
+			if (function_exists('apc_delete_file')) {
71
+							@apc_delete_file($cachedir . '/data_' . $key . '.php');
72
+			}
69 73
 
70 74
 			// php will cache file_exists et all, we can't 100% depend on its results so proceed with caution
71 75
 			@include($cachedir . '/data_' . $key . '.php');
@@ -89,16 +93,18 @@  discard block
 block discarded – undo
89 93
 
90 94
 		// Work around Zend's opcode caching (PHP 5.5+), they would cache older files for a couple of seconds
91 95
 		// causing newer files to take effect a while later.
92
-		if (function_exists('opcache_invalidate'))
93
-			opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
96
+		if (function_exists('opcache_invalidate')) {
97
+					opcache_invalidate($cachedir . '/data_' . $key . '.php', true);
98
+		}
94 99
 
95
-		if (function_exists('apc_delete_file'))
96
-			@apc_delete_file($cachedir . '/data_' . $key . '.php');
100
+		if (function_exists('apc_delete_file')) {
101
+					@apc_delete_file($cachedir . '/data_' . $key . '.php');
102
+		}
97 103
 
98 104
 		// Otherwise custom cache?
99
-		if ($value === null)
100
-			@unlink($cachedir . '/data_' . $key . '.php');
101
-		else
105
+		if ($value === null) {
106
+					@unlink($cachedir . '/data_' . $key . '.php');
107
+		} else
102 108
 		{
103 109
 			$cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>';
104 110
 
@@ -109,9 +115,9 @@  discard block
 block discarded – undo
109 115
 			{
110 116
 				@unlink($cachedir . '/data_' . $key . '.php');
111 117
 				return false;
118
+			} else {
119
+							return true;
112 120
 			}
113
-			else
114
-				return true;
115 121
 		}
116 122
 	}
117 123
 
@@ -123,15 +129,17 @@  discard block
 block discarded – undo
123 129
 		$cachedir = $this->cachedir;
124 130
 
125 131
 		// No directory = no game.
126
-		if (!is_dir($cachedir))
127
-			return;
132
+		if (!is_dir($cachedir)) {
133
+					return;
134
+		}
128 135
 
129 136
 		// Remove the files in SMF's own disk cache, if any
130 137
 		$dh = opendir($cachedir);
131 138
 		while ($file = readdir($dh))
132 139
 		{
133
-			if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type))
134
-				@unlink($cachedir . '/' . $file);
140
+			if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type)) {
141
+							@unlink($cachedir . '/' . $file);
142
+			}
135 143
 		}
136 144
 		closedir($dh);
137 145
 
@@ -165,8 +173,9 @@  discard block
 block discarded – undo
165 173
 		$config_vars[] = $txt['cache_smf_settings'];
166 174
 		$config_vars[] = array('cachedir', $txt['cachedir'], 'file', 'text', 36, 'cache_cachedir');
167 175
 
168
-		if (!isset($context['settings_post_javascript']))
169
-			$context['settings_post_javascript'] = '';
176
+		if (!isset($context['settings_post_javascript'])) {
177
+					$context['settings_post_javascript'] = '';
178
+		}
170 179
 
171 180
 		$context['settings_post_javascript'] .= '
172 181
 			$("#cache_accelerator").change(function (e) {
@@ -187,10 +196,11 @@  discard block
 block discarded – undo
187 196
 		global $cachedir;
188 197
 
189 198
 		// If its invalid, use SMF's.
190
-		if (is_null($dir) || !is_writable($dir))
191
-			$this->cachedir = $cachedir;
192
-		else
193
-			$this->cachedir = $dir;
199
+		if (is_null($dir) || !is_writable($dir)) {
200
+					$this->cachedir = $cachedir;
201
+		} else {
202
+					$this->cachedir = $dir;
203
+		}
194 204
 	}
195 205
 
196 206
 	/**
Please login to merge, or discard this patch.
Sources/Class-Graphics.php 3 patches
Doc Comments   +28 added lines patch added patch discarded remove patch
@@ -44,6 +44,10 @@  discard block
 block discarded – undo
44 44
 		$this->Buf   = range(0, 279);
45 45
 	}
46 46
 
47
+	/**
48
+	 * @param string $data
49
+	 * @param integer $datLen
50
+	 */
47 51
 	public function decompress($data, &$datLen)
48 52
 	{
49 53
 		$stLen  = strlen($data);
@@ -63,6 +67,11 @@  discard block
 block discarded – undo
63 67
 		return $ret;
64 68
 	}
65 69
 
70
+	/**
71
+	 * @param boolean $bInit
72
+	 *
73
+	 * @return integer
74
+	 */
66 75
 	public function LZWCommand(&$data, $bInit)
67 76
 	{
68 77
 		if ($bInit)
@@ -253,6 +262,10 @@  discard block
 block discarded – undo
253 262
 		unset($this->m_nColors, $this->m_arColors);
254 263
 	}
255 264
 
265
+	/**
266
+	 * @param string $lpData
267
+	 * @param integer $num
268
+	 */
256 269
 	public function load($lpData, $num)
257 270
 	{
258 271
 		$this->m_nColors  = 0;
@@ -324,6 +337,9 @@  discard block
 block discarded – undo
324 337
 		unset($this->m_bSorted, $this->m_nTableSize, $this->m_nBgColor, $this->m_nPixelRatio, $this->m_colorTable);
325 338
 	}
326 339
 
340
+	/**
341
+	 * @param integer $hdrLen
342
+	 */
327 343
 	public function load($lpData, &$hdrLen)
328 344
 	{
329 345
 		$hdrLen = 0;
@@ -370,6 +386,10 @@  discard block
 block discarded – undo
370 386
 		unset($this->m_bInterlace, $this->m_bSorted, $this->m_nTableSize, $this->m_colorTable);
371 387
 	}
372 388
 
389
+	/**
390
+	 * @param string $lpData
391
+	 * @param integer $hdrLen
392
+	 */
373 393
 	public function load($lpData, &$hdrLen)
374 394
 	{
375 395
 		$hdrLen = 0;
@@ -412,6 +432,10 @@  discard block
 block discarded – undo
412 432
 		$this->m_lzw = new gif_lzw_compression();
413 433
 	}
414 434
 
435
+	/**
436
+	 * @param string $data
437
+	 * @param integer $datLen
438
+	 */
415 439
 	public function load($data, &$datLen)
416 440
 	{
417 441
 		$datLen = 0;
@@ -464,6 +488,10 @@  discard block
 block discarded – undo
464 488
 		return false;
465 489
 	}
466 490
 
491
+	/**
492
+	 * @param string $data
493
+	 * @param integer $extLen
494
+	 */
467 495
 	public function skipExt(&$data, &$extLen)
468 496
 	{
469 497
 		$extLen = 0;
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 		$this->MAX_LZW_BITS = 12;
39 39
 		unset($this->Next, $this->Vals, $this->Stack, $this->Buf);
40 40
 
41
-		$this->Next  = range(0, (1 << $this->MAX_LZW_BITS)       - 1);
42
-		$this->Vals  = range(0, (1 << $this->MAX_LZW_BITS)       - 1);
41
+		$this->Next  = range(0, (1 << $this->MAX_LZW_BITS) - 1);
42
+		$this->Vals  = range(0, (1 << $this->MAX_LZW_BITS) - 1);
43 43
 		$this->Stack = range(0, (1 << ($this->MAX_LZW_BITS + 1)) - 1);
44 44
 		$this->Buf   = range(0, 279);
45 45
 	}
@@ -278,9 +278,9 @@  discard block
 block discarded – undo
278 278
 		for ($i = 0; $i < $this->m_nColors; $i++)
279 279
 		{
280 280
 			$ret .=
281
-				chr(($this->m_arColors[$i] & 0x000000FF))       . // R
282
-				chr(($this->m_arColors[$i] & 0x0000FF00) >>  8) . // G
283
-				chr(($this->m_arColors[$i] & 0x00FF0000) >> 16);  // B
281
+				chr(($this->m_arColors[$i] & 0x000000FF)) . // R
282
+				chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G
283
+				chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B
284 284
 		}
285 285
 
286 286
 		return $ret;
@@ -290,14 +290,14 @@  discard block
 block discarded – undo
290 290
 	{
291 291
 		$rgb  = intval($rgb) & 0xFFFFFF;
292 292
 		$r1   = ($rgb & 0x0000FF);
293
-		$g1   = ($rgb & 0x00FF00) >>  8;
293
+		$g1   = ($rgb & 0x00FF00) >> 8;
294 294
 		$b1   = ($rgb & 0xFF0000) >> 16;
295 295
 		$idx  = -1;
296 296
 
297 297
 		for ($i = 0; $i < $this->m_nColors; $i++)
298 298
 		{
299 299
 			$r2 = ($this->m_arColors[$i] & 0x000000FF);
300
-			$g2 = ($this->m_arColors[$i] & 0x0000FF00) >>  8;
300
+			$g2 = ($this->m_arColors[$i] & 0x0000FF00) >> 8;
301 301
 			$b2 = ($this->m_arColors[$i] & 0x00FF0000) >> 16;
302 302
 			$d  = abs($r2 - $r1) + abs($g2 - $g1) + abs($b2 - $b1);
303 303
 
Please login to merge, or discard this patch.
Braces   +90 added lines, -62 removed lines patch added patch discarded remove patch
@@ -19,8 +19,9 @@  discard block
 block discarded – undo
19 19
  * @version 2.1 Beta 4
20 20
  */
21 21
 
22
-if (!defined('SMF'))
22
+if (!defined('SMF')) {
23 23
 	die('No direct access...');
24
+}
24 25
 
25 26
 /**
26 27
  * Class gif_lzw_compression
@@ -52,13 +53,15 @@  discard block
 block discarded – undo
52 53
 
53 54
 		$this->LZWCommand($data, true);
54 55
 
55
-		while (($iIndex = $this->LZWCommand($data, false)) >= 0)
56
-			$ret .= chr($iIndex);
56
+		while (($iIndex = $this->LZWCommand($data, false)) >= 0) {
57
+					$ret .= chr($iIndex);
58
+		}
57 59
 
58 60
 		$datLen = $stLen - strlen($data);
59 61
 
60
-		if ($iIndex != -2)
61
-			return false;
62
+		if ($iIndex != -2) {
63
+					return false;
64
+		}
62 65
 
63 66
 		return $ret;
64 67
 	}
@@ -140,8 +143,9 @@  discard block
 block discarded – undo
140 143
 				return $this->FirstCode;
141 144
 			}
142 145
 
143
-			if ($Code == $this->EndCode)
144
-				return -2;
146
+			if ($Code == $this->EndCode) {
147
+							return -2;
148
+			}
145 149
 
146 150
 			$InCode = $Code;
147 151
 			if ($Code >= $this->MaxCode)
@@ -156,8 +160,10 @@  discard block
 block discarded – undo
156 160
 				$this->Stack[$this->sp] = $this->Vals[$Code];
157 161
 				$this->sp++;
158 162
 
159
-				if ($Code == $this->Next[$Code]) // Circular table entry, big GIF Error!
163
+				if ($Code == $this->Next[$Code]) {
164
+					// Circular table entry, big GIF Error!
160 165
 					return -1;
166
+				}
161 167
 
162 168
 				$Code = $this->Next[$Code];
163 169
 			}
@@ -207,8 +213,9 @@  discard block
 block discarded – undo
207 213
 			if ($this->Done)
208 214
 			{
209 215
 				// Ran off the end of my bits...
210
-				if ($this->CurBit >= $this->LastBit)
211
-					return 0;
216
+				if ($this->CurBit >= $this->LastBit) {
217
+									return 0;
218
+				}
212 219
 
213 220
 				return -1;
214 221
 			}
@@ -221,13 +228,14 @@  discard block
 block discarded – undo
221 228
 
222 229
 			if ($count)
223 230
 			{
224
-				for ($i = 0; $i < $count; $i++)
225
-					$this->Buf[2 + $i] = ord($data{$i});
231
+				for ($i = 0; $i < $count; $i++) {
232
+									$this->Buf[2 + $i] = ord($data{$i});
233
+				}
226 234
 
227 235
 				$data = substr($data, $count);
236
+			} else {
237
+							$this->Done = 1;
228 238
 			}
229
-			else
230
-				$this->Done = 1;
231 239
 
232 240
 			$this->LastByte = 2 + $count;
233 241
 			$this->CurBit = ($this->CurBit - $this->LastBit) + 16;
@@ -235,8 +243,9 @@  discard block
 block discarded – undo
235 243
 		}
236 244
 
237 245
 		$iRet = 0;
238
-		for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++)
239
-			$iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j;
246
+		for ($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) {
247
+					$iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j;
248
+		}
240 249
 
241 250
 		$this->CurBit += $this->CodeSize;
242 251
 		return $iRet;
@@ -261,8 +270,9 @@  discard block
 block discarded – undo
261 270
 		for ($i = 0; $i < $num; $i++)
262 271
 		{
263 272
 			$rgb = substr($lpData, $i * 3, 3);
264
-			if (strlen($rgb) < 3)
265
-				return false;
273
+			if (strlen($rgb) < 3) {
274
+							return false;
275
+			}
266 276
 
267 277
 			$this->m_arColors[] = (ord($rgb[2]) << 16) + (ord($rgb[1]) << 8) + ord($rgb[0]);
268 278
 			$this->m_nColors++;
@@ -329,13 +339,15 @@  discard block
 block discarded – undo
329 339
 		$hdrLen = 0;
330 340
 
331 341
 		$this->m_lpVer = substr($lpData, 0, 6);
332
-		if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a'))
333
-			return false;
342
+		if (($this->m_lpVer != 'GIF87a') && ($this->m_lpVer != 'GIF89a')) {
343
+					return false;
344
+		}
334 345
 
335 346
 		list ($this->m_nWidth, $this->m_nHeight) = array_values(unpack('v2', substr($lpData, 6, 4)));
336 347
 
337
-		if (!$this->m_nWidth || !$this->m_nHeight)
338
-			return false;
348
+		if (!$this->m_nWidth || !$this->m_nHeight) {
349
+					return false;
350
+		}
339 351
 
340 352
 		$b = ord(substr($lpData, 10, 1));
341 353
 		$this->m_bGlobalClr  = ($b & 0x80) ? true : false;
@@ -349,8 +361,9 @@  discard block
 block discarded – undo
349 361
 		if ($this->m_bGlobalClr)
350 362
 		{
351 363
 			$this->m_colorTable = new gif_color_table();
352
-			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize))
353
-				return false;
364
+			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) {
365
+							return false;
366
+			}
354 367
 
355 368
 			$hdrLen += 3 * $this->m_nTableSize;
356 369
 		}
@@ -377,8 +390,9 @@  discard block
 block discarded – undo
377 390
 		// Get the width/height/etc. from the header.
378 391
 		list ($this->m_nLeft, $this->m_nTop, $this->m_nWidth, $this->m_nHeight) = array_values(unpack('v4', substr($lpData, 0, 8)));
379 392
 
380
-		if (!$this->m_nWidth || !$this->m_nHeight)
381
-			return false;
393
+		if (!$this->m_nWidth || !$this->m_nHeight) {
394
+					return false;
395
+		}
382 396
 
383 397
 		$b = ord($lpData[8]);
384 398
 		$this->m_bLocalClr  = ($b & 0x80) ? true : false;
@@ -390,8 +404,9 @@  discard block
 block discarded – undo
390 404
 		if ($this->m_bLocalClr)
391 405
 		{
392 406
 			$this->m_colorTable = new gif_color_table();
393
-			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize))
394
-				return false;
407
+			if (!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) {
408
+							return false;
409
+			}
395 410
 
396 411
 			$hdrLen += 3 * $this->m_nTableSize;
397 412
 		}
@@ -427,8 +442,9 @@  discard block
 block discarded – undo
427 442
 			// Extension...
428 443
 				case 0x21:
429 444
 					$len = 0;
430
-					if (!$this->skipExt($data, $len))
431
-						return false;
445
+					if (!$this->skipExt($data, $len)) {
446
+											return false;
447
+					}
432 448
 
433 449
 					$datLen += $len;
434 450
 					break;
@@ -437,21 +453,24 @@  discard block
 block discarded – undo
437 453
 				case 0x2C:
438 454
 					// Load the header and color table.
439 455
 					$len = 0;
440
-					if (!$this->m_gih->load($data, $len))
441
-						return false;
456
+					if (!$this->m_gih->load($data, $len)) {
457
+											return false;
458
+					}
442 459
 
443 460
 					$data = substr($data, $len);
444 461
 					$datLen += $len;
445 462
 
446 463
 					// Decompress the data, and ride on home ;).
447 464
 					$len = 0;
448
-					if (!($this->m_data = $this->m_lzw->decompress($data, $len)))
449
-						return false;
465
+					if (!($this->m_data = $this->m_lzw->decompress($data, $len))) {
466
+											return false;
467
+					}
450 468
 
451 469
 					$datLen += $len;
452 470
 
453
-					if ($this->m_gih->m_bInterlace)
454
-						$this->deInterlace();
471
+					if ($this->m_gih->m_bInterlace) {
472
+											$this->deInterlace();
473
+					}
455 474
 
456 475
 					return true;
457 476
 
@@ -571,17 +590,20 @@  discard block
 block discarded – undo
571 590
 
572 591
 	public function loadFile($filename, $iIndex)
573 592
 	{
574
-		if ($iIndex < 0)
575
-			return false;
593
+		if ($iIndex < 0) {
594
+					return false;
595
+		}
576 596
 
577 597
 		$this->data = @file_get_contents($filename);
578
-		if ($this->data === false)
579
-			return false;
598
+		if ($this->data === false) {
599
+					return false;
600
+		}
580 601
 
581 602
 		// Tell the header to load up....
582 603
 		$len = 0;
583
-		if (!$this->header->load($this->data, $len))
584
-			return false;
604
+		if (!$this->header->load($this->data, $len)) {
605
+					return false;
606
+		}
585 607
 
586 608
 		$this->data = substr($this->data, $len);
587 609
 
@@ -589,8 +611,9 @@  discard block
 block discarded – undo
589 611
 		for ($j = 0; $j <= $iIndex; $j++)
590 612
 		{
591 613
 			$imgLen = 0;
592
-			if (!$this->image->load($this->data, $imgLen))
593
-				return false;
614
+			if (!$this->image->load($this->data, $imgLen)) {
615
+							return false;
616
+			}
594 617
 
595 618
 			$this->data = substr($this->data, $imgLen);
596 619
 		}
@@ -601,8 +624,9 @@  discard block
 block discarded – undo
601 624
 
602 625
 	public function get_png_data($background_color)
603 626
 	{
604
-		if (!$this->loaded)
605
-			return false;
627
+		if (!$this->loaded) {
628
+					return false;
629
+		}
606 630
 
607 631
 		// Prepare the color table.
608 632
 		if ($this->image->m_gih->m_bLocalClr)
@@ -610,25 +634,26 @@  discard block
 block discarded – undo
610 634
 			$colors = $this->image->m_gih->m_nTableSize;
611 635
 			$pal = $this->image->m_gih->m_colorTable->toString();
612 636
 
613
-			if ($background_color != -1)
614
-				$background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color);
615
-		}
616
-		elseif ($this->header->m_bGlobalClr)
637
+			if ($background_color != -1) {
638
+							$background_color = $this->image->m_gih->m_colorTable->colorIndex($background_color);
639
+			}
640
+		} elseif ($this->header->m_bGlobalClr)
617 641
 		{
618 642
 			$colors = $this->header->m_nTableSize;
619 643
 			$pal = $this->header->m_colorTable->toString();
620 644
 
621
-			if ($background_color != -1)
622
-				$background_color = $this->header->m_colorTable->colorIndex($background_color);
623
-		}
624
-		else
645
+			if ($background_color != -1) {
646
+							$background_color = $this->header->m_colorTable->colorIndex($background_color);
647
+			}
648
+		} else
625 649
 		{
626 650
 			$colors = 0;
627 651
 			$background_color = -1;
628 652
 		}
629 653
 
630
-		if ($background_color == -1)
631
-			$background_color = $this->header->m_nBgColor;
654
+		if ($background_color == -1) {
655
+					$background_color = $this->header->m_nBgColor;
656
+		}
632 657
 
633 658
 		$data = &$this->image->m_data;
634 659
 		$header = &$this->image->m_gih;
@@ -644,11 +669,13 @@  discard block
 block discarded – undo
644 669
 			for ($x = 0; $x < $this->header->m_nWidth; $x++, $i++)
645 670
 			{
646 671
 				// Is this in the proper range?  If so, get the specific pixel data...
647
-				if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight))
648
-					$bmp .= $data{$i};
672
+				if ($x >= $header->m_nLeft && $y >= $header->m_nTop && $x < ($header->m_nLeft + $header->m_nWidth) && $y < ($header->m_nTop + $header->m_nHeight)) {
673
+									$bmp .= $data{$i};
674
+				}
649 675
 				// Otherwise, this is background...
650
-				else
651
-					$bmp .= chr($background_color);
676
+				else {
677
+									$bmp .= chr($background_color);
678
+				}
652 679
 			}
653 680
 		}
654 681
 
@@ -677,8 +704,9 @@  discard block
 block discarded – undo
677 704
 			$tmp = 'tRNS';
678 705
 
679 706
 			// Stick each color on - full transparency or none.
680
-			for ($i = 0; $i < $colors; $i++)
681
-				$tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF";
707
+			for ($i = 0; $i < $colors; $i++) {
708
+							$tmp .= $i == $this->image->m_nTrans ? "\x00" : "\xFF";
709
+			}
682 710
 
683 711
 			$out .= $tmp . pack('N', smf_crc32($tmp));
684 712
 		}
Please login to merge, or discard this patch.
Sources/Class-SearchAPI.php 1 patch
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,6 +56,7 @@  discard block
 block discarded – undo
56 56
 	 * @param array $wordsSearch Search words
57 57
 	 * @param array $wordsExclude Words to exclude
58 58
 	 * @param bool $isExcluded Whether the specfied word should be excluded
59
+	 * @return void
59 60
 	 */
60 61
 	public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, $isExcluded);
61 62
 
@@ -130,7 +131,7 @@  discard block
 block discarded – undo
130 131
 	 * @param array $excludedIndexWords Indexed words that should be excluded
131 132
 	 * @param array $participants
132 133
 	 * @param array $searchArray
133
-	 * @return mixed
134
+	 * @return integer
134 135
 	 */
135 136
 	public function searchQuery(array $query_params, array $searchWords, array $excludedIndexWords, array &$participants, array &$searchArray);
136 137
 }
Please login to merge, or discard this patch.
Sources/Class-TOTP.php 1 patch
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 	/**
280 280
 	 * Generate the timestamp for the calculation
281 281
 	 *
282
-	 * @return integer Timestamp
282
+	 * @return double Timestamp
283 283
 	 */
284 284
 	public function generateTimestamp()
285 285
 	{
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 * Truncate the given hash down to just what we need
291 291
 	 *
292 292
 	 * @param string $hash Hash to truncate
293
-	 * @return string Truncated hash value
293
+	 * @return integer Truncated hash value
294 294
 	 */
295 295
 	public function truncateHash($hash)
296 296
 	{
Please login to merge, or discard this patch.
Sources/DbPackages-mysql.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -382,7 +382,7 @@
 block discarded – undo
382 382
  * @param array $parameters Not used?
383 383
  * @param string $if_exists What to do if the index exists. If 'update', the definition will be updated.
384 384
  * @param string $error
385
- * @return boolean Whether or not the operation was successful
385
+ * @return false|null Whether or not the operation was successful
386 386
  */
387 387
 function smf_db_add_index($table_name, $index_info, $parameters = array(), $if_exists = 'update', $error = 'fatal')
388 388
 {
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 		{
127 127
 			$smcFunc['db_transaction']('begin');
128 128
 			$db_trans = true;
129
-			$smcFunc['db_drop_table']($table_name.'_old');
130
-			$smcFunc['db_query']('','
131
-				RENAME TABLE '. $table_name .' TO ' . $table_name . '_old',
129
+			$smcFunc['db_drop_table']($table_name . '_old');
130
+			$smcFunc['db_query']('', '
131
+				RENAME TABLE '. $table_name . ' TO ' . $table_name . '_old',
132 132
 				array(
133 133
 					'security_override' => true,
134 134
 				)
@@ -202,15 +202,15 @@  discard block
 block discarded – undo
202 202
 	{	
203 203
 		$same_col = array();
204 204
 
205
-		$request = $smcFunc['db_query']('','
205
+		$request = $smcFunc['db_query']('', '
206 206
 			SELECT count(*), column_name
207 207
 			FROM information_schema.columns
208 208
 			WHERE table_name in ({string:table1},{string:table2}) AND table_schema = {string:schema}
209 209
 			GROUP BY column_name
210 210
 			HAVING count(*) > 1',
211
-			array (
211
+			array(
212 212
 				'table1' => $table_name,
213
-				'table2' => $table_name.'_old',
213
+				'table2' => $table_name . '_old',
214 214
 				'schema' => $db_name,
215 215
 			)
216 216
 		);
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
 			$same_col[] = $row['column_name'];
221 221
 		}
222 222
 
223
-		$smcFunc['db_query']('','
224
-			INSERT INTO ' . $table_name .'('
223
+		$smcFunc['db_query']('', '
224
+			INSERT INTO ' . $table_name . '('
225 225
 			. implode($same_col, ',') .
226 226
 			')
227 227
 			SELECT '. implode($same_col, ',') . '
Please login to merge, or discard this patch.
Braces   +122 added lines, -98 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
  * Add the file functions to the $smcFunc array.
@@ -53,8 +54,9 @@  discard block
 block discarded – undo
53 54
 		'messages', 'moderator_groups', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages',
54 55
 		'pm_labeled_messages', 'pm_labels', 'pm_recipients', 'pm_rules', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys',
55 56
 		'spiders', 'subscriptions', 'themes', 'topics', 'user_alerts', 'user_alerts_prefs', 'user_drafts', 'user_likes');
56
-	foreach ($reservedTables as $k => $table_name)
57
-		$reservedTables[$k] = strtolower($db_prefix . $table_name);
57
+	foreach ($reservedTables as $k => $table_name) {
58
+			$reservedTables[$k] = strtolower($db_prefix . $table_name);
59
+	}
58 60
 
59 61
 	// We in turn may need the extra stuff.
60 62
 	db_extend('extra');
@@ -109,8 +111,9 @@  discard block
 block discarded – undo
109 111
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
110 112
 
111 113
 	// First - no way do we touch SMF tables.
112
-	if (in_array(strtolower($table_name), $reservedTables))
113
-		return false;
114
+	if (in_array(strtolower($table_name), $reservedTables)) {
115
+			return false;
116
+	}
114 117
 
115 118
 	// Log that we'll want to remove this on uninstall.
116 119
 	$db_package_log[] = array('remove_table', $table_name);
@@ -120,9 +123,9 @@  discard block
 block discarded – undo
120 123
 	if (in_array($full_table_name, $tables))
121 124
 	{
122 125
 		// This is a sad day... drop the table? If not, return false (error) by default.
123
-		if ($if_exists == 'overwrite')
124
-			$smcFunc['db_drop_table']($table_name);
125
-		else if ($if_exists == 'update')
126
+		if ($if_exists == 'overwrite') {
127
+					$smcFunc['db_drop_table']($table_name);
128
+		} else if ($if_exists == 'update')
126 129
 		{
127 130
 			$smcFunc['db_transaction']('begin');
128 131
 			$db_trans = true;
@@ -134,15 +137,16 @@  discard block
 block discarded – undo
134 137
 				)
135 138
 			);
136 139
 			$old_table_exists = true;
140
+		} else {
141
+					return $if_exists == 'ignore';
137 142
 		}
138
-		else
139
-			return $if_exists == 'ignore';
140 143
 	}
141 144
 
142 145
 	// Righty - let's do the damn thing!
143 146
 	$table_query = 'CREATE TABLE ' . $table_name . "\n" . '(';
144
-	foreach ($columns as $column)
145
-		$table_query .= "\n\t" . smf_db_create_query_column($column) . ',';
147
+	foreach ($columns as $column) {
148
+			$table_query .= "\n\t" . smf_db_create_query_column($column) . ',';
149
+	}
146 150
 
147 151
 	// Loop through the indexes next...
148 152
 	foreach ($indexes as $index)
@@ -150,19 +154,21 @@  discard block
 block discarded – undo
150 154
 		$columns = implode(',', $index['columns']);
151 155
 
152 156
 		// Is it the primary?
153
-		if (isset($index['type']) && $index['type'] == 'primary')
154
-			$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
155
-		else
157
+		if (isset($index['type']) && $index['type'] == 'primary') {
158
+					$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
159
+		} else
156 160
 		{
157
-			if (empty($index['name']))
158
-				$index['name'] = implode('_', $index['columns']);
161
+			if (empty($index['name'])) {
162
+							$index['name'] = implode('_', $index['columns']);
163
+			}
159 164
 			$table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),';
160 165
 		}
161 166
 	}
162 167
 
163 168
 	// No trailing commas!
164
-	if (substr($table_query, -1) == ',')
165
-		$table_query = substr($table_query, 0, -1);
169
+	if (substr($table_query, -1) == ',') {
170
+			$table_query = substr($table_query, 0, -1);
171
+	}
166 172
 
167 173
 	// Which engine do we want here?
168 174
 	if (empty($engines))
@@ -172,8 +178,9 @@  discard block
 block discarded – undo
172 178
 
173 179
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
174 180
 		{
175
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
176
-				$engines[] = $row['Engine'];
181
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
182
+							$engines[] = $row['Engine'];
183
+			}
177 184
 		}
178 185
 
179 186
 		$smcFunc['db_free_result']($get_engines);
@@ -187,8 +194,9 @@  discard block
 block discarded – undo
187 194
 	}
188 195
 
189 196
 	$table_query .= ') ENGINE=' . $parameters['engine'];
190
-	if (!empty($db_character_set) && $db_character_set == 'utf8')
191
-		$table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
197
+	if (!empty($db_character_set) && $db_character_set == 'utf8') {
198
+			$table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
199
+	}
192 200
 
193 201
 	// Create the table!
194 202
 	$smcFunc['db_query']('', $table_query,
@@ -255,8 +263,9 @@  discard block
 block discarded – undo
255 263
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
256 264
 
257 265
 	// God no - dropping one of these = bad.
258
-	if (in_array(strtolower($table_name), $reservedTables))
259
-		return false;
266
+	if (in_array(strtolower($table_name), $reservedTables)) {
267
+			return false;
268
+	}
260 269
 
261 270
 	// Does it exist?
262 271
 	if (in_array($full_table_name, $smcFunc['db_list_tables']()))
@@ -297,14 +306,16 @@  discard block
 block discarded – undo
297 306
 
298 307
 	// Does it exist - if so don't add it again!
299 308
 	$columns = $smcFunc['db_list_columns']($table_name, false);
300
-	foreach ($columns as $column)
301
-		if ($column == $column_info['name'])
309
+	foreach ($columns as $column) {
310
+			if ($column == $column_info['name'])
302 311
 		{
303 312
 			// If we're going to overwrite then use change column.
304 313
 			if ($if_exists == 'update')
305 314
 				return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
306
-			else
307
-				return false;
315
+	}
316
+			else {
317
+							return false;
318
+			}
308 319
 		}
309 320
 
310 321
 	// Get the specifics...
@@ -340,8 +351,8 @@  discard block
 block discarded – undo
340 351
 
341 352
 	// Does it exist?
342 353
 	$columns = $smcFunc['db_list_columns']($table_name, true);
343
-	foreach ($columns as $column)
344
-		if ($column['name'] == $column_name)
354
+	foreach ($columns as $column) {
355
+			if ($column['name'] == $column_name)
345 356
 		{
346 357
 			$smcFunc['db_query']('', '
347 358
 				ALTER TABLE ' . $table_name . '
@@ -350,6 +361,7 @@  discard block
 block discarded – undo
350 361
 					'security_override' => true,
351 362
 				)
352 363
 			);
364
+	}
353 365
 
354 366
 			return true;
355 367
 		}
@@ -375,37 +387,47 @@  discard block
 block discarded – undo
375 387
 	// Check it does exist!
376 388
 	$columns = $smcFunc['db_list_columns']($table_name, true);
377 389
 	$old_info = null;
378
-	foreach ($columns as $column)
379
-		if ($column['name'] == $old_column)
390
+	foreach ($columns as $column) {
391
+			if ($column['name'] == $old_column)
380 392
 			$old_info = $column;
393
+	}
381 394
 
382 395
 	// Nothing?
383
-	if ($old_info == null)
384
-		return false;
396
+	if ($old_info == null) {
397
+			return false;
398
+	}
385 399
 
386 400
 	// Get the right bits.
387
-	if (!isset($column_info['name']))
388
-		$column_info['name'] = $old_column;
389
-	if (!isset($column_info['default']))
390
-		$column_info['default'] = $old_info['default'];
391
-	if (!isset($column_info['null']))
392
-		$column_info['null'] = $old_info['null'];
393
-	if (!isset($column_info['auto']))
394
-		$column_info['auto'] = $old_info['auto'];
395
-	if (!isset($column_info['type']))
396
-		$column_info['type'] = $old_info['type'];
397
-	if (!isset($column_info['size']) || !is_numeric($column_info['size']))
398
-		$column_info['size'] = $old_info['size'];
399
-	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')))
400
-		$column_info['unsigned'] = '';
401
+	if (!isset($column_info['name'])) {
402
+			$column_info['name'] = $old_column;
403
+	}
404
+	if (!isset($column_info['default'])) {
405
+			$column_info['default'] = $old_info['default'];
406
+	}
407
+	if (!isset($column_info['null'])) {
408
+			$column_info['null'] = $old_info['null'];
409
+	}
410
+	if (!isset($column_info['auto'])) {
411
+			$column_info['auto'] = $old_info['auto'];
412
+	}
413
+	if (!isset($column_info['type'])) {
414
+			$column_info['type'] = $old_info['type'];
415
+	}
416
+	if (!isset($column_info['size']) || !is_numeric($column_info['size'])) {
417
+			$column_info['size'] = $old_info['size'];
418
+	}
419
+	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) {
420
+			$column_info['unsigned'] = '';
421
+	}
401 422
 
402 423
 	list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
403 424
 
404 425
 	// Allow for unsigned integers (mysql only)
405 426
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : '';
406 427
 
407
-	if ($size !== null)
408
-		$type = $type . '(' . $size . ')';
428
+	if ($size !== null) {
429
+			$type = $type . '(' . $size . ')';
430
+	}
409 431
 
410 432
 	$smcFunc['db_query']('', '
411 433
 		ALTER TABLE ' . $table_name . '
@@ -435,18 +457,20 @@  discard block
 block discarded – undo
435 457
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
436 458
 
437 459
 	// No columns = no index.
438
-	if (empty($index_info['columns']))
439
-		return false;
460
+	if (empty($index_info['columns'])) {
461
+			return false;
462
+	}
440 463
 	$columns = implode(',', $index_info['columns']);
441 464
 
442 465
 	// No name - make it up!
443 466
 	if (empty($index_info['name']))
444 467
 	{
445 468
 		// No need for primary.
446
-		if (isset($index_info['type']) && $index_info['type'] == 'primary')
447
-			$index_info['name'] = '';
448
-		else
449
-			$index_info['name'] = implode('_', $index_info['columns']);
469
+		if (isset($index_info['type']) && $index_info['type'] == 'primary') {
470
+					$index_info['name'] = '';
471
+		} else {
472
+					$index_info['name'] = implode('_', $index_info['columns']);
473
+		}
450 474
 	}
451 475
 
452 476
 	// Log that we are going to want to remove this!
@@ -460,10 +484,11 @@  discard block
 block discarded – undo
460 484
 		if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary'))
461 485
 		{
462 486
 			// If we want to overwrite simply remove the current one then continue.
463
-			if ($if_exists != 'update' || $index['type'] == 'primary')
464
-				return false;
465
-			else
466
-				$smcFunc['db_remove_index']($table_name, $index_info['name']);
487
+			if ($if_exists != 'update' || $index['type'] == 'primary') {
488
+							return false;
489
+			} else {
490
+							$smcFunc['db_remove_index']($table_name, $index_info['name']);
491
+			}
467 492
 		}
468 493
 	}
469 494
 
@@ -477,8 +502,7 @@  discard block
 block discarded – undo
477 502
 				'security_override' => true,
478 503
 			)
479 504
 		);
480
-	}
481
-	else
505
+	} else
482 506
 	{
483 507
 		$smcFunc['db_query']('', '
484 508
 			ALTER TABLE ' . $table_name . '
@@ -562,8 +586,7 @@  discard block
 block discarded – undo
562 586
 		$types = array(
563 587
 			'inet' => 'varbinary',
564 588
 		);
565
-	}
566
-	else
589
+	} else
567 590
 	{
568 591
 		$types = array(
569 592
 			'varbinary' => 'inet',
@@ -577,16 +600,15 @@  discard block
 block discarded – undo
577 600
 		{
578 601
 			$type_size = 16;
579 602
 			$type_name = 'varbinary';
580
-		}
581
-		elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)
603
+		} elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)
582 604
 		{
583 605
 			$type_name = 'inet';
584 606
 			$type_size = null;
607
+		} elseif ($type_name == 'varbinary') {
608
+					$type_name = 'varbinary';
609
+		} else {
610
+					$type_name = $types[$type_name];
585 611
 		}
586
-		elseif ($type_name == 'varbinary')
587
-			$type_name = 'varbinary';
588
-		else
589
-			$type_name = $types[$type_name];
590 612
 	}
591 613
 
592 614
 	return array($type_name, $type_size);
@@ -653,8 +675,7 @@  discard block
 block discarded – undo
653 675
 		if (!$detail)
654 676
 		{
655 677
 			$columns[] = $row['Field'];
656
-		}
657
-		else
678
+		} else
658 679
 		{
659 680
 			// Is there an auto_increment?
660 681
 			$auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false;
@@ -664,10 +685,10 @@  discard block
 block discarded – undo
664 685
 			{
665 686
 				$type = $matches[1];
666 687
 				$size = $matches[2];
667
-				if (!empty($matches[3]) && $matches[3] == 'unsigned')
668
-					$unsigned = true;
669
-			}
670
-			else
688
+				if (!empty($matches[3]) && $matches[3] == 'unsigned') {
689
+									$unsigned = true;
690
+				}
691
+			} else
671 692
 			{
672 693
 				$type = $row['Type'];
673 694
 				$size = null;
@@ -718,19 +739,20 @@  discard block
 block discarded – undo
718 739
 	$indexes = array();
719 740
 	while ($row = $smcFunc['db_fetch_assoc']($result))
720 741
 	{
721
-		if (!$detail)
722
-			$indexes[] = $row['Key_name'];
723
-		else
742
+		if (!$detail) {
743
+					$indexes[] = $row['Key_name'];
744
+		} else
724 745
 		{
725 746
 			// What is the type?
726
-			if ($row['Key_name'] == 'PRIMARY')
727
-				$type = 'primary';
728
-			elseif (empty($row['Non_unique']))
729
-				$type = 'unique';
730
-			elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT')
731
-				$type = 'fulltext';
732
-			else
733
-				$type = 'index';
747
+			if ($row['Key_name'] == 'PRIMARY') {
748
+							$type = 'primary';
749
+			} elseif (empty($row['Non_unique'])) {
750
+							$type = 'unique';
751
+			} elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') {
752
+							$type = 'fulltext';
753
+			} else {
754
+							$type = 'index';
755
+			}
734 756
 
735 757
 			// This is the first column we've seen?
736 758
 			if (empty($indexes[$row['Key_name']]))
@@ -743,10 +765,11 @@  discard block
 block discarded – undo
743 765
 			}
744 766
 
745 767
 			// Is it a partial index?
746
-			if (!empty($row['Sub_part']))
747
-				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')';
748
-			else
749
-				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'];
768
+			if (!empty($row['Sub_part'])) {
769
+							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')';
770
+			} else {
771
+							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'];
772
+			}
750 773
 		}
751 774
 	}
752 775
 	$smcFunc['db_free_result']($result);
@@ -768,11 +791,11 @@  discard block
 block discarded – undo
768 791
 	if (!empty($column['auto']))
769 792
 	{
770 793
 		$default = 'auto_increment';
794
+	} elseif (isset($column['default']) && $column['default'] !== null) {
795
+			$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
796
+	} else {
797
+			$default = '';
771 798
 	}
772
-	elseif (isset($column['default']) && $column['default'] !== null)
773
-		$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
774
-	else
775
-		$default = '';
776 799
 
777 800
 	// Sort out the size... and stuff...
778 801
 	$column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
@@ -781,8 +804,9 @@  discard block
 block discarded – undo
781 804
 	// Allow unsigned integers (mysql only)
782 805
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : '';
783 806
 
784
-	if ($size !== null)
785
-		$type = $type . '(' . $size . ')';
807
+	if ($size !== null) {
808
+			$type = $type . '(' . $size . ')';
809
+	}
786 810
 
787 811
 	// Now just put it together!
788 812
 	return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default;
Please login to merge, or discard this patch.
Sources/Errors.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -475,7 +475,7 @@
 block discarded – undo
475 475
  * Used by fatal_error(), fatal_lang_error()
476 476
  *
477 477
  * @param string $error The error
478
- * @param array $sprintf An array of data to be sprintf()'d into the specified message
478
+ * @param boolean $sprintf An array of data to be sprintf()'d into the specified message
479 479
  */
480 480
 function log_error_online($error, $sprintf = array())
481 481
 {
Please login to merge, or discard this patch.
Braces   +120 added lines, -85 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
  * Log an error, if the error logging is enabled.
@@ -36,8 +37,9 @@  discard block
 block discarded – undo
36 37
 	static $tried_hook = false;
37 38
 
38 39
 	// Check if error logging is actually on.
39
-	if (empty($modSettings['enableErrorLogging']))
40
-		return $error_message;
40
+	if (empty($modSettings['enableErrorLogging'])) {
41
+			return $error_message;
42
+	}
41 43
 
42 44
 	// Basically, htmlspecialchars it minus &. (for entities!)
43 45
 	$error_message = strtr($error_message, array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;'));
@@ -45,33 +47,39 @@  discard block
 block discarded – undo
45 47
 
46 48
 	// Add a file and line to the error message?
47 49
 	// Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line
48
-	if ($file == null)
49
-		$file = '';
50
-	else
51
-		// Window style slashes don't play well, lets convert them to the unix style.
50
+	if ($file == null) {
51
+			$file = '';
52
+	} else {
53
+			// Window style slashes don't play well, lets convert them to the unix style.
52 54
 		$file = str_replace('\\', '/', $file);
55
+	}
53 56
 
54
-	if ($line == null)
55
-		$line = 0;
56
-	else
57
-		$line = (int) $line;
57
+	if ($line == null) {
58
+			$line = 0;
59
+	} else {
60
+			$line = (int) $line;
61
+	}
58 62
 
59 63
 	// Just in case there's no id_member or IP set yet.
60
-	if (empty($user_info['id']))
61
-		$user_info['id'] = 0;
62
-	if (empty($user_info['ip']))
63
-		$user_info['ip'] = '';
64
+	if (empty($user_info['id'])) {
65
+			$user_info['id'] = 0;
66
+	}
67
+	if (empty($user_info['ip'])) {
68
+			$user_info['ip'] = '';
69
+	}
64 70
 
65 71
 	// Find the best query string we can...
66 72
 	$query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];
67 73
 
68 74
 	// Don't log the session hash in the url twice, it's a waste.
69
-	if (!empty($smcFunc['htmlspecialchars']))
70
-		$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
75
+	if (!empty($smcFunc['htmlspecialchars'])) {
76
+			$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
77
+	}
71 78
 
72 79
 	// Just so we know what board error messages are from.
73
-	if (isset($_POST['board']) && !isset($_GET['board']))
74
-		$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
80
+	if (isset($_POST['board']) && !isset($_GET['board'])) {
81
+			$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
82
+	}
75 83
 
76 84
 	// What types of categories do we have?
77 85
 	$known_error_types = array(
@@ -134,12 +142,14 @@  discard block
 block discarded – undo
134 142
 	global $txt;
135 143
 
136 144
 	// Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all
137
-	if (!empty($status))
138
-		send_http_status($status);
145
+	if (!empty($status)) {
146
+			send_http_status($status);
147
+	}
139 148
 
140 149
 	// We don't have $txt yet, but that's okay...
141
-	if (empty($txt))
142
-		die($error);
150
+	if (empty($txt)) {
151
+			die($error);
152
+	}
143 153
 
144 154
 	log_error_online($error, false);
145 155
 	setup_fatal_error_context($log ? log_error($error, $log) : $error);
@@ -166,8 +176,9 @@  discard block
 block discarded – undo
166 176
 	static $fatal_error_called = false;
167 177
 
168 178
 	// Send the status header - set this to 0 or false if you don't want to send one at all
169
-	if (!empty($status))
170
-		send_http_status($status);
179
+	if (!empty($status)) {
180
+			send_http_status($status);
181
+	}
171 182
 
172 183
 	// Try to load a theme if we don't have one.
173 184
 	if (empty($context['theme_loaded']) && empty($fatal_error_called))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 	}
178 189
 
179 190
 	// If we have no theme stuff we can't have the language file...
180
-	if (empty($context['theme_loaded']))
181
-		die($error);
191
+	if (empty($context['theme_loaded'])) {
192
+			die($error);
193
+	}
182 194
 
183 195
 	$reload_lang_file = true;
184 196
 	// Log the error in the forum's language, but don't waste the time if we aren't logging
@@ -214,8 +226,9 @@  discard block
 block discarded – undo
214 226
 	global $settings, $modSettings, $db_show_debug;
215 227
 
216 228
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5 (which cannot be solved without breaking PHP 4.)
217
-	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging'])))
218
-		return;
229
+	if (error_reporting() == 0 || (defined('E_STRICT') && $error_level == E_STRICT && !empty($modSettings['enableErrorLogging']))) {
230
+			return;
231
+	}
219 232
 
220 233
 	if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename']))
221 234
 	{
@@ -223,19 +236,22 @@  discard block
 block discarded – undo
223 236
 		$count = count($array);
224 237
 		for ($i = 0; $i < $count; $i++)
225 238
 		{
226
-			if ($array[$i]['function'] != 'loadSubTemplate')
227
-				continue;
239
+			if ($array[$i]['function'] != 'loadSubTemplate') {
240
+							continue;
241
+			}
228 242
 
229 243
 			// This is a bug in PHP, with eval, it seems!
230
-			if (empty($array[$i]['args']))
231
-				$i++;
244
+			if (empty($array[$i]['args'])) {
245
+							$i++;
246
+			}
232 247
 			break;
233 248
 		}
234 249
 
235
-		if (isset($array[$i]) && !empty($array[$i]['args']))
236
-			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
237
-		else
238
-			$file = realpath($settings['current_include_filename']) . ' (eval?)';
250
+		if (isset($array[$i]) && !empty($array[$i]['args'])) {
251
+					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
252
+		} else {
253
+					$file = realpath($settings['current_include_filename']) . ' (eval?)';
254
+		}
239 255
 	}
240 256
 
241 257
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -244,8 +260,9 @@  discard block
 block discarded – undo
244 260
 		if ($error_level % 255 != E_ERROR)
245 261
 		{
246 262
 			$temporary = ob_get_contents();
247
-			if (substr($temporary, -2) == '="')
248
-				echo '"';
263
+			if (substr($temporary, -2) == '="') {
264
+							echo '"';
265
+			}
249 266
 		}
250 267
 
251 268
 		// Debugging!  This should look like a PHP error message.
@@ -261,23 +278,27 @@  discard block
 block discarded – undo
261 278
 	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line));
262 279
 
263 280
 	// Dying on these errors only causes MORE problems (blank pages!)
264
-	if ($file == 'Unknown')
265
-		return;
281
+	if ($file == 'Unknown') {
282
+			return;
283
+	}
266 284
 
267 285
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
268
-	if ($error_level % 255 == E_ERROR)
269
-		obExit(false);
270
-	else
271
-		return;
286
+	if ($error_level % 255 == E_ERROR) {
287
+			obExit(false);
288
+	} else {
289
+			return;
290
+	}
272 291
 
273 292
 	// If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die.  Violently so.
274
-	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING)
275
-		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
293
+	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) {
294
+			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
295
+	}
276 296
 
277 297
 	// We should NEVER get to this point.  Any fatal error MUST quit, or very bad things can happen.
278
-	if ($error_level % 255 == E_ERROR)
279
-		die('No direct access...');
280
-}
298
+	if ($error_level % 255 == E_ERROR) {
299
+			die('No direct access...');
300
+	}
301
+	}
281 302
 
282 303
 /**
283 304
  * It is called by {@link fatal_error()} and {@link fatal_lang_error()}.
@@ -293,24 +314,28 @@  discard block
 block discarded – undo
293 314
 
294 315
 	// Attempt to prevent a recursive loop.
295 316
 	++$level;
296
-	if ($level > 1)
297
-		return false;
317
+	if ($level > 1) {
318
+			return false;
319
+	}
298 320
 
299 321
 	// Maybe they came from dlattach or similar?
300
-	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded']))
301
-		loadTheme();
322
+	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) {
323
+			loadTheme();
324
+	}
302 325
 
303 326
 	// Don't bother indexing errors mate...
304 327
 	$context['robot_no_index'] = true;
305 328
 
306
-	if (!isset($context['error_title']))
307
-		$context['error_title'] = $txt['error_occured'];
329
+	if (!isset($context['error_title'])) {
330
+			$context['error_title'] = $txt['error_occured'];
331
+	}
308 332
 	$context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
309 333
 
310 334
 	$context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : '';
311 335
 
312
-	if (empty($context['page_title']))
313
-		$context['page_title'] = $context['error_title'];
336
+	if (empty($context['page_title'])) {
337
+			$context['page_title'] = $context['error_title'];
338
+	}
314 339
 
315 340
 	loadTemplate('Errors');
316 341
 	$context['sub_template'] = 'fatal_error';
@@ -318,23 +343,26 @@  discard block
 block discarded – undo
318 343
 	// If this is SSI, what do they want us to do?
319 344
 	if (SMF == 'SSI')
320 345
 	{
321
-		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method))
322
-			$ssi_on_error_method();
323
-		elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
324
-			loadSubTemplate('fatal_error');
346
+		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
347
+					$ssi_on_error_method();
348
+		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
349
+					loadSubTemplate('fatal_error');
350
+		}
325 351
 
326 352
 		// No layers?
327
-		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
328
-			exit;
353
+		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
354
+					exit;
355
+		}
329 356
 	}
330 357
 	// Alternatively from the cron call?
331 358
 	elseif (SMF == 'BACKGROUND')
332 359
 	{
333 360
 		// We can't rely on even having language files available.
334
-		if (defined('FROM_CLI') && FROM_CLI)
335
-			echo 'cron error: ', $context['error_message'];
336
-		else
337
-			echo 'An error occurred. More information may be available in your logs.';
361
+		if (defined('FROM_CLI') && FROM_CLI) {
362
+					echo 'cron error: ', $context['error_message'];
363
+		} else {
364
+					echo 'An error occurred. More information may be available in your logs.';
365
+		}
338 366
 		exit;
339 367
 	}
340 368
 
@@ -362,8 +390,8 @@  discard block
 block discarded – undo
362 390
 
363 391
 	set_fatal_error_headers();
364 392
 
365
-	if (!empty($maintenance))
366
-		echo '<!DOCTYPE html>
393
+	if (!empty($maintenance)) {
394
+			echo '<!DOCTYPE html>
367 395
 <html>
368 396
 	<head>
369 397
 		<meta name="robots" content="noindex">
@@ -374,6 +402,7 @@  discard block
 block discarded – undo
374 402
 		', $mmessage, '
375 403
 	</body>
376 404
 </html>';
405
+	}
377 406
 
378 407
 	die();
379 408
 }
@@ -395,15 +424,17 @@  discard block
 block discarded – undo
395 424
 	// For our purposes, we're gonna want this on if at all possible.
396 425
 	$modSettings['cache_enable'] = '1';
397 426
 
398
-	if (($temp = cache_get_data('db_last_error', 600)) !== null)
399
-		$db_last_error = max($db_last_error, $temp);
427
+	if (($temp = cache_get_data('db_last_error', 600)) !== null) {
428
+			$db_last_error = max($db_last_error, $temp);
429
+	}
400 430
 
401 431
 	if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send))
402 432
 	{
403 433
 		// Avoid writing to the Settings.php file if at all possible; use shared memory instead.
404 434
 		cache_put_data('db_last_error', time(), 600);
405
-		if (($temp = cache_get_data('db_last_error', 600)) === null)
406
-			logLastDatabaseError();
435
+		if (($temp = cache_get_data('db_last_error', 600)) === null) {
436
+					logLastDatabaseError();
437
+		}
407 438
 
408 439
 		// Language files aren't loaded yet :(.
409 440
 		$db_error = @$smcFunc['db_error']($db_connection);
@@ -484,12 +515,14 @@  discard block
 block discarded – undo
484 515
 	global $smcFunc, $user_info, $modSettings;
485 516
 
486 517
 	// Don't bother if Who's Online is disabled.
487
-	if (empty($modSettings['who_enabled']))
488
-		return;
518
+	if (empty($modSettings['who_enabled'])) {
519
+			return;
520
+	}
489 521
 
490 522
 	// Maybe they came from SSI or similar where sessions are not recorded?
491
-	if (SMF == 'SSI' || SMF == 'BACKGROUND')
492
-		return;
523
+	if (SMF == 'SSI' || SMF == 'BACKGROUND') {
524
+			return;
525
+	}
493 526
 
494 527
 	$session_id = !empty($user_info['is_guest']) ? 'ip' . $user_info['ip'] : session_id();
495 528
 
@@ -515,8 +548,9 @@  discard block
 block discarded – undo
515 548
 		$url = $smcFunc['json_decode']($url, true);
516 549
 		$url['error'] = $error;
517 550
 
518
-		if (!empty($sprintf))
519
-			$url['error_params'] = $sprintf;
551
+		if (!empty($sprintf)) {
552
+					$url['error_params'] = $sprintf;
553
+		}
520 554
 
521 555
 		$smcFunc['db_query']('', '
522 556
 			UPDATE {db_prefix}log_online
@@ -547,10 +581,11 @@  discard block
 block discarded – undo
547 581
 
548 582
 	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
549 583
 
550
-	if (!isset($statuses[$code]))
551
-		header($protocol . ' 500 Internal Server Error');
552
-	else
553
-		header($protocol . ' ' . $code . ' ' . $statuses[$code]);
554
-}
584
+	if (!isset($statuses[$code])) {
585
+			header($protocol . ' 500 Internal Server Error');
586
+	} else {
587
+			header($protocol . ' ' . $code . ' ' . $statuses[$code]);
588
+	}
589
+	}
555 590
 
556 591
 ?>
557 592
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManageBans.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
  * Doesn't clean the inputs
930 930
  *
931 931
  * @param array $items_ids The items to remove
932
- * @param bool|int $group_id The ID of the group these triggers are associated with or false if deleting them from all groups
932
+ * @param integer $group_id The ID of the group these triggers are associated with or false if deleting them from all groups
933 933
  * @return bool Always returns true
934 934
  */
935 935
 function removeBanTriggers($items_ids = array(), $group_id = false)
@@ -1123,7 +1123,7 @@  discard block
 block discarded – undo
1123 1123
  * Errors in $context['ban_errors']
1124 1124
  *
1125 1125
  * @param array $triggers The triggers to validate
1126
- * @return array An array of riggers and log info ready to be used
1126
+ * @return integer An array of riggers and log info ready to be used
1127 1127
  */
1128 1128
 function validateTriggers(&$triggers)
1129 1129
 {
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
 		)
785 785
 	);
786 786
 	while ($row = $smcFunc['db_fetch_assoc']($request))
787
-	    $error_ips[] = inet_dtop($row['ip']);
787
+		$error_ips[] = inet_dtop($row['ip']);
788 788
 	$smcFunc['db_free_result']($request);
789 789
 
790 790
 	return $error_ips;
@@ -2168,9 +2168,9 @@  discard block
 block discarded – undo
2168 2168
 
2169 2169
 	if ($low == '255.255.255.255') return 'unknown';
2170 2170
 	if ($low == $high)
2171
-	    return $low;
2171
+		return $low;
2172 2172
 	else
2173
-	    return $low . '-' . $high;
2173
+		return $low . '-' . $high;
2174 2174
 }
2175 2175
 
2176 2176
 /**
Please login to merge, or discard this patch.
Braces   +258 added lines, -207 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
  * Ban center. The main entrance point for all ban center functions.
@@ -120,10 +121,11 @@  discard block
 block discarded – undo
120 121
 	}
121 122
 
122 123
 	// Create a date string so we don't overload them with date info.
123
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
124
-		$context['ban_time_format'] = $user_info['time_format'];
125
-	else
126
-		$context['ban_time_format'] = $matches[0];
124
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
125
+			$context['ban_time_format'] = $user_info['time_format'];
126
+	} else {
127
+			$context['ban_time_format'] = $matches[0];
128
+	}
127 129
 
128 130
 	$listOptions = array(
129 131
 		'id' => 'ban_list',
@@ -201,16 +203,19 @@  discard block
 block discarded – undo
201 203
 					'function' => function($rowData) use ($txt)
202 204
 					{
203 205
 						// This ban never expires...whahaha.
204
-						if ($rowData['expire_time'] === null)
205
-							return $txt['never'];
206
+						if ($rowData['expire_time'] === null) {
207
+													return $txt['never'];
208
+						}
206 209
 
207 210
 						// This ban has already expired.
208
-						elseif ($rowData['expire_time'] < time())
209
-							return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']);
211
+						elseif ($rowData['expire_time'] < time()) {
212
+													return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']);
213
+						}
210 214
 
211 215
 						// Still need to wait a few days for this ban to expire.
212
-						else
213
-							return sprintf('%1$d&nbsp;%2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']);
216
+						else {
217
+													return sprintf('%1$d&nbsp;%2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']);
218
+						}
214 219
 					},
215 220
 				),
216 221
 				'sort' => array(
@@ -309,8 +314,9 @@  discard block
 block discarded – undo
309 314
 		)
310 315
 	);
311 316
 	$bans = array();
312
-	while ($row = $smcFunc['db_fetch_assoc']($request))
313
-		$bans[] = $row;
317
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
318
+			$bans[] = $row;
319
+	}
314 320
 
315 321
 	$smcFunc['db_free_result']($request);
316 322
 
@@ -352,8 +358,9 @@  discard block
 block discarded – undo
352 358
 {
353 359
 	global $txt, $modSettings, $context, $scripturl, $smcFunc, $sourcedir;
354 360
 
355
-	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors']))
356
-		BanEdit2();
361
+	if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) {
362
+			BanEdit2();
363
+	}
357 364
 
358 365
 	$ban_group_id = isset($context['ban']['id']) ? $context['ban']['id'] : (isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0);
359 366
 
@@ -364,10 +371,10 @@  discard block
 block discarded – undo
364 371
 
365 372
 	if (!empty($context['ban_errors']))
366 373
 	{
367
-		foreach ($context['ban_errors'] as $error)
368
-			$context['error_messages'][$error] = $txt[$error];
369
-	}
370
-	else
374
+		foreach ($context['ban_errors'] as $error) {
375
+					$context['error_messages'][$error] = $txt[$error];
376
+		}
377
+	} else
371 378
 	{
372 379
 		// If we're editing an existing ban, get it from the database.
373 380
 		if (!empty($ban_group_id))
@@ -403,12 +410,13 @@  discard block
 block discarded – undo
403 410
 						'data' => array(
404 411
 							'function' => function($ban_item) use ($txt)
405 412
 							{
406
-								if (in_array($ban_item['type'], array('ip', 'hostname', 'email')))
407
-									return '<strong>' . $txt[$ban_item['type']] . ':</strong>&nbsp;' . $ban_item[$ban_item['type']];
408
-								elseif ($ban_item['type'] == 'user')
409
-									return '<strong>' . $txt['username'] . ':</strong>&nbsp;' . $ban_item['user']['link'];
410
-								else
411
-									return '<strong>' . $txt['unknown'] . ':</strong>&nbsp;' . $ban_item['no_bantype_selected'];
413
+								if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) {
414
+																	return '<strong>' . $txt[$ban_item['type']] . ':</strong>&nbsp;' . $ban_item[$ban_item['type']];
415
+								} elseif ($ban_item['type'] == 'user') {
416
+																	return '<strong>' . $txt['username'] . ':</strong>&nbsp;' . $ban_item['user']['link'];
417
+								} else {
418
+																	return '<strong>' . $txt['unknown'] . ':</strong>&nbsp;' . $ban_item['no_bantype_selected'];
419
+								}
412 420
 							},
413 421
 							'style' => 'text-align: left;',
414 422
 						),
@@ -546,8 +554,9 @@  discard block
 block discarded – undo
546 554
 					$context['ban']['from_user'] = true;
547 555
 
548 556
 					// Would be nice if we could also ban the hostname.
549
-					if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup']))
550
-						$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
557
+					if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) {
558
+											$context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
559
+					}
551 560
 
552 561
 					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
553 562
 				}
@@ -615,8 +624,9 @@  discard block
 block discarded – undo
615 624
 			'items_per_page' => $items_per_page,
616 625
 		)
617 626
 	);
618
-	if ($smcFunc['db_num_rows']($request) == 0)
619
-		fatal_lang_error('ban_not_found', false);
627
+	if ($smcFunc['db_num_rows']($request) == 0) {
628
+			fatal_lang_error('ban_not_found', false);
629
+	}
620 630
 
621 631
 	while ($row = $smcFunc['db_fetch_assoc']($request))
622 632
 	{
@@ -653,18 +663,15 @@  discard block
 block discarded – undo
653 663
 			{
654 664
 				$ban_items[$row['id_ban']]['type'] = 'ip';
655 665
 				$ban_items[$row['id_ban']]['ip'] = range2ip($row['ip_low'], $row['ip_high']);
656
-			}
657
-			elseif (!empty($row['hostname']))
666
+			} elseif (!empty($row['hostname']))
658 667
 			{
659 668
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
660 669
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
661
-			}
662
-			elseif (!empty($row['email_address']))
670
+			} elseif (!empty($row['email_address']))
663 671
 			{
664 672
 				$ban_items[$row['id_ban']]['type'] = 'email';
665 673
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
666
-			}
667
-			elseif (!empty($row['id_member']))
674
+			} elseif (!empty($row['id_member']))
668 675
 			{
669 676
 				$ban_items[$row['id_ban']]['type'] = 'user';
670 677
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -730,9 +737,10 @@  discard block
 block discarded – undo
730 737
 	$search_list += array('ips_in_messages' => 'banLoadAdditionalIPsMember', 'ips_in_errors' => 'banLoadAdditionalIPsError');
731 738
 
732 739
 	$return = array();
733
-	foreach ($search_list as $key => $callable)
734
-		if (is_callable($callable))
740
+	foreach ($search_list as $key => $callable) {
741
+			if (is_callable($callable))
735 742
 			$return[$key] = call_user_func($callable, $member_id);
743
+	}
736 744
 
737 745
 	return $return;
738 746
 }
@@ -757,8 +765,9 @@  discard block
 block discarded – undo
757 765
 			'current_user' => $member_id,
758 766
 		)
759 767
 	);
760
-	while ($row = $smcFunc['db_fetch_assoc']($request))
761
-		$message_ips[] = inet_dtop($row['poster_ip']);
768
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
769
+			$message_ips[] = inet_dtop($row['poster_ip']);
770
+	}
762 771
 	$smcFunc['db_free_result']($request);
763 772
 
764 773
 	return $message_ips;
@@ -783,8 +792,9 @@  discard block
 block discarded – undo
783 792
 			'current_user' => $member_id,
784 793
 		)
785 794
 	);
786
-	while ($row = $smcFunc['db_fetch_assoc']($request))
787
-	    $error_ips[] = inet_dtop($row['ip']);
795
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
796
+		    $error_ips[] = inet_dtop($row['ip']);
797
+	}
788 798
 	$smcFunc['db_free_result']($request);
789 799
 
790 800
 	return $error_ips;
@@ -825,11 +835,13 @@  discard block
 block discarded – undo
825 835
 		$ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1;
826 836
 
827 837
 		// Adding a new ban group
828
-		if (empty($_REQUEST['bg']))
829
-			$ban_group_id = insertBanGroup($ban_info);
838
+		if (empty($_REQUEST['bg'])) {
839
+					$ban_group_id = insertBanGroup($ban_info);
840
+		}
830 841
 		// Editing an existing ban group
831
-		else
832
-			$ban_group_id = updateBanGroup($ban_info);
842
+		else {
843
+					$ban_group_id = updateBanGroup($ban_info);
844
+		}
833 845
 
834 846
 		if (is_numeric($ban_group_id))
835 847
 		{
@@ -840,9 +852,10 @@  discard block
 block discarded – undo
840 852
 		$context['ban'] = $ban_info;
841 853
 	}
842 854
 
843
-	if (isset($_POST['ban_suggestions']))
844
-		// @TODO: is $_REQUEST['bi'] ever set?
855
+	if (isset($_POST['ban_suggestions'])) {
856
+			// @TODO: is $_REQUEST['bi'] ever set?
845 857
 		$saved_triggers = saveTriggers($_POST['ban_suggestions'], $ban_info['id'], isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0);
858
+	}
846 859
 
847 860
 	// Something went wrong somewhere... Oh well, let's go back.
848 861
 	if (!empty($context['ban_errors']))
@@ -852,8 +865,9 @@  discard block
 block discarded – undo
852 865
 		$context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u']));
853 866
 
854 867
 		// Not strictly necessary, but it's nice
855
-		if (!empty($context['ban_suggestions']['member']['id']))
856
-			$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
868
+		if (!empty($context['ban_suggestions']['member']['id'])) {
869
+					$context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
870
+		}
857 871
 		return BanEdit();
858 872
 	}
859 873
 	$context['ban_suggestions']['saved_triggers'] = !empty($saved_triggers) ? $saved_triggers : array();
@@ -900,10 +914,11 @@  discard block
 block discarded – undo
900 914
 
901 915
 	foreach ($suggestions as $key => $value)
902 916
 	{
903
-		if (is_array($value))
904
-			$triggers[$key] = $value;
905
-		else
906
-			$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
917
+		if (is_array($value)) {
918
+					$triggers[$key] = $value;
919
+		} else {
920
+					$triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : '';
921
+		}
907 922
 	}
908 923
 
909 924
 	$ban_triggers = validateTriggers($triggers);
@@ -911,16 +926,18 @@  discard block
 block discarded – undo
911 926
 	// Time to save!
912 927
 	if (!empty($ban_triggers['ban_triggers']) && empty($context['ban_errors']))
913 928
 	{
914
-		if (empty($ban_id))
915
-			addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
916
-		else
917
-			updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
929
+		if (empty($ban_id)) {
930
+					addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']);
931
+		} else {
932
+					updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']);
933
+		}
934
+	}
935
+	if (!empty($context['ban_errors'])) {
936
+			return $triggers;
937
+	} else {
938
+			return false;
939
+	}
918 940
 	}
919
-	if (!empty($context['ban_errors']))
920
-		return $triggers;
921
-	else
922
-		return false;
923
-}
924 941
 
925 942
 /**
926 943
  * This function removes a bunch of triggers based on ids
@@ -934,14 +951,17 @@  discard block
 block discarded – undo
934 951
 {
935 952
 	global $smcFunc, $scripturl;
936 953
 
937
-	if ($group_id !== false)
938
-		$group_id = (int) $group_id;
954
+	if ($group_id !== false) {
955
+			$group_id = (int) $group_id;
956
+	}
939 957
 
940
-	if (empty($group_id) && empty($items_ids))
941
-		return false;
958
+	if (empty($group_id) && empty($items_ids)) {
959
+			return false;
960
+	}
942 961
 
943
-	if (!is_array($items_ids))
944
-		$items_ids = array($items_ids);
962
+	if (!is_array($items_ids)) {
963
+			$items_ids = array($items_ids);
964
+	}
945 965
 
946 966
 	$log_info = array();
947 967
 	$ban_items = array();
@@ -979,8 +999,7 @@  discard block
 block discarded – undo
979 999
 					'bantype' => ($is_range ? 'ip_range' : 'main_ip'),
980 1000
 					'value' => $ban_items[$row['id_ban']]['ip'],
981 1001
 				);
982
-			}
983
-			elseif (!empty($row['hostname']))
1002
+			} elseif (!empty($row['hostname']))
984 1003
 			{
985 1004
 				$ban_items[$row['id_ban']]['type'] = 'hostname';
986 1005
 				$ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
@@ -988,8 +1007,7 @@  discard block
 block discarded – undo
988 1007
 					'bantype' => 'hostname',
989 1008
 					'value' => $row['hostname'],
990 1009
 				);
991
-			}
992
-			elseif (!empty($row['email_address']))
1010
+			} elseif (!empty($row['email_address']))
993 1011
 			{
994 1012
 				$ban_items[$row['id_ban']]['type'] = 'email';
995 1013
 				$ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
@@ -997,8 +1015,7 @@  discard block
 block discarded – undo
997 1015
 					'bantype' => 'email',
998 1016
 					'value' => $ban_items[$row['id_ban']]['email'],
999 1017
 				);
1000
-			}
1001
-			elseif (!empty($row['id_member']))
1018
+			} elseif (!empty($row['id_member']))
1002 1019
 			{
1003 1020
 				$ban_items[$row['id_ban']]['type'] = 'user';
1004 1021
 				$ban_items[$row['id_ban']]['user'] = array(
@@ -1031,8 +1048,7 @@  discard block
 block discarded – undo
1031 1048
 				'ban_group' => $group_id,
1032 1049
 			)
1033 1050
 		);
1034
-	}
1035
-	elseif (!empty($items_ids))
1051
+	} elseif (!empty($items_ids))
1036 1052
 	{
1037 1053
 		$smcFunc['db_query']('', '
1038 1054
 			DELETE FROM {db_prefix}ban_items
@@ -1057,13 +1073,15 @@  discard block
 block discarded – undo
1057 1073
 {
1058 1074
 	global $smcFunc;
1059 1075
 
1060
-	if (!is_array($group_ids))
1061
-		$group_ids = array($group_ids);
1076
+	if (!is_array($group_ids)) {
1077
+			$group_ids = array($group_ids);
1078
+	}
1062 1079
 
1063 1080
 	$group_ids = array_unique($group_ids);
1064 1081
 
1065
-	if (empty($group_ids))
1066
-		return false;
1082
+	if (empty($group_ids)) {
1083
+			return false;
1084
+	}
1067 1085
 
1068 1086
 	$smcFunc['db_query']('', '
1069 1087
 		DELETE FROM {db_prefix}ban_groups
@@ -1087,21 +1105,23 @@  discard block
 block discarded – undo
1087 1105
 {
1088 1106
 	global $smcFunc;
1089 1107
 
1090
-	if (empty($ids))
1091
-		$smcFunc['db_query']('truncate_table', '
1108
+	if (empty($ids)) {
1109
+			$smcFunc['db_query']('truncate_table', '
1092 1110
 			TRUNCATE {db_prefix}log_banned',
1093 1111
 			array(
1094 1112
 			)
1095 1113
 		);
1096
-	else
1114
+	} else
1097 1115
 	{
1098
-		if (!is_array($ids))
1099
-			$ids = array($ids);
1116
+		if (!is_array($ids)) {
1117
+					$ids = array($ids);
1118
+		}
1100 1119
 
1101 1120
 		$ids = array_unique($ids);
1102 1121
 
1103
-		if (empty($ids))
1104
-			return false;
1122
+		if (empty($ids)) {
1123
+					return false;
1124
+		}
1105 1125
 
1106 1126
 		$smcFunc['db_query']('', '
1107 1127
 			DELETE FROM {db_prefix}log_banned
@@ -1127,8 +1147,9 @@  discard block
 block discarded – undo
1127 1147
 {
1128 1148
 	global $context, $smcFunc;
1129 1149
 
1130
-	if (empty($triggers))
1131
-		$context['ban_erros'][] = 'ban_empty_triggers';
1150
+	if (empty($triggers)) {
1151
+			$context['ban_erros'][] = 'ban_empty_triggers';
1152
+	}
1132 1153
 
1133 1154
 	$ban_triggers = array();
1134 1155
 	$log_info = array();
@@ -1137,39 +1158,39 @@  discard block
 block discarded – undo
1137 1158
 	{
1138 1159
 		if (!empty($value))
1139 1160
 		{
1140
-			if ($key == 'member')
1141
-				continue;
1161
+			if ($key == 'member') {
1162
+							continue;
1163
+			}
1142 1164
 
1143 1165
 			if ($key == 'main_ip')
1144 1166
 			{
1145 1167
 				$value = trim($value);
1146 1168
 				$ip_parts = ip2range($value);
1147
-				if (!checkExistingTriggerIP($ip_parts, $value))
1148
-					$context['ban_erros'][] = 'invalid_ip';
1149
-				else
1169
+				if (!checkExistingTriggerIP($ip_parts, $value)) {
1170
+									$context['ban_erros'][] = 'invalid_ip';
1171
+				} else
1150 1172
 				{
1151 1173
 					$ban_triggers['main_ip'] = array(
1152 1174
 						'ip_low' => $ip_parts['low'],
1153 1175
 						'ip_high' => $ip_parts['high']
1154 1176
 					);
1155 1177
 				}
1156
-			}
1157
-			elseif ($key == 'hostname')
1178
+			} elseif ($key == 'hostname')
1158 1179
 			{
1159
-				if (preg_match('/[^\w.\-*]/', $value) == 1)
1160
-					$context['ban_erros'][] = 'invalid_hostname';
1161
-				else
1180
+				if (preg_match('/[^\w.\-*]/', $value) == 1) {
1181
+									$context['ban_erros'][] = 'invalid_hostname';
1182
+				} else
1162 1183
 				{
1163 1184
 					// Replace the * wildcard by a MySQL wildcard %.
1164 1185
 					$value = substr(str_replace('*', '%', $value), 0, 255);
1165 1186
 
1166 1187
 					$ban_triggers['hostname']['hostname'] = $value;
1167 1188
 				}
1168
-			}
1169
-			elseif ($key == 'email')
1189
+			} elseif ($key == 'email')
1170 1190
 			{
1171
-				if (preg_match('/[^\w.\-\+*@]/', $value) == 1)
1172
-					$context['ban_erros'][] = 'invalid_email';
1191
+				if (preg_match('/[^\w.\-\+*@]/', $value) == 1) {
1192
+									$context['ban_erros'][] = 'invalid_email';
1193
+				}
1173 1194
 
1174 1195
 				// Check the user is not banning an admin.
1175 1196
 				$request = $smcFunc['db_query']('', '
@@ -1183,15 +1204,15 @@  discard block
 block discarded – undo
1183 1204
 						'email' => $value,
1184 1205
 					)
1185 1206
 				);
1186
-				if ($smcFunc['db_num_rows']($request) != 0)
1187
-					$context['ban_erros'][] = 'no_ban_admin';
1207
+				if ($smcFunc['db_num_rows']($request) != 0) {
1208
+									$context['ban_erros'][] = 'no_ban_admin';
1209
+				}
1188 1210
 				$smcFunc['db_free_result']($request);
1189 1211
 
1190 1212
 				$value = substr(strtolower(str_replace('*', '%', $value)), 0, 255);
1191 1213
 
1192 1214
 				$ban_triggers['email']['email_address'] = $value;
1193
-			}
1194
-			elseif ($key == 'user')
1215
+			} elseif ($key == 'user')
1195 1216
 			{
1196 1217
 				$user = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($value, ENT_QUOTES));
1197 1218
 
@@ -1205,8 +1226,9 @@  discard block
 block discarded – undo
1205 1226
 						'username' => $user,
1206 1227
 					)
1207 1228
 				);
1208
-				if ($smcFunc['db_num_rows']($request) == 0)
1209
-					$context['ban_erros'][] = 'invalid_username';
1229
+				if ($smcFunc['db_num_rows']($request) == 0) {
1230
+									$context['ban_erros'][] = 'invalid_username';
1231
+				}
1210 1232
 				list ($value, $isAdmin) = $smcFunc['db_fetch_row']($request);
1211 1233
 				$smcFunc['db_free_result']($request);
1212 1234
 
@@ -1214,25 +1236,25 @@  discard block
 block discarded – undo
1214 1236
 				{
1215 1237
 					unset($value);
1216 1238
 					$context['ban_erros'][] = 'no_ban_admin';
1239
+				} else {
1240
+									$ban_triggers['user']['id_member'] = $value;
1217 1241
 				}
1218
-				else
1219
-					$ban_triggers['user']['id_member'] = $value;
1220
-			}
1221
-			elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1242
+			} elseif (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1222 1243
 			{
1223 1244
 				// Special case, those two are arrays themselves
1224 1245
 				$values = array_unique($value);
1225 1246
 				// Don't add the main IP again.
1226
-				if (isset($triggers['main_ip']))
1227
-					$values = array_diff($values, array($triggers['main_ip']));
1247
+				if (isset($triggers['main_ip'])) {
1248
+									$values = array_diff($values, array($triggers['main_ip']));
1249
+				}
1228 1250
 				unset($value);
1229 1251
 				foreach ($values as $val)
1230 1252
 				{
1231 1253
 					$val = trim($val);
1232 1254
 					$ip_parts = ip2range($val);
1233
-					if (!checkExistingTriggerIP($ip_parts, $val))
1234
-						$context['ban_erros'][] = 'invalid_ip';
1235
-					else
1255
+					if (!checkExistingTriggerIP($ip_parts, $val)) {
1256
+											$context['ban_erros'][] = 'invalid_ip';
1257
+					} else
1236 1258
 					{
1237 1259
 						$ban_triggers[$key][] = array(
1238 1260
 							'ip_low' => $ip_parts['low'],
@@ -1245,15 +1267,16 @@  discard block
 block discarded – undo
1245 1267
 						);
1246 1268
 					}
1247 1269
 				}
1270
+			} else {
1271
+							$context['ban_erros'][] = 'no_bantype_selected';
1248 1272
 			}
1249
-			else
1250
-				$context['ban_erros'][] = 'no_bantype_selected';
1251 1273
 
1252
-			if (isset($value) && !is_array($value))
1253
-				$log_info[] = array(
1274
+			if (isset($value) && !is_array($value)) {
1275
+							$log_info[] = array(
1254 1276
 					'value' => $value,
1255 1277
 					'bantype' => $key,
1256 1278
 				);
1279
+			}
1257 1280
 		}
1258 1281
 	}
1259 1282
 	return array('ban_triggers' => $ban_triggers, 'log_info' => $log_info);
@@ -1273,8 +1296,9 @@  discard block
 block discarded – undo
1273 1296
 {
1274 1297
 	global $smcFunc, $context;
1275 1298
 
1276
-	if (empty($group_id))
1277
-		$context['ban_errors'][] = 'ban_id_empty';
1299
+	if (empty($group_id)) {
1300
+			$context['ban_errors'][] = 'ban_id_empty';
1301
+	}
1278 1302
 
1279 1303
 	// Preset all values that are required.
1280 1304
 	$values = array(
@@ -1299,18 +1323,21 @@  discard block
 block discarded – undo
1299 1323
 	foreach ($triggers as $key => $trigger)
1300 1324
 	{
1301 1325
 		// Exceptions, exceptions, exceptions...always exceptions... :P
1302
-		if (in_array($key, array('ips_in_messages', 'ips_in_errors')))
1303
-			foreach ($trigger as $real_trigger)
1326
+		if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) {
1327
+					foreach ($trigger as $real_trigger)
1304 1328
 				$insertTriggers[] = array_merge($values, $real_trigger);
1305
-		else
1306
-			$insertTriggers[] = array_merge($values, $trigger);
1329
+		} else {
1330
+					$insertTriggers[] = array_merge($values, $trigger);
1331
+		}
1307 1332
 	}
1308 1333
 
1309
-	if (empty($insertTriggers))
1310
-		$context['ban_errors'][] = 'ban_no_triggers';
1334
+	if (empty($insertTriggers)) {
1335
+			$context['ban_errors'][] = 'ban_no_triggers';
1336
+	}
1311 1337
 
1312
-	if (!empty($context['ban_errors']))
1313
-		return false;
1338
+	if (!empty($context['ban_errors'])) {
1339
+			return false;
1340
+	}
1314 1341
 
1315 1342
 	$smcFunc['db_insert']('',
1316 1343
 		'{db_prefix}ban_items',
@@ -1338,15 +1365,19 @@  discard block
 block discarded – undo
1338 1365
 {
1339 1366
 	global $smcFunc, $context;
1340 1367
 
1341
-	if (empty($ban_item))
1342
-		$context['ban_errors'][] = 'ban_ban_item_empty';
1343
-	if (empty($group_id))
1344
-		$context['ban_errors'][] = 'ban_id_empty';
1345
-	if (empty($trigger))
1346
-		$context['ban_errors'][] = 'ban_no_triggers';
1368
+	if (empty($ban_item)) {
1369
+			$context['ban_errors'][] = 'ban_ban_item_empty';
1370
+	}
1371
+	if (empty($group_id)) {
1372
+			$context['ban_errors'][] = 'ban_id_empty';
1373
+	}
1374
+	if (empty($trigger)) {
1375
+			$context['ban_errors'][] = 'ban_no_triggers';
1376
+	}
1347 1377
 
1348
-	if (!empty($context['ban_errors']))
1349
-		return;
1378
+	if (!empty($context['ban_errors'])) {
1379
+			return;
1380
+	}
1350 1381
 
1351 1382
 	// Preset all values that are required.
1352 1383
 	$values = array(
@@ -1387,8 +1418,9 @@  discard block
 block discarded – undo
1387 1418
  */
1388 1419
 function logTriggersUpdates($logs, $new = true, $removal = false)
1389 1420
 {
1390
-	if (empty($logs))
1391
-		return;
1421
+	if (empty($logs)) {
1422
+			return;
1423
+	}
1392 1424
 
1393 1425
 	$log_name_map = array(
1394 1426
 		'main_ip' => 'ip_range',
@@ -1399,14 +1431,15 @@  discard block
 block discarded – undo
1399 1431
 	);
1400 1432
 
1401 1433
 	// Log the addion of the ban entries into the moderation log.
1402
-	foreach ($logs as $log)
1403
-		logAction('ban' . ($removal == true ? 'remove' : ''), array(
1434
+	foreach ($logs as $log) {
1435
+			logAction('ban' . ($removal == true ? 'remove' : ''), array(
1404 1436
 			$log_name_map[$log['bantype']] => $log['value'],
1405 1437
 			'new' => empty($new) ? 0 : 1,
1406 1438
 			'remove' => empty($removal) ? 0 : 1,
1407 1439
 			'type' => $log['bantype'],
1408 1440
 		));
1409
-}
1441
+	}
1442
+	}
1410 1443
 
1411 1444
 /**
1412 1445
  * Updates an existing ban group
@@ -1420,12 +1453,15 @@  discard block
 block discarded – undo
1420 1453
 {
1421 1454
 	global $smcFunc, $context;
1422 1455
 
1423
-	if (empty($ban_info['name']))
1424
-		$context['ban_errors'][] = 'ban_name_empty';
1425
-	if (empty($ban_info['id']))
1426
-		$context['ban_errors'][] = 'ban_id_empty';
1427
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1428
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1456
+	if (empty($ban_info['name'])) {
1457
+			$context['ban_errors'][] = 'ban_name_empty';
1458
+	}
1459
+	if (empty($ban_info['id'])) {
1460
+			$context['ban_errors'][] = 'ban_id_empty';
1461
+	}
1462
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1463
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1464
+	}
1429 1465
 
1430 1466
 	if (!empty($ban_info['id']))
1431 1467
 	{
@@ -1440,8 +1476,9 @@  discard block
 block discarded – undo
1440 1476
 			)
1441 1477
 		);
1442 1478
 
1443
-		if ($smcFunc['db_num_rows']($request) == 0)
1444
-			$context['ban_errors'][] = 'ban_not_found';
1479
+		if ($smcFunc['db_num_rows']($request) == 0) {
1480
+					$context['ban_errors'][] = 'ban_not_found';
1481
+		}
1445 1482
 		$smcFunc['db_free_result']($request);
1446 1483
 	}
1447 1484
 
@@ -1459,13 +1496,15 @@  discard block
 block discarded – undo
1459 1496
 				'new_ban_name' => $ban_info['name'],
1460 1497
 			)
1461 1498
 		);
1462
-		if ($smcFunc['db_num_rows']($request) != 0)
1463
-			$context['ban_errors'][] = 'ban_name_exists';
1499
+		if ($smcFunc['db_num_rows']($request) != 0) {
1500
+					$context['ban_errors'][] = 'ban_name_exists';
1501
+		}
1464 1502
 		$smcFunc['db_free_result']($request);
1465 1503
 	}
1466 1504
 
1467
-	if (!empty($context['ban_errors']))
1468
-		return $ban_info['id'];
1505
+	if (!empty($context['ban_errors'])) {
1506
+			return $ban_info['id'];
1507
+	}
1469 1508
 
1470 1509
 	$smcFunc['db_query']('', '
1471 1510
 		UPDATE {db_prefix}ban_groups
@@ -1509,10 +1548,12 @@  discard block
 block discarded – undo
1509 1548
 {
1510 1549
 	global $smcFunc, $context;
1511 1550
 
1512
-	if (empty($ban_info['name']))
1513
-		$context['ban_errors'][] = 'ban_name_empty';
1514
-	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login']))
1515
-		$context['ban_errors'][] = 'ban_unknown_restriction_type';
1551
+	if (empty($ban_info['name'])) {
1552
+			$context['ban_errors'][] = 'ban_name_empty';
1553
+	}
1554
+	if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) {
1555
+			$context['ban_errors'][] = 'ban_unknown_restriction_type';
1556
+	}
1516 1557
 
1517 1558
 	if (!empty($ban_info['name']))
1518 1559
 	{
@@ -1527,13 +1568,15 @@  discard block
 block discarded – undo
1527 1568
 			)
1528 1569
 		);
1529 1570
 
1530
-		if ($smcFunc['db_num_rows']($request) == 1)
1531
-			$context['ban_errors'][] = 'ban_name_exists';
1571
+		if ($smcFunc['db_num_rows']($request) == 1) {
1572
+					$context['ban_errors'][] = 'ban_name_exists';
1573
+		}
1532 1574
 		$smcFunc['db_free_result']($request);
1533 1575
 	}
1534 1576
 
1535
-	if (!empty($context['ban_errors']))
1536
-		return;
1577
+	if (!empty($context['ban_errors'])) {
1578
+			return;
1579
+	}
1537 1580
 
1538 1581
 	// Yes yes, we're ready to add now.
1539 1582
 	$ban_info['id'] = $smcFunc['db_insert']('',
@@ -1550,8 +1593,9 @@  discard block
 block discarded – undo
1550 1593
 		1
1551 1594
 	);
1552 1595
 
1553
-	if (empty($ban_info['id']))
1554
-		$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1596
+	if (empty($ban_info['id'])) {
1597
+			$context['ban_errors'][] = 'impossible_insert_new_bangroup';
1598
+	}
1555 1599
 
1556 1600
 	return $ban_info['id'];
1557 1601
 }
@@ -1576,24 +1620,24 @@  discard block
 block discarded – undo
1576 1620
 	$ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;
1577 1621
 	$ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0;
1578 1622
 
1579
-	if (empty($ban_group))
1580
-		fatal_lang_error('ban_not_found', false);
1623
+	if (empty($ban_group)) {
1624
+			fatal_lang_error('ban_not_found', false);
1625
+	}
1581 1626
 
1582 1627
 	if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions']))
1583 1628
 	{
1584 1629
 		saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id);
1585 1630
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1586
-	}
1587
-	elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1631
+	} elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions']))
1588 1632
 	{
1589 1633
 		// The first replaces the old one, the others are added new (simplification, otherwise it would require another query and some work...)
1590 1634
 		saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id);
1591
-		if (!empty($_POST['ban_suggestions']))
1592
-			saveTriggers($_POST['ban_suggestions'], $ban_group);
1635
+		if (!empty($_POST['ban_suggestions'])) {
1636
+					saveTriggers($_POST['ban_suggestions'], $ban_group);
1637
+		}
1593 1638
 
1594 1639
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
1595
-	}
1596
-	elseif (isset($_POST['edit_trigger']))
1640
+	} elseif (isset($_POST['edit_trigger']))
1597 1641
 	{
1598 1642
 		removeBanTriggers($ban_id);
1599 1643
 		redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
@@ -1624,8 +1668,7 @@  discard block
 block discarded – undo
1624 1668
 			),
1625 1669
 			'is_new' => true,
1626 1670
 		);
1627
-	}
1628
-	else
1671
+	} else
1629 1672
 	{
1630 1673
 		$request = $smcFunc['db_query']('', '
1631 1674
 			SELECT
@@ -1642,8 +1685,9 @@  discard block
 block discarded – undo
1642 1685
 				'ban_group' => $ban_group,
1643 1686
 			)
1644 1687
 		);
1645
-		if ($smcFunc['db_num_rows']($request) == 0)
1646
-			fatal_lang_error('ban_not_found', false);
1688
+		if ($smcFunc['db_num_rows']($request) == 0) {
1689
+					fatal_lang_error('ban_not_found', false);
1690
+		}
1647 1691
 		$row = $smcFunc['db_fetch_assoc']($request);
1648 1692
 		$smcFunc['db_free_result']($request);
1649 1693
 
@@ -1692,8 +1736,9 @@  discard block
 block discarded – undo
1692 1736
 		removeBanTriggers($_POST['remove']);
1693 1737
 
1694 1738
 		// Rehabilitate some members.
1695
-		if ($_REQUEST['entity'] == 'member')
1696
-			updateBanMembers();
1739
+		if ($_REQUEST['entity'] == 'member') {
1740
+					updateBanMembers();
1741
+		}
1697 1742
 
1698 1743
 		// Make sure the ban cache is refreshed.
1699 1744
 		updateSettings(array('banLastUpdated' => time()));
@@ -1806,8 +1851,7 @@  discard block
 block discarded – undo
1806 1851
 			'default' => 'bi.ip_low, bi.ip_high, bi.ip_low',
1807 1852
 			'reverse' => 'bi.ip_low DESC, bi.ip_high DESC',
1808 1853
 		);
1809
-	}
1810
-	elseif ($context['selected_entity'] === 'hostname')
1854
+	} elseif ($context['selected_entity'] === 'hostname')
1811 1855
 	{
1812 1856
 		$listOptions['columns']['banned_entity']['data'] = array(
1813 1857
 			'function' => function($rowData) use ($smcFunc)
@@ -1819,8 +1863,7 @@  discard block
 block discarded – undo
1819 1863
 			'default' => 'bi.hostname',
1820 1864
 			'reverse' => 'bi.hostname DESC',
1821 1865
 		);
1822
-	}
1823
-	elseif ($context['selected_entity'] === 'email')
1866
+	} elseif ($context['selected_entity'] === 'email')
1824 1867
 	{
1825 1868
 		$listOptions['columns']['banned_entity']['data'] = array(
1826 1869
 			'function' => function($rowData) use ($smcFunc)
@@ -1832,8 +1875,7 @@  discard block
 block discarded – undo
1832 1875
 			'default' => 'bi.email_address',
1833 1876
 			'reverse' => 'bi.email_address DESC',
1834 1877
 		);
1835
-	}
1836
-	elseif ($context['selected_entity'] === 'member')
1878
+	} elseif ($context['selected_entity'] === 'member')
1837 1879
 	{
1838 1880
 		$listOptions['columns']['banned_entity']['data'] = array(
1839 1881
 			'sprintf' => array(
@@ -1897,8 +1939,9 @@  discard block
 block discarded – undo
1897 1939
 		)
1898 1940
 	);
1899 1941
 	$ban_triggers = array();
1900
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1901
-		$ban_triggers[] = $row;
1942
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1943
+			$ban_triggers[] = $row;
1944
+	}
1902 1945
 	$smcFunc['db_free_result']($request);
1903 1946
 
1904 1947
 	return $ban_triggers;
@@ -1954,8 +1997,9 @@  discard block
 block discarded – undo
1954 1997
 		validateToken('admin-bl');
1955 1998
 
1956 1999
 		// 'Delete all entries' button was pressed.
1957
-		if (!empty($_POST['removeAll']))
1958
-			removeBanLogs();
2000
+		if (!empty($_POST['removeAll'])) {
2001
+					removeBanLogs();
2002
+		}
1959 2003
 		// 'Delete selection' button was pressed.
1960 2004
 		else
1961 2005
 		{
@@ -2164,12 +2208,15 @@  discard block
 block discarded – undo
2164 2208
 	$low = inet_dtop($low);
2165 2209
 	$high = inet_dtop($high);
2166 2210
 
2167
-	if ($low == '255.255.255.255') return 'unknown';
2168
-	if ($low == $high)
2169
-	    return $low;
2170
-	else
2171
-	    return $low . '-' . $high;
2172
-}
2211
+	if ($low == '255.255.255.255') {
2212
+		return 'unknown';
2213
+	}
2214
+	if ($low == $high) {
2215
+		    return $low;
2216
+	} else {
2217
+		    return $low . '-' . $high;
2218
+	}
2219
+	}
2173 2220
 
2174 2221
 /**
2175 2222
  * Checks whether a given IP range already exists in the trigger list.
@@ -2245,15 +2292,17 @@  discard block
 block discarded – undo
2245 2292
 	$memberEmailWild = array();
2246 2293
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2247 2294
 	{
2248
-		if ($row['id_member'])
2249
-			$memberIDs[$row['id_member']] = $row['id_member'];
2295
+		if ($row['id_member']) {
2296
+					$memberIDs[$row['id_member']] = $row['id_member'];
2297
+		}
2250 2298
 		if ($row['email_address'])
2251 2299
 		{
2252 2300
 			// Does it have a wildcard - if so we can't do a IN on it.
2253
-			if (strpos($row['email_address'], '%') !== false)
2254
-				$memberEmailWild[$row['email_address']] = $row['email_address'];
2255
-			else
2256
-				$memberEmails[$row['email_address']] = $row['email_address'];
2301
+			if (strpos($row['email_address'], '%') !== false) {
2302
+							$memberEmailWild[$row['email_address']] = $row['email_address'];
2303
+			} else {
2304
+							$memberEmails[$row['email_address']] = $row['email_address'];
2305
+			}
2257 2306
 		}
2258 2307
 	}
2259 2308
 	$smcFunc['db_free_result']($request);
@@ -2304,14 +2353,15 @@  discard block
 block discarded – undo
2304 2353
 	}
2305 2354
 
2306 2355
 	// We welcome our new members in the realm of the banned.
2307
-	if (!empty($newMembers))
2308
-		$smcFunc['db_query']('', '
2356
+	if (!empty($newMembers)) {
2357
+			$smcFunc['db_query']('', '
2309 2358
 			DELETE FROM {db_prefix}log_online
2310 2359
 			WHERE id_member IN ({array_int:new_banned_members})',
2311 2360
 			array(
2312 2361
 				'new_banned_members' => $newMembers,
2313 2362
 			)
2314 2363
 		);
2364
+	}
2315 2365
 
2316 2366
 	// Find members that are wrongfully marked as banned.
2317 2367
 	$request = $smcFunc['db_query']('', '
@@ -2338,9 +2388,10 @@  discard block
 block discarded – undo
2338 2388
 	}
2339 2389
 	$smcFunc['db_free_result']($request);
2340 2390
 
2341
-	if (!empty($updates))
2342
-		foreach ($updates as $newStatus => $members)
2391
+	if (!empty($updates)) {
2392
+			foreach ($updates as $newStatus => $members)
2343 2393
 			updateMemberData($members, array('is_activated' => $newStatus));
2394
+	}
2344 2395
 
2345 2396
 	// Update the latest member and our total members as banning may change them.
2346 2397
 	updateStats('member');
Please login to merge, or discard this patch.
Sources/ManagePaid.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1452,7 +1452,7 @@
 block discarded – undo
1452 1452
  *
1453 1453
  * @param int $id_subscribe The subscription ID
1454 1454
  * @param int $id_member The ID of the member
1455
- * @param int|string $renewal 0 if we're forcing start/end time, otherwise a string indicating how long to renew the subscription for ('D', 'W', 'M' or 'Y')
1455
+ * @param integer $renewal 0 if we're forcing start/end time, otherwise a string indicating how long to renew the subscription for ('D', 'W', 'M' or 'Y')
1456 1456
  * @param int $forceStartTime If set, forces the subscription to start at the specified time
1457 1457
  * @param int $forceEndTime If set, forces the subscription to end at the specified time
1458 1458
  */
Please login to merge, or discard this patch.
Braces   +202 added lines, -148 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
  * The main entrance point for the 'Paid Subscription' screen, calling
@@ -32,18 +33,19 @@  discard block
 block discarded – undo
32 33
 	loadLanguage('ManagePaid');
33 34
 	loadTemplate('ManagePaid');
34 35
 
35
-	if (!empty($modSettings['paid_enabled']))
36
-		$subActions = array(
36
+	if (!empty($modSettings['paid_enabled'])) {
37
+			$subActions = array(
37 38
 			'modify' => array('ModifySubscription', 'admin_forum'),
38 39
 			'modifyuser' => array('ModifyUserSubscription', 'admin_forum'),
39 40
 			'settings' => array('ModifySubscriptionSettings', 'admin_forum'),
40 41
 			'view' => array('ViewSubscriptions', 'admin_forum'),
41 42
 			'viewsub' => array('ViewSubscribedUsers', 'admin_forum'),
42 43
 		);
43
-	else
44
-		$subActions = array(
44
+	} else {
45
+			$subActions = array(
45 46
 			'settings' => array('ModifySubscriptionSettings', 'admin_forum'),
46 47
 		);
48
+	}
47 49
 
48 50
 	// Default the sub-action to 'view subscriptions', but only if they have already set things up..
49 51
 	$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (!empty($modSettings['paid_currency_symbol']) && !empty($modSettings['paid_enabled']) ? 'view' : 'settings');
@@ -59,8 +61,8 @@  discard block
 block discarded – undo
59 61
 		'help' => '',
60 62
 		'description' => $txt['paid_subscriptions_desc'],
61 63
 	);
62
-	if (!empty($modSettings['paid_enabled']))
63
-		$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
64
+	if (!empty($modSettings['paid_enabled'])) {
65
+			$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
64 66
 			'view' => array(
65 67
 				'description' => $txt['paid_subs_view_desc'],
66 68
 			),
@@ -68,6 +70,7 @@  discard block
 block discarded – undo
68 70
 				'description' => $txt['paid_subs_settings_desc'],
69 71
 			),
70 72
 		);
73
+	}
71 74
 
72 75
 	call_integration_hook('integrate_manage_subscriptions', array(&$subActions));
73 76
 
@@ -92,8 +95,9 @@  discard block
 block discarded – undo
92 95
 	{
93 96
 		// If the currency is set to something different then we need to set it to other for this to work and set it back shortly.
94 97
 		$modSettings['paid_currency'] = !empty($modSettings['paid_currency_code']) ? $modSettings['paid_currency_code'] : '';
95
-		if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud')))
96
-			$modSettings['paid_currency'] = 'other';
98
+		if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud'))) {
99
+					$modSettings['paid_currency'] = 'other';
100
+		}
97 101
 
98 102
 		// These are all the default settings.
99 103
 		$config_vars = array(
@@ -156,8 +160,7 @@  discard block
 block discarded – undo
156 160
 			}
157 161
 		}
158 162
 		toggleOther();', true);
159
-	}
160
-	else
163
+	} else
161 164
 	{
162 165
 		$config_vars = array(
163 166
 			array('check', 'paid_enabled'),
@@ -166,8 +169,9 @@  discard block
 block discarded – undo
166 169
 	}
167 170
 
168 171
 	// Just searching?
169
-	if ($return_config)
170
-		return $config_vars;
172
+	if ($return_config) {
173
+			return $config_vars;
174
+	}
171 175
 
172 176
 	// Get the settings template fired up.
173 177
 	require_once($sourcedir . '/ManageServer.php');
@@ -211,8 +215,9 @@  discard block
 block discarded – undo
211 215
 			foreach (explode(',', $_POST['paid_email_to']) as $email)
212 216
 			{
213 217
 				$email = trim($email);
214
-				if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL))
215
-					$email_addresses[] = $email;
218
+				if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
219
+									$email_addresses[] = $email;
220
+				}
216 221
 				$_POST['paid_email_to'] = implode(',', $email_addresses);
217 222
 			}
218 223
 		}
@@ -249,8 +254,9 @@  discard block
 block discarded – undo
249 254
 	global $context, $txt, $modSettings, $sourcedir, $scripturl;
250 255
 
251 256
 	// Not made the settings yet?
252
-	if (empty($modSettings['paid_currency_symbol']))
253
-		fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings');
257
+	if (empty($modSettings['paid_currency_symbol'])) {
258
+			fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings');
259
+	}
254 260
 
255 261
 	// Some basic stuff.
256 262
 	$context['page_title'] = $txt['paid_subs_view'];
@@ -270,10 +276,11 @@  discard block
 block discarded – undo
270 276
 
271 277
 				foreach ($context['subscriptions'] as $data)
272 278
 				{
273
-					if (++$counter < $start)
274
-						continue;
275
-					elseif ($counter == $start + $items_per_page)
276
-						break;
279
+					if (++$counter < $start) {
280
+											continue;
281
+					} elseif ($counter == $start + $items_per_page) {
282
+											break;
283
+					}
277 284
 
278 285
 					$subscriptions[] = $data;
279 286
 				}
@@ -450,8 +457,9 @@  discard block
 block discarded – undo
450 457
 			);
451 458
 			$id_group = 0;
452 459
 			$add_groups = '';
453
-			if ($smcFunc['db_num_rows']($request))
454
-				list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request);
460
+			if ($smcFunc['db_num_rows']($request)) {
461
+							list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request);
462
+			}
455 463
 			$smcFunc['db_free_result']($request);
456 464
 
457 465
 			$changes = array();
@@ -463,8 +471,9 @@  discard block
 block discarded – undo
463 471
 				{
464 472
 					// If their current primary group isn't what they had before the subscription, and their current group was
465 473
 					// granted by the sub, remove it.
466
-					if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group)
467
-						$changes[$id_member]['id_group'] = $member_data['old_id_group'];
474
+					if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group) {
475
+											$changes[$id_member]['id_group'] = $member_data['old_id_group'];
476
+					}
468 477
 				}
469 478
 			}
470 479
 
@@ -477,15 +486,17 @@  discard block
 block discarded – undo
477 486
 					// First let's get their groups sorted.
478 487
 					$current_groups = explode(',', $member_data['additional_groups']);
479 488
 					$new_groups = implode(',', array_diff($current_groups, $add_groups));
480
-					if ($new_groups != $member_data['additional_groups'])
481
-						$changes[$id_member]['additional_groups'] = $new_groups;
489
+					if ($new_groups != $member_data['additional_groups']) {
490
+											$changes[$id_member]['additional_groups'] = $new_groups;
491
+					}
482 492
 				}
483 493
 			}
484 494
 
485 495
 			// We're going through changes...
486
-			if (!empty($changes))
487
-				foreach ($changes as $id_member => $new_values)
496
+			if (!empty($changes)) {
497
+							foreach ($changes as $id_member => $new_values)
488 498
 					updateMemberData($id_member, $new_values);
499
+			}
489 500
 		}
490 501
 
491 502
 		// Delete the subscription
@@ -533,11 +544,13 @@  discard block
 block discarded – undo
533 544
 				'M' => 24,
534 545
 				'Y' => 5,
535 546
 			);
536
-			if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1)
537
-				fatal_lang_error('paid_invalid_duration', false);
547
+			if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1) {
548
+							fatal_lang_error('paid_invalid_duration', false);
549
+			}
538 550
 
539
-			if ($_POST['span_value'] > $limits[$_POST['span_unit']])
540
-				fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false);
551
+			if ($_POST['span_value'] > $limits[$_POST['span_unit']]) {
552
+							fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false);
553
+			}
541 554
 
542 555
 			// Clean the span.
543 556
 			$span = $_POST['span_value'] . $_POST['span_unit'];
@@ -546,8 +559,9 @@  discard block
 block discarded – undo
546 559
 			$cost = array('fixed' => sprintf('%01.2f', strtr($_POST['cost'], ',', '.')));
547 560
 
548 561
 			// There needs to be something.
549
-			if (empty($_POST['span_value']) || empty($_POST['cost']))
550
-				fatal_lang_error('paid_no_cost_value');
562
+			if (empty($_POST['span_value']) || empty($_POST['cost'])) {
563
+							fatal_lang_error('paid_no_cost_value');
564
+			}
551 565
 		}
552 566
 		// Flexible is harder but more fun ;)
553 567
 		else
@@ -561,8 +575,9 @@  discard block
 block discarded – undo
561 575
 				'year' => sprintf('%01.2f', strtr($_POST['cost_year'], ',', '.')),
562 576
 			);
563 577
 
564
-			if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year']))
565
-				fatal_lang_error('paid_all_freq_blank');
578
+			if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year'])) {
579
+							fatal_lang_error('paid_all_freq_blank');
580
+			}
566 581
 		}
567 582
 		$cost = $smcFunc['json_encode']($cost);
568 583
 
@@ -571,9 +586,10 @@  discard block
 block discarded – undo
571 586
 
572 587
 		// Yep, time to do additional groups.
573 588
 		$addgroups = array();
574
-		if (!empty($_POST['addgroup']))
575
-			foreach ($_POST['addgroup'] as $id => $dummy)
589
+		if (!empty($_POST['addgroup'])) {
590
+					foreach ($_POST['addgroup'] as $id => $dummy)
576 591
 				$addgroups[] = (int) $id;
592
+		}
577 593
 		$addgroups = implode(',', $addgroups);
578 594
 
579 595
 		// Is it new?!
@@ -683,18 +699,18 @@  discard block
 block discarded – undo
683 699
 			{
684 700
 				$span_value = $match[1];
685 701
 				$span_unit = $match[2];
686
-			}
687
-			else
702
+			} else
688 703
 			{
689 704
 				$span_value = 0;
690 705
 				$span_unit = 'D';
691 706
 			}
692 707
 
693 708
 			// Is this a flexible one?
694
-			if ($row['length'] == 'F')
695
-				$isFlexible = true;
696
-			else
697
-				$isFlexible = false;
709
+			if ($row['length'] == 'F') {
710
+							$isFlexible = true;
711
+			} else {
712
+							$isFlexible = false;
713
+			}
698 714
 
699 715
 			$context['sub'] = array(
700 716
 				'name' => $row['name'],
@@ -743,8 +759,9 @@  discard block
 block discarded – undo
743 759
 		)
744 760
 	);
745 761
 	$context['groups'] = array();
746
-	while ($row = $smcFunc['db_fetch_assoc']($request))
747
-		$context['groups'][$row['id_group']] = $row['group_name'];
762
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
763
+			$context['groups'][$row['id_group']] = $row['group_name'];
764
+	}
748 765
 	$smcFunc['db_free_result']($request);
749 766
 
750 767
 	// This always happens.
@@ -778,8 +795,9 @@  discard block
 block discarded – undo
778 795
 		)
779 796
 	);
780 797
 	// Something wrong?
781
-	if ($smcFunc['db_num_rows']($request) == 0)
782
-		fatal_lang_error('no_access', false);
798
+	if ($smcFunc['db_num_rows']($request) == 0) {
799
+			fatal_lang_error('no_access', false);
800
+	}
783 801
 	// Do the subscription context.
784 802
 	$row = $smcFunc['db_fetch_assoc']($request);
785 803
 	$context['subscription'] = array(
@@ -1014,8 +1032,8 @@  discard block
 block discarded – undo
1014 1032
 		))
1015 1033
 	);
1016 1034
 	$subscribers = array();
1017
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1018
-		$subscribers[] = array(
1035
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1036
+			$subscribers[] = array(
1019 1037
 			'id' => $row['id_sublog'],
1020 1038
 			'id_member' => $row['id_member'],
1021 1039
 			'name' => $row['name'],
@@ -1025,6 +1043,7 @@  discard block
 block discarded – undo
1025 1043
 			'status' => $row['status'],
1026 1044
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] == 0 ? $txt['paid_finished'] : $txt['paid_pending']) : $txt['paid_active'],
1027 1045
 		);
1046
+	}
1028 1047
 	$smcFunc['db_free_result']($request);
1029 1048
 
1030 1049
 	return $subscribers;
@@ -1059,14 +1078,16 @@  discard block
 block discarded – undo
1059 1078
 				'current_log_item' => $context['log_id'],
1060 1079
 			)
1061 1080
 		);
1062
-		if ($smcFunc['db_num_rows']($request) == 0)
1063
-			fatal_lang_error('no_access', false);
1081
+		if ($smcFunc['db_num_rows']($request) == 0) {
1082
+					fatal_lang_error('no_access', false);
1083
+		}
1064 1084
 		list ($context['sub_id']) = $smcFunc['db_fetch_row']($request);
1065 1085
 		$smcFunc['db_free_result']($request);
1066 1086
 	}
1067 1087
 
1068
-	if (!isset($context['subscriptions'][$context['sub_id']]))
1069
-		fatal_lang_error('no_access', false);
1088
+	if (!isset($context['subscriptions'][$context['sub_id']])) {
1089
+			fatal_lang_error('no_access', false);
1090
+	}
1070 1091
 	$context['current_subscription'] = $context['subscriptions'][$context['sub_id']];
1071 1092
 
1072 1093
 	// Searching?
@@ -1099,8 +1120,9 @@  discard block
 block discarded – undo
1099 1120
 					'name' => $_POST['name'],
1100 1121
 				)
1101 1122
 			);
1102
-			if ($smcFunc['db_num_rows']($request) == 0)
1103
-				fatal_lang_error('error_member_not_found');
1123
+			if ($smcFunc['db_num_rows']($request) == 0) {
1124
+							fatal_lang_error('error_member_not_found');
1125
+			}
1104 1126
 
1105 1127
 			list ($id_member, $id_group) = $smcFunc['db_fetch_row']($request);
1106 1128
 			$smcFunc['db_free_result']($request);
@@ -1116,14 +1138,15 @@  discard block
 block discarded – undo
1116 1138
 					'current_member' => $id_member,
1117 1139
 				)
1118 1140
 			);
1119
-			if ($smcFunc['db_num_rows']($request) != 0)
1120
-				fatal_lang_error('member_already_subscribed');
1141
+			if ($smcFunc['db_num_rows']($request) != 0) {
1142
+							fatal_lang_error('member_already_subscribed');
1143
+			}
1121 1144
 			$smcFunc['db_free_result']($request);
1122 1145
 
1123 1146
 			// Actually put the subscription in place.
1124
-			if ($status == 1)
1125
-				addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1126
-			else
1147
+			if ($status == 1) {
1148
+							addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1149
+			} else
1127 1150
 			{
1128 1151
 				$smcFunc['db_insert']('',
1129 1152
 					'{db_prefix}log_subscribed',
@@ -1150,20 +1173,20 @@  discard block
 block discarded – undo
1150 1173
 					'current_log_item' => $context['log_id'],
1151 1174
 				)
1152 1175
 			);
1153
-			if ($smcFunc['db_num_rows']($request) == 0)
1154
-				fatal_lang_error('no_access', false);
1176
+			if ($smcFunc['db_num_rows']($request) == 0) {
1177
+							fatal_lang_error('no_access', false);
1178
+			}
1155 1179
 
1156 1180
 			list ($id_member, $old_status) = $smcFunc['db_fetch_row']($request);
1157 1181
 			$smcFunc['db_free_result']($request);
1158 1182
 
1159 1183
 			// Pick the right permission stuff depending on what the status is changing from/to.
1160
-			if ($old_status == 1 && $status != 1)
1161
-				removeSubscription($context['sub_id'], $id_member);
1162
-			elseif ($status == 1 && $old_status != 1)
1184
+			if ($old_status == 1 && $status != 1) {
1185
+							removeSubscription($context['sub_id'], $id_member);
1186
+			} elseif ($status == 1 && $old_status != 1)
1163 1187
 			{
1164 1188
 				addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1165
-			}
1166
-			else
1189
+			} else
1167 1190
 			{
1168 1191
 				$smcFunc['db_query']('', '
1169 1192
 					UPDATE {db_prefix}log_subscribed
@@ -1191,8 +1214,9 @@  discard block
 block discarded – undo
1191 1214
 		if (!empty($_REQUEST['delsub']))
1192 1215
 		{
1193 1216
 			$toDelete = array();
1194
-			foreach ($_REQUEST['delsub'] as $id => $dummy)
1195
-				$toDelete[] = (int) $id;
1217
+			foreach ($_REQUEST['delsub'] as $id => $dummy) {
1218
+							$toDelete[] = (int) $id;
1219
+			}
1196 1220
 
1197 1221
 			$request = $smcFunc['db_query']('', '
1198 1222
 				SELECT id_subscribe, id_member
@@ -1202,8 +1226,9 @@  discard block
 block discarded – undo
1202 1226
 					'subscription_list' => $toDelete,
1203 1227
 				)
1204 1228
 			);
1205
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1206
-				removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete']));
1229
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1230
+							removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete']));
1231
+			}
1207 1232
 			$smcFunc['db_free_result']($request);
1208 1233
 		}
1209 1234
 		redirectexit('action=admin;area=paidsubscribe;sa=viewsub;sid=' . $context['sub_id']);
@@ -1247,9 +1272,9 @@  discard block
 block discarded – undo
1247 1272
 			);
1248 1273
 			list ($context['sub']['username']) = $smcFunc['db_fetch_row']($request);
1249 1274
 			$smcFunc['db_free_result']($request);
1275
+		} else {
1276
+					$context['sub']['username'] = '';
1250 1277
 		}
1251
-		else
1252
-			$context['sub']['username'] = '';
1253 1278
 	}
1254 1279
 	// Otherwise load the existing info.
1255 1280
 	else
@@ -1266,8 +1291,9 @@  discard block
 block discarded – undo
1266 1291
 				'blank_string' => '',
1267 1292
 			)
1268 1293
 		);
1269
-		if ($smcFunc['db_num_rows']($request) == 0)
1270
-			fatal_lang_error('no_access', false);
1294
+		if ($smcFunc['db_num_rows']($request) == 0) {
1295
+					fatal_lang_error('no_access', false);
1296
+		}
1271 1297
 		$row = $smcFunc['db_fetch_assoc']($request);
1272 1298
 		$smcFunc['db_free_result']($request);
1273 1299
 
@@ -1288,13 +1314,13 @@  discard block
 block discarded – undo
1288 1314
 					{
1289 1315
 						foreach ($costs as $duration => $cost)
1290 1316
 						{
1291
-							if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2])
1292
-								$context['pending_payments'][$id] = array(
1317
+							if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2]) {
1318
+															$context['pending_payments'][$id] = array(
1293 1319
 									'desc' => sprintf($modSettings['paid_currency_symbol'], $cost . '/' . $txt[$duration]),
1294 1320
 								);
1321
+							}
1295 1322
 						}
1296
-					}
1297
-					elseif ($costs['fixed'] == $pending[1])
1323
+					} elseif ($costs['fixed'] == $pending[1])
1298 1324
 					{
1299 1325
 						$context['pending_payments'][$id] = array(
1300 1326
 							'desc' => sprintf($modSettings['paid_currency_symbol'], $costs['fixed']),
@@ -1312,8 +1338,9 @@  discard block
 block discarded – undo
1312 1338
 					if ($_GET['pending'] == $id && $pending[3] == 'payback' && isset($context['pending_payments'][$id]))
1313 1339
 					{
1314 1340
 						// Flexible?
1315
-						if (isset($_GET['accept']))
1316
-							addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0);
1341
+						if (isset($_GET['accept'])) {
1342
+													addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0);
1343
+						}
1317 1344
 						unset($pending_details[$id]);
1318 1345
 
1319 1346
 						$new_details = $smcFunc['json_encode']($pending_details);
@@ -1375,8 +1402,9 @@  discard block
 block discarded – undo
1375 1402
 	global $smcFunc;
1376 1403
 
1377 1404
 	// Make it an array.
1378
-	if (!is_array($users))
1379
-		$users = array($users);
1405
+	if (!is_array($users)) {
1406
+			$users = array($users);
1407
+	}
1380 1408
 
1381 1409
 	// Get all the members current groups.
1382 1410
 	$groups = array();
@@ -1414,14 +1442,16 @@  discard block
 block discarded – undo
1414 1442
 		if ($row['id_group'] != 0)
1415 1443
 		{
1416 1444
 			// If this is changing - add the old one to the additional groups so it's not lost.
1417
-			if ($row['id_group'] != $groups[$row['id_member']]['primary'])
1418
-				$groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary'];
1445
+			if ($row['id_group'] != $groups[$row['id_member']]['primary']) {
1446
+							$groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary'];
1447
+			}
1419 1448
 			$groups[$row['id_member']]['primary'] = $row['id_group'];
1420 1449
 		}
1421 1450
 
1422 1451
 		// Additional groups.
1423
-		if (!empty($row['add_groups']))
1424
-			$groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups']));
1452
+		if (!empty($row['add_groups'])) {
1453
+					$groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups']));
1454
+		}
1425 1455
 	}
1426 1456
 	$smcFunc['db_free_result']($request);
1427 1457
 
@@ -1429,9 +1459,10 @@  discard block
 block discarded – undo
1429 1459
 	foreach ($groups as $id => $group)
1430 1460
 	{
1431 1461
 		$group['additional'] = array_unique($group['additional']);
1432
-		foreach ($group['additional'] as $key => $value)
1433
-			if (empty($value))
1462
+		foreach ($group['additional'] as $key => $value) {
1463
+					if (empty($value))
1434 1464
 				unset($group['additional'][$key]);
1465
+		}
1435 1466
 		$addgroups = implode(',', $group['additional']);
1436 1467
 
1437 1468
 		$smcFunc['db_query']('', '
@@ -1465,8 +1496,9 @@  discard block
 block discarded – undo
1465 1496
 	loadSubscriptions();
1466 1497
 
1467 1498
 	// Exists, yes?
1468
-	if (!isset($context['subscriptions'][$id_subscribe]))
1469
-		return;
1499
+	if (!isset($context['subscriptions'][$id_subscribe])) {
1500
+			return;
1501
+	}
1470 1502
 
1471 1503
 	$curSub = $context['subscriptions'][$id_subscribe];
1472 1504
 
@@ -1514,16 +1546,19 @@  discard block
 block discarded – undo
1514 1546
 		list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request);
1515 1547
 
1516 1548
 		// If this has already expired but is active, extension means the period from now.
1517
-		if ($endtime < time())
1518
-			$endtime = time();
1519
-		if ($starttime == 0)
1520
-			$starttime = time();
1549
+		if ($endtime < time()) {
1550
+					$endtime = time();
1551
+		}
1552
+		if ($starttime == 0) {
1553
+					$starttime = time();
1554
+		}
1521 1555
 
1522 1556
 		// Work out the new expiry date.
1523 1557
 		$endtime += $duration;
1524 1558
 
1525
-		if ($forceEndTime != 0)
1526
-			$endtime = $forceEndTime;
1559
+		if ($forceEndTime != 0) {
1560
+					$endtime = $forceEndTime;
1561
+		}
1527 1562
 
1528 1563
 		// As everything else should be good, just update!
1529 1564
 		$smcFunc['db_query']('', '
@@ -1553,8 +1588,9 @@  discard block
 block discarded – undo
1553 1588
 	);
1554 1589
 
1555 1590
 	// Just in case the member doesn't exist.
1556
-	if ($smcFunc['db_num_rows']($request) == 0)
1557
-		return;
1591
+	if ($smcFunc['db_num_rows']($request) == 0) {
1592
+			return;
1593
+	}
1558 1594
 
1559 1595
 	list ($old_id_group, $additional_groups) = $smcFunc['db_fetch_row']($request);
1560 1596
 	$smcFunc['db_free_result']($request);
@@ -1571,16 +1607,18 @@  discard block
 block discarded – undo
1571 1607
 		$id_group = $curSub['prim_group'];
1572 1608
 
1573 1609
 		// Ensure their old privileges are maintained.
1574
-		if ($old_id_group != 0)
1575
-			$newAddGroups[] = $old_id_group;
1610
+		if ($old_id_group != 0) {
1611
+					$newAddGroups[] = $old_id_group;
1612
+		}
1613
+	} else {
1614
+			$id_group = $old_id_group;
1576 1615
 	}
1577
-	else
1578
-		$id_group = $old_id_group;
1579 1616
 
1580 1617
 	// Yep, make sure it's unique, and no empties.
1581
-	foreach ($newAddGroups as $k => $v)
1582
-		if (empty($v))
1618
+	foreach ($newAddGroups as $k => $v) {
1619
+			if (empty($v))
1583 1620
 			unset($newAddGroups[$k]);
1621
+	}
1584 1622
 	$newAddGroups = array_unique($newAddGroups);
1585 1623
 	$newAddGroups = implode(',', $newAddGroups);
1586 1624
 
@@ -1616,16 +1654,19 @@  discard block
 block discarded – undo
1616 1654
 		list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request);
1617 1655
 
1618 1656
 		// If this has already expired but is active, extension means the period from now.
1619
-		if ($endtime < time())
1620
-			$endtime = time();
1621
-		if ($starttime == 0)
1622
-			$starttime = time();
1657
+		if ($endtime < time()) {
1658
+					$endtime = time();
1659
+		}
1660
+		if ($starttime == 0) {
1661
+					$starttime = time();
1662
+		}
1623 1663
 
1624 1664
 		// Work out the new expiry date.
1625 1665
 		$endtime += $duration;
1626 1666
 
1627
-		if ($forceEndTime != 0)
1628
-			$endtime = $forceEndTime;
1667
+		if ($forceEndTime != 0) {
1668
+					$endtime = $forceEndTime;
1669
+		}
1629 1670
 
1630 1671
 		// As everything else should be good, just update!
1631 1672
 		$smcFunc['db_query']('', '
@@ -1648,13 +1689,15 @@  discard block
 block discarded – undo
1648 1689
 
1649 1690
 	// Otherwise a very simple insert.
1650 1691
 	$endtime = time() + $duration;
1651
-	if ($forceEndTime != 0)
1652
-		$endtime = $forceEndTime;
1692
+	if ($forceEndTime != 0) {
1693
+			$endtime = $forceEndTime;
1694
+	}
1653 1695
 
1654
-	if ($forceStartTime == 0)
1655
-		$starttime = time();
1656
-	else
1657
-		$starttime = $forceStartTime;
1696
+	if ($forceStartTime == 0) {
1697
+			$starttime = time();
1698
+	} else {
1699
+			$starttime = $forceStartTime;
1700
+	}
1658 1701
 
1659 1702
 	$smcFunc['db_insert']('',
1660 1703
 		'{db_prefix}log_subscribed',
@@ -1727,15 +1770,17 @@  discard block
 block discarded – undo
1727 1770
 	$new_id_group = -1;
1728 1771
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1729 1772
 	{
1730
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
1731
-			continue;
1773
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
1774
+					continue;
1775
+		}
1732 1776
 
1733 1777
 		// The one we're removing?
1734 1778
 		if ($row['id_subscribe'] == $id_subscribe)
1735 1779
 		{
1736 1780
 			$removals = explode(',', $context['subscriptions'][$row['id_subscribe']]['add_groups']);
1737
-			if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0)
1738
-				$removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];
1781
+			if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0) {
1782
+							$removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];
1783
+			}
1739 1784
 			$old_id_group = $row['old_id_group'];
1740 1785
 		}
1741 1786
 		// Otherwise things we allow.
@@ -1753,30 +1798,33 @@  discard block
 block discarded – undo
1753 1798
 
1754 1799
 	// Now, for everything we are removing check they definitely are not allowed it.
1755 1800
 	$existingGroups = explode(',', $additional_groups);
1756
-	foreach ($existingGroups as $key => $group)
1757
-		if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed)))
1801
+	foreach ($existingGroups as $key => $group) {
1802
+			if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed)))
1758 1803
 			unset($existingGroups[$key]);
1804
+	}
1759 1805
 
1760 1806
 	// Finally, do something with the current primary group.
1761 1807
 	if (in_array($id_group, $removals))
1762 1808
 	{
1763 1809
 		// If this primary group is actually allowed keep it.
1764
-		if (in_array($id_group, $allowed))
1765
-			$existingGroups[] = $id_group;
1810
+		if (in_array($id_group, $allowed)) {
1811
+					$existingGroups[] = $id_group;
1812
+		}
1766 1813
 
1767 1814
 		// Either way, change the id_group back.
1768 1815
 		if ($new_id_group < 1)
1769 1816
 		{
1770 1817
 			// If we revert to the old id-group we need to ensure it wasn't from a subscription.
1771
-			foreach ($context['subscriptions'] as $id => $group)
1772
-				// It was? Make them a regular member then!
1818
+			foreach ($context['subscriptions'] as $id => $group) {
1819
+							// It was? Make them a regular member then!
1773 1820
 				if ($group['prim_group'] == $old_id_group)
1774 1821
 					$old_id_group = 0;
1822
+			}
1775 1823
 
1776 1824
 			$id_group = $old_id_group;
1825
+		} else {
1826
+					$id_group = $new_id_group;
1777 1827
 		}
1778
-		else
1779
-			$id_group = $new_id_group;
1780 1828
 	}
1781 1829
 
1782 1830
 	// Crazy stuff, we seem to have our groups fixed, just make them unique
@@ -1796,8 +1844,8 @@  discard block
 block discarded – undo
1796 1844
 	);
1797 1845
 
1798 1846
 	// Disable the subscription.
1799
-	if (!$delete)
1800
-		$smcFunc['db_query']('', '
1847
+	if (!$delete) {
1848
+			$smcFunc['db_query']('', '
1801 1849
 			UPDATE {db_prefix}log_subscribed
1802 1850
 			SET status = {int:not_active}
1803 1851
 			WHERE id_member = {int:current_member}
@@ -1808,9 +1856,10 @@  discard block
 block discarded – undo
1808 1856
 				'current_subscription' => $id_subscribe,
1809 1857
 			)
1810 1858
 		);
1859
+	}
1811 1860
 	// Otherwise delete it!
1812
-	else
1813
-		$smcFunc['db_query']('', '
1861
+	else {
1862
+			$smcFunc['db_query']('', '
1814 1863
 			DELETE FROM {db_prefix}log_subscribed
1815 1864
 			WHERE id_member = {int:current_member}
1816 1865
 				AND id_subscribe = {int:current_subscription}',
@@ -1819,7 +1868,8 @@  discard block
 block discarded – undo
1819 1868
 				'current_subscription' => $id_subscribe,
1820 1869
 			)
1821 1870
 		);
1822
-}
1871
+	}
1872
+	}
1823 1873
 
1824 1874
 /**
1825 1875
  * This just kind of caches all the subscription data.
@@ -1828,8 +1878,9 @@  discard block
 block discarded – undo
1828 1878
 {
1829 1879
 	global $context, $txt, $modSettings, $smcFunc;
1830 1880
 
1831
-	if (!empty($context['subscriptions']))
1832
-		return;
1881
+	if (!empty($context['subscriptions'])) {
1882
+			return;
1883
+	}
1833 1884
 
1834 1885
 	// Make sure this is loaded, just in case.
1835 1886
 	loadLanguage('ManagePaid');
@@ -1846,10 +1897,11 @@  discard block
 block discarded – undo
1846 1897
 		// Pick a cost.
1847 1898
 		$costs = $smcFunc['json_decode']($row['cost'], true);
1848 1899
 
1849
-		if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed']))
1850
-			$cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']);
1851
-		else
1852
-			$cost = '???';
1900
+		if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed'])) {
1901
+					$cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']);
1902
+		} else {
1903
+					$cost = '???';
1904
+		}
1853 1905
 
1854 1906
 		// Do the span.
1855 1907
 		preg_match('~(\d*)(\w)~', $row['length'], $match);
@@ -1876,9 +1928,9 @@  discard block
 block discarded – undo
1876 1928
 					$num_length *= 31556926;
1877 1929
 					break;
1878 1930
 			}
1931
+		} else {
1932
+					$length = '??';
1879 1933
 		}
1880
-		else
1881
-			$length = '??';
1882 1934
 
1883 1935
 		$context['subscriptions'][$row['id_subscribe']] = array(
1884 1936
 			'id' => $row['id_subscribe'],
@@ -1913,8 +1965,9 @@  discard block
 block discarded – undo
1913 1965
 	{
1914 1966
 		$ind = $row['status'] == 0 ? 'finished' : 'total';
1915 1967
 
1916
-		if (isset($context['subscriptions'][$row['id_subscribe']]))
1917
-			$context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count'];
1968
+		if (isset($context['subscriptions'][$row['id_subscribe']])) {
1969
+					$context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count'];
1970
+		}
1918 1971
 	}
1919 1972
 	$smcFunc['db_free_result']($request);
1920 1973
 
@@ -1928,8 +1981,9 @@  discard block
 block discarded – undo
1928 1981
 	);
1929 1982
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1930 1983
 	{
1931
-		if (isset($context['subscriptions'][$row['id_subscribe']]))
1932
-			$context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending'];
1984
+		if (isset($context['subscriptions'][$row['id_subscribe']])) {
1985
+					$context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending'];
1986
+		}
1933 1987
 	}
1934 1988
 	$smcFunc['db_free_result']($request);
1935 1989
 }
Please login to merge, or discard this patch.
Sources/PersonalMessage.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4070,7 +4070,7 @@
 block discarded – undo
4070 4070
  *
4071 4071
  * @param int $pmID The ID of the PM
4072 4072
  * @param string $validFor Which folders this is valud for - can be 'inbox', 'outbox' or 'in_or_outbox'
4073
- * @return boolean Whether the PM is accessible in that folder for the current user
4073
+ * @return boolean|null Whether the PM is accessible in that folder for the current user
4074 4074
  */
4075 4075
 function isAccessiblePM($pmID, $validFor = 'in_or_outbox')
4076 4076
 {
Please login to merge, or discard this patch.
Braces   +633 added lines, -471 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
  * This helps organize things...
@@ -37,13 +38,14 @@  discard block
 block discarded – undo
37 38
 
38 39
 	loadLanguage('PersonalMessage+Drafts');
39 40
 
40
-	if (!isset($_REQUEST['xml']))
41
-		loadTemplate('PersonalMessage');
41
+	if (!isset($_REQUEST['xml'])) {
42
+			loadTemplate('PersonalMessage');
43
+	}
42 44
 
43 45
 	// Load up the members maximum message capacity.
44
-	if ($user_info['is_admin'])
45
-		$context['message_limit'] = 0;
46
-	elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
46
+	if ($user_info['is_admin']) {
47
+			$context['message_limit'] = 0;
48
+	} elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
47 49
 	{
48 50
 		// @todo Why do we do this?  It seems like if they have any limit we should use it.
49 51
 		$request = $smcFunc['db_query']('', '
@@ -78,8 +80,9 @@  discard block
 block discarded – undo
78 80
 	}
79 81
 
80 82
 	// a previous message was sent successfully? show a small indication.
81
-	if (isset($_GET['done']) && ($_GET['done'] == 'sent'))
82
-		$context['pm_sent'] = true;
83
+	if (isset($_GET['done']) && ($_GET['done'] == 'sent')) {
84
+			$context['pm_sent'] = true;
85
+	}
83 86
 
84 87
 	$context['labels'] = array();
85 88
 
@@ -210,11 +213,11 @@  discard block
 block discarded – undo
210 213
 	{
211 214
 		$_REQUEST['sa'] = '';
212 215
 		MessageFolder();
213
-	}
214
-	else
216
+	} else
215 217
 	{
216
-		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup')
217
-			messageIndexBar($_REQUEST['sa']);
218
+		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') {
219
+					messageIndexBar($_REQUEST['sa']);
220
+		}
218 221
 
219 222
 		call_helper($subActions[$_REQUEST['sa']]);
220 223
 	}
@@ -291,16 +294,17 @@  discard block
 block discarded – undo
291 294
 	);
292 295
 
293 296
 	// Handle labels.
294
-	if (empty($context['currently_using_labels']))
295
-		unset($pm_areas['labels']);
296
-	else
297
+	if (empty($context['currently_using_labels'])) {
298
+			unset($pm_areas['labels']);
299
+	} else
297 300
 	{
298 301
 		// Note we send labels by id as it will have less problems in the querystring.
299 302
 		$unread_in_labels = 0;
300 303
 		foreach ($context['labels'] as $label)
301 304
 		{
302
-			if ($label['id'] == -1)
303
-				continue;
305
+			if ($label['id'] == -1) {
306
+							continue;
307
+			}
304 308
 
305 309
 			// Count the amount of unread items in labels.
306 310
 			$unread_in_labels += $label['unread_messages'];
@@ -314,8 +318,9 @@  discard block
 block discarded – undo
314 318
 			);
315 319
 		}
316 320
 
317
-		if (!empty($unread_in_labels))
318
-			$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
321
+		if (!empty($unread_in_labels)) {
322
+					$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
323
+		}
319 324
 	}
320 325
 
321 326
 	$pm_areas['folders']['areas']['inbox']['unread_messages'] = &$context['labels'][-1]['unread_messages'];
@@ -353,8 +358,9 @@  discard block
 block discarded – undo
353 358
 	unset($pm_areas);
354 359
 
355 360
 	// No menu means no access.
356
-	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession()))
357
-		fatal_lang_error('no_access', false);
361
+	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) {
362
+			fatal_lang_error('no_access', false);
363
+	}
358 364
 
359 365
 	// Make a note of the Unique ID for this menu.
360 366
 	$context['pm_menu_id'] = $context['max_menu_id'];
@@ -365,9 +371,10 @@  discard block
 block discarded – undo
365 371
 	$context['menu_item_selected'] = $current_area;
366 372
 
367 373
 	// Set the template for this area and add the profile layer.
368
-	if (!isset($_REQUEST['xml']))
369
-		$context['template_layers'][] = 'pm';
370
-}
374
+	if (!isset($_REQUEST['xml'])) {
375
+			$context['template_layers'][] = 'pm';
376
+	}
377
+	}
371 378
 
372 379
 /**
373 380
  * The popup for when we ask for the popup from the user.
@@ -399,8 +406,9 @@  discard block
 block discarded – undo
399 406
 		)
400 407
 	);
401 408
 	$pms = array();
402
-	while ($row = $smcFunc['db_fetch_row']($request))
403
-		$pms[] = $row[0];
409
+	while ($row = $smcFunc['db_fetch_row']($request)) {
410
+			$pms[] = $row[0];
411
+	}
404 412
 	$smcFunc['db_free_result']($request);
405 413
 
406 414
 	if (!empty($pms))
@@ -428,8 +436,9 @@  discard block
 block discarded – undo
428 436
 		);
429 437
 		while ($row = $smcFunc['db_fetch_assoc']($request))
430 438
 		{
431
-			if (!empty($row['id_member_from']))
432
-				$senders[] = $row['id_member_from'];
439
+			if (!empty($row['id_member_from'])) {
440
+							$senders[] = $row['id_member_from'];
441
+			}
433 442
 
434 443
 			$row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head'];
435 444
 			$row['time'] = timeformat($row['timestamp']);
@@ -439,13 +448,15 @@  discard block
 block discarded – undo
439 448
 		$smcFunc['db_free_result']($request);
440 449
 
441 450
 		$senders = loadMemberData($senders);
442
-		foreach ($senders as $member)
443
-			loadMemberContext($member);
451
+		foreach ($senders as $member) {
452
+					loadMemberContext($member);
453
+		}
444 454
 
445 455
 		// Having loaded everyone, attach them to the PMs.
446
-		foreach ($context['unread_pms'] as $id_pm => $details)
447
-			if (!empty($memberContext[$details['id_member_from']]))
456
+		foreach ($context['unread_pms'] as $id_pm => $details) {
457
+					if (!empty($memberContext[$details['id_member_from']]))
448 458
 				$context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']];
459
+		}
449 460
 	}
450 461
 }
451 462
 
@@ -465,12 +476,13 @@  discard block
 block discarded – undo
465 476
 	}
466 477
 
467 478
 	// Make sure the starting location is valid.
468
-	if (isset($_GET['start']) && $_GET['start'] != 'new')
469
-		$_GET['start'] = (int) $_GET['start'];
470
-	elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first']))
471
-		$_GET['start'] = 0;
472
-	else
473
-		$_GET['start'] = 'new';
479
+	if (isset($_GET['start']) && $_GET['start'] != 'new') {
480
+			$_GET['start'] = (int) $_GET['start'];
481
+	} elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) {
482
+			$_GET['start'] = 0;
483
+	} else {
484
+			$_GET['start'] = 'new';
485
+	}
474 486
 
475 487
 	// Set up some basic theme stuff.
476 488
 	$context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to';
@@ -487,8 +499,7 @@  discard block
 block discarded – undo
487 499
 	{
488 500
 		$labelQuery = '
489 501
 			AND pmr.in_inbox = 1';
490
-	}
491
-	elseif ($context['folder'] != 'sent')
502
+	} elseif ($context['folder'] != 'sent')
492 503
 	{
493 504
 		$labelJoin = '
494 505
 			INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)';
@@ -530,22 +541,24 @@  discard block
 block discarded – undo
530 541
 	$txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']);
531 542
 
532 543
 	// Now, build the link tree!
533
-	if ($context['current_label_id'] == -1)
534
-		$context['linktree'][] = array(
544
+	if ($context['current_label_id'] == -1) {
545
+			$context['linktree'][] = array(
535 546
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'],
536 547
 			'name' => $pmbox
537 548
 		);
549
+	}
538 550
 
539 551
 	// Build it further for a label.
540
-	if ($context['current_label_id'] != -1)
541
-		$context['linktree'][] = array(
552
+	if ($context['current_label_id'] != -1) {
553
+			$context['linktree'][] = array(
542 554
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'],
543 555
 			'name' => $txt['pm_current_label'] . ': ' . $context['current_label']
544 556
 		);
557
+	}
545 558
 
546 559
 	// Figure out how many messages there are.
547
-	if ($context['folder'] == 'sent')
548
-		$request = $smcFunc['db_query']('', '
560
+	if ($context['folder'] == 'sent') {
561
+			$request = $smcFunc['db_query']('', '
549 562
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
550 563
 			FROM {db_prefix}personal_messages AS pm
551 564
 			WHERE pm.id_member_from = {int:current_member}
@@ -555,8 +568,8 @@  discard block
 block discarded – undo
555 568
 				'not_deleted' => 0,
556 569
 			)
557 570
 		);
558
-	else
559
-		$request = $smcFunc['db_query']('', '
571
+	} else {
572
+			$request = $smcFunc['db_query']('', '
560 573
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
561 574
 			FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
562 575
 				INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -567,6 +580,7 @@  discard block
 block discarded – undo
567 580
 				'not_deleted' => 0,
568 581
 			)
569 582
 		);
583
+	}
570 584
 	list ($max_messages) = $smcFunc['db_fetch_row']($request);
571 585
 	$smcFunc['db_free_result']($request);
572 586
 
@@ -575,10 +589,11 @@  discard block
 block discarded – undo
575 589
 	$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
576 590
 
577 591
 	// Start on the last page.
578
-	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages)
579
-		$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
580
-	elseif ($_GET['start'] < 0)
581
-		$_GET['start'] = 0;
592
+	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) {
593
+			$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
594
+	} elseif ($_GET['start'] < 0) {
595
+			$_GET['start'] = 0;
596
+	}
582 597
 
583 598
 	// ... but wait - what if we want to start from a specific message?
584 599
 	if (isset($_GET['pmid']))
@@ -586,19 +601,21 @@  discard block
 block discarded – undo
586 601
 		$pmID = (int) $_GET['pmid'];
587 602
 
588 603
 		// Make sure you have access to this PM.
589
-		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
590
-			fatal_lang_error('no_access', false);
604
+		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
605
+					fatal_lang_error('no_access', false);
606
+		}
591 607
 
592 608
 		$context['current_pm'] = $pmID;
593 609
 
594 610
 		// With only one page of PM's we're gonna want page 1.
595
-		if ($max_messages <= $maxPerPage)
596
-			$_GET['start'] = 0;
611
+		if ($max_messages <= $maxPerPage) {
612
+					$_GET['start'] = 0;
613
+		}
597 614
 		// If we pass kstart we assume we're in the right place.
598 615
 		elseif (!isset($_GET['kstart']))
599 616
 		{
600
-			if ($context['folder'] == 'sent')
601
-				$request = $smcFunc['db_query']('', '
617
+			if ($context['folder'] == 'sent') {
618
+							$request = $smcFunc['db_query']('', '
602 619
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
603 620
 					FROM {db_prefix}personal_messages
604 621
 					WHERE id_member_from = {int:current_member}
@@ -610,8 +627,8 @@  discard block
 block discarded – undo
610 627
 						'id_pm' => $pmID,
611 628
 					)
612 629
 				);
613
-			else
614
-				$request = $smcFunc['db_query']('', '
630
+			} else {
631
+							$request = $smcFunc['db_query']('', '
615 632
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
616 633
 					FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
617 634
 						INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -624,6 +641,7 @@  discard block
 block discarded – undo
624 641
 						'id_pm' => $pmID,
625 642
 					)
626 643
 				);
644
+			}
627 645
 
628 646
 			list ($_GET['start']) = $smcFunc['db_fetch_row']($request);
629 647
 			$smcFunc['db_free_result']($request);
@@ -638,8 +656,9 @@  discard block
 block discarded – undo
638 656
 	{
639 657
 		$pmsg = (int) $_GET['pmsg'];
640 658
 
641
-		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
642
-			fatal_lang_error('no_access', false);
659
+		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
660
+					fatal_lang_error('no_access', false);
661
+		}
643 662
 	}
644 663
 
645 664
 	// Set up the page index.
@@ -734,8 +753,9 @@  discard block
 block discarded – undo
734 753
 	{
735 754
 		if (!isset($recipients[$row['id_pm']]))
736 755
 		{
737
-			if (isset($row['id_member_from']))
738
-				$posters[$row['id_pm']] = $row['id_member_from'];
756
+			if (isset($row['id_member_from'])) {
757
+							$posters[$row['id_pm']] = $row['id_member_from'];
758
+			}
739 759
 			$pms[$row['id_pm']] = $row['id_pm'];
740 760
 			$recipients[$row['id_pm']] = array(
741 761
 				'to' => array(),
@@ -744,29 +764,33 @@  discard block
 block discarded – undo
744 764
 		}
745 765
 
746 766
 		// Keep track of the last message so we know what the head is without another query!
747
-		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm']))
748
-			$lastData = array(
767
+		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) {
768
+					$lastData = array(
749 769
 				'id' => $row['id_pm'],
750 770
 				'head' => $row['id_pm_head'],
751 771
 			);
772
+		}
752 773
 	}
753 774
 	$smcFunc['db_free_result']($request);
754 775
 
755 776
 	// Make sure that we have been given a correct head pm id!
756
-	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id'])
757
-		fatal_lang_error('no_access', false);
777
+	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) {
778
+			fatal_lang_error('no_access', false);
779
+	}
758 780
 
759 781
 	if (!empty($pms))
760 782
 	{
761 783
 		// Select the correct current message.
762
-		if (empty($pmID))
763
-			$context['current_pm'] = $lastData['id'];
784
+		if (empty($pmID)) {
785
+					$context['current_pm'] = $lastData['id'];
786
+		}
764 787
 
765 788
 		// This is a list of the pm's that are used for "full" display.
766
-		if ($context['display_mode'] == 0)
767
-			$display_pms = $pms;
768
-		else
769
-			$display_pms = array($context['current_pm']);
789
+		if ($context['display_mode'] == 0) {
790
+					$display_pms = $pms;
791
+		} else {
792
+					$display_pms = array($context['current_pm']);
793
+		}
770 794
 
771 795
 		// At this point we know the main id_pm's. But - if we are looking at conversations we need the others!
772 796
 		if ($context['display_mode'] == 2)
@@ -788,16 +812,18 @@  discard block
 block discarded – undo
788 812
 			while ($row = $smcFunc['db_fetch_assoc']($request))
789 813
 			{
790 814
 				// This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn!
791
-				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1)
792
-					continue;
793
-				elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1)
794
-					continue;
815
+				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) {
816
+									continue;
817
+				} elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) {
818
+									continue;
819
+				}
795 820
 
796
-				if (!isset($recipients[$row['id_pm']]))
797
-					$recipients[$row['id_pm']] = array(
821
+				if (!isset($recipients[$row['id_pm']])) {
822
+									$recipients[$row['id_pm']] = array(
798 823
 						'to' => array(),
799 824
 						'bcc' => array()
800 825
 					);
826
+				}
801 827
 				$display_pms[] = $row['id_pm'];
802 828
 				$posters[$row['id_pm']] = $row['id_member_from'];
803 829
 			}
@@ -848,8 +874,9 @@  discard block
 block discarded – undo
848 874
 				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
849 875
 				{
850 876
 					$l_id = $row2['id_label'];
851
-					if (isset($context['labels'][$l_id]))
852
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
877
+					if (isset($context['labels'][$l_id])) {
878
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
879
+					}
853 880
 				}
854 881
 
855 882
 				$smcFunc['db_free_result']($request2);
@@ -866,9 +893,10 @@  discard block
 block discarded – undo
866 893
 		// Make sure we don't load unnecessary data.
867 894
 		if ($context['display_mode'] == 1)
868 895
 		{
869
-			foreach ($posters as $k => $v)
870
-				if (!in_array($k, $display_pms))
896
+			foreach ($posters as $k => $v) {
897
+							if (!in_array($k, $display_pms))
871 898
 					unset($posters[$k]);
899
+			}
872 900
 		}
873 901
 
874 902
 		// Load any users....
@@ -879,8 +907,9 @@  discard block
 block discarded – undo
879 907
 		{
880 908
 			// Get the order right.
881 909
 			$orderBy = array();
882
-			foreach (array_reverse($pms) as $pm)
883
-				$orderBy[] = 'pm.id_pm = ' . $pm;
910
+			foreach (array_reverse($pms) as $pm) {
911
+							$orderBy[] = 'pm.id_pm = ' . $pm;
912
+			}
884 913
 
885 914
 			// Seperate query for these bits!
886 915
 			$subjects_request = $smcFunc['db_query']('', '
@@ -926,9 +955,9 @@  discard block
 block discarded – undo
926 955
 			// Allow mods to add additional buttons here
927 956
 			call_integration_hook('integrate_conversation_buttons');
928 957
 		}
958
+	} else {
959
+			$messages_request = false;
929 960
 	}
930
-	else
931
-		$messages_request = false;
932 961
 
933 962
 	$context['can_send_pm'] = allowedTo('pm_send');
934 963
 	$context['can_send_email'] = allowedTo('moderate_forum');
@@ -939,11 +968,13 @@  discard block
 block discarded – undo
939 968
 	if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages']))
940 969
 	{
941 970
 		// If the display mode is "old sk00l" do them all...
942
-		if ($context['display_mode'] == 0)
943
-			markMessages(null, $context['current_label_id']);
971
+		if ($context['display_mode'] == 0) {
972
+					markMessages(null, $context['current_label_id']);
973
+		}
944 974
 		// Otherwise do just the current one!
945
-		elseif (!empty($context['current_pm']))
946
-			markMessages($display_pms, $context['current_label_id']);
975
+		elseif (!empty($context['current_pm'])) {
976
+					markMessages($display_pms, $context['current_label_id']);
977
+		}
947 978
 	}
948 979
 }
949 980
 
@@ -961,8 +992,9 @@  discard block
 block discarded – undo
961 992
 
962 993
 	// Count the current message number....
963 994
 	static $counter = null;
964
-	if ($counter === null || $reset)
965
-		$counter = $context['start'];
995
+	if ($counter === null || $reset) {
996
+			$counter = $context['start'];
997
+	}
966 998
 
967 999
 	static $temp_pm_selected = null;
968 1000
 	if ($temp_pm_selected === null)
@@ -1007,19 +1039,22 @@  discard block
 block discarded – undo
1007 1039
 	}
1008 1040
 
1009 1041
 	// Bail if it's false, ie. no messages.
1010
-	if ($messages_request == false)
1011
-		return false;
1042
+	if ($messages_request == false) {
1043
+			return false;
1044
+	}
1012 1045
 
1013 1046
 	// Reset the data?
1014
-	if ($reset == true)
1015
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1047
+	if ($reset == true) {
1048
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1049
+	}
1016 1050
 
1017 1051
 	// Get the next one... bail if anything goes wrong.
1018 1052
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1019 1053
 	if (!$message)
1020 1054
 	{
1021
-		if ($type != 'subject')
1022
-			$smcFunc['db_free_result']($messages_request);
1055
+		if ($type != 'subject') {
1056
+					$smcFunc['db_free_result']($messages_request);
1057
+		}
1023 1058
 
1024 1059
 		return false;
1025 1060
 	}
@@ -1039,8 +1074,7 @@  discard block
 block discarded – undo
1039 1074
 		$memberContext[$message['id_member_from']]['email'] = '';
1040 1075
 		$memberContext[$message['id_member_from']]['show_email'] = false;
1041 1076
 		$memberContext[$message['id_member_from']]['is_guest'] = true;
1042
-	}
1043
-	else
1077
+	} else
1044 1078
 	{
1045 1079
 		$memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']);
1046 1080
 		$memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id'])));
@@ -1081,12 +1115,13 @@  discard block
 block discarded – undo
1081 1115
 	$counter++;
1082 1116
 
1083 1117
 	// Any custom profile fields?
1084
-	if (!empty($memberContext[$message['id_member_from']]['custom_fields']))
1085
-		foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1118
+	if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) {
1119
+			foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1086 1120
 			switch ($custom['placement'])
1087 1121
 			{
1088 1122
 				case 1:
1089 1123
 					$output['custom_fields']['icons'][] = $custom;
1124
+	}
1090 1125
 					break;
1091 1126
 				case 2:
1092 1127
 					$output['custom_fields']['above_signature'][] = $custom;
@@ -1129,22 +1164,28 @@  discard block
 block discarded – undo
1129 1164
 			$context['search_params'][$k] = $v;
1130 1165
 		}
1131 1166
 	}
1132
-	if (isset($_REQUEST['search']))
1133
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1167
+	if (isset($_REQUEST['search'])) {
1168
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1169
+	}
1134 1170
 
1135
-	if (isset($context['search_params']['search']))
1136
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1137
-	if (isset($context['search_params']['userspec']))
1138
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1171
+	if (isset($context['search_params']['search'])) {
1172
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1173
+	}
1174
+	if (isset($context['search_params']['userspec'])) {
1175
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1176
+	}
1139 1177
 
1140
-	if (!empty($context['search_params']['searchtype']))
1141
-		$context['search_params']['searchtype'] = 2;
1178
+	if (!empty($context['search_params']['searchtype'])) {
1179
+			$context['search_params']['searchtype'] = 2;
1180
+	}
1142 1181
 
1143
-	if (!empty($context['search_params']['minage']))
1144
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1182
+	if (!empty($context['search_params']['minage'])) {
1183
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1184
+	}
1145 1185
 
1146
-	if (!empty($context['search_params']['maxage']))
1147
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1186
+	if (!empty($context['search_params']['maxage'])) {
1187
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1188
+	}
1148 1189
 
1149 1190
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
1150 1191
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
@@ -1171,8 +1212,9 @@  discard block
 block discarded – undo
1171 1212
 		$context['search_errors']['messages'] = array();
1172 1213
 		foreach ($context['search_errors'] as $search_error => $dummy)
1173 1214
 		{
1174
-			if ($search_error == 'messages')
1175
-				continue;
1215
+			if ($search_error == 'messages') {
1216
+							continue;
1217
+			}
1176 1218
 
1177 1219
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
1178 1220
 		}
@@ -1194,8 +1236,9 @@  discard block
 block discarded – undo
1194 1236
 	global $scripturl, $modSettings, $user_info, $context, $txt;
1195 1237
 	global $memberContext, $smcFunc;
1196 1238
 
1197
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
1198
-		fatal_lang_error('loadavg_search_disabled', false);
1239
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
1240
+			fatal_lang_error('loadavg_search_disabled', false);
1241
+	}
1199 1242
 
1200 1243
 	/**
1201 1244
 	 * @todo For the moment force the folder to the inbox.
@@ -1224,35 +1267,40 @@  discard block
 block discarded – undo
1224 1267
 	$context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1225 1268
 
1226 1269
 	// Store whether simple search was used (needed if the user wants to do another query).
1227
-	if (!isset($search_params['advanced']))
1228
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1270
+	if (!isset($search_params['advanced'])) {
1271
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1272
+	}
1229 1273
 
1230 1274
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
1231
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
1232
-		$search_params['searchtype'] = 2;
1275
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
1276
+			$search_params['searchtype'] = 2;
1277
+	}
1233 1278
 
1234 1279
 	// Minimum age of messages. Default to zero (don't set param in that case).
1235
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
1236
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1280
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
1281
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1282
+	}
1237 1283
 
1238 1284
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
1239
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999))
1240
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1285
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) {
1286
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1287
+	}
1241 1288
 
1242 1289
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
1243 1290
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
1244 1291
 
1245 1292
 	// Default the user name to a wildcard matching every user (*).
1246
-	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
1247
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1293
+	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
1294
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1295
+	}
1248 1296
 
1249 1297
 	// This will be full of all kinds of parameters!
1250 1298
 	$searchq_parameters = array();
1251 1299
 
1252 1300
 	// If there's no specific user, then don't mention it in the main query.
1253
-	if (empty($search_params['userspec']))
1254
-		$userQuery = '';
1255
-	else
1301
+	if (empty($search_params['userspec'])) {
1302
+			$userQuery = '';
1303
+	} else
1256 1304
 	{
1257 1305
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
1258 1306
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -1264,8 +1312,9 @@  discard block
 block discarded – undo
1264 1312
 		{
1265 1313
 			$possible_users[$k] = trim($possible_users[$k]);
1266 1314
 
1267
-			if (strlen($possible_users[$k]) == 0)
1268
-				unset($possible_users[$k]);
1315
+			if (strlen($possible_users[$k]) == 0) {
1316
+							unset($possible_users[$k]);
1317
+			}
1269 1318
 		}
1270 1319
 
1271 1320
 		if (!empty($possible_users))
@@ -1277,8 +1326,9 @@  discard block
 block discarded – undo
1277 1326
 			{
1278 1327
 				$where_params['name_' . $k] = $v;
1279 1328
 				$where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}';
1280
-				if (!isset($where_params['real_name']))
1281
-					$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1329
+				if (!isset($where_params['real_name'])) {
1330
+									$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1331
+				}
1282 1332
 			}
1283 1333
 
1284 1334
 			// Who matches those criteria?
@@ -1291,28 +1341,28 @@  discard block
 block discarded – undo
1291 1341
 			);
1292 1342
 
1293 1343
 			// Simply do nothing if there're too many members matching the criteria.
1294
-			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
1295
-				$userQuery = '';
1296
-			elseif ($smcFunc['db_num_rows']($request) == 0)
1344
+			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
1345
+							$userQuery = '';
1346
+			} elseif ($smcFunc['db_num_rows']($request) == 0)
1297 1347
 			{
1298 1348
 				$userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})';
1299 1349
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1300 1350
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1301
-			}
1302
-			else
1351
+			} else
1303 1352
 			{
1304 1353
 				$memberlist = array();
1305
-				while ($row = $smcFunc['db_fetch_assoc']($request))
1306
-					$memberlist[] = $row['id_member'];
1354
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
1355
+									$memberlist[] = $row['id_member'];
1356
+				}
1307 1357
 				$userQuery = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})))';
1308 1358
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1309 1359
 				$searchq_parameters['member_list'] = $memberlist;
1310 1360
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1311 1361
 			}
1312 1362
 			$smcFunc['db_free_result']($request);
1363
+		} else {
1364
+					$userQuery = '';
1313 1365
 		}
1314
-		else
1315
-			$userQuery = '';
1316 1366
 	}
1317 1367
 
1318 1368
 	// Setup the sorting variables...
@@ -1320,8 +1370,9 @@  discard block
 block discarded – undo
1320 1370
 	$sort_columns = array(
1321 1371
 		'pm.id_pm',
1322 1372
 	);
1323
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
1324
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1373
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
1374
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1375
+	}
1325 1376
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm';
1326 1377
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
1327 1378
 
@@ -1331,24 +1382,27 @@  discard block
 block discarded – undo
1331 1382
 	if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels'])
1332 1383
 	{
1333 1384
 		// Came here from pagination?  Put them back into $_REQUEST for sanitization.
1334
-		if (isset($search_params['labels']))
1335
-			$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1385
+		if (isset($search_params['labels'])) {
1386
+					$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1387
+		}
1336 1388
 
1337 1389
 		// Assuming we have some labels - make them all integers.
1338 1390
 		if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel']))
1339 1391
 		{
1340
-			foreach ($_REQUEST['searchlabel'] as $key => $id)
1341
-				$_REQUEST['searchlabel'][$key] = (int) $id;
1392
+			foreach ($_REQUEST['searchlabel'] as $key => $id) {
1393
+							$_REQUEST['searchlabel'][$key] = (int) $id;
1394
+			}
1395
+		} else {
1396
+					$_REQUEST['searchlabel'] = array();
1342 1397
 		}
1343
-		else
1344
-			$_REQUEST['searchlabel'] = array();
1345 1398
 
1346 1399
 		// Now that everything is cleaned up a bit, make the labels a param.
1347 1400
 		$search_params['labels'] = implode(',', $_REQUEST['searchlabel']);
1348 1401
 
1349 1402
 		// No labels selected? That must be an error!
1350
-		if (empty($_REQUEST['searchlabel']))
1351
-			$context['search_errors']['no_labels_selected'] = true;
1403
+		if (empty($_REQUEST['searchlabel'])) {
1404
+					$context['search_errors']['no_labels_selected'] = true;
1405
+		}
1352 1406
 		// Otherwise prepare the query!
1353 1407
 		elseif (count($_REQUEST['searchlabel']) != count($context['labels']))
1354 1408
 		{
@@ -1371,8 +1425,7 @@  discard block
 block discarded – undo
1371 1425
 					// Not searching the inbox - PM must be labeled
1372 1426
 					$labelQuery = ' AND pml.id_label IN ({array_int:labels})';
1373 1427
 					$labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)';
1374
-				}
1375
-				else
1428
+				} else
1376 1429
 				{
1377 1430
 					// Searching the inbox - PM doesn't have to be labeled
1378 1431
 					$labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))';
@@ -1387,8 +1440,9 @@  discard block
 block discarded – undo
1387 1440
 	// What are we actually searching for?
1388 1441
 	$search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : '');
1389 1442
 	// If we ain't got nothing - we should error!
1390
-	if (!isset($search_params['search']) || $search_params['search'] == '')
1391
-		$context['search_errors']['invalid_search_string'] = true;
1443
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
1444
+			$context['search_errors']['invalid_search_string'] = true;
1445
+	}
1392 1446
 
1393 1447
 	// Extract phrase parts first (e.g. some words "this is a phrase" some more words.)
1394 1448
 	preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER);
@@ -1401,12 +1455,14 @@  discard block
 block discarded – undo
1401 1455
 	$excludedWords = array();
1402 1456
 
1403 1457
 	// .. first, we check for things like -"some words", but not "-some words".
1404
-	foreach ($matches[1] as $index => $word)
1405
-		if ($word == '-')
1458
+	foreach ($matches[1] as $index => $word) {
1459
+			if ($word == '-')
1406 1460
 		{
1407 1461
 			$word = $smcFunc['strtolower'](trim($searchArray[$index]));
1408
-			if (strlen($word) > 0)
1409
-				$excludedWords[] = $word;
1462
+	}
1463
+			if (strlen($word) > 0) {
1464
+							$excludedWords[] = $word;
1465
+			}
1410 1466
 			unset($searchArray[$index]);
1411 1467
 		}
1412 1468
 
@@ -1416,8 +1472,9 @@  discard block
 block discarded – undo
1416 1472
 		if (strpos(trim($word), '-') === 0)
1417 1473
 		{
1418 1474
 			$word = substr($smcFunc['strtolower']($word), 1);
1419
-			if (strlen($word) > 0)
1420
-				$excludedWords[] = $word;
1475
+			if (strlen($word) > 0) {
1476
+							$excludedWords[] = $word;
1477
+			}
1421 1478
 			unset($tempSearch[$index]);
1422 1479
 		}
1423 1480
 	}
@@ -1428,9 +1485,9 @@  discard block
 block discarded – undo
1428 1485
 	foreach ($searchArray as $index => $value)
1429 1486
 	{
1430 1487
 		$searchArray[$index] = $smcFunc['strtolower'](trim($value));
1431
-		if ($searchArray[$index] == '')
1432
-			unset($searchArray[$index]);
1433
-		else
1488
+		if ($searchArray[$index] == '') {
1489
+					unset($searchArray[$index]);
1490
+		} else
1434 1491
 		{
1435 1492
 			// Sort out entities first.
1436 1493
 			$searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]);
@@ -1440,27 +1497,32 @@  discard block
 block discarded – undo
1440 1497
 
1441 1498
 	// Create an array of replacements for highlighting.
1442 1499
 	$context['mark'] = array();
1443
-	foreach ($searchArray as $word)
1444
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1500
+	foreach ($searchArray as $word) {
1501
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1502
+	}
1445 1503
 
1446 1504
 	// This contains *everything*
1447 1505
 	$searchWords = array_merge($searchArray, $excludedWords);
1448 1506
 
1449 1507
 	// Make sure at least one word is being searched for.
1450
-	if (empty($searchArray))
1451
-		$context['search_errors']['invalid_search_string'] = true;
1508
+	if (empty($searchArray)) {
1509
+			$context['search_errors']['invalid_search_string'] = true;
1510
+	}
1452 1511
 
1453 1512
 	// Sort out the search query so the user can edit it - if they want.
1454 1513
 	$context['search_params'] = $search_params;
1455
-	if (isset($context['search_params']['search']))
1456
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1457
-	if (isset($context['search_params']['userspec']))
1458
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1514
+	if (isset($context['search_params']['search'])) {
1515
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1516
+	}
1517
+	if (isset($context['search_params']['userspec'])) {
1518
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1519
+	}
1459 1520
 
1460 1521
 	// Now we have all the parameters, combine them together for pagination and the like...
1461 1522
 	$context['params'] = array();
1462
-	foreach ($search_params as $k => $v)
1463
-		$context['params'][] = $k . '|\'|' . $v;
1523
+	foreach ($search_params as $k => $v) {
1524
+			$context['params'][] = $k . '|\'|' . $v;
1525
+	}
1464 1526
 	$context['params'] = base64_encode(implode('|"|', $context['params']));
1465 1527
 
1466 1528
 	// Compile the subject query part.
@@ -1468,26 +1530,31 @@  discard block
 block discarded – undo
1468 1530
 
1469 1531
 	foreach ($searchWords as $index => $word)
1470 1532
 	{
1471
-		if ($word == '')
1472
-			continue;
1533
+		if ($word == '') {
1534
+					continue;
1535
+		}
1473 1536
 
1474
-		if ($search_params['subject_only'])
1475
-			$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1476
-		else
1477
-			$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1537
+		if ($search_params['subject_only']) {
1538
+					$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1539
+		} else {
1540
+					$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1541
+		}
1478 1542
 		$searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%';
1479 1543
 	}
1480 1544
 
1481 1545
 	$searchQuery = ' 1=1';
1482
-	if (!empty($andQueryParts))
1483
-		$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1546
+	if (!empty($andQueryParts)) {
1547
+			$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1548
+	}
1484 1549
 
1485 1550
 	// Age limits?
1486 1551
 	$timeQuery = '';
1487
-	if (!empty($search_params['minage']))
1488
-		$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1489
-	if (!empty($search_params['maxage']))
1490
-		$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1552
+	if (!empty($search_params['minage'])) {
1553
+			$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1554
+	}
1555
+	if (!empty($search_params['maxage'])) {
1556
+			$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1557
+	}
1491 1558
 
1492 1559
 	// If we have errors - return back to the first screen...
1493 1560
 	if (!empty($context['search_errors']))
@@ -1573,8 +1640,9 @@  discard block
 block discarded – undo
1573 1640
 			)
1574 1641
 		);
1575 1642
 		$real_pm_ids = array();
1576
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1577
-			$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1643
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1644
+					$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1645
+		}
1578 1646
 		$smcFunc['db_free_result']($request);
1579 1647
 	}
1580 1648
 
@@ -1604,8 +1672,9 @@  discard block
 block discarded – undo
1604 1672
 		);
1605 1673
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1606 1674
 		{
1607
-			if ($context['folder'] == 'sent' || empty($row['bcc']))
1608
-				$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1675
+			if ($context['folder'] == 'sent' || empty($row['bcc'])) {
1676
+							$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1677
+			}
1609 1678
 
1610 1679
 			if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')
1611 1680
 			{
@@ -1626,12 +1695,14 @@  discard block
 block discarded – undo
1626 1695
 				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
1627 1696
 				{
1628 1697
 					$l_id = $row2['id_label'];
1629
-					if (isset($context['labels'][$l_id]))
1630
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1698
+					if (isset($context['labels'][$l_id])) {
1699
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1700
+					}
1631 1701
 
1632 1702
 					// Here we find the first label on a message - for linking to posts in results
1633
-					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1)
1634
-						$context['first_label'][$row['id_pm']] = $l_id;
1703
+					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) {
1704
+											$context['first_label'][$row['id_pm']] = $l_id;
1705
+					}
1635 1706
 				}
1636 1707
 
1637 1708
 				$smcFunc['db_free_result']($request2);
@@ -1758,8 +1829,9 @@  discard block
 block discarded – undo
1758 1829
 		list ($postCount) = $smcFunc['db_fetch_row']($request);
1759 1830
 		$smcFunc['db_free_result']($request);
1760 1831
 
1761
-		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
1762
-			fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1832
+		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) {
1833
+					fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1834
+		}
1763 1835
 	}
1764 1836
 
1765 1837
 	// Quoting/Replying to a message?
@@ -1768,8 +1840,9 @@  discard block
 block discarded – undo
1768 1840
 		$pmsg = (int) $_REQUEST['pmsg'];
1769 1841
 
1770 1842
 		// Make sure this is yours.
1771
-		if (!isAccessiblePM($pmsg))
1772
-			fatal_lang_error('no_access', false);
1843
+		if (!isAccessiblePM($pmsg)) {
1844
+					fatal_lang_error('no_access', false);
1845
+		}
1773 1846
 
1774 1847
 		// Work out whether this is one you've received?
1775 1848
 		$request = $smcFunc['db_query']('', '
@@ -1806,8 +1879,9 @@  discard block
 block discarded – undo
1806 1879
 				'id_pm' => $pmsg,
1807 1880
 			)
1808 1881
 		);
1809
-		if ($smcFunc['db_num_rows']($request) == 0)
1810
-			fatal_lang_error('pm_not_yours', false);
1882
+		if ($smcFunc['db_num_rows']($request) == 0) {
1883
+					fatal_lang_error('pm_not_yours', false);
1884
+		}
1811 1885
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
1812 1886
 		$smcFunc['db_free_result']($request);
1813 1887
 
@@ -1818,9 +1892,9 @@  discard block
 block discarded – undo
1818 1892
 		// Add 'Re: ' to it....
1819 1893
 		if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
1820 1894
 		{
1821
-			if ($language === $user_info['language'])
1822
-				$context['response_prefix'] = $txt['response_prefix'];
1823
-			else
1895
+			if ($language === $user_info['language']) {
1896
+							$context['response_prefix'] = $txt['response_prefix'];
1897
+			} else
1824 1898
 			{
1825 1899
 				loadLanguage('index', $language, false);
1826 1900
 				$context['response_prefix'] = $txt['response_prefix'];
@@ -1829,22 +1903,25 @@  discard block
 block discarded – undo
1829 1903
 			cache_put_data('response_prefix', $context['response_prefix'], 600);
1830 1904
 		}
1831 1905
 		$form_subject = $row_quoted['subject'];
1832
-		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
1833
-			$form_subject = $context['response_prefix'] . $form_subject;
1906
+		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
1907
+					$form_subject = $context['response_prefix'] . $form_subject;
1908
+		}
1834 1909
 
1835 1910
 		if (isset($_REQUEST['quote']))
1836 1911
 		{
1837 1912
 			// Remove any nested quotes and <br>...
1838 1913
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']);
1839
-			if (!empty($modSettings['removeNestedQuotes']))
1840
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1841
-			if (empty($row_quoted['id_member']))
1842
-				$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1843
-			else
1844
-				$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1914
+			if (!empty($modSettings['removeNestedQuotes'])) {
1915
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1916
+			}
1917
+			if (empty($row_quoted['id_member'])) {
1918
+							$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1919
+			} else {
1920
+							$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1921
+			}
1922
+		} else {
1923
+					$form_message = '';
1845 1924
 		}
1846
-		else
1847
-			$form_message = '';
1848 1925
 
1849 1926
 		// Do the BBC thang on the message.
1850 1927
 		$row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']);
@@ -1865,8 +1942,7 @@  discard block
 block discarded – undo
1865 1942
 			'timestamp' => forum_time(true, $row_quoted['msgtime']),
1866 1943
 			'body' => $row_quoted['body']
1867 1944
 		);
1868
-	}
1869
-	else
1945
+	} else
1870 1946
 	{
1871 1947
 		$context['quoted_message'] = false;
1872 1948
 		$form_subject = '';
@@ -1885,11 +1961,12 @@  discard block
 block discarded – undo
1885 1961
 		if ($_REQUEST['u'] == 'all' && isset($row_quoted))
1886 1962
 		{
1887 1963
 			// Firstly, to reply to all we clearly already have $row_quoted - so have the original member from.
1888
-			if ($row_quoted['id_member'] != $user_info['id'])
1889
-				$context['recipients']['to'][] = array(
1964
+			if ($row_quoted['id_member'] != $user_info['id']) {
1965
+							$context['recipients']['to'][] = array(
1890 1966
 					'id' => $row_quoted['id_member'],
1891 1967
 					'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']),
1892 1968
 				);
1969
+			}
1893 1970
 
1894 1971
 			// Now to get the others.
1895 1972
 			$request = $smcFunc['db_query']('', '
@@ -1905,18 +1982,19 @@  discard block
 block discarded – undo
1905 1982
 					'not_bcc' => 0,
1906 1983
 				)
1907 1984
 			);
1908
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1909
-				$context['recipients']['to'][] = array(
1985
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1986
+							$context['recipients']['to'][] = array(
1910 1987
 					'id' => $row['id_member'],
1911 1988
 					'name' => $row['real_name'],
1912 1989
 				);
1990
+			}
1913 1991
 			$smcFunc['db_free_result']($request);
1914
-		}
1915
-		else
1992
+		} else
1916 1993
 		{
1917 1994
 			$_REQUEST['u'] = explode(',', $_REQUEST['u']);
1918
-			foreach ($_REQUEST['u'] as $key => $uID)
1919
-				$_REQUEST['u'][$key] = (int) $uID;
1995
+			foreach ($_REQUEST['u'] as $key => $uID) {
1996
+							$_REQUEST['u'][$key] = (int) $uID;
1997
+			}
1920 1998
 
1921 1999
 			$_REQUEST['u'] = array_unique($_REQUEST['u']);
1922 2000
 
@@ -1930,22 +2008,24 @@  discard block
 block discarded – undo
1930 2008
 					'limit' => count($_REQUEST['u']),
1931 2009
 				)
1932 2010
 			);
1933
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1934
-				$context['recipients']['to'][] = array(
2011
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2012
+							$context['recipients']['to'][] = array(
1935 2013
 					'id' => $row['id_member'],
1936 2014
 					'name' => $row['real_name'],
1937 2015
 				);
2016
+			}
1938 2017
 			$smcFunc['db_free_result']($request);
1939 2018
 		}
1940 2019
 
1941 2020
 		// Get a literal name list in case the user has JavaScript disabled.
1942 2021
 		$names = array();
1943
-		foreach ($context['recipients']['to'] as $to)
1944
-			$names[] = $to['name'];
2022
+		foreach ($context['recipients']['to'] as $to) {
2023
+					$names[] = $to['name'];
2024
+		}
1945 2025
 		$context['to_value'] = empty($names) ? '' : '&quot;' . implode('&quot;, &quot;', $names) . '&quot;';
2026
+	} else {
2027
+			$context['to_value'] = '';
1946 2028
 	}
1947
-	else
1948
-		$context['to_value'] = '';
1949 2029
 
1950 2030
 	// Set the defaults...
1951 2031
 	$context['subject'] = $form_subject;
@@ -2015,8 +2095,9 @@  discard block
 block discarded – undo
2015 2095
 
2016 2096
 	// validate with loadMemberData()
2017 2097
 	$memberResult = loadMemberData($user_info['id'], false);
2018
-	if (!$memberResult)
2019
-		fatal_lang_error('not_a_user', false);
2098
+	if (!$memberResult) {
2099
+			fatal_lang_error('not_a_user', false);
2100
+	}
2020 2101
 	list ($memID) = $memberResult;
2021 2102
 
2022 2103
 	// drafts is where the functions reside
@@ -2042,9 +2123,9 @@  discard block
 block discarded – undo
2042 2123
 		$context['sub_template'] = 'send';
2043 2124
 		loadJavaScriptFile('PersonalMessage.js', array('defer' => false), 'smf_pms');
2044 2125
 		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
2126
+	} else {
2127
+			$context['sub_template'] = 'pm';
2045 2128
 	}
2046
-	else
2047
-		$context['sub_template'] = 'pm';
2048 2129
 
2049 2130
 	$context['page_title'] = $txt['send_message'];
2050 2131
 
@@ -2105,10 +2186,11 @@  discard block
 block discarded – undo
2105 2186
 		);
2106 2187
 		if ($smcFunc['db_num_rows']($request) == 0)
2107 2188
 		{
2108
-			if (!isset($_REQUEST['xml']))
2109
-				fatal_lang_error('pm_not_yours', false);
2110
-			else
2111
-				$error_types[] = 'pm_not_yours';
2189
+			if (!isset($_REQUEST['xml'])) {
2190
+							fatal_lang_error('pm_not_yours', false);
2191
+			} else {
2192
+							$error_types[] = 'pm_not_yours';
2193
+			}
2112 2194
 		}
2113 2195
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
2114 2196
 		$smcFunc['db_free_result']($request);
@@ -2155,14 +2237,16 @@  discard block
 block discarded – undo
2155 2237
 		$context['post_error'][$error_type] = true;
2156 2238
 		if (isset($txt['error_' . $error_type]))
2157 2239
 		{
2158
-			if ($error_type == 'long_message')
2159
-				$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2240
+			if ($error_type == 'long_message') {
2241
+							$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2242
+			}
2160 2243
 			$context['post_error']['messages'][] = $txt['error_' . $error_type];
2161 2244
 		}
2162 2245
 
2163 2246
 		// If it's not a minor error flag it as such.
2164
-		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject')))
2165
-			$context['error_type'] = 'serious';
2247
+		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) {
2248
+					$context['error_type'] = 'serious';
2249
+		}
2166 2250
 	}
2167 2251
 
2168 2252
 	// We need to load the editor once more.
@@ -2220,8 +2304,9 @@  discard block
 block discarded – undo
2220 2304
 	require_once($sourcedir . '/Subs-Auth.php');
2221 2305
 
2222 2306
 	// PM Drafts enabled and needed?
2223
-	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft'])))
2224
-		require_once($sourcedir . '/Drafts.php');
2307
+	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) {
2308
+			require_once($sourcedir . '/Drafts.php');
2309
+	}
2225 2310
 
2226 2311
 	loadLanguage('PersonalMessage', '', false);
2227 2312
 
@@ -2251,24 +2336,27 @@  discard block
 block discarded – undo
2251 2336
 
2252 2337
 		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
2253 2338
 		{
2254
-			if (!isset($_REQUEST['xml']))
2255
-				fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2256
-			else
2257
-				$post_errors[] = 'pm_too_many_per_hour';
2339
+			if (!isset($_REQUEST['xml'])) {
2340
+							fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2341
+			} else {
2342
+							$post_errors[] = 'pm_too_many_per_hour';
2343
+			}
2258 2344
 		}
2259 2345
 	}
2260 2346
 
2261 2347
 	// If your session timed out, show an error, but do allow to re-submit.
2262
-	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '')
2263
-		$post_errors[] = 'session_timeout';
2348
+	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') {
2349
+			$post_errors[] = 'session_timeout';
2350
+	}
2264 2351
 
2265 2352
 	$_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
2266 2353
 	$_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to'];
2267 2354
 	$_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc'];
2268 2355
 
2269 2356
 	// Route the input from the 'u' parameter to the 'to'-list.
2270
-	if (!empty($_POST['u']))
2271
-		$_POST['recipient_to'] = explode(',', $_POST['u']);
2357
+	if (!empty($_POST['u'])) {
2358
+			$_POST['recipient_to'] = explode(',', $_POST['u']);
2359
+	}
2272 2360
 
2273 2361
 	// Construct the list of recipients.
2274 2362
 	$recipientList = array();
@@ -2280,8 +2368,9 @@  discard block
 block discarded – undo
2280 2368
 		$recipientList[$recipientType] = array();
2281 2369
 		if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType]))
2282 2370
 		{
2283
-			foreach ($_POST['recipient_' . $recipientType] as $recipient)
2284
-				$recipientList[$recipientType][] = (int) $recipient;
2371
+			foreach ($_POST['recipient_' . $recipientType] as $recipient) {
2372
+							$recipientList[$recipientType][] = (int) $recipient;
2373
+			}
2285 2374
 		}
2286 2375
 
2287 2376
 		// Are there also literal names set?
@@ -2295,10 +2384,11 @@  discard block
 block discarded – undo
2295 2384
 
2296 2385
 			foreach ($namedRecipientList[$recipientType] as $index => $recipient)
2297 2386
 			{
2298
-				if (strlen(trim($recipient)) > 0)
2299
-					$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2300
-				else
2301
-					unset($namedRecipientList[$recipientType][$index]);
2387
+				if (strlen(trim($recipient)) > 0) {
2388
+									$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2389
+				} else {
2390
+									unset($namedRecipientList[$recipientType][$index]);
2391
+				}
2302 2392
 			}
2303 2393
 
2304 2394
 			if (!empty($namedRecipientList[$recipientType]))
@@ -2328,8 +2418,9 @@  discard block
 block discarded – undo
2328 2418
 		}
2329 2419
 
2330 2420
 		// Selected a recipient to be deleted? Remove them now.
2331
-		if (!empty($_POST['delete_recipient']))
2332
-			$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2421
+		if (!empty($_POST['delete_recipient'])) {
2422
+					$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2423
+		}
2333 2424
 
2334 2425
 		// Make sure we don't include the same name twice
2335 2426
 		$recipientList[$recipientType] = array_unique($recipientList[$recipientType]);
@@ -2339,8 +2430,9 @@  discard block
 block discarded – undo
2339 2430
 	$is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']);
2340 2431
 
2341 2432
 	// Check if there's at least one recipient.
2342
-	if (empty($recipientList['to']) && empty($recipientList['bcc']))
2343
-		$post_errors[] = 'no_to';
2433
+	if (empty($recipientList['to']) && empty($recipientList['bcc'])) {
2434
+			$post_errors[] = 'no_to';
2435
+	}
2344 2436
 
2345 2437
 	// Make sure that we remove the members who did get it from the screen.
2346 2438
 	if (!$is_recipient_change)
@@ -2354,28 +2446,31 @@  discard block
 block discarded – undo
2354 2446
 				// Since we already have a post error, remove the previous one.
2355 2447
 				$post_errors = array_diff($post_errors, array('no_to'));
2356 2448
 
2357
-				foreach ($namesNotFound[$recipientType] as $name)
2358
-					$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2449
+				foreach ($namesNotFound[$recipientType] as $name) {
2450
+									$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2451
+				}
2359 2452
 			}
2360 2453
 		}
2361 2454
 	}
2362 2455
 
2363 2456
 	// Did they make any mistakes?
2364
-	if ($_REQUEST['subject'] == '')
2365
-		$post_errors[] = 'no_subject';
2366
-	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '')
2367
-		$post_errors[] = 'no_message';
2368
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength'])
2369
-		$post_errors[] = 'long_message';
2370
-	else
2457
+	if ($_REQUEST['subject'] == '') {
2458
+			$post_errors[] = 'no_subject';
2459
+	}
2460
+	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') {
2461
+			$post_errors[] = 'no_message';
2462
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) {
2463
+			$post_errors[] = 'long_message';
2464
+	} else
2371 2465
 	{
2372 2466
 		// Preparse the message.
2373 2467
 		$message = $_REQUEST['message'];
2374 2468
 		preparsecode($message);
2375 2469
 
2376 2470
 		// Make sure there's still some content left without the tags.
2377
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false))
2378
-			$post_errors[] = 'no_message';
2471
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) {
2472
+					$post_errors[] = 'no_message';
2473
+		}
2379 2474
 	}
2380 2475
 
2381 2476
 	// Wrong verification code?
@@ -2387,13 +2482,15 @@  discard block
 block discarded – undo
2387 2482
 		);
2388 2483
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
2389 2484
 
2390
-		if (is_array($context['require_verification']))
2391
-			$post_errors = array_merge($post_errors, $context['require_verification']);
2485
+		if (is_array($context['require_verification'])) {
2486
+					$post_errors = array_merge($post_errors, $context['require_verification']);
2487
+		}
2392 2488
 	}
2393 2489
 
2394 2490
 	// If they did, give a chance to make ammends.
2395
-	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml']))
2396
-		return messagePostError($post_errors, $namedRecipientList, $recipientList);
2491
+	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) {
2492
+			return messagePostError($post_errors, $namedRecipientList, $recipientList);
2493
+	}
2397 2494
 
2398 2495
 	// Want to take a second glance before you send?
2399 2496
 	if (isset($_REQUEST['preview']))
@@ -2424,8 +2521,9 @@  discard block
 block discarded – undo
2424 2521
 		foreach ($namesNotFound as $recipientType => $names)
2425 2522
 		{
2426 2523
 			$post_errors[] = 'bad_' . $recipientType;
2427
-			foreach ($names as $name)
2428
-				$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2524
+			foreach ($names as $name) {
2525
+							$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2526
+			}
2429 2527
 		}
2430 2528
 
2431 2529
 		return messagePostError(array(), $namedRecipientList, $recipientList);
@@ -2455,13 +2553,14 @@  discard block
 block discarded – undo
2455 2553
 	checkSubmitOnce('check');
2456 2554
 
2457 2555
 	// Do the actual sending of the PM.
2458
-	if (!empty($recipientList['to']) || !empty($recipientList['bcc']))
2459
-		$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2460
-	else
2461
-		$context['send_log'] = array(
2556
+	if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) {
2557
+			$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2558
+	} else {
2559
+			$context['send_log'] = array(
2462 2560
 			'sent' => array(),
2463 2561
 			'failed' => array()
2464 2562
 		);
2563
+	}
2465 2564
 
2466 2565
 	// Mark the message as "replied to".
2467 2566
 	if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox')
@@ -2479,11 +2578,12 @@  discard block
 block discarded – undo
2479 2578
 	}
2480 2579
 
2481 2580
 	// If one or more of the recipient were invalid, go back to the post screen with the failed usernames.
2482
-	if (!empty($context['send_log']['failed']))
2483
-		return messagePostError($post_errors, $namesNotFound, array(
2581
+	if (!empty($context['send_log']['failed'])) {
2582
+			return messagePostError($post_errors, $namesNotFound, array(
2484 2583
 			'to' => array_intersect($recipientList['to'], $context['send_log']['failed']),
2485 2584
 			'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed'])
2486 2585
 		));
2586
+	}
2487 2587
 
2488 2588
 	// Message sent successfully?
2489 2589
 	if (!empty($context['send_log']) && empty($context['send_log']['failed']))
@@ -2491,8 +2591,9 @@  discard block
 block discarded – undo
2491 2591
 		$context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent';
2492 2592
 
2493 2593
 		// If we had a PM draft for this one, then its time to remove it since it was just sent
2494
-		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft']))
2495
-			DeleteDraft($_POST['id_pm_draft']);
2594
+		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) {
2595
+					DeleteDraft($_POST['id_pm_draft']);
2596
+		}
2496 2597
 	}
2497 2598
 
2498 2599
 	// Go back to the where they sent from, if possible...
@@ -2507,24 +2608,28 @@  discard block
 block discarded – undo
2507 2608
 
2508 2609
 	checkSession('request');
2509 2610
 
2510
-	if (isset($_REQUEST['del_selected']))
2511
-		$_REQUEST['pm_action'] = 'delete';
2611
+	if (isset($_REQUEST['del_selected'])) {
2612
+			$_REQUEST['pm_action'] = 'delete';
2613
+	}
2512 2614
 
2513 2615
 	if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms']))
2514 2616
 	{
2515
-		foreach ($_REQUEST['pms'] as $pm)
2516
-			$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2617
+		foreach ($_REQUEST['pms'] as $pm) {
2618
+					$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2619
+		}
2517 2620
 	}
2518 2621
 
2519
-	if (empty($_REQUEST['pm_actions']))
2520
-		redirectexit($context['current_label_redirect']);
2622
+	if (empty($_REQUEST['pm_actions'])) {
2623
+			redirectexit($context['current_label_redirect']);
2624
+	}
2521 2625
 
2522 2626
 	// If we are in conversation, we may need to apply this to every message in the conversation.
2523 2627
 	if ($context['display_mode'] == 2 && isset($_REQUEST['conversation']))
2524 2628
 	{
2525 2629
 		$id_pms = array();
2526
-		foreach ($_REQUEST['pm_actions'] as $pm => $dummy)
2527
-			$id_pms[] = (int) $pm;
2630
+		foreach ($_REQUEST['pm_actions'] as $pm => $dummy) {
2631
+					$id_pms[] = (int) $pm;
2632
+		}
2528 2633
 
2529 2634
 		$request = $smcFunc['db_query']('', '
2530 2635
 			SELECT id_pm_head, id_pm
@@ -2535,8 +2640,9 @@  discard block
 block discarded – undo
2535 2640
 			)
2536 2641
 		);
2537 2642
 		$pm_heads = array();
2538
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2539
-			$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2643
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2644
+					$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2645
+		}
2540 2646
 		$smcFunc['db_free_result']($request);
2541 2647
 
2542 2648
 		$request = $smcFunc['db_query']('', '
@@ -2550,8 +2656,9 @@  discard block
 block discarded – undo
2550 2656
 		// Copy the action from the single to PM to the others.
2551 2657
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2552 2658
 		{
2553
-			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]))
2554
-				$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2659
+			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) {
2660
+							$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2661
+			}
2555 2662
 		}
2556 2663
 		$smcFunc['db_free_result']($request);
2557 2664
 	}
@@ -2562,22 +2669,21 @@  discard block
 block discarded – undo
2562 2669
 	$labels = array();
2563 2670
 	foreach ($_REQUEST['pm_actions'] as $pm => $action)
2564 2671
 	{
2565
-		if ($action === 'delete')
2566
-			$to_delete[] = (int) $pm;
2567
-		else
2672
+		if ($action === 'delete') {
2673
+					$to_delete[] = (int) $pm;
2674
+		} else
2568 2675
 		{
2569 2676
 			if (substr($action, 0, 4) == 'add_')
2570 2677
 			{
2571 2678
 				$type = 'add';
2572 2679
 				$action = substr($action, 4);
2573
-			}
2574
-			elseif (substr($action, 0, 4) == 'rem_')
2680
+			} elseif (substr($action, 0, 4) == 'rem_')
2575 2681
 			{
2576 2682
 				$type = 'rem';
2577 2683
 				$action = substr($action, 4);
2684
+			} else {
2685
+							$type = 'unk';
2578 2686
 			}
2579
-			else
2580
-				$type = 'unk';
2581 2687
 
2582 2688
 			if ($action == '-1' || (int) $action > 0)
2583 2689
 			{
@@ -2588,8 +2694,9 @@  discard block
 block discarded – undo
2588 2694
 	}
2589 2695
 
2590 2696
 	// Deleting, it looks like?
2591
-	if (!empty($to_delete))
2592
-		deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2697
+	if (!empty($to_delete)) {
2698
+			deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2699
+	}
2593 2700
 
2594 2701
 	// Are we labeling anything?
2595 2702
 	if (!empty($to_label) && $context['folder'] == 'inbox')
@@ -2655,8 +2762,7 @@  discard block
 block discarded – undo
2655 2762
 				}
2656 2763
 
2657 2764
 				$smcFunc['db_free_result']($request2);
2658
-			}
2659
-			elseif ($type == 'rem')
2765
+			} elseif ($type == 'rem')
2660 2766
 			{
2661 2767
 				// If we're removing from the inbox, see if we have at least one other label.
2662 2768
 				// This query is faster than the one above
@@ -2688,21 +2794,25 @@  discard block
 block discarded – undo
2688 2794
 			if ($to_label[$row['id_pm']] != '-1')
2689 2795
 			{
2690 2796
 				// If this label is in the list and we're not adding it, remove it
2691
-				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add')
2692
-					unset($labels[$to_label[$row['id_pm']]]);
2693
-				else if ($type !== 'rem')
2694
-					$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2797
+				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') {
2798
+									unset($labels[$to_label[$row['id_pm']]]);
2799
+				} else if ($type !== 'rem') {
2800
+									$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2801
+				}
2695 2802
 			}
2696 2803
 
2697 2804
 			// Removing all labels or just removing the inbox label
2698
-			if ($type == 'rem' && empty($labels))
2699
-				$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2805
+			if ($type == 'rem' && empty($labels)) {
2806
+							$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2807
+			}
2700 2808
 			// Adding new labels, but removing inbox and applying new ones
2701
-			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels))
2702
-				$in_inbox = 0;
2809
+			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) {
2810
+							$in_inbox = 0;
2811
+			}
2703 2812
 			// Just adding it to the inbox
2704
-			else
2705
-				$in_inbox = 1;
2813
+			else {
2814
+							$in_inbox = 1;
2815
+			}
2706 2816
 
2707 2817
 			// Are we adding it to or removing it from the inbox?
2708 2818
 			if ($in_inbox != $row['in_inbox'])
@@ -2744,8 +2854,9 @@  discard block
 block discarded – undo
2744 2854
 			if (!empty($labels_to_apply))
2745 2855
 			{
2746 2856
 				$inserts = array();
2747
-				foreach ($labels_to_apply as $label)
2748
-					$inserts[] = array($row['id_pm'], $label);
2857
+				foreach ($labels_to_apply as $label) {
2858
+									$inserts[] = array($row['id_pm'], $label);
2859
+				}
2749 2860
 
2750 2861
 				$smcFunc['db_insert']('',
2751 2862
 					'{db_prefix}pm_labeled_messages',
@@ -2789,11 +2900,13 @@  discard block
 block discarded – undo
2789 2900
 	checkSession('get');
2790 2901
 
2791 2902
 	// If all then delete all messages the user has.
2792
-	if ($_REQUEST['f'] == 'all')
2793
-		deleteMessages(null, null);
2903
+	if ($_REQUEST['f'] == 'all') {
2904
+			deleteMessages(null, null);
2905
+	}
2794 2906
 	// Otherwise just the selected folder.
2795
-	else
2796
-		deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2907
+	else {
2908
+			deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2909
+	}
2797 2910
 
2798 2911
 	// Done... all gone.
2799 2912
 	redirectexit($context['current_label_redirect']);
@@ -2830,8 +2943,9 @@  discard block
 block discarded – undo
2830 2943
 				'msgtime' => $deleteTime,
2831 2944
 			)
2832 2945
 		);
2833
-		while ($row = $smcFunc['db_fetch_row']($request))
2834
-			$toDelete[] = $row[0];
2946
+		while ($row = $smcFunc['db_fetch_row']($request)) {
2947
+					$toDelete[] = $row[0];
2948
+		}
2835 2949
 		$smcFunc['db_free_result']($request);
2836 2950
 
2837 2951
 		// Select all messages in their inbox older than $deleteTime.
@@ -2848,8 +2962,9 @@  discard block
 block discarded – undo
2848 2962
 				'msgtime' => $deleteTime,
2849 2963
 			)
2850 2964
 		);
2851
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2852
-			$toDelete[] = $row['id_pm'];
2965
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2966
+					$toDelete[] = $row['id_pm'];
2967
+		}
2853 2968
 		$smcFunc['db_free_result']($request);
2854 2969
 
2855 2970
 		// Delete the actual messages.
@@ -2880,26 +2995,29 @@  discard block
 block discarded – undo
2880 2995
 {
2881 2996
 	global $user_info, $smcFunc;
2882 2997
 
2883
-	if ($owner === null)
2884
-		$owner = array($user_info['id']);
2885
-	elseif (empty($owner))
2886
-		return;
2887
-	elseif (!is_array($owner))
2888
-		$owner = array($owner);
2998
+	if ($owner === null) {
2999
+			$owner = array($user_info['id']);
3000
+	} elseif (empty($owner)) {
3001
+			return;
3002
+	} elseif (!is_array($owner)) {
3003
+			$owner = array($owner);
3004
+	}
2889 3005
 
2890 3006
 	if ($personal_messages !== null)
2891 3007
 	{
2892
-		if (empty($personal_messages) || !is_array($personal_messages))
2893
-			return;
3008
+		if (empty($personal_messages) || !is_array($personal_messages)) {
3009
+					return;
3010
+		}
2894 3011
 
2895
-		foreach ($personal_messages as $index => $delete_id)
2896
-			$personal_messages[$index] = (int) $delete_id;
3012
+		foreach ($personal_messages as $index => $delete_id) {
3013
+					$personal_messages[$index] = (int) $delete_id;
3014
+		}
2897 3015
 
2898 3016
 		$where = '
2899 3017
 				AND id_pm IN ({array_int:pm_list})';
3018
+	} else {
3019
+			$where = '';
2900 3020
 	}
2901
-	else
2902
-		$where = '';
2903 3021
 
2904 3022
 	if ($folder == 'sent' || $folder === null)
2905 3023
 	{
@@ -2934,17 +3052,19 @@  discard block
 block discarded – undo
2934 3052
 		// ...And update the statistics accordingly - now including unread messages!.
2935 3053
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2936 3054
 		{
2937
-			if ($row['is_read'])
2938
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
2939
-			else
2940
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3055
+			if ($row['is_read']) {
3056
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
3057
+			} else {
3058
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3059
+			}
2941 3060
 
2942 3061
 			// If this is the current member we need to make their message count correct.
2943 3062
 			if ($user_info['id'] == $row['id_member'])
2944 3063
 			{
2945 3064
 				$user_info['messages'] -= $row['num_deleted_messages'];
2946
-				if (!($row['is_read']))
2947
-					$user_info['unread_messages'] -= $row['num_deleted_messages'];
3065
+				if (!($row['is_read'])) {
3066
+									$user_info['unread_messages'] -= $row['num_deleted_messages'];
3067
+				}
2948 3068
 			}
2949 3069
 		}
2950 3070
 		$smcFunc['db_free_result']($request);
@@ -3012,8 +3132,9 @@  discard block
 block discarded – undo
3012 3132
 		)
3013 3133
 	);
3014 3134
 	$remove_pms = array();
3015
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3016
-		$remove_pms[] = $row['sender'];
3135
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3136
+			$remove_pms[] = $row['sender'];
3137
+	}
3017 3138
 	$smcFunc['db_free_result']($request);
3018 3139
 
3019 3140
 	if (!empty($remove_pms))
@@ -3058,8 +3179,9 @@  discard block
 block discarded – undo
3058 3179
 {
3059 3180
 	global $user_info, $context, $smcFunc;
3060 3181
 
3061
-	if ($owner === null)
3062
-		$owner = $user_info['id'];
3182
+	if ($owner === null) {
3183
+			$owner = $user_info['id'];
3184
+	}
3063 3185
 
3064 3186
 	$in_inbox = '';
3065 3187
 
@@ -3083,8 +3205,7 @@  discard block
 block discarded – undo
3083 3205
 		}
3084 3206
 
3085 3207
 		$smcFunc['db_free_result']($get_messages);
3086
-	}
3087
-	elseif ($label = '-1')
3208
+	} elseif ($label = '-1')
3088 3209
 	{
3089 3210
 		// Marking all PMs in your inbox read
3090 3211
 		$in_inbox = '
@@ -3109,8 +3230,9 @@  discard block
 block discarded – undo
3109 3230
 	{
3110 3231
 		if ($owner == $user_info['id'])
3111 3232
 		{
3112
-			foreach ($context['labels'] as $label)
3113
-				$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3233
+			foreach ($context['labels'] as $label) {
3234
+							$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3235
+			}
3114 3236
 		}
3115 3237
 
3116 3238
 		$result = $smcFunc['db_query']('', '
@@ -3130,8 +3252,9 @@  discard block
 block discarded – undo
3130 3252
 		{
3131 3253
 			$total_unread += $row['num'];
3132 3254
 
3133
-			if ($owner != $user_info['id'] || empty($row['id_pm']))
3134
-				continue;
3255
+			if ($owner != $user_info['id'] || empty($row['id_pm'])) {
3256
+							continue;
3257
+			}
3135 3258
 
3136 3259
 			$this_labels = array();
3137 3260
 
@@ -3155,11 +3278,13 @@  discard block
 block discarded – undo
3155 3278
 
3156 3279
 			$smcFunc['db_free_result']($result2);
3157 3280
 
3158
-			foreach ($this_labels as $this_label)
3159
-				$context['labels'][$this_label]['unread_messages'] += $row['num'];
3281
+			foreach ($this_labels as $this_label) {
3282
+							$context['labels'][$this_label]['unread_messages'] += $row['num'];
3283
+			}
3160 3284
 
3161
-			if ($row['in_inbox'] == 1)
3162
-				$context['labels'][-1]['unread_messages'] += $row['num'];
3285
+			if ($row['in_inbox'] == 1) {
3286
+							$context['labels'][-1]['unread_messages'] += $row['num'];
3287
+			}
3163 3288
 		}
3164 3289
 		$smcFunc['db_free_result']($result);
3165 3290
 
@@ -3168,8 +3293,9 @@  discard block
 block discarded – undo
3168 3293
 		updateMemberData($owner, array('unread_messages' => $total_unread));
3169 3294
 
3170 3295
 		// If it was for the current member, reflect this in the $user_info array too.
3171
-		if ($owner == $user_info['id'])
3172
-			$user_info['unread_messages'] = $total_unread;
3296
+		if ($owner == $user_info['id']) {
3297
+					$user_info['unread_messages'] = $total_unread;
3298
+		}
3173 3299
 	}
3174 3300
 }
3175 3301
 
@@ -3197,8 +3323,9 @@  discard block
 block discarded – undo
3197 3323
 	// Add all existing labels to the array to save, slashing them as necessary...
3198 3324
 	foreach ($context['labels'] as $label)
3199 3325
 	{
3200
-		if ($label['id'] != -1)
3201
-			$the_labels[$label['id']] = $label['name'];
3326
+		if ($label['id'] != -1) {
3327
+					$the_labels[$label['id']] = $label['name'];
3328
+		}
3202 3329
 	}
3203 3330
 
3204 3331
 	if (isset($_POST[$context['session_var']]))
@@ -3217,8 +3344,9 @@  discard block
 block discarded – undo
3217 3344
 		{
3218 3345
 			$_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => '&#044;'));
3219 3346
 
3220
-			if ($smcFunc['strlen']($_POST['label']) > 30)
3221
-				$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3347
+			if ($smcFunc['strlen']($_POST['label']) > 30) {
3348
+							$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3349
+			}
3222 3350
 			if ($_POST['label'] != '')
3223 3351
 			{
3224 3352
 				$the_labels[] = $_POST['label'];
@@ -3239,24 +3367,25 @@  discard block
 block discarded – undo
3239 3367
 		{
3240 3368
 			foreach ($the_labels as $id => $name)
3241 3369
 			{
3242
-				if ($id == -1)
3243
-					continue;
3244
-				elseif (isset($_POST['label_name'][$id]))
3370
+				if ($id == -1) {
3371
+									continue;
3372
+				} elseif (isset($_POST['label_name'][$id]))
3245 3373
 				{
3246 3374
 					$_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => '&#044;')));
3247 3375
 
3248
-					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30)
3249
-						$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3376
+					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) {
3377
+											$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3378
+					}
3250 3379
 					if ($_POST['label_name'][$id] != '')
3251 3380
 					{
3252 3381
 						// Changing the name of this label?
3253
-						if ($the_labels[$id] != $_POST['label_name'][$id])
3254
-							$label_updates[$id] = $_POST['label_name'][$id];
3382
+						if ($the_labels[$id] != $_POST['label_name'][$id]) {
3383
+													$label_updates[$id] = $_POST['label_name'][$id];
3384
+						}
3255 3385
 
3256 3386
 						$the_labels[(int) $id] = $_POST['label_name'][$id];
3257 3387
 
3258
-					}
3259
-					else
3388
+					} else
3260 3389
 					{
3261 3390
 						unset($the_labels[(int) $id]);
3262 3391
 						$labels_to_remove[] = $id;
@@ -3270,8 +3399,9 @@  discard block
 block discarded – undo
3270 3399
 		if (!empty($labels_to_add))
3271 3400
 		{
3272 3401
 			$inserts = array();
3273
-			foreach ($labels_to_add AS $label)
3274
-				$inserts[] = array($user_info['id'], $label);
3402
+			foreach ($labels_to_add AS $label) {
3403
+							$inserts[] = array($user_info['id'], $label);
3404
+			}
3275 3405
 
3276 3406
 			$smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
3277 3407
 		}
@@ -3361,8 +3491,9 @@  discard block
 block discarded – undo
3361 3491
 				// Each action...
3362 3492
 				foreach ($rule['actions'] as $k2 => $action)
3363 3493
 				{
3364
-					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove))
3365
-						continue;
3494
+					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) {
3495
+											continue;
3496
+					}
3366 3497
 
3367 3498
 					$rule_changes[] = $rule['id'];
3368 3499
 
@@ -3377,8 +3508,8 @@  discard block
 block discarded – undo
3377 3508
 		{
3378 3509
 			$rule_changes = array_unique($rule_changes);
3379 3510
 			// Update/delete as appropriate.
3380
-			foreach ($rule_changes as $k => $id)
3381
-				if (!empty($context['rules'][$id]['actions']))
3511
+			foreach ($rule_changes as $k => $id) {
3512
+							if (!empty($context['rules'][$id]['actions']))
3382 3513
 				{
3383 3514
 					$smcFunc['db_query']('', '
3384 3515
 						UPDATE {db_prefix}pm_rules
@@ -3391,12 +3522,13 @@  discard block
 block discarded – undo
3391 3522
 							'actions' => $smcFunc['json_encode']($context['rules'][$id]['actions']),
3392 3523
 						)
3393 3524
 					);
3525
+			}
3394 3526
 					unset($rule_changes[$k]);
3395 3527
 				}
3396 3528
 
3397 3529
 			// Anything left here means it's lost all actions...
3398
-			if (!empty($rule_changes))
3399
-				$smcFunc['db_query']('', '
3530
+			if (!empty($rule_changes)) {
3531
+							$smcFunc['db_query']('', '
3400 3532
 					DELETE FROM {db_prefix}pm_rules
3401 3533
 					WHERE id_rule IN ({array_int:rule_list})
3402 3534
 							AND id_member = {int:current_member}',
@@ -3405,6 +3537,7 @@  discard block
 block discarded – undo
3405 3537
 						'rule_list' => $rule_changes,
3406 3538
 					)
3407 3539
 				);
3540
+			}
3408 3541
 		}
3409 3542
 
3410 3543
 		// Make sure we're not caching this!
@@ -3474,8 +3607,9 @@  discard block
 block discarded – undo
3474 3607
 		// Save the fields.
3475 3608
 		saveProfileFields();
3476 3609
 
3477
-		if (!empty($profile_vars))
3478
-			updateMemberData($user_info['id'], $profile_vars);
3610
+		if (!empty($profile_vars)) {
3611
+					updateMemberData($user_info['id'], $profile_vars);
3612
+		}
3479 3613
 	}
3480 3614
 
3481 3615
 	setupProfileContext(
@@ -3500,13 +3634,15 @@  discard block
 block discarded – undo
3500 3634
 	global $user_info, $language, $modSettings, $smcFunc;
3501 3635
 
3502 3636
 	// Check that this feature is even enabled!
3503
-	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg']))
3504
-		fatal_lang_error('no_access', false);
3637
+	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) {
3638
+			fatal_lang_error('no_access', false);
3639
+	}
3505 3640
 
3506 3641
 	$pmsg = (int) $_REQUEST['pmsg'];
3507 3642
 
3508
-	if (!isAccessiblePM($pmsg, 'inbox'))
3509
-		fatal_lang_error('no_access', false);
3643
+	if (!isAccessiblePM($pmsg, 'inbox')) {
3644
+			fatal_lang_error('no_access', false);
3645
+	}
3510 3646
 
3511 3647
 	$context['pm_id'] = $pmsg;
3512 3648
 	$context['page_title'] = $txt['pm_report_title'];
@@ -3528,8 +3664,9 @@  discard block
 block discarded – undo
3528 3664
 			)
3529 3665
 		);
3530 3666
 		$context['admins'] = array();
3531
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3532
-			$context['admins'][$row['id_member']] = $row['real_name'];
3667
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3668
+					$context['admins'][$row['id_member']] = $row['real_name'];
3669
+		}
3533 3670
 		$smcFunc['db_free_result']($request);
3534 3671
 
3535 3672
 		// How many admins in total?
@@ -3558,8 +3695,9 @@  discard block
 block discarded – undo
3558 3695
 			)
3559 3696
 		);
3560 3697
 		// Can only be a hacker here!
3561
-		if ($smcFunc['db_num_rows']($request) == 0)
3562
-			fatal_lang_error('no_access', false);
3698
+		if ($smcFunc['db_num_rows']($request) == 0) {
3699
+					fatal_lang_error('no_access', false);
3700
+		}
3563 3701
 		list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request);
3564 3702
 		$smcFunc['db_free_result']($request);
3565 3703
 
@@ -3583,15 +3721,17 @@  discard block
 block discarded – undo
3583 3721
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3584 3722
 		{
3585 3723
 			// If it's hidden still don't reveal their names - privacy after all ;)
3586
-			if ($row['bcc'])
3587
-				$hidden_recipients++;
3588
-			else
3589
-				$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3724
+			if ($row['bcc']) {
3725
+							$hidden_recipients++;
3726
+			} else {
3727
+							$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3728
+			}
3590 3729
 		}
3591 3730
 		$smcFunc['db_free_result']($request);
3592 3731
 
3593
-		if ($hidden_recipients)
3594
-			$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3732
+		if ($hidden_recipients) {
3733
+					$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3734
+		}
3595 3735
 
3596 3736
 		// Now let's get out and loop through the admins.
3597 3737
 		$request = $smcFunc['db_query']('', '
@@ -3607,8 +3747,9 @@  discard block
 block discarded – undo
3607 3747
 		);
3608 3748
 
3609 3749
 		// Maybe we shouldn't advertise this?
3610
-		if ($smcFunc['db_num_rows']($request) == 0)
3611
-			fatal_lang_error('no_access', false);
3750
+		if ($smcFunc['db_num_rows']($request) == 0) {
3751
+					fatal_lang_error('no_access', false);
3752
+		}
3612 3753
 
3613 3754
 		$memberFromName = un_htmlspecialchars($memberFromName);
3614 3755
 
@@ -3627,8 +3768,9 @@  discard block
 block discarded – undo
3627 3768
 				// Make the body.
3628 3769
 				$report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']);
3629 3770
 				$report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n";
3630
-				if (!empty($recipients))
3631
-					$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3771
+				if (!empty($recipients)) {
3772
+									$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3773
+				}
3632 3774
 				$report_body .= $txt['pm_report_pm_unedited_below'] . "\n" . '[quote author=' . (empty($memberFromID) ? '&quot;' . $memberFromName . '&quot;' : $memberFromName . ' link=action=profile;u=' . $memberFromID . ' date=' . $time) . ']' . "\n" . un_htmlspecialchars($body) . '[/quote]';
3633 3775
 
3634 3776
 				// Plonk it in the array ;)
@@ -3648,12 +3790,14 @@  discard block
 block discarded – undo
3648 3790
 		$smcFunc['db_free_result']($request);
3649 3791
 
3650 3792
 		// Send a different email for each language.
3651
-		foreach ($messagesToSend as $lang => $message)
3652
-			sendpm($message['recipients'], $message['subject'], $message['body']);
3793
+		foreach ($messagesToSend as $lang => $message) {
3794
+					sendpm($message['recipients'], $message['subject'], $message['body']);
3795
+		}
3653 3796
 
3654 3797
 		// Give the user their own language back!
3655
-		if (!empty($modSettings['userLanguage']))
3656
-			loadLanguage('PersonalMessage', '', false);
3798
+		if (!empty($modSettings['userLanguage'])) {
3799
+					loadLanguage('PersonalMessage', '', false);
3800
+		}
3657 3801
 
3658 3802
 		// Leave them with a template.
3659 3803
 		$context['sub_template'] = 'report_message_complete';
@@ -3699,8 +3843,9 @@  discard block
 block discarded – undo
3699 3843
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3700 3844
 	{
3701 3845
 		// Hide hidden groups!
3702
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
3703
-			continue;
3846
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
3847
+					continue;
3848
+		}
3704 3849
 
3705 3850
 		$context['groups'][$row['id_group']] = $row['group_name'];
3706 3851
 	}
@@ -3726,9 +3871,10 @@  discard block
 block discarded – undo
3726 3871
 			$context['rule'] = $context['rules'][$context['rid']];
3727 3872
 			$members = array();
3728 3873
 			// Need to get member names!
3729
-			foreach ($context['rule']['criteria'] as $k => $criteria)
3730
-				if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3874
+			foreach ($context['rule']['criteria'] as $k => $criteria) {
3875
+							if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3731 3876
 					$members[(int) $criteria['v']] = $k;
3877
+			}
3732 3878
 
3733 3879
 			if (!empty($members))
3734 3880
 			{
@@ -3740,19 +3886,20 @@  discard block
 block discarded – undo
3740 3886
 						'member_list' => array_keys($members),
3741 3887
 					)
3742 3888
 				);
3743
-				while ($row = $smcFunc['db_fetch_assoc']($request))
3744
-					$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3889
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
3890
+									$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3891
+				}
3745 3892
 				$smcFunc['db_free_result']($request);
3746 3893
 			}
3747
-		}
3748
-		else
3749
-			$context['rule'] = array(
3894
+		} else {
3895
+					$context['rule'] = array(
3750 3896
 				'id' => '',
3751 3897
 				'name' => '',
3752 3898
 				'criteria' => array(),
3753 3899
 				'actions' => array(),
3754 3900
 				'logic' => 'and',
3755 3901
 			);
3902
+		}
3756 3903
 	}
3757 3904
 	// Saving?
3758 3905
 	elseif (isset($_GET['save']))
@@ -3762,22 +3909,25 @@  discard block
 block discarded – undo
3762 3909
 
3763 3910
 		// Name is easy!
3764 3911
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
3765
-		if (empty($ruleName))
3766
-			fatal_lang_error('pm_rule_no_name', false);
3912
+		if (empty($ruleName)) {
3913
+					fatal_lang_error('pm_rule_no_name', false);
3914
+		}
3767 3915
 
3768 3916
 		// Sanity check...
3769
-		if (empty($_POST['ruletype']) || empty($_POST['acttype']))
3770
-			fatal_lang_error('pm_rule_no_criteria', false);
3917
+		if (empty($_POST['ruletype']) || empty($_POST['acttype'])) {
3918
+					fatal_lang_error('pm_rule_no_criteria', false);
3919
+		}
3771 3920
 
3772 3921
 		// Let's do the criteria first - it's also hardest!
3773 3922
 		$criteria = array();
3774 3923
 		foreach ($_POST['ruletype'] as $ind => $type)
3775 3924
 		{
3776 3925
 			// Check everything is here...
3777
-			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]])))
3778
-				continue;
3779
-			elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind]))
3780
-				continue;
3926
+			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) {
3927
+							continue;
3928
+			} elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) {
3929
+							continue;
3930
+			}
3781 3931
 
3782 3932
 			// Members need to be found.
3783 3933
 			if ($type == 'mid')
@@ -3801,13 +3951,13 @@  discard block
 block discarded – undo
3801 3951
 				$smcFunc['db_free_result']($request);
3802 3952
 
3803 3953
 				$criteria[] = array('t' => 'mid', 'v' => $memID);
3954
+			} elseif ($type == 'bud') {
3955
+							$criteria[] = array('t' => 'bud', 'v' => 1);
3956
+			} elseif ($type == 'gid') {
3957
+							$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3958
+			} elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') {
3959
+							$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3804 3960
 			}
3805
-			elseif ($type == 'bud')
3806
-				$criteria[] = array('t' => 'bud', 'v' => 1);
3807
-			elseif ($type == 'gid')
3808
-				$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3809
-			elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '')
3810
-				$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3811 3961
 		}
3812 3962
 
3813 3963
 		// Also do the actions!
@@ -3817,26 +3967,29 @@  discard block
 block discarded – undo
3817 3967
 		foreach ($_POST['acttype'] as $ind => $type)
3818 3968
 		{
3819 3969
 			// Picking a valid label?
3820
-			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]])))
3821
-				continue;
3970
+			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) {
3971
+							continue;
3972
+			}
3822 3973
 
3823 3974
 			// Record what we're doing.
3824
-			if ($type == 'del')
3825
-				$doDelete = 1;
3826
-			elseif ($type == 'lab')
3827
-				$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3975
+			if ($type == 'del') {
3976
+							$doDelete = 1;
3977
+			} elseif ($type == 'lab') {
3978
+							$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3979
+			}
3828 3980
 		}
3829 3981
 
3830
-		if (empty($criteria) || (empty($actions) && !$doDelete))
3831
-			fatal_lang_error('pm_rule_no_criteria', false);
3982
+		if (empty($criteria) || (empty($actions) && !$doDelete)) {
3983
+					fatal_lang_error('pm_rule_no_criteria', false);
3984
+		}
3832 3985
 
3833 3986
 		// What are we storing?
3834 3987
 		$criteria = $smcFunc['json_encode']($criteria);
3835 3988
 		$actions = $smcFunc['json_encode']($actions);
3836 3989
 
3837 3990
 		// Create the rule?
3838
-		if (empty($context['rid']))
3839
-			$smcFunc['db_insert']('',
3991
+		if (empty($context['rid'])) {
3992
+					$smcFunc['db_insert']('',
3840 3993
 				'{db_prefix}pm_rules',
3841 3994
 				array(
3842 3995
 					'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string',
@@ -3847,8 +4000,8 @@  discard block
 block discarded – undo
3847 4000
 				),
3848 4001
 				array('id_rule')
3849 4002
 			);
3850
-		else
3851
-			$smcFunc['db_query']('', '
4003
+		} else {
4004
+					$smcFunc['db_query']('', '
3852 4005
 				UPDATE {db_prefix}pm_rules
3853 4006
 				SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions},
3854 4007
 					delete_pm = {int:delete_pm}, is_or = {int:is_or}
@@ -3864,6 +4017,7 @@  discard block
 block discarded – undo
3864 4017
 					'actions' => $actions,
3865 4018
 				)
3866 4019
 			);
4020
+		}
3867 4021
 
3868 4022
 		redirectexit('action=pm;sa=manrules');
3869 4023
 	}
@@ -3872,11 +4026,12 @@  discard block
 block discarded – undo
3872 4026
 	{
3873 4027
 		checkSession();
3874 4028
 		$toDelete = array();
3875
-		foreach ($_POST['delrule'] as $k => $v)
3876
-			$toDelete[] = (int) $k;
4029
+		foreach ($_POST['delrule'] as $k => $v) {
4030
+					$toDelete[] = (int) $k;
4031
+		}
3877 4032
 
3878
-		if (!empty($toDelete))
3879
-			$smcFunc['db_query']('', '
4033
+		if (!empty($toDelete)) {
4034
+					$smcFunc['db_query']('', '
3880 4035
 				DELETE FROM {db_prefix}pm_rules
3881 4036
 				WHERE id_rule IN ({array_int:delete_list})
3882 4037
 					AND id_member = {int:current_member}',
@@ -3885,6 +4040,7 @@  discard block
 block discarded – undo
3885 4040
 					'delete_list' => $toDelete,
3886 4041
 				)
3887 4042
 			);
4043
+		}
3888 4044
 
3889 4045
 		redirectexit('action=pm;sa=manrules');
3890 4046
 	}
@@ -3903,8 +4059,9 @@  discard block
 block discarded – undo
3903 4059
 	loadRules();
3904 4060
 
3905 4061
 	// No rules?
3906
-	if (empty($context['rules']))
3907
-		return;
4062
+	if (empty($context['rules'])) {
4063
+			return;
4064
+	}
3908 4065
 
3909 4066
 	// Just unread ones?
3910 4067
 	$ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1';
@@ -3934,8 +4091,9 @@  discard block
 block discarded – undo
3934 4091
 			// Loop through all the criteria hoping to make a match.
3935 4092
 			foreach ($rule['criteria'] as $criterium)
3936 4093
 			{
3937
-				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false))
3938
-					$match = true;
4094
+				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) {
4095
+									$match = true;
4096
+				}
3939 4097
 				// If we're adding and one criteria don't match then we stop!
3940 4098
 				elseif ($rule['logic'] == 'and')
3941 4099
 				{
@@ -3947,17 +4105,18 @@  discard block
 block discarded – undo
3947 4105
 			// If we have a match the rule must be true - act!
3948 4106
 			if ($match)
3949 4107
 			{
3950
-				if ($rule['delete'])
3951
-					$actions['deletes'][] = $row['id_pm'];
3952
-				else
4108
+				if ($rule['delete']) {
4109
+									$actions['deletes'][] = $row['id_pm'];
4110
+				} else
3953 4111
 				{
3954 4112
 					foreach ($rule['actions'] as $ruleAction)
3955 4113
 					{
3956 4114
 						if ($ruleAction['t'] == 'lab')
3957 4115
 						{
3958 4116
 							// Get a basic pot started!
3959
-							if (!isset($actions['labels'][$row['id_pm']]))
3960
-								$actions['labels'][$row['id_pm']] = array();
4117
+							if (!isset($actions['labels'][$row['id_pm']])) {
4118
+															$actions['labels'][$row['id_pm']] = array();
4119
+							}
3961 4120
 							$actions['labels'][$row['id_pm']][] = $ruleAction['v'];
3962 4121
 						}
3963 4122
 					}
@@ -3968,8 +4127,9 @@  discard block
 block discarded – undo
3968 4127
 	$smcFunc['db_free_result']($request);
3969 4128
 
3970 4129
 	// Deletes are easy!
3971
-	if (!empty($actions['deletes']))
3972
-		deleteMessages($actions['deletes']);
4130
+	if (!empty($actions['deletes'])) {
4131
+			deleteMessages($actions['deletes']);
4132
+	}
3973 4133
 
3974 4134
 	// Relabel?
3975 4135
 	if (!empty($actions['labels']))
@@ -3996,8 +4156,7 @@  discard block
 block discarded – undo
3996 4156
 								'current_member' => $user_info['id'],
3997 4157
 							)
3998 4158
 						);
3999
-					}
4000
-					else
4159
+					} else
4001 4160
 					{
4002 4161
 						$realLabels[] = $label['id'];
4003 4162
 					}
@@ -4006,8 +4165,9 @@  discard block
 block discarded – undo
4006 4165
 
4007 4166
 			$inserts = array();
4008 4167
 			// Now we insert the label info
4009
-			foreach ($realLabels as $a_label)
4010
-				$inserts[] = array($pm, $a_label);
4168
+			foreach ($realLabels as $a_label) {
4169
+							$inserts[] = array($pm, $a_label);
4170
+			}
4011 4171
 
4012 4172
 			$smcFunc['db_insert']('ignore',
4013 4173
 				'{db_prefix}pm_labeled_messages',
@@ -4028,8 +4188,9 @@  discard block
 block discarded – undo
4028 4188
 {
4029 4189
 	global $user_info, $context, $smcFunc;
4030 4190
 
4031
-	if (isset($context['rules']) && !$reload)
4032
-		return;
4191
+	if (isset($context['rules']) && !$reload) {
4192
+			return;
4193
+	}
4033 4194
 
4034 4195
 	$request = $smcFunc['db_query']('', '
4035 4196
 		SELECT
@@ -4053,8 +4214,9 @@  discard block
 block discarded – undo
4053 4214
 			'logic' => $row['is_or'] ? 'or' : 'and',
4054 4215
 		);
4055 4216
 
4056
-		if ($row['delete_pm'])
4057
-			$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4217
+		if ($row['delete_pm']) {
4218
+					$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4219
+		}
4058 4220
 	}
4059 4221
 	$smcFunc['db_free_result']($request);
4060 4222
 }
Please login to merge, or discard this patch.