Completed
Push — release-2.1 ( e39a06...35b3d8 )
by Mathias
07:09
created
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 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -474,7 +474,7 @@
 block discarded – undo
474 474
  * Used by fatal_error(), fatal_lang_error()
475 475
  *
476 476
  * @param string $error The error
477
- * @param array $sprintf An array of data to be sprintf()'d into the specified message
477
+ * @param boolean $sprintf An array of data to be sprintf()'d into the specified message
478 478
  */
479 479
 function log_error_online($error, $sprintf = array())
480 480
 {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
 	$error_call++;
40 40
 
41 41
 	// are we in a loop?
42
-	if($error_call > 2)
42
+	if ($error_call > 2)
43 43
 	{
44 44
 		if (!isset($db_show_debug) || $db_show_debug === false)
45 45
 			$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
Please login to merge, or discard this patch.
Braces   +125 added lines, -89 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.
@@ -41,17 +42,19 @@  discard block
 block discarded – undo
41 42
 	// are we in a loop?
42 43
 	if($error_call > 2)
43 44
 	{
44
-		if (!isset($db_show_debug) || $db_show_debug === false)
45
-			$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
46
-		else
47
-			$backtrace = debug_backtrace();
45
+		if (!isset($db_show_debug) || $db_show_debug === false) {
46
+					$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
47
+		} else {
48
+					$backtrace = debug_backtrace();
49
+		}
48 50
 		var_dump($backtrace);
49 51
 		die('Error loop.');
50 52
 	}
51 53
 
52 54
 	// Check if error logging is actually on.
53
-	if (empty($modSettings['enableErrorLogging']))
54
-		return $error_message;
55
+	if (empty($modSettings['enableErrorLogging'])) {
56
+			return $error_message;
57
+	}
55 58
 
56 59
 	// Basically, htmlspecialchars it minus &. (for entities!)
57 60
 	$error_message = strtr($error_message, array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;'));
@@ -59,33 +62,39 @@  discard block
 block discarded – undo
59 62
 
60 63
 	// Add a file and line to the error message?
61 64
 	// Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line
62
-	if ($file == null)
63
-		$file = '';
64
-	else
65
-		// Window style slashes don't play well, lets convert them to the unix style.
65
+	if ($file == null) {
66
+			$file = '';
67
+	} else {
68
+			// Window style slashes don't play well, lets convert them to the unix style.
66 69
 		$file = str_replace('\\', '/', $file);
70
+	}
67 71
 
68
-	if ($line == null)
69
-		$line = 0;
70
-	else
71
-		$line = (int) $line;
72
+	if ($line == null) {
73
+			$line = 0;
74
+	} else {
75
+			$line = (int) $line;
76
+	}
72 77
 
73 78
 	// Just in case there's no id_member or IP set yet.
74
-	if (empty($user_info['id']))
75
-		$user_info['id'] = 0;
76
-	if (empty($user_info['ip']))
77
-		$user_info['ip'] = '';
79
+	if (empty($user_info['id'])) {
80
+			$user_info['id'] = 0;
81
+	}
82
+	if (empty($user_info['ip'])) {
83
+			$user_info['ip'] = '';
84
+	}
78 85
 
79 86
 	// Find the best query string we can...
80 87
 	$query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];
81 88
 
82 89
 	// Don't log the session hash in the url twice, it's a waste.
83
-	if (!empty($smcFunc['htmlspecialchars']))
84
-		$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
90
+	if (!empty($smcFunc['htmlspecialchars'])) {
91
+			$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
92
+	}
85 93
 
86 94
 	// Just so we know what board error messages are from.
87
-	if (isset($_POST['board']) && !isset($_GET['board']))
88
-		$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
95
+	if (isset($_POST['board']) && !isset($_GET['board'])) {
96
+			$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
97
+	}
89 98
 
90 99
 	// What types of categories do we have?
91 100
 	$known_error_types = array(
@@ -146,12 +155,14 @@  discard block
 block discarded – undo
146 155
 	global $txt;
147 156
 
148 157
 	// Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all
149
-	if (!empty($status))
150
-		send_http_status($status);
158
+	if (!empty($status)) {
159
+			send_http_status($status);
160
+	}
151 161
 
152 162
 	// We don't have $txt yet, but that's okay...
153
-	if (empty($txt))
154
-		die($error);
163
+	if (empty($txt)) {
164
+			die($error);
165
+	}
155 166
 
156 167
 	log_error_online($error, false);
157 168
 	setup_fatal_error_context($log ? log_error($error, $log) : $error);
@@ -178,8 +189,9 @@  discard block
 block discarded – undo
178 189
 	static $fatal_error_called = false;
179 190
 
180 191
 	// Send the status header - set this to 0 or false if you don't want to send one at all
181
-	if (!empty($status))
182
-		send_http_status($status);
192
+	if (!empty($status)) {
193
+			send_http_status($status);
194
+	}
183 195
 
184 196
 	// Try to load a theme if we don't have one.
185 197
 	if (empty($context['theme_loaded']) && empty($fatal_error_called))
@@ -189,8 +201,9 @@  discard block
 block discarded – undo
189 201
 	}
190 202
 
191 203
 	// If we have no theme stuff we can't have the language file...
192
-	if (empty($context['theme_loaded']))
193
-		die($error);
204
+	if (empty($context['theme_loaded'])) {
205
+			die($error);
206
+	}
194 207
 
195 208
 	$reload_lang_file = true;
196 209
 	// Log the error in the forum's language, but don't waste the time if we aren't logging
@@ -226,8 +239,9 @@  discard block
 block discarded – undo
226 239
 	global $settings, $modSettings, $db_show_debug;
227 240
 
228 241
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5
229
-	if (error_reporting() == 0)
230
-		return;
242
+	if (error_reporting() == 0) {
243
+			return;
244
+	}
231 245
 
232 246
 	if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename']))
233 247
 	{
@@ -235,19 +249,22 @@  discard block
 block discarded – undo
235 249
 		$count = count($array);
236 250
 		for ($i = 0; $i < $count; $i++)
237 251
 		{
238
-			if ($array[$i]['function'] != 'loadSubTemplate')
239
-				continue;
252
+			if ($array[$i]['function'] != 'loadSubTemplate') {
253
+							continue;
254
+			}
240 255
 
241 256
 			// This is a bug in PHP, with eval, it seems!
242
-			if (empty($array[$i]['args']))
243
-				$i++;
257
+			if (empty($array[$i]['args'])) {
258
+							$i++;
259
+			}
244 260
 			break;
245 261
 		}
246 262
 
247
-		if (isset($array[$i]) && !empty($array[$i]['args']))
248
-			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
249
-		else
250
-			$file = realpath($settings['current_include_filename']) . ' (eval?)';
263
+		if (isset($array[$i]) && !empty($array[$i]['args'])) {
264
+					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
265
+		} else {
266
+					$file = realpath($settings['current_include_filename']) . ' (eval?)';
267
+		}
251 268
 	}
252 269
 
253 270
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -256,8 +273,9 @@  discard block
 block discarded – undo
256 273
 		if ($error_level % 255 != E_ERROR)
257 274
 		{
258 275
 			$temporary = ob_get_contents();
259
-			if (substr($temporary, -2) == '="')
260
-				echo '"';
276
+			if (substr($temporary, -2) == '="') {
277
+							echo '"';
278
+			}
261 279
 		}
262 280
 
263 281
 		// Debugging!  This should look like a PHP error message.
@@ -273,23 +291,27 @@  discard block
 block discarded – undo
273 291
 	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line));
274 292
 
275 293
 	// Dying on these errors only causes MORE problems (blank pages!)
276
-	if ($file == 'Unknown')
277
-		return;
294
+	if ($file == 'Unknown') {
295
+			return;
296
+	}
278 297
 
279 298
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
280
-	if ($error_level % 255 == E_ERROR)
281
-		obExit(false);
282
-	else
283
-		return;
299
+	if ($error_level % 255 == E_ERROR) {
300
+			obExit(false);
301
+	} else {
302
+			return;
303
+	}
284 304
 
285 305
 	// If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die.  Violently so.
286
-	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING)
287
-		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
306
+	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) {
307
+			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
308
+	}
288 309
 
289 310
 	// We should NEVER get to this point.  Any fatal error MUST quit, or very bad things can happen.
290
-	if ($error_level % 255 == E_ERROR)
291
-		die('No direct access...');
292
-}
311
+	if ($error_level % 255 == E_ERROR) {
312
+			die('No direct access...');
313
+	}
314
+	}
293 315
 
