| @@ -44,6 +44,10 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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; | 
| @@ -38,8 +38,8 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | |
| @@ -19,8 +19,9 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | } | 
| @@ -56,6 +56,7 @@ discard block | ||
| 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 | ||
| 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 | } | 
| @@ -279,7 +279,7 @@ discard block | ||
| 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 | ||
| 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 |  	{ | 
| @@ -382,7 +382,7 @@ | ||
| 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 |  { | 
| @@ -13,8 +13,9 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 350 | 361 | 'security_override' => true, | 
| 351 | 362 | ) | 
| 352 | 363 | ); | 
| 364 | + } | |
| 353 | 365 | |
| 354 | 366 | return true; | 
| 355 | 367 | } | 
| @@ -375,37 +387,47 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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; | 
| @@ -126,9 +126,9 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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, ',') . ' | 
| @@ -474,7 +474,7 @@ | ||
| 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 |  { | 
| @@ -39,7 +39,7 @@ | ||
| 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); | 
| @@ -15,8 +15,9 @@ discard block | ||
| 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 | ||
| 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('<' => '<', '>' => '>', '"' => '"')); | 
| @@ -59,33 +62,39 @@ discard block | ||
| 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( | 
| @@ -134,9 +143,9 @@ discard block | ||
| 134 | 143 | |
| 135 | 144 | list($context['num_errors']) = $smcFunc['db_fetch_row']($query); | 
| 136 | 145 | $smcFunc['db_free_result']($query); | 
| 146 | +		} else { | |
| 147 | + $context['num_errors']++; | |
| 137 | 148 | } | 
| 138 | - else | |
| 139 | - $context['num_errors']++; | |
| 140 | 149 | } | 
| 141 | 150 | |
| 142 | 151 | // reset error call | 
| @@ -158,12 +167,14 @@ discard block | ||
| 158 | 167 | global $txt; | 
| 159 | 168 | |
| 160 | 169 | // Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all | 
| 161 | - if (!empty($status)) | |
| 162 | - send_http_status($status); | |
| 170 | +	if (!empty($status)) { | |
| 171 | + send_http_status($status); | |
| 172 | + } | |
| 163 | 173 | |
| 164 | 174 | // We don't have $txt yet, but that's okay... | 
| 165 | - if (empty($txt)) | |
| 166 | - die($error); | |
| 175 | +	if (empty($txt)) { | |
| 176 | + die($error); | |
| 177 | + } | |
| 167 | 178 | |
| 168 | 179 | log_error_online($error, false); | 
| 169 | 180 | setup_fatal_error_context($log ? log_error($error, $log) : $error); | 
| @@ -190,8 +201,9 @@ discard block | ||
| 190 | 201 | static $fatal_error_called = false; | 
| 191 | 202 | |
| 192 | 203 | // Send the status header - set this to 0 or false if you don't want to send one at all | 
| 193 | - if (!empty($status)) | |
| 194 | - send_http_status($status); | |
| 204 | +	if (!empty($status)) { | |
| 205 | + send_http_status($status); | |
| 206 | + } | |
| 195 | 207 | |
| 196 | 208 | // Try to load a theme if we don't have one. | 
| 197 | 209 | if (empty($context['theme_loaded']) && empty($fatal_error_called)) | 
| @@ -201,8 +213,9 @@ discard block | ||
| 201 | 213 | } | 
| 202 | 214 | |
| 203 | 215 | // If we have no theme stuff we can't have the language file... | 
| 204 | - if (empty($context['theme_loaded'])) | |
| 205 | - die($error); | |
| 216 | +	if (empty($context['theme_loaded'])) { | |
| 217 | + die($error); | |
| 218 | + } | |
| 206 | 219 | |
| 207 | 220 | $reload_lang_file = true; | 
| 208 | 221 | // Log the error in the forum's language, but don't waste the time if we aren't logging | 
| @@ -238,8 +251,9 @@ discard block | ||
| 238 | 251 | global $settings, $modSettings, $db_show_debug; | 
| 239 | 252 | |
| 240 | 253 | // Ignore errors if we're ignoring them or they are strict notices from PHP 5 | 
| 241 | - if (error_reporting() == 0) | |
| 242 | - return; | |
| 254 | +	if (error_reporting() == 0) { | |
| 255 | + return; | |
| 256 | + } | |
| 243 | 257 | |
| 244 | 258 | if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename'])) | 
| 245 | 259 |  	{ | 
| @@ -247,19 +261,22 @@ discard block | ||
| 247 | 261 | $count = count($array); | 
| 248 | 262 | for ($i = 0; $i < $count; $i++) | 
| 249 | 263 |  		{ | 
| 250 | - if ($array[$i]['function'] != 'loadSubTemplate') | |
| 251 | - continue; | |
| 264 | +			if ($array[$i]['function'] != 'loadSubTemplate') { | |
| 265 | + continue; | |
| 266 | + } | |
| 252 | 267 | |
| 253 | 268 | // This is a bug in PHP, with eval, it seems! | 
| 254 | - if (empty($array[$i]['args'])) | |
| 255 | - $i++; | |
| 269 | +			if (empty($array[$i]['args'])) { | |
| 270 | + $i++; | |
| 271 | + } | |
| 256 | 272 | break; | 
| 257 | 273 | } | 
| 258 | 274 | |
| 259 | - if (isset($array[$i]) && !empty($array[$i]['args'])) | |
| 260 | -			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; | |
| 261 | - else | |
| 262 | - $file = realpath($settings['current_include_filename']) . ' (eval?)'; | |
| 275 | +		if (isset($array[$i]) && !empty($array[$i]['args'])) { | |
| 276 | +					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)'; | |
| 277 | +		} else { | |
| 278 | + $file = realpath($settings['current_include_filename']) . ' (eval?)'; | |
| 279 | + } | |
| 263 | 280 | } | 
| 264 | 281 | |
| 265 | 282 | if (isset($db_show_debug) && $db_show_debug === true) | 
| @@ -268,8 +285,9 @@ discard block | ||
| 268 | 285 | if ($error_level % 255 != E_ERROR) | 
| 269 | 286 |  		{ | 
| 270 | 287 | $temporary = ob_get_contents(); | 
| 271 | - if (substr($temporary, -2) == '="') | |
| 272 | - echo '"'; | |
| 288 | +			if (substr($temporary, -2) == '="') { | |
| 289 | + echo '"'; | |
| 290 | + } | |
| 273 | 291 | } | 
| 274 | 292 | |
| 275 | 293 | // Debugging! This should look like a PHP error message. | 
| @@ -285,23 +303,27 @@ discard block | ||
| 285 | 303 |  	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line)); | 
| 286 | 304 | |
| 287 | 305 | // Dying on these errors only causes MORE problems (blank pages!) | 
| 288 | - if ($file == 'Unknown') | |
| 289 | - return; | |
| 306 | +	if ($file == 'Unknown') { | |
| 307 | + return; | |
| 308 | + } | |
| 290 | 309 | |
| 291 | 310 | // If this is an E_ERROR or E_USER_ERROR.... die. Violently so. | 
| 292 | - if ($error_level % 255 == E_ERROR) | |
| 293 | - obExit(false); | |
| 294 | - else | |
| 295 | - return; | |
| 311 | +	if ($error_level % 255 == E_ERROR) { | |
| 312 | + obExit(false); | |
| 313 | +	} else { | |
| 314 | + return; | |
| 315 | + } | |
| 296 | 316 | |
| 297 | 317 | // If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die. Violently so. | 
| 298 | - if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) | |
| 299 | -		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); | |
| 318 | +	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) { | |
| 319 | +			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false); | |
| 320 | + } | |
| 300 | 321 | |
| 301 | 322 | // We should NEVER get to this point. Any fatal error MUST quit, or very bad things can happen. | 
| 302 | - if ($error_level % 255 == E_ERROR) | |
| 303 | -		die('No direct access...'); | |
| 304 | -} | |
| 323 | +	if ($error_level % 255 == E_ERROR) { | |
| 324 | +			die('No direct access...'); | |
| 325 | + } | |
| 326 | + } | |
| 305 | 327 | |
| 306 | 328 | /** | 
| 307 | 329 |   * It is called by {@link fatal_error()} and {@link fatal_lang_error()}. | 
| @@ -317,24 +339,28 @@ discard block | ||
| 317 | 339 | |
| 318 | 340 | // Attempt to prevent a recursive loop. | 
| 319 | 341 | ++$level; | 
| 320 | - if ($level > 1) | |
| 321 | - return false; | |
| 342 | +	if ($level > 1) { | |
| 343 | + return false; | |
| 344 | + } | |
| 322 | 345 | |
| 323 | 346 | // Maybe they came from dlattach or similar? | 
| 324 | - if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) | |
| 325 | - loadTheme(); | |
| 347 | +	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) { | |
| 348 | + loadTheme(); | |
| 349 | + } | |
| 326 | 350 | |
| 327 | 351 | // Don't bother indexing errors mate... | 
| 328 | 352 | $context['robot_no_index'] = true; | 
| 329 | 353 | |
| 330 | - if (!isset($context['error_title'])) | |
| 331 | - $context['error_title'] = $txt['error_occured']; | |
| 354 | +	if (!isset($context['error_title'])) { | |
| 355 | + $context['error_title'] = $txt['error_occured']; | |
| 356 | + } | |
| 332 | 357 | $context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message; | 
| 333 | 358 | |
| 334 | 359 | $context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : ''; | 
| 335 | 360 | |
| 336 | - if (empty($context['page_title'])) | |
| 337 | - $context['page_title'] = $context['error_title']; | |
| 361 | +	if (empty($context['page_title'])) { | |
| 362 | + $context['page_title'] = $context['error_title']; | |
| 363 | + } | |
| 338 | 364 | |
| 339 | 365 |  	loadTemplate('Errors'); | 
| 340 | 366 | $context['sub_template'] = 'fatal_error'; | 
| @@ -342,23 +368,26 @@ discard block | ||
| 342 | 368 | // If this is SSI, what do they want us to do? | 
| 343 | 369 | if (SMF == 'SSI') | 
| 344 | 370 |  	{ | 
| 345 | - if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) | |
| 346 | - $ssi_on_error_method(); | |
| 347 | - elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) | |
| 348 | -			loadSubTemplate('fatal_error'); | |
| 371 | +		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) { | |
| 372 | + $ssi_on_error_method(); | |
| 373 | +		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { | |
| 374 | +					loadSubTemplate('fatal_error'); | |
| 375 | + } | |
| 349 | 376 | |
| 350 | 377 | // No layers? | 
| 351 | - if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) | |
| 352 | - exit; | |
| 378 | +		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) { | |
| 379 | + exit; | |
| 380 | + } | |
| 353 | 381 | } | 
| 354 | 382 | // Alternatively from the cron call? | 
| 355 | 383 | elseif (SMF == 'BACKGROUND') | 
| 356 | 384 |  	{ | 
| 357 | 385 | // We can't rely on even having language files available. | 
| 358 | -		if (defined('FROM_CLI') && FROM_CLI) | |
| 359 | - echo 'cron error: ', $context['error_message']; | |
| 360 | - else | |
| 361 | - echo 'An error occurred. More information may be available in your logs.'; | |
| 386 | +		if (defined('FROM_CLI') && FROM_CLI) { | |
| 387 | + echo 'cron error: ', $context['error_message']; | |
| 388 | +		} else { | |
| 389 | + echo 'An error occurred. More information may be available in your logs.'; | |
| 390 | + } | |
| 362 | 391 | exit; | 
| 363 | 392 | } | 
| 364 | 393 | |
| @@ -386,8 +415,8 @@ discard block | ||
| 386 | 415 | |
| 387 | 416 | set_fatal_error_headers(); | 
| 388 | 417 | |
| 389 | - if (!empty($maintenance)) | |
| 390 | - echo '<!DOCTYPE html> | |
| 418 | +	if (!empty($maintenance)) { | |
| 419 | + echo '<!DOCTYPE html> | |
| 391 | 420 | <html> | 
| 392 | 421 | <head> | 
| 393 | 422 | <meta name="robots" content="noindex"> | 
| @@ -398,6 +427,7 @@ discard block | ||
| 398 | 427 | ', $mmessage, ' | 
| 399 | 428 | </body> | 
| 400 | 429 | </html>'; | 
| 430 | + } | |
| 401 | 431 | |
| 402 | 432 | die(); | 
| 403 | 433 | } | 
| @@ -419,15 +449,17 @@ discard block | ||
| 419 | 449 | // For our purposes, we're gonna want this on if at all possible. | 
| 420 | 450 | $modSettings['cache_enable'] = '1'; | 
| 421 | 451 | |
| 422 | -	if (($temp = cache_get_data('db_last_error', 600)) !== null) | |
| 423 | - $db_last_error = max($db_last_error, $temp); | |
| 452 | +	if (($temp = cache_get_data('db_last_error', 600)) !== null) { | |
| 453 | + $db_last_error = max($db_last_error, $temp); | |
| 454 | + } | |
| 424 | 455 | |
| 425 | 456 | if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send)) | 
| 426 | 457 |  	{ | 
| 427 | 458 | // Avoid writing to the Settings.php file if at all possible; use shared memory instead. | 
| 428 | 459 |  		cache_put_data('db_last_error', time(), 600); | 
| 429 | -		if (($temp = cache_get_data('db_last_error', 600)) === null) | |
| 430 | - logLastDatabaseError(); | |
| 460 | +		if (($temp = cache_get_data('db_last_error', 600)) === null) { | |
| 461 | + logLastDatabaseError(); | |
| 462 | + } | |
| 431 | 463 | |
| 432 | 464 | // Language files aren't loaded yet :(. | 
| 433 | 465 | $db_error = @$smcFunc['db_error']($db_connection); | 
| @@ -508,12 +540,14 @@ discard block | ||
| 508 | 540 | global $smcFunc, $user_info, $modSettings; | 
| 509 | 541 | |
| 510 | 542 | // Don't bother if Who's Online is disabled. | 
| 511 | - if (empty($modSettings['who_enabled'])) | |
| 512 | - return; | |
| 543 | +	if (empty($modSettings['who_enabled'])) { | |
| 544 | + return; | |
| 545 | + } | |
| 513 | 546 | |
| 514 | 547 | // Maybe they came from SSI or similar where sessions are not recorded? | 
| 515 | - if (SMF == 'SSI' || SMF == 'BACKGROUND') | |
| 516 | - return; | |
| 548 | +	if (SMF == 'SSI' || SMF == 'BACKGROUND') { | |
| 549 | + return; | |
| 550 | + } | |
| 517 | 551 | |
| 518 | 552 | $session_id = !empty($user_info['is_guest']) ? 'ip' . $user_info['ip'] : session_id(); | 
| 519 | 553 | |
| @@ -539,8 +573,9 @@ discard block | ||
| 539 | 573 | $url = $smcFunc['json_decode']($url, true); | 
| 540 | 574 | $url['error'] = $error; | 
| 541 | 575 | |
| 542 | - if (!empty($sprintf)) | |
| 543 | - $url['error_params'] = $sprintf; | |
| 576 | +		if (!empty($sprintf)) { | |
| 577 | + $url['error_params'] = $sprintf; | |
| 578 | + } | |
| 544 | 579 | |
| 545 | 580 |  		$smcFunc['db_query']('', ' | 
| 546 | 581 |  			UPDATE {db_prefix}log_online | 
| @@ -571,10 +606,11 @@ discard block | ||
| 571 | 606 | |
| 572 | 607 |  	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; | 
| 573 | 608 | |
| 574 | - if (!isset($statuses[$code])) | |
| 575 | - header($protocol . ' 500 Internal Server Error'); | |
| 576 | - else | |
| 577 | - header($protocol . ' ' . $code . ' ' . $statuses[$code]); | |
| 578 | -} | |
| 609 | +	if (!isset($statuses[$code])) { | |
| 610 | + header($protocol . ' 500 Internal Server Error'); | |
| 611 | +	} else { | |
| 612 | + header($protocol . ' ' . $code . ' ' . $statuses[$code]); | |
| 613 | + } | |
| 614 | + } | |
| 579 | 615 | |
| 580 | 616 | ?> | 
| 581 | 617 | \ No newline at end of file | 
| @@ -929,7 +929,7 @@ discard block | ||
| 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 | ||
| 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 |  { | 
| @@ -784,7 +784,7 @@ discard block | ||
| 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 | ||
| 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 | /** | 
| @@ -14,8 +14,9 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 %2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']); | |
| 216 | +						else { | |
| 217 | +													return sprintf('%1$d %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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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> ' . $ban_item[$ban_item['type']]; | |
| 408 | - elseif ($ban_item['type'] == 'user') | |
| 409 | - return '<strong>' . $txt['username'] . ':</strong> ' . $ban_item['user']['link']; | |
| 410 | - else | |
| 411 | - return '<strong>' . $txt['unknown'] . ':</strong> ' . $ban_item['no_bantype_selected']; | |
| 413 | +								if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) { | |
| 414 | + return '<strong>' . $txt[$ban_item['type']] . ':</strong> ' . $ban_item[$ban_item['type']]; | |
| 415 | +								} elseif ($ban_item['type'] == 'user') { | |
| 416 | + return '<strong>' . $txt['username'] . ':</strong> ' . $ban_item['user']['link']; | |
| 417 | +								} else { | |
| 418 | + return '<strong>' . $txt['unknown'] . ':</strong> ' . $ban_item['no_bantype_selected']; | |
| 419 | + } | |
| 412 | 420 | }, | 
| 413 | 421 | 'style' => 'text-align: left;', | 
| 414 | 422 | ), | 
| @@ -546,8 +554,9 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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('~&#(\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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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'); | 
| @@ -1452,7 +1452,7 @@ | ||
| 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 | */ | 
| @@ -14,8 +14,9 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | } | 
| @@ -4070,7 +4070,7 @@ | ||
| 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 |  { | 
| @@ -15,8 +15,9 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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('"' => '"')); | 
| 1236 | 1284 |  		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')); | 
| @@ -1242,8 +1290,9 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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="' . $row_quoted['real_name'] . '"]' . "\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="' . $row_quoted['real_name'] . '"]' . "\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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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) ? '' : '"' . implode('", "', $names) . '"'; | 
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 3195 | 3322 |  		{ | 
| 3196 | 3323 |  			$_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => ',')); | 
| 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 | ||
| 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(',' => ','))); | 
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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) ? '"' . $memberFromName . '"' : $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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | } | 
| @@ -2183,7 +2183,7 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 |  { | 
| @@ -15,8 +15,9 @@ discard block | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 1382 | 1450 |  		{ | 
| 1383 | 1451 |  			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => ''')); | 
| 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 | ||
| 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 | ||
| 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'] == 'None') | |
| 1456 | - unset($context['custom_pf']['cust_gender']); | |
| 1527 | +	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None') { | |
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 1580 | 1657 |  		{ | 
| 1581 | 1658 |  			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => ''')); | 
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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 | ||
| 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; | 
| @@ -1819,8 +1909,9 @@ discard block | ||
| 1819 | 1909 |  	call_integration_hook('integrate_theme_options'); | 
| 1820 | 1910 | |
| 1821 | 1911 | loadThemeOptions($memID); | 
| 1822 | -	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) | |
| 1823 | - loadCustomFields($memID, 'theme'); | |
| 1912 | +	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) { | |
| 1913 | + loadCustomFields($memID, 'theme'); | |
| 1914 | + } | |
| 1824 | 1915 | |
| 1825 | 1916 | $context['sub_template'] = 'edit_options'; | 
| 1826 | 1917 | $context['page_desc'] = $txt['theme_info']; | 
| @@ -1874,16 +1965,19 @@ discard block | ||
| 1874 | 1965 |  { | 
| 1875 | 1966 | global $txt, $context, $modSettings, $smcFunc, $sourcedir; | 
| 1876 | 1967 | |
| 1877 | - if (!isset($context['token_check'])) | |
| 1878 | - $context['token_check'] = 'profile-nt' . $memID; | |
| 1968 | +	if (!isset($context['token_check'])) { | |
| 1969 | + $context['token_check'] = 'profile-nt' . $memID; | |
| 1970 | + } | |
| 1879 | 1971 | |
| 1880 | 1972 | is_not_guest(); | 
| 1881 | - if (!$context['user']['is_owner']) | |
| 1882 | -		isAllowedTo('profile_extra_any'); | |
| 1973 | +	if (!$context['user']['is_owner']) { | |
| 1974 | +			isAllowedTo('profile_extra_any'); | |
| 1975 | + } | |
| 1883 | 1976 | |
| 1884 | 1977 | // Set the post action if we're coming from the profile... | 
| 1885 | - if (!isset($context['action'])) | |
| 1886 | - $context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID; | |
| 1978 | +	if (!isset($context['action'])) { | |
| 1979 | + $context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID; | |
| 1980 | + } | |
| 1887 | 1981 | |
| 1888 | 1982 | // What options are set | 
| 1889 | 1983 | loadThemeOptions($memID); | 
| @@ -1970,28 +2064,34 @@ discard block | ||
| 1970 | 2064 | ); | 
| 1971 | 2065 | |
| 1972 | 2066 | // There are certain things that are disabled at the group level. | 
| 1973 | - if (empty($modSettings['cal_enabled'])) | |
| 1974 | - unset($alert_types['calendar']); | |
| 2067 | +	if (empty($modSettings['cal_enabled'])) { | |
| 2068 | + unset($alert_types['calendar']); | |
| 2069 | + } | |
| 1975 | 2070 | |
| 1976 | 2071 | // Disable paid subscriptions at group level if they're disabled | 
| 1977 | - if (empty($modSettings['paid_enabled'])) | |
| 1978 | - unset($alert_types['paidsubs']); | |
| 2072 | +	if (empty($modSettings['paid_enabled'])) { | |
| 2073 | + unset($alert_types['paidsubs']); | |
| 2074 | + } | |
| 1979 | 2075 | |
| 1980 | 2076 | // Disable membergroup requests at group level if they're disabled | 
| 1981 | - if (empty($modSettings['show_group_membership'])) | |
| 1982 | - unset($alert_types['groupr'], $alert_types['members']['request_group']); | |
| 2077 | +	if (empty($modSettings['show_group_membership'])) { | |
| 2078 | + unset($alert_types['groupr'], $alert_types['members']['request_group']); | |
| 2079 | + } | |
| 1983 | 2080 | |
| 1984 | 2081 | // Disable mentions if they're disabled | 
| 1985 | - if (empty($modSettings['enable_mentions'])) | |
| 1986 | - unset($alert_types['msg']['msg_mention']); | |
| 2082 | +	if (empty($modSettings['enable_mentions'])) { | |
| 2083 | + unset($alert_types['msg']['msg_mention']); | |
| 2084 | + } | |
| 1987 | 2085 | |
| 1988 | 2086 | // Disable likes if they're disabled | 
| 1989 | - if (empty($modSettings['enable_likes'])) | |
| 1990 | - unset($alert_types['msg']['msg_like']); | |
| 2087 | +	if (empty($modSettings['enable_likes'])) { | |
| 2088 | + unset($alert_types['msg']['msg_like']); | |
| 2089 | + } | |
| 1991 | 2090 | |
| 1992 | 2091 | // Disable buddy requests if they're disabled | 
| 1993 | - if (empty($modSettings['enable_buddylist'])) | |
| 1994 | - unset($alert_types['members']['buddy_request']); | |
| 2092 | +	if (empty($modSettings['enable_buddylist'])) { | |
| 2093 | + unset($alert_types['members']['buddy_request']); | |
| 2094 | + } | |
| 1995 | 2095 | |
| 1996 | 2096 | // Now, now, we could pass this through global but we should really get into the habit of | 
| 1997 | 2097 | // passing content to hooks, not expecting hooks to splatter everything everywhere. | 
| @@ -2019,15 +2119,17 @@ discard block | ||
| 2019 | 2119 | $perms_cache['manage_membergroups'] = in_array($memID, $members); | 
| 2020 | 2120 | } | 
| 2021 | 2121 | |
| 2022 | - if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) | |
| 2023 | - unset($alert_types['members']['request_group']); | |
| 2122 | +		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) { | |
| 2123 | + unset($alert_types['members']['request_group']); | |
| 2124 | + } | |
| 2024 | 2125 | |
| 2025 | 2126 | foreach ($alert_types as $group => $items) | 
| 2026 | 2127 |  		{ | 
| 2027 | 2128 | foreach ($items as $alert_key => $alert_value) | 
| 2028 | 2129 |  			{ | 
| 2029 | - if (!isset($alert_value['permission'])) | |
| 2030 | - continue; | |
| 2130 | +				if (!isset($alert_value['permission'])) { | |
| 2131 | + continue; | |
| 2132 | + } | |
| 2031 | 2133 | if (!isset($perms_cache[$alert_value['permission']['name']])) | 
| 2032 | 2134 |  				{ | 
| 2033 | 2135 | $in_board = !empty($alert_value['permission']['is_board']) ? 0 : null; | 
| @@ -2035,12 +2137,14 @@ discard block | ||
| 2035 | 2137 | $perms_cache[$alert_value['permission']['name']] = in_array($memID, $members); | 
| 2036 | 2138 | } | 
| 2037 | 2139 | |
| 2038 | - if (!$perms_cache[$alert_value['permission']['name']]) | |
| 2039 | - unset ($alert_types[$group][$alert_key]); | |
| 2140 | +				if (!$perms_cache[$alert_value['permission']['name']]) { | |
| 2141 | + unset ($alert_types[$group][$alert_key]); | |
| 2142 | + } | |
| 2040 | 2143 | } | 
| 2041 | 2144 | |
| 2042 | - if (empty($alert_types[$group])) | |
| 2043 | - unset ($alert_types[$group]); | |
| 2145 | +			if (empty($alert_types[$group])) { | |
| 2146 | + unset ($alert_types[$group]); | |
| 2147 | + } | |
| 2044 | 2148 | } | 
| 2045 | 2149 | } | 
| 2046 | 2150 | |
| @@ -2072,9 +2176,9 @@ discard block | ||
| 2072 | 2176 | $update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0; | 
| 2073 | 2177 | break; | 
| 2074 | 2178 | case 'select': | 
| 2075 | - if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) | |
| 2076 | - $update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]]; | |
| 2077 | - else | |
| 2179 | +						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) { | |
| 2180 | + $update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]]; | |
| 2181 | + } else | |
| 2078 | 2182 |  						{ | 
| 2079 | 2183 | // We didn't have a sane value. Let's grab the first item from the possibles. | 
| 2080 | 2184 | $keys = array_keys($this_option['opts']); | 
| @@ -2094,23 +2198,28 @@ discard block | ||
| 2094 | 2198 | $this_value = 0; | 
| 2095 | 2199 | foreach ($context['alert_bits'] as $type => $bitvalue) | 
| 2096 | 2200 |  				{ | 
| 2097 | - if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') | |
| 2098 | - $this_value |= $bitvalue; | |
| 2201 | +					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') { | |
| 2202 | + $this_value |= $bitvalue; | |
| 2203 | + } | |
| 2204 | + } | |
| 2205 | +				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) { | |
| 2206 | + $update_prefs[$item_key] = $this_value; | |
| 2099 | 2207 | } | 
| 2100 | - if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) | |
| 2101 | - $update_prefs[$item_key] = $this_value; | |
| 2102 | 2208 | } | 
| 2103 | 2209 | } | 
| 2104 | 2210 | |
| 2105 | - if (!empty($_POST['opt_alert_timeout'])) | |
| 2106 | - $update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout']; | |
| 2211 | +		if (!empty($_POST['opt_alert_timeout'])) { | |
| 2212 | + $update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout']; | |
| 2213 | + } | |
| 2107 | 2214 | |
| 2108 | - if (!empty($_POST['notify_announcements'])) | |
| 2109 | - $update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements']; | |
| 2215 | +		if (!empty($_POST['notify_announcements'])) { | |
| 2216 | + $update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements']; | |
| 2217 | + } | |
| 2110 | 2218 | |
| 2111 | 2219 | setNotifyPrefs((int) $memID, $update_prefs); | 
| 2112 | - foreach ($update_prefs as $pref => $value) | |
| 2113 | - $context['alert_prefs'][$pref] = $value; | |
| 2220 | +		foreach ($update_prefs as $pref => $value) { | |
| 2221 | + $context['alert_prefs'][$pref] = $value; | |
| 2222 | + } | |
| 2114 | 2223 | |
| 2115 | 2224 | makeNotificationChanges($memID); | 
| 2116 | 2225 | |
| @@ -2140,8 +2249,9 @@ discard block | ||
| 2140 | 2249 | |
| 2141 | 2250 | // Now we're all set up. | 
| 2142 | 2251 | is_not_guest(); | 
| 2143 | - if (!$context['user']['is_owner']) | |
| 2144 | -		fatal_error('no_access'); | |
| 2252 | +	if (!$context['user']['is_owner']) { | |
| 2253 | +			fatal_error('no_access'); | |
| 2254 | + } | |
| 2145 | 2255 | |
| 2146 | 2256 |  	checkSession('get'); | 
| 2147 | 2257 | |
| @@ -2173,8 +2283,9 @@ discard block | ||
| 2173 | 2283 |  { | 
| 2174 | 2284 | global $smcFunc; | 
| 2175 | 2285 | |
| 2176 | - if (empty($toMark) || empty($memID)) | |
| 2177 | - return false; | |
| 2286 | +	if (empty($toMark) || empty($memID)) { | |
| 2287 | + return false; | |
| 2288 | + } | |
| 2178 | 2289 | |
| 2179 | 2290 | $toMark = (array) $toMark; | 
| 2180 | 2291 | |
| @@ -2208,8 +2319,9 @@ discard block | ||
| 2208 | 2319 |  { | 
| 2209 | 2320 | global $smcFunc; | 
| 2210 | 2321 | |
| 2211 | - if (empty($toDelete)) | |
| 2212 | - return false; | |
| 2322 | +	if (empty($toDelete)) { | |
| 2323 | + return false; | |
| 2324 | + } | |
| 2213 | 2325 | |
| 2214 | 2326 | $toDelete = (array) $toDelete; | 
| 2215 | 2327 | |
| @@ -2244,8 +2356,9 @@ discard block | ||
| 2244 | 2356 |  { | 
| 2245 | 2357 | global $smcFunc; | 
| 2246 | 2358 | |
| 2247 | - if (empty($memID)) | |
| 2248 | - return false; | |
| 2359 | +	if (empty($memID)) { | |
| 2360 | + return false; | |
| 2361 | + } | |
| 2249 | 2362 | |
| 2250 | 2363 |  	$request = $smcFunc['db_query']('', ' | 
| 2251 | 2364 | SELECT id_alert | 
| @@ -2322,8 +2435,9 @@ discard block | ||
| 2322 | 2435 |  					{ | 
| 2323 | 2436 | $link = $topic['link']; | 
| 2324 | 2437 | |
| 2325 | - if ($topic['new']) | |
| 2326 | - $link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; | |
| 2438 | +						if ($topic['new']) { | |
| 2439 | + $link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; | |
| 2440 | + } | |
| 2327 | 2441 | |
| 2328 | 2442 | $link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>'; | 
| 2329 | 2443 | |
| @@ -2474,8 +2588,9 @@ discard block | ||
| 2474 | 2588 |  					{ | 
| 2475 | 2589 | $link = $board['link']; | 
| 2476 | 2590 | |
| 2477 | - if ($board['new']) | |
| 2478 | - $link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; | |
| 2591 | +						if ($board['new']) { | |
| 2592 | + $link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; | |
| 2593 | + } | |
| 2479 | 2594 | |
| 2480 | 2595 | return $link; | 
| 2481 | 2596 | }, | 
| @@ -2675,8 +2790,8 @@ discard block | ||
| 2675 | 2790 | ) | 
| 2676 | 2791 | ); | 
| 2677 | 2792 | $notification_boards = array(); | 
| 2678 | - while ($row = $smcFunc['db_fetch_assoc']($request)) | |
| 2679 | - $notification_boards[] = array( | |
| 2793 | +	while ($row = $smcFunc['db_fetch_assoc']($request)) { | |
| 2794 | + $notification_boards[] = array( | |
| 2680 | 2795 | 'id' => $row['id_board'], | 
| 2681 | 2796 | 'name' => $row['name'], | 
| 2682 | 2797 | 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', | 
| @@ -2684,6 +2799,7 @@ discard block | ||
| 2684 | 2799 | 'new' => $row['board_read'] < $row['id_msg_updated'], | 
| 2685 | 2800 | 'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0), | 
| 2686 | 2801 | ); | 
| 2802 | + } | |
| 2687 | 2803 | $smcFunc['db_free_result']($request); | 
| 2688 | 2804 | |
| 2689 | 2805 | return $notification_boards; | 
| @@ -2698,17 +2814,18 @@ discard block | ||
| 2698 | 2814 |  { | 
| 2699 | 2815 | global $context, $options, $cur_profile, $smcFunc; | 
| 2700 | 2816 | |
| 2701 | - if (isset($_POST['default_options'])) | |
| 2702 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; | |
| 2817 | +	if (isset($_POST['default_options'])) { | |
| 2818 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; | |
| 2819 | + } | |
| 2703 | 2820 | |
| 2704 | 2821 | if ($context['user']['is_owner']) | 
| 2705 | 2822 |  	{ | 
| 2706 | 2823 | $context['member']['options'] = $options; | 
| 2707 | - if (isset($_POST['options']) && is_array($_POST['options'])) | |
| 2708 | - foreach ($_POST['options'] as $k => $v) | |
| 2824 | +		if (isset($_POST['options']) && is_array($_POST['options'])) { | |
| 2825 | + foreach ($_POST['options'] as $k => $v) | |
| 2709 | 2826 | $context['member']['options'][$k] = $v; | 
| 2710 | - } | |
| 2711 | - else | |
| 2827 | + } | |
| 2828 | + } else | |
| 2712 | 2829 |  	{ | 
| 2713 | 2830 |  		$request = $smcFunc['db_query']('', ' | 
| 2714 | 2831 | SELECT id_member, variable, value | 
| @@ -2729,8 +2846,9 @@ discard block | ||
| 2729 | 2846 | continue; | 
| 2730 | 2847 | } | 
| 2731 | 2848 | |
| 2732 | - if (isset($_POST['options'][$row['variable']])) | |
| 2733 | - $row['value'] = $_POST['options'][$row['variable']]; | |
| 2849 | +			if (isset($_POST['options'][$row['variable']])) { | |
| 2850 | + $row['value'] = $_POST['options'][$row['variable']]; | |
| 2851 | + } | |
| 2734 | 2852 | $context['member']['options'][$row['variable']] = $row['value']; | 
| 2735 | 2853 | } | 
| 2736 | 2854 | $smcFunc['db_free_result']($request); | 
| @@ -2738,8 +2856,9 @@ discard block | ||
| 2738 | 2856 | // Load up the default theme options for any missing. | 
| 2739 | 2857 | foreach ($temp as $k => $v) | 
| 2740 | 2858 |  		{ | 
| 2741 | - if (!isset($context['member']['options'][$k])) | |
| 2742 | - $context['member']['options'][$k] = $v; | |
| 2859 | +			if (!isset($context['member']['options'][$k])) { | |
| 2860 | + $context['member']['options'][$k] = $v; | |
| 2861 | + } | |
| 2743 | 2862 | } | 
| 2744 | 2863 | } | 
| 2745 | 2864 | } | 
| @@ -2754,8 +2873,9 @@ discard block | ||
| 2754 | 2873 | global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir; | 
| 2755 | 2874 | |
| 2756 | 2875 | // Have the admins enabled this option? | 
| 2757 | - if (empty($modSettings['allow_ignore_boards'])) | |
| 2758 | -		fatal_lang_error('ignoreboards_disallowed', 'user'); | |
| 2876 | +	if (empty($modSettings['allow_ignore_boards'])) { | |
| 2877 | +			fatal_lang_error('ignoreboards_disallowed', 'user'); | |
| 2878 | + } | |
| 2759 | 2879 | |
| 2760 | 2880 | // Find all the boards this user is allowed to see. | 
| 2761 | 2881 |  	$request = $smcFunc['db_query']('order_by_board_order', ' | 
| @@ -2775,12 +2895,13 @@ discard block | ||
| 2775 | 2895 | while ($row = $smcFunc['db_fetch_assoc']($request)) | 
| 2776 | 2896 |  	{ | 
| 2777 | 2897 | // This category hasn't been set up yet.. | 
| 2778 | - if (!isset($context['categories'][$row['id_cat']])) | |
| 2779 | - $context['categories'][$row['id_cat']] = array( | |
| 2898 | +		if (!isset($context['categories'][$row['id_cat']])) { | |
| 2899 | + $context['categories'][$row['id_cat']] = array( | |
| 2780 | 2900 | 'id' => $row['id_cat'], | 
| 2781 | 2901 | 'name' => $row['cat_name'], | 
| 2782 | 2902 | 'boards' => array() | 
| 2783 | 2903 | ); | 
| 2904 | + } | |
| 2784 | 2905 | |
| 2785 | 2906 | // Set this board up, and let the template know when it's a child. (indent them..) | 
| 2786 | 2907 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( | 
| @@ -2810,18 +2931,20 @@ discard block | ||
| 2810 | 2931 | } | 
| 2811 | 2932 | |
| 2812 | 2933 | $max_boards = ceil(count($temp_boards) / 2); | 
| 2813 | - if ($max_boards == 1) | |
| 2814 | - $max_boards = 2; | |
| 2934 | +	if ($max_boards == 1) { | |
| 2935 | + $max_boards = 2; | |
| 2936 | + } | |
| 2815 | 2937 | |
| 2816 | 2938 | // Now, alternate them so they can be shown left and right ;). | 
| 2817 | 2939 | $context['board_columns'] = array(); | 
| 2818 | 2940 | for ($i = 0; $i < $max_boards; $i++) | 
| 2819 | 2941 |  	{ | 
| 2820 | 2942 | $context['board_columns'][] = $temp_boards[$i]; | 
| 2821 | - if (isset($temp_boards[$i + $max_boards])) | |
| 2822 | - $context['board_columns'][] = $temp_boards[$i + $max_boards]; | |
| 2823 | - else | |
| 2824 | - $context['board_columns'][] = array(); | |
| 2943 | +		if (isset($temp_boards[$i + $max_boards])) { | |
| 2944 | + $context['board_columns'][] = $temp_boards[$i + $max_boards]; | |
| 2945 | +		} else { | |
| 2946 | + $context['board_columns'][] = array(); | |
| 2947 | + } | |
| 2825 | 2948 | } | 
| 2826 | 2949 | |
| 2827 | 2950 | loadThemeOptions($memID); | 
| @@ -2890,8 +3013,9 @@ discard block | ||
| 2890 | 3013 | while ($row = $smcFunc['db_fetch_assoc']($request)) | 
| 2891 | 3014 |  	{ | 
| 2892 | 3015 | // We should skip the administrator group if they don't have the admin_forum permission! | 
| 2893 | -		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) | |
| 2894 | - continue; | |
| 3016 | +		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) { | |
| 3017 | + continue; | |
| 3018 | + } | |
| 2895 | 3019 | |
| 2896 | 3020 | $context['member_groups'][$row['id_group']] = array( | 
| 2897 | 3021 | 'id' => $row['id_group'], | 
| @@ -2937,16 +3061,17 @@ discard block | ||
| 2937 | 3061 | $context['max_signature_length'] = $context['signature_limits']['max_length']; | 
| 2938 | 3062 | // Warning message for signature image limits? | 
| 2939 | 3063 | $context['signature_warning'] = ''; | 
| 2940 | - if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) | |
| 2941 | - $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']); | |
| 2942 | - elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) | |
| 2943 | - $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']); | |
| 3064 | +	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) { | |
| 3065 | + $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']); | |
| 3066 | +	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) { | |
| 3067 | + $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']); | |
| 3068 | + } | |
| 2944 | 3069 | |
| 2945 | 3070 |  	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv')))); | 
| 2946 | 3071 | |
| 2947 | - if (empty($context['do_preview'])) | |
| 2948 | -		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '<', '>', '"', '''), $cur_profile['signature']); | |
| 2949 | - else | |
| 3072 | +	if (empty($context['do_preview'])) { | |
| 3073 | +			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '<', '>', '"', '''), $cur_profile['signature']); | |
| 3074 | + } else | |
| 2950 | 3075 |  	{ | 
| 2951 | 3076 | $signature = !empty($_POST['signature']) ? $_POST['signature'] : ''; | 
| 2952 | 3077 | $validation = profileValidateSignature($signature); | 
| @@ -2956,8 +3081,9 @@ discard block | ||
| 2956 | 3081 | $context['post_errors'] = array(); | 
| 2957 | 3082 | } | 
| 2958 | 3083 | $context['post_errors'][] = 'signature_not_yet_saved'; | 
| 2959 | - if ($validation !== true && $validation !== false) | |
| 2960 | - $context['post_errors'][] = $validation; | |
| 3084 | +		if ($validation !== true && $validation !== false) { | |
| 3085 | + $context['post_errors'][] = $validation; | |
| 3086 | + } | |
| 2961 | 3087 | |
| 2962 | 3088 | censorText($context['member']['signature']); | 
| 2963 | 3089 | $context['member']['current_signature'] = $context['member']['signature']; | 
| @@ -2967,8 +3093,9 @@ discard block | ||
| 2967 | 3093 | } | 
| 2968 | 3094 | |
| 2969 | 3095 | // Load the spell checker? | 
| 2970 | - if ($context['show_spellchecking']) | |
| 2971 | -		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); | |
| 3096 | +	if ($context['show_spellchecking']) { | |
| 3097 | +			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); | |
| 3098 | + } | |
| 2972 | 3099 | |
| 2973 | 3100 | return true; | 
| 2974 | 3101 | } | 
| @@ -3002,8 +3129,7 @@ discard block | ||
| 3002 | 3129 | 'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11) | 
| 3003 | 3130 | ); | 
| 3004 | 3131 | $context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']); | 
| 3005 | - } | |
| 3006 | - elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload']) | |
| 3132 | + } elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload']) | |
| 3007 | 3133 |  	{ | 
| 3008 | 3134 | $context['member']['avatar'] += array( | 
| 3009 | 3135 | 'choice' => 'upload', | 
| @@ -3013,33 +3139,34 @@ discard block | ||
| 3013 | 3139 | $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']; | 
| 3014 | 3140 | } | 
| 3015 | 3141 | // Use "avatar_original" here so we show what the user entered even if the image proxy is enabled | 
| 3016 | - elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) | |
| 3017 | - $context['member']['avatar'] += array( | |
| 3142 | +	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) { | |
| 3143 | + $context['member']['avatar'] += array( | |
| 3018 | 3144 | 'choice' => 'external', | 
| 3019 | 3145 | 'server_pic' => 'blank.png', | 
| 3020 | 3146 | 'external' => $cur_profile['avatar_original'] | 
| 3021 | 3147 | ); | 
| 3022 | - elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) | |
| 3023 | - $context['member']['avatar'] += array( | |
| 3148 | +	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) { | |
| 3149 | + $context['member']['avatar'] += array( | |
| 3024 | 3150 | 'choice' => 'server_stored', | 
| 3025 | 3151 | 'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'], | 
| 3026 | 3152 | 'external' => 'http://' | 
| 3027 | 3153 | ); | 
| 3028 | - else | |
| 3029 | - $context['member']['avatar'] += array( | |
| 3154 | +	} else { | |
| 3155 | + $context['member']['avatar'] += array( | |
| 3030 | 3156 | 'choice' => 'none', | 
| 3031 | 3157 | 'server_pic' => 'blank.png', | 
| 3032 | 3158 | 'external' => 'http://' | 
| 3033 | 3159 | ); | 
| 3160 | + } | |
| 3034 | 3161 | |
| 3035 | 3162 | // Get a list of all the avatars. | 
| 3036 | 3163 | if ($context['member']['avatar']['allow_server_stored']) | 
| 3037 | 3164 |  	{ | 
| 3038 | 3165 | $context['avatar_list'] = array(); | 
| 3039 | 3166 |  		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array(); | 
| 3167 | +	} else { | |
| 3168 | + $context['avatars'] = array(); | |
| 3040 | 3169 | } | 
| 3041 | - else | |
| 3042 | - $context['avatars'] = array(); | |
| 3043 | 3170 | |
| 3044 | 3171 | // Second level selected avatar... | 
| 3045 | 3172 | $context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1); | 
| @@ -3068,19 +3195,22 @@ discard block | ||
| 3068 | 3195 | ) | 
| 3069 | 3196 | ); | 
| 3070 | 3197 | $protected_groups = array(1); | 
| 3071 | - while ($row = $smcFunc['db_fetch_assoc']($request)) | |
| 3072 | - $protected_groups[] = $row['id_group']; | |
| 3198 | +		while ($row = $smcFunc['db_fetch_assoc']($request)) { | |
| 3199 | + $protected_groups[] = $row['id_group']; | |
| 3200 | + } | |
| 3073 | 3201 | $smcFunc['db_free_result']($request); | 
| 3074 | 3202 | |
| 3075 | 3203 | $protected_groups = array_unique($protected_groups); | 
| 3076 | 3204 | } | 
| 3077 | 3205 | |
| 3078 | 3206 | // The account page allows the change of your id_group - but not to a protected group! | 
| 3079 | - if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) | |
| 3080 | - $value = (int) $value; | |
| 3207 | +	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) { | |
| 3208 | + $value = (int) $value; | |
| 3209 | + } | |
| 3081 | 3210 | // ... otherwise it's the old group sir. | 
| 3082 | - else | |
| 3083 | - $value = $old_profile['id_group']; | |
| 3211 | +	else { | |
| 3212 | + $value = $old_profile['id_group']; | |
| 3213 | + } | |
| 3084 | 3214 | |
| 3085 | 3215 | // Find the additional membergroups (if any) | 
| 3086 | 3216 | if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups'])) | 
| @@ -3089,16 +3219,18 @@ discard block | ||
| 3089 | 3219 | foreach ($_POST['additional_groups'] as $group_id) | 
| 3090 | 3220 |  		{ | 
| 3091 | 3221 | $group_id = (int) $group_id; | 
| 3092 | - if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) | |
| 3093 | - $additional_groups[] = $group_id; | |
| 3222 | +			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) { | |
| 3223 | + $additional_groups[] = $group_id; | |
| 3224 | + } | |
| 3094 | 3225 | } | 
| 3095 | 3226 | |
| 3096 | 3227 | // Put the protected groups back in there if you don't have permission to take them away. | 
| 3097 | 3228 |  		$old_additional_groups = explode(',', $old_profile['additional_groups']); | 
| 3098 | 3229 | foreach ($old_additional_groups as $group_id) | 
| 3099 | 3230 |  		{ | 
| 3100 | - if (!empty($protected_groups) && in_array($group_id, $protected_groups)) | |
| 3101 | - $additional_groups[] = $group_id; | |
| 3231 | +			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) { | |
| 3232 | + $additional_groups[] = $group_id; | |
| 3233 | + } | |
| 3102 | 3234 | } | 
| 3103 | 3235 | |
| 3104 | 3236 |  		if (implode(',', $additional_groups) !== $old_profile['additional_groups']) | 
| @@ -3130,18 +3262,20 @@ discard block | ||
| 3130 | 3262 | list ($another) = $smcFunc['db_fetch_row']($request); | 
| 3131 | 3263 | $smcFunc['db_free_result']($request); | 
| 3132 | 3264 | |
| 3133 | - if (empty($another)) | |
| 3134 | -				fatal_lang_error('at_least_one_admin', 'critical'); | |
| 3265 | +			if (empty($another)) { | |
| 3266 | +							fatal_lang_error('at_least_one_admin', 'critical'); | |
| 3267 | + } | |
| 3135 | 3268 | } | 
| 3136 | 3269 | } | 
| 3137 | 3270 | |
| 3138 | 3271 | // If we are changing group status, update permission cache as necessary. | 
| 3139 | 3272 | if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups'])) | 
| 3140 | 3273 |  	{ | 
| 3141 | - if ($context['user']['is_owner']) | |
| 3142 | - $_SESSION['mc']['time'] = 0; | |
| 3143 | - else | |
| 3144 | -			updateSettings(array('settings_updated' => time())); | |
| 3274 | +		if ($context['user']['is_owner']) { | |
| 3275 | + $_SESSION['mc']['time'] = 0; | |
| 3276 | +		} else { | |
| 3277 | +					updateSettings(array('settings_updated' => time())); | |
| 3278 | + } | |
| 3145 | 3279 | } | 
| 3146 | 3280 | |
| 3147 | 3281 | // Announce to any hooks that we have changed groups, but don't allow them to change it. | 
| @@ -3162,8 +3296,9 @@ discard block | ||
| 3162 | 3296 | global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context; | 
| 3163 | 3297 | |
| 3164 | 3298 | $memID = $context['id_member']; | 
| 3165 | - if (empty($memID) && !empty($context['password_auth_failed'])) | |
| 3166 | - return false; | |
| 3299 | +	if (empty($memID) && !empty($context['password_auth_failed'])) { | |
| 3300 | + return false; | |
| 3301 | + } | |
| 3167 | 3302 | |
| 3168 | 3303 | require_once($sourcedir . '/ManageAttachments.php'); | 
| 3169 | 3304 | |
| @@ -3174,8 +3309,9 @@ discard block | ||
| 3174 | 3309 | $downloadedExternalAvatar = false; | 
| 3175 | 3310 |  	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'])) | 
| 3176 | 3311 |  	{ | 
| 3177 | - if (!is_writable($uploadDir)) | |
| 3178 | -			fatal_lang_error('attachments_no_write', 'critical'); | |
| 3312 | +		if (!is_writable($uploadDir)) { | |
| 3313 | +					fatal_lang_error('attachments_no_write', 'critical'); | |
| 3314 | + } | |
| 3179 | 3315 | |
| 3180 | 3316 | require_once($sourcedir . '/Subs-Package.php'); | 
| 3181 | 3317 | |
| @@ -3219,19 +3355,18 @@ discard block | ||
| 3219 | 3355 | |
| 3220 | 3356 | // Get rid of their old avatar. (if uploaded.) | 
| 3221 | 3357 |  		removeAttachments(array('id_member' => $memID)); | 
| 3222 | - } | |
| 3223 | - elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled'])) | |
| 3358 | + } elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled'])) | |
| 3224 | 3359 |  	{ | 
| 3225 | 3360 | // 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. | 
| 3226 | - if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) | |
| 3227 | - $profile_vars['avatar'] = 'gravatar://'; | |
| 3228 | - else | |
| 3229 | - $profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : ''); | |
| 3361 | +		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) { | |
| 3362 | + $profile_vars['avatar'] = 'gravatar://'; | |
| 3363 | +		} else { | |
| 3364 | + $profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : ''); | |
| 3365 | + } | |
| 3230 | 3366 | |
| 3231 | 3367 | // Get rid of their old avatar. (if uploaded.) | 
| 3232 | 3368 |  		removeAttachments(array('id_member' => $memID)); | 
| 3233 | - } | |
| 3234 | -	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external'])) | |
| 3369 | +	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external'])) | |
| 3235 | 3370 |  	{ | 
| 3236 | 3371 | // We need these clean... | 
| 3237 | 3372 | $cur_profile['id_attach'] = 0; | 
| @@ -3243,11 +3378,13 @@ discard block | ||
| 3243 | 3378 | |
| 3244 | 3379 |  		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal'])); | 
| 3245 | 3380 | |
| 3246 | - if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') | |
| 3247 | - $profile_vars['avatar'] = ''; | |
| 3381 | +		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') { | |
| 3382 | + $profile_vars['avatar'] = ''; | |
| 3383 | + } | |
| 3248 | 3384 | // Trying to make us do something we'll regret? | 
| 3249 | - elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') | |
| 3250 | - return 'bad_avatar_invalid_url'; | |
| 3385 | +		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') { | |
| 3386 | + return 'bad_avatar_invalid_url'; | |
| 3387 | + } | |
| 3251 | 3388 | // Should we check dimensions? | 
| 3252 | 3389 | elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external'])) | 
| 3253 | 3390 |  		{ | 
| @@ -3257,9 +3394,9 @@ discard block | ||
| 3257 | 3394 | 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'])))) | 
| 3258 | 3395 |  			{ | 
| 3259 | 3396 | // Houston, we have a problem. The avatar is too large!! | 
| 3260 | - if ($modSettings['avatar_action_too_large'] == 'option_refuse') | |
| 3261 | - return 'bad_avatar_too_large'; | |
| 3262 | - elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize') | |
| 3397 | +				if ($modSettings['avatar_action_too_large'] == 'option_refuse') { | |
| 3398 | + return 'bad_avatar_too_large'; | |
| 3399 | + } elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize') | |
| 3263 | 3400 |  				{ | 
| 3264 | 3401 | // @todo remove this if appropriate | 
| 3265 | 3402 | require_once($sourcedir . '/Subs-Graphics.php'); | 
| @@ -3269,26 +3406,27 @@ discard block | ||
| 3269 | 3406 | $cur_profile['id_attach'] = $modSettings['new_avatar_data']['id']; | 
| 3270 | 3407 | $cur_profile['filename'] = $modSettings['new_avatar_data']['filename']; | 
| 3271 | 3408 | $cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type']; | 
| 3409 | +					} else { | |
| 3410 | + return 'bad_avatar'; | |
| 3272 | 3411 | } | 
| 3273 | - else | |
| 3274 | - return 'bad_avatar'; | |
| 3275 | 3412 | } | 
| 3276 | 3413 | } | 
| 3277 | 3414 | } | 
| 3278 | - } | |
| 3279 | -	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar) | |
| 3415 | +	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar) | |
| 3280 | 3416 |  	{ | 
| 3281 | 3417 | if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar) | 
| 3282 | 3418 |  		{ | 
| 3283 | 3419 | // Get the dimensions of the image. | 
| 3284 | 3420 | if (!$downloadedExternalAvatar) | 
| 3285 | 3421 |  			{ | 
| 3286 | - if (!is_writable($uploadDir)) | |
| 3287 | -					fatal_lang_error('attachments_no_write', 'critical'); | |
| 3422 | +				if (!is_writable($uploadDir)) { | |
| 3423 | +									fatal_lang_error('attachments_no_write', 'critical'); | |
| 3424 | + } | |
| 3288 | 3425 | |
| 3289 | 3426 |  				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true); | 
| 3290 | - if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) | |
| 3291 | -					fatal_lang_error('attach_timeout', 'critical'); | |
| 3427 | +				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) { | |
| 3428 | +									fatal_lang_error('attach_timeout', 'critical'); | |
| 3429 | + } | |
| 3292 | 3430 | |
| 3293 | 3431 | $_FILES['attachment']['tmp_name'] = $new_filename; | 
| 3294 | 3432 | } | 
| @@ -3401,17 +3539,19 @@ discard block | ||
| 3401 | 3539 | $profile_vars['avatar'] = ''; | 
| 3402 | 3540 | |
| 3403 | 3541 | // Delete any temporary file. | 
| 3404 | - if (file_exists($_FILES['attachment']['tmp_name'])) | |
| 3405 | - @unlink($_FILES['attachment']['tmp_name']); | |
| 3542 | +			if (file_exists($_FILES['attachment']['tmp_name'])) { | |
| 3543 | + @unlink($_FILES['attachment']['tmp_name']); | |
| 3544 | + } | |
| 3406 | 3545 | } | 
| 3407 | 3546 | // Selected the upload avatar option and had one already uploaded before or didn't upload one. | 
| 3408 | - else | |
| 3547 | +		else { | |
| 3548 | + $profile_vars['avatar'] = ''; | |
| 3549 | + } | |
| 3550 | +	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) { | |
| 3551 | + $profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address']))); | |
| 3552 | +	} else { | |
| 3409 | 3553 | $profile_vars['avatar'] = ''; | 
| 3410 | 3554 | } | 
| 3411 | -	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) | |
| 3412 | - $profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address']))); | |
| 3413 | - else | |
| 3414 | - $profile_vars['avatar'] = ''; | |
| 3415 | 3555 | |
| 3416 | 3556 | // Setup the profile variables so it shows things right on display! | 
| 3417 | 3557 | $cur_profile['avatar'] = $profile_vars['avatar']; | 
| @@ -3459,9 +3599,9 @@ discard block | ||
| 3459 | 3599 | $smiley_parsed = $unparsed_signature; | 
| 3460 | 3600 | parsesmileys($smiley_parsed); | 
| 3461 | 3601 | $smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img'); | 
| 3462 | - if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) | |
| 3463 | - return 'signature_allow_smileys'; | |
| 3464 | - elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4]) | |
| 3602 | +		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) { | |
| 3603 | + return 'signature_allow_smileys'; | |
| 3604 | + } elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4]) | |
| 3465 | 3605 |  		{ | 
| 3466 | 3606 | $txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]); | 
| 3467 | 3607 | return 'signature_max_smileys'; | 
| @@ -3474,14 +3614,15 @@ discard block | ||
| 3474 | 3614 |  			{ | 
| 3475 | 3615 | $limit_broke = 0; | 
| 3476 | 3616 | // Attempt to allow all sizes of abuse, so to speak. | 
| 3477 | - if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) | |
| 3478 | - $limit_broke = $sig_limits[7] . 'px'; | |
| 3479 | - elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) | |
| 3480 | - $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; | |
| 3481 | - elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) | |
| 3482 | - $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; | |
| 3483 | - elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) | |
| 3484 | - $limit_broke = 'large'; | |
| 3617 | +				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) { | |
| 3618 | + $limit_broke = $sig_limits[7] . 'px'; | |
| 3619 | +				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) { | |
| 3620 | + $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; | |
| 3621 | +				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) { | |
| 3622 | + $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; | |
| 3623 | +				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) { | |
| 3624 | + $limit_broke = 'large'; | |
| 3625 | + } | |
| 3485 | 3626 | |
| 3486 | 3627 | if ($limit_broke) | 
| 3487 | 3628 |  				{ | 
| @@ -3523,24 +3664,26 @@ discard block | ||
| 3523 | 3664 | $width = -1; $height = -1; | 
| 3524 | 3665 | |
| 3525 | 3666 | // Does it have predefined restraints? Width first. | 
| 3526 | - if ($matches[6][$key]) | |
| 3527 | - $matches[2][$key] = $matches[6][$key]; | |
| 3667 | +					if ($matches[6][$key]) { | |
| 3668 | + $matches[2][$key] = $matches[6][$key]; | |
| 3669 | + } | |
| 3528 | 3670 | if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5]) | 
| 3529 | 3671 |  					{ | 
| 3530 | 3672 | $width = $sig_limits[5]; | 
| 3531 | 3673 | $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]); | 
| 3674 | +					} elseif ($matches[2][$key]) { | |
| 3675 | + $width = $matches[2][$key]; | |
| 3532 | 3676 | } | 
| 3533 | - elseif ($matches[2][$key]) | |
| 3534 | - $width = $matches[2][$key]; | |
| 3535 | 3677 | // ... and height. | 
| 3536 | 3678 | if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6]) | 
| 3537 | 3679 |  					{ | 
| 3538 | 3680 | $height = $sig_limits[6]; | 
| 3539 | - if ($width != -1) | |
| 3540 | - $width = $width * ($height / $matches[4][$key]); | |
| 3681 | +						if ($width != -1) { | |
| 3682 | + $width = $width * ($height / $matches[4][$key]); | |
| 3683 | + } | |
| 3684 | +					} elseif ($matches[4][$key]) { | |
| 3685 | + $height = $matches[4][$key]; | |
| 3541 | 3686 | } | 
| 3542 | - elseif ($matches[4][$key]) | |
| 3543 | - $height = $matches[4][$key]; | |
| 3544 | 3687 | |
| 3545 | 3688 | // If the dimensions are still not fixed - we need to check the actual image. | 
| 3546 | 3689 | if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6])) | 
| @@ -3558,21 +3701,24 @@ discard block | ||
| 3558 | 3701 | if ($sizes[1] > $sig_limits[6] && $sig_limits[6]) | 
| 3559 | 3702 |  							{ | 
| 3560 | 3703 | $height = $sig_limits[6]; | 
| 3561 | - if ($width == -1) | |
| 3562 | - $width = $sizes[0]; | |
| 3704 | +								if ($width == -1) { | |
| 3705 | + $width = $sizes[0]; | |
| 3706 | + } | |
| 3563 | 3707 | $width = $width * ($height / $sizes[1]); | 
| 3708 | +							} elseif ($width != -1) { | |
| 3709 | + $height = $sizes[1]; | |
| 3564 | 3710 | } | 
| 3565 | - elseif ($width != -1) | |
| 3566 | - $height = $sizes[1]; | |
| 3567 | 3711 | } | 
| 3568 | 3712 | } | 
| 3569 | 3713 | |
| 3570 | 3714 | // Did we come up with some changes? If so remake the string. | 
| 3571 | - if ($width != -1 || $height != -1) | |
| 3572 | - $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]'; | |
| 3715 | +					if ($width != -1 || $height != -1) { | |
| 3716 | + $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]'; | |
| 3717 | + } | |
| 3718 | + } | |
| 3719 | +				if (!empty($replaces)) { | |
| 3720 | + $value = str_replace(array_keys($replaces), array_values($replaces), $value); | |
| 3573 | 3721 | } | 
| 3574 | - if (!empty($replaces)) | |
| 3575 | - $value = str_replace(array_keys($replaces), array_values($replaces), $value); | |
| 3576 | 3722 | } | 
| 3577 | 3723 | } | 
| 3578 | 3724 | |
| @@ -3616,10 +3762,12 @@ discard block | ||
| 3616 | 3762 |  	$email = strtr($email, array(''' => '\'')); | 
| 3617 | 3763 | |
| 3618 | 3764 | // Check the name and email for validity. | 
| 3619 | - if (trim($email) == '') | |
| 3620 | - return 'no_email'; | |
| 3621 | - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) | |
| 3622 | - return 'bad_email'; | |
| 3765 | +	if (trim($email) == '') { | |
| 3766 | + return 'no_email'; | |
| 3767 | + } | |
| 3768 | +	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
| 3769 | + return 'bad_email'; | |
| 3770 | + } | |
| 3623 | 3771 | |
| 3624 | 3772 | // Email addresses should be and stay unique. | 
| 3625 | 3773 |  	$request = $smcFunc['db_query']('', ' | 
| @@ -3634,8 +3782,9 @@ discard block | ||
| 3634 | 3782 | ) | 
| 3635 | 3783 | ); | 
| 3636 | 3784 | |
| 3637 | - if ($smcFunc['db_num_rows']($request) > 0) | |
| 3638 | - return 'email_taken'; | |
| 3785 | +	if ($smcFunc['db_num_rows']($request) > 0) { | |
| 3786 | + return 'email_taken'; | |
| 3787 | + } | |
| 3639 | 3788 | $smcFunc['db_free_result']($request); | 
| 3640 | 3789 | |
| 3641 | 3790 | return true; | 
| @@ -3648,8 +3797,9 @@ discard block | ||
| 3648 | 3797 |  { | 
| 3649 | 3798 | global $modSettings, $context, $cur_profile; | 
| 3650 | 3799 | |
| 3651 | - if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') | |
| 3652 | - setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt'])); | |
| 3800 | +	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') { | |
| 3801 | + setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt'])); | |
| 3802 | + } | |
| 3653 | 3803 | |
| 3654 | 3804 | loadUserSettings(); | 
| 3655 | 3805 | writeLog(); | 
| @@ -3665,8 +3815,9 @@ discard block | ||
| 3665 | 3815 | require_once($sourcedir . '/Subs-Post.php'); | 
| 3666 | 3816 | |
| 3667 | 3817 | // Shouldn't happen but just in case. | 
| 3668 | - if (empty($profile_vars['email_address'])) | |
| 3669 | - return; | |
| 3818 | +	if (empty($profile_vars['email_address'])) { | |
| 3819 | + return; | |
| 3820 | + } | |
| 3670 | 3821 | |
| 3671 | 3822 | $replacements = array( | 
| 3672 | 3823 | 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'], | 
| @@ -3689,8 +3840,9 @@ discard block | ||
| 3689 | 3840 | $_SESSION['log_time'] = 0; | 
| 3690 | 3841 | $_SESSION['login_' . $cookiename] = $smcFunc['json_encode'](array(0, '', 0)); | 
| 3691 | 3842 | |
| 3692 | - if (isset($_COOKIE[$cookiename])) | |
| 3693 | - $_COOKIE[$cookiename] = ''; | |
| 3843 | +	if (isset($_COOKIE[$cookiename])) { | |
| 3844 | + $_COOKIE[$cookiename] = ''; | |
| 3845 | + } | |
| 3694 | 3846 | |
| 3695 | 3847 | loadUserSettings(); | 
| 3696 | 3848 | |
| @@ -3723,11 +3875,13 @@ discard block | ||
| 3723 | 3875 | $groups[] = $curMember['id_group']; | 
| 3724 | 3876 | |
| 3725 | 3877 | // Ensure the query doesn't croak! | 
| 3726 | - if (empty($groups)) | |
| 3727 | - $groups = array(0); | |
| 3878 | +	if (empty($groups)) { | |
| 3879 | + $groups = array(0); | |
| 3880 | + } | |
| 3728 | 3881 | // Just to be sure... | 
| 3729 | - foreach ($groups as $k => $v) | |
| 3730 | - $groups[$k] = (int) $v; | |
| 3882 | +	foreach ($groups as $k => $v) { | |
| 3883 | + $groups[$k] = (int) $v; | |
| 3884 | + } | |
| 3731 | 3885 | |
| 3732 | 3886 | // Get all the membergroups they can join. | 
| 3733 | 3887 |  	$request = $smcFunc['db_query']('', ' | 
| @@ -3757,12 +3911,14 @@ discard block | ||
| 3757 | 3911 | while ($row = $smcFunc['db_fetch_assoc']($request)) | 
| 3758 | 3912 |  	{ | 
| 3759 | 3913 | // Can they edit their primary group? | 
| 3760 | - if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) | |
| 3761 | - $context['can_edit_primary'] = true; | |
| 3914 | +		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) { | |
| 3915 | + $context['can_edit_primary'] = true; | |
| 3916 | + } | |
| 3762 | 3917 | |
| 3763 | 3918 | // If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it. | 
| 3764 | - if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) | |
| 3765 | - continue; | |
| 3919 | +		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) { | |
| 3920 | + continue; | |
| 3921 | + } | |
| 3766 | 3922 | |
| 3767 | 3923 | $context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array( | 
| 3768 | 3924 | 'id' => $row['id_group'], | 
| @@ -3791,13 +3947,15 @@ discard block | ||
| 3791 | 3947 | ); | 
| 3792 | 3948 | |
| 3793 | 3949 | // No changing primary one unless you have enough groups! | 
| 3794 | - if (count($context['groups']['member']) < 2) | |
| 3795 | - $context['can_edit_primary'] = false; | |
| 3950 | +	if (count($context['groups']['member']) < 2) { | |
| 3951 | + $context['can_edit_primary'] = false; | |
| 3952 | + } | |
| 3796 | 3953 | |
| 3797 | 3954 | // In the special case that someone is requesting membership of a group, setup some special context vars. | 
| 3798 | - if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) | |
| 3799 | - $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']]; | |
| 3800 | -} | |
| 3955 | +	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) { | |
| 3956 | + $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']]; | |
| 3957 | + } | |
| 3958 | + } | |
| 3801 | 3959 | |
| 3802 | 3960 | /** | 
| 3803 | 3961 | * This function actually makes all the group changes | 
| @@ -3812,10 +3970,12 @@ discard block | ||
| 3812 | 3970 | global $user_info, $context, $user_profile, $modSettings, $smcFunc; | 
| 3813 | 3971 | |
| 3814 | 3972 | // Let's be extra cautious... | 
| 3815 | - if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) | |
| 3816 | -		isAllowedTo('manage_membergroups'); | |
| 3817 | - if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) | |
| 3818 | -		fatal_lang_error('no_access', false); | |
| 3973 | +	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) { | |
| 3974 | +			isAllowedTo('manage_membergroups'); | |
| 3975 | + } | |
| 3976 | +	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) { | |
| 3977 | +			fatal_lang_error('no_access', false); | |
| 3978 | + } | |
| 3819 | 3979 | |
| 3820 | 3980 | checkSession(isset($_GET['gid']) ? 'get' : 'post'); | 
| 3821 | 3981 | |
| @@ -3834,8 +3994,9 @@ discard block | ||
| 3834 | 3994 | $foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false; | 
| 3835 | 3995 | |
| 3836 | 3996 | // Sanity check!! | 
| 3837 | - if ($group_id == 1) | |
| 3838 | -		isAllowedTo('admin_forum'); | |
| 3997 | +	if ($group_id == 1) { | |
| 3998 | +			isAllowedTo('admin_forum'); | |
| 3999 | + } | |
| 3839 | 4000 | // Protected groups too! | 
| 3840 | 4001 | else | 
| 3841 | 4002 |  	{ | 
| @@ -3852,8 +4013,9 @@ discard block | ||
| 3852 | 4013 | list ($is_protected) = $smcFunc['db_fetch_row']($request); | 
| 3853 | 4014 | $smcFunc['db_free_result']($request); | 
| 3854 | 4015 | |
| 3855 | - if ($is_protected == 1) | |
| 3856 | -			isAllowedTo('admin_forum'); | |
| 4016 | +		if ($is_protected == 1) { | |
| 4017 | +					isAllowedTo('admin_forum'); | |
| 4018 | + } | |
| 3857 | 4019 | } | 
| 3858 | 4020 | |
| 3859 | 4021 | // What ever we are doing, we need to determine if changing primary is possible! | 
| @@ -3875,36 +4037,43 @@ discard block | ||
| 3875 | 4037 | $group_name = $row['group_name']; | 
| 3876 | 4038 | |
| 3877 | 4039 | // Does the group type match what we're doing - are we trying to request a non-requestable group? | 
| 3878 | - if ($changeType == 'request' && $row['group_type'] != 2) | |
| 3879 | -				fatal_lang_error('no_access', false); | |
| 4040 | +			if ($changeType == 'request' && $row['group_type'] != 2) { | |
| 4041 | +							fatal_lang_error('no_access', false); | |
| 4042 | + } | |
| 3880 | 4043 | // What about leaving a requestable group we are not a member of? | 
| 3881 | - elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) | |
| 3882 | -				fatal_lang_error('no_access', false); | |
| 3883 | - elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) | |
| 3884 | -				fatal_lang_error('no_access', false); | |
| 4044 | +			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) { | |
| 4045 | +							fatal_lang_error('no_access', false); | |
| 4046 | +			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) { | |
| 4047 | +							fatal_lang_error('no_access', false); | |
| 4048 | + } | |
| 3885 | 4049 | |
| 3886 | 4050 | // We can't change the primary group if this is hidden! | 
| 3887 | - if ($row['hidden'] == 2) | |
| 3888 | - $canChangePrimary = false; | |
| 4051 | +			if ($row['hidden'] == 2) { | |
| 4052 | + $canChangePrimary = false; | |
| 4053 | + } | |
| 3889 | 4054 | } | 
| 3890 | 4055 | |
| 3891 | 4056 | // If this is their old primary, can we change it? | 
| 3892 | - if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) | |
| 3893 | - $canChangePrimary = 1; | |
| 4057 | +		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) { | |
| 4058 | + $canChangePrimary = 1; | |
| 4059 | + } | |
| 3894 | 4060 | |
| 3895 | 4061 | // If we are not doing a force primary move, don't do it automatically if current primary is not 0. | 
| 3896 | - if ($changeType != 'primary' && $old_profile['id_group'] != 0) | |
| 3897 | - $canChangePrimary = false; | |
| 4062 | +		if ($changeType != 'primary' && $old_profile['id_group'] != 0) { | |
| 4063 | + $canChangePrimary = false; | |
| 4064 | + } | |
| 3898 | 4065 | |
| 3899 | 4066 | // If this is the one we are acting on, can we even act? | 
| 3900 | - if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) | |
| 3901 | - $canChangePrimary = false; | |
| 4067 | +		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) { | |
| 4068 | + $canChangePrimary = false; | |
| 4069 | + } | |
| 3902 | 4070 | } | 
| 3903 | 4071 | $smcFunc['db_free_result']($request); | 
| 3904 | 4072 | |
| 3905 | 4073 | // Didn't find the target? | 
| 3906 | - if (!$foundTarget) | |
| 3907 | -		fatal_lang_error('no_access', false); | |
| 4074 | +	if (!$foundTarget) { | |
| 4075 | +			fatal_lang_error('no_access', false); | |
| 4076 | + } | |
| 3908 | 4077 | |
| 3909 | 4078 | // Final security check, don't allow users to promote themselves to admin. | 
| 3910 | 4079 |  	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum')) | 
| @@ -3924,8 +4093,9 @@ discard block | ||
| 3924 | 4093 | list ($disallow) = $smcFunc['db_fetch_row']($request); | 
| 3925 | 4094 | $smcFunc['db_free_result']($request); | 
| 3926 | 4095 | |
| 3927 | - if ($disallow) | |
| 3928 | -			isAllowedTo('admin_forum'); | |
| 4096 | +		if ($disallow) { | |
| 4097 | +					isAllowedTo('admin_forum'); | |
| 4098 | + } | |
| 3929 | 4099 | } | 
| 3930 | 4100 | |
| 3931 | 4101 | // If we're requesting, add the note then return. | 
| @@ -3943,8 +4113,9 @@ discard block | ||
| 3943 | 4113 | 'status_open' => 0, | 
| 3944 | 4114 | ) | 
| 3945 | 4115 | ); | 
| 3946 | - if ($smcFunc['db_num_rows']($request) != 0) | |
| 3947 | -			fatal_lang_error('profile_error_already_requested_group'); | |
| 4116 | +		if ($smcFunc['db_num_rows']($request) != 0) { | |
| 4117 | +					fatal_lang_error('profile_error_already_requested_group'); | |
| 4118 | + } | |
| 3948 | 4119 | $smcFunc['db_free_result']($request); | 
| 3949 | 4120 | |
| 3950 | 4121 | // Log the request. | 
| @@ -3978,10 +4149,11 @@ discard block | ||
| 3978 | 4149 | // Are we leaving? | 
| 3979 | 4150 | if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id])) | 
| 3980 | 4151 |  		{ | 
| 3981 | - if ($old_profile['id_group'] == $group_id) | |
| 3982 | - $newPrimary = 0; | |
| 3983 | - else | |
| 3984 | - unset($addGroups[$group_id]); | |
| 4152 | +			if ($old_profile['id_group'] == $group_id) { | |
| 4153 | + $newPrimary = 0; | |
| 4154 | +			} else { | |
| 4155 | + unset($addGroups[$group_id]); | |
| 4156 | + } | |
| 3985 | 4157 | } | 
| 3986 | 4158 | // ... if not, must be joining. | 
| 3987 | 4159 | else | 
| @@ -3989,36 +4161,42 @@ discard block | ||
| 3989 | 4161 | // Can we change the primary, and do we want to? | 
| 3990 | 4162 | if ($canChangePrimary) | 
| 3991 | 4163 |  			{ | 
| 3992 | - if ($old_profile['id_group'] != 0) | |
| 3993 | - $addGroups[$old_profile['id_group']] = -1; | |
| 4164 | +				if ($old_profile['id_group'] != 0) { | |
| 4165 | + $addGroups[$old_profile['id_group']] = -1; | |
| 4166 | + } | |
| 3994 | 4167 | $newPrimary = $group_id; | 
| 3995 | 4168 | } | 
| 3996 | 4169 | // Otherwise it's an additional group... | 
| 3997 | - else | |
| 3998 | - $addGroups[$group_id] = -1; | |
| 4170 | +			else { | |
| 4171 | + $addGroups[$group_id] = -1; | |
| 4172 | + } | |
| 3999 | 4173 | } | 
| 4000 | 4174 | } | 
| 4001 | 4175 | // Finally, we must be setting the primary. | 
| 4002 | 4176 | elseif ($canChangePrimary) | 
| 4003 | 4177 |  	{ | 
| 4004 | - if ($old_profile['id_group'] != 0) | |
| 4005 | - $addGroups[$old_profile['id_group']] = -1; | |
| 4006 | - if (isset($addGroups[$group_id])) | |
| 4007 | - unset($addGroups[$group_id]); | |
| 4178 | +		if ($old_profile['id_group'] != 0) { | |
| 4179 | + $addGroups[$old_profile['id_group']] = -1; | |
| 4180 | + } | |
| 4181 | +		if (isset($addGroups[$group_id])) { | |
| 4182 | + unset($addGroups[$group_id]); | |
| 4183 | + } | |
| 4008 | 4184 | $newPrimary = $group_id; | 
| 4009 | 4185 | } | 
| 4010 | 4186 | |
| 4011 | 4187 | // Finally, we can make the changes! | 
| 4012 | - foreach ($addGroups as $id => $dummy) | |
| 4013 | - if (empty($id)) | |
| 4188 | +	foreach ($addGroups as $id => $dummy) { | |
| 4189 | + if (empty($id)) | |
| 4014 | 4190 | unset($addGroups[$id]); | 
| 4191 | + } | |
| 4015 | 4192 |  	$addGroups = implode(',', array_flip($addGroups)); | 
| 4016 | 4193 | |
| 4017 | 4194 | // Ensure that we don't cache permissions if the group is changing. | 
| 4018 | - if ($context['user']['is_owner']) | |
| 4019 | - $_SESSION['mc']['time'] = 0; | |
| 4020 | - else | |
| 4021 | -		updateSettings(array('settings_updated' => time())); | |
| 4195 | +	if ($context['user']['is_owner']) { | |
| 4196 | + $_SESSION['mc']['time'] = 0; | |
| 4197 | +	} else { | |
| 4198 | +			updateSettings(array('settings_updated' => time())); | |
| 4199 | + } | |
| 4022 | 4200 | |
| 4023 | 4201 |  	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups)); | 
| 4024 | 4202 | |
| @@ -4041,8 +4219,9 @@ discard block | ||
| 4041 | 4219 | if (empty($user_settings['tfa_secret']) && $context['user']['is_owner']) | 
| 4042 | 4220 |  	{ | 
| 4043 | 4221 | // Check to ensure we're forcing SSL for authentication | 
| 4044 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) | |
| 4045 | -			fatal_lang_error('login_ssl_required'); | |
| 4222 | +		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { | |
| 4223 | +					fatal_lang_error('login_ssl_required'); | |
| 4224 | + } | |
| 4046 | 4225 | |
| 4047 | 4226 | // In some cases (forced 2FA or backup code) they would be forced to be redirected here, | 
| 4048 | 4227 | // we do not want too much AJAX to confuse them. | 
| @@ -4079,8 +4258,7 @@ discard block | ||
| 4079 | 4258 | $context['sub_template'] = 'tfasetup_backup'; | 
| 4080 | 4259 | |
| 4081 | 4260 | return; | 
| 4082 | - } | |
| 4083 | - else | |
| 4261 | + } else | |
| 4084 | 4262 |  			{ | 
| 4085 | 4263 | $context['tfa_secret'] = $_SESSION['tfa_secret']; | 
| 4086 | 4264 | $context['tfa_error'] = !$valid_code; | 
| @@ -4088,8 +4266,7 @@ discard block | ||
| 4088 | 4266 | $context['tfa_pass_value'] = $_POST['passwd']; | 
| 4089 | 4267 | $context['tfa_value'] = $_POST['tfa_code']; | 
| 4090 | 4268 | } | 
| 4091 | - } | |
| 4092 | - else | |
| 4269 | + } else | |
| 4093 | 4270 |  		{ | 
| 4094 | 4271 | $totp = new \TOTP\Auth(); | 
| 4095 | 4272 | $secret = $totp->generateCode(); | 
| @@ -4099,17 +4276,16 @@ discard block | ||
| 4099 | 4276 | } | 
| 4100 | 4277 | |
| 4101 | 4278 | $context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']); | 
| 4102 | - } | |
| 4103 | - elseif (isset($_REQUEST['disable'])) | |
| 4279 | + } elseif (isset($_REQUEST['disable'])) | |
| 4104 | 4280 |  	{ | 
| 4105 | 4281 | updateMemberData($memID, array( | 
| 4106 | 4282 | 'tfa_secret' => '', | 
| 4107 | 4283 | 'tfa_backup' => '', | 
| 4108 | 4284 | )); | 
| 4109 | 4285 |  		redirectexit('action=profile;area=account;u=' . $memID); | 
| 4286 | +	} else { | |
| 4287 | +			redirectexit('action=profile;area=account;u=' . $memID); | |
| 4288 | + } | |
| 4110 | 4289 | } | 
| 4111 | - else | |
| 4112 | -		redirectexit('action=profile;area=account;u=' . $memID); | |
| 4113 | -} | |
| 4114 | 4290 | |
| 4115 | 4291 | ?> | 
| 4116 | 4292 | \ No newline at end of file |