294 316
 /**
295 317
  * It is called by {@link fatal_error()} and {@link fatal_lang_error()}.
@@ -305,24 +327,28 @@  discard block
 block discarded – undo
305 327
 
306 328
 	// Attempt to prevent a recursive loop.
307 329
 	++$level;
308
-	if ($level > 1)
309
-		return false;
330
+	if ($level > 1) {
331
+			return false;
332
+	}
310 333
 
311 334
 	// Maybe they came from dlattach or similar?
312
-	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded']))
313
-		loadTheme();
335
+	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) {
336
+			loadTheme();
337
+	}
314 338
 
315 339
 	// Don't bother indexing errors mate...
316 340
 	$context['robot_no_index'] = true;
317 341
 
318
-	if (!isset($context['error_title']))
319
-		$context['error_title'] = $txt['error_occured'];
342
+	if (!isset($context['error_title'])) {
343
+			$context['error_title'] = $txt['error_occured'];
344
+	}
320 345
 	$context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
321 346
 
322 347
 	$context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : '';
323 348
 
324
-	if (empty($context['page_title']))
325
-		$context['page_title'] = $context['error_title'];
349
+	if (empty($context['page_title'])) {
350
+			$context['page_title'] = $context['error_title'];
351
+	}
326 352
 
327 353
 	loadTemplate('Errors');
328 354
 	$context['sub_template'] = 'fatal_error';
@@ -330,23 +356,26 @@  discard block
 block discarded – undo
330 356
 	// If this is SSI, what do they want us to do?
331 357
 	if (SMF == 'SSI')
332 358
 	{
333
-		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method))
334
-			$ssi_on_error_method();
335
-		elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
336
-			loadSubTemplate('fatal_error');
359
+		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
360
+					$ssi_on_error_method();
361
+		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
362
+					loadSubTemplate('fatal_error');
363
+		}
337 364
 
338 365
 		// No layers?
339
-		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
340
-			exit;
366
+		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
367
+					exit;
368
+		}
341 369
 	}
342 370
 	// Alternatively from the cron call?
343 371
 	elseif (SMF == 'BACKGROUND')
344 372
 	{
345 373
 		// We can't rely on even having language files available.
346
-		if (defined('FROM_CLI') && FROM_CLI)
347
-			echo 'cron error: ', $context['error_message'];
348
-		else
349
-			echo 'An error occurred. More information may be available in your logs.';
374
+		if (defined('FROM_CLI') && FROM_CLI) {
375
+					echo 'cron error: ', $context['error_message'];
376
+		} else {
377
+					echo 'An error occurred. More information may be available in your logs.';
378
+		}
350 379
 		exit;
351 380
 	}
352 381
 
@@ -374,8 +403,8 @@  discard block
 block discarded – undo
374 403
 
375 404
 	set_fatal_error_headers();
376 405
 
377
-	if (!empty($maintenance))
378
-		echo '<!DOCTYPE html>
406
+	if (!empty($maintenance)) {
407
+			echo '<!DOCTYPE html>
379 408
 <html>
380 409
 	<head>
381 410
 		<meta name="robots" content="noindex">
@@ -386,6 +415,7 @@  discard block
 block discarded – undo
386 415
 		', $mmessage, '
387 416
 	</body>
388 417
 </html>';
418
+	}
389 419
 
390 420
 	die();
391 421
 }
@@ -407,15 +437,17 @@  discard block
 block discarded – undo
407 437
 	// For our purposes, we're gonna want this on if at all possible.
408 438
 	$modSettings['cache_enable'] = '1';
409 439
 
410
-	if (($temp = cache_get_data('db_last_error', 600)) !== null)
411
-		$db_last_error = max($db_last_error, $temp);
440
+	if (($temp = cache_get_data('db_last_error', 600)) !== null) {
441
+			$db_last_error = max($db_last_error, $temp);
442
+	}
412 443
 
413 444
 	if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send))
414 445
 	{
415 446
 		// Avoid writing to the Settings.php file if at all possible; use shared memory instead.
416 447
 		cache_put_data('db_last_error', time(), 600);
417
-		if (($temp = cache_get_data('db_last_error', 600)) === null)
418
-			logLastDatabaseError();
448
+		if (($temp = cache_get_data('db_last_error', 600)) === null) {
449
+					logLastDatabaseError();
450
+		}
419 451
 
420 452
 		// Language files aren't loaded yet :(.
421 453
 		$db_error = @$smcFunc['db_error']($db_connection);
@@ -496,12 +528,14 @@  discard block
 block discarded – undo
496 528
 	global $smcFunc, $user_info, $modSettings;
497 529
 
498 530
 	// Don't bother if Who's Online is disabled.
499
-	if (empty($modSettings['who_enabled']))
500
-		return;
531
+	if (empty($modSettings['who_enabled'])) {
532
+			return;
533
+	}
501 534
 
502 535
 	// Maybe they came from SSI or similar where sessions are not recorded?
503
-	if (SMF == 'SSI' || SMF == 'BACKGROUND')
504
-		return;
536
+	if (SMF == 'SSI' || SMF == 'BACKGROUND') {
537
+			return;
538
+	}
505 539
 
506 540
 	$session_id = !empty($user_info['is_guest']) ? 'ip' . $user_info['ip'] : session_id();
507 541
 
@@ -527,8 +561,9 @@  discard block
 block discarded – undo
527 561
 		$url = $smcFunc['json_decode']($url, true);
528 562
 		$url['error'] = $error;
529 563
 
530
-		if (!empty($sprintf))
531
-			$url['error_params'] = $sprintf;
564
+		if (!empty($sprintf)) {
565
+					$url['error_params'] = $sprintf;
566
+		}
532 567
 
533 568
 		$smcFunc['db_query']('', '
534 569
 			UPDATE {db_prefix}log_online
@@ -559,10 +594,11 @@  discard block
 block discarded – undo
559 594
 
560 595
 	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
561 596
 
562
-	if (!isset($statuses[$code]))
563
-		header($protocol . ' 500 Internal Server Error');
564
-	else
565
-		header($protocol . ' ' . $code . ' ' . $statuses[$code]);
566
-}
597
+	if (!isset($statuses[$code])) {
598
+			header($protocol . ' 500 Internal Server Error');
599
+	} else {
600
+			header($protocol . ' ' . $code . ' ' . $statuses[$code]);
601
+	}
602
+	}
567 603
 
568 604
 ?>
569 605
\ 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;
@@ -2166,9 +2166,9 @@  discard block
 block discarded – undo
2166 2166
 
2167 2167
 	if ($low == '255.255.255.255') return 'unknown';
2168 2168
 	if ($low == $high)
2169
-	    return $low;
2169
+		return $low;
2170 2170
 	else
2171
-	    return $low . '-' . $high;
2171
+		return $low . '-' . $high;
2172 2172
 }
2173 2173
 
2174 2174
 /**
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,9 +1115,10 @@  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
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1121
+	}
1087 1122
 
1088 1123
 	call_integration_hook('integrate_prepare_pm_context', array(&$output, &$message, $counter));
1089 1124
 
@@ -1107,22 +1142,28 @@  discard block
 block discarded – undo
1107 1142
 			$context['search_params'][$k] = $v;
1108 1143
 		}
1109 1144
 	}
1110
-	if (isset($_REQUEST['search']))
1111
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1145
+	if (isset($_REQUEST['search'])) {
1146
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1147
+	}
1112 1148
 
1113
-	if (isset($context['search_params']['search']))
1114
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1115
-	if (isset($context['search_params']['userspec']))
1116
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1149
+	if (isset($context['search_params']['search'])) {
1150
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1151
+	}
1152
+	if (isset($context['search_params']['userspec'])) {
1153
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1154
+	}
1117 1155
 
1118
-	if (!empty($context['search_params']['searchtype']))
1119
-		$context['search_params']['searchtype'] = 2;
1156
+	if (!empty($context['search_params']['searchtype'])) {
1157
+			$context['search_params']['searchtype'] = 2;
1158
+	}
1120 1159
 
1121
-	if (!empty($context['search_params']['minage']))
1122
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1160
+	if (!empty($context['search_params']['minage'])) {
1161
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1162
+	}
1123 1163
 
1124
-	if (!empty($context['search_params']['maxage']))
1125
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1164
+	if (!empty($context['search_params']['maxage'])) {
1165
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1166
+	}
1126 1167
 
1127 1168
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
1128 1169
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
@@ -1149,8 +1190,9 @@  discard block
 block discarded – undo
1149 1190
 		$context['search_errors']['messages'] = array();
1150 1191
 		foreach ($context['search_errors'] as $search_error => $dummy)
1151 1192
 		{
1152
-			if ($search_error == 'messages')
1153
-				continue;
1193
+			if ($search_error == 'messages') {
1194
+							continue;
1195
+			}
1154 1196
 
1155 1197
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
1156 1198
 		}
@@ -1172,8 +1214,9 @@  discard block
 block discarded – undo
1172 1214
 	global $scripturl, $modSettings, $user_info, $context, $txt;
1173 1215
 	global $memberContext, $smcFunc;
1174 1216
 
1175
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
1176
-		fatal_lang_error('loadavg_search_disabled', false);
1217
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
1218
+			fatal_lang_error('loadavg_search_disabled', false);
1219
+	}
1177 1220
 
1178 1221
 	/**
1179 1222
 	 * @todo For the moment force the folder to the inbox.
@@ -1202,35 +1245,40 @@  discard block
 block discarded – undo
1202 1245
 	$context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1203 1246
 
1204 1247
 	// Store whether simple search was used (needed if the user wants to do another query).
1205
-	if (!isset($search_params['advanced']))
1206
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1248
+	if (!isset($search_params['advanced'])) {
1249
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1250
+	}
1207 1251
 
1208 1252
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
1209
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
1210
-		$search_params['searchtype'] = 2;
1253
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
1254
+			$search_params['searchtype'] = 2;
1255
+	}
1211 1256
 
1212 1257
 	// Minimum age of messages. Default to zero (don't set param in that case).
1213
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
1214
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1258
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
1259
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1260
+	}
1215 1261
 
1216 1262
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
1217
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999))
1218
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1263
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) {
1264
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1265
+	}
1219 1266
 
1220 1267
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
1221 1268
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
1222 1269
 
1223 1270
 	// Default the user name to a wildcard matching every user (*).
1224
-	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
1225
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1271
+	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
1272
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1273
+	}
1226 1274
 
1227 1275
 	// This will be full of all kinds of parameters!
1228 1276
 	$searchq_parameters = array();
1229 1277
 
1230 1278
 	// If there's no specific user, then don't mention it in the main query.
1231
-	if (empty($search_params['userspec']))
1232
-		$userQuery = '';
1233
-	else
1279
+	if (empty($search_params['userspec'])) {
1280
+			$userQuery = '';
1281
+	} else
1234 1282
 	{
1235 1283
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
1236 1284
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -1242,8 +1290,9 @@  discard block
 block discarded – undo
1242 1290
 		{
1243 1291
 			$possible_users[$k] = trim($possible_users[$k]);
1244 1292
 
1245
-			if (strlen($possible_users[$k]) == 0)
1246
-				unset($possible_users[$k]);
1293
+			if (strlen($possible_users[$k]) == 0) {
1294
+							unset($possible_users[$k]);
1295
+			}
1247 1296
 		}
1248 1297
 
1249 1298
 		if (!empty($possible_users))
@@ -1255,8 +1304,9 @@  discard block
 block discarded – undo
1255 1304
 			{
1256 1305
 				$where_params['name_' . $k] = $v;
1257 1306
 				$where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}';
1258
-				if (!isset($where_params['real_name']))
1259
-					$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1307
+				if (!isset($where_params['real_name'])) {
1308
+									$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1309
+				}
1260 1310
 			}
1261 1311
 
1262 1312
 			// Who matches those criteria?
@@ -1269,28 +1319,28 @@  discard block
 block discarded – undo
1269 1319
 			);
1270 1320
 
1271 1321
 			// Simply do nothing if there're too many members matching the criteria.
1272
-			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
1273
-				$userQuery = '';
1274
-			elseif ($smcFunc['db_num_rows']($request) == 0)
1322
+			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
1323
+							$userQuery = '';
1324
+			} elseif ($smcFunc['db_num_rows']($request) == 0)
1275 1325
 			{
1276 1326
 				$userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})';
1277 1327
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1278 1328
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1279
-			}
1280
-			else
1329
+			} else
1281 1330
 			{
1282 1331
 				$memberlist = array();
1283
-				while ($row = $smcFunc['db_fetch_assoc']($request))
1284
-					$memberlist[] = $row['id_member'];
1332
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
1333
+									$memberlist[] = $row['id_member'];
1334
+				}
1285 1335
 				$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})))';
1286 1336
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1287 1337
 				$searchq_parameters['member_list'] = $memberlist;
1288 1338
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1289 1339
 			}
1290 1340
 			$smcFunc['db_free_result']($request);
1341
+		} else {
1342
+					$userQuery = '';
1291 1343
 		}
1292
-		else
1293
-			$userQuery = '';
1294 1344
 	}
1295 1345
 
1296 1346
 	// Setup the sorting variables...
@@ -1298,8 +1348,9 @@  discard block
 block discarded – undo
1298 1348
 	$sort_columns = array(
1299 1349
 		'pm.id_pm',
1300 1350
 	);
1301
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
1302
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1351
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
1352
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1353
+	}
1303 1354
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm';
1304 1355
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
1305 1356
 
@@ -1309,24 +1360,27 @@  discard block
 block discarded – undo
1309 1360
 	if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels'])
1310 1361
 	{
1311 1362
 		// Came here from pagination?  Put them back into $_REQUEST for sanitization.
1312
-		if (isset($search_params['labels']))
1313
-			$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1363
+		if (isset($search_params['labels'])) {
1364
+					$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1365
+		}
1314 1366
 
1315 1367
 		// Assuming we have some labels - make them all integers.
1316 1368
 		if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel']))
1317 1369
 		{
1318
-			foreach ($_REQUEST['searchlabel'] as $key => $id)
1319
-				$_REQUEST['searchlabel'][$key] = (int) $id;
1370
+			foreach ($_REQUEST['searchlabel'] as $key => $id) {
1371
+							$_REQUEST['searchlabel'][$key] = (int) $id;
1372
+			}
1373
+		} else {
1374
+					$_REQUEST['searchlabel'] = array();
1320 1375
 		}
1321
-		else
1322
-			$_REQUEST['searchlabel'] = array();
1323 1376
 
1324 1377
 		// Now that everything is cleaned up a bit, make the labels a param.
1325 1378
 		$search_params['labels'] = implode(',', $_REQUEST['searchlabel']);
1326 1379
 
1327 1380
 		// No labels selected? That must be an error!
1328
-		if (empty($_REQUEST['searchlabel']))
1329
-			$context['search_errors']['no_labels_selected'] = true;
1381
+		if (empty($_REQUEST['searchlabel'])) {
1382
+					$context['search_errors']['no_labels_selected'] = true;
1383
+		}
1330 1384
 		// Otherwise prepare the query!
1331 1385
 		elseif (count($_REQUEST['searchlabel']) != count($context['labels']))
1332 1386
 		{
@@ -1349,8 +1403,7 @@  discard block
 block discarded – undo
1349 1403
 					// Not searching the inbox - PM must be labeled
1350 1404
 					$labelQuery = ' AND pml.id_label IN ({array_int:labels})';
1351 1405
 					$labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)';
1352
-				}
1353
-				else
1406
+				} else
1354 1407
 				{
1355 1408
 					// Searching the inbox - PM doesn't have to be labeled
1356 1409
 					$labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))';
@@ -1365,8 +1418,9 @@  discard block
 block discarded – undo
1365 1418
 	// What are we actually searching for?
1366 1419
 	$search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : '');
1367 1420
 	// If we ain't got nothing - we should error!
1368
-	if (!isset($search_params['search']) || $search_params['search'] == '')
1369
-		$context['search_errors']['invalid_search_string'] = true;
1421
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
1422
+			$context['search_errors']['invalid_search_string'] = true;
1423
+	}
1370 1424
 
1371 1425
 	// Extract phrase parts first (e.g. some words "this is a phrase" some more words.)
1372 1426
 	preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER);
@@ -1379,12 +1433,14 @@  discard block
 block discarded – undo
1379 1433
 	$excludedWords = array();
1380 1434
 
1381 1435
 	// .. first, we check for things like -"some words", but not "-some words".
1382
-	foreach ($matches[1] as $index => $word)
1383
-		if ($word == '-')
1436
+	foreach ($matches[1] as $index => $word) {
1437
+			if ($word == '-')
1384 1438
 		{
1385 1439
 			$word = $smcFunc['strtolower'](trim($searchArray[$index]));
1386
-			if (strlen($word) > 0)
1387
-				$excludedWords[] = $word;
1440
+	}
1441
+			if (strlen($word) > 0) {
1442
+							$excludedWords[] = $word;
1443
+			}
1388 1444
 			unset($searchArray[$index]);
1389 1445
 		}
1390 1446
 
@@ -1394,8 +1450,9 @@  discard block
 block discarded – undo
1394 1450
 		if (strpos(trim($word), '-') === 0)
1395 1451
 		{
1396 1452
 			$word = substr($smcFunc['strtolower']($word), 1);
1397
-			if (strlen($word) > 0)
1398
-				$excludedWords[] = $word;
1453
+			if (strlen($word) > 0) {
1454
+							$excludedWords[] = $word;
1455
+			}
1399 1456
 			unset($tempSearch[$index]);
1400 1457
 		}
1401 1458
 	}
@@ -1406,9 +1463,9 @@  discard block
 block discarded – undo
1406 1463
 	foreach ($searchArray as $index => $value)
1407 1464
 	{
1408 1465
 		$searchArray[$index] = $smcFunc['strtolower'](trim($value));
1409
-		if ($searchArray[$index] == '')
1410
-			unset($searchArray[$index]);
1411
-		else
1466
+		if ($searchArray[$index] == '') {
1467
+					unset($searchArray[$index]);
1468
+		} else
1412 1469
 		{
1413 1470
 			// Sort out entities first.
1414 1471
 			$searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]);
@@ -1418,27 +1475,32 @@  discard block
 block discarded – undo
1418 1475
 
1419 1476
 	// Create an array of replacements for highlighting.
1420 1477
 	$context['mark'] = array();
1421
-	foreach ($searchArray as $word)
1422
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1478
+	foreach ($searchArray as $word) {
1479
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1480
+	}
1423 1481
 
1424 1482
 	// This contains *everything*
1425 1483
 	$searchWords = array_merge($searchArray, $excludedWords);
1426 1484
 
1427 1485
 	// Make sure at least one word is being searched for.
1428
-	if (empty($searchArray))
1429
-		$context['search_errors']['invalid_search_string'] = true;
1486
+	if (empty($searchArray)) {
1487
+			$context['search_errors']['invalid_search_string'] = true;
1488
+	}
1430 1489
 
1431 1490
 	// Sort out the search query so the user can edit it - if they want.
1432 1491
 	$context['search_params'] = $search_params;
1433
-	if (isset($context['search_params']['search']))
1434
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1435
-	if (isset($context['search_params']['userspec']))
1436
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1492
+	if (isset($context['search_params']['search'])) {
1493
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1494
+	}
1495
+	if (isset($context['search_params']['userspec'])) {
1496
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1497
+	}
1437 1498
 
1438 1499
 	// Now we have all the parameters, combine them together for pagination and the like...
1439 1500
 	$context['params'] = array();
1440
-	foreach ($search_params as $k => $v)
1441
-		$context['params'][] = $k . '|\'|' . $v;
1501
+	foreach ($search_params as $k => $v) {
1502
+			$context['params'][] = $k . '|\'|' . $v;
1503
+	}
1442 1504
 	$context['params'] = base64_encode(implode('|"|', $context['params']));
1443 1505
 
1444 1506
 	// Compile the subject query part.
@@ -1446,26 +1508,31 @@  discard block
 block discarded – undo
1446 1508
 
1447 1509
 	foreach ($searchWords as $index => $word)
1448 1510
 	{
1449
-		if ($word == '')
1450
-			continue;
1511
+		if ($word == '') {
1512
+					continue;
1513
+		}
1451 1514
 
1452
-		if ($search_params['subject_only'])
1453
-			$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1454
-		else
1455
-			$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 . '})';
1515
+		if ($search_params['subject_only']) {
1516
+					$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1517
+		} else {
1518
+					$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 . '})';
1519
+		}
1456 1520
 		$searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%';
1457 1521
 	}
1458 1522
 
1459 1523
 	$searchQuery = ' 1=1';
1460
-	if (!empty($andQueryParts))
1461
-		$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1524
+	if (!empty($andQueryParts)) {
1525
+			$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1526
+	}
1462 1527
 
1463 1528
 	// Age limits?
1464 1529
 	$timeQuery = '';
1465
-	if (!empty($search_params['minage']))
1466
-		$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1467
-	if (!empty($search_params['maxage']))
1468
-		$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1530
+	if (!empty($search_params['minage'])) {
1531
+			$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1532
+	}
1533
+	if (!empty($search_params['maxage'])) {
1534
+			$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1535
+	}
1469 1536
 
1470 1537
 	// If we have errors - return back to the first screen...
1471 1538
 	if (!empty($context['search_errors']))
@@ -1551,8 +1618,9 @@  discard block
 block discarded – undo
1551 1618
 			)
1552 1619
 		);
1553 1620
 		$real_pm_ids = array();
1554
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1555
-			$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1621
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1622
+					$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1623
+		}
1556 1624
 		$smcFunc['db_free_result']($request);
1557 1625
 	}
1558 1626
 
@@ -1582,8 +1650,9 @@  discard block
 block discarded – undo
1582 1650
 		);
1583 1651
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1584 1652
 		{
1585
-			if ($context['folder'] == 'sent' || empty($row['bcc']))
1586
-				$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>';
1653
+			if ($context['folder'] == 'sent' || empty($row['bcc'])) {
1654
+							$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>';
1655
+			}
1587 1656
 
1588 1657
 			if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')
1589 1658
 			{
@@ -1604,12 +1673,14 @@  discard block
 block discarded – undo
1604 1673
 				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
1605 1674
 				{
1606 1675
 					$l_id = $row2['id_label'];
1607
-					if (isset($context['labels'][$l_id]))
1608
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1676
+					if (isset($context['labels'][$l_id])) {
1677
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1678
+					}
1609 1679
 
1610 1680
 					// Here we find the first label on a message - for linking to posts in results
1611
-					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1)
1612
-						$context['first_label'][$row['id_pm']] = $l_id;
1681
+					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) {
1682
+											$context['first_label'][$row['id_pm']] = $l_id;
1683
+					}
1613 1684
 				}
1614 1685
 
1615 1686
 				$smcFunc['db_free_result']($request2);
@@ -1736,8 +1807,9 @@  discard block
 block discarded – undo
1736 1807
 		list ($postCount) = $smcFunc['db_fetch_row']($request);
1737 1808
 		$smcFunc['db_free_result']($request);
1738 1809
 
1739
-		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
1740
-			fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1810
+		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) {
1811
+					fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1812
+		}
1741 1813
 	}
1742 1814
 
1743 1815
 	// Quoting/Replying to a message?
@@ -1746,8 +1818,9 @@  discard block
 block discarded – undo
1746 1818
 		$pmsg = (int) $_REQUEST['pmsg'];
1747 1819
 
1748 1820
 		// Make sure this is yours.
1749
-		if (!isAccessiblePM($pmsg))
1750
-			fatal_lang_error('no_access', false);
1821
+		if (!isAccessiblePM($pmsg)) {
1822
+					fatal_lang_error('no_access', false);
1823
+		}
1751 1824
 
1752 1825
 		// Work out whether this is one you've received?
1753 1826
 		$request = $smcFunc['db_query']('', '
@@ -1784,8 +1857,9 @@  discard block
 block discarded – undo
1784 1857
 				'id_pm' => $pmsg,
1785 1858
 			)
1786 1859
 		);
1787
-		if ($smcFunc['db_num_rows']($request) == 0)
1788
-			fatal_lang_error('pm_not_yours', false);
1860
+		if ($smcFunc['db_num_rows']($request) == 0) {
1861
+					fatal_lang_error('pm_not_yours', false);
1862
+		}
1789 1863
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
1790 1864
 		$smcFunc['db_free_result']($request);
1791 1865
 
@@ -1796,9 +1870,9 @@  discard block
 block discarded – undo
1796 1870
 		// Add 'Re: ' to it....
1797 1871
 		if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
1798 1872
 		{
1799
-			if ($language === $user_info['language'])
1800
-				$context['response_prefix'] = $txt['response_prefix'];
1801
-			else
1873
+			if ($language === $user_info['language']) {
1874
+							$context['response_prefix'] = $txt['response_prefix'];
1875
+			} else
1802 1876
 			{
1803 1877
 				loadLanguage('index', $language, false);
1804 1878
 				$context['response_prefix'] = $txt['response_prefix'];
@@ -1807,22 +1881,25 @@  discard block
 block discarded – undo
1807 1881
 			cache_put_data('response_prefix', $context['response_prefix'], 600);
1808 1882
 		}
1809 1883
 		$form_subject = $row_quoted['subject'];
1810
-		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
1811
-			$form_subject = $context['response_prefix'] . $form_subject;
1884
+		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
1885
+					$form_subject = $context['response_prefix'] . $form_subject;
1886
+		}
1812 1887
 
1813 1888
 		if (isset($_REQUEST['quote']))
1814 1889
 		{
1815 1890
 			// Remove any nested quotes and <br>...
1816 1891
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']);
1817
-			if (!empty($modSettings['removeNestedQuotes']))
1818
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1819
-			if (empty($row_quoted['id_member']))
1820
-				$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1821
-			else
1822
-				$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]';
1892
+			if (!empty($modSettings['removeNestedQuotes'])) {
1893
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1894
+			}
1895
+			if (empty($row_quoted['id_member'])) {
1896
+							$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1897
+			} else {
1898
+							$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]';
1899
+			}
1900
+		} else {
1901
+					$form_message = '';
1823 1902
 		}
1824
-		else
1825
-			$form_message = '';
1826 1903
 
1827 1904
 		// Do the BBC thang on the message.
1828 1905
 		$row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']);
@@ -1843,8 +1920,7 @@  discard block
 block discarded – undo
1843 1920
 			'timestamp' => forum_time(true, $row_quoted['msgtime']),
1844 1921
 			'body' => $row_quoted['body']
1845 1922
 		);
1846
-	}
1847
-	else
1923
+	} else
1848 1924
 	{
1849 1925
 		$context['quoted_message'] = false;
1850 1926
 		$form_subject = '';
@@ -1863,11 +1939,12 @@  discard block
 block discarded – undo
1863 1939
 		if ($_REQUEST['u'] == 'all' && isset($row_quoted))
1864 1940
 		{
1865 1941
 			// Firstly, to reply to all we clearly already have $row_quoted - so have the original member from.
1866
-			if ($row_quoted['id_member'] != $user_info['id'])
1867
-				$context['recipients']['to'][] = array(
1942
+			if ($row_quoted['id_member'] != $user_info['id']) {
1943
+							$context['recipients']['to'][] = array(
1868 1944
 					'id' => $row_quoted['id_member'],
1869 1945
 					'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']),
1870 1946
 				);
1947
+			}
1871 1948
 
1872 1949
 			// Now to get the others.
1873 1950
 			$request = $smcFunc['db_query']('', '
@@ -1883,18 +1960,19 @@  discard block
 block discarded – undo
1883 1960
 					'not_bcc' => 0,
1884 1961
 				)
1885 1962
 			);
1886
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1887
-				$context['recipients']['to'][] = array(
1963
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1964
+							$context['recipients']['to'][] = array(
1888 1965
 					'id' => $row['id_member'],
1889 1966
 					'name' => $row['real_name'],
1890 1967
 				);
1968
+			}
1891 1969
 			$smcFunc['db_free_result']($request);
1892
-		}
1893
-		else
1970
+		} else
1894 1971
 		{
1895 1972
 			$_REQUEST['u'] = explode(',', $_REQUEST['u']);
1896
-			foreach ($_REQUEST['u'] as $key => $uID)
1897
-				$_REQUEST['u'][$key] = (int) $uID;
1973
+			foreach ($_REQUEST['u'] as $key => $uID) {
1974
+							$_REQUEST['u'][$key] = (int) $uID;
1975
+			}
1898 1976
 
1899 1977
 			$_REQUEST['u'] = array_unique($_REQUEST['u']);
1900 1978
 
@@ -1908,22 +1986,24 @@  discard block
 block discarded – undo
1908 1986
 					'limit' => count($_REQUEST['u']),
1909 1987
 				)
1910 1988
 			);
1911
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1912
-				$context['recipients']['to'][] = array(
1989
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1990
+							$context['recipients']['to'][] = array(
1913 1991
 					'id' => $row['id_member'],
1914 1992
 					'name' => $row['real_name'],
1915 1993
 				);
1994
+			}
1916 1995
 			$smcFunc['db_free_result']($request);
1917 1996
 		}
1918 1997
 
1919 1998
 		// Get a literal name list in case the user has JavaScript disabled.
1920 1999
 		$names = array();
1921
-		foreach ($context['recipients']['to'] as $to)
1922
-			$names[] = $to['name'];
2000
+		foreach ($context['recipients']['to'] as $to) {
2001
+					$names[] = $to['name'];
2002
+		}
1923 2003
 		$context['to_value'] = empty($names) ? '' : '&quot;' . implode('&quot;, &quot;', $names) . '&quot;';
2004
+	} else {
2005
+			$context['to_value'] = '';
1924 2006
 	}
1925
-	else
1926
-		$context['to_value'] = '';
1927 2007
 
1928 2008
 	// Set the defaults...
1929 2009
 	$context['subject'] = $form_subject;
@@ -1993,8 +2073,9 @@  discard block
 block discarded – undo
1993 2073
 
1994 2074
 	// validate with loadMemberData()
1995 2075
 	$memberResult = loadMemberData($user_info['id'], false);
1996
-	if (!$memberResult)
1997
-		fatal_lang_error('not_a_user', false);
2076
+	if (!$memberResult) {
2077
+			fatal_lang_error('not_a_user', false);
2078
+	}
1998 2079
 	list ($memID) = $memberResult;
1999 2080
 
2000 2081
 	// drafts is where the functions reside
@@ -2020,9 +2101,9 @@  discard block
 block discarded – undo
2020 2101
 		$context['sub_template'] = 'send';
2021 2102
 		loadJavaScriptFile('PersonalMessage.js', array('defer' => false), 'smf_pms');
2022 2103
 		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
2104
+	} else {
2105
+			$context['sub_template'] = 'pm';
2023 2106
 	}
2024
-	else
2025
-		$context['sub_template'] = 'pm';
2026 2107
 
2027 2108
 	$context['page_title'] = $txt['send_message'];
2028 2109
 
@@ -2083,10 +2164,11 @@  discard block
 block discarded – undo
2083 2164
 		);
2084 2165
 		if ($smcFunc['db_num_rows']($request) == 0)
2085 2166
 		{
2086
-			if (!isset($_REQUEST['xml']))
2087
-				fatal_lang_error('pm_not_yours', false);
2088
-			else
2089
-				$error_types[] = 'pm_not_yours';
2167
+			if (!isset($_REQUEST['xml'])) {
2168
+							fatal_lang_error('pm_not_yours', false);
2169
+			} else {
2170
+							$error_types[] = 'pm_not_yours';
2171
+			}
2090 2172
 		}
2091 2173
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
2092 2174
 		$smcFunc['db_free_result']($request);
@@ -2133,14 +2215,16 @@  discard block
 block discarded – undo
2133 2215
 		$context['post_error'][$error_type] = true;
2134 2216
 		if (isset($txt['error_' . $error_type]))
2135 2217
 		{
2136
-			if ($error_type == 'long_message')
2137
-				$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2218
+			if ($error_type == 'long_message') {
2219
+							$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2220
+			}
2138 2221
 			$context['post_error']['messages'][] = $txt['error_' . $error_type];
2139 2222
 		}
2140 2223
 
2141 2224
 		// If it's not a minor error flag it as such.
2142
-		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject')))
2143
-			$context['error_type'] = 'serious';
2225
+		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) {
2226
+					$context['error_type'] = 'serious';
2227
+		}
2144 2228
 	}
2145 2229
 
2146 2230
 	// We need to load the editor once more.
@@ -2198,8 +2282,9 @@  discard block
 block discarded – undo
2198 2282
 	require_once($sourcedir . '/Subs-Auth.php');
2199 2283
 
2200 2284
 	// PM Drafts enabled and needed?
2201
-	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft'])))
2202
-		require_once($sourcedir . '/Drafts.php');
2285
+	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) {
2286
+			require_once($sourcedir . '/Drafts.php');
2287
+	}
2203 2288
 
2204 2289
 	loadLanguage('PersonalMessage', '', false);
2205 2290
 
@@ -2229,24 +2314,27 @@  discard block
 block discarded – undo
2229 2314
 
2230 2315
 		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
2231 2316
 		{
2232
-			if (!isset($_REQUEST['xml']))
2233
-				fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2234
-			else
2235
-				$post_errors[] = 'pm_too_many_per_hour';
2317
+			if (!isset($_REQUEST['xml'])) {
2318
+							fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2319
+			} else {
2320
+							$post_errors[] = 'pm_too_many_per_hour';
2321
+			}
2236 2322
 		}
2237 2323
 	}
2238 2324
 
2239 2325
 	// If your session timed out, show an error, but do allow to re-submit.
2240
-	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '')
2241
-		$post_errors[] = 'session_timeout';
2326
+	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') {
2327
+			$post_errors[] = 'session_timeout';
2328
+	}
2242 2329
 
2243 2330
 	$_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
2244 2331
 	$_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to'];
2245 2332
 	$_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc'];
2246 2333
 
2247 2334
 	// Route the input from the 'u' parameter to the 'to'-list.
2248
-	if (!empty($_POST['u']))
2249
-		$_POST['recipient_to'] = explode(',', $_POST['u']);
2335
+	if (!empty($_POST['u'])) {
2336
+			$_POST['recipient_to'] = explode(',', $_POST['u']);
2337
+	}
2250 2338
 
2251 2339
 	// Construct the list of recipients.
2252 2340
 	$recipientList = array();
@@ -2258,8 +2346,9 @@  discard block
 block discarded – undo
2258 2346
 		$recipientList[$recipientType] = array();
2259 2347
 		if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType]))
2260 2348
 		{
2261
-			foreach ($_POST['recipient_' . $recipientType] as $recipient)
2262
-				$recipientList[$recipientType][] = (int) $recipient;
2349
+			foreach ($_POST['recipient_' . $recipientType] as $recipient) {
2350
+							$recipientList[$recipientType][] = (int) $recipient;
2351
+			}
2263 2352
 		}
2264 2353
 
2265 2354
 		// Are there also literal names set?
@@ -2273,10 +2362,11 @@  discard block
 block discarded – undo
2273 2362
 
2274 2363
 			foreach ($namedRecipientList[$recipientType] as $index => $recipient)
2275 2364
 			{
2276
-				if (strlen(trim($recipient)) > 0)
2277
-					$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2278
-				else
2279
-					unset($namedRecipientList[$recipientType][$index]);
2365
+				if (strlen(trim($recipient)) > 0) {
2366
+									$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2367
+				} else {
2368
+									unset($namedRecipientList[$recipientType][$index]);
2369
+				}
2280 2370
 			}
2281 2371
 
2282 2372
 			if (!empty($namedRecipientList[$recipientType]))
@@ -2306,8 +2396,9 @@  discard block
 block discarded – undo
2306 2396
 		}
2307 2397
 
2308 2398
 		// Selected a recipient to be deleted? Remove them now.
2309
-		if (!empty($_POST['delete_recipient']))
2310
-			$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2399
+		if (!empty($_POST['delete_recipient'])) {
2400
+					$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2401
+		}
2311 2402
 
2312 2403
 		// Make sure we don't include the same name twice
2313 2404
 		$recipientList[$recipientType] = array_unique($recipientList[$recipientType]);
@@ -2317,8 +2408,9 @@  discard block
 block discarded – undo
2317 2408
 	$is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']);
2318 2409
 
2319 2410
 	// Check if there's at least one recipient.
2320
-	if (empty($recipientList['to']) && empty($recipientList['bcc']))
2321
-		$post_errors[] = 'no_to';
2411
+	if (empty($recipientList['to']) && empty($recipientList['bcc'])) {
2412
+			$post_errors[] = 'no_to';
2413
+	}
2322 2414
 
2323 2415
 	// Make sure that we remove the members who did get it from the screen.
2324 2416
 	if (!$is_recipient_change)
@@ -2332,28 +2424,31 @@  discard block
 block discarded – undo
2332 2424
 				// Since we already have a post error, remove the previous one.
2333 2425
 				$post_errors = array_diff($post_errors, array('no_to'));
2334 2426
 
2335
-				foreach ($namesNotFound[$recipientType] as $name)
2336
-					$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2427
+				foreach ($namesNotFound[$recipientType] as $name) {
2428
+									$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2429
+				}
2337 2430
 			}
2338 2431
 		}
2339 2432
 	}
2340 2433
 
2341 2434
 	// Did they make any mistakes?
2342
-	if ($_REQUEST['subject'] == '')
2343
-		$post_errors[] = 'no_subject';
2344
-	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '')
2345
-		$post_errors[] = 'no_message';
2346
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength'])
2347
-		$post_errors[] = 'long_message';
2348
-	else
2435
+	if ($_REQUEST['subject'] == '') {
2436
+			$post_errors[] = 'no_subject';
2437
+	}
2438
+	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') {
2439
+			$post_errors[] = 'no_message';
2440
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) {
2441
+			$post_errors[] = 'long_message';
2442
+	} else
2349 2443
 	{
2350 2444
 		// Preparse the message.
2351 2445
 		$message = $_REQUEST['message'];
2352 2446
 		preparsecode($message);
2353 2447
 
2354 2448
 		// Make sure there's still some content left without the tags.
2355
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false))
2356
-			$post_errors[] = 'no_message';
2449
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) {
2450
+					$post_errors[] = 'no_message';
2451
+		}
2357 2452
 	}
2358 2453
 
2359 2454
 	// Wrong verification code?
@@ -2365,13 +2460,15 @@  discard block
 block discarded – undo
2365 2460
 		);
2366 2461
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
2367 2462
 
2368
-		if (is_array($context['require_verification']))
2369
-			$post_errors = array_merge($post_errors, $context['require_verification']);
2463
+		if (is_array($context['require_verification'])) {
2464
+					$post_errors = array_merge($post_errors, $context['require_verification']);
2465
+		}
2370 2466
 	}
2371 2467
 
2372 2468
 	// If they did, give a chance to make ammends.
2373
-	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml']))
2374
-		return messagePostError($post_errors, $namedRecipientList, $recipientList);
2469
+	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) {
2470
+			return messagePostError($post_errors, $namedRecipientList, $recipientList);
2471
+	}
2375 2472
 
2376 2473
 	// Want to take a second glance before you send?
2377 2474
 	if (isset($_REQUEST['preview']))
@@ -2402,8 +2499,9 @@  discard block
 block discarded – undo
2402 2499
 		foreach ($namesNotFound as $recipientType => $names)
2403 2500
 		{
2404 2501
 			$post_errors[] = 'bad_' . $recipientType;
2405
-			foreach ($names as $name)
2406
-				$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2502
+			foreach ($names as $name) {
2503
+							$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2504
+			}
2407 2505
 		}
2408 2506
 
2409 2507
 		return messagePostError(array(), $namedRecipientList, $recipientList);
@@ -2433,13 +2531,14 @@  discard block
 block discarded – undo
2433 2531
 	checkSubmitOnce('check');
2434 2532
 
2435 2533
 	// Do the actual sending of the PM.
2436
-	if (!empty($recipientList['to']) || !empty($recipientList['bcc']))
2437
-		$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2438
-	else
2439
-		$context['send_log'] = array(
2534
+	if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) {
2535
+			$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2536
+	} else {
2537
+			$context['send_log'] = array(
2440 2538
 			'sent' => array(),
2441 2539
 			'failed' => array()
2442 2540
 		);
2541
+	}
2443 2542
 
2444 2543
 	// Mark the message as "replied to".
2445 2544
 	if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox')
@@ -2457,11 +2556,12 @@  discard block
 block discarded – undo
2457 2556
 	}
2458 2557
 
2459 2558
 	// If one or more of the recipient were invalid, go back to the post screen with the failed usernames.
2460
-	if (!empty($context['send_log']['failed']))
2461
-		return messagePostError($post_errors, $namesNotFound, array(
2559
+	if (!empty($context['send_log']['failed'])) {
2560
+			return messagePostError($post_errors, $namesNotFound, array(
2462 2561
 			'to' => array_intersect($recipientList['to'], $context['send_log']['failed']),
2463 2562
 			'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed'])
2464 2563
 		));
2564
+	}
2465 2565
 
2466 2566
 	// Message sent successfully?
2467 2567
 	if (!empty($context['send_log']) && empty($context['send_log']['failed']))
@@ -2469,8 +2569,9 @@  discard block
 block discarded – undo
2469 2569
 		$context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent';
2470 2570
 
2471 2571
 		// If we had a PM draft for this one, then its time to remove it since it was just sent
2472
-		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft']))
2473
-			DeleteDraft($_POST['id_pm_draft']);
2572
+		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) {
2573
+					DeleteDraft($_POST['id_pm_draft']);
2574
+		}
2474 2575
 	}
2475 2576
 
2476 2577
 	// Go back to the where they sent from, if possible...
@@ -2485,24 +2586,28 @@  discard block
 block discarded – undo
2485 2586
 
2486 2587
 	checkSession('request');
2487 2588
 
2488
-	if (isset($_REQUEST['del_selected']))
2489
-		$_REQUEST['pm_action'] = 'delete';
2589
+	if (isset($_REQUEST['del_selected'])) {
2590
+			$_REQUEST['pm_action'] = 'delete';
2591
+	}
2490 2592
 
2491 2593
 	if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms']))
2492 2594
 	{
2493
-		foreach ($_REQUEST['pms'] as $pm)
2494
-			$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2595
+		foreach ($_REQUEST['pms'] as $pm) {
2596
+					$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2597
+		}
2495 2598
 	}
2496 2599
 
2497
-	if (empty($_REQUEST['pm_actions']))
2498
-		redirectexit($context['current_label_redirect']);
2600
+	if (empty($_REQUEST['pm_actions'])) {
2601
+			redirectexit($context['current_label_redirect']);
2602
+	}
2499 2603
 
2500 2604
 	// If we are in conversation, we may need to apply this to every message in the conversation.
2501 2605
 	if ($context['display_mode'] == 2 && isset($_REQUEST['conversation']))
2502 2606
 	{
2503 2607
 		$id_pms = array();
2504
-		foreach ($_REQUEST['pm_actions'] as $pm => $dummy)
2505
-			$id_pms[] = (int) $pm;
2608
+		foreach ($_REQUEST['pm_actions'] as $pm => $dummy) {
2609
+					$id_pms[] = (int) $pm;
2610
+		}
2506 2611
 
2507 2612
 		$request = $smcFunc['db_query']('', '
2508 2613
 			SELECT id_pm_head, id_pm
@@ -2513,8 +2618,9 @@  discard block
 block discarded – undo
2513 2618
 			)
2514 2619
 		);
2515 2620
 		$pm_heads = array();
2516
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2517
-			$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2621
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2622
+					$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2623
+		}
2518 2624
 		$smcFunc['db_free_result']($request);
2519 2625
 
2520 2626
 		$request = $smcFunc['db_query']('', '
@@ -2528,8 +2634,9 @@  discard block
 block discarded – undo
2528 2634
 		// Copy the action from the single to PM to the others.
2529 2635
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2530 2636
 		{
2531
-			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]))
2532
-				$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2637
+			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) {
2638
+							$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2639
+			}
2533 2640
 		}
2534 2641
 		$smcFunc['db_free_result']($request);
2535 2642
 	}
@@ -2540,22 +2647,21 @@  discard block
 block discarded – undo
2540 2647
 	$labels = array();
2541 2648
 	foreach ($_REQUEST['pm_actions'] as $pm => $action)
2542 2649
 	{
2543
-		if ($action === 'delete')
2544
-			$to_delete[] = (int) $pm;
2545
-		else
2650
+		if ($action === 'delete') {
2651
+					$to_delete[] = (int) $pm;
2652
+		} else
2546 2653
 		{
2547 2654
 			if (substr($action, 0, 4) == 'add_')
2548 2655
 			{
2549 2656
 				$type = 'add';
2550 2657
 				$action = substr($action, 4);
2551
-			}
2552
-			elseif (substr($action, 0, 4) == 'rem_')
2658
+			} elseif (substr($action, 0, 4) == 'rem_')
2553 2659
 			{
2554 2660
 				$type = 'rem';
2555 2661
 				$action = substr($action, 4);
2662
+			} else {
2663
+							$type = 'unk';
2556 2664
 			}
2557
-			else
2558
-				$type = 'unk';
2559 2665
 
2560 2666
 			if ($action == '-1' || (int) $action > 0)
2561 2667
 			{
@@ -2566,8 +2672,9 @@  discard block
 block discarded – undo
2566 2672
 	}
2567 2673
 
2568 2674
 	// Deleting, it looks like?
2569
-	if (!empty($to_delete))
2570
-		deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2675
+	if (!empty($to_delete)) {
2676
+			deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2677
+	}
2571 2678
 
2572 2679
 	// Are we labeling anything?
2573 2680
 	if (!empty($to_label) && $context['folder'] == 'inbox')
@@ -2633,8 +2740,7 @@  discard block
 block discarded – undo
2633 2740
 				}
2634 2741
 
2635 2742
 				$smcFunc['db_free_result']($request2);
2636
-			}
2637
-			elseif ($type == 'rem')
2743
+			} elseif ($type == 'rem')
2638 2744
 			{
2639 2745
 				// If we're removing from the inbox, see if we have at least one other label.
2640 2746
 				// This query is faster than the one above
@@ -2666,21 +2772,25 @@  discard block
 block discarded – undo
2666 2772
 			if ($to_label[$row['id_pm']] != '-1')
2667 2773
 			{
2668 2774
 				// If this label is in the list and we're not adding it, remove it
2669
-				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add')
2670
-					unset($labels[$to_label[$row['id_pm']]]);
2671
-				else if ($type !== 'rem')
2672
-					$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2775
+				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') {
2776
+									unset($labels[$to_label[$row['id_pm']]]);
2777
+				} else if ($type !== 'rem') {
2778
+									$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2779
+				}
2673 2780
 			}
2674 2781
 
2675 2782
 			// Removing all labels or just removing the inbox label
2676
-			if ($type == 'rem' && empty($labels))
2677
-				$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2783
+			if ($type == 'rem' && empty($labels)) {
2784
+							$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2785
+			}
2678 2786
 			// Adding new labels, but removing inbox and applying new ones
2679
-			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels))
2680
-				$in_inbox = 0;
2787
+			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) {
2788
+							$in_inbox = 0;
2789
+			}
2681 2790
 			// Just adding it to the inbox
2682
-			else
2683
-				$in_inbox = 1;
2791
+			else {
2792
+							$in_inbox = 1;
2793
+			}
2684 2794
 
2685 2795
 			// Are we adding it to or removing it from the inbox?
2686 2796
 			if ($in_inbox != $row['in_inbox'])
@@ -2722,8 +2832,9 @@  discard block
 block discarded – undo
2722 2832
 			if (!empty($labels_to_apply))
2723 2833
 			{
2724 2834
 				$inserts = array();
2725
-				foreach ($labels_to_apply as $label)
2726
-					$inserts[] = array($row['id_pm'], $label);
2835
+				foreach ($labels_to_apply as $label) {
2836
+									$inserts[] = array($row['id_pm'], $label);
2837
+				}
2727 2838
 
2728 2839
 				$smcFunc['db_insert']('',
2729 2840
 					'{db_prefix}pm_labeled_messages',
@@ -2767,11 +2878,13 @@  discard block
 block discarded – undo
2767 2878
 	checkSession('get');
2768 2879
 
2769 2880
 	// If all then delete all messages the user has.
2770
-	if ($_REQUEST['f'] == 'all')
2771
-		deleteMessages(null, null);
2881
+	if ($_REQUEST['f'] == 'all') {
2882
+			deleteMessages(null, null);
2883
+	}
2772 2884
 	// Otherwise just the selected folder.
2773
-	else
2774
-		deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2885
+	else {
2886
+			deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2887
+	}
2775 2888
 
2776 2889
 	// Done... all gone.
2777 2890
 	redirectexit($context['current_label_redirect']);
@@ -2808,8 +2921,9 @@  discard block
 block discarded – undo
2808 2921
 				'msgtime' => $deleteTime,
2809 2922
 			)
2810 2923
 		);
2811
-		while ($row = $smcFunc['db_fetch_row']($request))
2812
-			$toDelete[] = $row[0];
2924
+		while ($row = $smcFunc['db_fetch_row']($request)) {
2925
+					$toDelete[] = $row[0];
2926
+		}
2813 2927
 		$smcFunc['db_free_result']($request);
2814 2928
 
2815 2929
 		// Select all messages in their inbox older than $deleteTime.
@@ -2826,8 +2940,9 @@  discard block
 block discarded – undo
2826 2940
 				'msgtime' => $deleteTime,
2827 2941
 			)
2828 2942
 		);
2829
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2830
-			$toDelete[] = $row['id_pm'];
2943
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2944
+					$toDelete[] = $row['id_pm'];
2945
+		}
2831 2946
 		$smcFunc['db_free_result']($request);
2832 2947
 
2833 2948
 		// Delete the actual messages.
@@ -2858,26 +2973,29 @@  discard block
 block discarded – undo
2858 2973
 {
2859 2974
 	global $user_info, $smcFunc;
2860 2975
 
2861
-	if ($owner === null)
2862
-		$owner = array($user_info['id']);
2863
-	elseif (empty($owner))
2864
-		return;
2865
-	elseif (!is_array($owner))
2866
-		$owner = array($owner);
2976
+	if ($owner === null) {
2977
+			$owner = array($user_info['id']);
2978
+	} elseif (empty($owner)) {
2979
+			return;
2980
+	} elseif (!is_array($owner)) {
2981
+			$owner = array($owner);
2982
+	}
2867 2983
 
2868 2984
 	if ($personal_messages !== null)
2869 2985
 	{
2870
-		if (empty($personal_messages) || !is_array($personal_messages))
2871
-			return;
2986
+		if (empty($personal_messages) || !is_array($personal_messages)) {
2987
+					return;
2988
+		}
2872 2989
 
2873
-		foreach ($personal_messages as $index => $delete_id)
2874
-			$personal_messages[$index] = (int) $delete_id;
2990
+		foreach ($personal_messages as $index => $delete_id) {
2991
+					$personal_messages[$index] = (int) $delete_id;
2992
+		}
2875 2993
 
2876 2994
 		$where = '
2877 2995
 				AND id_pm IN ({array_int:pm_list})';
2996
+	} else {
2997
+			$where = '';
2878 2998
 	}
2879
-	else
2880
-		$where = '';
2881 2999
 
2882 3000
 	if ($folder == 'sent' || $folder === null)
2883 3001
 	{
@@ -2912,17 +3030,19 @@  discard block
 block discarded – undo
2912 3030
 		// ...And update the statistics accordingly - now including unread messages!.
2913 3031
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2914 3032
 		{
2915
-			if ($row['is_read'])
2916
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
2917
-			else
2918
-				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']));
3033
+			if ($row['is_read']) {
3034
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
3035
+			} else {
3036
+							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']));
3037
+			}
2919 3038
 
2920 3039
 			// If this is the current member we need to make their message count correct.
2921 3040
 			if ($user_info['id'] == $row['id_member'])
2922 3041
 			{
2923 3042
 				$user_info['messages'] -= $row['num_deleted_messages'];
2924
-				if (!($row['is_read']))
2925
-					$user_info['unread_messages'] -= $row['num_deleted_messages'];
3043
+				if (!($row['is_read'])) {
3044
+									$user_info['unread_messages'] -= $row['num_deleted_messages'];
3045
+				}
2926 3046
 			}
2927 3047
 		}
2928 3048
 		$smcFunc['db_free_result']($request);
@@ -2990,8 +3110,9 @@  discard block
 block discarded – undo
2990 3110
 		)
2991 3111
 	);
2992 3112
 	$remove_pms = array();
2993
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2994
-		$remove_pms[] = $row['sender'];
3113
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3114
+			$remove_pms[] = $row['sender'];
3115
+	}
2995 3116
 	$smcFunc['db_free_result']($request);
2996 3117
 
2997 3118
 	if (!empty($remove_pms))
@@ -3036,8 +3157,9 @@  discard block
 block discarded – undo
3036 3157
 {
3037 3158
 	global $user_info, $context, $smcFunc;
3038 3159
 
3039
-	if ($owner === null)
3040
-		$owner = $user_info['id'];
3160
+	if ($owner === null) {
3161
+			$owner = $user_info['id'];
3162
+	}
3041 3163
 
3042 3164
 	$in_inbox = '';
3043 3165
 
@@ -3061,8 +3183,7 @@  discard block
 block discarded – undo
3061 3183
 		}
3062 3184
 
3063 3185
 		$smcFunc['db_free_result']($get_messages);
3064
-	}
3065
-	elseif ($label = '-1')
3186
+	} elseif ($label = '-1')
3066 3187
 	{
3067 3188
 		// Marking all PMs in your inbox read
3068 3189
 		$in_inbox = '
@@ -3087,8 +3208,9 @@  discard block
 block discarded – undo
3087 3208
 	{
3088 3209
 		if ($owner == $user_info['id'])
3089 3210
 		{
3090
-			foreach ($context['labels'] as $label)
3091
-				$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3211
+			foreach ($context['labels'] as $label) {
3212
+							$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3213
+			}
3092 3214
 		}
3093 3215
 
3094 3216
 		$result = $smcFunc['db_query']('', '
@@ -3108,8 +3230,9 @@  discard block
 block discarded – undo
3108 3230
 		{
3109 3231
 			$total_unread += $row['num'];
3110 3232
 
3111
-			if ($owner != $user_info['id'] || empty($row['id_pm']))
3112
-				continue;
3233
+			if ($owner != $user_info['id'] || empty($row['id_pm'])) {
3234
+							continue;
3235
+			}
3113 3236
 
3114 3237
 			$this_labels = array();
3115 3238
 
@@ -3133,11 +3256,13 @@  discard block
 block discarded – undo
3133 3256
 
3134 3257
 			$smcFunc['db_free_result']($result2);
3135 3258
 
3136
-			foreach ($this_labels as $this_label)
3137
-				$context['labels'][$this_label]['unread_messages'] += $row['num'];
3259
+			foreach ($this_labels as $this_label) {
3260
+							$context['labels'][$this_label]['unread_messages'] += $row['num'];
3261
+			}
3138 3262
 
3139
-			if ($row['in_inbox'] == 1)
3140
-				$context['labels'][-1]['unread_messages'] += $row['num'];
3263
+			if ($row['in_inbox'] == 1) {
3264
+							$context['labels'][-1]['unread_messages'] += $row['num'];
3265
+			}
3141 3266
 		}
3142 3267
 		$smcFunc['db_free_result']($result);
3143 3268
 
@@ -3146,8 +3271,9 @@  discard block
 block discarded – undo
3146 3271
 		updateMemberData($owner, array('unread_messages' => $total_unread));
3147 3272
 
3148 3273
 		// If it was for the current member, reflect this in the $user_info array too.
3149
-		if ($owner == $user_info['id'])
3150
-			$user_info['unread_messages'] = $total_unread;
3274
+		if ($owner == $user_info['id']) {
3275
+					$user_info['unread_messages'] = $total_unread;
3276
+		}
3151 3277
 	}
3152 3278
 }
3153 3279
 
@@ -3175,8 +3301,9 @@  discard block
 block discarded – undo
3175 3301
 	// Add all existing labels to the array to save, slashing them as necessary...
3176 3302
 	foreach ($context['labels'] as $label)
3177 3303
 	{
3178
-		if ($label['id'] != -1)
3179
-			$the_labels[$label['id']] = $label['name'];
3304
+		if ($label['id'] != -1) {
3305
+					$the_labels[$label['id']] = $label['name'];
3306
+		}
3180 3307
 	}
3181 3308
 
3182 3309
 	if (isset($_POST[$context['session_var']]))
@@ -3195,8 +3322,9 @@  discard block
 block discarded – undo
3195 3322
 		{
3196 3323
 			$_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => '&#044;'));
3197 3324
 
3198
-			if ($smcFunc['strlen']($_POST['label']) > 30)
3199
-				$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3325
+			if ($smcFunc['strlen']($_POST['label']) > 30) {
3326
+							$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3327
+			}
3200 3328
 			if ($_POST['label'] != '')
3201 3329
 			{
3202 3330
 				$the_labels[] = $_POST['label'];
@@ -3217,24 +3345,25 @@  discard block
 block discarded – undo
3217 3345
 		{
3218 3346
 			foreach ($the_labels as $id => $name)
3219 3347
 			{
3220
-				if ($id == -1)
3221
-					continue;
3222
-				elseif (isset($_POST['label_name'][$id]))
3348
+				if ($id == -1) {
3349
+									continue;
3350
+				} elseif (isset($_POST['label_name'][$id]))
3223 3351
 				{
3224 3352
 					$_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => '&#044;')));
3225 3353
 
3226
-					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30)
3227
-						$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3354
+					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) {
3355
+											$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3356
+					}
3228 3357
 					if ($_POST['label_name'][$id] != '')
3229 3358
 					{
3230 3359
 						// Changing the name of this label?
3231
-						if ($the_labels[$id] != $_POST['label_name'][$id])
3232
-							$label_updates[$id] = $_POST['label_name'][$id];
3360
+						if ($the_labels[$id] != $_POST['label_name'][$id]) {
3361
+													$label_updates[$id] = $_POST['label_name'][$id];
3362
+						}
3233 3363
 
3234 3364
 						$the_labels[(int) $id] = $_POST['label_name'][$id];
3235 3365
 
3236
-					}
3237
-					else
3366
+					} else
3238 3367
 					{
3239 3368
 						unset($the_labels[(int) $id]);
3240 3369
 						$labels_to_remove[] = $id;
@@ -3248,8 +3377,9 @@  discard block
 block discarded – undo
3248 3377
 		if (!empty($labels_to_add))
3249 3378
 		{
3250 3379
 			$inserts = array();
3251
-			foreach ($labels_to_add AS $label)
3252
-				$inserts[] = array($user_info['id'], $label);
3380
+			foreach ($labels_to_add AS $label) {
3381
+							$inserts[] = array($user_info['id'], $label);
3382
+			}
3253 3383
 
3254 3384
 			$smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
3255 3385
 		}
@@ -3339,8 +3469,9 @@  discard block
 block discarded – undo
3339 3469
 				// Each action...
3340 3470
 				foreach ($rule['actions'] as $k2 => $action)
3341 3471
 				{
3342
-					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove))
3343
-						continue;
3472
+					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) {
3473
+											continue;
3474
+					}
3344 3475
 
3345 3476
 					$rule_changes[] = $rule['id'];
3346 3477
 
@@ -3355,8 +3486,8 @@  discard block
 block discarded – undo
3355 3486
 		{
3356 3487
 			$rule_changes = array_unique($rule_changes);
3357 3488
 			// Update/delete as appropriate.
3358
-			foreach ($rule_changes as $k => $id)
3359
-				if (!empty($context['rules'][$id]['actions']))
3489
+			foreach ($rule_changes as $k => $id) {
3490
+							if (!empty($context['rules'][$id]['actions']))
3360 3491
 				{
3361 3492
 					$smcFunc['db_query']('', '
3362 3493
 						UPDATE {db_prefix}pm_rules
@@ -3369,12 +3500,13 @@  discard block
 block discarded – undo
3369 3500
 							'actions' => $smcFunc['json_encode']($context['rules'][$id]['actions']),
3370 3501
 						)
3371 3502
 					);
3503
+			}
3372 3504
 					unset($rule_changes[$k]);
3373 3505
 				}
3374 3506
 
3375 3507
 			// Anything left here means it's lost all actions...
3376
-			if (!empty($rule_changes))
3377
-				$smcFunc['db_query']('', '
3508
+			if (!empty($rule_changes)) {
3509
+							$smcFunc['db_query']('', '
3378 3510
 					DELETE FROM {db_prefix}pm_rules
3379 3511
 					WHERE id_rule IN ({array_int:rule_list})
3380 3512
 							AND id_member = {int:current_member}',
@@ -3383,6 +3515,7 @@  discard block
 block discarded – undo
3383 3515
 						'rule_list' => $rule_changes,
3384 3516
 					)
3385 3517
 				);
3518
+			}
3386 3519
 		}
3387 3520
 
3388 3521
 		// Make sure we're not caching this!
@@ -3452,8 +3585,9 @@  discard block
 block discarded – undo
3452 3585
 		// Save the fields.
3453 3586
 		saveProfileFields();
3454 3587
 
3455
-		if (!empty($profile_vars))
3456
-			updateMemberData($user_info['id'], $profile_vars);
3588
+		if (!empty($profile_vars)) {
3589
+					updateMemberData($user_info['id'], $profile_vars);
3590
+		}
3457 3591
 	}
3458 3592
 
3459 3593
 	setupProfileContext(
@@ -3478,13 +3612,15 @@  discard block
 block discarded – undo
3478 3612
 	global $user_info, $language, $modSettings, $smcFunc;
3479 3613
 
3480 3614
 	// Check that this feature is even enabled!
3481
-	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg']))
3482
-		fatal_lang_error('no_access', false);
3615
+	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) {
3616
+			fatal_lang_error('no_access', false);
3617
+	}
3483 3618
 
3484 3619
 	$pmsg = (int) $_REQUEST['pmsg'];
3485 3620
 
3486
-	if (!isAccessiblePM($pmsg, 'inbox'))
3487
-		fatal_lang_error('no_access', false);
3621
+	if (!isAccessiblePM($pmsg, 'inbox')) {
3622
+			fatal_lang_error('no_access', false);
3623
+	}
3488 3624
 
3489 3625
 	$context['pm_id'] = $pmsg;
3490 3626
 	$context['page_title'] = $txt['pm_report_title'];
@@ -3506,8 +3642,9 @@  discard block
 block discarded – undo
3506 3642
 			)
3507 3643
 		);
3508 3644
 		$context['admins'] = array();
3509
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3510
-			$context['admins'][$row['id_member']] = $row['real_name'];
3645
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3646
+					$context['admins'][$row['id_member']] = $row['real_name'];
3647
+		}
3511 3648
 		$smcFunc['db_free_result']($request);
3512 3649
 
3513 3650
 		// How many admins in total?
@@ -3536,8 +3673,9 @@  discard block
 block discarded – undo
3536 3673
 			)
3537 3674
 		);
3538 3675
 		// Can only be a hacker here!
3539
-		if ($smcFunc['db_num_rows']($request) == 0)
3540
-			fatal_lang_error('no_access', false);
3676
+		if ($smcFunc['db_num_rows']($request) == 0) {
3677
+					fatal_lang_error('no_access', false);
3678
+		}
3541 3679
 		list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request);
3542 3680
 		$smcFunc['db_free_result']($request);
3543 3681
 
@@ -3561,15 +3699,17 @@  discard block
 block discarded – undo
3561 3699
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3562 3700
 		{
3563 3701
 			// If it's hidden still don't reveal their names - privacy after all ;)
3564
-			if ($row['bcc'])
3565
-				$hidden_recipients++;
3566
-			else
3567
-				$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3702
+			if ($row['bcc']) {
3703
+							$hidden_recipients++;
3704
+			} else {
3705
+							$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3706
+			}
3568 3707
 		}
3569 3708
 		$smcFunc['db_free_result']($request);
3570 3709
 
3571
-		if ($hidden_recipients)
3572
-			$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3710
+		if ($hidden_recipients) {
3711
+					$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3712
+		}
3573 3713
 
3574 3714
 		// Now let's get out and loop through the admins.
3575 3715
 		$request = $smcFunc['db_query']('', '
@@ -3585,8 +3725,9 @@  discard block
 block discarded – undo
3585 3725
 		);
3586 3726
 
3587 3727
 		// Maybe we shouldn't advertise this?
3588
-		if ($smcFunc['db_num_rows']($request) == 0)
3589
-			fatal_lang_error('no_access', false);
3728
+		if ($smcFunc['db_num_rows']($request) == 0) {
3729
+					fatal_lang_error('no_access', false);
3730
+		}
3590 3731
 
3591 3732
 		$memberFromName = un_htmlspecialchars($memberFromName);
3592 3733
 
@@ -3605,8 +3746,9 @@  discard block
 block discarded – undo
3605 3746
 				// Make the body.
3606 3747
 				$report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']);
3607 3748
 				$report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n";
3608
-				if (!empty($recipients))
3609
-					$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3749
+				if (!empty($recipients)) {
3750
+									$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3751
+				}
3610 3752
 				$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]';
3611 3753
 
3612 3754
 				// Plonk it in the array ;)
@@ -3626,12 +3768,14 @@  discard block
 block discarded – undo
3626 3768
 		$smcFunc['db_free_result']($request);
3627 3769
 
3628 3770
 		// Send a different email for each language.
3629
-		foreach ($messagesToSend as $lang => $message)
3630
-			sendpm($message['recipients'], $message['subject'], $message['body']);
3771
+		foreach ($messagesToSend as $lang => $message) {
3772
+					sendpm($message['recipients'], $message['subject'], $message['body']);
3773
+		}
3631 3774
 
3632 3775
 		// Give the user their own language back!
3633
-		if (!empty($modSettings['userLanguage']))
3634
-			loadLanguage('PersonalMessage', '', false);
3776
+		if (!empty($modSettings['userLanguage'])) {
3777
+					loadLanguage('PersonalMessage', '', false);
3778
+		}
3635 3779
 
3636 3780
 		// Leave them with a template.
3637 3781
 		$context['sub_template'] = 'report_message_complete';
@@ -3677,8 +3821,9 @@  discard block
 block discarded – undo
3677 3821
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3678 3822
 	{
3679 3823
 		// Hide hidden groups!
3680
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
3681
-			continue;
3824
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
3825
+					continue;
3826
+		}
3682 3827
 
3683 3828
 		$context['groups'][$row['id_group']] = $row['group_name'];
3684 3829
 	}
@@ -3704,9 +3849,10 @@  discard block
 block discarded – undo
3704 3849
 			$context['rule'] = $context['rules'][$context['rid']];
3705 3850
 			$members = array();
3706 3851
 			// Need to get member names!
3707
-			foreach ($context['rule']['criteria'] as $k => $criteria)
3708
-				if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3852
+			foreach ($context['rule']['criteria'] as $k => $criteria) {
3853
+							if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3709 3854
 					$members[(int) $criteria['v']] = $k;
3855
+			}
3710 3856
 
3711 3857
 			if (!empty($members))
3712 3858
 			{
@@ -3718,19 +3864,20 @@  discard block
 block discarded – undo
3718 3864
 						'member_list' => array_keys($members),
3719 3865
 					)
3720 3866
 				);
3721
-				while ($row = $smcFunc['db_fetch_assoc']($request))
3722
-					$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3867
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
3868
+									$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3869
+				}
3723 3870
 				$smcFunc['db_free_result']($request);
3724 3871
 			}
3725
-		}
3726
-		else
3727
-			$context['rule'] = array(
3872
+		} else {
3873
+					$context['rule'] = array(
3728 3874
 				'id' => '',
3729 3875
 				'name' => '',
3730 3876
 				'criteria' => array(),
3731 3877
 				'actions' => array(),
3732 3878
 				'logic' => 'and',
3733 3879
 			);
3880
+		}
3734 3881
 	}
3735 3882
 	// Saving?
3736 3883
 	elseif (isset($_GET['save']))
@@ -3740,22 +3887,25 @@  discard block
 block discarded – undo
3740 3887
 
3741 3888
 		// Name is easy!
3742 3889
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
3743
-		if (empty($ruleName))
3744
-			fatal_lang_error('pm_rule_no_name', false);
3890
+		if (empty($ruleName)) {
3891
+					fatal_lang_error('pm_rule_no_name', false);
3892
+		}
3745 3893
 
3746 3894
 		// Sanity check...
3747
-		if (empty($_POST['ruletype']) || empty($_POST['acttype']))
3748
-			fatal_lang_error('pm_rule_no_criteria', false);
3895
+		if (empty($_POST['ruletype']) || empty($_POST['acttype'])) {
3896
+					fatal_lang_error('pm_rule_no_criteria', false);
3897
+		}
3749 3898
 
3750 3899
 		// Let's do the criteria first - it's also hardest!
3751 3900
 		$criteria = array();
3752 3901
 		foreach ($_POST['ruletype'] as $ind => $type)
3753 3902
 		{
3754 3903
 			// Check everything is here...
3755
-			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]])))
3756
-				continue;
3757
-			elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind]))
3758
-				continue;
3904
+			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) {
3905
+							continue;
3906
+			} elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) {
3907
+							continue;
3908
+			}
3759 3909
 
3760 3910
 			// Members need to be found.
3761 3911
 			if ($type == 'mid')
@@ -3779,13 +3929,13 @@  discard block
 block discarded – undo
3779 3929
 				$smcFunc['db_free_result']($request);
3780 3930
 
3781 3931
 				$criteria[] = array('t' => 'mid', 'v' => $memID);
3932
+			} elseif ($type == 'bud') {
3933
+							$criteria[] = array('t' => 'bud', 'v' => 1);
3934
+			} elseif ($type == 'gid') {
3935
+							$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3936
+			} elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') {
3937
+							$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3782 3938
 			}
3783
-			elseif ($type == 'bud')
3784
-				$criteria[] = array('t' => 'bud', 'v' => 1);
3785
-			elseif ($type == 'gid')
3786
-				$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3787
-			elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '')
3788
-				$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3789 3939
 		}
3790 3940
 
3791 3941
 		// Also do the actions!
@@ -3795,26 +3945,29 @@  discard block
 block discarded – undo
3795 3945
 		foreach ($_POST['acttype'] as $ind => $type)
3796 3946
 		{
3797 3947
 			// Picking a valid label?
3798
-			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]])))
3799
-				continue;
3948
+			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) {
3949
+							continue;
3950
+			}
3800 3951
 
3801 3952
 			// Record what we're doing.
3802
-			if ($type == 'del')
3803
-				$doDelete = 1;
3804
-			elseif ($type == 'lab')
3805
-				$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3953
+			if ($type == 'del') {
3954
+							$doDelete = 1;
3955
+			} elseif ($type == 'lab') {
3956
+							$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3957
+			}
3806 3958
 		}
3807 3959
 
3808
-		if (empty($criteria) || (empty($actions) && !$doDelete))
3809
-			fatal_lang_error('pm_rule_no_criteria', false);
3960
+		if (empty($criteria) || (empty($actions) && !$doDelete)) {
3961
+					fatal_lang_error('pm_rule_no_criteria', false);
3962
+		}
3810 3963
 
3811 3964
 		// What are we storing?
3812 3965
 		$criteria = $smcFunc['json_encode']($criteria);
3813 3966
 		$actions = $smcFunc['json_encode']($actions);
3814 3967
 
3815 3968
 		// Create the rule?
3816
-		if (empty($context['rid']))
3817
-			$smcFunc['db_insert']('',
3969
+		if (empty($context['rid'])) {
3970
+					$smcFunc['db_insert']('',
3818 3971
 				'{db_prefix}pm_rules',
3819 3972
 				array(
3820 3973
 					'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string',
@@ -3825,8 +3978,8 @@  discard block
 block discarded – undo
3825 3978
 				),
3826 3979
 				array('id_rule')
3827 3980
 			);
3828
-		else
3829
-			$smcFunc['db_query']('', '
3981
+		} else {
3982
+					$smcFunc['db_query']('', '
3830 3983
 				UPDATE {db_prefix}pm_rules
3831 3984
 				SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions},
3832 3985
 					delete_pm = {int:delete_pm}, is_or = {int:is_or}
@@ -3842,6 +3995,7 @@  discard block
 block discarded – undo
3842 3995
 					'actions' => $actions,
3843 3996
 				)
3844 3997
 			);
3998
+		}
3845 3999
 
3846 4000
 		redirectexit('action=pm;sa=manrules');
3847 4001
 	}
@@ -3850,11 +4004,12 @@  discard block
 block discarded – undo
3850 4004
 	{
3851 4005
 		checkSession();
3852 4006
 		$toDelete = array();
3853
-		foreach ($_POST['delrule'] as $k => $v)
3854
-			$toDelete[] = (int) $k;
4007
+		foreach ($_POST['delrule'] as $k => $v) {
4008
+					$toDelete[] = (int) $k;
4009
+		}
3855 4010
 
3856
-		if (!empty($toDelete))
3857
-			$smcFunc['db_query']('', '
4011
+		if (!empty($toDelete)) {
4012
+					$smcFunc['db_query']('', '
3858 4013
 				DELETE FROM {db_prefix}pm_rules
3859 4014
 				WHERE id_rule IN ({array_int:delete_list})
3860 4015
 					AND id_member = {int:current_member}',
@@ -3863,6 +4018,7 @@  discard block
 block discarded – undo
3863 4018
 					'delete_list' => $toDelete,
3864 4019
 				)
3865 4020
 			);
4021
+		}
3866 4022
 
3867 4023
 		redirectexit('action=pm;sa=manrules');
3868 4024
 	}
@@ -3881,8 +4037,9 @@  discard block
 block discarded – undo
3881 4037
 	loadRules();
3882 4038
 
3883 4039
 	// No rules?
3884
-	if (empty($context['rules']))
3885
-		return;
4040
+	if (empty($context['rules'])) {
4041
+			return;
4042
+	}
3886 4043
 
3887 4044
 	// Just unread ones?
3888 4045
 	$ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1';
@@ -3912,8 +4069,9 @@  discard block
 block discarded – undo
3912 4069
 			// Loop through all the criteria hoping to make a match.
3913 4070
 			foreach ($rule['criteria'] as $criterium)
3914 4071
 			{
3915
-				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))
3916
-					$match = true;
4072
+				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)) {
4073
+									$match = true;
4074
+				}
3917 4075
 				// If we're adding and one criteria don't match then we stop!
3918 4076
 				elseif ($rule['logic'] == 'and')
3919 4077
 				{
@@ -3925,17 +4083,18 @@  discard block
 block discarded – undo
3925 4083
 			// If we have a match the rule must be true - act!
3926 4084
 			if ($match)
3927 4085
 			{
3928
-				if ($rule['delete'])
3929
-					$actions['deletes'][] = $row['id_pm'];
3930
-				else
4086
+				if ($rule['delete']) {
4087
+									$actions['deletes'][] = $row['id_pm'];
4088
+				} else
3931 4089
 				{
3932 4090
 					foreach ($rule['actions'] as $ruleAction)
3933 4091
 					{
3934 4092
 						if ($ruleAction['t'] == 'lab')
3935 4093
 						{
3936 4094
 							// Get a basic pot started!
3937
-							if (!isset($actions['labels'][$row['id_pm']]))
3938
-								$actions['labels'][$row['id_pm']] = array();
4095
+							if (!isset($actions['labels'][$row['id_pm']])) {
4096
+															$actions['labels'][$row['id_pm']] = array();
4097
+							}
3939 4098
 							$actions['labels'][$row['id_pm']][] = $ruleAction['v'];
3940 4099
 						}
3941 4100
 					}
@@ -3946,8 +4105,9 @@  discard block
 block discarded – undo
3946 4105
 	$smcFunc['db_free_result']($request);
3947 4106
 
3948 4107
 	// Deletes are easy!
3949
-	if (!empty($actions['deletes']))
3950
-		deleteMessages($actions['deletes']);
4108
+	if (!empty($actions['deletes'])) {
4109
+			deleteMessages($actions['deletes']);
4110
+	}
3951 4111
 
3952 4112
 	// Relabel?
3953 4113
 	if (!empty($actions['labels']))
@@ -3974,8 +4134,7 @@  discard block
 block discarded – undo
3974 4134
 								'current_member' => $user_info['id'],
3975 4135
 							)
3976 4136
 						);
3977
-					}
3978
-					else
4137
+					} else
3979 4138
 					{
3980 4139
 						$realLabels[] = $label['id'];
3981 4140
 					}
@@ -3984,8 +4143,9 @@  discard block
 block discarded – undo
3984 4143
 
3985 4144
 			$inserts = array();
3986 4145
 			// Now we insert the label info
3987
-			foreach ($realLabels as $a_label)
3988
-				$inserts[] = array($pm, $a_label);
4146
+			foreach ($realLabels as $a_label) {
4147
+							$inserts[] = array($pm, $a_label);
4148
+			}
3989 4149
 
3990 4150
 			$smcFunc['db_insert']('ignore',
3991 4151
 				'{db_prefix}pm_labeled_messages',
@@ -4006,8 +4166,9 @@  discard block
 block discarded – undo
4006 4166
 {
4007 4167
 	global $user_info, $context, $smcFunc;
4008 4168
 
4009
-	if (isset($context['rules']) && !$reload)
4010
-		return;
4169
+	if (isset($context['rules']) && !$reload) {
4170
+			return;
4171
+	}
4011 4172
 
4012 4173
 	$request = $smcFunc['db_query']('', '
4013 4174
 		SELECT
@@ -4031,8 +4192,9 @@  discard block
 block discarded – undo
4031 4192
 			'logic' => $row['is_or'] ? 'or' : 'and',
4032 4193
 		);
4033 4194
 
4034
-		if ($row['delete_pm'])
4035
-			$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4195
+		if ($row['delete_pm']) {
4196
+					$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4197
+		}
4036 4198
 	}
4037 4199
 	$smcFunc['db_free_result']($request);
4038 4200
 }
Please login to merge, or discard this patch.
Sources/Profile-Modify.php 2 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2183,7 +2183,7 @@  discard block
 block discarded – undo
2183 2183
  * Deletes a single or a group of alerts by ID
2184 2184
  *
2185 2185
  * @param int|array The ID of a single alert to delete or an array containing the IDs of multiple alerts. The function will convert integers into an array for better handling.
2186
- * @param bool|int $memID The user ID. Used to update the user unread alerts count.
2186
+ * @param integer $memID The user ID. Used to update the user unread alerts count.
2187 2187
  * @return void|int If the $memID param is set, returns the new amount of unread alerts.
2188 2188
  */
2189 2189
 function alert_delete($toDelete, $memID = false)
@@ -2839,7 +2839,7 @@  discard block
 block discarded – undo
2839 2839
 /**
2840 2840
  * Handles the "manage groups" section of the profile
2841 2841
  *
2842
- * @return true Always returns true
2842
+ * @return boolean Always returns true
2843 2843
  */
2844 2844
 function profileLoadGroups()
2845 2845
 {
@@ -2896,7 +2896,7 @@  discard block
 block discarded – undo
2896 2896
 /**
2897 2897
  * Load key signature context data.
2898 2898
  *
2899
- * @return true Always returns true
2899
+ * @return boolean Always returns true
2900 2900
  */
2901 2901
 function profileLoadSignatureData()
2902 2902
 {
@@ -2960,7 +2960,7 @@  discard block
 block discarded – undo
2960 2960
 /**
2961 2961
  * Load avatar context data.
2962 2962
  *
2963
- * @return true Always returns true
2963
+ * @return boolean Always returns true
2964 2964
  */
2965 2965
 function profileLoadAvatarData()
2966 2966
 {
@@ -3033,7 +3033,7 @@  discard block
 block discarded – undo
3033 3033
  * Save a members group.
3034 3034
  *
3035 3035
  * @param int &$value The ID of the (new) primary group
3036
- * @return true Always returns true
3036
+ * @return boolean Always returns true
3037 3037
  */
3038 3038
 function profileSaveGroups(&$value)
3039 3039
 {
@@ -3138,7 +3138,7 @@  discard block
 block discarded – undo
3138 3138
  * @todo argh, the avatar here. Take this out of here!
3139 3139
  *
3140 3140
  * @param string &$value What kind of avatar we're expecting. Can be 'none', 'server_stored', 'gravatar', 'external' or 'upload'
3141
- * @return bool|string False if success (or if memID is empty and password authentication failed), otherwise a string indicating what error occurred
3141
+ * @return false|string False if success (or if memID is empty and password authentication failed), otherwise a string indicating what error occurred
3142 3142
  */
3143 3143
 function profileSaveAvatarData(&$value)
3144 3144
 {
Please login to merge, or discard this patch.
Braces   +703 added lines, -527 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 defines every profile field known to man.
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $sourcedir, $profile_vars;
30 31
 
31 32
 	// Don't load this twice!
32
-	if (!empty($profile_fields) && !$force_reload)
33
-		return;
33
+	if (!empty($profile_fields) && !$force_reload) {
34
+			return;
35
+	}
34 36
 
35 37
 	/* This horrific array defines all the profile fields in the whole world!
36 38
 		In general each "field" has one array - the key of which is the database column name associated with said field. Each item
@@ -103,13 +105,14 @@  discard block
 block discarded – undo
103 105
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 106
 				{
105 107
 					// Set to blank?
106
-					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
107
-						$value = '1004-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '1004-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
112
+					}
113
+				} else {
114
+									$value = '1004-01-01';
110 115
 				}
111
-				else
112
-					$value = '1004-01-01';
113 116
 
114 117
 				$profile_vars['birthdate'] = $value;
115 118
 				$cur_profile['birthdate'] = $value;
@@ -127,8 +130,7 @@  discard block
 block discarded – undo
127 130
 				{
128 131
 					$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '1004-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '1004-01-01' : $cur_profile['birthdate'];
134 136
 					return false;
@@ -150,10 +152,11 @@  discard block
 block discarded – undo
150 152
 					return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
151 153
 				}
152 154
 				// As long as it doesn't equal "N/A"...
153
-				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
154
-					$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
155
-				else
156
-					$value = $cur_profile['date_registered'];
155
+				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) {
156
+									$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
157
+				} else {
158
+									$value = $cur_profile['date_registered'];
159
+				}
157 160
 
158 161
 				return true;
159 162
 			},
@@ -177,8 +180,9 @@  discard block
 block discarded – undo
177 180
 			{
178 181
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 182
 
180
-				if (strtolower($value) == strtolower($old_profile['email_address']))
181
-					return false;
183
+				if (strtolower($value) == strtolower($old_profile['email_address'])) {
184
+									return false;
185
+				}
182 186
 
183 187
 				$isValid = profileValidateEmail($value, $context['id_member']);
184 188
 
@@ -254,11 +258,11 @@  discard block
 block discarded – undo
254 258
 
255 259
 				if (isset($context['profile_languages'][$value]))
256 260
 				{
257
-					if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
258
-						$_SESSION['language'] = $value;
261
+					if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) {
262
+											$_SESSION['language'] = $value;
263
+					}
259 264
 					return true;
260
-				}
261
-				else
265
+				} else
262 266
 				{
263 267
 					$value = $cur_profile['lngfile'];
264 268
 					return false;
@@ -282,13 +286,14 @@  discard block
 block discarded – undo
282 286
 
283 287
 					// Maybe they are trying to change their password as well?
284 288
 					$resetPassword = true;
285
-					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
286
-						$resetPassword = false;
289
+					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) {
290
+											$resetPassword = false;
291
+					}
287 292
 
288 293
 					// Do the reset... this will send them an email too.
289
-					if ($resetPassword)
290
-						resetPassword($context['id_member'], $value);
291
-					elseif ($value !== null)
294
+					if ($resetPassword) {
295
+											resetPassword($context['id_member'], $value);
296
+					} elseif ($value !== null)
292 297
 					{
293 298
 						validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
294 299
 						updateMemberData($context['id_member'], array('member_name' => $value));
@@ -312,20 +317,23 @@  discard block
 block discarded – undo
312 317
 			'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 318
 			{
314 319
 				// If we didn't try it then ignore it!
315
-				if ($value == '')
316
-					return false;
320
+				if ($value == '') {
321
+									return false;
322
+				}
317 323
 
318 324
 				// Do the two entries for the password even match?
319
-				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
320
-					return 'bad_new_password';
325
+				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) {
326
+									return 'bad_new_password';
327
+				}
321 328
 
322 329
 				// Let's get the validation function into play...
323 330
 				require_once($sourcedir . '/Subs-Auth.php');
324 331
 				$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
325 332
 
326 333
 				// Were there errors?
327
-				if ($passwordErrors != null)
328
-					return 'password_' . $passwordErrors;
334
+				if ($passwordErrors != null) {
335
+									return 'password_' . $passwordErrors;
336
+				}
329 337
 
330 338
 				// Set up the new password variable... ready for storage.
331 339
 				$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
@@ -350,8 +358,9 @@  discard block
 block discarded – undo
350 358
 			'permission' => 'profile_blurb',
351 359
 			'input_validate' => function(&$value) use ($smcFunc)
352 360
 			{
353
-				if ($smcFunc['strlen']($value) > 50)
354
-					return 'personal_text_too_long';
361
+				if ($smcFunc['strlen']($value) > 50) {
362
+									return 'personal_text_too_long';
363
+				}
355 364
 
356 365
 				return true;
357 366
 			},
@@ -386,10 +395,11 @@  discard block
 block discarded – undo
386 395
 			'permission' => 'moderate_forum',
387 396
 			'input_validate' => function(&$value)
388 397
 			{
389
-				if (!is_numeric($value))
390
-					return 'digits_only';
391
-				else
392
-					$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
398
+				if (!is_numeric($value)) {
399
+									return 'digits_only';
400
+				} else {
401
+									$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
402
+				}
393 403
 				return true;
394 404
 			},
395 405
 		),
@@ -405,15 +415,16 @@  discard block
 block discarded – undo
405 415
 			{
406 416
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 417
 
408
-				if (trim($value) == '')
409
-					return 'no_name';
410
-				elseif ($smcFunc['strlen']($value) > 60)
411
-					return 'name_too_long';
412
-				elseif ($cur_profile['real_name'] != $value)
418
+				if (trim($value) == '') {
419
+									return 'no_name';
420
+				} elseif ($smcFunc['strlen']($value) > 60) {
421
+									return 'name_too_long';
422
+				} elseif ($cur_profile['real_name'] != $value)
413 423
 				{
414 424
 					require_once($sourcedir . '/Subs-Members.php');
415
-					if (isReservedName($value, $context['id_member']))
416
-						return 'name_taken';
425
+					if (isReservedName($value, $context['id_member'])) {
426
+											return 'name_taken';
427
+					}
417 428
 				}
418 429
 				return true;
419 430
 			},
@@ -471,8 +482,9 @@  discard block
 block discarded – undo
471 482
 						'selected' => $set == $context['member']['smiley_set']['id']
472 483
 					);
473 484
 
474
-					if ($context['smiley_sets'][$i]['selected'])
475
-						$context['member']['smiley_set']['name'] = $set_names[$i];
485
+					if ($context['smiley_sets'][$i]['selected']) {
486
+											$context['member']['smiley_set']['name'] = $set_names[$i];
487
+					}
476 488
 				}
477 489
 				return true;
478 490
 			},
@@ -481,8 +493,9 @@  discard block
 block discarded – undo
481 493
 				global $modSettings;
482 494
 
483 495
 				$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
484
-				if (!in_array($value, $smiley_sets) && $value != 'none')
485
-					$value = '';
496
+				if (!in_array($value, $smiley_sets) && $value != 'none') {
497
+									$value = '';
498
+				}
486 499
 				return true;
487 500
 			},
488 501
 		),
@@ -497,8 +510,9 @@  discard block
 block discarded – undo
497 510
 				loadLanguage('Settings');
498 511
 
499 512
 				$context['allow_no_censored'] = false;
500
-				if ($user_info['is_admin'] || $context['user']['is_owner'])
501
-					$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
513
+				if ($user_info['is_admin'] || $context['user']['is_owner']) {
514
+									$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
515
+				}
502 516
 
503 517
 				return true;
504 518
 			},
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 			'input_validate' => function($value)
546 560
 			{
547 561
 				$tz = smf_list_timezones();
548
-				if (!isset($tz[$value]))
549
-					return 'bad_timezone';
562
+				if (!isset($tz[$value])) {
563
+									return 'bad_timezone';
564
+				}
550 565
 
551 566
 				return true;
552 567
 			},
@@ -561,8 +576,9 @@  discard block
 block discarded – undo
561 576
 			'enabled' => !empty($modSettings['titlesEnable']),
562 577
 			'input_validate' => function(&$value) use ($smcFunc)
563 578
 			{
564
-				if ($smcFunc['strlen']($value) > 50)
565
-					return 'user_title_too_long';
579
+				if ($smcFunc['strlen']($value) > 50) {
580
+									return 'user_title_too_long';
581
+				}
566 582
 
567 583
 				return true;
568 584
 			},
@@ -584,10 +600,12 @@  discard block
 block discarded – undo
584 600
 			// Fix the URL...
585 601
 			'input_validate' => function(&$value)
586 602
 			{
587
-				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588
-					$value = 'http://' . $value;
589
-				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
590
-					$value = '';
603
+				if (strlen(trim($value)) > 0 && strpos($value, '://') === false) {
604
+									$value = 'http://' . $value;
605
+				}
606
+				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) {
607
+									$value = '';
608
+				}
591 609
 				return true;
592 610
 			},
593 611
 			'link_with' => 'website',
@@ -601,16 +619,19 @@  discard block
 block discarded – undo
601 619
 	foreach ($profile_fields as $key => $field)
602 620
 	{
603 621
 		// Do we have permission to do this?
604
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
605
-			unset($profile_fields[$key]);
622
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
623
+					unset($profile_fields[$key]);
624
+		}
606 625
 
607 626
 		// Is it enabled?
608
-		if (isset($field['enabled']) && !$field['enabled'])
609
-			unset($profile_fields[$key]);
627
+		if (isset($field['enabled']) && !$field['enabled']) {
628
+					unset($profile_fields[$key]);
629
+		}
610 630
 
611 631
 		// Is it specifically disabled?
612
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
613
-			unset($profile_fields[$key]);
632
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
633
+					unset($profile_fields[$key]);
634
+		}
614 635
 	}
615 636
 }
616 637
 
@@ -635,9 +656,10 @@  discard block
 block discarded – undo
635 656
 	loadProfileFields(true);
636 657
 
637 658
 	// First check for any linked sets.
638
-	foreach ($profile_fields as $key => $field)
639
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
659
+	foreach ($profile_fields as $key => $field) {
660
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
640 661
 			$fields[] = $key;
662
+	}
641 663
 
642 664
 	$i = 0;
643 665
 	$last_type = '';
@@ -649,38 +671,46 @@  discard block
 block discarded – undo
649 671
 			$cur_field = &$profile_fields[$field];
650 672
 
651 673
 			// Does it have a preload and does that preload succeed?
652
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
653
-				continue;
674
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
675
+							continue;
676
+			}
654 677
 
655 678
 			// If this is anything but complex we need to do more cleaning!
656 679
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
657 680
 			{
658
-				if (!isset($cur_field['label']))
659
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
681
+				if (!isset($cur_field['label'])) {
682
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
683
+				}
660 684
 
661 685
 				// Everything has a value!
662
-				if (!isset($cur_field['value']))
663
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
686
+				if (!isset($cur_field['value'])) {
687
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
688
+				}
664 689
 
665 690
 				// Any input attributes?
666 691
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
667 692
 			}
668 693
 
669 694
 			// Was there an error with this field on posting?
670
-			if (isset($context['profile_errors'][$field]))
671
-				$cur_field['is_error'] = true;
695
+			if (isset($context['profile_errors'][$field])) {
696
+							$cur_field['is_error'] = true;
697
+			}
672 698
 
673 699
 			// Any javascript stuff?
674
-			if (!empty($cur_field['js_submit']))
675
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
676
-			if (!empty($cur_field['js']))
677
-				$context['profile_javascript'] .= $cur_field['js'];
700
+			if (!empty($cur_field['js_submit'])) {
701
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
702
+			}
703
+			if (!empty($cur_field['js'])) {
704
+							$context['profile_javascript'] .= $cur_field['js'];
705
+			}
678 706
 
679 707
 			// Any template stuff?
680
-			if (!empty($cur_field['prehtml']))
681
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
682
-			if (!empty($cur_field['posthtml']))
683
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
708
+			if (!empty($cur_field['prehtml'])) {
709
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
710
+			}
711
+			if (!empty($cur_field['posthtml'])) {
712
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
713
+			}
684 714
 
685 715
 			// Finally put it into context?
686 716
 			if ($cur_field['type'] != 'hidden')
@@ -713,12 +743,14 @@  discard block
 block discarded – undo
713 743
 	}, false);' : ''), true);
714 744
 
715 745
 	// Any onsubmit javascript?
716
-	if (!empty($context['profile_onsubmit_javascript']))
717
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
746
+	if (!empty($context['profile_onsubmit_javascript'])) {
747
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
748
+	}
718 749
 
719 750
 	// Any totally custom stuff?
720
-	if (!empty($context['profile_javascript']))
721
-		addInlineJavaScript($context['profile_javascript'], true);
751
+	if (!empty($context['profile_javascript'])) {
752
+			addInlineJavaScript($context['profile_javascript'], true);
753
+	}
722 754
 
723 755
 	// Free up some memory.
724 756
 	unset($profile_fields);
@@ -739,8 +771,9 @@  discard block
 block discarded – undo
739 771
 
740 772
 	// This allows variables to call activities when they save - by default just to reload their settings
741 773
 	$context['profile_execute_on_save'] = array();
742
-	if ($context['user']['is_owner'])
743
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
774
+	if ($context['user']['is_owner']) {
775
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
776
+	}
744 777
 
745 778
 	// Assume we log nothing.
746 779
 	$context['log_changes'] = array();
@@ -748,8 +781,9 @@  discard block
 block discarded – undo
748 781
 	// Cycle through the profile fields working out what to do!
749 782
 	foreach ($profile_fields as $key => $field)
750 783
 	{
751
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
752
-			continue;
784
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
785
+					continue;
786
+		}
753 787
 
754 788
 		// What gets updated?
755 789
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -777,12 +811,13 @@  discard block
 block discarded – undo
777 811
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
778 812
 
779 813
 		// Finally, clean up certain types.
780
-		if ($field['cast_type'] == 'int')
781
-			$_POST[$key] = (int) $_POST[$key];
782
-		elseif ($field['cast_type'] == 'float')
783
-			$_POST[$key] = (float) $_POST[$key];
784
-		elseif ($field['cast_type'] == 'check')
785
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
814
+		if ($field['cast_type'] == 'int') {
815
+					$_POST[$key] = (int) $_POST[$key];
816
+		} elseif ($field['cast_type'] == 'float') {
817
+					$_POST[$key] = (float) $_POST[$key];
818
+		} elseif ($field['cast_type'] == 'check') {
819
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
820
+		}
786 821
 
787 822
 		// If we got here we're doing OK.
788 823
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -793,11 +828,12 @@  discard block
 block discarded – undo
793 828
 			$cur_profile[$key] = $_POST[$key];
794 829
 
795 830
 			// Are we logging it?
796
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
797
-				$context['log_changes'][$key] = array(
831
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
832
+							$context['log_changes'][$key] = array(
798 833
 					'previous' => $old_profile[$key],
799 834
 					'new' => $_POST[$key],
800 835
 				);
836
+			}
801 837
 		}
802 838
 
803 839
 		// Logging group changes are a bit different...
@@ -830,10 +866,11 @@  discard block
 block discarded – undo
830 866
 				{
831 867
 					foreach ($groups as $id => $group)
832 868
 					{
833
-						if (isset($context['member_groups'][$group]))
834
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
835
-						else
836
-							unset($additional_groups[$type][$id]);
869
+						if (isset($context['member_groups'][$group])) {
870
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
871
+						} else {
872
+													unset($additional_groups[$type][$id]);
873
+						}
837 874
 					}
838 875
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
839 876
 				}
@@ -844,10 +881,11 @@  discard block
 block discarded – undo
844 881
 	}
845 882
 
846 883
 	// @todo Temporary
847
-	if ($context['user']['is_owner'])
848
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
849
-	else
850
-		$changeOther = allowedTo('profile_extra_any');
884
+	if ($context['user']['is_owner']) {
885
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
886
+	} else {
887
+			$changeOther = allowedTo('profile_extra_any');
888
+	}
851 889
 	if ($changeOther && empty($post_errors))
852 890
 	{
853 891
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -855,8 +893,9 @@  discard block
 block discarded – undo
855 893
 		{
856 894
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
857 895
 
858
-			if (!empty($custom_fields_errors))
859
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
896
+			if (!empty($custom_fields_errors)) {
897
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
898
+			}
860 899
 		}
861 900
 	}
862 901
 
@@ -882,9 +921,9 @@  discard block
 block discarded – undo
882 921
 	if ($context['user']['is_owner'])
883 922
 	{
884 923
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
924
+	} else {
925
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
885 926
 	}
886
-	else
887
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
888 927
 
889 928
 	// Arrays of all the changes - makes things easier.
890 929
 	$profile_bools = array();
@@ -895,22 +934,25 @@  discard block
 block discarded – undo
895 934
 		'ignore_boards',
896 935
 	);
897 936
 
898
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
899
-		$_POST['ignore_brd'] = array();
937
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
938
+			$_POST['ignore_brd'] = array();
939
+	}
900 940
 
901 941
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
902 942
 	if (isset($_POST['ignore_brd']))
903 943
 	{
904
-		if (!is_array($_POST['ignore_brd']))
905
-			$_POST['ignore_brd'] = array($_POST['ignore_brd']);
944
+		if (!is_array($_POST['ignore_brd'])) {
945
+					$_POST['ignore_brd'] = array($_POST['ignore_brd']);
946
+		}
906 947
 
907 948
 		foreach ($_POST['ignore_brd'] as $k => $d)
908 949
 		{
909 950
 			$d = (int) $d;
910
-			if ($d != 0)
911
-				$_POST['ignore_brd'][$k] = $d;
912
-			else
913
-				unset($_POST['ignore_brd'][$k]);
951
+			if ($d != 0) {
952
+							$_POST['ignore_brd'][$k] = $d;
953
+			} else {
954
+							unset($_POST['ignore_brd'][$k]);
955
+			}
914 956
 		}
915 957
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
916 958
 		unset($_POST['ignore_brd']);
@@ -923,21 +965,26 @@  discard block
 block discarded – undo
923 965
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
924 966
 		//makeAvatarChanges($memID, $post_errors);
925 967
 
926
-		if (!empty($_REQUEST['sa']))
927
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
968
+		if (!empty($_REQUEST['sa'])) {
969
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
970
+		}
928 971
 
929
-		foreach ($profile_bools as $var)
930
-			if (isset($_POST[$var]))
972
+		foreach ($profile_bools as $var) {
973
+					if (isset($_POST[$var]))
931 974
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
932
-		foreach ($profile_ints as $var)
933
-			if (isset($_POST[$var]))
975
+		}
976
+		foreach ($profile_ints as $var) {
977
+					if (isset($_POST[$var]))
934 978
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
935
-		foreach ($profile_floats as $var)
936
-			if (isset($_POST[$var]))
979
+		}
980
+		foreach ($profile_floats as $var) {
981
+					if (isset($_POST[$var]))
937 982
 				$profile_vars[$var] = (float) $_POST[$var];
938
-		foreach ($profile_strings as $var)
939
-			if (isset($_POST[$var]))
983
+		}
984
+		foreach ($profile_strings as $var) {
985
+					if (isset($_POST[$var]))
940 986
 				$profile_vars[$var] = $_POST[$var];
987
+		}
941 988
 	}
942 989
 }
943 990
 
@@ -971,8 +1018,9 @@  discard block
 block discarded – undo
971 1018
 	);
972 1019
 
973 1020
 	// Can't change reserved vars.
974
-	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
975
-		fatal_lang_error('no_access', false);
1021
+	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) {
1022
+			fatal_lang_error('no_access', false);
1023
+	}
976 1024
 
977 1025
 	// Don't allow any overriding of custom fields with default or non-default options.
978 1026
 	$request = $smcFunc['db_query']('', '
@@ -984,8 +1032,9 @@  discard block
 block discarded – undo
984 1032
 		)
985 1033
 	);
986 1034
 	$custom_fields = array();
987
-	while ($row = $smcFunc['db_fetch_assoc']($request))
988
-		$custom_fields[] = $row['col_name'];
1035
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1036
+			$custom_fields[] = $row['col_name'];
1037
+	}
989 1038
 	$smcFunc['db_free_result']($request);
990 1039
 
991 1040
 	// These are the theme changes...
@@ -994,33 +1043,39 @@  discard block
 block discarded – undo
994 1043
 	{
995 1044
 		foreach ($_POST['options'] as $opt => $val)
996 1045
 		{
997
-			if (in_array($opt, $custom_fields))
998
-				continue;
1046
+			if (in_array($opt, $custom_fields)) {
1047
+							continue;
1048
+			}
999 1049
 
1000 1050
 			// These need to be controlled.
1001
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1002
-				$val = max(0, min($val, 50));
1051
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1052
+							$val = max(0, min($val, 50));
1053
+			}
1003 1054
 			// We don't set this per theme anymore.
1004
-			elseif ($opt == 'allow_no_censored')
1005
-				continue;
1055
+			elseif ($opt == 'allow_no_censored') {
1056
+							continue;
1057
+			}
1006 1058
 
1007 1059
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1008 1060
 		}
1009 1061
 	}
1010 1062
 
1011 1063
 	$erase_options = array();
1012
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1013
-		foreach ($_POST['default_options'] as $opt => $val)
1064
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1065
+			foreach ($_POST['default_options'] as $opt => $val)
1014 1066
 		{
1015 1067
 			if (in_array($opt, $custom_fields))
1016 1068
 				continue;
1069
+	}
1017 1070
 
1018 1071
 			// These need to be controlled.
1019
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1020
-				$val = max(0, min($val, 50));
1072
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1073
+							$val = max(0, min($val, 50));
1074
+			}
1021 1075
 			// Only let admins and owners change the censor.
1022
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1023
-					continue;
1076
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1077
+								continue;
1078
+			}
1024 1079
 
1025 1080
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1026 1081
 			$erase_options[] = $opt;
@@ -1056,8 +1111,9 @@  discard block
 block discarded – undo
1056 1111
 
1057 1112
 		// Admins can choose any theme, even if it's not enabled...
1058 1113
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1059
-		foreach ($themes as $t)
1060
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1114
+		foreach ($themes as $t) {
1115
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1116
+		}
1061 1117
 	}
1062 1118
 }
1063 1119
 
@@ -1076,8 +1132,9 @@  discard block
 block discarded – undo
1076 1132
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1077 1133
 	{
1078 1134
 		// Make sure only integers are deleted.
1079
-		foreach ($_POST['notify_boards'] as $index => $id)
1080
-			$_POST['notify_boards'][$index] = (int) $id;
1135
+		foreach ($_POST['notify_boards'] as $index => $id) {
1136
+					$_POST['notify_boards'][$index] = (int) $id;
1137
+		}
1081 1138
 
1082 1139
 		// id_board = 0 is reserved for topic notifications.
1083 1140
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1096,8 +1153,9 @@  discard block
 block discarded – undo
1096 1153
 	// We are editing topic notifications......
1097 1154
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1098 1155
 	{
1099
-		foreach ($_POST['notify_topics'] as $index => $id)
1100
-			$_POST['notify_topics'][$index] = (int) $id;
1156
+		foreach ($_POST['notify_topics'] as $index => $id) {
1157
+					$_POST['notify_topics'][$index] = (int) $id;
1158
+		}
1101 1159
 
1102 1160
 		// Make sure there are no zeros left.
1103 1161
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1111,16 +1169,18 @@  discard block
 block discarded – undo
1111 1169
 				'selected_member' => $memID,
1112 1170
 			)
1113 1171
 		);
1114
-		foreach ($_POST['notify_topics'] as $topic)
1115
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1172
+		foreach ($_POST['notify_topics'] as $topic) {
1173
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1174
+		}
1116 1175
 	}
1117 1176
 
1118 1177
 	// We are removing topic preferences
1119 1178
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1120 1179
 	{
1121 1180
 		$prefs = array();
1122
-		foreach ($_POST['notify_topics'] as $topic)
1123
-			$prefs[] = 'topic_notify_' . $topic;
1181
+		foreach ($_POST['notify_topics'] as $topic) {
1182
+					$prefs[] = 'topic_notify_' . $topic;
1183
+		}
1124 1184
 		deleteNotifyPrefs($memID, $prefs);
1125 1185
 	}
1126 1186
 
@@ -1128,8 +1188,9 @@  discard block
 block discarded – undo
1128 1188
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1129 1189
 	{
1130 1190
 		$prefs = array();
1131
-		foreach ($_POST['notify_boards'] as $board)
1132
-			$prefs[] = 'board_notify_' . $board;
1191
+		foreach ($_POST['notify_boards'] as $board) {
1192
+					$prefs[] = 'board_notify_' . $board;
1193
+		}
1133 1194
 		deleteNotifyPrefs($memID, $prefs);
1134 1195
 	}
1135 1196
 }
@@ -1150,8 +1211,9 @@  discard block
 block discarded – undo
1150 1211
 
1151 1212
 	$errors = array();
1152 1213
 
1153
-	if ($sanitize && isset($_POST['customfield']))
1154
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1214
+	if ($sanitize && isset($_POST['customfield'])) {
1215
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1216
+	}
1155 1217
 
1156 1218
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1157 1219
 
@@ -1176,26 +1238,29 @@  discard block
 block discarded – undo
1176 1238
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1177 1239
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1178 1240
 		*/
1179
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1180
-			continue;
1241
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1242
+					continue;
1243
+		}
1181 1244
 
1182 1245
 		// Validate the user data.
1183
-		if ($row['field_type'] == 'check')
1184
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1185
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1246
+		if ($row['field_type'] == 'check') {
1247
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1248
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1186 1249
 		{
1187 1250
 			$value = $row['default_value'];
1188
-			foreach (explode(',', $row['field_options']) as $k => $v)
1189
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1251
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1252
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1190 1253
 					$value = $v;
1254
+			}
1191 1255
 		}
1192 1256
 		// Otherwise some form of text!
1193 1257
 		else
1194 1258
 		{
1195 1259
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1196 1260
 
1197
-			if ($row['field_length'])
1198
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1261
+			if ($row['field_length']) {
1262
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1263
+			}
1199 1264
 
1200 1265
 			// Any masks?
1201 1266
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
@@ -1204,36 +1269,34 @@  discard block
 block discarded – undo
1204 1269
 				$valueReference = un_htmlspecialchars($value);
1205 1270
 
1206 1271
 				// Try and avoid some checks. '0' could be a valid non-empty value.
1207
-				if (empty($value) && !is_numeric($value))
1208
-					$value = '';
1272
+				if (empty($value) && !is_numeric($value)) {
1273
+									$value = '';
1274
+				}
1209 1275
 
1210 1276
 				if ($row['mask'] == 'nohtml' && ($valueReference != strip_tags($valueReference) || $value != filter_var($value, FILTER_SANITIZE_STRING) || preg_match('/<(.+?)[\s]*\/?[\s]*>/si', $valueReference)))
1211 1277
 				{
1212
-					if ($returnErrors)
1213
-						$errors[] = 'custom_field_nohtml_fail';
1214
-
1215
-					else
1216
-						$value = '';
1217
-				}
1218
-				elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1278
+					if ($returnErrors) {
1279
+											$errors[] = 'custom_field_nohtml_fail';
1280
+					} else {
1281
+											$value = '';
1282
+					}
1283
+				} elseif ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1219 1284
 				{
1220
-					if ($returnErrors)
1221
-						$errors[] = 'custom_field_mail_fail';
1222
-
1223
-					else
1224
-						$value = '';
1225
-				}
1226
-				elseif ($row['mask'] == 'number')
1285
+					if ($returnErrors) {
1286
+											$errors[] = 'custom_field_mail_fail';
1287
+					} else {
1288
+											$value = '';
1289
+					}
1290
+				} elseif ($row['mask'] == 'number')
1227 1291
 				{
1228 1292
 					$value = (int) $value;
1229
-				}
1230
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1293
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1231 1294
 				{
1232
-					if ($returnErrors)
1233
-						$errors[] = 'custom_field_regex_fail';
1234
-
1235
-					else
1236
-						$value = '';
1295
+					if ($returnErrors) {
1296
+											$errors[] = 'custom_field_regex_fail';
1297
+					} else {
1298
+											$value = '';
1299
+					}
1237 1300
 				}
1238 1301
 
1239 1302
 				unset($valueReference);
@@ -1261,8 +1324,9 @@  discard block
 block discarded – undo
1261 1324
 
1262 1325
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1263 1326
 
1264
-	if (!empty($hook_errors) && is_array($hook_errors))
1265
-		$errors = array_merge($errors, $hook_errors);
1327
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1328
+			$errors = array_merge($errors, $hook_errors);
1329
+	}
1266 1330
 
1267 1331
 	// Make those changes!
1268 1332
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1280,9 +1344,10 @@  discard block
 block discarded – undo
1280 1344
 		}
1281 1345
 	}
1282 1346
 
1283
-	if ($returnErrors)
1284
-		return $errors;
1285
-}
1347
+	if ($returnErrors) {
1348
+			return $errors;
1349
+	}
1350
+	}
1286 1351
 
1287 1352
 /**
1288 1353
  * Show all the users buddies, as well as a add/delete interface.
@@ -1294,8 +1359,9 @@  discard block
 block discarded – undo
1294 1359
 	global $context, $txt, $modSettings;
1295 1360
 
1296 1361
 	// Do a quick check to ensure people aren't getting here illegally!
1297
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1298
-		fatal_lang_error('no_access', false);
1362
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1363
+			fatal_lang_error('no_access', false);
1364
+	}
1299 1365
 
1300 1366
 	// Can we email the user direct?
1301 1367
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1325,9 +1391,10 @@  discard block
 block discarded – undo
1325 1391
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1326 1392
 	$call = call_helper($subActions[$context['list_area']][0], true);
1327 1393
 
1328
-	if (!empty($call))
1329
-		call_user_func($call, $memID);
1330
-}
1394
+	if (!empty($call)) {
1395
+			call_user_func($call, $memID);
1396
+	}
1397
+	}
1331 1398
 
1332 1399
 /**
1333 1400
  * Show all the users buddies, as well as a add/delete interface.
@@ -1341,9 +1408,10 @@  discard block
 block discarded – undo
1341 1408
 
1342 1409
 	// For making changes!
1343 1410
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1344
-	foreach ($buddiesArray as $k => $dummy)
1345
-		if ($dummy == '')
1411
+	foreach ($buddiesArray as $k => $dummy) {
1412
+			if ($dummy == '')
1346 1413
 			unset($buddiesArray[$k]);
1414
+	}
1347 1415
 
1348 1416
 	// Removing a buddy?
1349 1417
 	if (isset($_GET['remove']))
@@ -1355,10 +1423,11 @@  discard block
 block discarded – undo
1355 1423
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1356 1424
 
1357 1425
 		// Heh, I'm lazy, do it the easy way...
1358
-		foreach ($buddiesArray as $key => $buddy)
1359
-			if ($buddy == (int) $_GET['remove'])
1426
+		foreach ($buddiesArray as $key => $buddy) {
1427
+					if ($buddy == (int) $_GET['remove'])
1360 1428
 			{
1361 1429
 				unset($buddiesArray[$key]);
1430
+		}
1362 1431
 				$_SESSION['prf-save'] = true;
1363 1432
 			}
1364 1433
 
@@ -1368,8 +1437,7 @@  discard block
 block discarded – undo
1368 1437
 
1369 1438
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1370 1439
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1371
-	}
1372
-	elseif (isset($_POST['new_buddy']))
1440
+	} elseif (isset($_POST['new_buddy']))
1373 1441
 	{
1374 1442
 		checkSession();
1375 1443
 
@@ -1382,8 +1450,9 @@  discard block
 block discarded – undo
1382 1450
 		{
1383 1451
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1384 1452
 
1385
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1386
-				unset($new_buddies[$k]);
1453
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1454
+							unset($new_buddies[$k]);
1455
+			}
1387 1456
 		}
1388 1457
 
1389 1458
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1403,16 +1472,18 @@  discard block
 block discarded – undo
1403 1472
 				)
1404 1473
 			);
1405 1474
 
1406
-			if ($smcFunc['db_num_rows']($request) != 0)
1407
-				$_SESSION['prf-save'] = true;
1475
+			if ($smcFunc['db_num_rows']($request) != 0) {
1476
+							$_SESSION['prf-save'] = true;
1477
+			}
1408 1478
 
1409 1479
 			// Add the new member to the buddies array.
1410 1480
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1411 1481
 			{
1412
-				if (in_array($row['id_member'], $buddiesArray))
1413
-					continue;
1414
-				else
1415
-					$buddiesArray[] = (int) $row['id_member'];
1482
+				if (in_array($row['id_member'], $buddiesArray)) {
1483
+									continue;
1484
+				} else {
1485
+									$buddiesArray[] = (int) $row['id_member'];
1486
+				}
1416 1487
 			}
1417 1488
 			$smcFunc['db_free_result']($request);
1418 1489
 
@@ -1442,18 +1513,20 @@  discard block
 block discarded – undo
1442 1513
 
1443 1514
 	$context['custom_pf'] = array();
1444 1515
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1445
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1446
-		if (!isset($disabled_fields[$row['col_name']]))
1516
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1517
+			if (!isset($disabled_fields[$row['col_name']]))
1447 1518
 			$context['custom_pf'][$row['col_name']] = array(
1448 1519
 				'label' => $row['field_name'],
1449 1520
 				'type' => $row['field_type'],
1450 1521
 				'bbc' => !empty($row['bbc']),
1451 1522
 				'enclose' => $row['enclose'],
1452 1523
 			);
1524
+	}
1453 1525
 
1454 1526
 	// Gotta disable the gender option.
1455
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled')
1456
-		unset($context['custom_pf']['cust_gender']);
1527
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') {
1528
+			unset($context['custom_pf']['cust_gender']);
1529
+	}
1457 1530
 
1458 1531
 	$smcFunc['db_free_result']($request);
1459 1532
 
@@ -1470,8 +1543,9 @@  discard block
 block discarded – undo
1470 1543
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1471 1544
 			)
1472 1545
 		);
1473
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1474
-			$buddies[] = $row['id_member'];
1546
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1547
+					$buddies[] = $row['id_member'];
1548
+		}
1475 1549
 		$smcFunc['db_free_result']($result);
1476 1550
 	}
1477 1551
 
@@ -1499,30 +1573,32 @@  discard block
 block discarded – undo
1499 1573
 					continue;
1500 1574
 				}
1501 1575
 
1502
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1503
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1504
-
1505
-				elseif ($column['type'] == 'check')
1506
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1576
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1577
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1578
+				} elseif ($column['type'] == 'check') {
1579
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1580
+				}
1507 1581
 
1508 1582
 				// Enclosing the user input within some other text?
1509
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1510
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1583
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1584
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1511 1585
 						'{SCRIPTURL}' => $scripturl,
1512 1586
 						'{IMAGES_URL}' => $settings['images_url'],
1513 1587
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1514 1588
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1515 1589
 					));
1590
+				}
1516 1591
 			}
1517 1592
 		}
1518 1593
 	}
1519 1594
 
1520 1595
 	if (isset($_SESSION['prf-save']))
1521 1596
 	{
1522
-		if ($_SESSION['prf-save'] === true)
1523
-			$context['saved_successful'] = true;
1524
-		else
1525
-			$context['saved_failed'] = $_SESSION['prf-save'];
1597
+		if ($_SESSION['prf-save'] === true) {
1598
+					$context['saved_successful'] = true;
1599
+		} else {
1600
+					$context['saved_failed'] = $_SESSION['prf-save'];
1601
+		}
1526 1602
 
1527 1603
 		unset($_SESSION['prf-save']);
1528 1604
 	}
@@ -1542,9 +1618,10 @@  discard block
 block discarded – undo
1542 1618
 
1543 1619
 	// For making changes!
1544 1620
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1545
-	foreach ($ignoreArray as $k => $dummy)
1546
-		if ($dummy == '')
1621
+	foreach ($ignoreArray as $k => $dummy) {
1622
+			if ($dummy == '')
1547 1623
 			unset($ignoreArray[$k]);
1624
+	}
1548 1625
 
1549 1626
 	// Removing a member from the ignore list?
1550 1627
 	if (isset($_GET['remove']))
@@ -1554,10 +1631,11 @@  discard block
 block discarded – undo
1554 1631
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1555 1632
 
1556 1633
 		// Heh, I'm lazy, do it the easy way...
1557
-		foreach ($ignoreArray as $key => $id_remove)
1558
-			if ($id_remove == (int) $_GET['remove'])
1634
+		foreach ($ignoreArray as $key => $id_remove) {
1635
+					if ($id_remove == (int) $_GET['remove'])
1559 1636
 			{
1560 1637
 				unset($ignoreArray[$key]);
1638
+		}
1561 1639
 				$_SESSION['prf-save'] = true;
1562 1640
 			}
1563 1641
 
@@ -1567,8 +1645,7 @@  discard block
 block discarded – undo
1567 1645
 
1568 1646
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1569 1647
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1570
-	}
1571
-	elseif (isset($_POST['new_ignore']))
1648
+	} elseif (isset($_POST['new_ignore']))
1572 1649
 	{
1573 1650
 		checkSession();
1574 1651
 		// Prepare the string for extraction...
@@ -1580,8 +1657,9 @@  discard block
 block discarded – undo
1580 1657
 		{
1581 1658
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1582 1659
 
1583
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1584
-				unset($new_entries[$k]);
1660
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1661
+							unset($new_entries[$k]);
1662
+			}
1585 1663
 		}
1586 1664
 
1587 1665
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1599,16 +1677,18 @@  discard block
 block discarded – undo
1599 1677
 				)
1600 1678
 			);
1601 1679
 
1602
-			if ($smcFunc['db_num_rows']($request) != 0)
1603
-				$_SESSION['prf-save'] = true;
1680
+			if ($smcFunc['db_num_rows']($request) != 0) {
1681
+							$_SESSION['prf-save'] = true;
1682
+			}
1604 1683
 
1605 1684
 			// Add the new member to the buddies array.
1606 1685
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1607 1686
 			{
1608
-				if (in_array($row['id_member'], $ignoreArray))
1609
-					continue;
1610
-				else
1611
-					$ignoreArray[] = (int) $row['id_member'];
1687
+				if (in_array($row['id_member'], $ignoreArray)) {
1688
+									continue;
1689
+				} else {
1690
+									$ignoreArray[] = (int) $row['id_member'];
1691
+				}
1612 1692
 			}
1613 1693
 			$smcFunc['db_free_result']($request);
1614 1694
 
@@ -1637,8 +1717,9 @@  discard block
 block discarded – undo
1637 1717
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1638 1718
 			)
1639 1719
 		);
1640
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1641
-			$ignored[] = $row['id_member'];
1720
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1721
+					$ignored[] = $row['id_member'];
1722
+		}
1642 1723
 		$smcFunc['db_free_result']($result);
1643 1724
 	}
1644 1725
 
@@ -1657,10 +1738,11 @@  discard block
 block discarded – undo
1657 1738
 
1658 1739
 	if (isset($_SESSION['prf-save']))
1659 1740
 	{
1660
-		if ($_SESSION['prf-save'] === true)
1661
-			$context['saved_successful'] = true;
1662
-		else
1663
-			$context['saved_failed'] = $_SESSION['prf-save'];
1741
+		if ($_SESSION['prf-save'] === true) {
1742
+					$context['saved_successful'] = true;
1743
+		} else {
1744
+					$context['saved_failed'] = $_SESSION['prf-save'];
1745
+		}
1664 1746
 
1665 1747
 		unset($_SESSION['prf-save']);
1666 1748
 	}
@@ -1676,8 +1758,9 @@  discard block
 block discarded – undo
1676 1758
 	global $context, $txt;
1677 1759
 
1678 1760
 	loadThemeOptions($memID);
1679
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1680
-		loadCustomFields($memID, 'account');
1761
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1762
+			loadCustomFields($memID, 'account');
1763
+	}
1681 1764
 
1682 1765
 	$context['sub_template'] = 'edit_options';
1683 1766
 	$context['page_desc'] = $txt['account_info'];
@@ -1704,8 +1787,9 @@  discard block
 block discarded – undo
1704 1787
 	global $context, $txt;
1705 1788
 
1706 1789
 	loadThemeOptions($memID);
1707
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1708
-		loadCustomFields($memID, 'forumprofile');
1790
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1791
+			loadCustomFields($memID, 'forumprofile');
1792
+	}
1709 1793
 
1710 1794
 	$context['sub_template'] = 'edit_options';
1711 1795
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1738,18 +1822,21 @@  discard block
 block discarded – undo
1738 1822
 	$dirs = array();
1739 1823
 	$files = array();
1740 1824
 
1741
-	if (!$dir)
1742
-		return array();
1825
+	if (!$dir) {
1826
+			return array();
1827
+	}
1743 1828
 
1744 1829
 	while ($line = $dir->read())
1745 1830
 	{
1746
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1747
-			continue;
1831
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1832
+					continue;
1833
+		}
1748 1834
 
1749
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1750
-			$dirs[] = $line;
1751
-		else
1752
-			$files[] = $line;
1835
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1836
+					$dirs[] = $line;
1837
+		} else {
1838
+					$files[] = $line;
1839
+		}
1753 1840
 	}
1754 1841
 	$dir->close();
1755 1842
 
@@ -1770,14 +1857,15 @@  discard block
 block discarded – undo
1770 1857
 	foreach ($dirs as $line)
1771 1858
 	{
1772 1859
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1773
-		if (!empty($tmp))
1774
-			$result[] = array(
1860
+		if (!empty($tmp)) {
1861
+					$result[] = array(
1775 1862
 				'filename' => $smcFunc['htmlspecialchars']($line),
1776 1863
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1777 1864
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1778 1865
 				'is_dir' => true,
1779 1866
 				'files' => $tmp
1780 1867
 		);
1868
+		}
1781 1869
 		unset($tmp);
1782 1870
 	}
1783 1871
 
@@ -1787,8 +1875,9 @@  discard block
 block discarded – undo
1787 1875
 		$extension = substr(strrchr($line, '.'), 1);
1788 1876
 
1789 1877
 		// Make sure it is an image.
1790
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1791
-			continue;
1878
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1879
+					continue;
1880
+		}
1792 1881
 
1793 1882
 		$result[] = array(
1794 1883
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1796,8 +1885,9 @@  discard block
 block discarded – undo
1796 1885
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1797 1886
 			'is_dir' => false
1798 1887
 		);
1799
-		if ($level == 1)
1800
-			$context['avatar_list'][] = $directory . '/' . $line;
1888
+		if ($level == 1) {
1889
+					$context['avatar_list'][] = $directory . '/' . $line;
1890
+		}
1801 1891
 	}
1802 1892
 
1803 1893
 	return $result;
@@ -1816,8 +1906,9 @@  discard block
 block discarded – undo
1816 1906
 	loadSubTemplate('options');
1817 1907
 
1818 1908
 	loadThemeOptions($memID);
1819
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1820
-		loadCustomFields($memID, 'theme');
1909
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1910
+			loadCustomFields($memID, 'theme');
1911
+	}
1821 1912
 
1822 1913
 	$context['sub_template'] = 'edit_options';
1823 1914
 	$context['page_desc'] = $txt['theme_info'];
@@ -1871,16 +1962,19 @@  discard block
 block discarded – undo
1871 1962
 {
1872 1963
 	global $txt, $context, $modSettings, $smcFunc, $sourcedir;
1873 1964
 
1874
-	if (!isset($context['token_check']))
1875
-		$context['token_check'] = 'profile-nt' . $memID;
1965
+	if (!isset($context['token_check'])) {
1966
+			$context['token_check'] = 'profile-nt' . $memID;
1967
+	}
1876 1968
 
1877 1969
 	is_not_guest();
1878
-	if (!$context['user']['is_owner'])
1879
-		isAllowedTo('profile_extra_any');
1970
+	if (!$context['user']['is_owner']) {
1971
+			isAllowedTo('profile_extra_any');
1972
+	}
1880 1973
 
1881 1974
 	// Set the post action if we're coming from the profile...
1882
-	if (!isset($context['action']))
1883
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1975
+	if (!isset($context['action'])) {
1976
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1977
+	}
1884 1978
 
1885 1979
 	// What options are set
1886 1980
 	loadThemeOptions($memID);
@@ -1967,28 +2061,34 @@  discard block
 block discarded – undo
1967 2061
 	);
1968 2062
 
1969 2063
 	// There are certain things that are disabled at the group level.
1970
-	if (empty($modSettings['cal_enabled']))
1971
-		unset($alert_types['calendar']);
2064
+	if (empty($modSettings['cal_enabled'])) {
2065
+			unset($alert_types['calendar']);
2066
+	}
1972 2067
 
1973 2068
 	// Disable paid subscriptions at group level if they're disabled
1974
-	if (empty($modSettings['paid_enabled']))
1975
-		unset($alert_types['paidsubs']);
2069
+	if (empty($modSettings['paid_enabled'])) {
2070
+			unset($alert_types['paidsubs']);
2071
+	}
1976 2072
 
1977 2073
 	// Disable membergroup requests at group level if they're disabled
1978
-	if (empty($modSettings['show_group_membership']))
1979
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2074
+	if (empty($modSettings['show_group_membership'])) {
2075
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2076
+	}
1980 2077
 
1981 2078
 	// Disable mentions if they're disabled
1982
-	if (empty($modSettings['enable_mentions']))
1983
-		unset($alert_types['msg']['msg_mention']);
2079
+	if (empty($modSettings['enable_mentions'])) {
2080
+			unset($alert_types['msg']['msg_mention']);
2081
+	}
1984 2082
 
1985 2083
 	// Disable likes if they're disabled
1986
-	if (empty($modSettings['enable_likes']))
1987
-		unset($alert_types['msg']['msg_like']);
2084
+	if (empty($modSettings['enable_likes'])) {
2085
+			unset($alert_types['msg']['msg_like']);
2086
+	}
1988 2087
 
1989 2088
 	// Disable buddy requests if they're disabled
1990
-	if (empty($modSettings['enable_buddylist']))
1991
-		unset($alert_types['members']['buddy_request']);
2089
+	if (empty($modSettings['enable_buddylist'])) {
2090
+			unset($alert_types['members']['buddy_request']);
2091
+	}
1992 2092
 
1993 2093
 	// Now, now, we could pass this through global but we should really get into the habit of
1994 2094
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -2016,15 +2116,17 @@  discard block
 block discarded – undo
2016 2116
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
2017 2117
 		}
2018 2118
 
2019
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2020
-			unset($alert_types['members']['request_group']);
2119
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2120
+					unset($alert_types['members']['request_group']);
2121
+		}
2021 2122
 
2022 2123
 		foreach ($alert_types as $group => $items)
2023 2124
 		{
2024 2125
 			foreach ($items as $alert_key => $alert_value)
2025 2126
 			{
2026
-				if (!isset($alert_value['permission']))
2027
-					continue;
2127
+				if (!isset($alert_value['permission'])) {
2128
+									continue;
2129
+				}
2028 2130
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2029 2131
 				{
2030 2132
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2032,12 +2134,14 @@  discard block
 block discarded – undo
2032 2134
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2033 2135
 				}
2034 2136
 
2035
-				if (!$perms_cache[$alert_value['permission']['name']])
2036
-					unset ($alert_types[$group][$alert_key]);
2137
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2138
+									unset ($alert_types[$group][$alert_key]);
2139
+				}
2037 2140
 			}
2038 2141
 
2039
-			if (empty($alert_types[$group]))
2040
-				unset ($alert_types[$group]);
2142
+			if (empty($alert_types[$group])) {
2143
+							unset ($alert_types[$group]);
2144
+			}
2041 2145
 		}
2042 2146
 	}
2043 2147
 
@@ -2069,9 +2173,9 @@  discard block
 block discarded – undo
2069 2173
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2070 2174
 						break;
2071 2175
 					case 'select':
2072
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2073
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2074
-						else
2176
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2177
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2178
+						} else
2075 2179
 						{
2076 2180
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2077 2181
 							$keys = array_keys($this_option['opts']);
@@ -2091,23 +2195,28 @@  discard block
 block discarded – undo
2091 2195
 				$this_value = 0;
2092 2196
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2093 2197
 				{
2094
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2095
-						$this_value |= $bitvalue;
2198
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2199
+											$this_value |= $bitvalue;
2200
+					}
2201
+				}
2202
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2203
+									$update_prefs[$item_key] = $this_value;
2096 2204
 				}
2097
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2098
-					$update_prefs[$item_key] = $this_value;
2099 2205
 			}
2100 2206
 		}
2101 2207
 
2102
-		if (!empty($_POST['opt_alert_timeout']))
2103
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2208
+		if (!empty($_POST['opt_alert_timeout'])) {
2209
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2210
+		}
2104 2211
 
2105
-		if (!empty($_POST['notify_announcements']))
2106
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2212
+		if (!empty($_POST['notify_announcements'])) {
2213
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2214
+		}
2107 2215
 
2108 2216
 		setNotifyPrefs((int) $memID, $update_prefs);
2109
-		foreach ($update_prefs as $pref => $value)
2110
-			$context['alert_prefs'][$pref] = $value;
2217
+		foreach ($update_prefs as $pref => $value) {
2218
+					$context['alert_prefs'][$pref] = $value;
2219
+		}
2111 2220
 
2112 2221
 		makeNotificationChanges($memID);
2113 2222
 
@@ -2137,8 +2246,9 @@  discard block
 block discarded – undo
2137 2246
 
2138 2247
 	// Now we're all set up.
2139 2248
 	is_not_guest();
2140
-	if (!$context['user']['is_owner'])
2141
-		fatal_error('no_access');
2249
+	if (!$context['user']['is_owner']) {
2250
+			fatal_error('no_access');
2251
+	}
2142 2252
 
2143 2253
 	checkSession('get');
2144 2254
 
@@ -2170,8 +2280,9 @@  discard block
 block discarded – undo
2170 2280
 {
2171 2281
 	global $smcFunc;
2172 2282
 
2173
-	if (empty($toMark) || empty($memID))
2174
-		return false;
2283
+	if (empty($toMark) || empty($memID)) {
2284
+			return false;
2285
+	}
2175 2286
 
2176 2287
 	$toMark = (array) $toMark;
2177 2288
 
@@ -2205,8 +2316,9 @@  discard block
 block discarded – undo
2205 2316
 {
2206 2317
 	global $smcFunc;
2207 2318
 
2208
-	if (empty($toDelete))
2209
-		return false;
2319
+	if (empty($toDelete)) {
2320
+			return false;
2321
+	}
2210 2322
 
2211 2323
 	$toDelete = (array) $toDelete;
2212 2324
 
@@ -2241,8 +2353,9 @@  discard block
 block discarded – undo
2241 2353
 {
2242 2354
 	global $smcFunc;
2243 2355
 
2244
-	if (empty($memID))
2245
-		return false;
2356
+	if (empty($memID)) {
2357
+			return false;
2358
+	}
2246 2359
 
2247 2360
 	$request = $smcFunc['db_query']('', '
2248 2361
 		SELECT id_alert
@@ -2319,8 +2432,9 @@  discard block
 block discarded – undo
2319 2432
 					{
2320 2433
 						$link = $topic['link'];
2321 2434
 
2322
-						if ($topic['new'])
2323
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2435
+						if ($topic['new']) {
2436
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2437
+						}
2324 2438
 
2325 2439
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2326 2440
 
@@ -2471,8 +2585,9 @@  discard block
 block discarded – undo
2471 2585
 					{
2472 2586
 						$link = $board['link'];
2473 2587
 
2474
-						if ($board['new'])
2475
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2588
+						if ($board['new']) {
2589
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2590
+						}
2476 2591
 
2477 2592
 						return $link;
2478 2593
 					},
@@ -2672,8 +2787,8 @@  discard block
 block discarded – undo
2672 2787
 		)
2673 2788
 	);
2674 2789
 	$notification_boards = array();
2675
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2676
-		$notification_boards[] = array(
2790
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2791
+			$notification_boards[] = array(
2677 2792
 			'id' => $row['id_board'],
2678 2793
 			'name' => $row['name'],
2679 2794
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2681,6 +2796,7 @@  discard block
 block discarded – undo
2681 2796
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2682 2797
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2683 2798
 		);
2799
+	}
2684 2800
 	$smcFunc['db_free_result']($request);
2685 2801
 
2686 2802
 	return $notification_boards;
@@ -2695,17 +2811,18 @@  discard block
 block discarded – undo
2695 2811
 {
2696 2812
 	global $context, $options, $cur_profile, $smcFunc;
2697 2813
 
2698
-	if (isset($_POST['default_options']))
2699
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2814
+	if (isset($_POST['default_options'])) {
2815
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2816
+	}
2700 2817
 
2701 2818
 	if ($context['user']['is_owner'])
2702 2819
 	{
2703 2820
 		$context['member']['options'] = $options;
2704
-		if (isset($_POST['options']) && is_array($_POST['options']))
2705
-			foreach ($_POST['options'] as $k => $v)
2821
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2822
+					foreach ($_POST['options'] as $k => $v)
2706 2823
 				$context['member']['options'][$k] = $v;
2707
-	}
2708
-	else
2824
+		}
2825
+	} else
2709 2826
 	{
2710 2827
 		$request = $smcFunc['db_query']('', '
2711 2828
 			SELECT id_member, variable, value
@@ -2726,8 +2843,9 @@  discard block
 block discarded – undo
2726 2843
 				continue;
2727 2844
 			}
2728 2845
 
2729
-			if (isset($_POST['options'][$row['variable']]))
2730
-				$row['value'] = $_POST['options'][$row['variable']];
2846
+			if (isset($_POST['options'][$row['variable']])) {
2847
+							$row['value'] = $_POST['options'][$row['variable']];
2848
+			}
2731 2849
 			$context['member']['options'][$row['variable']] = $row['value'];
2732 2850
 		}
2733 2851
 		$smcFunc['db_free_result']($request);
@@ -2735,8 +2853,9 @@  discard block
 block discarded – undo
2735 2853
 		// Load up the default theme options for any missing.
2736 2854
 		foreach ($temp as $k => $v)
2737 2855
 		{
2738
-			if (!isset($context['member']['options'][$k]))
2739
-				$context['member']['options'][$k] = $v;
2856
+			if (!isset($context['member']['options'][$k])) {
2857
+							$context['member']['options'][$k] = $v;
2858
+			}
2740 2859
 		}
2741 2860
 	}
2742 2861
 }
@@ -2751,8 +2870,9 @@  discard block
 block discarded – undo
2751 2870
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2752 2871
 
2753 2872
 	// Have the admins enabled this option?
2754
-	if (empty($modSettings['allow_ignore_boards']))
2755
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2873
+	if (empty($modSettings['allow_ignore_boards'])) {
2874
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2875
+	}
2756 2876
 
2757 2877
 	// Find all the boards this user is allowed to see.
2758 2878
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2772,12 +2892,13 @@  discard block
 block discarded – undo
2772 2892
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2773 2893
 	{
2774 2894
 		// This category hasn't been set up yet..
2775
-		if (!isset($context['categories'][$row['id_cat']]))
2776
-			$context['categories'][$row['id_cat']] = array(
2895
+		if (!isset($context['categories'][$row['id_cat']])) {
2896
+					$context['categories'][$row['id_cat']] = array(
2777 2897
 				'id' => $row['id_cat'],
2778 2898
 				'name' => $row['cat_name'],
2779 2899
 				'boards' => array()
2780 2900
 			);
2901
+		}
2781 2902
 
2782 2903
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2783 2904
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2807,18 +2928,20 @@  discard block
 block discarded – undo
2807 2928
 	}
2808 2929
 
2809 2930
 	$max_boards = ceil(count($temp_boards) / 2);
2810
-	if ($max_boards == 1)
2811
-		$max_boards = 2;
2931
+	if ($max_boards == 1) {
2932
+			$max_boards = 2;
2933
+	}
2812 2934
 
2813 2935
 	// Now, alternate them so they can be shown left and right ;).
2814 2936
 	$context['board_columns'] = array();
2815 2937
 	for ($i = 0; $i < $max_boards; $i++)
2816 2938
 	{
2817 2939
 		$context['board_columns'][] = $temp_boards[$i];
2818
-		if (isset($temp_boards[$i + $max_boards]))
2819
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2820
-		else
2821
-			$context['board_columns'][] = array();
2940
+		if (isset($temp_boards[$i + $max_boards])) {
2941
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2942
+		} else {
2943
+					$context['board_columns'][] = array();
2944
+		}
2822 2945
 	}
2823 2946
 
2824 2947
 	loadThemeOptions($memID);
@@ -2887,8 +3010,9 @@  discard block
 block discarded – undo
2887 3010
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2888 3011
 	{
2889 3012
 		// We should skip the administrator group if they don't have the admin_forum permission!
2890
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2891
-			continue;
3013
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
3014
+					continue;
3015
+		}
2892 3016
 
2893 3017
 		$context['member_groups'][$row['id_group']] = array(
2894 3018
 			'id' => $row['id_group'],
@@ -2934,16 +3058,17 @@  discard block
 block discarded – undo
2934 3058
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2935 3059
 	// Warning message for signature image limits?
2936 3060
 	$context['signature_warning'] = '';
2937
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2938
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2939
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2940
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3061
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3062
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3063
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3064
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3065
+	}
2941 3066
 
2942 3067
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2943 3068
 
2944
-	if (empty($context['do_preview']))
2945
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2946
-	else
3069
+	if (empty($context['do_preview'])) {
3070
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3071
+	} else
2947 3072
 	{
2948 3073
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2949 3074
 		$validation = profileValidateSignature($signature);
@@ -2953,8 +3078,9 @@  discard block
 block discarded – undo
2953 3078
 			$context['post_errors'] = array();
2954 3079
 		}
2955 3080
 		$context['post_errors'][] = 'signature_not_yet_saved';
2956
-		if ($validation !== true && $validation !== false)
2957
-			$context['post_errors'][] = $validation;
3081
+		if ($validation !== true && $validation !== false) {
3082
+					$context['post_errors'][] = $validation;
3083
+		}
2958 3084
 
2959 3085
 		censorText($context['member']['signature']);
2960 3086
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2964,8 +3090,9 @@  discard block
 block discarded – undo
2964 3090
 	}
2965 3091
 
2966 3092
 	// Load the spell checker?
2967
-	if ($context['show_spellchecking'])
2968
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3093
+	if ($context['show_spellchecking']) {
3094
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3095
+	}
2969 3096
 
2970 3097
 	return true;
2971 3098
 }
@@ -2999,8 +3126,7 @@  discard block
 block discarded – undo
2999 3126
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
3000 3127
 		);
3001 3128
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
3002
-	}
3003
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3129
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3004 3130
 	{
3005 3131
 		$context['member']['avatar'] += array(
3006 3132
 			'choice' => 'upload',
@@ -3010,33 +3136,34 @@  discard block
 block discarded – undo
3010 3136
 		$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
3011 3137
 	}
3012 3138
 	// Use "avatar_original" here so we show what the user entered even if the image proxy is enabled
3013
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
3014
-		$context['member']['avatar'] += array(
3139
+	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3140
+			$context['member']['avatar'] += array(
3015 3141
 			'choice' => 'external',
3016 3142
 			'server_pic' => 'blank.png',
3017 3143
 			'external' => $cur_profile['avatar_original']
3018 3144
 		);
3019
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3020
-		$context['member']['avatar'] += array(
3145
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3146
+			$context['member']['avatar'] += array(
3021 3147
 			'choice' => 'server_stored',
3022 3148
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3023 3149
 			'external' => 'http://'
3024 3150
 		);
3025
-	else
3026
-		$context['member']['avatar'] += array(
3151
+	} else {
3152
+			$context['member']['avatar'] += array(
3027 3153
 			'choice' => 'none',
3028 3154
 			'server_pic' => 'blank.png',
3029 3155
 			'external' => 'http://'
3030 3156
 		);
3157
+	}
3031 3158
 
3032 3159
 	// Get a list of all the avatars.
3033 3160
 	if ($context['member']['avatar']['allow_server_stored'])
3034 3161
 	{
3035 3162
 		$context['avatar_list'] = array();
3036 3163
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3164
+	} else {
3165
+			$context['avatars'] = array();
3037 3166
 	}
3038
-	else
3039
-		$context['avatars'] = array();
3040 3167
 
3041 3168
 	// Second level selected avatar...
3042 3169
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3065,19 +3192,22 @@  discard block
 block discarded – undo
3065 3192
 			)
3066 3193
 		);
3067 3194
 		$protected_groups = array(1);
3068
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3069
-			$protected_groups[] = $row['id_group'];
3195
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3196
+					$protected_groups[] = $row['id_group'];
3197
+		}
3070 3198
 		$smcFunc['db_free_result']($request);
3071 3199
 
3072 3200
 		$protected_groups = array_unique($protected_groups);
3073 3201
 	}
3074 3202
 
3075 3203
 	// The account page allows the change of your id_group - but not to a protected group!
3076
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3077
-		$value = (int) $value;
3204
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3205
+			$value = (int) $value;
3206
+	}
3078 3207
 	// ... otherwise it's the old group sir.
3079
-	else
3080
-		$value = $old_profile['id_group'];
3208
+	else {
3209
+			$value = $old_profile['id_group'];
3210
+	}
3081 3211
 
3082 3212
 	// Find the additional membergroups (if any)
3083 3213
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3086,16 +3216,18 @@  discard block
 block discarded – undo
3086 3216
 		foreach ($_POST['additional_groups'] as $group_id)
3087 3217
 		{
3088 3218
 			$group_id = (int) $group_id;
3089
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3090
-				$additional_groups[] = $group_id;
3219
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3220
+							$additional_groups[] = $group_id;
3221
+			}
3091 3222
 		}
3092 3223
 
3093 3224
 		// Put the protected groups back in there if you don't have permission to take them away.
3094 3225
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3095 3226
 		foreach ($old_additional_groups as $group_id)
3096 3227
 		{
3097
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3098
-				$additional_groups[] = $group_id;
3228
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3229
+							$additional_groups[] = $group_id;
3230
+			}
3099 3231
 		}
3100 3232
 
3101 3233
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3127,18 +3259,20 @@  discard block
 block discarded – undo
3127 3259
 			list ($another) = $smcFunc['db_fetch_row']($request);
3128 3260
 			$smcFunc['db_free_result']($request);
3129 3261
 
3130
-			if (empty($another))
3131
-				fatal_lang_error('at_least_one_admin', 'critical');
3262
+			if (empty($another)) {
3263
+							fatal_lang_error('at_least_one_admin', 'critical');
3264
+			}
3132 3265
 		}
3133 3266
 	}
3134 3267
 
3135 3268
 	// If we are changing group status, update permission cache as necessary.
3136 3269
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3137 3270
 	{
3138
-		if ($context['user']['is_owner'])
3139
-			$_SESSION['mc']['time'] = 0;
3140
-		else
3141
-			updateSettings(array('settings_updated' => time()));
3271
+		if ($context['user']['is_owner']) {
3272
+					$_SESSION['mc']['time'] = 0;
3273
+		} else {
3274
+					updateSettings(array('settings_updated' => time()));
3275
+		}
3142 3276
 	}
3143 3277
 
3144 3278
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3159,8 +3293,9 @@  discard block
 block discarded – undo
3159 3293
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3160 3294
 
3161 3295
 	$memID = $context['id_member'];
3162
-	if (empty($memID) && !empty($context['password_auth_failed']))
3163
-		return false;
3296
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3297
+			return false;
3298
+	}
3164 3299
 
3165 3300
 	require_once($sourcedir . '/ManageAttachments.php');
3166 3301
 
@@ -3171,8 +3306,9 @@  discard block
 block discarded – undo
3171 3306
 	$downloadedExternalAvatar = false;
3172 3307
 	if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
3173 3308
 	{
3174
-		if (!is_writable($uploadDir))
3175
-			fatal_lang_error('attachments_no_write', 'critical');
3309
+		if (!is_writable($uploadDir)) {
3310
+					fatal_lang_error('attachments_no_write', 'critical');
3311
+		}
3176 3312
 
3177 3313
 		require_once($sourcedir . '/Subs-Package.php');
3178 3314
 
@@ -3216,19 +3352,18 @@  discard block
 block discarded – undo
3216 3352
 
3217 3353
 		// Get rid of their old avatar. (if uploaded.)
3218 3354
 		removeAttachments(array('id_member' => $memID));
3219
-	}
3220
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3355
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3221 3356
 	{
3222 3357
 		// One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar.
3223
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3224
-			$profile_vars['avatar'] = 'gravatar://';
3225
-		else
3226
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3358
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3359
+					$profile_vars['avatar'] = 'gravatar://';
3360
+		} else {
3361
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3362
+		}
3227 3363
 
3228 3364
 		// Get rid of their old avatar. (if uploaded.)
3229 3365
 		removeAttachments(array('id_member' => $memID));
3230
-	}
3231
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3366
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3232 3367
 	{
3233 3368
 		// We need these clean...
3234 3369
 		$cur_profile['id_attach'] = 0;
@@ -3240,11 +3375,13 @@  discard block
 block discarded – undo
3240 3375
 
3241 3376
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3242 3377
 
3243
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3244
-			$profile_vars['avatar'] = '';
3378
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3379
+					$profile_vars['avatar'] = '';
3380
+		}
3245 3381
 		// Trying to make us do something we'll regret?
3246
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3247
-			return 'bad_avatar_invalid_url';
3382
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3383
+					return 'bad_avatar_invalid_url';
3384
+		}
3248 3385
 		// Should we check dimensions?
3249 3386
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3250 3387
 		{
@@ -3254,9 +3391,9 @@  discard block
 block discarded – undo
3254 3391
 			if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
3255 3392
 			{
3256 3393
 				// Houston, we have a problem. The avatar is too large!!
3257
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3258
-					return 'bad_avatar_too_large';
3259
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3394
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3395
+									return 'bad_avatar_too_large';
3396
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3260 3397
 				{
3261 3398
 					// @todo remove this if appropriate
3262 3399
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3266,26 +3403,27 @@  discard block
 block discarded – undo
3266 3403
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3267 3404
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3268 3405
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3406
+					} else {
3407
+											return 'bad_avatar';
3269 3408
 					}
3270
-					else
3271
-						return 'bad_avatar';
3272 3409
 				}
3273 3410
 			}
3274 3411
 		}
3275
-	}
3276
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3412
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3277 3413
 	{
3278 3414
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3279 3415
 		{
3280 3416
 			// Get the dimensions of the image.
3281 3417
 			if (!$downloadedExternalAvatar)
3282 3418
 			{
3283
-				if (!is_writable($uploadDir))
3284
-					fatal_lang_error('attachments_no_write', 'critical');
3419
+				if (!is_writable($uploadDir)) {
3420
+									fatal_lang_error('attachments_no_write', 'critical');
3421
+				}
3285 3422
 
3286 3423
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3287
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3288
-					fatal_lang_error('attach_timeout', 'critical');
3424
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3425
+									fatal_lang_error('attach_timeout', 'critical');
3426
+				}
3289 3427
 
3290 3428
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3291 3429
 			}
@@ -3398,17 +3536,19 @@  discard block
 block discarded – undo
3398 3536
 			$profile_vars['avatar'] = '';
3399 3537
 
3400 3538
 			// Delete any temporary file.
3401
-			if (file_exists($_FILES['attachment']['tmp_name']))
3402
-				@unlink($_FILES['attachment']['tmp_name']);
3539
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3540
+							@unlink($_FILES['attachment']['tmp_name']);
3541
+			}
3403 3542
 		}
3404 3543
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3405
-		else
3544
+		else {
3545
+					$profile_vars['avatar'] = '';
3546
+		}
3547
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3548
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3549
+	} else {
3406 3550
 			$profile_vars['avatar'] = '';
3407 3551
 	}
3408
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3409
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3410
-	else
3411
-		$profile_vars['avatar'] = '';
3412 3552
 
3413 3553
 	// Setup the profile variables so it shows things right on display!
3414 3554
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3456,9 +3596,9 @@  discard block
 block discarded – undo
3456 3596
 		$smiley_parsed = $unparsed_signature;
3457 3597
 		parsesmileys($smiley_parsed);
3458 3598
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3459
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3460
-			return 'signature_allow_smileys';
3461
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3599
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3600
+					return 'signature_allow_smileys';
3601
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3462 3602
 		{
3463 3603
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3464 3604
 			return 'signature_max_smileys';
@@ -3471,14 +3611,15 @@  discard block
 block discarded – undo
3471 3611
 			{
3472 3612
 				$limit_broke = 0;
3473 3613
 				// Attempt to allow all sizes of abuse, so to speak.
3474
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3475
-					$limit_broke = $sig_limits[7] . 'px';
3476
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3477
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3478
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3479
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3480
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3481
-					$limit_broke = 'large';
3614
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3615
+									$limit_broke = $sig_limits[7] . 'px';
3616
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3617
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3618
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3619
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3620
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3621
+									$limit_broke = 'large';
3622
+				}
3482 3623
 
3483 3624
 				if ($limit_broke)
3484 3625
 				{
@@ -3520,24 +3661,26 @@  discard block
 block discarded – undo
3520 3661
 					$width = -1; $height = -1;
3521 3662
 
3522 3663
 					// Does it have predefined restraints? Width first.
3523
-					if ($matches[6][$key])
3524
-						$matches[2][$key] = $matches[6][$key];
3664
+					if ($matches[6][$key]) {
3665
+											$matches[2][$key] = $matches[6][$key];
3666
+					}
3525 3667
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3526 3668
 					{
3527 3669
 						$width = $sig_limits[5];
3528 3670
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3671
+					} elseif ($matches[2][$key]) {
3672
+											$width = $matches[2][$key];
3529 3673
 					}
3530
-					elseif ($matches[2][$key])
3531
-						$width = $matches[2][$key];
3532 3674
 					// ... and height.
3533 3675
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3534 3676
 					{
3535 3677
 						$height = $sig_limits[6];
3536
-						if ($width != -1)
3537
-							$width = $width * ($height / $matches[4][$key]);
3678
+						if ($width != -1) {
3679
+													$width = $width * ($height / $matches[4][$key]);
3680
+						}
3681
+					} elseif ($matches[4][$key]) {
3682
+											$height = $matches[4][$key];
3538 3683
 					}
3539
-					elseif ($matches[4][$key])
3540
-						$height = $matches[4][$key];
3541 3684
 
3542 3685
 					// If the dimensions are still not fixed - we need to check the actual image.
3543 3686
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3555,21 +3698,24 @@  discard block
 block discarded – undo
3555 3698
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3556 3699
 							{
3557 3700
 								$height = $sig_limits[6];
3558
-								if ($width == -1)
3559
-									$width = $sizes[0];
3701
+								if ($width == -1) {
3702
+																	$width = $sizes[0];
3703
+								}
3560 3704
 								$width = $width * ($height / $sizes[1]);
3705
+							} elseif ($width != -1) {
3706
+															$height = $sizes[1];
3561 3707
 							}
3562
-							elseif ($width != -1)
3563
-								$height = $sizes[1];
3564 3708
 						}
3565 3709
 					}
3566 3710
 
3567 3711
 					// Did we come up with some changes? If so remake the string.
3568
-					if ($width != -1 || $height != -1)
3569
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3712
+					if ($width != -1 || $height != -1) {
3713
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3714
+					}
3715
+				}
3716
+				if (!empty($replaces)) {
3717
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3570 3718
 				}
3571
-				if (!empty($replaces))
3572
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3573 3719
 			}
3574 3720
 		}
3575 3721
 
@@ -3613,10 +3759,12 @@  discard block
 block discarded – undo
3613 3759
 	$email = strtr($email, array('&#039;' => '\''));
3614 3760
 
3615 3761
 	// Check the name and email for validity.
3616
-	if (trim($email) == '')
3617
-		return 'no_email';
3618
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3619
-		return 'bad_email';
3762
+	if (trim($email) == '') {
3763
+			return 'no_email';
3764
+	}
3765
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3766
+			return 'bad_email';
3767
+	}
3620 3768
 
3621 3769
 	// Email addresses should be and stay unique.
3622 3770
 	$request = $smcFunc['db_query']('', '
@@ -3631,8 +3779,9 @@  discard block
 block discarded – undo
3631 3779
 		)
3632 3780
 	);
3633 3781
 
3634
-	if ($smcFunc['db_num_rows']($request) > 0)
3635
-		return 'email_taken';
3782
+	if ($smcFunc['db_num_rows']($request) > 0) {
3783
+			return 'email_taken';
3784
+	}
3636 3785
 	$smcFunc['db_free_result']($request);
3637 3786
 
3638 3787
 	return true;
@@ -3645,8 +3794,9 @@  discard block
 block discarded – undo
3645 3794
 {
3646 3795
 	global $modSettings, $context, $cur_profile;
3647 3796
 
3648
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3649
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3797
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3798
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3799
+	}
3650 3800
 
3651 3801
 	loadUserSettings();
3652 3802
 	writeLog();
@@ -3662,8 +3812,9 @@  discard block
 block discarded – undo
3662 3812
 	require_once($sourcedir . '/Subs-Post.php');
3663 3813
 
3664 3814
 	// Shouldn't happen but just in case.
3665
-	if (empty($profile_vars['email_address']))
3666
-		return;
3815
+	if (empty($profile_vars['email_address'])) {
3816
+			return;
3817
+	}
3667 3818
 
3668 3819
 	$replacements = array(
3669 3820
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3686,8 +3837,9 @@  discard block
 block discarded – undo
3686 3837
 	$_SESSION['log_time'] = 0;
3687 3838
 	$_SESSION['login_' . $cookiename] = $smcFunc['json_encode'](array(0, '', 0));
3688 3839
 
3689
-	if (isset($_COOKIE[$cookiename]))
3690
-		$_COOKIE[$cookiename] = '';
3840
+	if (isset($_COOKIE[$cookiename])) {
3841
+			$_COOKIE[$cookiename] = '';
3842
+	}
3691 3843
 
3692 3844
 	loadUserSettings();
3693 3845
 
@@ -3720,11 +3872,13 @@  discard block
 block discarded – undo
3720 3872
 	$groups[] = $curMember['id_group'];
3721 3873
 
3722 3874
 	// Ensure the query doesn't croak!
3723
-	if (empty($groups))
3724
-		$groups = array(0);
3875
+	if (empty($groups)) {
3876
+			$groups = array(0);
3877
+	}
3725 3878
 	// Just to be sure...
3726
-	foreach ($groups as $k => $v)
3727
-		$groups[$k] = (int) $v;
3879
+	foreach ($groups as $k => $v) {
3880
+			$groups[$k] = (int) $v;
3881
+	}
3728 3882
 
3729 3883
 	// Get all the membergroups they can join.
3730 3884
 	$request = $smcFunc['db_query']('', '
@@ -3754,12 +3908,14 @@  discard block
 block discarded – undo
3754 3908
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3755 3909
 	{
3756 3910
 		// Can they edit their primary group?
3757
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3758
-			$context['can_edit_primary'] = true;
3911
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3912
+					$context['can_edit_primary'] = true;
3913
+		}
3759 3914
 
3760 3915
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3761
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3762
-			continue;
3916
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3917
+					continue;
3918
+		}
3763 3919
 
3764 3920
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3765 3921
 			'id' => $row['id_group'],
@@ -3788,13 +3944,15 @@  discard block
 block discarded – undo
3788 3944
 	);
3789 3945
 
3790 3946
 	// No changing primary one unless you have enough groups!
3791
-	if (count($context['groups']['member']) < 2)
3792
-		$context['can_edit_primary'] = false;
3947
+	if (count($context['groups']['member']) < 2) {
3948
+			$context['can_edit_primary'] = false;
3949
+	}
3793 3950
 
3794 3951
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3795
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3796
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3797
-}
3952
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3953
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3954
+	}
3955
+	}
3798 3956
 
3799 3957
 /**
3800 3958
  * This function actually makes all the group changes
@@ -3809,10 +3967,12 @@  discard block
 block discarded – undo
3809 3967
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3810 3968
 
3811 3969
 	// Let's be extra cautious...
3812
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3813
-		isAllowedTo('manage_membergroups');
3814
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3815
-		fatal_lang_error('no_access', false);
3970
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3971
+			isAllowedTo('manage_membergroups');
3972
+	}
3973
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3974
+			fatal_lang_error('no_access', false);
3975
+	}
3816 3976
 
3817 3977
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3818 3978
 
@@ -3831,8 +3991,9 @@  discard block
 block discarded – undo
3831 3991
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3832 3992
 
3833 3993
 	// Sanity check!!
3834
-	if ($group_id == 1)
3835
-		isAllowedTo('admin_forum');
3994
+	if ($group_id == 1) {
3995
+			isAllowedTo('admin_forum');
3996
+	}
3836 3997
 	// Protected groups too!
3837 3998
 	else
3838 3999
 	{
@@ -3849,8 +4010,9 @@  discard block
 block discarded – undo
3849 4010
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3850 4011
 		$smcFunc['db_free_result']($request);
3851 4012
 
3852
-		if ($is_protected == 1)
3853
-			isAllowedTo('admin_forum');
4013
+		if ($is_protected == 1) {
4014
+					isAllowedTo('admin_forum');
4015
+		}
3854 4016
 	}
3855 4017
 
3856 4018
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3872,36 +4034,43 @@  discard block
 block discarded – undo
3872 4034
 			$group_name = $row['group_name'];
3873 4035
 
3874 4036
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3875
-			if ($changeType == 'request' && $row['group_type'] != 2)
3876
-				fatal_lang_error('no_access', false);
4037
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4038
+							fatal_lang_error('no_access', false);
4039
+			}
3877 4040
 			// What about leaving a requestable group we are not a member of?
3878
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3879
-				fatal_lang_error('no_access', false);
3880
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3881
-				fatal_lang_error('no_access', false);
4041
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4042
+							fatal_lang_error('no_access', false);
4043
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4044
+							fatal_lang_error('no_access', false);
4045
+			}
3882 4046
 
3883 4047
 			// We can't change the primary group if this is hidden!
3884
-			if ($row['hidden'] == 2)
3885
-				$canChangePrimary = false;
4048
+			if ($row['hidden'] == 2) {
4049
+							$canChangePrimary = false;
4050
+			}
3886 4051
 		}
3887 4052
 
3888 4053
 		// If this is their old primary, can we change it?
3889
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3890
-			$canChangePrimary = 1;
4054
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4055
+					$canChangePrimary = 1;
4056
+		}
3891 4057
 
3892 4058
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3893
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3894
-			$canChangePrimary = false;
4059
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4060
+					$canChangePrimary = false;
4061
+		}
3895 4062
 
3896 4063
 		// If this is the one we are acting on, can we even act?
3897
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3898
-			$canChangePrimary = false;
4064
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4065
+					$canChangePrimary = false;
4066
+		}
3899 4067
 	}
3900 4068
 	$smcFunc['db_free_result']($request);
3901 4069
 
3902 4070
 	// Didn't find the target?
3903
-	if (!$foundTarget)
3904
-		fatal_lang_error('no_access', false);
4071
+	if (!$foundTarget) {
4072
+			fatal_lang_error('no_access', false);
4073
+	}
3905 4074
 
3906 4075
 	// Final security check, don't allow users to promote themselves to admin.
3907 4076
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3921,8 +4090,9 @@  discard block
 block discarded – undo
3921 4090
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3922 4091
 		$smcFunc['db_free_result']($request);
3923 4092
 
3924
-		if ($disallow)
3925
-			isAllowedTo('admin_forum');
4093
+		if ($disallow) {
4094
+					isAllowedTo('admin_forum');
4095
+		}
3926 4096
 	}
3927 4097
 
3928 4098
 	// If we're requesting, add the note then return.
@@ -3940,8 +4110,9 @@  discard block
 block discarded – undo
3940 4110
 				'status_open' => 0,
3941 4111
 			)
3942 4112
 		);
3943
-		if ($smcFunc['db_num_rows']($request) != 0)
3944
-			fatal_lang_error('profile_error_already_requested_group');
4113
+		if ($smcFunc['db_num_rows']($request) != 0) {
4114
+					fatal_lang_error('profile_error_already_requested_group');
4115
+		}
3945 4116
 		$smcFunc['db_free_result']($request);
3946 4117
 
3947 4118
 		// Log the request.
@@ -3975,10 +4146,11 @@  discard block
 block discarded – undo
3975 4146
 		// Are we leaving?
3976 4147
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3977 4148
 		{
3978
-			if ($old_profile['id_group'] == $group_id)
3979
-				$newPrimary = 0;
3980
-			else
3981
-				unset($addGroups[$group_id]);
4149
+			if ($old_profile['id_group'] == $group_id) {
4150
+							$newPrimary = 0;
4151
+			} else {
4152
+							unset($addGroups[$group_id]);
4153
+			}
3982 4154
 		}
3983 4155
 		// ... if not, must be joining.
3984 4156
 		else
@@ -3986,36 +4158,42 @@  discard block
 block discarded – undo
3986 4158
 			// Can we change the primary, and do we want to?
3987 4159
 			if ($canChangePrimary)
3988 4160
 			{
3989
-				if ($old_profile['id_group'] != 0)
3990
-					$addGroups[$old_profile['id_group']] = -1;
4161
+				if ($old_profile['id_group'] != 0) {
4162
+									$addGroups[$old_profile['id_group']] = -1;
4163
+				}
3991 4164
 				$newPrimary = $group_id;
3992 4165
 			}
3993 4166
 			// Otherwise it's an additional group...
3994
-			else
3995
-				$addGroups[$group_id] = -1;
4167
+			else {
4168
+							$addGroups[$group_id] = -1;
4169
+			}
3996 4170
 		}
3997 4171
 	}
3998 4172
 	// Finally, we must be setting the primary.
3999 4173
 	elseif ($canChangePrimary)
4000 4174
 	{
4001
-		if ($old_profile['id_group'] != 0)
4002
-			$addGroups[$old_profile['id_group']] = -1;
4003
-		if (isset($addGroups[$group_id]))
4004
-			unset($addGroups[$group_id]);
4175
+		if ($old_profile['id_group'] != 0) {
4176
+					$addGroups[$old_profile['id_group']] = -1;
4177
+		}
4178
+		if (isset($addGroups[$group_id])) {
4179
+					unset($addGroups[$group_id]);
4180
+		}
4005 4181
 		$newPrimary = $group_id;
4006 4182
 	}
4007 4183
 
4008 4184
 	// Finally, we can make the changes!
4009
-	foreach ($addGroups as $id => $dummy)
4010
-		if (empty($id))
4185
+	foreach ($addGroups as $id => $dummy) {
4186
+			if (empty($id))
4011 4187
 			unset($addGroups[$id]);
4188
+	}
4012 4189
 	$addGroups = implode(',', array_flip($addGroups));
4013 4190
 
4014 4191
 	// Ensure that we don't cache permissions if the group is changing.
4015
-	if ($context['user']['is_owner'])
4016
-		$_SESSION['mc']['time'] = 0;
4017
-	else
4018
-		updateSettings(array('settings_updated' => time()));
4192
+	if ($context['user']['is_owner']) {
4193
+			$_SESSION['mc']['time'] = 0;
4194
+	} else {
4195
+			updateSettings(array('settings_updated' => time()));
4196
+	}
4019 4197
 
4020 4198
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4021 4199
 
@@ -4038,8 +4216,9 @@  discard block
 block discarded – undo
4038 4216
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4039 4217
 	{
4040 4218
 		// Check to ensure we're forcing SSL for authentication
4041
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
4042
-			fatal_lang_error('login_ssl_required');
4219
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
4220
+					fatal_lang_error('login_ssl_required');
4221
+		}
4043 4222
 
4044 4223
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4045 4224
 		// we do not want too much AJAX to confuse them.
@@ -4076,8 +4255,7 @@  discard block
 block discarded – undo
4076 4255
 				$context['sub_template'] = 'tfasetup_backup';
4077 4256
 
4078 4257
 				return;
4079
-			}
4080
-			else
4258
+			} else
4081 4259
 			{
4082 4260
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4083 4261
 				$context['tfa_error'] = !$valid_code;
@@ -4085,8 +4263,7 @@  discard block
 block discarded – undo
4085 4263
 				$context['tfa_pass_value'] = $_POST['passwd'];
4086 4264
 				$context['tfa_value'] = $_POST['tfa_code'];
4087 4265
 			}
4088
-		}
4089
-		else
4266
+		} else
4090 4267
 		{
4091 4268
 			$totp = new \TOTP\Auth();
4092 4269
 			$secret = $totp->generateCode();
@@ -4096,17 +4273,16 @@  discard block
 block discarded – undo
4096 4273
 		}
4097 4274
 
4098 4275
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4099
-	}
4100
-	elseif (isset($_REQUEST['disable']))
4276
+	} elseif (isset($_REQUEST['disable']))
4101 4277
 	{
4102 4278
 		updateMemberData($memID, array(
4103 4279
 			'tfa_secret' => '',
4104 4280
 			'tfa_backup' => '',
4105 4281
 		));
4106 4282
 		redirectexit('action=profile;area=account;u=' . $memID);
4283
+	} else {
4284
+			redirectexit('action=profile;area=account;u=' . $memID);
4285
+	}
4107 4286
 	}
4108
-	else
4109
-		redirectexit('action=profile;area=account;u=' . $memID);
4110
-}
4111 4287
 
4112 4288
 ?>
4113 4289
\ No newline at end of file
Please login to merge, or discard this patch.