@@ -18,8 +18,9 @@ discard block |
||
18 | 18 | * @version 2.1 Beta 4 |
19 | 19 | */ |
20 | 20 | |
21 | -if (!defined('SMF')) |
|
21 | +if (!defined('SMF')) { |
|
22 | 22 | die('No direct access...'); |
23 | +} |
|
23 | 24 | |
24 | 25 | /** |
25 | 26 | * downloads a file from a url and stores it locally for avatar use by id_member. |
@@ -44,8 +45,9 @@ discard block |
||
44 | 45 | $destName = 'avatar_' . $memID . '_' . time() . '.' . $ext; |
45 | 46 | |
46 | 47 | // Just making sure there is a non-zero member. |
47 | - if (empty($memID)) |
|
48 | - return false; |
|
48 | + if (empty($memID)) { |
|
49 | + return false; |
|
50 | + } |
|
49 | 51 | |
50 | 52 | require_once($sourcedir . '/ManageAttachments.php'); |
51 | 53 | removeAttachments(array('id_member' => $memID)); |
@@ -76,10 +78,11 @@ discard block |
||
76 | 78 | $destName = $modSettings['custom_avatar_dir'] . '/' . $destName . '.tmp'; |
77 | 79 | |
78 | 80 | // Resize it. |
79 | - if (!empty($modSettings['avatar_download_png'])) |
|
80 | - $success = resizeImageFile($url, $destName, $max_width, $max_height, 3); |
|
81 | - else |
|
82 | - $success = resizeImageFile($url, $destName, $max_width, $max_height); |
|
81 | + if (!empty($modSettings['avatar_download_png'])) { |
|
82 | + $success = resizeImageFile($url, $destName, $max_width, $max_height, 3); |
|
83 | + } else { |
|
84 | + $success = resizeImageFile($url, $destName, $max_width, $max_height); |
|
85 | + } |
|
83 | 86 | |
84 | 87 | // Remove the .tmp extension. |
85 | 88 | $destName = substr($destName, 0, -4); |
@@ -108,11 +111,10 @@ discard block |
||
108 | 111 | ) |
109 | 112 | ); |
110 | 113 | return true; |
114 | + } else { |
|
115 | + return false; |
|
111 | 116 | } |
112 | - else |
|
113 | - return false; |
|
114 | - } |
|
115 | - else |
|
117 | + } else |
|
116 | 118 | { |
117 | 119 | $smcFunc['db_query']('', ' |
118 | 120 | DELETE FROM {db_prefix}attachments |
@@ -144,17 +146,18 @@ discard block |
||
144 | 146 | $destName = $source . '_thumb.tmp'; |
145 | 147 | |
146 | 148 | // Do the actual resize. |
147 | - if (!empty($modSettings['attachment_thumb_png'])) |
|
148 | - $success = resizeImageFile($source, $destName, $max_width, $max_height, 3); |
|
149 | - else |
|
150 | - $success = resizeImageFile($source, $destName, $max_width, $max_height); |
|
149 | + if (!empty($modSettings['attachment_thumb_png'])) { |
|
150 | + $success = resizeImageFile($source, $destName, $max_width, $max_height, 3); |
|
151 | + } else { |
|
152 | + $success = resizeImageFile($source, $destName, $max_width, $max_height); |
|
153 | + } |
|
151 | 154 | |
152 | 155 | // Okay, we're done with the temporary stuff. |
153 | 156 | $destName = substr($destName, 0, -4); |
154 | 157 | |
155 | - if ($success && @rename($destName . '.tmp', $destName)) |
|
156 | - return true; |
|
157 | - else |
|
158 | + if ($success && @rename($destName . '.tmp', $destName)) { |
|
159 | + return true; |
|
160 | + } else |
|
158 | 161 | { |
159 | 162 | @unlink($destName . '.tmp'); |
160 | 163 | @touch($destName); |
@@ -176,18 +179,21 @@ discard block |
||
176 | 179 | { |
177 | 180 | if (!resizeImageFile($fileName, $fileName . '.tmp', null, null, $preferred_format)) |
178 | 181 | { |
179 | - if (file_exists($fileName . '.tmp')) |
|
180 | - unlink($fileName . '.tmp'); |
|
182 | + if (file_exists($fileName . '.tmp')) { |
|
183 | + unlink($fileName . '.tmp'); |
|
184 | + } |
|
181 | 185 | |
182 | 186 | return false; |
183 | 187 | } |
184 | 188 | |
185 | - if (!unlink($fileName)) |
|
186 | - return false; |
|
189 | + if (!unlink($fileName)) { |
|
190 | + return false; |
|
191 | + } |
|
187 | 192 | |
188 | - if (!rename($fileName . '.tmp', $fileName)) |
|
189 | - return false; |
|
190 | -} |
|
193 | + if (!rename($fileName . '.tmp', $fileName)) { |
|
194 | + return false; |
|
195 | + } |
|
196 | + } |
|
191 | 197 | |
192 | 198 | /** |
193 | 199 | * Searches through the file to see if there's potentially harmful non-binary content. |
@@ -200,8 +206,9 @@ discard block |
||
200 | 206 | function checkImageContents($fileName, $extensiveCheck = false) |
201 | 207 | { |
202 | 208 | $fp = fopen($fileName, 'rb'); |
203 | - if (!$fp) |
|
204 | - fatal_lang_error('attach_timeout'); |
|
209 | + if (!$fp) { |
|
210 | + fatal_lang_error('attach_timeout'); |
|
211 | + } |
|
205 | 212 | |
206 | 213 | $prev_chunk = ''; |
207 | 214 | while (!feof($fp)) |
@@ -218,8 +225,7 @@ discard block |
||
218 | 225 | fclose($fp); |
219 | 226 | return false; |
220 | 227 | } |
221 | - } |
|
222 | - else |
|
228 | + } else |
|
223 | 229 | { |
224 | 230 | // Check for potential infection - focus on clues for inline php & flash. |
225 | 231 | // Will result in significantly fewer false positives than the paranoid check. |
@@ -247,8 +253,9 @@ discard block |
||
247 | 253 | global $gd2; |
248 | 254 | |
249 | 255 | // Check to see if GD is installed and what version. |
250 | - if (($extensionFunctions = get_extension_funcs('gd')) === false) |
|
251 | - return false; |
|
256 | + if (($extensionFunctions = get_extension_funcs('gd')) === false) { |
|
257 | + return false; |
|
258 | + } |
|
252 | 259 | |
253 | 260 | // Also determine if GD2 is installed and store it in a global. |
254 | 261 | $gd2 = in_array('imagecreatetruecolor', $extensionFunctions) && function_exists('imagecreatetruecolor'); |
@@ -320,8 +327,9 @@ discard block |
||
320 | 327 | global $sourcedir; |
321 | 328 | |
322 | 329 | // Nothing to do without GD or IM/MW |
323 | - if (!checkGD() && !checkImagick() && !checkMagickWand()) |
|
324 | - return false; |
|
330 | + if (!checkGD() && !checkImagick() && !checkMagickWand()) { |
|
331 | + return false; |
|
332 | + } |
|
325 | 333 | |
326 | 334 | static $default_formats = array( |
327 | 335 | '1' => 'gif', |
@@ -341,38 +349,39 @@ discard block |
||
341 | 349 | fclose($fp_destination); |
342 | 350 | |
343 | 351 | $sizes = @getimagesize($destination); |
344 | - } |
|
345 | - elseif ($fp_destination) |
|
352 | + } elseif ($fp_destination) |
|
346 | 353 | { |
347 | 354 | $sizes = @getimagesize($source); |
348 | 355 | |
349 | 356 | $fp_source = fopen($source, 'rb'); |
350 | 357 | if ($fp_source !== false) |
351 | 358 | { |
352 | - while (!feof($fp_source)) |
|
353 | - fwrite($fp_destination, fread($fp_source, 8192)); |
|
359 | + while (!feof($fp_source)) { |
|
360 | + fwrite($fp_destination, fread($fp_source, 8192)); |
|
361 | + } |
|
354 | 362 | fclose($fp_source); |
363 | + } else { |
|
364 | + $sizes = array(-1, -1, -1); |
|
355 | 365 | } |
356 | - else |
|
357 | - $sizes = array(-1, -1, -1); |
|
358 | 366 | fclose($fp_destination); |
359 | 367 | } |
360 | 368 | // We can't get to the file. |
361 | - else |
|
362 | - $sizes = array(-1, -1, -1); |
|
369 | + else { |
|
370 | + $sizes = array(-1, -1, -1); |
|
371 | + } |
|
363 | 372 | |
364 | 373 | // See if we have -or- can get the needed memory for this operation |
365 | 374 | // ImageMagick isn't subject to PHP's memory limits :) |
366 | - if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) |
|
367 | - return false; |
|
375 | + if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) { |
|
376 | + return false; |
|
377 | + } |
|
368 | 378 | |
369 | 379 | // A known and supported format? |
370 | 380 | // @todo test PSD and gif. |
371 | 381 | if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]])) |
372 | 382 | { |
373 | 383 | return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format); |
374 | - } |
|
375 | - elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) |
|
384 | + } elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) |
|
376 | 385 | { |
377 | 386 | $imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]]; |
378 | 387 | if ($src_img = @$imagecreatefrom($destination)) |
@@ -425,14 +434,14 @@ discard block |
||
425 | 434 | $dest_width = empty($max_width) ? $src_width : $max_width; |
426 | 435 | $dest_height = empty($max_height) ? $src_height : $max_height; |
427 | 436 | |
428 | - if ($default_formats[$preferred_format] == 'jpeg') |
|
429 | - $imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
437 | + if ($default_formats[$preferred_format] == 'jpeg') { |
|
438 | + $imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
439 | + } |
|
430 | 440 | |
431 | 441 | $imagick->setImageFormat($default_formats[$preferred_format]); |
432 | 442 | $imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true); |
433 | 443 | $success = $imagick->writeImage($destName); |
434 | - } |
|
435 | - else |
|
444 | + } else |
|
436 | 445 | { |
437 | 446 | $magick_wand = newMagickWand(); |
438 | 447 | MagickReadImage($magick_wand, $destName); |
@@ -441,8 +450,9 @@ discard block |
||
441 | 450 | $dest_width = empty($max_width) ? $src_width : $max_width; |
442 | 451 | $dest_height = empty($max_height) ? $src_height : $max_height; |
443 | 452 | |
444 | - if ($default_formats[$preferred_format] == 'jpeg') |
|
445 | - MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
453 | + if ($default_formats[$preferred_format] == 'jpeg') { |
|
454 | + MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
455 | + } |
|
446 | 456 | |
447 | 457 | MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]); |
448 | 458 | MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true); |
@@ -450,8 +460,7 @@ discard block |
||
450 | 460 | } |
451 | 461 | |
452 | 462 | return !empty($success); |
453 | - } |
|
454 | - elseif (checkGD()) |
|
463 | + } elseif (checkGD()) |
|
455 | 464 | { |
456 | 465 | $success = false; |
457 | 466 | |
@@ -462,8 +471,7 @@ discard block |
||
462 | 471 | { |
463 | 472 | $dst_width = $max_width; |
464 | 473 | $dst_height = round($src_height * $max_width / $src_width); |
465 | - } |
|
466 | - elseif (!empty($max_height)) |
|
474 | + } elseif (!empty($max_height)) |
|
467 | 475 | { |
468 | 476 | $dst_width = round($src_width * $max_height / $src_height); |
469 | 477 | $dst_height = $max_height; |
@@ -481,44 +489,48 @@ discard block |
||
481 | 489 | if ((!empty($preferred_format)) && ($preferred_format == 3)) |
482 | 490 | { |
483 | 491 | imagealphablending($dst_img, false); |
484 | - if (function_exists('imagesavealpha')) |
|
485 | - imagesavealpha($dst_img, true); |
|
492 | + if (function_exists('imagesavealpha')) { |
|
493 | + imagesavealpha($dst_img, true); |
|
494 | + } |
|
486 | 495 | } |
496 | + } else { |
|
497 | + $dst_img = imagecreate($dst_width, $dst_height); |
|
487 | 498 | } |
488 | - else |
|
489 | - $dst_img = imagecreate($dst_width, $dst_height); |
|
490 | 499 | |
491 | 500 | // Resize it! |
492 | - if ($gd2) |
|
493 | - imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
494 | - else |
|
495 | - imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
501 | + if ($gd2) { |
|
502 | + imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
503 | + } else { |
|
504 | + imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
505 | + } |
|
506 | + } else { |
|
507 | + $dst_img = $src_img; |
|
496 | 508 | } |
497 | - else |
|
498 | - $dst_img = $src_img; |
|
509 | + } else { |
|
510 | + $dst_img = $src_img; |
|
499 | 511 | } |
500 | - else |
|
501 | - $dst_img = $src_img; |
|
502 | 512 | |
503 | 513 | // Save the image as ... |
504 | - if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) |
|
505 | - $success = imagepng($dst_img, $destName); |
|
506 | - elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) |
|
507 | - $success = imagegif($dst_img, $destName); |
|
508 | - elseif (function_exists('imagejpeg')) |
|
509 | - $success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
514 | + if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) { |
|
515 | + $success = imagepng($dst_img, $destName); |
|
516 | + } elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) { |
|
517 | + $success = imagegif($dst_img, $destName); |
|
518 | + } elseif (function_exists('imagejpeg')) { |
|
519 | + $success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
520 | + } |
|
510 | 521 | |
511 | 522 | // Free the memory. |
512 | 523 | imagedestroy($src_img); |
513 | - if ($dst_img != $src_img) |
|
514 | - imagedestroy($dst_img); |
|
524 | + if ($dst_img != $src_img) { |
|
525 | + imagedestroy($dst_img); |
|
526 | + } |
|
515 | 527 | |
516 | 528 | return $success; |
517 | - } |
|
518 | - else |
|
519 | - // Without GD, no image resizing at all. |
|
529 | + } else { |
|
530 | + // Without GD, no image resizing at all. |
|
520 | 531 | return false; |
521 | -} |
|
532 | + } |
|
533 | + } |
|
522 | 534 | |
523 | 535 | /** |
524 | 536 | * Copy image. |
@@ -572,8 +584,9 @@ discard block |
||
572 | 584 | $color = imagecolorresolve($dst_img, $red, $green, $blue); |
573 | 585 | if ($color == -1) |
574 | 586 | { |
575 | - if ($palsize++ < 256) |
|
576 | - imagecolorallocate($dst_img, $red, $green, $blue); |
|
587 | + if ($palsize++ < 256) { |
|
588 | + imagecolorallocate($dst_img, $red, $green, $blue); |
|
589 | + } |
|
577 | 590 | $color = imagecolorclosest($dst_img, $red, $green, $blue); |
578 | 591 | } |
579 | 592 | |
@@ -603,13 +616,15 @@ discard block |
||
603 | 616 | $header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14)); |
604 | 617 | $info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40)); |
605 | 618 | |
606 | - if ($header['type'] != 0x4D42) |
|
607 | - return false; |
|
619 | + if ($header['type'] != 0x4D42) { |
|
620 | + return false; |
|
621 | + } |
|
608 | 622 | |
609 | - if ($gd2) |
|
610 | - $dst_img = imagecreatetruecolor($info['width'], $info['height']); |
|
611 | - else |
|
612 | - $dst_img = imagecreate($info['width'], $info['height']); |
|
623 | + if ($gd2) { |
|
624 | + $dst_img = imagecreatetruecolor($info['width'], $info['height']); |
|
625 | + } else { |
|
626 | + $dst_img = imagecreate($info['width'], $info['height']); |
|
627 | + } |
|
613 | 628 | |
614 | 629 | $palette_size = $header['offset'] - 54; |
615 | 630 | $info['ncolor'] = $palette_size / 4; |
@@ -635,8 +650,9 @@ discard block |
||
635 | 650 | fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l); |
636 | 651 | $scan_line = fread($fp, $scan_line_size); |
637 | 652 | |
638 | - if (strlen($scan_line) < $scan_line_size) |
|
639 | - continue; |
|
653 | + if (strlen($scan_line) < $scan_line_size) { |
|
654 | + continue; |
|
655 | + } |
|
640 | 656 | |
641 | 657 | if ($info['bits'] == 32) |
642 | 658 | { |
@@ -654,14 +670,14 @@ discard block |
||
654 | 670 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
655 | 671 | |
656 | 672 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
657 | - if ($color == -1) |
|
658 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
673 | + if ($color == -1) { |
|
674 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
675 | + } |
|
659 | 676 | } |
660 | 677 | |
661 | 678 | imagesetpixel($dst_img, $x, $y, $color); |
662 | 679 | } |
663 | - } |
|
664 | - elseif ($info['bits'] == 24) |
|
680 | + } elseif ($info['bits'] == 24) |
|
665 | 681 | { |
666 | 682 | $x = 0; |
667 | 683 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -676,14 +692,14 @@ discard block |
||
676 | 692 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
677 | 693 | |
678 | 694 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
679 | - if ($color == -1) |
|
680 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
695 | + if ($color == -1) { |
|
696 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
697 | + } |
|
681 | 698 | } |
682 | 699 | |
683 | 700 | imagesetpixel($dst_img, $x, $y, $color); |
684 | 701 | } |
685 | - } |
|
686 | - elseif ($info['bits'] == 16) |
|
702 | + } elseif ($info['bits'] == 16) |
|
687 | 703 | { |
688 | 704 | $x = 0; |
689 | 705 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -704,20 +720,20 @@ discard block |
||
704 | 720 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
705 | 721 | |
706 | 722 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
707 | - if ($color == -1) |
|
708 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
723 | + if ($color == -1) { |
|
724 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
725 | + } |
|
709 | 726 | } |
710 | 727 | |
711 | 728 | imagesetpixel($dst_img, $x, $y, $color); |
712 | 729 | } |
713 | - } |
|
714 | - elseif ($info['bits'] == 8) |
|
730 | + } elseif ($info['bits'] == 8) |
|
715 | 731 | { |
716 | 732 | $x = 0; |
717 | - for ($j = 0; $j < $scan_line_size; $x++) |
|
718 | - imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]); |
|
719 | - } |
|
720 | - elseif ($info['bits'] == 4) |
|
733 | + for ($j = 0; $j < $scan_line_size; $x++) { |
|
734 | + imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]); |
|
735 | + } |
|
736 | + } elseif ($info['bits'] == 4) |
|
721 | 737 | { |
722 | 738 | $x = 0; |
723 | 739 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -726,11 +742,11 @@ discard block |
||
726 | 742 | |
727 | 743 | imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]); |
728 | 744 | |
729 | - if (++$x < $info['width']) |
|
730 | - imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]); |
|
745 | + if (++$x < $info['width']) { |
|
746 | + imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]); |
|
747 | + } |
|
731 | 748 | } |
732 | - } |
|
733 | - elseif ($info['bits'] == 1) |
|
749 | + } elseif ($info['bits'] == 1) |
|
734 | 750 | { |
735 | 751 | $x = 0; |
736 | 752 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -741,8 +757,9 @@ discard block |
||
741 | 757 | |
742 | 758 | for ($shift = 1; $shift < 8; $shift++) |
743 | 759 | { |
744 | - if (++$x < $info['width']) |
|
745 | - imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]); |
|
760 | + if (++$x < $info['width']) { |
|
761 | + imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]); |
|
762 | + } |
|
746 | 763 | } |
747 | 764 | } |
748 | 765 | } |
@@ -766,15 +783,18 @@ discard block |
||
766 | 783 | */ |
767 | 784 | function gif_outputAsPng($gif, $lpszFileName, $background_color = -1) |
768 | 785 | { |
769 | - if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') |
|
770 | - return false; |
|
786 | + if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') { |
|
787 | + return false; |
|
788 | + } |
|
771 | 789 | |
772 | 790 | $fd = $gif->get_png_data($background_color); |
773 | - if (strlen($fd) <= 0) |
|
774 | - return false; |
|
791 | + if (strlen($fd) <= 0) { |
|
792 | + return false; |
|
793 | + } |
|
775 | 794 | |
776 | - if (!($fh = @fopen($lpszFileName, 'wb'))) |
|
777 | - return false; |
|
795 | + if (!($fh = @fopen($lpszFileName, 'wb'))) { |
|
796 | + return false; |
|
797 | + } |
|
778 | 798 | |
779 | 799 | @fwrite($fh, $fd, strlen($fd)); |
780 | 800 | @fflush($fh); |
@@ -801,8 +821,9 @@ discard block |
||
801 | 821 | // What type are we going to be doing? |
802 | 822 | $imageType = $modSettings['visual_verification_type']; |
803 | 823 | // Special case to allow the admin center to show samples. |
804 | - if ($user_info['is_admin'] && isset($_GET['type'])) |
|
805 | - $imageType = (int) $_GET['type']; |
|
824 | + if ($user_info['is_admin'] && isset($_GET['type'])) { |
|
825 | + $imageType = (int) $_GET['type']; |
|
826 | + } |
|
806 | 827 | |
807 | 828 | // Some quick references for what we do. |
808 | 829 | // Do we show no, low or high noise? |
@@ -836,25 +857,28 @@ discard block |
||
836 | 857 | $character_spacing = 1; |
837 | 858 | |
838 | 859 | // What color is the background - generally white unless we're on "hard". |
839 | - if ($simpleBGColor) |
|
840 | - $background_color = array(255, 255, 255); |
|
841 | - else |
|
842 | - $background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243); |
|
860 | + if ($simpleBGColor) { |
|
861 | + $background_color = array(255, 255, 255); |
|
862 | + } else { |
|
863 | + $background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243); |
|
864 | + } |
|
843 | 865 | |
844 | 866 | // The color of the characters shown (red, green, blue). |
845 | - if ($simpleFGColor) |
|
846 | - $foreground_color = array(0, 0, 0); |
|
847 | - else |
|
867 | + if ($simpleFGColor) { |
|
868 | + $foreground_color = array(0, 0, 0); |
|
869 | + } else |
|
848 | 870 | { |
849 | 871 | $foreground_color = array(64, 101, 136); |
850 | 872 | |
851 | 873 | // Has the theme author requested a custom color? |
852 | - if (isset($settings['verification_foreground'])) |
|
853 | - $foreground_color = $settings['verification_foreground']; |
|
874 | + if (isset($settings['verification_foreground'])) { |
|
875 | + $foreground_color = $settings['verification_foreground']; |
|
876 | + } |
|
854 | 877 | } |
855 | 878 | |
856 | - if (!is_dir($settings['default_theme_dir'] . '/fonts')) |
|
857 | - return false; |
|
879 | + if (!is_dir($settings['default_theme_dir'] . '/fonts')) { |
|
880 | + return false; |
|
881 | + } |
|
858 | 882 | |
859 | 883 | // Get a list of the available fonts. |
860 | 884 | $font_dir = dir($settings['default_theme_dir'] . '/fonts'); |
@@ -865,25 +889,28 @@ discard block |
||
865 | 889 | { |
866 | 890 | if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1) |
867 | 891 | { |
868 | - if ($endian ^ (strpos($entry, '_end.gdf') === false)) |
|
869 | - $font_list[] = $entry; |
|
892 | + if ($endian ^ (strpos($entry, '_end.gdf') === false)) { |
|
893 | + $font_list[] = $entry; |
|
894 | + } |
|
895 | + } elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) { |
|
896 | + $ttfont_list[] = $entry; |
|
870 | 897 | } |
871 | - elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) |
|
872 | - $ttfont_list[] = $entry; |
|
873 | 898 | } |
874 | 899 | |
875 | - if (empty($font_list)) |
|
876 | - return false; |
|
900 | + if (empty($font_list)) { |
|
901 | + return false; |
|
902 | + } |
|
877 | 903 | |
878 | 904 | // For non-hard things don't even change fonts. |
879 | 905 | if (!$varyFonts) |
880 | 906 | { |
881 | 907 | $font_list = array($font_list[0]); |
882 | 908 | // Try use Screenge if we can - it looks good! |
883 | - if (in_array('AnonymousPro.ttf', $ttfont_list)) |
|
884 | - $ttfont_list = array('AnonymousPro.ttf'); |
|
885 | - else |
|
886 | - $ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]); |
|
909 | + if (in_array('AnonymousPro.ttf', $ttfont_list)) { |
|
910 | + $ttfont_list = array('AnonymousPro.ttf'); |
|
911 | + } else { |
|
912 | + $ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]); |
|
913 | + } |
|
887 | 914 | } |
888 | 915 | |
889 | 916 | // Create a list of characters to be shown. |
@@ -900,14 +927,16 @@ discard block |
||
900 | 927 | } |
901 | 928 | |
902 | 929 | // Load all fonts and determine the maximum font height. |
903 | - foreach ($loaded_fonts as $font_index => $dummy) |
|
904 | - $loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]); |
|
930 | + foreach ($loaded_fonts as $font_index => $dummy) { |
|
931 | + $loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]); |
|
932 | + } |
|
905 | 933 | |
906 | 934 | // Determine the dimensions of each character. |
907 | - if ($imageType == 4 || $imageType == 5) |
|
908 | - $extra = 80; |
|
909 | - else |
|
910 | - $extra = 45; |
|
935 | + if ($imageType == 4 || $imageType == 5) { |
|
936 | + $extra = 80; |
|
937 | + } else { |
|
938 | + $extra = 45; |
|
939 | + } |
|
911 | 940 | |
912 | 941 | $total_width = $character_spacing * strlen($code) + $extra; |
913 | 942 | $max_height = 0; |
@@ -928,13 +957,15 @@ discard block |
||
928 | 957 | imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color); |
929 | 958 | |
930 | 959 | // Randomize the foreground color a little. |
931 | - for ($i = 0; $i < 3; $i++) |
|
932 | - $foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255)); |
|
960 | + for ($i = 0; $i < 3; $i++) { |
|
961 | + $foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255)); |
|
962 | + } |
|
933 | 963 | $fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]); |
934 | 964 | |
935 | 965 | // Color for the dots. |
936 | - for ($i = 0; $i < 3; $i++) |
|
937 | - $dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255); |
|
966 | + for ($i = 0; $i < 3; $i++) { |
|
967 | + $dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255); |
|
968 | + } |
|
938 | 969 | $randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]); |
939 | 970 | |
940 | 971 | // Some squares/rectanges for new extreme level |
@@ -960,10 +991,11 @@ discard block |
||
960 | 991 | $can_do_ttf = function_exists('imagettftext'); |
961 | 992 | |
962 | 993 | // How much rotation will we give? |
963 | - if ($rotationType == 'none') |
|
964 | - $angle = 0; |
|
965 | - else |
|
966 | - $angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10); |
|
994 | + if ($rotationType == 'none') { |
|
995 | + $angle = 0; |
|
996 | + } else { |
|
997 | + $angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10); |
|
998 | + } |
|
967 | 999 | |
968 | 1000 | // What color shall we do it? |
969 | 1001 | if ($fontColorType == 'cyclic') |
@@ -977,51 +1009,56 @@ discard block |
||
977 | 1009 | array(0, 0, 0), |
978 | 1010 | array(143, 39, 31), |
979 | 1011 | ); |
980 | - if (!isset($last_index)) |
|
981 | - $last_index = -1; |
|
1012 | + if (!isset($last_index)) { |
|
1013 | + $last_index = -1; |
|
1014 | + } |
|
982 | 1015 | $new_index = $last_index; |
983 | - while ($last_index == $new_index) |
|
984 | - $new_index = mt_rand(0, count($colors) - 1); |
|
1016 | + while ($last_index == $new_index) { |
|
1017 | + $new_index = mt_rand(0, count($colors) - 1); |
|
1018 | + } |
|
985 | 1019 | $char_fg_color = $colors[$new_index]; |
986 | 1020 | $last_index = $new_index; |
1021 | + } elseif ($fontColorType == 'random') { |
|
1022 | + $char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2])); |
|
1023 | + } else { |
|
1024 | + $char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]); |
|
987 | 1025 | } |
988 | - elseif ($fontColorType == 'random') |
|
989 | - $char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2])); |
|
990 | - else |
|
991 | - $char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]); |
|
992 | 1026 | |
993 | 1027 | if (!empty($can_do_ttf)) |
994 | 1028 | { |
995 | 1029 | // GD2 handles font size differently. |
996 | - if ($fontSizeRandom) |
|
997 | - $font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25); |
|
998 | - else |
|
999 | - $font_size = $gd2 ? 18 : 24; |
|
1030 | + if ($fontSizeRandom) { |
|
1031 | + $font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25); |
|
1032 | + } else { |
|
1033 | + $font_size = $gd2 ? 18 : 24; |
|
1034 | + } |
|
1000 | 1035 | |
1001 | 1036 | // Work out the sizes - also fix the character width cause TTF not quite so wide! |
1002 | 1037 | $font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5; |
1003 | 1038 | $font_y = $max_height - ($fontVerPos == 'vrandom' ? mt_rand(2, 8) : ($fontVerPos == 'random' ? mt_rand(3, 5) : 5)); |
1004 | 1039 | |
1005 | 1040 | // What font face? |
1006 | - if (!empty($ttfont_list)) |
|
1007 | - $fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)]; |
|
1041 | + if (!empty($ttfont_list)) { |
|
1042 | + $fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)]; |
|
1043 | + } |
|
1008 | 1044 | |
1009 | 1045 | // What color are we to do it in? |
1010 | 1046 | $is_reverse = $showReverseChars ? mt_rand(0, 1) : false; |
1011 | 1047 | $char_color = function_exists('imagecolorallocatealpha') && $fontTrans ? imagecolorallocatealpha($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2], 50) : imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]); |
1012 | 1048 | |
1013 | 1049 | $fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']); |
1014 | - if (empty($fontcord)) |
|
1015 | - $can_do_ttf = false; |
|
1016 | - elseif ($is_reverse) |
|
1050 | + if (empty($fontcord)) { |
|
1051 | + $can_do_ttf = false; |
|
1052 | + } elseif ($is_reverse) |
|
1017 | 1053 | { |
1018 | 1054 | imagefilledpolygon($code_image, $fontcord, 4, $fg_color); |
1019 | 1055 | // Put the character back! |
1020 | 1056 | imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']); |
1021 | 1057 | } |
1022 | 1058 | |
1023 | - if ($can_do_ttf) |
|
1024 | - $cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3); |
|
1059 | + if ($can_do_ttf) { |
|
1060 | + $cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3); |
|
1061 | + } |
|
1025 | 1062 | } |
1026 | 1063 | |
1027 | 1064 | if (!$can_do_ttf) |
@@ -1040,8 +1077,9 @@ discard block |
||
1040 | 1077 | } |
1041 | 1078 | |
1042 | 1079 | // Sorry, no rotation available. |
1043 | - else |
|
1044 | - imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2])); |
|
1080 | + else { |
|
1081 | + imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2])); |
|
1082 | + } |
|
1045 | 1083 | $cur_x += $character['width'] + $character_spacing; |
1046 | 1084 | } |
1047 | 1085 | } |
@@ -1054,17 +1092,22 @@ discard block |
||
1054 | 1092 | } |
1055 | 1093 | |
1056 | 1094 | // Make the background color transparent on the hard image. |
1057 | - if (!$simpleBGColor) |
|
1058 | - imagecolortransparent($code_image, $bg_color); |
|
1059 | - if ($hasBorder) |
|
1060 | - imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color); |
|
1095 | + if (!$simpleBGColor) { |
|
1096 | + imagecolortransparent($code_image, $bg_color); |
|
1097 | + } |
|
1098 | + if ($hasBorder) { |
|
1099 | + imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color); |
|
1100 | + } |
|
1061 | 1101 | |
1062 | 1102 | // Add some noise to the background? |
1063 | 1103 | if ($noiseType != 'none') |
1064 | 1104 | { |
1065 | - for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2)) |
|
1066 | - for ($j = mt_rand(0, 10); $j < $total_width; $j += mt_rand(1, 10)) |
|
1067 | - imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color); |
|
1105 | + for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2)) { |
|
1106 | + for ($j = mt_rand(0, 10); |
|
1107 | + } |
|
1108 | + $j < $total_width; $j += mt_rand(1, 10)) { |
|
1109 | + imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color); |
|
1110 | + } |
|
1068 | 1111 | |
1069 | 1112 | // Put in some lines too? |
1070 | 1113 | if ($noiseType != 'extreme') |
@@ -1077,8 +1120,7 @@ discard block |
||
1077 | 1120 | $x1 = mt_rand(0, $total_width); |
1078 | 1121 | $x2 = mt_rand(0, $total_width); |
1079 | 1122 | $y1 = 0; $y2 = $max_height; |
1080 | - } |
|
1081 | - else |
|
1123 | + } else |
|
1082 | 1124 | { |
1083 | 1125 | $y1 = mt_rand(0, $max_height); |
1084 | 1126 | $y2 = mt_rand(0, $max_height); |
@@ -1087,8 +1129,7 @@ discard block |
||
1087 | 1129 | imagesetthickness($code_image, mt_rand(1, 2)); |
1088 | 1130 | imageline($code_image, $x1, $y1, $x2, $y2, mt_rand(0, 1) ? $fg_color : $randomness_color); |
1089 | 1131 | } |
1090 | - } |
|
1091 | - else |
|
1132 | + } else |
|
1092 | 1133 | { |
1093 | 1134 | // Put in some ellipse |
1094 | 1135 | $num_ellipse = $noiseType == 'extreme' ? mt_rand(6, 12) : mt_rand(2, 6); |
@@ -1108,8 +1149,7 @@ discard block |
||
1108 | 1149 | { |
1109 | 1150 | header('content-type: image/gif'); |
1110 | 1151 | imagegif($code_image); |
1111 | - } |
|
1112 | - else |
|
1152 | + } else |
|
1113 | 1153 | { |
1114 | 1154 | header('content-type: image/png'); |
1115 | 1155 | imagepng($code_image); |
@@ -1132,25 +1172,29 @@ discard block |
||
1132 | 1172 | { |
1133 | 1173 | global $settings; |
1134 | 1174 | |
1135 | - if (!is_dir($settings['default_theme_dir'] . '/fonts')) |
|
1136 | - return false; |
|
1175 | + if (!is_dir($settings['default_theme_dir'] . '/fonts')) { |
|
1176 | + return false; |
|
1177 | + } |
|
1137 | 1178 | |
1138 | 1179 | // Get a list of the available font directories. |
1139 | 1180 | $font_dir = dir($settings['default_theme_dir'] . '/fonts'); |
1140 | 1181 | $font_list = array(); |
1141 | - while ($entry = $font_dir->read()) |
|
1142 | - if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf')) |
|
1182 | + while ($entry = $font_dir->read()) { |
|
1183 | + if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf')) |
|
1143 | 1184 | $font_list[] = $entry; |
1185 | + } |
|
1144 | 1186 | |
1145 | - if (empty($font_list)) |
|
1146 | - return false; |
|
1187 | + if (empty($font_list)) { |
|
1188 | + return false; |
|
1189 | + } |
|
1147 | 1190 | |
1148 | 1191 | // Pick a random font. |
1149 | 1192 | $random_font = $font_list[array_rand($font_list)]; |
1150 | 1193 | |
1151 | 1194 | // Check if the given letter exists. |
1152 | - if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) |
|
1153 | - return false; |
|
1195 | + if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) { |
|
1196 | + return false; |
|
1197 | + } |
|
1154 | 1198 | |
1155 | 1199 | // Include it! |
1156 | 1200 | header('content-type: image/png'); |
@@ -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 | * Check if the user is who he/she says he is |
@@ -42,12 +43,14 @@ discard block |
||
42 | 43 | $refreshTime = isset($_GET['xml']) ? 4200 : 3600; |
43 | 44 | |
44 | 45 | // Is the security option off? |
45 | - if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) |
|
46 | - return; |
|
46 | + if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) { |
|
47 | + return; |
|
48 | + } |
|
47 | 49 | |
48 | 50 | // Or are they already logged in?, Moderator or admin session is need for this area |
49 | - if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) |
|
50 | - return; |
|
51 | + if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) { |
|
52 | + return; |
|
53 | + } |
|
51 | 54 | |
52 | 55 | require_once($sourcedir . '/Subs-Auth.php'); |
53 | 56 | |
@@ -55,8 +58,9 @@ discard block |
||
55 | 58 | if (isset($_POST[$type . '_pass'])) |
56 | 59 | { |
57 | 60 | // Check to ensure we're forcing SSL for authentication |
58 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
59 | - fatal_lang_error('login_ssl_required'); |
|
61 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
62 | + fatal_lang_error('login_ssl_required'); |
|
63 | + } |
|
60 | 64 | |
61 | 65 | checkSession(); |
62 | 66 | |
@@ -72,17 +76,19 @@ discard block |
||
72 | 76 | } |
73 | 77 | |
74 | 78 | // Better be sure to remember the real referer |
75 | - if (empty($_SESSION['request_referer'])) |
|
76 | - $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
77 | - elseif (empty($_POST)) |
|
78 | - unset($_SESSION['request_referer']); |
|
79 | + if (empty($_SESSION['request_referer'])) { |
|
80 | + $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
81 | + } elseif (empty($_POST)) { |
|
82 | + unset($_SESSION['request_referer']); |
|
83 | + } |
|
79 | 84 | |
80 | 85 | // Need to type in a password for that, man. |
81 | - if (!isset($_GET['xml'])) |
|
82 | - adminLogin($type); |
|
83 | - else |
|
84 | - return 'session_verify_fail'; |
|
85 | -} |
|
86 | + if (!isset($_GET['xml'])) { |
|
87 | + adminLogin($type); |
|
88 | + } else { |
|
89 | + return 'session_verify_fail'; |
|
90 | + } |
|
91 | + } |
|
86 | 92 | |
87 | 93 | /** |
88 | 94 | * Require a user who is logged in. (not a guest.) |
@@ -96,25 +102,30 @@ discard block |
||
96 | 102 | global $user_info, $txt, $context, $scripturl, $modSettings; |
97 | 103 | |
98 | 104 | // Luckily, this person isn't a guest. |
99 | - if (!$user_info['is_guest']) |
|
100 | - return; |
|
105 | + if (!$user_info['is_guest']) { |
|
106 | + return; |
|
107 | + } |
|
101 | 108 | |
102 | 109 | // Log what they were trying to do didn't work) |
103 | - if (!empty($modSettings['who_enabled'])) |
|
104 | - $_GET['error'] = 'guest_login'; |
|
110 | + if (!empty($modSettings['who_enabled'])) { |
|
111 | + $_GET['error'] = 'guest_login'; |
|
112 | + } |
|
105 | 113 | writeLog(true); |
106 | 114 | |
107 | 115 | // Just die. |
108 | - if (isset($_REQUEST['xml'])) |
|
109 | - obExit(false); |
|
116 | + if (isset($_REQUEST['xml'])) { |
|
117 | + obExit(false); |
|
118 | + } |
|
110 | 119 | |
111 | 120 | // Attempt to detect if they came from dlattach. |
112 | - if (SMF != 'SSI' && empty($context['theme_loaded'])) |
|
113 | - loadTheme(); |
|
121 | + if (SMF != 'SSI' && empty($context['theme_loaded'])) { |
|
122 | + loadTheme(); |
|
123 | + } |
|
114 | 124 | |
115 | 125 | // Never redirect to an attachment |
116 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
117 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
126 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
127 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
128 | + } |
|
118 | 129 | |
119 | 130 | // Load the Login template and language file. |
120 | 131 | loadLanguage('Login'); |
@@ -124,8 +135,7 @@ discard block |
||
124 | 135 | { |
125 | 136 | $_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING']; |
126 | 137 | redirectexit('action=login'); |
127 | - } |
|
128 | - else |
|
138 | + } else |
|
129 | 139 | { |
130 | 140 | loadTemplate('Login'); |
131 | 141 | $context['sub_template'] = 'kick_guest'; |
@@ -155,8 +165,9 @@ discard block |
||
155 | 165 | global $sourcedir, $cookiename, $user_settings, $smcFunc; |
156 | 166 | |
157 | 167 | // You cannot be banned if you are an admin - doesn't help if you log out. |
158 | - if ($user_info['is_admin']) |
|
159 | - return; |
|
168 | + if ($user_info['is_admin']) { |
|
169 | + return; |
|
170 | + } |
|
160 | 171 | |
161 | 172 | // Only check the ban every so often. (to reduce load.) |
162 | 173 | if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email'])) |
@@ -177,8 +188,9 @@ discard block |
||
177 | 188 | // Check both IP addresses. |
178 | 189 | foreach (array('ip', 'ip2') as $ip_number) |
179 | 190 | { |
180 | - if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) |
|
181 | - continue; |
|
191 | + if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) { |
|
192 | + continue; |
|
193 | + } |
|
182 | 194 | $ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high'; |
183 | 195 | $ban_query_vars[$ip_number] = $user_info[$ip_number]; |
184 | 196 | // IP was valid, maybe there's also a hostname... |
@@ -228,24 +240,28 @@ discard block |
||
228 | 240 | // Store every type of ban that applies to you in your session. |
229 | 241 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
230 | 242 | { |
231 | - foreach ($restrictions as $restriction) |
|
232 | - if (!empty($row[$restriction])) |
|
243 | + foreach ($restrictions as $restriction) { |
|
244 | + if (!empty($row[$restriction])) |
|
233 | 245 | { |
234 | 246 | $_SESSION['ban'][$restriction]['reason'] = $row['reason']; |
247 | + } |
|
235 | 248 | $_SESSION['ban'][$restriction]['ids'][] = $row['id_ban']; |
236 | - if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) |
|
237 | - $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
249 | + if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) { |
|
250 | + $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
251 | + } |
|
238 | 252 | |
239 | - if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) |
|
240 | - $flag_is_activated = true; |
|
253 | + if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) { |
|
254 | + $flag_is_activated = true; |
|
255 | + } |
|
241 | 256 | } |
242 | 257 | } |
243 | 258 | $smcFunc['db_free_result']($request); |
244 | 259 | } |
245 | 260 | |
246 | 261 | // Mark the cannot_access and cannot_post bans as being 'hit'. |
247 | - if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) |
|
248 | - log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
262 | + if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) { |
|
263 | + log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
264 | + } |
|
249 | 265 | |
250 | 266 | // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up. |
251 | 267 | if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated) |
@@ -260,8 +276,9 @@ discard block |
||
260 | 276 | if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) |
261 | 277 | { |
262 | 278 | $bans = explode(',', $_COOKIE[$cookiename . '_']); |
263 | - foreach ($bans as $key => $value) |
|
264 | - $bans[$key] = (int) $value; |
|
279 | + foreach ($bans as $key => $value) { |
|
280 | + $bans[$key] = (int) $value; |
|
281 | + } |
|
265 | 282 | $request = $smcFunc['db_query']('', ' |
266 | 283 | SELECT bi.id_ban, bg.reason |
267 | 284 | FROM {db_prefix}ban_items AS bi |
@@ -297,14 +314,15 @@ discard block |
||
297 | 314 | if (isset($_SESSION['ban']['cannot_access'])) |
298 | 315 | { |
299 | 316 | // We don't wanna see you! |
300 | - if (!$user_info['is_guest']) |
|
301 | - $smcFunc['db_query']('', ' |
|
317 | + if (!$user_info['is_guest']) { |
|
318 | + $smcFunc['db_query']('', ' |
|
302 | 319 | DELETE FROM {db_prefix}log_online |
303 | 320 | WHERE id_member = {int:current_member}', |
304 | 321 | array( |
305 | 322 | 'current_member' => $user_info['id'], |
306 | 323 | ) |
307 | 324 | ); |
325 | + } |
|
308 | 326 | |
309 | 327 | // 'Log' the user out. Can't have any funny business... (save the name!) |
310 | 328 | $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title']; |
@@ -390,9 +408,10 @@ discard block |
||
390 | 408 | } |
391 | 409 | |
392 | 410 | // Fix up the banning permissions. |
393 | - if (isset($user_info['permissions'])) |
|
394 | - banPermissions(); |
|
395 | -} |
|
411 | + if (isset($user_info['permissions'])) { |
|
412 | + banPermissions(); |
|
413 | + } |
|
414 | + } |
|
396 | 415 | |
397 | 416 | /** |
398 | 417 | * Fix permissions according to ban status. |
@@ -403,8 +422,9 @@ discard block |
||
403 | 422 | global $user_info, $sourcedir, $modSettings, $context; |
404 | 423 | |
405 | 424 | // Somehow they got here, at least take away all permissions... |
406 | - if (isset($_SESSION['ban']['cannot_access'])) |
|
407 | - $user_info['permissions'] = array(); |
|
425 | + if (isset($_SESSION['ban']['cannot_access'])) { |
|
426 | + $user_info['permissions'] = array(); |
|
427 | + } |
|
408 | 428 | // Okay, well, you can watch, but don't touch a thing. |
409 | 429 | elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning'])) |
410 | 430 | { |
@@ -446,19 +466,20 @@ discard block |
||
446 | 466 | call_integration_hook('integrate_warn_permissions', array(&$permission_change)); |
447 | 467 | foreach ($permission_change as $old => $new) |
448 | 468 | { |
449 | - if (!in_array($old, $user_info['permissions'])) |
|
450 | - unset($permission_change[$old]); |
|
451 | - else |
|
452 | - $user_info['permissions'][] = $new; |
|
469 | + if (!in_array($old, $user_info['permissions'])) { |
|
470 | + unset($permission_change[$old]); |
|
471 | + } else { |
|
472 | + $user_info['permissions'][] = $new; |
|
473 | + } |
|
453 | 474 | } |
454 | 475 | $user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change)); |
455 | 476 | } |
456 | 477 | |
457 | 478 | // @todo Find a better place to call this? Needs to be after permissions loaded! |
458 | 479 | // Finally, some bits we cache in the session because it saves queries. |
459 | - if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) |
|
460 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
461 | - else |
|
480 | + if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) { |
|
481 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
482 | + } else |
|
462 | 483 | { |
463 | 484 | require_once($sourcedir . '/Subs-Auth.php'); |
464 | 485 | rebuildModCache(); |
@@ -469,14 +490,12 @@ discard block |
||
469 | 490 | { |
470 | 491 | $context['open_mod_reports'] = $_SESSION['rc']['reports']; |
471 | 492 | $context['open_member_reports'] = $_SESSION['rc']['member_reports']; |
472 | - } |
|
473 | - elseif ($_SESSION['mc']['bq'] != '0=1') |
|
493 | + } elseif ($_SESSION['mc']['bq'] != '0=1') |
|
474 | 494 | { |
475 | 495 | require_once($sourcedir . '/Subs-ReportedContent.php'); |
476 | 496 | $context['open_mod_reports'] = recountOpenReports('posts'); |
477 | 497 | $context['open_member_reports'] = recountOpenReports('members'); |
478 | - } |
|
479 | - else |
|
498 | + } else |
|
480 | 499 | { |
481 | 500 | $context['open_mod_reports'] = 0; |
482 | 501 | $context['open_member_reports'] = 0; |
@@ -496,8 +515,9 @@ discard block |
||
496 | 515 | global $user_info, $smcFunc; |
497 | 516 | |
498 | 517 | // Don't log web accelerators, it's very confusing... |
499 | - if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
|
500 | - return; |
|
518 | + if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') { |
|
519 | + return; |
|
520 | + } |
|
501 | 521 | |
502 | 522 | $smcFunc['db_insert']('', |
503 | 523 | '{db_prefix}log_banned', |
@@ -507,8 +527,8 @@ discard block |
||
507 | 527 | ); |
508 | 528 | |
509 | 529 | // One extra point for these bans. |
510 | - if (!empty($ban_ids)) |
|
511 | - $smcFunc['db_query']('', ' |
|
530 | + if (!empty($ban_ids)) { |
|
531 | + $smcFunc['db_query']('', ' |
|
512 | 532 | UPDATE {db_prefix}ban_items |
513 | 533 | SET hits = hits + 1 |
514 | 534 | WHERE id_ban IN ({array_int:ban_ids})', |
@@ -516,7 +536,8 @@ discard block |
||
516 | 536 | 'ban_ids' => $ban_ids, |
517 | 537 | ) |
518 | 538 | ); |
519 | -} |
|
539 | + } |
|
540 | + } |
|
520 | 541 | |
521 | 542 | /** |
522 | 543 | * Checks if a given email address might be banned. |
@@ -532,8 +553,9 @@ discard block |
||
532 | 553 | global $txt, $smcFunc; |
533 | 554 | |
534 | 555 | // Can't ban an empty email |
535 | - if (empty($email) || trim($email) == '') |
|
536 | - return; |
|
556 | + if (empty($email) || trim($email) == '') { |
|
557 | + return; |
|
558 | + } |
|
537 | 559 | |
538 | 560 | // Let's start with the bans based on your IP/hostname/memberID... |
539 | 561 | $ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array(); |
@@ -606,16 +628,18 @@ discard block |
||
606 | 628 | if ($type == 'post') |
607 | 629 | { |
608 | 630 | $check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null); |
609 | - if ($check !== $sc) |
|
610 | - $error = 'session_timeout'; |
|
631 | + if ($check !== $sc) { |
|
632 | + $error = 'session_timeout'; |
|
633 | + } |
|
611 | 634 | } |
612 | 635 | |
613 | 636 | // How about $_GET['sesc']? |
614 | 637 | elseif ($type == 'get') |
615 | 638 | { |
616 | 639 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null); |
617 | - if ($check !== $sc) |
|
618 | - $error = 'session_verify_fail'; |
|
640 | + if ($check !== $sc) { |
|
641 | + $error = 'session_verify_fail'; |
|
642 | + } |
|
619 | 643 | } |
620 | 644 | |
621 | 645 | // Or can it be in either? |
@@ -623,13 +647,15 @@ discard block |
||
623 | 647 | { |
624 | 648 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null))); |
625 | 649 | |
626 | - if ($check !== $sc) |
|
627 | - $error = 'session_verify_fail'; |
|
650 | + if ($check !== $sc) { |
|
651 | + $error = 'session_verify_fail'; |
|
652 | + } |
|
628 | 653 | } |
629 | 654 | |
630 | 655 | // Verify that they aren't changing user agents on us - that could be bad. |
631 | - if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) |
|
632 | - $error = 'session_verify_fail'; |
|
656 | + if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) { |
|
657 | + $error = 'session_verify_fail'; |
|
658 | + } |
|
633 | 659 | |
634 | 660 | // Make sure a page with session check requirement is not being prefetched. |
635 | 661 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -640,30 +666,35 @@ discard block |
||
640 | 666 | } |
641 | 667 | |
642 | 668 | // Check the referring site - it should be the same server at least! |
643 | - if (isset($_SESSION['request_referer'])) |
|
644 | - $referrer = $_SESSION['request_referer']; |
|
645 | - else |
|
646 | - $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
669 | + if (isset($_SESSION['request_referer'])) { |
|
670 | + $referrer = $_SESSION['request_referer']; |
|
671 | + } else { |
|
672 | + $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
673 | + } |
|
647 | 674 | if (!empty($referrer['host'])) |
648 | 675 | { |
649 | - if (strpos($_SERVER['HTTP_HOST'], ':') !== false) |
|
650 | - $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
651 | - else |
|
652 | - $real_host = $_SERVER['HTTP_HOST']; |
|
676 | + if (strpos($_SERVER['HTTP_HOST'], ':') !== false) { |
|
677 | + $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
678 | + } else { |
|
679 | + $real_host = $_SERVER['HTTP_HOST']; |
|
680 | + } |
|
653 | 681 | |
654 | 682 | $parsed_url = parse_url($boardurl); |
655 | 683 | |
656 | 684 | // Are global cookies on? If so, let's check them ;). |
657 | 685 | if (!empty($modSettings['globalCookies'])) |
658 | 686 | { |
659 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
660 | - $parsed_url['host'] = $parts[1]; |
|
687 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
688 | + $parsed_url['host'] = $parts[1]; |
|
689 | + } |
|
661 | 690 | |
662 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) |
|
663 | - $referrer['host'] = $parts[1]; |
|
691 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) { |
|
692 | + $referrer['host'] = $parts[1]; |
|
693 | + } |
|
664 | 694 | |
665 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) |
|
666 | - $real_host = $parts[1]; |
|
695 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) { |
|
696 | + $real_host = $parts[1]; |
|
697 | + } |
|
667 | 698 | } |
668 | 699 | |
669 | 700 | // Okay: referrer must either match parsed_url or real_host. |
@@ -681,12 +712,14 @@ discard block |
||
681 | 712 | $log_error = true; |
682 | 713 | } |
683 | 714 | |
684 | - if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') |
|
685 | - fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
715 | + if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') { |
|
716 | + fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
717 | + } |
|
686 | 718 | |
687 | 719 | // Everything is ok, return an empty string. |
688 | - if (!isset($error)) |
|
689 | - return ''; |
|
720 | + if (!isset($error)) { |
|
721 | + return ''; |
|
722 | + } |
|
690 | 723 | // A session error occurred, show the error. |
691 | 724 | elseif ($is_fatal) |
692 | 725 | { |
@@ -695,13 +728,14 @@ discard block |
||
695 | 728 | ob_end_clean(); |
696 | 729 | header('HTTP/1.1 403 Forbidden - Session timeout'); |
697 | 730 | die; |
731 | + } else { |
|
732 | + fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
698 | 733 | } |
699 | - else |
|
700 | - fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
701 | 734 | } |
702 | 735 | // A session error occurred, return the error to the calling function. |
703 | - else |
|
704 | - return $error; |
|
736 | + else { |
|
737 | + return $error; |
|
738 | + } |
|
705 | 739 | |
706 | 740 | // We really should never fall through here, for very important reasons. Let's make sure. |
707 | 741 | trigger_error('Hacking attempt...', E_USER_ERROR); |
@@ -717,10 +751,9 @@ discard block |
||
717 | 751 | { |
718 | 752 | global $modSettings; |
719 | 753 | |
720 | - if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) |
|
721 | - return true; |
|
722 | - |
|
723 | - else |
|
754 | + if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) { |
|
755 | + return true; |
|
756 | + } else |
|
724 | 757 | { |
725 | 758 | $token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']); |
726 | 759 | $_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']); |
@@ -771,9 +804,9 @@ discard block |
||
771 | 804 | $return = $_SESSION['token'][$type . '-' . $action][3]; |
772 | 805 | unset($_SESSION['token'][$type . '-' . $action]); |
773 | 806 | return $return; |
807 | + } else { |
|
808 | + return ''; |
|
774 | 809 | } |
775 | - else |
|
776 | - return ''; |
|
777 | 810 | } |
778 | 811 | |
779 | 812 | // This nasty piece of code validates a token. |
@@ -804,12 +837,14 @@ discard block |
||
804 | 837 | fatal_lang_error('token_verify_fail', false); |
805 | 838 | } |
806 | 839 | // Remove this token as its useless |
807 | - else |
|
808 | - unset($_SESSION['token'][$type . '-' . $action]); |
|
840 | + else { |
|
841 | + unset($_SESSION['token'][$type . '-' . $action]); |
|
842 | + } |
|
809 | 843 | |
810 | 844 | // Randomly check if we should remove some older tokens. |
811 | - if (mt_rand(0, 138) == 23) |
|
812 | - cleanTokens(); |
|
845 | + if (mt_rand(0, 138) == 23) { |
|
846 | + cleanTokens(); |
|
847 | + } |
|
813 | 848 | |
814 | 849 | return false; |
815 | 850 | } |
@@ -824,14 +859,16 @@ discard block |
||
824 | 859 | function cleanTokens($complete = false) |
825 | 860 | { |
826 | 861 | // We appreciate cleaning up after yourselves. |
827 | - if (!isset($_SESSION['token'])) |
|
828 | - return; |
|
862 | + if (!isset($_SESSION['token'])) { |
|
863 | + return; |
|
864 | + } |
|
829 | 865 | |
830 | 866 | // Clean up tokens, trying to give enough time still. |
831 | - foreach ($_SESSION['token'] as $key => $data) |
|
832 | - if ($data[2] + 10800 < time() || $complete) |
|
867 | + foreach ($_SESSION['token'] as $key => $data) { |
|
868 | + if ($data[2] + 10800 < time() || $complete) |
|
833 | 869 | unset($_SESSION['token'][$key]); |
834 | -} |
|
870 | + } |
|
871 | + } |
|
835 | 872 | |
836 | 873 | /** |
837 | 874 | * Check whether a form has been submitted twice. |
@@ -849,37 +886,40 @@ discard block |
||
849 | 886 | { |
850 | 887 | global $context; |
851 | 888 | |
852 | - if (!isset($_SESSION['forms'])) |
|
853 | - $_SESSION['forms'] = array(); |
|
889 | + if (!isset($_SESSION['forms'])) { |
|
890 | + $_SESSION['forms'] = array(); |
|
891 | + } |
|
854 | 892 | |
855 | 893 | // Register a form number and store it in the session stack. (use this on the page that has the form.) |
856 | 894 | if ($action == 'register') |
857 | 895 | { |
858 | 896 | $context['form_sequence_number'] = 0; |
859 | - while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) |
|
860 | - $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
897 | + while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) { |
|
898 | + $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
899 | + } |
|
861 | 900 | } |
862 | 901 | // Check whether the submitted number can be found in the session. |
863 | 902 | elseif ($action == 'check') |
864 | 903 | { |
865 | - if (!isset($_REQUEST['seqnum'])) |
|
866 | - return true; |
|
867 | - elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
904 | + if (!isset($_REQUEST['seqnum'])) { |
|
905 | + return true; |
|
906 | + } elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
868 | 907 | { |
869 | 908 | $_SESSION['forms'][] = (int) $_REQUEST['seqnum']; |
870 | 909 | return true; |
910 | + } elseif ($is_fatal) { |
|
911 | + fatal_lang_error('error_form_already_submitted', false); |
|
912 | + } else { |
|
913 | + return false; |
|
871 | 914 | } |
872 | - elseif ($is_fatal) |
|
873 | - fatal_lang_error('error_form_already_submitted', false); |
|
874 | - else |
|
875 | - return false; |
|
876 | 915 | } |
877 | 916 | // Don't check, just free the stack number. |
878 | - elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
879 | - $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
880 | - elseif ($action != 'free') |
|
881 | - trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
882 | -} |
|
917 | + elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { |
|
918 | + $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
919 | + } elseif ($action != 'free') { |
|
920 | + trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
921 | + } |
|
922 | + } |
|
883 | 923 | |
884 | 924 | /** |
885 | 925 | * Check the user's permissions. |
@@ -898,16 +938,19 @@ discard block |
||
898 | 938 | global $user_info, $smcFunc; |
899 | 939 | |
900 | 940 | // You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!) |
901 | - if (empty($permission)) |
|
902 | - return true; |
|
941 | + if (empty($permission)) { |
|
942 | + return true; |
|
943 | + } |
|
903 | 944 | |
904 | 945 | // You're never allowed to do something if your data hasn't been loaded yet! |
905 | - if (empty($user_info)) |
|
906 | - return false; |
|
946 | + if (empty($user_info)) { |
|
947 | + return false; |
|
948 | + } |
|
907 | 949 | |
908 | 950 | // Administrators are supermen :P. |
909 | - if ($user_info['is_admin']) |
|
910 | - return true; |
|
951 | + if ($user_info['is_admin']) { |
|
952 | + return true; |
|
953 | + } |
|
911 | 954 | |
912 | 955 | // Let's ensure this is an array. |
913 | 956 | $permission = (array) $permission; |
@@ -915,14 +958,16 @@ discard block |
||
915 | 958 | // Are we checking the _current_ board, or some other boards? |
916 | 959 | if ($boards === null) |
917 | 960 | { |
918 | - if (count(array_intersect($permission, $user_info['permissions'])) != 0) |
|
919 | - return true; |
|
961 | + if (count(array_intersect($permission, $user_info['permissions'])) != 0) { |
|
962 | + return true; |
|
963 | + } |
|
920 | 964 | // You aren't allowed, by default. |
921 | - else |
|
922 | - return false; |
|
965 | + else { |
|
966 | + return false; |
|
967 | + } |
|
968 | + } elseif (!is_array($boards)) { |
|
969 | + $boards = array($boards); |
|
923 | 970 | } |
924 | - elseif (!is_array($boards)) |
|
925 | - $boards = array($boards); |
|
926 | 971 | |
927 | 972 | $request = $smcFunc['db_query']('', ' |
928 | 973 | SELECT MIN(bp.add_deny) AS add_deny |
@@ -950,20 +995,23 @@ discard block |
||
950 | 995 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
951 | 996 | { |
952 | 997 | $result = !empty($row['add_deny']); |
953 | - if ($result == true) |
|
954 | - break; |
|
998 | + if ($result == true) { |
|
999 | + break; |
|
1000 | + } |
|
955 | 1001 | } |
956 | 1002 | $smcFunc['db_free_result']($request); |
957 | 1003 | return $result; |
958 | 1004 | } |
959 | 1005 | |
960 | 1006 | // Make sure they can do it on all of the boards. |
961 | - if ($smcFunc['db_num_rows']($request) != count($boards)) |
|
962 | - return false; |
|
1007 | + if ($smcFunc['db_num_rows']($request) != count($boards)) { |
|
1008 | + return false; |
|
1009 | + } |
|
963 | 1010 | |
964 | 1011 | $result = true; |
965 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
966 | - $result &= !empty($row['add_deny']); |
|
1012 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1013 | + $result &= !empty($row['add_deny']); |
|
1014 | + } |
|
967 | 1015 | $smcFunc['db_free_result']($request); |
968 | 1016 | |
969 | 1017 | // If the query returned 1, they can do it... otherwise, they can't. |
@@ -1030,9 +1078,10 @@ discard block |
||
1030 | 1078 | |
1031 | 1079 | // If you're doing something on behalf of some "heavy" permissions, validate your session. |
1032 | 1080 | // (take out the heavy permissions, and if you can't do anything but those, you need a validated session.) |
1033 | - if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) |
|
1034 | - validateSession(); |
|
1035 | -} |
|
1081 | + if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) { |
|
1082 | + validateSession(); |
|
1083 | + } |
|
1084 | + } |
|
1036 | 1085 | |
1037 | 1086 | /** |
1038 | 1087 | * Return the boards a user has a certain (board) permission on. (array(0) if all.) |
@@ -1051,8 +1100,9 @@ discard block |
||
1051 | 1100 | global $user_info, $smcFunc; |
1052 | 1101 | |
1053 | 1102 | // Arrays are nice, most of the time. |
1054 | - if (!is_array($permissions)) |
|
1055 | - $permissions = array($permissions); |
|
1103 | + if (!is_array($permissions)) { |
|
1104 | + $permissions = array($permissions); |
|
1105 | + } |
|
1056 | 1106 | |
1057 | 1107 | /* |
1058 | 1108 | * Set $simple to true to use this function as it were in SMF 2.0.x. |
@@ -1064,13 +1114,14 @@ discard block |
||
1064 | 1114 | // Administrators are all powerful, sorry. |
1065 | 1115 | if ($user_info['is_admin']) |
1066 | 1116 | { |
1067 | - if ($simple) |
|
1068 | - return array(0); |
|
1069 | - else |
|
1117 | + if ($simple) { |
|
1118 | + return array(0); |
|
1119 | + } else |
|
1070 | 1120 | { |
1071 | 1121 | $boards = array(); |
1072 | - foreach ($permissions as $permission) |
|
1073 | - $boards[$permission] = array(0); |
|
1122 | + foreach ($permissions as $permission) { |
|
1123 | + $boards[$permission] = array(0); |
|
1124 | + } |
|
1074 | 1125 | |
1075 | 1126 | return $boards; |
1076 | 1127 | } |
@@ -1102,31 +1153,32 @@ discard block |
||
1102 | 1153 | { |
1103 | 1154 | if ($simple) |
1104 | 1155 | { |
1105 | - if (empty($row['add_deny'])) |
|
1106 | - $deny_boards[] = $row['id_board']; |
|
1107 | - else |
|
1108 | - $boards[] = $row['id_board']; |
|
1109 | - } |
|
1110 | - else |
|
1156 | + if (empty($row['add_deny'])) { |
|
1157 | + $deny_boards[] = $row['id_board']; |
|
1158 | + } else { |
|
1159 | + $boards[] = $row['id_board']; |
|
1160 | + } |
|
1161 | + } else |
|
1111 | 1162 | { |
1112 | - if (empty($row['add_deny'])) |
|
1113 | - $deny_boards[$row['permission']][] = $row['id_board']; |
|
1114 | - else |
|
1115 | - $boards[$row['permission']][] = $row['id_board']; |
|
1163 | + if (empty($row['add_deny'])) { |
|
1164 | + $deny_boards[$row['permission']][] = $row['id_board']; |
|
1165 | + } else { |
|
1166 | + $boards[$row['permission']][] = $row['id_board']; |
|
1167 | + } |
|
1116 | 1168 | } |
1117 | 1169 | } |
1118 | 1170 | $smcFunc['db_free_result']($request); |
1119 | 1171 | |
1120 | - if ($simple) |
|
1121 | - $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
1122 | - else |
|
1172 | + if ($simple) { |
|
1173 | + $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
1174 | + } else |
|
1123 | 1175 | { |
1124 | 1176 | foreach ($permissions as $permission) |
1125 | 1177 | { |
1126 | 1178 | // never had it to start with |
1127 | - if (empty($boards[$permission])) |
|
1128 | - $boards[$permission] = array(); |
|
1129 | - else |
|
1179 | + if (empty($boards[$permission])) { |
|
1180 | + $boards[$permission] = array(); |
|
1181 | + } else |
|
1130 | 1182 | { |
1131 | 1183 | // Or it may have been removed |
1132 | 1184 | $deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array(); |
@@ -1162,10 +1214,11 @@ discard block |
||
1162 | 1214 | |
1163 | 1215 | |
1164 | 1216 | // Moderators are free... |
1165 | - if (!allowedTo('moderate_board')) |
|
1166 | - $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
1167 | - else |
|
1168 | - $timeLimit = 2; |
|
1217 | + if (!allowedTo('moderate_board')) { |
|
1218 | + $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
1219 | + } else { |
|
1220 | + $timeLimit = 2; |
|
1221 | + } |
|
1169 | 1222 | |
1170 | 1223 | call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit)); |
1171 | 1224 | |
@@ -1192,8 +1245,9 @@ discard block |
||
1192 | 1245 | if ($smcFunc['db_affected_rows']() != 1) |
1193 | 1246 | { |
1194 | 1247 | // Spammer! You only have to wait a *few* seconds! |
1195 | - if (!$only_return_result) |
|
1196 | - fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
1248 | + if (!$only_return_result) { |
|
1249 | + fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
1250 | + } |
|
1197 | 1251 | |
1198 | 1252 | return true; |
1199 | 1253 | } |
@@ -1211,11 +1265,13 @@ discard block |
||
1211 | 1265 | */ |
1212 | 1266 | function secureDirectory($path, $attachments = false) |
1213 | 1267 | { |
1214 | - if (empty($path)) |
|
1215 | - return 'empty_path'; |
|
1268 | + if (empty($path)) { |
|
1269 | + return 'empty_path'; |
|
1270 | + } |
|
1216 | 1271 | |
1217 | - if (!is_writable($path)) |
|
1218 | - return 'path_not_writable'; |
|
1272 | + if (!is_writable($path)) { |
|
1273 | + return 'path_not_writable'; |
|
1274 | + } |
|
1219 | 1275 | |
1220 | 1276 | $directoryname = basename($path); |
1221 | 1277 | |
@@ -1227,9 +1283,9 @@ discard block |
||
1227 | 1283 | |
1228 | 1284 | RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml'; |
1229 | 1285 | |
1230 | - if (file_exists($path . '/.htaccess')) |
|
1231 | - $errors[] = 'htaccess_exists'; |
|
1232 | - else |
|
1286 | + if (file_exists($path . '/.htaccess')) { |
|
1287 | + $errors[] = 'htaccess_exists'; |
|
1288 | + } else |
|
1233 | 1289 | { |
1234 | 1290 | $fh = @fopen($path . '/.htaccess', 'w'); |
1235 | 1291 | if ($fh) |
@@ -1242,9 +1298,9 @@ discard block |
||
1242 | 1298 | $errors[] = 'htaccess_cannot_create_file'; |
1243 | 1299 | } |
1244 | 1300 | |
1245 | - if (file_exists($path . '/index.php')) |
|
1246 | - $errors[] = 'index-php_exists'; |
|
1247 | - else |
|
1301 | + if (file_exists($path . '/index.php')) { |
|
1302 | + $errors[] = 'index-php_exists'; |
|
1303 | + } else |
|
1248 | 1304 | { |
1249 | 1305 | $fh = @fopen($path . '/index.php', 'w'); |
1250 | 1306 | if ($fh) |
@@ -1272,11 +1328,12 @@ discard block |
||
1272 | 1328 | $errors[] = 'index-php_cannot_create_file'; |
1273 | 1329 | } |
1274 | 1330 | |
1275 | - if (!empty($errors)) |
|
1276 | - return $errors; |
|
1277 | - else |
|
1278 | - return true; |
|
1279 | -} |
|
1331 | + if (!empty($errors)) { |
|
1332 | + return $errors; |
|
1333 | + } else { |
|
1334 | + return true; |
|
1335 | + } |
|
1336 | + } |
|
1280 | 1337 | |
1281 | 1338 | /** |
1282 | 1339 | * This sets the X-Frame-Options header. |
@@ -1289,14 +1346,16 @@ discard block |
||
1289 | 1346 | global $modSettings; |
1290 | 1347 | |
1291 | 1348 | $option = 'SAMEORIGIN'; |
1292 | - if (is_null($override) && !empty($modSettings['frame_security'])) |
|
1293 | - $option = $modSettings['frame_security']; |
|
1294 | - elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) |
|
1295 | - $option = $override; |
|
1349 | + if (is_null($override) && !empty($modSettings['frame_security'])) { |
|
1350 | + $option = $modSettings['frame_security']; |
|
1351 | + } elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) { |
|
1352 | + $option = $override; |
|
1353 | + } |
|
1296 | 1354 | |
1297 | 1355 | // Don't bother setting the header if we have disabled it. |
1298 | - if ($option == 'DISABLE') |
|
1299 | - return; |
|
1356 | + if ($option == 'DISABLE') { |
|
1357 | + return; |
|
1358 | + } |
|
1300 | 1359 | |
1301 | 1360 | // Finally set it. |
1302 | 1361 | header('x-frame-options: ' . $option); |
@@ -51,34 +51,38 @@ discard block |
||
51 | 51 | $ignored_members = explode(',', $row['pm_ignore_list']); |
52 | 52 | |
53 | 53 | // If the user is in group 1 anywhere, they can see everything anyway. |
54 | - if (in_array(1, $groups) || count(array_intersect($allowed, $groups)) != 0) |
|
55 | - $author = $row['id_member']; |
|
54 | + if (in_array(1, $groups) || count(array_intersect($allowed, $groups)) != 0) { |
|
55 | + $author = $row['id_member']; |
|
56 | + } |
|
56 | 57 | } |
57 | 58 | $smcFunc['db_free_result']($request); |
58 | - } |
|
59 | - else |
|
59 | + } else |
|
60 | 60 | { |
61 | 61 | // This isn't something we know natively how to support. Call the hooks, if they're dealing with it, return false, otherwise return the user id. |
62 | 62 | $hook_results = call_integration_hook('integrate_find_like_author', array($this->_details['content_type'], $this->_details['content_id'])); |
63 | - foreach ($hook_results as $result) |
|
64 | - if (!empty($result)) |
|
63 | + foreach ($hook_results as $result) { |
|
64 | + if (!empty($result)) |
|
65 | 65 | { |
66 | 66 | $author = $result; |
67 | + } |
|
67 | 68 | break; |
68 | 69 | } |
69 | 70 | } |
70 | 71 | |
71 | 72 | // If we didn't have a member... leave. |
72 | - if (empty($author)) |
|
73 | - return true; |
|
73 | + if (empty($author)) { |
|
74 | + return true; |
|
75 | + } |
|
74 | 76 | |
75 | 77 | // If the person who sent the notification is the person whose content it is, do nothing. |
76 | - if ($author == $this->_details['sender_id']) |
|
77 | - return true; |
|
78 | + if ($author == $this->_details['sender_id']) { |
|
79 | + return true; |
|
80 | + } |
|
78 | 81 | |
79 | 82 | // If the person who sent the notification is on this person's ignore list, do nothing. |
80 | - if (!empty($ignored_members) && in_array($this->_details['sender_id'], $ignored_members)) |
|
81 | - return true; |
|
83 | + if (!empty($ignored_members) && in_array($this->_details['sender_id'], $ignored_members)) { |
|
84 | + return true; |
|
85 | + } |
|
82 | 86 | |
83 | 87 | require_once($sourcedir . '/Subs-Notify.php'); |
84 | 88 | $prefs = getNotifyPrefs($author, $this->_details['content_type'] . '_like', true); |
@@ -87,8 +91,9 @@ discard block |
||
87 | 91 | // As a result, the value should really just be non empty. |
88 | 92 | |
89 | 93 | // Check the value. If no value or it's empty, they didn't want alerts, oh well. |
90 | - if (empty($prefs[$author][$this->_details['content_type'] . '_like'])) |
|
91 | - return true; |
|
94 | + if (empty($prefs[$author][$this->_details['content_type'] . '_like'])) { |
|
95 | + return true; |
|
96 | + } |
|
92 | 97 | |
93 | 98 | // Don't spam the alerts: if there is an existing unread alert of the |
94 | 99 | // requested type for the target user from the sender, don't make a new one. |
@@ -108,8 +113,9 @@ discard block |
||
108 | 113 | ) |
109 | 114 | ); |
110 | 115 | |
111 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
112 | - return true; |
|
116 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
117 | + return true; |
|
118 | + } |
|
113 | 119 | $smcFunc['db_free_result']($request); |
114 | 120 | |
115 | 121 | // Issue, update, move on. |
@@ -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 | * Shows a listing of registered members. |
@@ -110,8 +111,9 @@ discard block |
||
110 | 111 | |
111 | 112 | $context['custom_profile_fields'] = getCustFieldsMList(); |
112 | 113 | |
113 | - if (!empty($context['custom_profile_fields']['columns'])) |
|
114 | - $context['columns'] += $context['custom_profile_fields']['columns']; |
|
114 | + if (!empty($context['custom_profile_fields']['columns'])) { |
|
115 | + $context['columns'] += $context['custom_profile_fields']['columns']; |
|
116 | + } |
|
115 | 117 | |
116 | 118 | $context['colspan'] = 0; |
117 | 119 | $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); |
@@ -147,12 +149,12 @@ discard block |
||
147 | 149 | call_integration_hook('integrate_memberlist_buttons'); |
148 | 150 | |
149 | 151 | // Jump to the sub action. |
150 | - if (isset($subActions[$context['listing_by']])) |
|
151 | - call_helper($subActions[$context['listing_by']][1]); |
|
152 | - |
|
153 | - else |
|
154 | - call_helper($subActions['all'][1]); |
|
155 | -} |
|
152 | + if (isset($subActions[$context['listing_by']])) { |
|
153 | + call_helper($subActions[$context['listing_by']][1]); |
|
154 | + } else { |
|
155 | + call_helper($subActions['all'][1]); |
|
156 | + } |
|
157 | + } |
|
156 | 158 | |
157 | 159 | /** |
158 | 160 | * List all members, page by page, with sorting. |
@@ -177,8 +179,9 @@ discard block |
||
177 | 179 | if ($use_cache) |
178 | 180 | { |
179 | 181 | // Maybe there's something cached already. |
180 | - if (!empty($modSettings['memberlist_cache'])) |
|
181 | - $memberlist_cache = $smcFunc['json_decode']($modSettings['memberlist_cache'], true); |
|
182 | + if (!empty($modSettings['memberlist_cache'])) { |
|
183 | + $memberlist_cache = $smcFunc['json_decode']($modSettings['memberlist_cache'], true); |
|
184 | + } |
|
182 | 185 | |
183 | 186 | // The chunk size for the cached index. |
184 | 187 | $cache_step_size = 500; |
@@ -234,13 +237,15 @@ discard block |
||
234 | 237 | } |
235 | 238 | |
236 | 239 | // Set defaults for sort (real_name) and start. (0) |
237 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
238 | - $_REQUEST['sort'] = 'real_name'; |
|
240 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
241 | + $_REQUEST['sort'] = 'real_name'; |
|
242 | + } |
|
239 | 243 | |
240 | 244 | if (!is_numeric($_REQUEST['start'])) |
241 | 245 | { |
242 | - if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) |
|
243 | - fatal_error('Hacker?', false); |
|
246 | + if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) { |
|
247 | + fatal_error('Hacker?', false); |
|
248 | + } |
|
244 | 249 | |
245 | 250 | $_REQUEST['start'] = $match[0]; |
246 | 251 | |
@@ -259,16 +264,18 @@ discard block |
||
259 | 264 | } |
260 | 265 | |
261 | 266 | $context['letter_links'] = ''; |
262 | - for ($i = 97; $i < 123; $i++) |
|
263 | - $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
267 | + for ($i = 97; $i < 123; $i++) { |
|
268 | + $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
269 | + } |
|
264 | 270 | |
265 | 271 | // Sort out the column information. |
266 | 272 | foreach ($context['columns'] as $col => $column_details) |
267 | 273 | { |
268 | 274 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sort=' . $col . ';start=0'; |
269 | 275 | |
270 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
271 | - $context['columns'][$col]['href'] .= ';desc'; |
|
276 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
277 | + $context['columns'][$col]['href'] .= ';desc'; |
|
278 | + } |
|
272 | 279 | |
273 | 280 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
274 | 281 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -317,8 +324,9 @@ discard block |
||
317 | 324 | elseif ($use_cache && $_REQUEST['sort'] === 'real_name') |
318 | 325 | { |
319 | 326 | $first_offset = floor(($memberlist_cache['num_members'] - $modSettings['defaultMaxMembers'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
320 | - if ($first_offset < 0) |
|
321 | - $first_offset = 0; |
|
327 | + if ($first_offset < 0) { |
|
328 | + $first_offset = 0; |
|
329 | + } |
|
322 | 330 | $second_offset = ceil(($memberlist_cache['num_members'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
323 | 331 | |
324 | 332 | $where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}'; |
@@ -328,8 +336,9 @@ discard block |
||
328 | 336 | } |
329 | 337 | |
330 | 338 | $custom_fields_qry = ''; |
331 | - if (!empty($context['custom_profile_fields']['join'][$_REQUEST['sort']])) |
|
332 | - $custom_fields_qry = $context['custom_profile_fields']['join'][$_REQUEST['sort']]; |
|
339 | + if (!empty($context['custom_profile_fields']['join'][$_REQUEST['sort']])) { |
|
340 | + $custom_fields_qry = $context['custom_profile_fields']['join'][$_REQUEST['sort']]; |
|
341 | + } |
|
333 | 342 | |
334 | 343 | // Select the members from the database. |
335 | 344 | $request = $smcFunc['db_query']('', ' |
@@ -399,12 +408,13 @@ discard block |
||
399 | 408 | ) |
400 | 409 | ); |
401 | 410 | $context['custom_search_fields'] = array(); |
402 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
403 | - $context['custom_search_fields'][$row['col_name']] = array( |
|
411 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
412 | + $context['custom_search_fields'][$row['col_name']] = array( |
|
404 | 413 | 'colname' => $row['col_name'], |
405 | 414 | 'name' => $row['field_name'], |
406 | 415 | 'desc' => $row['field_desc'], |
407 | 416 | ); |
417 | + } |
|
408 | 418 | $smcFunc['db_free_result']($request); |
409 | 419 | |
410 | 420 | // They're searching.. |
@@ -417,23 +427,27 @@ discard block |
||
417 | 427 | $context['old_search_value'] = urlencode($_REQUEST['search']); |
418 | 428 | |
419 | 429 | // No fields? Use default... |
420 | - if (empty($_POST['fields'])) |
|
421 | - $_POST['fields'] = array('name'); |
|
430 | + if (empty($_POST['fields'])) { |
|
431 | + $_POST['fields'] = array('name'); |
|
432 | + } |
|
422 | 433 | |
423 | 434 | // Set defaults for how the results are sorted |
424 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
425 | - $_REQUEST['sort'] = 'real_name'; |
|
435 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
436 | + $_REQUEST['sort'] = 'real_name'; |
|
437 | + } |
|
426 | 438 | |
427 | 439 | // Build the column link / sort information. |
428 | 440 | foreach ($context['columns'] as $col => $column_details) |
429 | 441 | { |
430 | 442 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sa=search;start=0;sort=' . $col; |
431 | 443 | |
432 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
433 | - $context['columns'][$col]['href'] .= ';desc'; |
|
444 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
445 | + $context['columns'][$col]['href'] .= ';desc'; |
|
446 | + } |
|
434 | 447 | |
435 | - if (isset($_POST['search']) && isset($_POST['fields'])) |
|
436 | - $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
448 | + if (isset($_POST['search']) && isset($_POST['fields'])) { |
|
449 | + $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
450 | + } |
|
437 | 451 | |
438 | 452 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
439 | 453 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -456,8 +470,7 @@ discard block |
||
456 | 470 | { |
457 | 471 | $fields = allowedTo('moderate_forum') ? array('member_name', 'real_name') : array('real_name'); |
458 | 472 | $search_fields[] = 'name'; |
459 | - } |
|
460 | - else |
|
473 | + } else |
|
461 | 474 | { |
462 | 475 | $fields = array(); |
463 | 476 | $search_fields = array(); |
@@ -482,9 +495,10 @@ discard block |
||
482 | 495 | $search_fields[] = 'email'; |
483 | 496 | } |
484 | 497 | |
485 | - if ($smcFunc['db_case_sensitive']) |
|
486 | - foreach ($fields as $key => $field) |
|
498 | + if ($smcFunc['db_case_sensitive']) { |
|
499 | + foreach ($fields as $key => $field) |
|
487 | 500 | $fields[$key] = 'LOWER(' . $field . ')'; |
501 | + } |
|
488 | 502 | |
489 | 503 | $customJoin = array(); |
490 | 504 | $customCount = 10; |
@@ -503,8 +517,9 @@ discard block |
||
503 | 517 | } |
504 | 518 | |
505 | 519 | // No search fields? That means you're trying to hack things |
506 | - if (empty($search_fields)) |
|
507 | - fatal_lang_error('invalid_search_string', false); |
|
520 | + if (empty($search_fields)) { |
|
521 | + fatal_lang_error('invalid_search_string', false); |
|
522 | + } |
|
508 | 523 | |
509 | 524 | $query = $_POST['search'] == '' ? '= {string:blank_string}' : ($smcFunc['db_case_sensitive'] ? 'LIKE LOWER({string:search})' : 'LIKE {string:search}'); |
510 | 525 | |
@@ -542,8 +557,7 @@ discard block |
||
542 | 557 | ); |
543 | 558 | printMemberListRows($request); |
544 | 559 | $smcFunc['db_free_result']($request); |
545 | - } |
|
546 | - else |
|
560 | + } else |
|
547 | 561 | { |
548 | 562 | // These are all the possible fields. |
549 | 563 | $context['search_fields'] = array( |
@@ -558,14 +572,14 @@ discard block |
||
558 | 572 | { |
559 | 573 | unset($context['search_fields']['email']); |
560 | 574 | $context['search_defaults'] = array('name'); |
561 | - } |
|
562 | - else |
|
575 | + } else |
|
563 | 576 | { |
564 | 577 | $context['search_defaults'] = array('name', 'email'); |
565 | 578 | } |
566 | 579 | |
567 | - foreach ($context['custom_search_fields'] as $field) |
|
568 | - $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
580 | + foreach ($context['custom_search_fields'] as $field) { |
|
581 | + $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
582 | + } |
|
569 | 583 | |
570 | 584 | $context['sub_template'] = 'search'; |
571 | 585 | $context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? $smcFunc['htmlspecialchars']($_POST['search']) : ''); |
@@ -607,12 +621,14 @@ discard block |
||
607 | 621 | $smcFunc['db_free_result']($result); |
608 | 622 | |
609 | 623 | // Avoid division by zero... |
610 | - if ($most_posts == 0) |
|
611 | - $most_posts = 1; |
|
624 | + if ($most_posts == 0) { |
|
625 | + $most_posts = 1; |
|
626 | + } |
|
612 | 627 | |
613 | 628 | $members = array(); |
614 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
615 | - $members[] = $row['id_member']; |
|
629 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
630 | + $members[] = $row['id_member']; |
|
631 | + } |
|
616 | 632 | |
617 | 633 | // Load all the members for display. |
618 | 634 | loadMemberData($members); |
@@ -620,8 +636,9 @@ discard block |
||
620 | 636 | $context['members'] = array(); |
621 | 637 | foreach ($members as $member) |
622 | 638 | { |
623 | - if (!loadMemberContext($member)) |
|
624 | - continue; |
|
639 | + if (!loadMemberContext($member)) { |
|
640 | + continue; |
|
641 | + } |
|
625 | 642 | |
626 | 643 | $context['members'][$member] = $memberContext[$member]; |
627 | 644 | $context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts); |
@@ -644,26 +661,28 @@ discard block |
||
644 | 661 | $fieldOptions = explode(',', $column['options']); |
645 | 662 | foreach ($fieldOptions as $k => $v) |
646 | 663 | { |
647 | - if (empty($currentKey)) |
|
648 | - $currentKey = $v === $context['members'][$member]['options'][$key] ? $k : 0; |
|
664 | + if (empty($currentKey)) { |
|
665 | + $currentKey = $v === $context['members'][$member]['options'][$key] ? $k : 0; |
|
666 | + } |
|
649 | 667 | } |
650 | 668 | } |
651 | 669 | |
652 | - if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) |
|
653 | - $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
654 | - |
|
655 | - elseif ($column['type'] == 'check') |
|
656 | - $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
670 | + if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) { |
|
671 | + $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
672 | + } elseif ($column['type'] == 'check') { |
|
673 | + $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
674 | + } |
|
657 | 675 | |
658 | 676 | // Enclosing the user input within some other text? |
659 | - if (!empty($column['enclose'])) |
|
660 | - $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
677 | + if (!empty($column['enclose'])) { |
|
678 | + $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
661 | 679 | '{SCRIPTURL}' => $scripturl, |
662 | 680 | '{IMAGES_URL}' => $settings['images_url'], |
663 | 681 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
664 | 682 | '{INPUT}' => $context['members'][$member]['options'][$key], |
665 | 683 | '{KEY}' => $currentKey |
666 | 684 | )); |
685 | + } |
|
667 | 686 | } |
668 | 687 | } |
669 | 688 | } |
@@ -705,17 +724,17 @@ discard block |
||
705 | 724 | ); |
706 | 725 | |
707 | 726 | // Get the right sort method depending on the cust field type. |
708 | - if ($row['field_type'] != 'check') |
|
709 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
727 | + if ($row['field_type'] != 'check') { |
|
728 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
710 | 729 | 'down' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 ASC, COALESCE(t' . $row['col_name'] . '.value, \'\') DESC', |
711 | 730 | 'up' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 DESC, COALESCE(t' . $row['col_name'] . '.value, \'\') ASC' |
712 | 731 | ); |
713 | - |
|
714 | - else |
|
715 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
732 | + } else { |
|
733 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
716 | 734 | 'down' => 't' . $row['col_name'] . '.value DESC', |
717 | 735 | 'up' => 't' . $row['col_name'] . '.value ASC' |
718 | 736 | ); |
737 | + } |
|
719 | 738 | |
720 | 739 | $cpf['join'][$row['col_name']] = 'LEFT JOIN {db_prefix}themes AS t' . $row['col_name'] . ' ON (t' . $row['col_name'] . '.variable = {literal:' . $row['col_name'] . '} AND t' . $row['col_name'] . '.id_theme = 1 AND t' . $row['col_name'] . '.id_member = mem.id_member)'; |
721 | 740 | } |
@@ -27,9 +27,10 @@ discard block |
||
27 | 27 | <h3 class="catbg"> |
28 | 28 | <span class="floatleft">', $txt['members_list'], '</span>'; |
29 | 29 | |
30 | - if (!isset($context['old_search'])) |
|
31 | - echo ' |
|
30 | + if (!isset($context['old_search'])) { |
|
31 | + echo ' |
|
32 | 32 | <span class="floatright">', $context['letter_links'], '</span>'; |
33 | + } |
|
33 | 34 | echo ' |
34 | 35 | </h3> |
35 | 36 | </div>'; |
@@ -44,20 +45,23 @@ discard block |
||
44 | 45 | foreach ($context['columns'] as $key => $column) |
45 | 46 | { |
46 | 47 | // @TODO maybe find something nicer? |
47 | - if ($key == 'email_address' && !$context['can_send_email']) |
|
48 | - continue; |
|
48 | + if ($key == 'email_address' && !$context['can_send_email']) { |
|
49 | + continue; |
|
50 | + } |
|
49 | 51 | |
50 | 52 | // This is a selected column, so underline it or some such. |
51 | - if ($column['selected']) |
|
52 | - echo ' |
|
53 | + if ($column['selected']) { |
|
54 | + echo ' |
|
53 | 55 | <th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', ' selected" style="width: auto;"' . (isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '') . '> |
54 | 56 | <a href="' . $column['href'] . '" rel="nofollow">' . $column['label'] . '</a><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></th>'; |
57 | + } |
|
55 | 58 | |
56 | 59 | // This is just some column... show the link and be done with it. |
57 | - else |
|
58 | - echo ' |
|
60 | + else { |
|
61 | + echo ' |
|
59 | 62 | <th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', '"', isset($column['width']) ? ' style="width: ' . $column['width'] . '"' : '', isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '', '> |
60 | 63 | ', $column['link'], '</th>'; |
64 | + } |
|
61 | 65 | } |
62 | 66 | |
63 | 67 | echo ' |
@@ -77,9 +81,10 @@ discard block |
||
77 | 81 | </td> |
78 | 82 | <td class="lefttext">', $member['link'], '</td>'; |
79 | 83 | |
80 | - if (!isset($context['disabled_fields']['website'])) |
|
81 | - echo ' |
|
84 | + if (!isset($context['disabled_fields']['website'])) { |
|
85 | + echo ' |
|
82 | 86 | <td class="centertext website_url">', $member['website']['url'] != '' ? '<a href="' . $member['website']['url'] . '" target="_blank" rel="noopener"><span class="generic_icons www" title="' . $member['website']['title'] . '"></span></a>' : '', '</td>'; |
87 | + } |
|
83 | 88 | |
84 | 89 | // Group and date. |
85 | 90 | echo ' |
@@ -92,32 +97,35 @@ discard block |
||
92 | 97 | <td class="centertext" style="white-space: nowrap; width: 15px">', $member['posts'], '</td> |
93 | 98 | <td class="centertext statsbar" style="width: 120px">'; |
94 | 99 | |
95 | - if (!empty($member['post_percent'])) |
|
96 | - echo ' |
|
100 | + if (!empty($member['post_percent'])) { |
|
101 | + echo ' |
|
97 | 102 | <div class="bar" style="width: ', $member['post_percent'] + 4, 'px;"> |
98 | 103 | <div style="width: ', $member['post_percent'], 'px;"></div> |
99 | 104 | </div>'; |
105 | + } |
|
100 | 106 | |
101 | 107 | echo ' |
102 | 108 | </td>'; |
103 | 109 | } |
104 | 110 | |
105 | 111 | // Show custom fields marked to be shown here |
106 | - if (!empty($context['custom_profile_fields']['columns'])) |
|
107 | - foreach ($context['custom_profile_fields']['columns'] as $key => $column) |
|
112 | + if (!empty($context['custom_profile_fields']['columns'])) { |
|
113 | + foreach ($context['custom_profile_fields']['columns'] as $key => $column) |
|
108 | 114 | echo ' |
109 | 115 | <td class="centertext">', $member['options'][$key], '</td>'; |
116 | + } |
|
110 | 117 | |
111 | 118 | echo ' |
112 | 119 | </tr>'; |
113 | 120 | } |
114 | 121 | } |
115 | 122 | // No members? |
116 | - else |
|
117 | - echo ' |
|
123 | + else { |
|
124 | + echo ' |
|
118 | 125 | <tr> |
119 | 126 | <td colspan="', $context['colspan'], '" class="windowbg">', $txt['search_no_results'], '</td> |
120 | 127 | </tr>'; |
128 | + } |
|
121 | 129 | |
122 | 130 | echo ' |
123 | 131 | </tbody> |
@@ -130,11 +138,12 @@ discard block |
||
130 | 138 | <div class="pagelinks floatleft">', $context['page_index'], '</div>'; |
131 | 139 | |
132 | 140 | // If it is displaying the result of a search show a "search again" link to edit their criteria. |
133 | - if (isset($context['old_search'])) |
|
134 | - echo ' |
|
141 | + if (isset($context['old_search'])) { |
|
142 | + echo ' |
|
135 | 143 | <div class="buttonlist floatright"> |
136 | 144 | <a class="button" href="', $scripturl, '?action=mlist;sa=search;search=', $context['old_search_value'], '">', $txt['mlist_search_again'], '</a> |
137 | 145 | </div>'; |
146 | + } |
|
138 | 147 | echo ' |
139 | 148 | </div> |
140 | 149 | </div><!-- #memberlist -->'; |
@@ -174,12 +183,13 @@ discard block |
||
174 | 183 | <dd> |
175 | 184 | <ul>'; |
176 | 185 | |
177 | - foreach ($context['search_fields'] as $id => $title) |
|
178 | - echo ' |
|
186 | + foreach ($context['search_fields'] as $id => $title) { |
|
187 | + echo ' |
|
179 | 188 | <li> |
180 | 189 | <input type="checkbox" name="fields[]" id="fields-', $id, '" value="', $id, '"', in_array($id, $context['search_defaults']) ? ' checked' : '', '> |
181 | 190 | <label for="fields-', $id, '">', $title, '</label> |
182 | 191 | </li>'; |
192 | + } |
|
183 | 193 | |
184 | 194 | echo ' |
185 | 195 | </ul> |
@@ -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 | * Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off. |
@@ -44,22 +45,26 @@ discard block |
||
44 | 45 | unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']); |
45 | 46 | |
46 | 47 | // These keys shouldn't be set...ever. |
47 | - if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) |
|
48 | - die('Invalid request variable.'); |
|
48 | + if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) { |
|
49 | + die('Invalid request variable.'); |
|
50 | + } |
|
49 | 51 | |
50 | 52 | // Same goes for numeric keys. |
51 | - foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) |
|
52 | - if (is_numeric($key)) |
|
53 | + foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) { |
|
54 | + if (is_numeric($key)) |
|
53 | 55 | die('Numeric request keys are invalid.'); |
56 | + } |
|
54 | 57 | |
55 | 58 | // Numeric keys in cookies are less of a problem. Just unset those. |
56 | - foreach ($_COOKIE as $key => $value) |
|
57 | - if (is_numeric($key)) |
|
59 | + foreach ($_COOKIE as $key => $value) { |
|
60 | + if (is_numeric($key)) |
|
58 | 61 | unset($_COOKIE[$key]); |
62 | + } |
|
59 | 63 | |
60 | 64 | // Get the correct query string. It may be in an environment variable... |
61 | - if (!isset($_SERVER['QUERY_STRING'])) |
|
62 | - $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); |
|
65 | + if (!isset($_SERVER['QUERY_STRING'])) { |
|
66 | + $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); |
|
67 | + } |
|
63 | 68 | |
64 | 69 | // It seems that sticking a URL after the query string is mighty common, well, it's evil - don't. |
65 | 70 | if (strpos($_SERVER['QUERY_STRING'], 'http') === 0) |
@@ -83,13 +88,14 @@ discard block |
||
83 | 88 | parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET); |
84 | 89 | |
85 | 90 | // Magic quotes still applies with parse_str - so clean it up. |
86 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
87 | - $_GET = $removeMagicQuoteFunction($_GET); |
|
88 | - } |
|
89 | - elseif (strpos(ini_get('arg_separator.input'), ';') !== false) |
|
91 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
92 | + $_GET = $removeMagicQuoteFunction($_GET); |
|
93 | + } |
|
94 | + } elseif (strpos(ini_get('arg_separator.input'), ';') !== false) |
|
90 | 95 | { |
91 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
92 | - $_GET = $removeMagicQuoteFunction($_GET); |
|
96 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
97 | + $_GET = $removeMagicQuoteFunction($_GET); |
|
98 | + } |
|
93 | 99 | |
94 | 100 | // Search engines will send action=profile%3Bu=1, which confuses PHP. |
95 | 101 | foreach ($_GET as $k => $v) |
@@ -102,8 +108,9 @@ discard block |
||
102 | 108 | for ($i = 1, $n = count($temp); $i < $n; $i++) |
103 | 109 | { |
104 | 110 | @list ($key, $val) = @explode('=', $temp[$i], 2); |
105 | - if (!isset($_GET[$key])) |
|
106 | - $_GET[$key] = $val; |
|
111 | + if (!isset($_GET[$key])) { |
|
112 | + $_GET[$key] = $val; |
|
113 | + } |
|
107 | 114 | } |
108 | 115 | } |
109 | 116 | |
@@ -120,18 +127,20 @@ discard block |
||
120 | 127 | if (!empty($_SERVER['REQUEST_URI'])) |
121 | 128 | { |
122 | 129 | // Remove the .html, assuming there is one. |
123 | - if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') |
|
124 | - $request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.')); |
|
125 | - else |
|
126 | - $request = $_SERVER['REQUEST_URI']; |
|
130 | + if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') { |
|
131 | + $request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.')); |
|
132 | + } else { |
|
133 | + $request = $_SERVER['REQUEST_URI']; |
|
134 | + } |
|
127 | 135 | |
128 | 136 | // @todo smflib. |
129 | 137 | // Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET. |
130 | 138 | if (strpos($request, basename($scripturl) . '/') !== false) |
131 | 139 | { |
132 | 140 | parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp); |
133 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
134 | - $temp = $removeMagicQuoteFunction($temp); |
|
141 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
142 | + $temp = $removeMagicQuoteFunction($temp); |
|
143 | + } |
|
135 | 144 | $_GET += $temp; |
136 | 145 | } |
137 | 146 | } |
@@ -142,9 +151,10 @@ discard block |
||
142 | 151 | $_ENV = $removeMagicQuoteFunction($_ENV); |
143 | 152 | $_POST = $removeMagicQuoteFunction($_POST); |
144 | 153 | $_COOKIE = $removeMagicQuoteFunction($_COOKIE); |
145 | - foreach ($_FILES as $k => $dummy) |
|
146 | - if (isset($_FILES[$k]['name'])) |
|
154 | + foreach ($_FILES as $k => $dummy) { |
|
155 | + if (isset($_FILES[$k]['name'])) |
|
147 | 156 | $_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']); |
157 | + } |
|
148 | 158 | } |
149 | 159 | |
150 | 160 | // Add entities to GET. This is kinda like the slashes on everything else. |
@@ -160,11 +170,13 @@ discard block |
||
160 | 170 | $_REQUEST['board'] = (string) $_REQUEST['board']; |
161 | 171 | |
162 | 172 | // If there's a slash in it, we've got a start value! (old, compatible links.) |
163 | - if (strpos($_REQUEST['board'], '/') !== false) |
|
164 | - list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']); |
|
173 | + if (strpos($_REQUEST['board'], '/') !== false) { |
|
174 | + list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']); |
|
175 | + } |
|
165 | 176 | // Same idea, but dots. This is the currently used format - ?board=1.0... |
166 | - elseif (strpos($_REQUEST['board'], '.') !== false) |
|
167 | - list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']); |
|
177 | + elseif (strpos($_REQUEST['board'], '.') !== false) { |
|
178 | + list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']); |
|
179 | + } |
|
168 | 180 | // Now make absolutely sure it's a number. |
169 | 181 | $board = (int) $_REQUEST['board']; |
170 | 182 | $_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0; |
@@ -173,12 +185,14 @@ discard block |
||
173 | 185 | $_GET['board'] = $board; |
174 | 186 | } |
175 | 187 | // Well, $board is going to be a number no matter what. |
176 | - else |
|
177 | - $board = 0; |
|
188 | + else { |
|
189 | + $board = 0; |
|
190 | + } |
|
178 | 191 | |
179 | 192 | // If there's a threadid, it's probably an old YaBB SE link. Flow with it. |
180 | - if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) |
|
181 | - $_REQUEST['topic'] = $_REQUEST['threadid']; |
|
193 | + if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) { |
|
194 | + $_REQUEST['topic'] = $_REQUEST['threadid']; |
|
195 | + } |
|
182 | 196 | |
183 | 197 | // We've got topic! |
184 | 198 | if (isset($_REQUEST['topic'])) |
@@ -187,11 +201,13 @@ discard block |
||
187 | 201 | $_REQUEST['topic'] = (string) $_REQUEST['topic']; |
188 | 202 | |
189 | 203 | // Slash means old, beta style, formatting. That's okay though, the link should still work. |
190 | - if (strpos($_REQUEST['topic'], '/') !== false) |
|
191 | - list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']); |
|
204 | + if (strpos($_REQUEST['topic'], '/') !== false) { |
|
205 | + list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']); |
|
206 | + } |
|
192 | 207 | // Dots are useful and fun ;). This is ?topic=1.15. |
193 | - elseif (strpos($_REQUEST['topic'], '.') !== false) |
|
194 | - list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']); |
|
208 | + elseif (strpos($_REQUEST['topic'], '.') !== false) { |
|
209 | + list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']); |
|
210 | + } |
|
195 | 211 | |
196 | 212 | // Topic should always be an integer |
197 | 213 | $topic = $_GET['topic'] = $_REQUEST['topic'] = (int) $_REQUEST['topic']; |
@@ -225,21 +241,25 @@ discard block |
||
225 | 241 | $_REQUEST['start'] = $timestamp === 0 ? 0 : 'from' . $timestamp; |
226 | 242 | } |
227 | 243 | // ... or something invalid, in which case we reset it to 0. |
228 | - else |
|
229 | - $_REQUEST['start'] = 0; |
|
244 | + else { |
|
245 | + $_REQUEST['start'] = 0; |
|
246 | + } |
|
247 | + } else { |
|
248 | + $topic = 0; |
|
230 | 249 | } |
231 | - else |
|
232 | - $topic = 0; |
|
233 | 250 | |
234 | 251 | // There should be a $_REQUEST['start'], some at least. If you need to default to other than 0, use $_GET['start']. |
235 | - if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) |
|
236 | - $_REQUEST['start'] = 0; |
|
252 | + if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) { |
|
253 | + $_REQUEST['start'] = 0; |
|
254 | + } |
|
237 | 255 | |
238 | 256 | // The action needs to be a string and not an array or anything else |
239 | - if (isset($_REQUEST['action'])) |
|
240 | - $_REQUEST['action'] = (string) $_REQUEST['action']; |
|
241 | - if (isset($_GET['action'])) |
|
242 | - $_GET['action'] = (string) $_GET['action']; |
|
257 | + if (isset($_REQUEST['action'])) { |
|
258 | + $_REQUEST['action'] = (string) $_REQUEST['action']; |
|
259 | + } |
|
260 | + if (isset($_GET['action'])) { |
|
261 | + $_GET['action'] = (string) $_GET['action']; |
|
262 | + } |
|
243 | 263 | |
244 | 264 | // Some mail providers like to encode semicolons in activation URLs... |
245 | 265 | if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b') |
@@ -265,29 +285,33 @@ discard block |
||
265 | 285 | $_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR']; |
266 | 286 | |
267 | 287 | // If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do. |
268 | - if (!isset($modSettings['proxy_ip_header'])) |
|
269 | - $modSettings['proxy_ip_header'] = 'autodetect'; |
|
288 | + if (!isset($modSettings['proxy_ip_header'])) { |
|
289 | + $modSettings['proxy_ip_header'] = 'autodetect'; |
|
290 | + } |
|
270 | 291 | |
271 | 292 | // Which headers are we going to check for Reverse Proxy IP headers? |
272 | - if ($modSettings['proxy_ip_header'] == 'disabled') |
|
273 | - $reverseIPheaders = array(); |
|
274 | - elseif ($modSettings['proxy_ip_header'] == 'autodetect') |
|
275 | - $reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP'); |
|
276 | - else |
|
277 | - $reverseIPheaders = array($modSettings['proxy_ip_header']); |
|
293 | + if ($modSettings['proxy_ip_header'] == 'disabled') { |
|
294 | + $reverseIPheaders = array(); |
|
295 | + } elseif ($modSettings['proxy_ip_header'] == 'autodetect') { |
|
296 | + $reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP'); |
|
297 | + } else { |
|
298 | + $reverseIPheaders = array($modSettings['proxy_ip_header']); |
|
299 | + } |
|
278 | 300 | |
279 | 301 | // Find the user's IP address. (but don't let it give you 'unknown'!) |
280 | 302 | foreach ($reverseIPheaders as $proxyIPheader) |
281 | 303 | { |
282 | 304 | // Ignore if this is not set. |
283 | - if (!isset($_SERVER[$proxyIPheader])) |
|
284 | - continue; |
|
305 | + if (!isset($_SERVER[$proxyIPheader])) { |
|
306 | + continue; |
|
307 | + } |
|
285 | 308 | |
286 | 309 | if (!empty($modSettings['proxy_ip_servers'])) |
287 | 310 | { |
288 | - foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) |
|
289 | - if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy)) |
|
311 | + foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) { |
|
312 | + if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy)) |
|
290 | 313 | continue; |
314 | + } |
|
291 | 315 | } |
292 | 316 | |
293 | 317 | // If there are commas, get the last one.. probably. |
@@ -307,8 +331,9 @@ discard block |
||
307 | 331 | |
308 | 332 | // Just incase we have a legacy IPv4 address. |
309 | 333 | // @ TODO: Convert to IPv6. |
310 | - if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) |
|
311 | - continue; |
|
334 | + if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) { |
|
335 | + continue; |
|
336 | + } |
|
312 | 337 | } |
313 | 338 | |
314 | 339 | continue; |
@@ -320,36 +345,40 @@ discard block |
||
320 | 345 | } |
321 | 346 | } |
322 | 347 | // Otherwise just use the only one. |
323 | - elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) |
|
324 | - $_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader]; |
|
325 | - elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0) |
|
348 | + elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) { |
|
349 | + $_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader]; |
|
350 | + } elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0) |
|
326 | 351 | { |
327 | 352 | $_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]); |
328 | 353 | |
329 | 354 | // Just incase we have a legacy IPv4 address. |
330 | 355 | // @ TODO: Convert to IPv6. |
331 | - if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) |
|
332 | - continue; |
|
356 | + if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) { |
|
357 | + continue; |
|
358 | + } |
|
333 | 359 | } |
334 | 360 | } |
335 | 361 | |
336 | 362 | // Make sure we know the URL of the current request. |
337 | - if (empty($_SERVER['REQUEST_URI'])) |
|
338 | - $_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''); |
|
339 | - elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) |
|
340 | - $_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI']; |
|
341 | - else |
|
342 | - $_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI']; |
|
363 | + if (empty($_SERVER['REQUEST_URI'])) { |
|
364 | + $_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''); |
|
365 | + } elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) { |
|
366 | + $_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI']; |
|
367 | + } else { |
|
368 | + $_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI']; |
|
369 | + } |
|
343 | 370 | |
344 | 371 | // And make sure HTTP_USER_AGENT is set. |
345 | 372 | $_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : ''; |
346 | 373 | |
347 | 374 | // Some final checking. |
348 | - if (!isValidIP($_SERVER['BAN_CHECK_IP'])) |
|
349 | - $_SERVER['BAN_CHECK_IP'] = ''; |
|
350 | - if ($_SERVER['REMOTE_ADDR'] == 'unknown') |
|
351 | - $_SERVER['REMOTE_ADDR'] = ''; |
|
352 | -} |
|
375 | + if (!isValidIP($_SERVER['BAN_CHECK_IP'])) { |
|
376 | + $_SERVER['BAN_CHECK_IP'] = ''; |
|
377 | + } |
|
378 | + if ($_SERVER['REMOTE_ADDR'] == 'unknown') { |
|
379 | + $_SERVER['REMOTE_ADDR'] = ''; |
|
380 | + } |
|
381 | + } |
|
353 | 382 | |
354 | 383 | /** |
355 | 384 | * Validates a IPv6 address. returns true if it is ipv6. |
@@ -360,8 +389,9 @@ discard block |
||
360 | 389 | function isValidIPv6($ip) |
361 | 390 | { |
362 | 391 | //looking for : |
363 | - if (strpos($ip, ':') === false) |
|
364 | - return false; |
|
392 | + if (strpos($ip, ':') === false) { |
|
393 | + return false; |
|
394 | + } |
|
365 | 395 | |
366 | 396 | //check valid address |
367 | 397 | return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); |
@@ -379,8 +409,9 @@ discard block |
||
379 | 409 | static $converted = array(); |
380 | 410 | |
381 | 411 | // Check if we have done this already. |
382 | - if (isset($converted[$addr])) |
|
383 | - return $converted[$addr]; |
|
412 | + if (isset($converted[$addr])) { |
|
413 | + return $converted[$addr]; |
|
414 | + } |
|
384 | 415 | |
385 | 416 | // Check if there are segments missing, insert if necessary. |
386 | 417 | if (strpos($addr, '::') !== false) |
@@ -390,18 +421,20 @@ discard block |
||
390 | 421 | $part[1] = explode(':', $part[1]); |
391 | 422 | $missing = array(); |
392 | 423 | |
393 | - for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) |
|
394 | - array_push($missing, '0000'); |
|
424 | + for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) { |
|
425 | + array_push($missing, '0000'); |
|
426 | + } |
|
395 | 427 | |
396 | 428 | $part = array_merge($part[0], $missing, $part[1]); |
429 | + } else { |
|
430 | + $part = explode(':', $addr); |
|
397 | 431 | } |
398 | - else |
|
399 | - $part = explode(':', $addr); |
|
400 | 432 | |
401 | 433 | // Pad each segment until it has 4 digits. |
402 | - foreach ($part as &$p) |
|
403 | - while (strlen($p) < 4) |
|
434 | + foreach ($part as &$p) { |
|
435 | + while (strlen($p) < 4) |
|
404 | 436 | $p = '0' . $p; |
437 | + } |
|
405 | 438 | |
406 | 439 | unset($p); |
407 | 440 | |
@@ -412,11 +445,12 @@ discard block |
||
412 | 445 | $converted[$addr] = $result; |
413 | 446 | |
414 | 447 | // Quick check to make sure the length is as expected. |
415 | - if (!$strict_check || strlen($result) == 39) |
|
416 | - return $result; |
|
417 | - else |
|
418 | - return false; |
|
419 | -} |
|
448 | + if (!$strict_check || strlen($result) == 39) { |
|
449 | + return $result; |
|
450 | + } else { |
|
451 | + return false; |
|
452 | + } |
|
453 | + } |
|
420 | 454 | |
421 | 455 | |
422 | 456 | /** |
@@ -434,8 +468,9 @@ discard block |
||
434 | 468 | //v6? |
435 | 469 | if ((strpos($cidr_network, ':') !== false)) |
436 | 470 | { |
437 | - if (!filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) || !filter_var($cidr_network, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) |
|
438 | - return false; |
|
471 | + if (!filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) || !filter_var($cidr_network, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
|
472 | + return false; |
|
473 | + } |
|
439 | 474 | |
440 | 475 | $ip_address = inet_pton($ip_address); |
441 | 476 | $cidr_network = inet_pton($cidr_network); |
@@ -457,10 +492,10 @@ discard block |
||
457 | 492 | $binMask = pack("H*" , $binMask); |
458 | 493 | |
459 | 494 | return ($ip_address & $binMask) == $cidr_network; |
495 | + } else { |
|
496 | + return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network); |
|
497 | + } |
|
460 | 498 | } |
461 | - else |
|
462 | - return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network); |
|
463 | -} |
|
464 | 499 | |
465 | 500 | /** |
466 | 501 | * Adds slashes to the array/variable. |
@@ -476,15 +511,17 @@ discard block |
||
476 | 511 | { |
477 | 512 | global $smcFunc; |
478 | 513 | |
479 | - if (!is_array($var)) |
|
480 | - return $smcFunc['db_escape_string']($var); |
|
514 | + if (!is_array($var)) { |
|
515 | + return $smcFunc['db_escape_string']($var); |
|
516 | + } |
|
481 | 517 | |
482 | 518 | // Reindex the array with slashes. |
483 | 519 | $new_var = array(); |
484 | 520 | |
485 | 521 | // Add slashes to every element, even the indexes! |
486 | - foreach ($var as $k => $v) |
|
487 | - $new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v); |
|
522 | + foreach ($var as $k => $v) { |
|
523 | + $new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v); |
|
524 | + } |
|
488 | 525 | |
489 | 526 | return $new_var; |
490 | 527 | } |
@@ -504,12 +541,14 @@ discard block |
||
504 | 541 | { |
505 | 542 | global $smcFunc; |
506 | 543 | |
507 | - if (!is_array($var)) |
|
508 | - return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES); |
|
544 | + if (!is_array($var)) { |
|
545 | + return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES); |
|
546 | + } |
|
509 | 547 | |
510 | 548 | // Add the htmlspecialchars to every element. |
511 | - foreach ($var as $k => $v) |
|
512 | - $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1); |
|
549 | + foreach ($var as $k => $v) { |
|
550 | + $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1); |
|
551 | + } |
|
513 | 552 | |
514 | 553 | return $var; |
515 | 554 | } |
@@ -527,15 +566,17 @@ discard block |
||
527 | 566 | */ |
528 | 567 | function urldecode__recursive($var, $level = 0) |
529 | 568 | { |
530 | - if (!is_array($var)) |
|
531 | - return urldecode($var); |
|
569 | + if (!is_array($var)) { |
|
570 | + return urldecode($var); |
|
571 | + } |
|
532 | 572 | |
533 | 573 | // Reindex the array... |
534 | 574 | $new_var = array(); |
535 | 575 | |
536 | 576 | // Add the htmlspecialchars to every element. |
537 | - foreach ($var as $k => $v) |
|
538 | - $new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1); |
|
577 | + foreach ($var as $k => $v) { |
|
578 | + $new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1); |
|
579 | + } |
|
539 | 580 | |
540 | 581 | return $new_var; |
541 | 582 | } |
@@ -553,15 +594,17 @@ discard block |
||
553 | 594 | { |
554 | 595 | global $smcFunc; |
555 | 596 | |
556 | - if (!is_array($var)) |
|
557 | - return $smcFunc['db_unescape_string']($var); |
|
597 | + if (!is_array($var)) { |
|
598 | + return $smcFunc['db_unescape_string']($var); |
|
599 | + } |
|
558 | 600 | |
559 | 601 | // Reindex the array without slashes, this time. |
560 | 602 | $new_var = array(); |
561 | 603 | |
562 | 604 | // Strip the slashes from every element. |
563 | - foreach ($var as $k => $v) |
|
564 | - $new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v); |
|
605 | + foreach ($var as $k => $v) { |
|
606 | + $new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v); |
|
607 | + } |
|
565 | 608 | |
566 | 609 | return $new_var; |
567 | 610 | } |
@@ -579,15 +622,17 @@ discard block |
||
579 | 622 | */ |
580 | 623 | function stripslashes__recursive($var, $level = 0) |
581 | 624 | { |
582 | - if (!is_array($var)) |
|
583 | - return stripslashes($var); |
|
625 | + if (!is_array($var)) { |
|
626 | + return stripslashes($var); |
|
627 | + } |
|
584 | 628 | |
585 | 629 | // Reindex the array without slashes, this time. |
586 | 630 | $new_var = array(); |
587 | 631 | |
588 | 632 | // Strip the slashes from every element. |
589 | - foreach ($var as $k => $v) |
|
590 | - $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1); |
|
633 | + foreach ($var as $k => $v) { |
|
634 | + $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1); |
|
635 | + } |
|
591 | 636 | |
592 | 637 | return $new_var; |
593 | 638 | } |
@@ -608,12 +653,14 @@ discard block |
||
608 | 653 | global $smcFunc; |
609 | 654 | |
610 | 655 | // Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160) |
611 | - if (!is_array($var)) |
|
612 | - return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0"); |
|
656 | + if (!is_array($var)) { |
|
657 | + return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0"); |
|
658 | + } |
|
613 | 659 | |
614 | 660 | // Go through all the elements and remove the whitespace. |
615 | - foreach ($var as $k => $v) |
|
616 | - $var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1); |
|
661 | + foreach ($var as $k => $v) { |
|
662 | + $var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1); |
|
663 | + } |
|
617 | 664 | |
618 | 665 | return $var; |
619 | 666 | } |
@@ -678,30 +725,37 @@ discard block |
||
678 | 725 | global $scripturl, $modSettings, $context; |
679 | 726 | |
680 | 727 | // If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit. |
681 | - if ($scripturl == '' || !defined('SID')) |
|
682 | - return $buffer; |
|
728 | + if ($scripturl == '' || !defined('SID')) { |
|
729 | + return $buffer; |
|
730 | + } |
|
683 | 731 | |
684 | 732 | // Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit(). This doesn't work below PHP 4.3.0, because it makes the output buffer bigger. |
685 | 733 | // @todo smflib |
686 | - if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) |
|
687 | - $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); |
|
734 | + if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) { |
|
735 | + $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); |
|
736 | + } |
|
688 | 737 | // Debugging templates, are we? |
689 | - elseif (isset($_GET['debug'])) |
|
690 | - $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer); |
|
738 | + elseif (isset($_GET['debug'])) { |
|
739 | + $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer); |
|
740 | + } |
|
691 | 741 | |
692 | 742 | // This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo. |
693 | 743 | if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed'])) |
694 | 744 | { |
695 | 745 | // Let's do something special for session ids! |
696 | - if (defined('SID') && SID != '') |
|
697 | - $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
746 | + if (defined('SID') && SID != '') { |
|
747 | + $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
698 | 748 | { |
699 | - global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"'; |
|
749 | + global $scripturl; |
|
750 | + } |
|
751 | + return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"'; |
|
700 | 752 | }, $buffer); |
701 | - else |
|
702 | - $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
753 | + else { |
|
754 | + $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
703 | 755 | { |
704 | - global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"'; |
|
756 | + global $scripturl; |
|
757 | + } |
|
758 | + return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"'; |
|
705 | 759 | }, $buffer); |
706 | 760 | } |
707 | 761 |
@@ -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 | * Scheduled tasks management dispatcher. This function checks permissions and delegates |
@@ -41,10 +42,11 @@ discard block |
||
41 | 42 | ); |
42 | 43 | |
43 | 44 | // We need to find what's the action. |
44 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
45 | - $context['sub_action'] = $_REQUEST['sa']; |
|
46 | - else |
|
47 | - $context['sub_action'] = 'tasks'; |
|
45 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
46 | + $context['sub_action'] = $_REQUEST['sa']; |
|
47 | + } else { |
|
48 | + $context['sub_action'] = 'tasks'; |
|
49 | + } |
|
48 | 50 | |
49 | 51 | // Now for the lovely tabs. That we all love. |
50 | 52 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -94,9 +96,10 @@ discard block |
||
94 | 96 | |
95 | 97 | // Enable and disable as required. |
96 | 98 | $enablers = array(0); |
97 | - foreach ($_POST['enable_task'] as $id => $enabled) |
|
98 | - if ($enabled) |
|
99 | + foreach ($_POST['enable_task'] as $id => $enabled) { |
|
100 | + if ($enabled) |
|
99 | 101 | $enablers[] = (int) $id; |
102 | + } |
|
100 | 103 | |
101 | 104 | // Do the update! |
102 | 105 | $smcFunc['db_query']('', ' |
@@ -134,8 +137,9 @@ discard block |
||
134 | 137 | |
135 | 138 | // Lets figure out which ones they want to run. |
136 | 139 | $tasks = array(); |
137 | - foreach ($_POST['run_task'] as $task => $dummy) |
|
138 | - $tasks[] = (int) $task; |
|
140 | + foreach ($_POST['run_task'] as $task => $dummy) { |
|
141 | + $tasks[] = (int) $task; |
|
142 | + } |
|
139 | 143 | |
140 | 144 | // Load up the tasks. |
141 | 145 | $request = $smcFunc['db_query']('', ' |
@@ -155,36 +159,41 @@ discard block |
||
155 | 159 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
156 | 160 | { |
157 | 161 | // What kind of task are we handling? |
158 | - if (!empty($row['callable'])) |
|
159 | - $task_string = $row['callable']; |
|
162 | + if (!empty($row['callable'])) { |
|
163 | + $task_string = $row['callable']; |
|
164 | + } |
|
160 | 165 | |
161 | 166 | // Default SMF task or old mods? |
162 | - elseif (function_exists('scheduled_' . $row['task'])) |
|
163 | - $task_string = 'scheduled_' . $row['task']; |
|
167 | + elseif (function_exists('scheduled_' . $row['task'])) { |
|
168 | + $task_string = 'scheduled_' . $row['task']; |
|
169 | + } |
|
164 | 170 | |
165 | 171 | // One last resource, the task name. |
166 | - elseif (!empty($row['task'])) |
|
167 | - $task_string = $row['task']; |
|
172 | + elseif (!empty($row['task'])) { |
|
173 | + $task_string = $row['task']; |
|
174 | + } |
|
168 | 175 | |
169 | 176 | $start_time = microtime(); |
170 | 177 | // The functions got to exist for us to use it. |
171 | - if (empty($task_string)) |
|
172 | - continue; |
|
178 | + if (empty($task_string)) { |
|
179 | + continue; |
|
180 | + } |
|
173 | 181 | |
174 | 182 | // Try to stop a timeout, this would be bad... |
175 | 183 | @set_time_limit(300); |
176 | - if (function_exists('apache_reset_timeout')) |
|
177 | - @apache_reset_timeout(); |
|
184 | + if (function_exists('apache_reset_timeout')) { |
|
185 | + @apache_reset_timeout(); |
|
186 | + } |
|
178 | 187 | |
179 | 188 | // Get the callable. |
180 | 189 | $callable_task = call_helper($task_string, true); |
181 | 190 | |
182 | 191 | // Perform the task. |
183 | - if (!empty($callable_task)) |
|
184 | - $completed = call_user_func($callable_task); |
|
185 | - |
|
186 | - else |
|
187 | - $completed = false; |
|
192 | + if (!empty($callable_task)) { |
|
193 | + $completed = call_user_func($callable_task); |
|
194 | + } else { |
|
195 | + $completed = false; |
|
196 | + } |
|
188 | 197 | |
189 | 198 | // Log that we did it ;) |
190 | 199 | if ($completed) |
@@ -201,8 +210,9 @@ discard block |
||
201 | 210 | $smcFunc['db_free_result']($request); |
202 | 211 | |
203 | 212 | // If we had any errors, push them to session so we can pick them up next time to tell the user. |
204 | - if (!empty($context['scheduled_errors'])) |
|
205 | - $_SESSION['st_error'] = $context['scheduled_errors']; |
|
213 | + if (!empty($context['scheduled_errors'])) { |
|
214 | + $_SESSION['st_error'] = $context['scheduled_errors']; |
|
215 | + } |
|
206 | 216 | |
207 | 217 | redirectexit('action=admin;area=scheduledtasks;done'); |
208 | 218 | } |
@@ -374,8 +384,9 @@ discard block |
||
374 | 384 | $context['server_time'] = timeformat(time(), false, 'server'); |
375 | 385 | |
376 | 386 | // Cleaning... |
377 | - if (!isset($_GET['tid'])) |
|
378 | - fatal_lang_error('no_access', false); |
|
387 | + if (!isset($_GET['tid'])) { |
|
388 | + fatal_lang_error('no_access', false); |
|
389 | + } |
|
379 | 390 | $_GET['tid'] = (int) $_GET['tid']; |
380 | 391 | |
381 | 392 | // Saving? |
@@ -391,10 +402,12 @@ discard block |
||
391 | 402 | preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches); |
392 | 403 | |
393 | 404 | // If a half is empty then assume zero offset! |
394 | - if (!isset($matches[2]) || $matches[2] > 59) |
|
395 | - $matches[2] = 0; |
|
396 | - if (!isset($matches[1]) || $matches[1] > 23) |
|
397 | - $matches[1] = 0; |
|
405 | + if (!isset($matches[2]) || $matches[2] > 59) { |
|
406 | + $matches[2] = 0; |
|
407 | + } |
|
408 | + if (!isset($matches[1]) || $matches[1] > 23) { |
|
409 | + $matches[1] = 0; |
|
410 | + } |
|
398 | 411 | |
399 | 412 | // Now the offset is easy; easy peasy - except we need to offset by a few hours... |
400 | 413 | $offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z'); |
@@ -404,8 +417,9 @@ discard block |
||
404 | 417 | $unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd'; |
405 | 418 | |
406 | 419 | // Don't allow one minute intervals. |
407 | - if ($interval == 1 && $unit == 'm') |
|
408 | - $interval = 2; |
|
420 | + if ($interval == 1 && $unit == 'm') { |
|
421 | + $interval = 2; |
|
422 | + } |
|
409 | 423 | |
410 | 424 | // Is it disabled? |
411 | 425 | $disabled = !isset($_POST['enabled']) ? 1 : 0; |
@@ -443,8 +457,9 @@ discard block |
||
443 | 457 | ); |
444 | 458 | |
445 | 459 | // Should never, ever, happen! |
446 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
447 | - fatal_lang_error('no_access', false); |
|
460 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
461 | + fatal_lang_error('no_access', false); |
|
462 | + } |
|
448 | 463 | |
449 | 464 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
450 | 465 | { |
@@ -602,13 +617,14 @@ discard block |
||
602 | 617 | ) |
603 | 618 | ); |
604 | 619 | $log_entries = array(); |
605 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
606 | - $log_entries[] = array( |
|
620 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
621 | + $log_entries[] = array( |
|
607 | 622 | 'id' => $row['id_log'], |
608 | 623 | 'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'], |
609 | 624 | 'time_run' => $row['time_run'], |
610 | 625 | 'time_taken' => $row['time_taken'], |
611 | 626 | ); |
627 | + } |
|
612 | 628 | $smcFunc['db_free_result']($request); |
613 | 629 | |
614 | 630 | return $log_entries; |
@@ -649,8 +665,9 @@ discard block |
||
649 | 665 | |
650 | 666 | call_integration_hook('integrate_scheduled_tasks_settings', array(&$config_vars)); |
651 | 667 | |
652 | - if ($return_config) |
|
653 | - return $config_vars; |
|
668 | + if ($return_config) { |
|
669 | + return $config_vars; |
|
670 | + } |
|
654 | 671 | |
655 | 672 | // Set up the template. |
656 | 673 | $context['page_title'] = $txt['scheduled_tasks_settings']; |
@@ -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 | * Begin the registration process. |
@@ -29,19 +30,23 @@ discard block |
||
29 | 30 | global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile; |
30 | 31 | |
31 | 32 | // Is this an incoming AJAX check? |
32 | - if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') |
|
33 | - return RegisterCheckUsername(); |
|
33 | + if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') { |
|
34 | + return RegisterCheckUsername(); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | // Check if the administrator has it disabled. |
36 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') |
|
37 | - fatal_lang_error('registration_disabled', false); |
|
38 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') { |
|
39 | + fatal_lang_error('registration_disabled', false); |
|
40 | + } |
|
38 | 41 | |
39 | 42 | // If this user is an admin - redirect them to the admin registration page. |
40 | - if (allowedTo('moderate_forum') && !$user_info['is_guest']) |
|
41 | - redirectexit('action=admin;area=regcenter;sa=register'); |
|
43 | + if (allowedTo('moderate_forum') && !$user_info['is_guest']) { |
|
44 | + redirectexit('action=admin;area=regcenter;sa=register'); |
|
45 | + } |
|
42 | 46 | // You are not a guest, so you are a member - and members don't get to register twice! |
43 | - elseif (empty($user_info['is_guest'])) |
|
44 | - redirectexit(); |
|
47 | + elseif (empty($user_info['is_guest'])) { |
|
48 | + redirectexit(); |
|
49 | + } |
|
45 | 50 | |
46 | 51 | loadLanguage('Login'); |
47 | 52 | loadTemplate('Register'); |
@@ -82,16 +87,18 @@ discard block |
||
82 | 87 | } |
83 | 88 | } |
84 | 89 | // Make sure they don't squeeze through without agreeing. |
85 | - elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) |
|
86 | - $current_step = 1; |
|
90 | + elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) { |
|
91 | + $current_step = 1; |
|
92 | + } |
|
87 | 93 | |
88 | 94 | // Show the user the right form. |
89 | 95 | $context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form'; |
90 | 96 | $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form']; |
91 | 97 | |
92 | 98 | // Kinda need this. |
93 | - if ($context['sub_template'] == 'registration_form') |
|
94 | - loadJavaScriptFile('register.js', array('defer' => false, 'minimize' => true), 'smf_register'); |
|
99 | + if ($context['sub_template'] == 'registration_form') { |
|
100 | + loadJavaScriptFile('register.js', array('defer' => false, 'minimize' => true), 'smf_register'); |
|
101 | + } |
|
95 | 102 | |
96 | 103 | // Add the register chain to the link tree. |
97 | 104 | $context['linktree'][] = array( |
@@ -100,24 +107,26 @@ discard block |
||
100 | 107 | ); |
101 | 108 | |
102 | 109 | // Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one. |
103 | - if (!isset($_SESSION['register'])) |
|
104 | - $_SESSION['register'] = array( |
|
110 | + if (!isset($_SESSION['register'])) { |
|
111 | + $_SESSION['register'] = array( |
|
105 | 112 | 'timenow' => time(), |
106 | 113 | 'limit' => 10, // minimum number of seconds required on this page for registration |
107 | 114 | ); |
108 | - else |
|
109 | - $_SESSION['register']['timenow'] = time(); |
|
115 | + } else { |
|
116 | + $_SESSION['register']['timenow'] = time(); |
|
117 | + } |
|
110 | 118 | |
111 | 119 | // If you have to agree to the agreement, it needs to be fetched from the file. |
112 | 120 | if ($context['require_agreement']) |
113 | 121 | { |
114 | 122 | // Have we got a localized one? |
115 | - if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) |
|
116 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
117 | - elseif (file_exists($boarddir . '/agreement.txt')) |
|
118 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
119 | - else |
|
120 | - $context['agreement'] = ''; |
|
123 | + if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { |
|
124 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
125 | + } elseif (file_exists($boarddir . '/agreement.txt')) { |
|
126 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
127 | + } else { |
|
128 | + $context['agreement'] = ''; |
|
129 | + } |
|
121 | 130 | |
122 | 131 | // Nothing to show, lets disable registration and inform the admin of this error |
123 | 132 | if (empty($context['agreement'])) |
@@ -133,8 +142,9 @@ discard block |
||
133 | 142 | $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language']; |
134 | 143 | |
135 | 144 | // Do we have any languages? |
136 | - if (empty($context['languages'])) |
|
137 | - getLanguages(); |
|
145 | + if (empty($context['languages'])) { |
|
146 | + getLanguages(); |
|
147 | + } |
|
138 | 148 | |
139 | 149 | // Try to find our selected language. |
140 | 150 | foreach ($context['languages'] as $key => $lang) |
@@ -142,8 +152,9 @@ discard block |
||
142 | 152 | $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => '')); |
143 | 153 | |
144 | 154 | // Found it! |
145 | - if ($selectedLanguage == $lang['filename']) |
|
146 | - $context['languages'][$key]['selected'] = true; |
|
155 | + if ($selectedLanguage == $lang['filename']) { |
|
156 | + $context['languages'][$key]['selected'] = true; |
|
157 | + } |
|
147 | 158 | } |
148 | 159 | } |
149 | 160 | |
@@ -170,16 +181,19 @@ discard block |
||
170 | 181 | if (in_array('website', $reg_fields)) |
171 | 182 | { |
172 | 183 | unset($reg_fields['website']); |
173 | - if (isset($_POST['website_title'])) |
|
174 | - $cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']); |
|
175 | - if (isset($_POST['website_url'])) |
|
176 | - $cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']); |
|
184 | + if (isset($_POST['website_title'])) { |
|
185 | + $cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']); |
|
186 | + } |
|
187 | + if (isset($_POST['website_url'])) { |
|
188 | + $cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']); |
|
189 | + } |
|
177 | 190 | } |
178 | 191 | |
179 | 192 | // We might have had some submissions on this front - go check. |
180 | - foreach ($reg_fields as $field) |
|
181 | - if (isset($_POST[$field])) |
|
193 | + foreach ($reg_fields as $field) { |
|
194 | + if (isset($_POST[$field])) |
|
182 | 195 | $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]); |
196 | + } |
|
183 | 197 | |
184 | 198 | // Load all the fields in question. |
185 | 199 | setupProfileContext($reg_fields); |
@@ -196,8 +210,9 @@ discard block |
||
196 | 210 | $context['visual_verification_id'] = $verificationOptions['id']; |
197 | 211 | } |
198 | 212 | // Otherwise we have nothing to show. |
199 | - else |
|
200 | - $context['visual_verification'] = false; |
|
213 | + else { |
|
214 | + $context['visual_verification'] = false; |
|
215 | + } |
|
201 | 216 | |
202 | 217 | |
203 | 218 | $context += array( |
@@ -208,8 +223,9 @@ discard block |
||
208 | 223 | |
209 | 224 | // Were there any errors? |
210 | 225 | $context['registration_errors'] = array(); |
211 | - if (!empty($reg_errors)) |
|
212 | - $context['registration_errors'] = $reg_errors; |
|
226 | + if (!empty($reg_errors)) { |
|
227 | + $context['registration_errors'] = $reg_errors; |
|
228 | + } |
|
213 | 229 | |
214 | 230 | createToken('register'); |
215 | 231 | } |
@@ -226,27 +242,32 @@ discard block |
||
226 | 242 | validateToken('register'); |
227 | 243 | |
228 | 244 | // Check to ensure we're forcing SSL for authentication |
229 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
230 | - fatal_lang_error('register_ssl_required'); |
|
245 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
246 | + fatal_lang_error('register_ssl_required'); |
|
247 | + } |
|
231 | 248 | |
232 | 249 | // Start collecting together any errors. |
233 | 250 | $reg_errors = array(); |
234 | 251 | |
235 | 252 | // You can't register if it's disabled. |
236 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) |
|
237 | - fatal_lang_error('registration_disabled', false); |
|
253 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { |
|
254 | + fatal_lang_error('registration_disabled', false); |
|
255 | + } |
|
238 | 256 | |
239 | 257 | // Well, if you don't agree, you can't register. |
240 | - if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) |
|
241 | - redirectexit(); |
|
258 | + if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) { |
|
259 | + redirectexit(); |
|
260 | + } |
|
242 | 261 | |
243 | 262 | // Make sure they came from *somewhere*, have a session. |
244 | - if (!isset($_SESSION['old_url'])) |
|
245 | - redirectexit('action=signup'); |
|
263 | + if (!isset($_SESSION['old_url'])) { |
|
264 | + redirectexit('action=signup'); |
|
265 | + } |
|
246 | 266 | |
247 | 267 | // If we don't require an agreement, we need a extra check for coppa. |
248 | - if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) |
|
249 | - $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
268 | + if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) { |
|
269 | + $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
270 | + } |
|
250 | 271 | // Are they under age, and under age users are banned? |
251 | 272 | if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) |
252 | 273 | { |
@@ -255,8 +276,9 @@ discard block |
||
255 | 276 | } |
256 | 277 | |
257 | 278 | // Check the time gate for miscreants. First make sure they came from somewhere that actually set it up. |
258 | - if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) |
|
259 | - redirectexit('action=signup'); |
|
279 | + if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) { |
|
280 | + redirectexit('action=signup'); |
|
281 | + } |
|
260 | 282 | // Failing that, check the time on it. |
261 | 283 | if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit']) |
262 | 284 | { |
@@ -276,8 +298,9 @@ discard block |
||
276 | 298 | if (is_array($context['visual_verification'])) |
277 | 299 | { |
278 | 300 | loadLanguage('Errors'); |
279 | - foreach ($context['visual_verification'] as $error) |
|
280 | - $reg_errors[] = $txt['error_' . $error]; |
|
301 | + foreach ($context['visual_verification'] as $error) { |
|
302 | + $reg_errors[] = $txt['error_' . $error]; |
|
303 | + } |
|
281 | 304 | } |
282 | 305 | } |
283 | 306 | |
@@ -286,14 +309,16 @@ discard block |
||
286 | 309 | if (!is_array($_POST[$key])) |
287 | 310 | { |
288 | 311 | // For UTF-8, replace any kind of space with a normal space, and remove any kind of control character (incl. "\n" and "\r"), then trim. |
289 | - if ($context['utf8']) |
|
290 | - $_POST[$key] = $smcFunc['htmltrim'](preg_replace(array('~\p{Z}+~u', '~\p{C}+~u'), array(' ', ''), $_POST[$key])); |
|
312 | + if ($context['utf8']) { |
|
313 | + $_POST[$key] = $smcFunc['htmltrim'](preg_replace(array('~\p{Z}+~u', '~\p{C}+~u'), array(' ', ''), $_POST[$key])); |
|
314 | + } |
|
291 | 315 | // Otherwise, just remove "\n" and "\r", then trim. |
292 | - else |
|
293 | - $_POST[$key] = $smcFunc['htmltrim'](str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
316 | + else { |
|
317 | + $_POST[$key] = $smcFunc['htmltrim'](str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
318 | + } |
|
319 | + } else { |
|
320 | + $_POST[$key] = htmltrim__recursive($_POST[$key]); |
|
294 | 321 | } |
295 | - else |
|
296 | - $_POST[$key] = htmltrim__recursive($_POST[$key]); |
|
297 | 322 | } |
298 | 323 | |
299 | 324 | // Collect all extra registration fields someone might have filled in. |
@@ -328,13 +353,15 @@ discard block |
||
328 | 353 | $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
329 | 354 | |
330 | 355 | // Make sure their website URL is squeaky clean |
331 | - if (isset($_POST['website_url'])) |
|
332 | - $_POST['website_url'] = (string) validate_iri(sanitize_iri($_POST['website_url'])); |
|
356 | + if (isset($_POST['website_url'])) { |
|
357 | + $_POST['website_url'] = (string) validate_iri(sanitize_iri($_POST['website_url'])); |
|
358 | + } |
|
333 | 359 | } |
334 | 360 | } |
335 | 361 | |
336 | - if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') |
|
337 | - $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
362 | + if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') { |
|
363 | + $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
364 | + } |
|
338 | 365 | |
339 | 366 | // Needed for isReservedName() and registerMember(). |
340 | 367 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -343,8 +370,9 @@ discard block |
||
343 | 370 | if (isset($_POST['real_name'])) |
344 | 371 | { |
345 | 372 | // Are you already allowed to edit the displayed name? |
346 | - if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) |
|
347 | - $canEditDisplayName = true; |
|
373 | + if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) { |
|
374 | + $canEditDisplayName = true; |
|
375 | + } |
|
348 | 376 | |
349 | 377 | // If you are a guest, will you be allowed to once you register? |
350 | 378 | else |
@@ -363,32 +391,37 @@ discard block |
||
363 | 391 | } |
364 | 392 | |
365 | 393 | // Only set it if you can and if we are sure it is good |
366 | - if ($canEditDisplayName && $smcFunc['htmltrim']($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) |
|
367 | - $possible_strings[] = 'real_name'; |
|
394 | + if ($canEditDisplayName && $smcFunc['htmltrim']($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) { |
|
395 | + $possible_strings[] = 'real_name'; |
|
396 | + } |
|
368 | 397 | } |
369 | 398 | |
370 | 399 | // Handle a string as a birthdate... |
371 | - if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') |
|
372 | - $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
400 | + if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') { |
|
401 | + $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
402 | + } |
|
373 | 403 | // Or birthdate parts... |
374 | - elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) |
|
375 | - $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
404 | + elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) { |
|
405 | + $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
406 | + } |
|
376 | 407 | |
377 | 408 | // Validate the passed language file. |
378 | 409 | if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage'])) |
379 | 410 | { |
380 | 411 | // Do we have any languages? |
381 | - if (empty($context['languages'])) |
|
382 | - getLanguages(); |
|
412 | + if (empty($context['languages'])) { |
|
413 | + getLanguages(); |
|
414 | + } |
|
383 | 415 | |
384 | 416 | // Did we find it? |
385 | - if (isset($context['languages'][$_POST['lngfile']])) |
|
386 | - $_SESSION['language'] = $_POST['lngfile']; |
|
387 | - else |
|
417 | + if (isset($context['languages'][$_POST['lngfile']])) { |
|
418 | + $_SESSION['language'] = $_POST['lngfile']; |
|
419 | + } else { |
|
420 | + unset($_POST['lngfile']); |
|
421 | + } |
|
422 | + } else { |
|
388 | 423 | unset($_POST['lngfile']); |
389 | 424 | } |
390 | - else |
|
391 | - unset($_POST['lngfile']); |
|
392 | 425 | |
393 | 426 | // Set the options needed for registration. |
394 | 427 | $regOptions = array( |
@@ -408,22 +441,27 @@ discard block |
||
408 | 441 | ); |
409 | 442 | |
410 | 443 | // Include the additional options that might have been filled in. |
411 | - foreach ($possible_strings as $var) |
|
412 | - if (isset($_POST[$var])) |
|
444 | + foreach ($possible_strings as $var) { |
|
445 | + if (isset($_POST[$var])) |
|
413 | 446 | $regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES); |
414 | - foreach ($possible_ints as $var) |
|
415 | - if (isset($_POST[$var])) |
|
447 | + } |
|
448 | + foreach ($possible_ints as $var) { |
|
449 | + if (isset($_POST[$var])) |
|
416 | 450 | $regOptions['extra_register_vars'][$var] = (int) $_POST[$var]; |
417 | - foreach ($possible_floats as $var) |
|
418 | - if (isset($_POST[$var])) |
|
451 | + } |
|
452 | + foreach ($possible_floats as $var) { |
|
453 | + if (isset($_POST[$var])) |
|
419 | 454 | $regOptions['extra_register_vars'][$var] = (float) $_POST[$var]; |
420 | - foreach ($possible_bools as $var) |
|
421 | - if (isset($_POST[$var])) |
|
455 | + } |
|
456 | + foreach ($possible_bools as $var) { |
|
457 | + if (isset($_POST[$var])) |
|
422 | 458 | $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1; |
459 | + } |
|
423 | 460 | |
424 | 461 | // Registration options are always default options... |
425 | - if (isset($_POST['default_options'])) |
|
426 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
462 | + if (isset($_POST['default_options'])) { |
|
463 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
464 | + } |
|
427 | 465 | $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array(); |
428 | 466 | |
429 | 467 | // Make sure they are clean, dammit! |
@@ -443,12 +481,14 @@ discard block |
||
443 | 481 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
444 | 482 | { |
445 | 483 | // Don't allow overriding of the theme variables. |
446 | - if (isset($regOptions['theme_vars'][$row['col_name']])) |
|
447 | - unset($regOptions['theme_vars'][$row['col_name']]); |
|
484 | + if (isset($regOptions['theme_vars'][$row['col_name']])) { |
|
485 | + unset($regOptions['theme_vars'][$row['col_name']]); |
|
486 | + } |
|
448 | 487 | |
449 | 488 | // Not actually showing it then? |
450 | - if (!$row['show_reg']) |
|
451 | - continue; |
|
489 | + if (!$row['show_reg']) { |
|
490 | + continue; |
|
491 | + } |
|
452 | 492 | |
453 | 493 | // Prepare the value! |
454 | 494 | $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : ''; |
@@ -457,24 +497,27 @@ discard block |
||
457 | 497 | if (!in_array($row['field_type'], array('check', 'select', 'radio'))) |
458 | 498 | { |
459 | 499 | // Is it too long? |
460 | - if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) |
|
461 | - $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
500 | + if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) { |
|
501 | + $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
502 | + } |
|
462 | 503 | |
463 | 504 | // Any masks to apply? |
464 | 505 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
465 | 506 | { |
466 | - if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
467 | - $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
468 | - elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) |
|
469 | - $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
470 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
471 | - $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
507 | + if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) { |
|
508 | + $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
509 | + } elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) { |
|
510 | + $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
511 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) { |
|
512 | + $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
513 | + } |
|
472 | 514 | } |
473 | 515 | } |
474 | 516 | |
475 | 517 | // Is this required but not there? |
476 | - if (trim($value) == '' && $row['show_reg'] > 1) |
|
477 | - $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
518 | + if (trim($value) == '' && $row['show_reg'] > 1) { |
|
519 | + $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
520 | + } |
|
478 | 521 | } |
479 | 522 | $smcFunc['db_free_result']($request); |
480 | 523 | |
@@ -482,8 +525,9 @@ discard block |
||
482 | 525 | if (!empty($custom_field_errors)) |
483 | 526 | { |
484 | 527 | loadLanguage('Errors'); |
485 | - foreach ($custom_field_errors as $error) |
|
486 | - $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
528 | + foreach ($custom_field_errors as $error) { |
|
529 | + $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
530 | + } |
|
487 | 531 | } |
488 | 532 | |
489 | 533 | // Lets check for other errors before trying to register the member. |
@@ -528,8 +572,9 @@ discard block |
||
528 | 572 | } |
529 | 573 | |
530 | 574 | // If COPPA has been selected then things get complicated, setup the template. |
531 | - if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) |
|
532 | - redirectexit('action=coppa;member=' . $memberID); |
|
575 | + if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) { |
|
576 | + redirectexit('action=coppa;member=' . $memberID); |
|
577 | + } |
|
533 | 578 | // Basic template variable setup. |
534 | 579 | elseif (!empty($modSettings['registration_method'])) |
535 | 580 | { |
@@ -541,8 +586,7 @@ discard block |
||
541 | 586 | 'sub_template' => 'after', |
542 | 587 | 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration'] |
543 | 588 | ); |
544 | - } |
|
545 | - else |
|
589 | + } else |
|
546 | 590 | { |
547 | 591 | call_integration_hook('integrate_activate', array($regOptions['username'])); |
548 | 592 | |
@@ -562,16 +606,18 @@ discard block |
||
562 | 606 | global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info; |
563 | 607 | |
564 | 608 | // Logged in users should not bother to activate their accounts |
565 | - if (!empty($user_info['id'])) |
|
566 | - redirectexit(); |
|
609 | + if (!empty($user_info['id'])) { |
|
610 | + redirectexit(); |
|
611 | + } |
|
567 | 612 | |
568 | 613 | loadLanguage('Login'); |
569 | 614 | loadTemplate('Login'); |
570 | 615 | |
571 | 616 | if (empty($_REQUEST['u']) && empty($_POST['user'])) |
572 | 617 | { |
573 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') |
|
574 | - fatal_lang_error('no_access', false); |
|
618 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') { |
|
619 | + fatal_lang_error('no_access', false); |
|
620 | + } |
|
575 | 621 | |
576 | 622 | $context['member_id'] = 0; |
577 | 623 | $context['sub_template'] = 'resend'; |
@@ -611,11 +657,13 @@ discard block |
||
611 | 657 | // Change their email address? (they probably tried a fake one first :P.) |
612 | 658 | if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2)) |
613 | 659 | { |
614 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) |
|
615 | - fatal_lang_error('no_access', false); |
|
660 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) { |
|
661 | + fatal_lang_error('no_access', false); |
|
662 | + } |
|
616 | 663 | |
617 | - if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) |
|
618 | - fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
664 | + if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) { |
|
665 | + fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
666 | + } |
|
619 | 667 | |
620 | 668 | // Make sure their email isn't banned. |
621 | 669 | isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']); |
@@ -631,8 +679,9 @@ discard block |
||
631 | 679 | ) |
632 | 680 | ); |
633 | 681 | |
634 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
635 | - fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
682 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
683 | + fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
684 | + } |
|
636 | 685 | $smcFunc['db_free_result']($request); |
637 | 686 | |
638 | 687 | updateMemberData($row['id_member'], array('email_address' => $_POST['new_email'])); |
@@ -670,9 +719,9 @@ discard block |
||
670 | 719 | // Quit if this code is not right. |
671 | 720 | if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) |
672 | 721 | { |
673 | - if (!empty($row['is_activated'])) |
|
674 | - fatal_lang_error('already_activated', false); |
|
675 | - elseif ($row['validation_code'] == '') |
|
722 | + if (!empty($row['is_activated'])) { |
|
723 | + fatal_lang_error('already_activated', false); |
|
724 | + } elseif ($row['validation_code'] == '') |
|
676 | 725 | { |
677 | 726 | loadLanguage('Profile'); |
678 | 727 | fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false); |
@@ -722,8 +771,9 @@ discard block |
||
722 | 771 | loadTemplate('Register'); |
723 | 772 | |
724 | 773 | // No User ID?? |
725 | - if (!isset($_GET['member'])) |
|
726 | - fatal_lang_error('no_access', false); |
|
774 | + if (!isset($_GET['member'])) { |
|
775 | + fatal_lang_error('no_access', false); |
|
776 | + } |
|
727 | 777 | |
728 | 778 | // Get the user details... |
729 | 779 | $request = $smcFunc['db_query']('', ' |
@@ -736,8 +786,9 @@ discard block |
||
736 | 786 | 'is_coppa' => 5, |
737 | 787 | ) |
738 | 788 | ); |
739 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
740 | - fatal_lang_error('no_access', false); |
|
789 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
790 | + fatal_lang_error('no_access', false); |
|
791 | + } |
|
741 | 792 | list ($username) = $smcFunc['db_fetch_row']($request); |
742 | 793 | $smcFunc['db_free_result']($request); |
743 | 794 | |
@@ -775,8 +826,7 @@ discard block |
||
775 | 826 | echo $data; |
776 | 827 | obExit(false); |
777 | 828 | } |
778 | - } |
|
779 | - else |
|
829 | + } else |
|
780 | 830 | { |
781 | 831 | $context += array( |
782 | 832 | 'page_title' => $txt['coppa_title'], |
@@ -829,8 +879,9 @@ discard block |
||
829 | 879 | { |
830 | 880 | require_once($sourcedir . '/Subs-Graphics.php'); |
831 | 881 | |
832 | - if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) |
|
833 | - header('HTTP/1.1 400 Bad Request'); |
|
882 | + if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) { |
|
883 | + header('HTTP/1.1 400 Bad Request'); |
|
884 | + } |
|
834 | 885 | |
835 | 886 | // Otherwise just show a pre-defined letter. |
836 | 887 | elseif (isset($_REQUEST['letter'])) |
@@ -848,14 +899,13 @@ discard block |
||
848 | 899 | header('content-type: image/gif'); |
849 | 900 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
850 | 901 | } |
851 | - } |
|
852 | - |
|
853 | - elseif ($_REQUEST['format'] === '.wav') |
|
902 | + } elseif ($_REQUEST['format'] === '.wav') |
|
854 | 903 | { |
855 | 904 | require_once($sourcedir . '/Subs-Sound.php'); |
856 | 905 | |
857 | - if (!createWaveFile($code)) |
|
858 | - header('HTTP/1.1 400 Bad Request'); |
|
906 | + if (!createWaveFile($code)) { |
|
907 | + header('HTTP/1.1 400 Bad Request'); |
|
908 | + } |
|
859 | 909 | } |
860 | 910 | |
861 | 911 | // We all die one day... |
@@ -75,8 +75,9 @@ discard block |
||
75 | 75 | $upcontext['inactive_timeout'] = 10; |
76 | 76 | |
77 | 77 | // The helper is crucial. Include it first thing. |
78 | -if (!file_exists($upgrade_path . '/upgrade-helper.php')) |
|
78 | +if (!file_exists($upgrade_path . '/upgrade-helper.php')) { |
|
79 | 79 | die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.'); |
80 | +} |
|
80 | 81 | |
81 | 82 | require_once($upgrade_path . '/upgrade-helper.php'); |
82 | 83 | |
@@ -107,11 +108,14 @@ discard block |
||
107 | 108 | ini_set('default_socket_timeout', 900); |
108 | 109 | } |
109 | 110 | // Clean the upgrade path if this is from the client. |
110 | -if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) |
|
111 | - for ($i = 1; $i < $_SERVER['argc']; $i++) |
|
111 | +if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { |
|
112 | + for ($i = 1; |
|
113 | +} |
|
114 | +$i < $_SERVER['argc']; $i++) |
|
112 | 115 | { |
113 | - if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) |
|
114 | - $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
116 | + if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) { |
|
117 | + $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
118 | + } |
|
115 | 119 | } |
116 | 120 | |
117 | 121 | // Are we from the client? |
@@ -119,16 +123,17 @@ discard block |
||
119 | 123 | { |
120 | 124 | $command_line = true; |
121 | 125 | $disable_security = true; |
122 | -} |
|
123 | -else |
|
126 | +} else { |
|
124 | 127 | $command_line = false; |
128 | +} |
|
125 | 129 | |
126 | 130 | // Load this now just because we can. |
127 | 131 | require_once($upgrade_path . '/Settings.php'); |
128 | 132 | |
129 | 133 | // We don't use "-utf8" anymore... Tweak the entry that may have been loaded by Settings.php |
130 | -if (isset($language)) |
|
134 | +if (isset($language)) { |
|
131 | 135 | $language = str_ireplace('-utf8', '', $language); |
136 | +} |
|
132 | 137 | |
133 | 138 | // Are we logged in? |
134 | 139 | if (isset($upgradeData)) |
@@ -136,10 +141,12 @@ discard block |
||
136 | 141 | $upcontext['user'] = json_decode(base64_decode($upgradeData), true); |
137 | 142 | |
138 | 143 | // Check for sensible values. |
139 | - if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) |
|
140 | - $upcontext['user']['started'] = time(); |
|
141 | - if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) |
|
142 | - $upcontext['user']['updated'] = 0; |
|
144 | + if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) { |
|
145 | + $upcontext['user']['started'] = time(); |
|
146 | + } |
|
147 | + if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) { |
|
148 | + $upcontext['user']['updated'] = 0; |
|
149 | + } |
|
143 | 150 | |
144 | 151 | $upcontext['started'] = $upcontext['user']['started']; |
145 | 152 | $upcontext['updated'] = $upcontext['user']['updated']; |
@@ -204,8 +211,9 @@ discard block |
||
204 | 211 | 'db_error_skip' => true, |
205 | 212 | ) |
206 | 213 | ); |
207 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
208 | - $modSettings[$row['variable']] = $row['value']; |
|
214 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
215 | + $modSettings[$row['variable']] = $row['value']; |
|
216 | + } |
|
209 | 217 | $smcFunc['db_free_result']($request); |
210 | 218 | } |
211 | 219 | |
@@ -215,10 +223,12 @@ discard block |
||
215 | 223 | $modSettings['theme_url'] = 'Themes/default'; |
216 | 224 | $modSettings['images_url'] = 'Themes/default/images'; |
217 | 225 | } |
218 | -if (!isset($settings['default_theme_url'])) |
|
226 | +if (!isset($settings['default_theme_url'])) { |
|
219 | 227 | $settings['default_theme_url'] = $modSettings['theme_url']; |
220 | -if (!isset($settings['default_theme_dir'])) |
|
228 | +} |
|
229 | +if (!isset($settings['default_theme_dir'])) { |
|
221 | 230 | $settings['default_theme_dir'] = $modSettings['theme_dir']; |
231 | +} |
|
222 | 232 | |
223 | 233 | $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000; |
224 | 234 | // Default title... |
@@ -236,13 +246,15 @@ discard block |
||
236 | 246 | $support_js = $upcontext['upgrade_status']['js']; |
237 | 247 | |
238 | 248 | // Only set this if the upgrader status says so. |
239 | - if (empty($is_debug)) |
|
240 | - $is_debug = $upcontext['upgrade_status']['debug']; |
|
249 | + if (empty($is_debug)) { |
|
250 | + $is_debug = $upcontext['upgrade_status']['debug']; |
|
251 | + } |
|
241 | 252 | |
242 | 253 | // Load the language. |
243 | - if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
244 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
245 | -} |
|
254 | + if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
255 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
256 | + } |
|
257 | + } |
|
246 | 258 | // Set the defaults. |
247 | 259 | else |
248 | 260 | { |
@@ -260,15 +272,18 @@ discard block |
||
260 | 272 | } |
261 | 273 | |
262 | 274 | // If this isn't the first stage see whether they are logging in and resuming. |
263 | -if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) |
|
275 | +if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) { |
|
264 | 276 | checkLogin(); |
277 | +} |
|
265 | 278 | |
266 | -if ($command_line) |
|
279 | +if ($command_line) { |
|
267 | 280 | cmdStep0(); |
281 | +} |
|
268 | 282 | |
269 | 283 | // Don't error if we're using xml. |
270 | -if (isset($_GET['xml'])) |
|
284 | +if (isset($_GET['xml'])) { |
|
271 | 285 | $upcontext['return_error'] = true; |
286 | +} |
|
272 | 287 | |
273 | 288 | // Loop through all the steps doing each one as required. |
274 | 289 | $upcontext['overall_percent'] = 0; |
@@ -289,9 +304,9 @@ discard block |
||
289 | 304 | } |
290 | 305 | |
291 | 306 | // Call the step and if it returns false that means pause! |
292 | - if (function_exists($step[2]) && $step[2]() === false) |
|
293 | - break; |
|
294 | - elseif (function_exists($step[2])) { |
|
307 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
308 | + break; |
|
309 | + } elseif (function_exists($step[2])) { |
|
295 | 310 | //Start each new step with this unset, so the 'normal' template is called first |
296 | 311 | unset($_GET['xml']); |
297 | 312 | //Clear out warnings at the start of each step |
@@ -337,17 +352,18 @@ discard block |
||
337 | 352 | // This should not happen my dear... HELP ME DEVELOPERS!! |
338 | 353 | if (!empty($command_line)) |
339 | 354 | { |
340 | - if (function_exists('debug_print_backtrace')) |
|
341 | - debug_print_backtrace(); |
|
355 | + if (function_exists('debug_print_backtrace')) { |
|
356 | + debug_print_backtrace(); |
|
357 | + } |
|
342 | 358 | |
343 | 359 | echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.'; |
344 | 360 | flush(); |
345 | 361 | die(); |
346 | 362 | } |
347 | 363 | |
348 | - if (!isset($_GET['xml'])) |
|
349 | - template_upgrade_above(); |
|
350 | - else |
|
364 | + if (!isset($_GET['xml'])) { |
|
365 | + template_upgrade_above(); |
|
366 | + } else |
|
351 | 367 | { |
352 | 368 | header('content-type: text/xml; charset=UTF-8'); |
353 | 369 | // Sadly we need to retain the $_GET data thanks to the old upgrade scripts. |
@@ -369,25 +385,29 @@ discard block |
||
369 | 385 | $upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(json_encode($upcontext['upgrade_status'])); |
370 | 386 | |
371 | 387 | // Custom stuff to pass back? |
372 | - if (!empty($upcontext['query_string'])) |
|
373 | - $upcontext['form_url'] .= $upcontext['query_string']; |
|
388 | + if (!empty($upcontext['query_string'])) { |
|
389 | + $upcontext['form_url'] .= $upcontext['query_string']; |
|
390 | + } |
|
374 | 391 | |
375 | 392 | // Call the appropriate subtemplate |
376 | - if (is_callable('template_' . $upcontext['sub_template'])) |
|
377 | - call_user_func('template_' . $upcontext['sub_template']); |
|
378 | - else |
|
379 | - die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
393 | + if (is_callable('template_' . $upcontext['sub_template'])) { |
|
394 | + call_user_func('template_' . $upcontext['sub_template']); |
|
395 | + } else { |
|
396 | + die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
397 | + } |
|
380 | 398 | } |
381 | 399 | |
382 | 400 | // Was there an error? |
383 | - if (!empty($upcontext['forced_error_message'])) |
|
384 | - echo $upcontext['forced_error_message']; |
|
401 | + if (!empty($upcontext['forced_error_message'])) { |
|
402 | + echo $upcontext['forced_error_message']; |
|
403 | + } |
|
385 | 404 | |
386 | 405 | // Show the footer. |
387 | - if (!isset($_GET['xml'])) |
|
388 | - template_upgrade_below(); |
|
389 | - else |
|
390 | - template_xml_below(); |
|
406 | + if (!isset($_GET['xml'])) { |
|
407 | + template_upgrade_below(); |
|
408 | + } else { |
|
409 | + template_xml_below(); |
|
410 | + } |
|
391 | 411 | } |
392 | 412 | |
393 | 413 | |
@@ -399,15 +419,19 @@ discard block |
||
399 | 419 | $seconds = intval($active % 60); |
400 | 420 | |
401 | 421 | $totalTime = ''; |
402 | - if ($hours > 0) |
|
403 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
404 | - if ($minutes > 0) |
|
405 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
406 | - if ($seconds > 0) |
|
407 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
422 | + if ($hours > 0) { |
|
423 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
424 | + } |
|
425 | + if ($minutes > 0) { |
|
426 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
427 | + } |
|
428 | + if ($seconds > 0) { |
|
429 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
430 | + } |
|
408 | 431 | |
409 | - if (!empty($totalTime)) |
|
410 | - echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n"; |
|
432 | + if (!empty($totalTime)) { |
|
433 | + echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n"; |
|
434 | + } |
|
411 | 435 | } |
412 | 436 | |
413 | 437 | // Bang - gone! |
@@ -428,8 +452,9 @@ discard block |
||
428 | 452 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
429 | 453 | while ($entry = $dir->read()) |
430 | 454 | { |
431 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
432 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
455 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
456 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
457 | + } |
|
433 | 458 | } |
434 | 459 | $dir->close(); |
435 | 460 | } |
@@ -464,10 +489,11 @@ discard block |
||
464 | 489 | } |
465 | 490 | |
466 | 491 | // Override the language file? |
467 | - if (isset($_GET['lang_file'])) |
|
468 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
469 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
470 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
492 | + if (isset($_GET['lang_file'])) { |
|
493 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
494 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
495 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
496 | + } |
|
471 | 497 | |
472 | 498 | // Make sure it exists, if it doesn't reset it. |
473 | 499 | if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang'])) |
@@ -476,12 +502,14 @@ discard block |
||
476 | 502 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
477 | 503 | |
478 | 504 | // If we have english and some other language, use the other language. We Americans hate english :P. |
479 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
480 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
505 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
506 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
507 | + } |
|
481 | 508 | |
482 | 509 | // For backup we load the english at first -> second language overwrite the english one |
483 | - if (count($incontext['detected_languages']) > 1) |
|
484 | - require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php'); |
|
510 | + if (count($incontext['detected_languages']) > 1) { |
|
511 | + require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php'); |
|
512 | + } |
|
485 | 513 | } |
486 | 514 | |
487 | 515 | // And now include the actual language file itself. |
@@ -489,11 +517,12 @@ discard block |
||
489 | 517 | |
490 | 518 | // Which language did we load? Assume that he likes his language. |
491 | 519 | preg_match('~^Install\.(.+[^-utf8])\.php$~', $_SESSION['installer_temp_lang'], $matches); |
492 | - if (empty($matches[1])) |
|
493 | - $matches = [ |
|
520 | + if (empty($matches[1])) { |
|
521 | + $matches = [ |
|
494 | 522 | 0 => 'nothing', |
495 | 523 | 1 => 'english', |
496 | 524 | ]; |
525 | + } |
|
497 | 526 | $user_info['language'] = $matches[1]; |
498 | 527 | } |
499 | 528 | |
@@ -503,8 +532,9 @@ discard block |
||
503 | 532 | global $upgradeurl, $upcontext, $command_line; |
504 | 533 | |
505 | 534 | // Command line users can't be redirected. |
506 | - if ($command_line) |
|
507 | - upgradeExit(true); |
|
535 | + if ($command_line) { |
|
536 | + upgradeExit(true); |
|
537 | + } |
|
508 | 538 | |
509 | 539 | // Are we providing the core info? |
510 | 540 | if ($addForm) |
@@ -530,12 +560,14 @@ discard block |
||
530 | 560 | define('SMF', 1); |
531 | 561 | |
532 | 562 | // Start the session. |
533 | - if (@ini_get('session.save_handler') == 'user') |
|
534 | - @ini_set('session.save_handler', 'files'); |
|
563 | + if (@ini_get('session.save_handler') == 'user') { |
|
564 | + @ini_set('session.save_handler', 'files'); |
|
565 | + } |
|
535 | 566 | @session_start(); |
536 | 567 | |
537 | - if (empty($smcFunc)) |
|
538 | - $smcFunc = array(); |
|
568 | + if (empty($smcFunc)) { |
|
569 | + $smcFunc = array(); |
|
570 | + } |
|
539 | 571 | |
540 | 572 | // We need this for authentication and some upgrade code |
541 | 573 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -562,24 +594,27 @@ discard block |
||
562 | 594 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
563 | 595 | |
564 | 596 | // Make the connection... |
565 | - if (empty($db_connection)) |
|
566 | - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true)); |
|
567 | - else |
|
568 | - // If we've returned here, ping/reconnect to be safe |
|
597 | + if (empty($db_connection)) { |
|
598 | + $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true)); |
|
599 | + } else { |
|
600 | + // If we've returned here, ping/reconnect to be safe |
|
569 | 601 | $smcFunc['db_ping']($db_connection); |
602 | + } |
|
570 | 603 | |
571 | 604 | // Oh dear god!! |
572 | - if ($db_connection === null) |
|
573 | - die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
605 | + if ($db_connection === null) { |
|
606 | + die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
607 | + } |
|
574 | 608 | |
575 | - if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) |
|
576 | - $smcFunc['db_query']('', ' |
|
609 | + if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) { |
|
610 | + $smcFunc['db_query']('', ' |
|
577 | 611 | SET NAMES {string:db_character_set}', |
578 | 612 | array( |
579 | 613 | 'db_error_skip' => true, |
580 | 614 | 'db_character_set' => $db_character_set, |
581 | 615 | ) |
582 | 616 | ); |
617 | + } |
|
583 | 618 | |
584 | 619 | // Load the modSettings data... |
585 | 620 | $request = $smcFunc['db_query']('', ' |
@@ -590,11 +625,11 @@ discard block |
||
590 | 625 | ) |
591 | 626 | ); |
592 | 627 | $modSettings = array(); |
593 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
594 | - $modSettings[$row['variable']] = $row['value']; |
|
628 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
629 | + $modSettings[$row['variable']] = $row['value']; |
|
630 | + } |
|
595 | 631 | $smcFunc['db_free_result']($request); |
596 | - } |
|
597 | - else |
|
632 | + } else |
|
598 | 633 | { |
599 | 634 | return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.'); |
600 | 635 | } |
@@ -608,9 +643,10 @@ discard block |
||
608 | 643 | cleanRequest(); |
609 | 644 | } |
610 | 645 | |
611 | - if (!isset($_GET['substep'])) |
|
612 | - $_GET['substep'] = 0; |
|
613 | -} |
|
646 | + if (!isset($_GET['substep'])) { |
|
647 | + $_GET['substep'] = 0; |
|
648 | + } |
|
649 | + } |
|
614 | 650 | |
615 | 651 | function initialize_inputs() |
616 | 652 | { |
@@ -640,8 +676,9 @@ discard block |
||
640 | 676 | $dh = opendir(dirname(__FILE__)); |
641 | 677 | while ($file = readdir($dh)) |
642 | 678 | { |
643 | - if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) |
|
644 | - @unlink(dirname(__FILE__) . '/' . $file); |
|
679 | + if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) { |
|
680 | + @unlink(dirname(__FILE__) . '/' . $file); |
|
681 | + } |
|
645 | 682 | } |
646 | 683 | closedir($dh); |
647 | 684 | |
@@ -670,8 +707,9 @@ discard block |
||
670 | 707 | $temp = 'upgrade_php?step'; |
671 | 708 | while (strlen($temp) > 4) |
672 | 709 | { |
673 | - if (isset($_GET[$temp])) |
|
674 | - unset($_GET[$temp]); |
|
710 | + if (isset($_GET[$temp])) { |
|
711 | + unset($_GET[$temp]); |
|
712 | + } |
|
675 | 713 | $temp = substr($temp, 1); |
676 | 714 | } |
677 | 715 | |
@@ -698,32 +736,39 @@ discard block |
||
698 | 736 | && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql'); |
699 | 737 | |
700 | 738 | // Need legacy scripts? |
701 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) |
|
702 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
703 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) |
|
704 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
705 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) |
|
706 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
739 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) { |
|
740 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
741 | + } |
|
742 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) { |
|
743 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
744 | + } |
|
745 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) { |
|
746 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
747 | + } |
|
707 | 748 | |
708 | 749 | // We don't need "-utf8" files anymore... |
709 | 750 | $upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']); |
710 | 751 | |
711 | 752 | // This needs to exist! |
712 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
713 | - return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
714 | - else |
|
715 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
753 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
754 | + return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
755 | + } else { |
|
756 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
757 | + } |
|
716 | 758 | |
717 | - if (!$check) |
|
718 | - // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb. |
|
759 | + if (!$check) { |
|
760 | + // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb. |
|
719 | 761 | return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.'); |
762 | + } |
|
720 | 763 | |
721 | 764 | // Do they meet the install requirements? |
722 | - if (!php_version_check()) |
|
723 | - return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.'); |
|
765 | + if (!php_version_check()) { |
|
766 | + return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.'); |
|
767 | + } |
|
724 | 768 | |
725 | - if (!db_version_check()) |
|
726 | - return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.'); |
|
769 | + if (!db_version_check()) { |
|
770 | + return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.'); |
|
771 | + } |
|
727 | 772 | |
728 | 773 | // Do some checks to make sure they have proper privileges |
729 | 774 | db_extend('packages'); |
@@ -738,14 +783,16 @@ discard block |
||
738 | 783 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
739 | 784 | |
740 | 785 | // Sorry... we need CREATE, ALTER and DROP |
741 | - if (!$create || !$alter || !$drop) |
|
742 | - return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.'); |
|
786 | + if (!$create || !$alter || !$drop) { |
|
787 | + return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.'); |
|
788 | + } |
|
743 | 789 | |
744 | 790 | // Do a quick version spot check. |
745 | 791 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
746 | 792 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
747 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
748 | - return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.'); |
|
793 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
794 | + return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.'); |
|
795 | + } |
|
749 | 796 | |
750 | 797 | // What absolutely needs to be writable? |
751 | 798 | $writable_files = array( |
@@ -754,12 +801,13 @@ discard block |
||
754 | 801 | ); |
755 | 802 | |
756 | 803 | // Only check for minified writable files if we have it enabled or not set. |
757 | - if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) |
|
758 | - $writable_files += array( |
|
804 | + if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) { |
|
805 | + $writable_files += array( |
|
759 | 806 | $modSettings['theme_dir'] . '/css/minified.css', |
760 | 807 | $modSettings['theme_dir'] . '/scripts/minified.js', |
761 | 808 | $modSettings['theme_dir'] . '/scripts/minified_deferred.js', |
762 | 809 | ); |
810 | + } |
|
763 | 811 | |
764 | 812 | // Do we need to add this setting? |
765 | 813 | $need_settings_update = empty($modSettings['custom_avatar_dir']); |
@@ -771,12 +819,13 @@ discard block |
||
771 | 819 | quickFileWritable($custom_av_dir); |
772 | 820 | |
773 | 821 | // Are we good now? |
774 | - if (!is_writable($custom_av_dir)) |
|
775 | - return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir)); |
|
776 | - elseif ($need_settings_update) |
|
822 | + if (!is_writable($custom_av_dir)) { |
|
823 | + return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir)); |
|
824 | + } elseif ($need_settings_update) |
|
777 | 825 | { |
778 | - if (!function_exists('cache_put_data')) |
|
779 | - require_once($sourcedir . '/Load.php'); |
|
826 | + if (!function_exists('cache_put_data')) { |
|
827 | + require_once($sourcedir . '/Load.php'); |
|
828 | + } |
|
780 | 829 | updateSettings(array('custom_avatar_dir' => $custom_av_dir)); |
781 | 830 | updateSettings(array('custom_avatar_url' => $custom_av_url)); |
782 | 831 | } |
@@ -785,28 +834,33 @@ discard block |
||
785 | 834 | |
786 | 835 | // Check the cache directory. |
787 | 836 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
788 | - if (!file_exists($cachedir_temp)) |
|
789 | - @mkdir($cachedir_temp); |
|
790 | - if (!file_exists($cachedir_temp)) |
|
791 | - return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called "cache" in your forum directory before continuing.'); |
|
792 | - |
|
793 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
794 | - return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.'); |
|
795 | - elseif (!isset($_GET['skiplang'])) |
|
837 | + if (!file_exists($cachedir_temp)) { |
|
838 | + @mkdir($cachedir_temp); |
|
839 | + } |
|
840 | + if (!file_exists($cachedir_temp)) { |
|
841 | + return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called "cache" in your forum directory before continuing.'); |
|
842 | + } |
|
843 | + |
|
844 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
845 | + return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.'); |
|
846 | + } elseif (!isset($_GET['skiplang'])) |
|
796 | 847 | { |
797 | 848 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
798 | 849 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
799 | 850 | |
800 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
801 | - return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
851 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
852 | + return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
853 | + } |
|
802 | 854 | } |
803 | 855 | |
804 | - if (!makeFilesWritable($writable_files)) |
|
805 | - return false; |
|
856 | + if (!makeFilesWritable($writable_files)) { |
|
857 | + return false; |
|
858 | + } |
|
806 | 859 | |
807 | 860 | // Check agreement.txt. (it may not exist, in which case $boarddir must be writable.) |
808 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
809 | - return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.'); |
|
861 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
862 | + return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.'); |
|
863 | + } |
|
810 | 864 | |
811 | 865 | // Upgrade the agreement. |
812 | 866 | elseif (isset($modSettings['agreement'])) |
@@ -817,8 +871,8 @@ discard block |
||
817 | 871 | } |
818 | 872 | |
819 | 873 | // We're going to check that their board dir setting is right in case they've been moving stuff around. |
820 | - if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) |
|
821 | - $upcontext['warning'] = ' |
|
874 | + if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) { |
|
875 | + $upcontext['warning'] = ' |
|
822 | 876 | It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to "' . $boarddir . '" but should probably be "' . dirname(__FILE__) . '". Settings.php currently lists your paths as:<br> |
823 | 877 | <ul> |
824 | 878 | <li>Board Directory: ' . $boarddir . '</li> |
@@ -826,19 +880,23 @@ discard block |
||
826 | 880 | <li>Cache Directory: ' . $cachedir_temp . '</li> |
827 | 881 | </ul> |
828 | 882 | If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.'; |
883 | + } |
|
829 | 884 | |
830 | 885 | // Confirm mbstring is loaded... |
831 | - if (!extension_loaded('mbstring')) |
|
832 | - return throw_error($txt['install_no_mbstring']); |
|
886 | + if (!extension_loaded('mbstring')) { |
|
887 | + return throw_error($txt['install_no_mbstring']); |
|
888 | + } |
|
833 | 889 | |
834 | 890 | // Check for https stream support. |
835 | 891 | $supported_streams = stream_get_wrappers(); |
836 | - if (!in_array('https', $supported_streams)) |
|
837 | - $upcontext['custom_warning'] = $txt['install_no_https']; |
|
892 | + if (!in_array('https', $supported_streams)) { |
|
893 | + $upcontext['custom_warning'] = $txt['install_no_https']; |
|
894 | + } |
|
838 | 895 | |
839 | 896 | // Either we're logged in or we're going to present the login. |
840 | - if (checkLogin()) |
|
841 | - return true; |
|
897 | + if (checkLogin()) { |
|
898 | + return true; |
|
899 | + } |
|
842 | 900 | |
843 | 901 | $upcontext += createToken('login'); |
844 | 902 | |
@@ -852,15 +910,17 @@ discard block |
||
852 | 910 | global $smcFunc, $db_type, $support_js; |
853 | 911 | |
854 | 912 | // Don't bother if the security is disabled. |
855 | - if ($disable_security) |
|
856 | - return true; |
|
913 | + if ($disable_security) { |
|
914 | + return true; |
|
915 | + } |
|
857 | 916 | |
858 | 917 | // Are we trying to login? |
859 | 918 | if (isset($_POST['contbutt']) && (!empty($_POST['user']))) |
860 | 919 | { |
861 | 920 | // If we've disabled security pick a suitable name! |
862 | - if (empty($_POST['user'])) |
|
863 | - $_POST['user'] = 'Administrator'; |
|
921 | + if (empty($_POST['user'])) { |
|
922 | + $_POST['user'] = 'Administrator'; |
|
923 | + } |
|
864 | 924 | |
865 | 925 | // Before 2.0 these column names were different! |
866 | 926 | $oldDB = false; |
@@ -875,16 +935,17 @@ discard block |
||
875 | 935 | 'db_error_skip' => true, |
876 | 936 | ) |
877 | 937 | ); |
878 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
879 | - $oldDB = true; |
|
938 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
939 | + $oldDB = true; |
|
940 | + } |
|
880 | 941 | $smcFunc['db_free_result']($request); |
881 | 942 | } |
882 | 943 | |
883 | 944 | // Get what we believe to be their details. |
884 | 945 | if (!$disable_security) |
885 | 946 | { |
886 | - if ($oldDB) |
|
887 | - $request = $smcFunc['db_query']('', ' |
|
947 | + if ($oldDB) { |
|
948 | + $request = $smcFunc['db_query']('', ' |
|
888 | 949 | SELECT id_member, memberName AS member_name, passwd, id_group, |
889 | 950 | additionalGroups AS additional_groups, lngfile |
890 | 951 | FROM {db_prefix}members |
@@ -894,8 +955,8 @@ discard block |
||
894 | 955 | 'db_error_skip' => true, |
895 | 956 | ) |
896 | 957 | ); |
897 | - else |
|
898 | - $request = $smcFunc['db_query']('', ' |
|
958 | + } else { |
|
959 | + $request = $smcFunc['db_query']('', ' |
|
899 | 960 | SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile |
900 | 961 | FROM {db_prefix}members |
901 | 962 | WHERE member_name = {string:member_name}', |
@@ -904,6 +965,7 @@ discard block |
||
904 | 965 | 'db_error_skip' => true, |
905 | 966 | ) |
906 | 967 | ); |
968 | + } |
|
907 | 969 | if ($smcFunc['db_num_rows']($request) != 0) |
908 | 970 | { |
909 | 971 | list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request); |
@@ -911,16 +973,17 @@ discard block |
||
911 | 973 | $groups = explode(',', $addGroups); |
912 | 974 | $groups[] = $id_group; |
913 | 975 | |
914 | - foreach ($groups as $k => $v) |
|
915 | - $groups[$k] = (int) $v; |
|
976 | + foreach ($groups as $k => $v) { |
|
977 | + $groups[$k] = (int) $v; |
|
978 | + } |
|
916 | 979 | |
917 | 980 | $sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd'])); |
918 | 981 | |
919 | 982 | // We don't use "-utf8" anymore... |
920 | 983 | $user_language = str_ireplace('-utf8', '', $user_language); |
984 | + } else { |
|
985 | + $upcontext['username_incorrect'] = true; |
|
921 | 986 | } |
922 | - else |
|
923 | - $upcontext['username_incorrect'] = true; |
|
924 | 987 | $smcFunc['db_free_result']($request); |
925 | 988 | } |
926 | 989 | $upcontext['username'] = $_POST['user']; |
@@ -930,13 +993,14 @@ discard block |
||
930 | 993 | { |
931 | 994 | $upcontext['upgrade_status']['js'] = 1; |
932 | 995 | $support_js = 1; |
996 | + } else { |
|
997 | + $support_js = 0; |
|
933 | 998 | } |
934 | - else |
|
935 | - $support_js = 0; |
|
936 | 999 | |
937 | 1000 | // Note down the version we are coming from. |
938 | - if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) |
|
939 | - $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
1001 | + if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) { |
|
1002 | + $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
1003 | + } |
|
940 | 1004 | |
941 | 1005 | // Didn't get anywhere? |
942 | 1006 | if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect'])) |
@@ -970,15 +1034,15 @@ discard block |
||
970 | 1034 | 'db_error_skip' => true, |
971 | 1035 | ) |
972 | 1036 | ); |
973 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
974 | - return throw_error('You need to be an admin to perform an upgrade!'); |
|
1037 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1038 | + return throw_error('You need to be an admin to perform an upgrade!'); |
|
1039 | + } |
|
975 | 1040 | $smcFunc['db_free_result']($request); |
976 | 1041 | } |
977 | 1042 | |
978 | 1043 | $upcontext['user']['id'] = $id_member; |
979 | 1044 | $upcontext['user']['name'] = $name; |
980 | - } |
|
981 | - else |
|
1045 | + } else |
|
982 | 1046 | { |
983 | 1047 | $upcontext['user']['id'] = 1; |
984 | 1048 | $upcontext['user']['name'] = 'Administrator'; |
@@ -994,11 +1058,11 @@ discard block |
||
994 | 1058 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096); |
995 | 1059 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
996 | 1060 | |
997 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
998 | - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
999 | - elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) |
|
1000 | - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
1001 | - else |
|
1061 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
1062 | + $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
1063 | + } elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) { |
|
1064 | + $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
1065 | + } else |
|
1002 | 1066 | { |
1003 | 1067 | // Set this as the new language. |
1004 | 1068 | $upcontext['language'] = $user_language; |
@@ -1042,8 +1106,9 @@ discard block |
||
1042 | 1106 | unset($member_columns); |
1043 | 1107 | |
1044 | 1108 | // If we've not submitted then we're done. |
1045 | - if (empty($_POST['upcont'])) |
|
1046 | - return false; |
|
1109 | + if (empty($_POST['upcont'])) { |
|
1110 | + return false; |
|
1111 | + } |
|
1047 | 1112 | |
1048 | 1113 | // Firstly, if they're enabling SM stat collection just do it. |
1049 | 1114 | if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats'])) |
@@ -1063,16 +1128,17 @@ discard block |
||
1063 | 1128 | fwrite($fp, $out); |
1064 | 1129 | |
1065 | 1130 | $return_data = ''; |
1066 | - while (!feof($fp)) |
|
1067 | - $return_data .= fgets($fp, 128); |
|
1131 | + while (!feof($fp)) { |
|
1132 | + $return_data .= fgets($fp, 128); |
|
1133 | + } |
|
1068 | 1134 | |
1069 | 1135 | fclose($fp); |
1070 | 1136 | |
1071 | 1137 | // Get the unique site ID. |
1072 | 1138 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
1073 | 1139 | |
1074 | - if (!empty($ID[1])) |
|
1075 | - $smcFunc['db_insert']('replace', |
|
1140 | + if (!empty($ID[1])) { |
|
1141 | + $smcFunc['db_insert']('replace', |
|
1076 | 1142 | $db_prefix . 'settings', |
1077 | 1143 | array('variable' => 'string', 'value' => 'string'), |
1078 | 1144 | array( |
@@ -1081,9 +1147,9 @@ discard block |
||
1081 | 1147 | ), |
1082 | 1148 | array('variable') |
1083 | 1149 | ); |
1150 | + } |
|
1084 | 1151 | } |
1085 | - } |
|
1086 | - else |
|
1152 | + } else |
|
1087 | 1153 | { |
1088 | 1154 | $smcFunc['db_insert']('replace', |
1089 | 1155 | $db_prefix . 'settings', |
@@ -1094,8 +1160,8 @@ discard block |
||
1094 | 1160 | } |
1095 | 1161 | } |
1096 | 1162 | // Don't remove stat collection unless we unchecked the box for real, not from the loop. |
1097 | - elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) |
|
1098 | - $smcFunc['db_query']('', ' |
|
1163 | + elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) { |
|
1164 | + $smcFunc['db_query']('', ' |
|
1099 | 1165 | DELETE FROM {db_prefix}settings |
1100 | 1166 | WHERE variable = {string:enable_sm_stats}', |
1101 | 1167 | array( |
@@ -1103,6 +1169,7 @@ discard block |
||
1103 | 1169 | 'db_error_skip' => true, |
1104 | 1170 | ) |
1105 | 1171 | ); |
1172 | + } |
|
1106 | 1173 | |
1107 | 1174 | // Deleting old karma stuff? |
1108 | 1175 | if (!empty($_POST['delete_karma'])) |
@@ -1117,20 +1184,22 @@ discard block |
||
1117 | 1184 | ); |
1118 | 1185 | |
1119 | 1186 | // Cleaning up old karma member settings. |
1120 | - if ($upcontext['karma_installed']['good']) |
|
1121 | - $smcFunc['db_query']('', ' |
|
1187 | + if ($upcontext['karma_installed']['good']) { |
|
1188 | + $smcFunc['db_query']('', ' |
|
1122 | 1189 | ALTER TABLE {db_prefix}members |
1123 | 1190 | DROP karma_good', |
1124 | 1191 | array() |
1125 | 1192 | ); |
1193 | + } |
|
1126 | 1194 | |
1127 | 1195 | // Does karma bad was enable? |
1128 | - if ($upcontext['karma_installed']['bad']) |
|
1129 | - $smcFunc['db_query']('', ' |
|
1196 | + if ($upcontext['karma_installed']['bad']) { |
|
1197 | + $smcFunc['db_query']('', ' |
|
1130 | 1198 | ALTER TABLE {db_prefix}members |
1131 | 1199 | DROP karma_bad', |
1132 | 1200 | array() |
1133 | 1201 | ); |
1202 | + } |
|
1134 | 1203 | |
1135 | 1204 | // Cleaning up old karma permissions. |
1136 | 1205 | $smcFunc['db_query']('', ' |
@@ -1148,32 +1217,37 @@ discard block |
||
1148 | 1217 | } |
1149 | 1218 | |
1150 | 1219 | // Emptying the error log? |
1151 | - if (!empty($_POST['empty_error'])) |
|
1152 | - $smcFunc['db_query']('truncate_table', ' |
|
1220 | + if (!empty($_POST['empty_error'])) { |
|
1221 | + $smcFunc['db_query']('truncate_table', ' |
|
1153 | 1222 | TRUNCATE {db_prefix}log_errors', |
1154 | 1223 | array( |
1155 | 1224 | ) |
1156 | 1225 | ); |
1226 | + } |
|
1157 | 1227 | |
1158 | 1228 | $changes = array(); |
1159 | 1229 | |
1160 | 1230 | // Add proxy settings. |
1161 | - if (!isset($GLOBALS['image_proxy_maxsize'])) |
|
1162 | - $changes += array( |
|
1231 | + if (!isset($GLOBALS['image_proxy_maxsize'])) { |
|
1232 | + $changes += array( |
|
1163 | 1233 | 'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'', |
1164 | 1234 | 'image_proxy_maxsize' => 5190, |
1165 | 1235 | 'image_proxy_enabled' => 0, |
1166 | 1236 | ); |
1237 | + } |
|
1167 | 1238 | |
1168 | 1239 | // If $boardurl reflects https, set force_ssl |
1169 | - if (!function_exists('cache_put_data')) |
|
1170 | - require_once($sourcedir . '/Load.php'); |
|
1171 | - if (stripos($boardurl, 'https://') !== false) |
|
1172 | - updateSettings(array('force_ssl' => '1')); |
|
1240 | + if (!function_exists('cache_put_data')) { |
|
1241 | + require_once($sourcedir . '/Load.php'); |
|
1242 | + } |
|
1243 | + if (stripos($boardurl, 'https://') !== false) { |
|
1244 | + updateSettings(array('force_ssl' => '1')); |
|
1245 | + } |
|
1173 | 1246 | |
1174 | 1247 | // If we're overriding the language follow it through. |
1175 | - if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) |
|
1176 | - $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
1248 | + if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) { |
|
1249 | + $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
1250 | + } |
|
1177 | 1251 | |
1178 | 1252 | if (!empty($_POST['maint'])) |
1179 | 1253 | { |
@@ -1185,26 +1259,29 @@ discard block |
||
1185 | 1259 | { |
1186 | 1260 | $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\''; |
1187 | 1261 | $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\''; |
1188 | - } |
|
1189 | - else |
|
1262 | + } else |
|
1190 | 1263 | { |
1191 | 1264 | $changes['mtitle'] = '\'Upgrading the forum...\''; |
1192 | 1265 | $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\''; |
1193 | 1266 | } |
1194 | 1267 | } |
1195 | 1268 | |
1196 | - if ($command_line) |
|
1197 | - echo ' * Updating Settings.php...'; |
|
1269 | + if ($command_line) { |
|
1270 | + echo ' * Updating Settings.php...'; |
|
1271 | + } |
|
1198 | 1272 | |
1199 | 1273 | // Fix some old paths. |
1200 | - if (substr($boarddir, 0, 1) == '.') |
|
1201 | - $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
1274 | + if (substr($boarddir, 0, 1) == '.') { |
|
1275 | + $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
1276 | + } |
|
1202 | 1277 | |
1203 | - if (substr($sourcedir, 0, 1) == '.') |
|
1204 | - $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
1278 | + if (substr($sourcedir, 0, 1) == '.') { |
|
1279 | + $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
1280 | + } |
|
1205 | 1281 | |
1206 | - if (empty($cachedir) || substr($cachedir, 0, 1) == '.') |
|
1207 | - $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
1282 | + if (empty($cachedir) || substr($cachedir, 0, 1) == '.') { |
|
1283 | + $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
1284 | + } |
|
1208 | 1285 | |
1209 | 1286 | // If they have a "host:port" setup for the host, split that into separate values |
1210 | 1287 | // You should never have a : in the hostname if you're not on MySQL, but better safe than sorry |
@@ -1215,32 +1292,36 @@ discard block |
||
1215 | 1292 | $changes['db_server'] = '\'' . $db_server . '\''; |
1216 | 1293 | |
1217 | 1294 | // Only set this if we're not using the default port |
1218 | - if ($db_port != ini_get('mysqli.default_port')) |
|
1219 | - $changes['db_port'] = (int) $db_port; |
|
1220 | - } |
|
1221 | - elseif (!empty($db_port)) |
|
1295 | + if ($db_port != ini_get('mysqli.default_port')) { |
|
1296 | + $changes['db_port'] = (int) $db_port; |
|
1297 | + } |
|
1298 | + } elseif (!empty($db_port)) |
|
1222 | 1299 | { |
1223 | 1300 | // If db_port is set and is the same as the default, set it to '' |
1224 | 1301 | if ($db_type == 'mysql') |
1225 | 1302 | { |
1226 | - if ($db_port == ini_get('mysqli.default_port')) |
|
1227 | - $changes['db_port'] = '\'\''; |
|
1228 | - elseif ($db_type == 'postgresql' && $db_port == 5432) |
|
1229 | - $changes['db_port'] = '\'\''; |
|
1303 | + if ($db_port == ini_get('mysqli.default_port')) { |
|
1304 | + $changes['db_port'] = '\'\''; |
|
1305 | + } elseif ($db_type == 'postgresql' && $db_port == 5432) { |
|
1306 | + $changes['db_port'] = '\'\''; |
|
1307 | + } |
|
1230 | 1308 | } |
1231 | 1309 | } |
1232 | 1310 | |
1233 | 1311 | // Maybe we haven't had this option yet? |
1234 | - if (empty($packagesdir)) |
|
1235 | - $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
1312 | + if (empty($packagesdir)) { |
|
1313 | + $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
1314 | + } |
|
1236 | 1315 | |
1237 | 1316 | // Add support for $tasksdir var. |
1238 | - if (empty($tasksdir)) |
|
1239 | - $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
1317 | + if (empty($tasksdir)) { |
|
1318 | + $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
1319 | + } |
|
1240 | 1320 | |
1241 | 1321 | // Make sure we fix the language as well. |
1242 | - if (stristr($language, '-utf8')) |
|
1243 | - $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
1322 | + if (stristr($language, '-utf8')) { |
|
1323 | + $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
1324 | + } |
|
1244 | 1325 | |
1245 | 1326 | // @todo Maybe change the cookie name if going to 1.1, too? |
1246 | 1327 | |
@@ -1251,8 +1332,9 @@ discard block |
||
1251 | 1332 | // Tell Settings.php to store db_last_error.php in the cache |
1252 | 1333 | move_db_last_error_to_cachedir(); |
1253 | 1334 | |
1254 | - if ($command_line) |
|
1255 | - echo ' Successful.' . "\n"; |
|
1335 | + if ($command_line) { |
|
1336 | + echo ' Successful.' . "\n"; |
|
1337 | + } |
|
1256 | 1338 | |
1257 | 1339 | // Are we doing debug? |
1258 | 1340 | if (isset($_POST['debug'])) |
@@ -1262,8 +1344,9 @@ discard block |
||
1262 | 1344 | } |
1263 | 1345 | |
1264 | 1346 | // If we're not backing up then jump one. |
1265 | - if (empty($_POST['backup'])) |
|
1266 | - $upcontext['current_step']++; |
|
1347 | + if (empty($_POST['backup'])) { |
|
1348 | + $upcontext['current_step']++; |
|
1349 | + } |
|
1267 | 1350 | |
1268 | 1351 | // If we've got here then let's proceed to the next step! |
1269 | 1352 | return true; |
@@ -1278,8 +1361,9 @@ discard block |
||
1278 | 1361 | $upcontext['page_title'] = $txt['backup_database']; |
1279 | 1362 | |
1280 | 1363 | // Done it already - js wise? |
1281 | - if (!empty($_POST['backup_done'])) |
|
1282 | - return true; |
|
1364 | + if (!empty($_POST['backup_done'])) { |
|
1365 | + return true; |
|
1366 | + } |
|
1283 | 1367 | |
1284 | 1368 | // Some useful stuff here. |
1285 | 1369 | db_extend(); |
@@ -1293,9 +1377,10 @@ discard block |
||
1293 | 1377 | $tables = $smcFunc['db_list_tables']($db, $filter); |
1294 | 1378 | |
1295 | 1379 | $table_names = array(); |
1296 | - foreach ($tables as $table) |
|
1297 | - if (substr($table, 0, 7) !== 'backup_') |
|
1380 | + foreach ($tables as $table) { |
|
1381 | + if (substr($table, 0, 7) !== 'backup_') |
|
1298 | 1382 | $table_names[] = $table; |
1383 | + } |
|
1299 | 1384 | |
1300 | 1385 | $upcontext['table_count'] = count($table_names); |
1301 | 1386 | $upcontext['cur_table_num'] = $_GET['substep']; |
@@ -1305,12 +1390,14 @@ discard block |
||
1305 | 1390 | $file_steps = $upcontext['table_count']; |
1306 | 1391 | |
1307 | 1392 | // What ones have we already done? |
1308 | - foreach ($table_names as $id => $table) |
|
1309 | - if ($id < $_GET['substep']) |
|
1393 | + foreach ($table_names as $id => $table) { |
|
1394 | + if ($id < $_GET['substep']) |
|
1310 | 1395 | $upcontext['previous_tables'][] = $table; |
1396 | + } |
|
1311 | 1397 | |
1312 | - if ($command_line) |
|
1313 | - echo 'Backing Up Tables.'; |
|
1398 | + if ($command_line) { |
|
1399 | + echo 'Backing Up Tables.'; |
|
1400 | + } |
|
1314 | 1401 | |
1315 | 1402 | // If we don't support javascript we backup here. |
1316 | 1403 | if (!$support_js || isset($_GET['xml'])) |
@@ -1329,8 +1416,9 @@ discard block |
||
1329 | 1416 | backupTable($table_names[$substep]); |
1330 | 1417 | |
1331 | 1418 | // If this is XML to keep it nice for the user do one table at a time anyway! |
1332 | - if (isset($_GET['xml'])) |
|
1333 | - return upgradeExit(); |
|
1419 | + if (isset($_GET['xml'])) { |
|
1420 | + return upgradeExit(); |
|
1421 | + } |
|
1334 | 1422 | } |
1335 | 1423 | |
1336 | 1424 | if ($command_line) |
@@ -1363,9 +1451,10 @@ discard block |
||
1363 | 1451 | |
1364 | 1452 | $smcFunc['db_backup_table']($table, 'backup_' . $table); |
1365 | 1453 | |
1366 | - if ($command_line) |
|
1367 | - echo ' done.'; |
|
1368 | -} |
|
1454 | + if ($command_line) { |
|
1455 | + echo ' done.'; |
|
1456 | + } |
|
1457 | + } |
|
1369 | 1458 | |
1370 | 1459 | // Step 2: Everything. |
1371 | 1460 | function DatabaseChanges() |
@@ -1374,8 +1463,9 @@ discard block |
||
1374 | 1463 | global $upcontext, $support_js, $db_type; |
1375 | 1464 | |
1376 | 1465 | // Have we just completed this? |
1377 | - if (!empty($_POST['database_done'])) |
|
1378 | - return true; |
|
1466 | + if (!empty($_POST['database_done'])) { |
|
1467 | + return true; |
|
1468 | + } |
|
1379 | 1469 | |
1380 | 1470 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes'; |
1381 | 1471 | $upcontext['page_title'] = $txt['database_changes']; |
@@ -1390,15 +1480,16 @@ discard block |
||
1390 | 1480 | ); |
1391 | 1481 | |
1392 | 1482 | // How many files are there in total? |
1393 | - if (isset($_GET['filecount'])) |
|
1394 | - $upcontext['file_count'] = (int) $_GET['filecount']; |
|
1395 | - else |
|
1483 | + if (isset($_GET['filecount'])) { |
|
1484 | + $upcontext['file_count'] = (int) $_GET['filecount']; |
|
1485 | + } else |
|
1396 | 1486 | { |
1397 | 1487 | $upcontext['file_count'] = 0; |
1398 | 1488 | foreach ($files as $file) |
1399 | 1489 | { |
1400 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) |
|
1401 | - $upcontext['file_count']++; |
|
1490 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) { |
|
1491 | + $upcontext['file_count']++; |
|
1492 | + } |
|
1402 | 1493 | } |
1403 | 1494 | } |
1404 | 1495 | |
@@ -1408,9 +1499,9 @@ discard block |
||
1408 | 1499 | $upcontext['cur_file_num'] = 0; |
1409 | 1500 | foreach ($files as $file) |
1410 | 1501 | { |
1411 | - if ($did_not_do) |
|
1412 | - $did_not_do--; |
|
1413 | - else |
|
1502 | + if ($did_not_do) { |
|
1503 | + $did_not_do--; |
|
1504 | + } else |
|
1414 | 1505 | { |
1415 | 1506 | $upcontext['cur_file_num']++; |
1416 | 1507 | $upcontext['cur_file_name'] = $file[0]; |
@@ -1437,12 +1528,13 @@ discard block |
||
1437 | 1528 | // Flag to move on to the next. |
1438 | 1529 | $upcontext['completed_step'] = true; |
1439 | 1530 | // Did we complete the whole file? |
1440 | - if ($nextFile) |
|
1441 | - $upcontext['current_debug_item_num'] = -1; |
|
1531 | + if ($nextFile) { |
|
1532 | + $upcontext['current_debug_item_num'] = -1; |
|
1533 | + } |
|
1442 | 1534 | return upgradeExit(); |
1535 | + } elseif ($support_js) { |
|
1536 | + break; |
|
1443 | 1537 | } |
1444 | - elseif ($support_js) |
|
1445 | - break; |
|
1446 | 1538 | } |
1447 | 1539 | // Set the progress bar to be right as if we had - even if we hadn't... |
1448 | 1540 | $upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100; |
@@ -1468,8 +1560,9 @@ discard block |
||
1468 | 1560 | global $user_info, $maintenance, $smcFunc, $db_type, $txt; |
1469 | 1561 | |
1470 | 1562 | // Now it's nice to have some of the basic SMF source files. |
1471 | - if (!isset($_GET['ssi']) && !$command_line) |
|
1472 | - redirectLocation('&ssi=1'); |
|
1563 | + if (!isset($_GET['ssi']) && !$command_line) { |
|
1564 | + redirectLocation('&ssi=1'); |
|
1565 | + } |
|
1473 | 1566 | |
1474 | 1567 | $upcontext['sub_template'] = 'upgrade_complete'; |
1475 | 1568 | $upcontext['page_title'] = $txt['upgrade_complete']; |
@@ -1485,14 +1578,16 @@ discard block |
||
1485 | 1578 | // Are we in maintenance mode? |
1486 | 1579 | if (isset($upcontext['user']['main'])) |
1487 | 1580 | { |
1488 | - if ($command_line) |
|
1489 | - echo ' * '; |
|
1581 | + if ($command_line) { |
|
1582 | + echo ' * '; |
|
1583 | + } |
|
1490 | 1584 | $upcontext['removed_maintenance'] = true; |
1491 | 1585 | $changes['maintenance'] = $upcontext['user']['main']; |
1492 | 1586 | } |
1493 | 1587 | // Otherwise if somehow we are in 2 let's go to 1. |
1494 | - elseif (!empty($maintenance) && $maintenance == 2) |
|
1495 | - $changes['maintenance'] = 1; |
|
1588 | + elseif (!empty($maintenance) && $maintenance == 2) { |
|
1589 | + $changes['maintenance'] = 1; |
|
1590 | + } |
|
1496 | 1591 | |
1497 | 1592 | // Wipe this out... |
1498 | 1593 | $upcontext['user'] = array(); |
@@ -1507,9 +1602,9 @@ discard block |
||
1507 | 1602 | $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__); |
1508 | 1603 | |
1509 | 1604 | // Now is the perfect time to fetch the SM files. |
1510 | - if ($command_line) |
|
1511 | - cli_scheduled_fetchSMfiles(); |
|
1512 | - else |
|
1605 | + if ($command_line) { |
|
1606 | + cli_scheduled_fetchSMfiles(); |
|
1607 | + } else |
|
1513 | 1608 | { |
1514 | 1609 | require_once($sourcedir . '/ScheduledTasks.php'); |
1515 | 1610 | $forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us. |
@@ -1517,8 +1612,9 @@ discard block |
||
1517 | 1612 | } |
1518 | 1613 | |
1519 | 1614 | // Log what we've done. |
1520 | - if (empty($user_info['id'])) |
|
1521 | - $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
1615 | + if (empty($user_info['id'])) { |
|
1616 | + $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
1617 | + } |
|
1522 | 1618 | |
1523 | 1619 | // Log the action manually, so CLI still works. |
1524 | 1620 | $smcFunc['db_insert']('', |
@@ -1537,8 +1633,9 @@ discard block |
||
1537 | 1633 | |
1538 | 1634 | // Save the current database version. |
1539 | 1635 | $server_version = $smcFunc['db_server_info'](); |
1540 | - if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
1541 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1636 | + if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
1637 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1638 | + } |
|
1542 | 1639 | |
1543 | 1640 | if ($command_line) |
1544 | 1641 | { |
@@ -1550,8 +1647,9 @@ discard block |
||
1550 | 1647 | |
1551 | 1648 | // Make sure it says we're done. |
1552 | 1649 | $upcontext['overall_percent'] = 100; |
1553 | - if (isset($upcontext['step_progress'])) |
|
1554 | - unset($upcontext['step_progress']); |
|
1650 | + if (isset($upcontext['step_progress'])) { |
|
1651 | + unset($upcontext['step_progress']); |
|
1652 | + } |
|
1555 | 1653 | |
1556 | 1654 | $_GET['substep'] = 0; |
1557 | 1655 | return false; |
@@ -1562,8 +1660,9 @@ discard block |
||
1562 | 1660 | { |
1563 | 1661 | global $sourcedir, $language, $forum_version, $modSettings, $smcFunc; |
1564 | 1662 | |
1565 | - if (empty($modSettings['time_format'])) |
|
1566 | - $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
1663 | + if (empty($modSettings['time_format'])) { |
|
1664 | + $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
1665 | + } |
|
1567 | 1666 | |
1568 | 1667 | // What files do we want to get |
1569 | 1668 | $request = $smcFunc['db_query']('', ' |
@@ -1597,8 +1696,9 @@ discard block |
||
1597 | 1696 | $file_data = fetch_web_data($url); |
1598 | 1697 | |
1599 | 1698 | // If we got an error - give up - the site might be down. |
1600 | - if ($file_data === false) |
|
1601 | - return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
1699 | + if ($file_data === false) { |
|
1700 | + return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
1701 | + } |
|
1602 | 1702 | |
1603 | 1703 | // Save the file to the database. |
1604 | 1704 | $smcFunc['db_query']('substring', ' |
@@ -1640,8 +1740,9 @@ discard block |
||
1640 | 1740 | $themeData = array(); |
1641 | 1741 | foreach ($values as $variable => $value) |
1642 | 1742 | { |
1643 | - if (!isset($value) || $value === null) |
|
1644 | - $value = 0; |
|
1743 | + if (!isset($value) || $value === null) { |
|
1744 | + $value = 0; |
|
1745 | + } |
|
1645 | 1746 | |
1646 | 1747 | $themeData[] = array(0, 1, $variable, $value); |
1647 | 1748 | } |
@@ -1670,8 +1771,9 @@ discard block |
||
1670 | 1771 | |
1671 | 1772 | foreach ($values as $variable => $value) |
1672 | 1773 | { |
1673 | - if (empty($modSettings[$value[0]])) |
|
1674 | - continue; |
|
1774 | + if (empty($modSettings[$value[0]])) { |
|
1775 | + continue; |
|
1776 | + } |
|
1675 | 1777 | |
1676 | 1778 | $smcFunc['db_query']('', ' |
1677 | 1779 | INSERT IGNORE INTO {db_prefix}themes |
@@ -1757,19 +1859,21 @@ discard block |
||
1757 | 1859 | set_error_handler( |
1758 | 1860 | function ($errno, $errstr, $errfile, $errline) use ($support_js) |
1759 | 1861 | { |
1760 | - if ($support_js) |
|
1761 | - return true; |
|
1762 | - else |
|
1763 | - echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
1862 | + if ($support_js) { |
|
1863 | + return true; |
|
1864 | + } else { |
|
1865 | + echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
1866 | + } |
|
1764 | 1867 | } |
1765 | 1868 | ); |
1766 | 1869 | |
1767 | 1870 | // If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8 |
1768 | 1871 | // Note it is expected to be in the format: ENGINE=MyISAM{$db_collation}; |
1769 | - if ($db_type == 'mysql') |
|
1770 | - $db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
1771 | - else |
|
1772 | - $db_collation = ''; |
|
1872 | + if ($db_type == 'mysql') { |
|
1873 | + $db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
1874 | + } else { |
|
1875 | + $db_collation = ''; |
|
1876 | + } |
|
1773 | 1877 | |
1774 | 1878 | $endl = $command_line ? "\n" : '<br>' . "\n"; |
1775 | 1879 | |
@@ -1781,8 +1885,9 @@ discard block |
||
1781 | 1885 | $last_step = ''; |
1782 | 1886 | |
1783 | 1887 | // Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php |
1784 | - if (isset($db_character_set) && $db_character_set === 'utf8') |
|
1785 | - $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
1888 | + if (isset($db_character_set) && $db_character_set === 'utf8') { |
|
1889 | + $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
1890 | + } |
|
1786 | 1891 | |
1787 | 1892 | // Count the total number of steps within this file - for progress. |
1788 | 1893 | $file_steps = substr_count(implode('', $lines), '---#'); |
@@ -1802,15 +1907,18 @@ discard block |
||
1802 | 1907 | $do_current = $substep >= $_GET['substep']; |
1803 | 1908 | |
1804 | 1909 | // Get rid of any comments in the beginning of the line... |
1805 | - if (substr(trim($line), 0, 2) === '/*') |
|
1806 | - $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
1910 | + if (substr(trim($line), 0, 2) === '/*') { |
|
1911 | + $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
1912 | + } |
|
1807 | 1913 | |
1808 | 1914 | // Always flush. Flush, flush, flush. Flush, flush, flush, flush! FLUSH! |
1809 | - if ($is_debug && !$support_js && $command_line) |
|
1810 | - flush(); |
|
1915 | + if ($is_debug && !$support_js && $command_line) { |
|
1916 | + flush(); |
|
1917 | + } |
|
1811 | 1918 | |
1812 | - if (trim($line) === '') |
|
1813 | - continue; |
|
1919 | + if (trim($line) === '') { |
|
1920 | + continue; |
|
1921 | + } |
|
1814 | 1922 | |
1815 | 1923 | if (trim(substr($line, 0, 3)) === '---') |
1816 | 1924 | { |
@@ -1820,8 +1928,9 @@ discard block |
||
1820 | 1928 | if (trim($current_data) != '' && $type !== '}') |
1821 | 1929 | { |
1822 | 1930 | $upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl; |
1823 | - if ($command_line) |
|
1824 | - echo $upcontext['error_message']; |
|
1931 | + if ($command_line) { |
|
1932 | + echo $upcontext['error_message']; |
|
1933 | + } |
|
1825 | 1934 | } |
1826 | 1935 | |
1827 | 1936 | if ($type == ' ') |
@@ -1839,17 +1948,18 @@ discard block |
||
1839 | 1948 | if ($do_current) |
1840 | 1949 | { |
1841 | 1950 | $upcontext['actioned_items'][] = $last_step; |
1842 | - if ($command_line) |
|
1843 | - echo ' * '; |
|
1951 | + if ($command_line) { |
|
1952 | + echo ' * '; |
|
1953 | + } |
|
1844 | 1954 | } |
1845 | - } |
|
1846 | - elseif ($type == '#') |
|
1955 | + } elseif ($type == '#') |
|
1847 | 1956 | { |
1848 | 1957 | $upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps; |
1849 | 1958 | |
1850 | 1959 | $upcontext['current_debug_item_num']++; |
1851 | - if (trim($line) != '---#') |
|
1852 | - $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
1960 | + if (trim($line) != '---#') { |
|
1961 | + $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
1962 | + } |
|
1853 | 1963 | |
1854 | 1964 | // Have we already done something? |
1855 | 1965 | if (isset($_GET['xml']) && $done_something) |
@@ -1860,34 +1970,36 @@ discard block |
||
1860 | 1970 | |
1861 | 1971 | if ($do_current) |
1862 | 1972 | { |
1863 | - if (trim($line) == '---#' && $command_line) |
|
1864 | - echo ' done.', $endl; |
|
1865 | - elseif ($command_line) |
|
1866 | - echo ' +++ ', rtrim(substr($line, 4)); |
|
1867 | - elseif (trim($line) != '---#') |
|
1973 | + if (trim($line) == '---#' && $command_line) { |
|
1974 | + echo ' done.', $endl; |
|
1975 | + } elseif ($command_line) { |
|
1976 | + echo ' +++ ', rtrim(substr($line, 4)); |
|
1977 | + } elseif (trim($line) != '---#') |
|
1868 | 1978 | { |
1869 | - if ($is_debug) |
|
1870 | - $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
1979 | + if ($is_debug) { |
|
1980 | + $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
1981 | + } |
|
1871 | 1982 | } |
1872 | 1983 | } |
1873 | 1984 | |
1874 | 1985 | if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep']) |
1875 | 1986 | { |
1876 | - if ($command_line) |
|
1877 | - echo ' * '; |
|
1878 | - else |
|
1879 | - $upcontext['actioned_items'][] = $last_step; |
|
1987 | + if ($command_line) { |
|
1988 | + echo ' * '; |
|
1989 | + } else { |
|
1990 | + $upcontext['actioned_items'][] = $last_step; |
|
1991 | + } |
|
1880 | 1992 | } |
1881 | 1993 | |
1882 | 1994 | // Small step - only if we're actually doing stuff. |
1883 | - if ($do_current) |
|
1884 | - nextSubstep(++$substep); |
|
1885 | - else |
|
1886 | - $substep++; |
|
1887 | - } |
|
1888 | - elseif ($type == '{') |
|
1889 | - $current_type = 'code'; |
|
1890 | - elseif ($type == '}') |
|
1995 | + if ($do_current) { |
|
1996 | + nextSubstep(++$substep); |
|
1997 | + } else { |
|
1998 | + $substep++; |
|
1999 | + } |
|
2000 | + } elseif ($type == '{') { |
|
2001 | + $current_type = 'code'; |
|
2002 | + } elseif ($type == '}') |
|
1891 | 2003 | { |
1892 | 2004 | $current_type = 'sql'; |
1893 | 2005 | |
@@ -1900,8 +2012,9 @@ discard block |
||
1900 | 2012 | if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false) |
1901 | 2013 | { |
1902 | 2014 | $upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl; |
1903 | - if ($command_line) |
|
1904 | - echo $upcontext['error_message']; |
|
2015 | + if ($command_line) { |
|
2016 | + echo $upcontext['error_message']; |
|
2017 | + } |
|
1905 | 2018 | } |
1906 | 2019 | |
1907 | 2020 | // Done with code! |
@@ -1988,8 +2101,9 @@ discard block |
||
1988 | 2101 | $db_unbuffered = false; |
1989 | 2102 | |
1990 | 2103 | // Failure?! |
1991 | - if ($result !== false) |
|
1992 | - return $result; |
|
2104 | + if ($result !== false) { |
|
2105 | + return $result; |
|
2106 | + } |
|
1993 | 2107 | |
1994 | 2108 | $db_error_message = $smcFunc['db_error']($db_connection); |
1995 | 2109 | // If MySQL we do something more clever. |
@@ -2017,54 +2131,61 @@ discard block |
||
2017 | 2131 | { |
2018 | 2132 | mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`'); |
2019 | 2133 | $result = mysqli_query($db_connection, $string); |
2020 | - if ($result !== false) |
|
2021 | - return $result; |
|
2134 | + if ($result !== false) { |
|
2135 | + return $result; |
|
2136 | + } |
|
2022 | 2137 | } |
2023 | - } |
|
2024 | - elseif ($mysqli_errno == 2013) |
|
2138 | + } elseif ($mysqli_errno == 2013) |
|
2025 | 2139 | { |
2026 | 2140 | $db_connection = mysqli_connect($db_server, $db_user, $db_passwd); |
2027 | 2141 | mysqli_select_db($db_connection, $db_name); |
2028 | 2142 | if ($db_connection) |
2029 | 2143 | { |
2030 | 2144 | $result = mysqli_query($db_connection, $string); |
2031 | - if ($result !== false) |
|
2032 | - return $result; |
|
2145 | + if ($result !== false) { |
|
2146 | + return $result; |
|
2147 | + } |
|
2033 | 2148 | } |
2034 | 2149 | } |
2035 | 2150 | // Duplicate column name... should be okay ;). |
2036 | - elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) |
|
2037 | - return false; |
|
2151 | + elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) { |
|
2152 | + return false; |
|
2153 | + } |
|
2038 | 2154 | // Duplicate insert... make sure it's the proper type of query ;). |
2039 | - elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) |
|
2040 | - return false; |
|
2155 | + elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) { |
|
2156 | + return false; |
|
2157 | + } |
|
2041 | 2158 | // Creating an index on a non-existent column. |
2042 | - elseif ($mysqli_errno == 1072) |
|
2043 | - return false; |
|
2044 | - elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') |
|
2045 | - return false; |
|
2159 | + elseif ($mysqli_errno == 1072) { |
|
2160 | + return false; |
|
2161 | + } elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') { |
|
2162 | + return false; |
|
2163 | + } |
|
2046 | 2164 | } |
2047 | 2165 | // If a table already exists don't go potty. |
2048 | 2166 | else |
2049 | 2167 | { |
2050 | 2168 | if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U'))) |
2051 | 2169 | { |
2052 | - if (strpos($db_error_message, 'exist') !== false) |
|
2053 | - return true; |
|
2054 | - } |
|
2055 | - elseif (strpos(trim($string), 'INSERT ') !== false) |
|
2170 | + if (strpos($db_error_message, 'exist') !== false) { |
|
2171 | + return true; |
|
2172 | + } |
|
2173 | + } elseif (strpos(trim($string), 'INSERT ') !== false) |
|
2056 | 2174 | { |
2057 | - if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) |
|
2058 | - return true; |
|
2175 | + if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) { |
|
2176 | + return true; |
|
2177 | + } |
|
2059 | 2178 | } |
2060 | 2179 | } |
2061 | 2180 | |
2062 | 2181 | // Get the query string so we pass everything. |
2063 | 2182 | $query_string = ''; |
2064 | - foreach ($_GET as $k => $v) |
|
2065 | - $query_string .= ';' . $k . '=' . $v; |
|
2066 | - if (strlen($query_string) != 0) |
|
2067 | - $query_string = '?' . substr($query_string, 1); |
|
2183 | + foreach ($_GET as $k => $v) { |
|
2184 | + $query_string .= ';' . $k . '=' . $v; |
|
2185 | + } |
|
2186 | + if (strlen($query_string) != 0) { |
|
2187 | + $query_string = '?' . substr($query_string, 1); |
|
2188 | + } |
|
2068 | 2189 | |
2069 | 2190 | if ($command_line) |
2070 | 2191 | { |
@@ -2119,16 +2240,18 @@ discard block |
||
2119 | 2240 | { |
2120 | 2241 | $found |= 1; |
2121 | 2242 | // Do some checks on the data if we have it set. |
2122 | - if (isset($change['col_type'])) |
|
2123 | - $found &= $change['col_type'] === $column['type']; |
|
2124 | - if (isset($change['null_allowed'])) |
|
2125 | - $found &= $column['null'] == $change['null_allowed']; |
|
2126 | - if (isset($change['default'])) |
|
2127 | - $found &= $change['default'] === $column['default']; |
|
2243 | + if (isset($change['col_type'])) { |
|
2244 | + $found &= $change['col_type'] === $column['type']; |
|
2245 | + } |
|
2246 | + if (isset($change['null_allowed'])) { |
|
2247 | + $found &= $column['null'] == $change['null_allowed']; |
|
2248 | + } |
|
2249 | + if (isset($change['default'])) { |
|
2250 | + $found &= $change['default'] === $column['default']; |
|
2251 | + } |
|
2128 | 2252 | } |
2129 | 2253 | } |
2130 | - } |
|
2131 | - elseif ($change['type'] === 'index') |
|
2254 | + } elseif ($change['type'] === 'index') |
|
2132 | 2255 | { |
2133 | 2256 | $request = upgrade_query(' |
2134 | 2257 | SHOW INDEX |
@@ -2137,9 +2260,10 @@ discard block |
||
2137 | 2260 | { |
2138 | 2261 | $cur_index = array(); |
2139 | 2262 | |
2140 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2141 | - if ($row['Key_name'] === $change['name']) |
|
2263 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2264 | + if ($row['Key_name'] === $change['name']) |
|
2142 | 2265 | $cur_index[(int) $row['Seq_in_index']] = $row['Column_name']; |
2266 | + } |
|
2143 | 2267 | |
2144 | 2268 | ksort($cur_index, SORT_NUMERIC); |
2145 | 2269 | $found = array_values($cur_index) === $change['target_columns']; |
@@ -2149,14 +2273,17 @@ discard block |
||
2149 | 2273 | } |
2150 | 2274 | |
2151 | 2275 | // If we're trying to add and it's added, we're done. |
2152 | - if ($found && in_array($change['method'], array('add', 'change'))) |
|
2153 | - return true; |
|
2276 | + if ($found && in_array($change['method'], array('add', 'change'))) { |
|
2277 | + return true; |
|
2278 | + } |
|
2154 | 2279 | // Otherwise if we're removing and it wasn't found we're also done. |
2155 | - elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) |
|
2156 | - return true; |
|
2280 | + elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) { |
|
2281 | + return true; |
|
2282 | + } |
|
2157 | 2283 | // Otherwise is it just a test? |
2158 | - elseif ($is_test) |
|
2159 | - return false; |
|
2284 | + elseif ($is_test) { |
|
2285 | + return false; |
|
2286 | + } |
|
2160 | 2287 | |
2161 | 2288 | // Not found it yet? Bummer! How about we see if we're currently doing it? |
2162 | 2289 | $running = false; |
@@ -2167,8 +2294,9 @@ discard block |
||
2167 | 2294 | SHOW FULL PROCESSLIST'); |
2168 | 2295 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2169 | 2296 | { |
2170 | - if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) |
|
2171 | - $found = true; |
|
2297 | + if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) { |
|
2298 | + $found = true; |
|
2299 | + } |
|
2172 | 2300 | } |
2173 | 2301 | |
2174 | 2302 | // Can't find it? Then we need to run it fools! |
@@ -2180,8 +2308,9 @@ discard block |
||
2180 | 2308 | ALTER TABLE ' . $db_prefix . $change['table'] . ' |
2181 | 2309 | ' . $change['text'], true) !== false; |
2182 | 2310 | |
2183 | - if (!$success) |
|
2184 | - return false; |
|
2311 | + if (!$success) { |
|
2312 | + return false; |
|
2313 | + } |
|
2185 | 2314 | |
2186 | 2315 | // Return |
2187 | 2316 | $running = true; |
@@ -2223,8 +2352,9 @@ discard block |
||
2223 | 2352 | 'db_error_skip' => true, |
2224 | 2353 | ) |
2225 | 2354 | ); |
2226 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
2227 | - die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
2355 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
2356 | + die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
2357 | + } |
|
2228 | 2358 | $table_row = $smcFunc['db_fetch_assoc']($request); |
2229 | 2359 | $smcFunc['db_free_result']($request); |
2230 | 2360 | |
@@ -2246,18 +2376,19 @@ discard block |
||
2246 | 2376 | ) |
2247 | 2377 | ); |
2248 | 2378 | // No results? Just forget it all together. |
2249 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
2250 | - unset($table_row['Collation']); |
|
2251 | - else |
|
2252 | - $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
2379 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
2380 | + unset($table_row['Collation']); |
|
2381 | + } else { |
|
2382 | + $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
2383 | + } |
|
2253 | 2384 | $smcFunc['db_free_result']($request); |
2254 | 2385 | } |
2255 | 2386 | |
2256 | 2387 | if ($column_fix) |
2257 | 2388 | { |
2258 | 2389 | // Make sure there are no NULL's left. |
2259 | - if ($null_fix) |
|
2260 | - $smcFunc['db_query']('', ' |
|
2390 | + if ($null_fix) { |
|
2391 | + $smcFunc['db_query']('', ' |
|
2261 | 2392 | UPDATE {db_prefix}' . $change['table'] . ' |
2262 | 2393 | SET ' . $change['column'] . ' = {string:default} |
2263 | 2394 | WHERE ' . $change['column'] . ' IS NULL', |
@@ -2266,6 +2397,7 @@ discard block |
||
2266 | 2397 | 'db_error_skip' => true, |
2267 | 2398 | ) |
2268 | 2399 | ); |
2400 | + } |
|
2269 | 2401 | |
2270 | 2402 | // Do the actual alteration. |
2271 | 2403 | $smcFunc['db_query']('', ' |
@@ -2294,8 +2426,9 @@ discard block |
||
2294 | 2426 | } |
2295 | 2427 | |
2296 | 2428 | // Not a column we need to check on? |
2297 | - if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) |
|
2298 | - return; |
|
2429 | + if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) { |
|
2430 | + return; |
|
2431 | + } |
|
2299 | 2432 | |
2300 | 2433 | // Break it up you (six|seven). |
2301 | 2434 | $temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text'])); |
@@ -2314,13 +2447,13 @@ discard block |
||
2314 | 2447 | 'new_name' => $temp[2], |
2315 | 2448 | )); |
2316 | 2449 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
2317 | - if ($smcFunc['db_num_rows'] != 1) |
|
2318 | - return; |
|
2450 | + if ($smcFunc['db_num_rows'] != 1) { |
|
2451 | + return; |
|
2452 | + } |
|
2319 | 2453 | |
2320 | 2454 | list (, $current_type) = $smcFunc['db_fetch_assoc']($request); |
2321 | 2455 | $smcFunc['db_free_result']($request); |
2322 | - } |
|
2323 | - else |
|
2456 | + } else |
|
2324 | 2457 | { |
2325 | 2458 | // Do this the old fashion, sure method way. |
2326 | 2459 | $request = $smcFunc['db_query']('', ' |
@@ -2331,21 +2464,24 @@ discard block |
||
2331 | 2464 | )); |
2332 | 2465 | // Mayday! |
2333 | 2466 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
2334 | - if ($smcFunc['db_num_rows'] == 0) |
|
2335 | - return; |
|
2467 | + if ($smcFunc['db_num_rows'] == 0) { |
|
2468 | + return; |
|
2469 | + } |
|
2336 | 2470 | |
2337 | 2471 | // Oh where, oh where has my little field gone. Oh where can it be... |
2338 | - while ($row = $smcFunc['db_query']($request)) |
|
2339 | - if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
2472 | + while ($row = $smcFunc['db_query']($request)) { |
|
2473 | + if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
2340 | 2474 | { |
2341 | 2475 | $current_type = $row['Type']; |
2476 | + } |
|
2342 | 2477 | break; |
2343 | 2478 | } |
2344 | 2479 | } |
2345 | 2480 | |
2346 | 2481 | // If this doesn't match, the column may of been altered for a reason. |
2347 | - if (trim($current_type) != trim($temp[3])) |
|
2348 | - $temp[3] = $current_type; |
|
2482 | + if (trim($current_type) != trim($temp[3])) { |
|
2483 | + $temp[3] = $current_type; |
|
2484 | + } |
|
2349 | 2485 | |
2350 | 2486 | // Piece this back together. |
2351 | 2487 | $change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp)); |
@@ -2357,8 +2493,9 @@ discard block |
||
2357 | 2493 | global $start_time, $timeLimitThreshold, $command_line, $custom_warning; |
2358 | 2494 | global $step_progress, $is_debug, $upcontext; |
2359 | 2495 | |
2360 | - if ($_GET['substep'] < $substep) |
|
2361 | - $_GET['substep'] = $substep; |
|
2496 | + if ($_GET['substep'] < $substep) { |
|
2497 | + $_GET['substep'] = $substep; |
|
2498 | + } |
|
2362 | 2499 | |
2363 | 2500 | if ($command_line) |
2364 | 2501 | { |
@@ -2371,29 +2508,33 @@ discard block |
||
2371 | 2508 | } |
2372 | 2509 | |
2373 | 2510 | @set_time_limit(300); |
2374 | - if (function_exists('apache_reset_timeout')) |
|
2375 | - @apache_reset_timeout(); |
|
2511 | + if (function_exists('apache_reset_timeout')) { |
|
2512 | + @apache_reset_timeout(); |
|
2513 | + } |
|
2376 | 2514 | |
2377 | - if (time() - $start_time <= $timeLimitThreshold) |
|
2378 | - return; |
|
2515 | + if (time() - $start_time <= $timeLimitThreshold) { |
|
2516 | + return; |
|
2517 | + } |
|
2379 | 2518 | |
2380 | 2519 | // Do we have some custom step progress stuff? |
2381 | 2520 | if (!empty($step_progress)) |
2382 | 2521 | { |
2383 | 2522 | $upcontext['substep_progress'] = 0; |
2384 | 2523 | $upcontext['substep_progress_name'] = $step_progress['name']; |
2385 | - if ($step_progress['current'] > $step_progress['total']) |
|
2386 | - $upcontext['substep_progress'] = 99.9; |
|
2387 | - else |
|
2388 | - $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
2524 | + if ($step_progress['current'] > $step_progress['total']) { |
|
2525 | + $upcontext['substep_progress'] = 99.9; |
|
2526 | + } else { |
|
2527 | + $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
2528 | + } |
|
2389 | 2529 | |
2390 | 2530 | // Make it nicely rounded. |
2391 | 2531 | $upcontext['substep_progress'] = round($upcontext['substep_progress'], 1); |
2392 | 2532 | } |
2393 | 2533 | |
2394 | 2534 | // If this is XML we just exit right away! |
2395 | - if (isset($_GET['xml'])) |
|
2396 | - return upgradeExit(); |
|
2535 | + if (isset($_GET['xml'])) { |
|
2536 | + return upgradeExit(); |
|
2537 | + } |
|
2397 | 2538 | |
2398 | 2539 | // We're going to pause after this! |
2399 | 2540 | $upcontext['pause'] = true; |
@@ -2401,13 +2542,15 @@ discard block |
||
2401 | 2542 | $upcontext['query_string'] = ''; |
2402 | 2543 | foreach ($_GET as $k => $v) |
2403 | 2544 | { |
2404 | - if ($k != 'data' && $k != 'substep' && $k != 'step') |
|
2405 | - $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
2545 | + if ($k != 'data' && $k != 'substep' && $k != 'step') { |
|
2546 | + $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
2547 | + } |
|
2406 | 2548 | } |
2407 | 2549 | |
2408 | 2550 | // Custom warning? |
2409 | - if (!empty($custom_warning)) |
|
2410 | - $upcontext['custom_warning'] = $custom_warning; |
|
2551 | + if (!empty($custom_warning)) { |
|
2552 | + $upcontext['custom_warning'] = $custom_warning; |
|
2553 | + } |
|
2411 | 2554 | |
2412 | 2555 | upgradeExit(); |
2413 | 2556 | } |
@@ -2422,25 +2565,26 @@ discard block |
||
2422 | 2565 | ob_implicit_flush(true); |
2423 | 2566 | @set_time_limit(600); |
2424 | 2567 | |
2425 | - if (!isset($_SERVER['argv'])) |
|
2426 | - $_SERVER['argv'] = array(); |
|
2568 | + if (!isset($_SERVER['argv'])) { |
|
2569 | + $_SERVER['argv'] = array(); |
|
2570 | + } |
|
2427 | 2571 | $_GET['maint'] = 1; |
2428 | 2572 | |
2429 | 2573 | foreach ($_SERVER['argv'] as $i => $arg) |
2430 | 2574 | { |
2431 | - if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) |
|
2432 | - $_GET['lang'] = $match[1]; |
|
2433 | - elseif (preg_match('~^--path=(.+)$~', $arg) != 0) |
|
2434 | - continue; |
|
2435 | - elseif ($arg == '--no-maintenance') |
|
2436 | - $_GET['maint'] = 0; |
|
2437 | - elseif ($arg == '--debug') |
|
2438 | - $is_debug = true; |
|
2439 | - elseif ($arg == '--backup') |
|
2440 | - $_POST['backup'] = 1; |
|
2441 | - elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) |
|
2442 | - $_GET['conv'] = 1; |
|
2443 | - elseif ($i != 0) |
|
2575 | + if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) { |
|
2576 | + $_GET['lang'] = $match[1]; |
|
2577 | + } elseif (preg_match('~^--path=(.+)$~', $arg) != 0) { |
|
2578 | + continue; |
|
2579 | + } elseif ($arg == '--no-maintenance') { |
|
2580 | + $_GET['maint'] = 0; |
|
2581 | + } elseif ($arg == '--debug') { |
|
2582 | + $is_debug = true; |
|
2583 | + } elseif ($arg == '--backup') { |
|
2584 | + $_POST['backup'] = 1; |
|
2585 | + } elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) { |
|
2586 | + $_GET['conv'] = 1; |
|
2587 | + } elseif ($i != 0) |
|
2444 | 2588 | { |
2445 | 2589 | echo 'SMF Command-line Upgrader |
2446 | 2590 | Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]... |
@@ -2454,10 +2598,12 @@ discard block |
||
2454 | 2598 | } |
2455 | 2599 | } |
2456 | 2600 | |
2457 | - if (!php_version_check()) |
|
2458 | - print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
2459 | - if (!db_version_check()) |
|
2460 | - print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
2601 | + if (!php_version_check()) { |
|
2602 | + print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
2603 | + } |
|
2604 | + if (!db_version_check()) { |
|
2605 | + print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
2606 | + } |
|
2461 | 2607 | |
2462 | 2608 | // Do some checks to make sure they have proper privileges |
2463 | 2609 | db_extend('packages'); |
@@ -2472,34 +2618,39 @@ discard block |
||
2472 | 2618 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
2473 | 2619 | |
2474 | 2620 | // Sorry... we need CREATE, ALTER and DROP |
2475 | - if (!$create || !$alter || !$drop) |
|
2476 | - print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true); |
|
2621 | + if (!$create || !$alter || !$drop) { |
|
2622 | + print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true); |
|
2623 | + } |
|
2477 | 2624 | |
2478 | 2625 | $check = @file_exists($modSettings['theme_dir'] . '/index.template.php') |
2479 | 2626 | && @file_exists($sourcedir . '/QueryString.php') |
2480 | 2627 | && @file_exists($sourcedir . '/ManageBoards.php'); |
2481 | - if (!$check && !isset($modSettings['smfVersion'])) |
|
2482 | - print_error('Error: Some files are missing or out-of-date.', true); |
|
2628 | + if (!$check && !isset($modSettings['smfVersion'])) { |
|
2629 | + print_error('Error: Some files are missing or out-of-date.', true); |
|
2630 | + } |
|
2483 | 2631 | |
2484 | 2632 | // Do a quick version spot check. |
2485 | 2633 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
2486 | 2634 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
2487 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
2488 | - print_error('Error: Some files have not yet been updated properly.'); |
|
2635 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
2636 | + print_error('Error: Some files have not yet been updated properly.'); |
|
2637 | + } |
|
2489 | 2638 | |
2490 | 2639 | // Make sure Settings.php is writable. |
2491 | 2640 | quickFileWritable($boarddir . '/Settings.php'); |
2492 | - if (!is_writable($boarddir . '/Settings.php')) |
|
2493 | - print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
2641 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
2642 | + print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
2643 | + } |
|
2494 | 2644 | |
2495 | 2645 | // Make sure Settings_bak.php is writable. |
2496 | 2646 | quickFileWritable($boarddir . '/Settings_bak.php'); |
2497 | - if (!is_writable($boarddir . '/Settings_bak.php')) |
|
2498 | - print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
2647 | + if (!is_writable($boarddir . '/Settings_bak.php')) { |
|
2648 | + print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
2649 | + } |
|
2499 | 2650 | |
2500 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
2501 | - print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
2502 | - elseif (isset($modSettings['agreement'])) |
|
2651 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
2652 | + print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
2653 | + } elseif (isset($modSettings['agreement'])) |
|
2503 | 2654 | { |
2504 | 2655 | $fp = fopen($boarddir . '/agreement.txt', 'w'); |
2505 | 2656 | fwrite($fp, $modSettings['agreement']); |
@@ -2509,36 +2660,42 @@ discard block |
||
2509 | 2660 | // Make sure Themes is writable. |
2510 | 2661 | quickFileWritable($modSettings['theme_dir']); |
2511 | 2662 | |
2512 | - if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) |
|
2513 | - print_error('Error: Unable to obtain write access to "Themes".'); |
|
2663 | + if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) { |
|
2664 | + print_error('Error: Unable to obtain write access to "Themes".'); |
|
2665 | + } |
|
2514 | 2666 | |
2515 | 2667 | // Make sure cache directory exists and is writable! |
2516 | 2668 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
2517 | - if (!file_exists($cachedir_temp)) |
|
2518 | - @mkdir($cachedir_temp); |
|
2669 | + if (!file_exists($cachedir_temp)) { |
|
2670 | + @mkdir($cachedir_temp); |
|
2671 | + } |
|
2519 | 2672 | |
2520 | 2673 | // Make sure the cache temp dir is writable. |
2521 | 2674 | quickFileWritable($cachedir_temp); |
2522 | 2675 | |
2523 | - if (!is_writable($cachedir_temp)) |
|
2524 | - print_error('Error: Unable to obtain write access to "cache".', true); |
|
2676 | + if (!is_writable($cachedir_temp)) { |
|
2677 | + print_error('Error: Unable to obtain write access to "cache".', true); |
|
2678 | + } |
|
2525 | 2679 | |
2526 | 2680 | // Make sure db_last_error.php is writable. |
2527 | 2681 | quickFileWritable($cachedir_temp . '/db_last_error.php'); |
2528 | - if (!is_writable($cachedir_temp . '/db_last_error.php')) |
|
2529 | - print_error('Error: Unable to obtain write access to "db_last_error.php".'); |
|
2682 | + if (!is_writable($cachedir_temp . '/db_last_error.php')) { |
|
2683 | + print_error('Error: Unable to obtain write access to "db_last_error.php".'); |
|
2684 | + } |
|
2530 | 2685 | |
2531 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
2532 | - print_error('Error: Unable to find language files!', true); |
|
2533 | - else |
|
2686 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
2687 | + print_error('Error: Unable to find language files!', true); |
|
2688 | + } else |
|
2534 | 2689 | { |
2535 | 2690 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
2536 | 2691 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
2537 | 2692 | |
2538 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
2539 | - print_error('Error: Language files out of date.', true); |
|
2540 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
2541 | - print_error('Error: Install language is missing for selected language.', true); |
|
2693 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
2694 | + print_error('Error: Language files out of date.', true); |
|
2695 | + } |
|
2696 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
2697 | + print_error('Error: Install language is missing for selected language.', true); |
|
2698 | + } |
|
2542 | 2699 | |
2543 | 2700 | // Otherwise include it! |
2544 | 2701 | require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
@@ -2558,8 +2715,9 @@ discard block |
||
2558 | 2715 | global $db_prefix, $db_type, $command_line, $support_js, $txt; |
2559 | 2716 | |
2560 | 2717 | // Done it already? |
2561 | - if (!empty($_POST['utf8_done'])) |
|
2562 | - return true; |
|
2718 | + if (!empty($_POST['utf8_done'])) { |
|
2719 | + return true; |
|
2720 | + } |
|
2563 | 2721 | |
2564 | 2722 | // First make sure they aren't already on UTF-8 before we go anywhere... |
2565 | 2723 | if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8')) |
@@ -2572,8 +2730,7 @@ discard block |
||
2572 | 2730 | ); |
2573 | 2731 | |
2574 | 2732 | return true; |
2575 | - } |
|
2576 | - else |
|
2733 | + } else |
|
2577 | 2734 | { |
2578 | 2735 | $upcontext['page_title'] = $txt['converting_utf8']; |
2579 | 2736 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8'; |
@@ -2617,8 +2774,9 @@ discard block |
||
2617 | 2774 | ) |
2618 | 2775 | ); |
2619 | 2776 | $db_charsets = array(); |
2620 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2621 | - $db_charsets[] = $row['Charset']; |
|
2777 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2778 | + $db_charsets[] = $row['Charset']; |
|
2779 | + } |
|
2622 | 2780 | |
2623 | 2781 | $smcFunc['db_free_result']($request); |
2624 | 2782 | |
@@ -2654,13 +2812,15 @@ discard block |
||
2654 | 2812 | // If there's a fulltext index, we need to drop it first... |
2655 | 2813 | if ($request !== false || $smcFunc['db_num_rows']($request) != 0) |
2656 | 2814 | { |
2657 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2658 | - if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
2815 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2816 | + if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
2659 | 2817 | $upcontext['fulltext_index'][] = $row['Key_name']; |
2818 | + } |
|
2660 | 2819 | $smcFunc['db_free_result']($request); |
2661 | 2820 | |
2662 | - if (isset($upcontext['fulltext_index'])) |
|
2663 | - $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
2821 | + if (isset($upcontext['fulltext_index'])) { |
|
2822 | + $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
2823 | + } |
|
2664 | 2824 | } |
2665 | 2825 | |
2666 | 2826 | // Drop it and make a note... |
@@ -2850,8 +3010,9 @@ discard block |
||
2850 | 3010 | $replace = '%field%'; |
2851 | 3011 | |
2852 | 3012 | // Build a huge REPLACE statement... |
2853 | - foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) |
|
2854 | - $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
3013 | + foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) { |
|
3014 | + $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
3015 | + } |
|
2855 | 3016 | } |
2856 | 3017 | |
2857 | 3018 | // Get a list of table names ahead of time... This makes it easier to set our substep and such |
@@ -2861,9 +3022,10 @@ discard block |
||
2861 | 3022 | $upcontext['table_count'] = count($queryTables); |
2862 | 3023 | |
2863 | 3024 | // What ones have we already done? |
2864 | - foreach ($queryTables as $id => $table) |
|
2865 | - if ($id < $_GET['substep']) |
|
3025 | + foreach ($queryTables as $id => $table) { |
|
3026 | + if ($id < $_GET['substep']) |
|
2866 | 3027 | $upcontext['previous_tables'][] = $table; |
3028 | + } |
|
2867 | 3029 | |
2868 | 3030 | $upcontext['cur_table_num'] = $_GET['substep']; |
2869 | 3031 | $upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]); |
@@ -2900,8 +3062,9 @@ discard block |
||
2900 | 3062 | nextSubstep($substep); |
2901 | 3063 | |
2902 | 3064 | // Just to make sure it doesn't time out. |
2903 | - if (function_exists('apache_reset_timeout')) |
|
2904 | - @apache_reset_timeout(); |
|
3065 | + if (function_exists('apache_reset_timeout')) { |
|
3066 | + @apache_reset_timeout(); |
|
3067 | + } |
|
2905 | 3068 | |
2906 | 3069 | $table_charsets = array(); |
2907 | 3070 | |
@@ -2924,8 +3087,9 @@ discard block |
||
2924 | 3087 | |
2925 | 3088 | // Build structure of columns to operate on organized by charset; only operate on columns not yet utf8 |
2926 | 3089 | if ($charset != 'utf8') { |
2927 | - if (!isset($table_charsets[$charset])) |
|
2928 | - $table_charsets[$charset] = array(); |
|
3090 | + if (!isset($table_charsets[$charset])) { |
|
3091 | + $table_charsets[$charset] = array(); |
|
3092 | + } |
|
2929 | 3093 | |
2930 | 3094 | $table_charsets[$charset][] = $column_info; |
2931 | 3095 | } |
@@ -2966,10 +3130,11 @@ discard block |
||
2966 | 3130 | if (isset($translation_tables[$upcontext['charset_detected']])) |
2967 | 3131 | { |
2968 | 3132 | $update = ''; |
2969 | - foreach ($table_charsets as $charset => $columns) |
|
2970 | - foreach ($columns as $column) |
|
3133 | + foreach ($table_charsets as $charset => $columns) { |
|
3134 | + foreach ($columns as $column) |
|
2971 | 3135 | $update .= ' |
2972 | 3136 | ' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ','; |
3137 | + } |
|
2973 | 3138 | |
2974 | 3139 | $smcFunc['db_query']('', ' |
2975 | 3140 | UPDATE {raw:table_name} |
@@ -2994,8 +3159,9 @@ discard block |
||
2994 | 3159 | // Now do the actual conversion (if still needed). |
2995 | 3160 | if ($charsets[$upcontext['charset_detected']] !== 'utf8') |
2996 | 3161 | { |
2997 | - if ($command_line) |
|
2998 | - echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
3162 | + if ($command_line) { |
|
3163 | + echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
3164 | + } |
|
2999 | 3165 | |
3000 | 3166 | $smcFunc['db_query']('', ' |
3001 | 3167 | ALTER TABLE {raw:table_name} |
@@ -3005,12 +3171,14 @@ discard block |
||
3005 | 3171 | ) |
3006 | 3172 | ); |
3007 | 3173 | |
3008 | - if ($command_line) |
|
3009 | - echo " done.\n"; |
|
3174 | + if ($command_line) { |
|
3175 | + echo " done.\n"; |
|
3176 | + } |
|
3010 | 3177 | } |
3011 | 3178 | // If this is XML to keep it nice for the user do one table at a time anyway! |
3012 | - if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) |
|
3013 | - return upgradeExit(); |
|
3179 | + if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) { |
|
3180 | + return upgradeExit(); |
|
3181 | + } |
|
3014 | 3182 | } |
3015 | 3183 | |
3016 | 3184 | $prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']]; |
@@ -3039,8 +3207,8 @@ discard block |
||
3039 | 3207 | ); |
3040 | 3208 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
3041 | 3209 | { |
3042 | - if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) |
|
3043 | - $smcFunc['db_query']('', ' |
|
3210 | + if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) { |
|
3211 | + $smcFunc['db_query']('', ' |
|
3044 | 3212 | UPDATE {db_prefix}log_actions |
3045 | 3213 | SET extra = {string:extra} |
3046 | 3214 | WHERE id_action = {int:current_action}', |
@@ -3049,6 +3217,7 @@ discard block |
||
3049 | 3217 | 'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4], |
3050 | 3218 | ) |
3051 | 3219 | ); |
3220 | + } |
|
3052 | 3221 | } |
3053 | 3222 | $smcFunc['db_free_result']($request); |
3054 | 3223 | |
@@ -3070,15 +3239,17 @@ discard block |
||
3070 | 3239 | // First thing's first - did we already do this? |
3071 | 3240 | if (!empty($modSettings['json_done'])) |
3072 | 3241 | { |
3073 | - if ($command_line) |
|
3074 | - return DeleteUpgrade(); |
|
3075 | - else |
|
3076 | - return true; |
|
3242 | + if ($command_line) { |
|
3243 | + return DeleteUpgrade(); |
|
3244 | + } else { |
|
3245 | + return true; |
|
3246 | + } |
|
3077 | 3247 | } |
3078 | 3248 | |
3079 | 3249 | // Done it already - js wise? |
3080 | - if (!empty($_POST['json_done'])) |
|
3081 | - return true; |
|
3250 | + if (!empty($_POST['json_done'])) { |
|
3251 | + return true; |
|
3252 | + } |
|
3082 | 3253 | |
3083 | 3254 | // List of tables affected by this function |
3084 | 3255 | // name => array('key', col1[,col2|true[,col3]]) |
@@ -3110,12 +3281,14 @@ discard block |
||
3110 | 3281 | $upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0]; |
3111 | 3282 | $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); |
3112 | 3283 | |
3113 | - foreach ($keys as $id => $table) |
|
3114 | - if ($id < $_GET['substep']) |
|
3284 | + foreach ($keys as $id => $table) { |
|
3285 | + if ($id < $_GET['substep']) |
|
3115 | 3286 | $upcontext['previous_tables'][] = $table; |
3287 | + } |
|
3116 | 3288 | |
3117 | - if ($command_line) |
|
3118 | - echo 'Converting data from serialize() to json_encode().'; |
|
3289 | + if ($command_line) { |
|
3290 | + echo 'Converting data from serialize() to json_encode().'; |
|
3291 | + } |
|
3119 | 3292 | |
3120 | 3293 | if (!$support_js || isset($_GET['xml'])) |
3121 | 3294 | { |
@@ -3155,8 +3328,9 @@ discard block |
||
3155 | 3328 | |
3156 | 3329 | // Loop through and fix these... |
3157 | 3330 | $new_settings = array(); |
3158 | - if ($command_line) |
|
3159 | - echo "\n" . 'Fixing some settings...'; |
|
3331 | + if ($command_line) { |
|
3332 | + echo "\n" . 'Fixing some settings...'; |
|
3333 | + } |
|
3160 | 3334 | |
3161 | 3335 | foreach ($serialized_settings as $var) |
3162 | 3336 | { |
@@ -3164,22 +3338,24 @@ discard block |
||
3164 | 3338 | { |
3165 | 3339 | // Attempt to unserialize the setting |
3166 | 3340 | $temp = @safe_unserialize($modSettings[$var]); |
3167 | - if (!$temp && $command_line) |
|
3168 | - echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
3169 | - elseif ($temp !== false) |
|
3170 | - $new_settings[$var] = json_encode($temp); |
|
3341 | + if (!$temp && $command_line) { |
|
3342 | + echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
3343 | + } elseif ($temp !== false) { |
|
3344 | + $new_settings[$var] = json_encode($temp); |
|
3345 | + } |
|
3171 | 3346 | } |
3172 | 3347 | } |
3173 | 3348 | |
3174 | 3349 | // Update everything at once |
3175 | - if (!function_exists('cache_put_data')) |
|
3176 | - require_once($sourcedir . '/Load.php'); |
|
3350 | + if (!function_exists('cache_put_data')) { |
|
3351 | + require_once($sourcedir . '/Load.php'); |
|
3352 | + } |
|
3177 | 3353 | updateSettings($new_settings, true); |
3178 | 3354 | |
3179 | - if ($command_line) |
|
3180 | - echo ' done.'; |
|
3181 | - } |
|
3182 | - elseif ($table == 'themes') |
|
3355 | + if ($command_line) { |
|
3356 | + echo ' done.'; |
|
3357 | + } |
|
3358 | + } elseif ($table == 'themes') |
|
3183 | 3359 | { |
3184 | 3360 | // Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point... |
3185 | 3361 | $query = $smcFunc['db_query']('', ' |
@@ -3198,10 +3374,11 @@ discard block |
||
3198 | 3374 | |
3199 | 3375 | if ($command_line) |
3200 | 3376 | { |
3201 | - if ($temp === false) |
|
3202 | - echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
3203 | - else |
|
3204 | - echo "\n" . 'Fixing admin preferences...'; |
|
3377 | + if ($temp === false) { |
|
3378 | + echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
3379 | + } else { |
|
3380 | + echo "\n" . 'Fixing admin preferences...'; |
|
3381 | + } |
|
3205 | 3382 | } |
3206 | 3383 | |
3207 | 3384 | if ($temp !== false) |
@@ -3223,15 +3400,15 @@ discard block |
||
3223 | 3400 | ) |
3224 | 3401 | ); |
3225 | 3402 | |
3226 | - if ($command_line) |
|
3227 | - echo ' done.'; |
|
3403 | + if ($command_line) { |
|
3404 | + echo ' done.'; |
|
3405 | + } |
|
3228 | 3406 | } |
3229 | 3407 | } |
3230 | 3408 | |
3231 | 3409 | $smcFunc['db_free_result']($query); |
3232 | 3410 | } |
3233 | - } |
|
3234 | - else |
|
3411 | + } else |
|
3235 | 3412 | { |
3236 | 3413 | // First item is always the key... |
3237 | 3414 | $key = $info[0]; |
@@ -3242,8 +3419,7 @@ discard block |
||
3242 | 3419 | { |
3243 | 3420 | $col_select = $info[1]; |
3244 | 3421 | $where = ' WHERE ' . $info[1] . ' != {empty}'; |
3245 | - } |
|
3246 | - else |
|
3422 | + } else |
|
3247 | 3423 | { |
3248 | 3424 | $col_select = implode(', ', $info); |
3249 | 3425 | } |
@@ -3276,8 +3452,7 @@ discard block |
||
3276 | 3452 | if ($temp === false && $command_line) |
3277 | 3453 | { |
3278 | 3454 | echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n"; |
3279 | - } |
|
3280 | - else |
|
3455 | + } else |
|
3281 | 3456 | { |
3282 | 3457 | $row[$col] = json_encode($temp); |
3283 | 3458 | |
@@ -3302,16 +3477,18 @@ discard block |
||
3302 | 3477 | } |
3303 | 3478 | } |
3304 | 3479 | |
3305 | - if ($command_line) |
|
3306 | - echo ' done.'; |
|
3480 | + if ($command_line) { |
|
3481 | + echo ' done.'; |
|
3482 | + } |
|
3307 | 3483 | |
3308 | 3484 | // Free up some memory... |
3309 | 3485 | $smcFunc['db_free_result']($query); |
3310 | 3486 | } |
3311 | 3487 | } |
3312 | 3488 | // If this is XML to keep it nice for the user do one table at a time anyway! |
3313 | - if (isset($_GET['xml'])) |
|
3314 | - return upgradeExit(); |
|
3489 | + if (isset($_GET['xml'])) { |
|
3490 | + return upgradeExit(); |
|
3491 | + } |
|
3315 | 3492 | } |
3316 | 3493 | |
3317 | 3494 | if ($command_line) |
@@ -3326,8 +3503,9 @@ discard block |
||
3326 | 3503 | |
3327 | 3504 | $_GET['substep'] = 0; |
3328 | 3505 | // Make sure we move on! |
3329 | - if ($command_line) |
|
3330 | - return DeleteUpgrade(); |
|
3506 | + if ($command_line) { |
|
3507 | + return DeleteUpgrade(); |
|
3508 | + } |
|
3331 | 3509 | |
3332 | 3510 | return true; |
3333 | 3511 | } |
@@ -3384,14 +3562,16 @@ discard block |
||
3384 | 3562 | global $upcontext, $txt, $settings; |
3385 | 3563 | |
3386 | 3564 | // Don't call me twice! |
3387 | - if (!empty($upcontext['chmod_called'])) |
|
3388 | - return; |
|
3565 | + if (!empty($upcontext['chmod_called'])) { |
|
3566 | + return; |
|
3567 | + } |
|
3389 | 3568 | |
3390 | 3569 | $upcontext['chmod_called'] = true; |
3391 | 3570 | |
3392 | 3571 | // Nothing? |
3393 | - if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) |
|
3394 | - return; |
|
3572 | + if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) { |
|
3573 | + return; |
|
3574 | + } |
|
3395 | 3575 | |
3396 | 3576 | // Was it a problem with Windows? |
3397 | 3577 | if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess') |
@@ -3423,11 +3603,12 @@ discard block |
||
3423 | 3603 | content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\'); |
3424 | 3604 | content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');'; |
3425 | 3605 | |
3426 | - if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') |
|
3427 | - echo ' |
|
3606 | + if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') { |
|
3607 | + echo ' |
|
3428 | 3608 | content.write(\'<hr>\n\t\t\t\'); |
3429 | 3609 | content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\'); |
3430 | 3610 | content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');'; |
3611 | + } |
|
3431 | 3612 | |
3432 | 3613 | echo ' |
3433 | 3614 | content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\'); |
@@ -3435,17 +3616,19 @@ discard block |
||
3435 | 3616 | } |
3436 | 3617 | </script>'; |
3437 | 3618 | |
3438 | - if (!empty($upcontext['chmod']['ftp_error'])) |
|
3439 | - echo ' |
|
3619 | + if (!empty($upcontext['chmod']['ftp_error'])) { |
|
3620 | + echo ' |
|
3440 | 3621 | <div class="error_message red"> |
3441 | 3622 | ', $txt['upgrade_ftp_error'], '<br><br> |
3442 | 3623 | <code>', $upcontext['chmod']['ftp_error'], '</code> |
3443 | 3624 | </div> |
3444 | 3625 | <br>'; |
3626 | + } |
|
3445 | 3627 | |
3446 | - if (empty($upcontext['chmod_in_form'])) |
|
3447 | - echo ' |
|
3628 | + if (empty($upcontext['chmod_in_form'])) { |
|
3629 | + echo ' |
|
3448 | 3630 | <form action="', $upcontext['form_url'], '" method="post">'; |
3631 | + } |
|
3449 | 3632 | |
3450 | 3633 | echo ' |
3451 | 3634 | <table width="520" border="0" align="center" style="margin-bottom: 1ex;"> |
@@ -3480,10 +3663,11 @@ discard block |
||
3480 | 3663 | <div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button"></div> |
3481 | 3664 | </div>'; |
3482 | 3665 | |
3483 | - if (empty($upcontext['chmod_in_form'])) |
|
3484 | - echo ' |
|
3666 | + if (empty($upcontext['chmod_in_form'])) { |
|
3667 | + echo ' |
|
3485 | 3668 | </form>'; |
3486 | -} |
|
3669 | + } |
|
3670 | + } |
|
3487 | 3671 | |
3488 | 3672 | function template_upgrade_above() |
3489 | 3673 | { |
@@ -3543,9 +3727,10 @@ discard block |
||
3543 | 3727 | <h2>', $txt['upgrade_progress'], '</h2> |
3544 | 3728 | <ul>'; |
3545 | 3729 | |
3546 | - foreach ($upcontext['steps'] as $num => $step) |
|
3547 | - echo ' |
|
3730 | + foreach ($upcontext['steps'] as $num => $step) { |
|
3731 | + echo ' |
|
3548 | 3732 | <li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
3733 | + } |
|
3549 | 3734 | |
3550 | 3735 | echo ' |
3551 | 3736 | </ul> |
@@ -3558,8 +3743,8 @@ discard block |
||
3558 | 3743 | </div> |
3559 | 3744 | </div>'; |
3560 | 3745 | |
3561 | - if (isset($upcontext['step_progress'])) |
|
3562 | - echo ' |
|
3746 | + if (isset($upcontext['step_progress'])) { |
|
3747 | + echo ' |
|
3563 | 3748 | <br> |
3564 | 3749 | <br> |
3565 | 3750 | <div id="progress_bar_step"> |
@@ -3568,6 +3753,7 @@ discard block |
||
3568 | 3753 | <span>', $txt['upgrade_step_progress'], '</span> |
3569 | 3754 | </div> |
3570 | 3755 | </div>'; |
3756 | + } |
|
3571 | 3757 | |
3572 | 3758 | echo ' |
3573 | 3759 | <div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div> |
@@ -3598,32 +3784,36 @@ discard block |
||
3598 | 3784 | { |
3599 | 3785 | global $upcontext, $txt; |
3600 | 3786 | |
3601 | - if (!empty($upcontext['pause'])) |
|
3602 | - echo ' |
|
3787 | + if (!empty($upcontext['pause'])) { |
|
3788 | + echo ' |
|
3603 | 3789 | <em>', $txt['upgrade_incomplete'], '.</em><br> |
3604 | 3790 | |
3605 | 3791 | <h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2> |
3606 | 3792 | <h3> |
3607 | 3793 | ', $txt['upgrade_paused_overload'], ' |
3608 | 3794 | </h3>'; |
3795 | + } |
|
3609 | 3796 | |
3610 | - if (!empty($upcontext['custom_warning'])) |
|
3611 | - echo ' |
|
3797 | + if (!empty($upcontext['custom_warning'])) { |
|
3798 | + echo ' |
|
3612 | 3799 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
3613 | 3800 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
3614 | 3801 | <strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br> |
3615 | 3802 | <div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div> |
3616 | 3803 | </div>'; |
3804 | + } |
|
3617 | 3805 | |
3618 | 3806 | echo ' |
3619 | 3807 | <div class="righttext" style="margin: 1ex;">'; |
3620 | 3808 | |
3621 | - if (!empty($upcontext['continue'])) |
|
3622 | - echo ' |
|
3809 | + if (!empty($upcontext['continue'])) { |
|
3810 | + echo ' |
|
3623 | 3811 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">'; |
3624 | - if (!empty($upcontext['skip'])) |
|
3625 | - echo ' |
|
3812 | + } |
|
3813 | + if (!empty($upcontext['skip'])) { |
|
3814 | + echo ' |
|
3626 | 3815 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">'; |
3816 | + } |
|
3627 | 3817 | |
3628 | 3818 | echo ' |
3629 | 3819 | </div> |
@@ -3673,11 +3863,12 @@ discard block |
||
3673 | 3863 | echo '<', '?xml version="1.0" encoding="UTF-8"?', '> |
3674 | 3864 | <smf>'; |
3675 | 3865 | |
3676 | - if (!empty($upcontext['get_data'])) |
|
3677 | - foreach ($upcontext['get_data'] as $k => $v) |
|
3866 | + if (!empty($upcontext['get_data'])) { |
|
3867 | + foreach ($upcontext['get_data'] as $k => $v) |
|
3678 | 3868 | echo ' |
3679 | 3869 | <get key="', $k, '">', $v, '</get>'; |
3680 | -} |
|
3870 | + } |
|
3871 | + } |
|
3681 | 3872 | |
3682 | 3873 | function template_xml_below() |
3683 | 3874 | { |
@@ -3718,8 +3909,8 @@ discard block |
||
3718 | 3909 | template_chmod(); |
3719 | 3910 | |
3720 | 3911 | // For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade! |
3721 | - if ($upcontext['is_large_forum']) |
|
3722 | - echo ' |
|
3912 | + if ($upcontext['is_large_forum']) { |
|
3913 | + echo ' |
|
3723 | 3914 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
3724 | 3915 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
3725 | 3916 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -3727,10 +3918,11 @@ discard block |
||
3727 | 3918 | ', $txt['upgrade_warning_lots_data'], ' |
3728 | 3919 | </div> |
3729 | 3920 | </div>'; |
3921 | + } |
|
3730 | 3922 | |
3731 | 3923 | // A warning message? |
3732 | - if (!empty($upcontext['warning'])) |
|
3733 | - echo ' |
|
3924 | + if (!empty($upcontext['warning'])) { |
|
3925 | + echo ' |
|
3734 | 3926 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
3735 | 3927 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
3736 | 3928 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -3738,6 +3930,7 @@ discard block |
||
3738 | 3930 | ', $upcontext['warning'], ' |
3739 | 3931 | </div> |
3740 | 3932 | </div>'; |
3933 | + } |
|
3741 | 3934 | |
3742 | 3935 | // Paths are incorrect? |
3743 | 3936 | echo ' |
@@ -3753,20 +3946,22 @@ discard block |
||
3753 | 3946 | if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600)) |
3754 | 3947 | { |
3755 | 3948 | $ago = time() - $upcontext['started']; |
3756 | - if ($ago < 60) |
|
3757 | - $ago = $ago . ' seconds'; |
|
3758 | - elseif ($ago < 3600) |
|
3759 | - $ago = (int) ($ago / 60) . ' minutes'; |
|
3760 | - else |
|
3761 | - $ago = (int) ($ago / 3600) . ' hours'; |
|
3949 | + if ($ago < 60) { |
|
3950 | + $ago = $ago . ' seconds'; |
|
3951 | + } elseif ($ago < 3600) { |
|
3952 | + $ago = (int) ($ago / 60) . ' minutes'; |
|
3953 | + } else { |
|
3954 | + $ago = (int) ($ago / 3600) . ' hours'; |
|
3955 | + } |
|
3762 | 3956 | |
3763 | 3957 | $active = time() - $upcontext['updated']; |
3764 | - if ($active < 60) |
|
3765 | - $updated = $active . ' seconds'; |
|
3766 | - elseif ($active < 3600) |
|
3767 | - $updated = (int) ($active / 60) . ' minutes'; |
|
3768 | - else |
|
3769 | - $updated = (int) ($active / 3600) . ' hours'; |
|
3958 | + if ($active < 60) { |
|
3959 | + $updated = $active . ' seconds'; |
|
3960 | + } elseif ($active < 3600) { |
|
3961 | + $updated = (int) ($active / 60) . ' minutes'; |
|
3962 | + } else { |
|
3963 | + $updated = (int) ($active / 3600) . ' hours'; |
|
3964 | + } |
|
3770 | 3965 | |
3771 | 3966 | echo ' |
3772 | 3967 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
@@ -3775,16 +3970,18 @@ discard block |
||
3775 | 3970 | <div style="padding-left: 6ex;"> |
3776 | 3971 | "', $upcontext['user']['name'], '" has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.'; |
3777 | 3972 | |
3778 | - if ($active < 600) |
|
3779 | - echo ' |
|
3973 | + if ($active < 600) { |
|
3974 | + echo ' |
|
3780 | 3975 | ', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], ''; |
3976 | + } |
|
3781 | 3977 | |
3782 | - if ($active > $upcontext['inactive_timeout']) |
|
3783 | - echo ' |
|
3978 | + if ($active > $upcontext['inactive_timeout']) { |
|
3979 | + echo ' |
|
3784 | 3980 | <br><br>',$txt['upgrade_run'], ''; |
3785 | - else |
|
3786 | - echo ' |
|
3981 | + } else { |
|
3982 | + echo ' |
|
3787 | 3983 | <br><br>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!'); |
3984 | + } |
|
3788 | 3985 | |
3789 | 3986 | echo ' |
3790 | 3987 | </div> |
@@ -3800,9 +3997,10 @@ discard block |
||
3800 | 3997 | <td> |
3801 | 3998 | <input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>'; |
3802 | 3999 | |
3803 | - if (!empty($upcontext['username_incorrect'])) |
|
3804 | - echo ' |
|
4000 | + if (!empty($upcontext['username_incorrect'])) { |
|
4001 | + echo ' |
|
3805 | 4002 | <div class="smalltext" style="color: red;">', $txt['upgrade_wrong_username'], '</div>'; |
4003 | + } |
|
3806 | 4004 | |
3807 | 4005 | echo ' |
3808 | 4006 | </td> |
@@ -3813,9 +4011,10 @@ discard block |
||
3813 | 4011 | <input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '> |
3814 | 4012 | <input type="hidden" name="hash_passwrd" value="">'; |
3815 | 4013 | |
3816 | - if (!empty($upcontext['password_failed'])) |
|
3817 | - echo ' |
|
4014 | + if (!empty($upcontext['password_failed'])) { |
|
4015 | + echo ' |
|
3818 | 4016 | <div class="smalltext" style="color: red;">', $txt['upgrade_wrong_password'], '</div>'; |
4017 | + } |
|
3819 | 4018 | |
3820 | 4019 | echo ' |
3821 | 4020 | </td> |
@@ -3886,8 +4085,8 @@ discard block |
||
3886 | 4085 | <form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">'; |
3887 | 4086 | |
3888 | 4087 | // Warning message? |
3889 | - if (!empty($upcontext['upgrade_options_warning'])) |
|
3890 | - echo ' |
|
4088 | + if (!empty($upcontext['upgrade_options_warning'])) { |
|
4089 | + echo ' |
|
3891 | 4090 | <div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
3892 | 4091 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
3893 | 4092 | <strong style="text-decoration: underline;">Warning!</strong><br> |
@@ -3895,6 +4094,7 @@ discard block |
||
3895 | 4094 | ', $upcontext['upgrade_options_warning'], ' |
3896 | 4095 | </div> |
3897 | 4096 | </div>'; |
4097 | + } |
|
3898 | 4098 | |
3899 | 4099 | echo ' |
3900 | 4100 | <table> |
@@ -3937,8 +4137,8 @@ discard block |
||
3937 | 4137 | </td> |
3938 | 4138 | </tr>'; |
3939 | 4139 | |
3940 | - if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) |
|
3941 | - echo ' |
|
4140 | + if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) { |
|
4141 | + echo ' |
|
3942 | 4142 | <tr valign="top"> |
3943 | 4143 | <td width="2%"> |
3944 | 4144 | <input type="checkbox" name="delete_karma" id="delete_karma" value="1"> |
@@ -3947,6 +4147,7 @@ discard block |
||
3947 | 4147 | <label for="delete_karma">', $txt['upgrade_delete_karma'], '</label> |
3948 | 4148 | </td> |
3949 | 4149 | </tr>'; |
4150 | + } |
|
3950 | 4151 | |
3951 | 4152 | echo ' |
3952 | 4153 | <tr valign="top"> |
@@ -3984,10 +4185,11 @@ discard block |
||
3984 | 4185 | </div>'; |
3985 | 4186 | |
3986 | 4187 | // Dont any tables so far? |
3987 | - if (!empty($upcontext['previous_tables'])) |
|
3988 | - foreach ($upcontext['previous_tables'] as $table) |
|
4188 | + if (!empty($upcontext['previous_tables'])) { |
|
4189 | + foreach ($upcontext['previous_tables'] as $table) |
|
3989 | 4190 | echo ' |
3990 | 4191 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
4192 | + } |
|
3991 | 4193 | |
3992 | 4194 | echo ' |
3993 | 4195 | <h3 id="current_tab_div">', $txt['upgrade_current_table'], ' "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3> |
@@ -4024,12 +4226,13 @@ discard block |
||
4024 | 4226 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
4025 | 4227 | |
4026 | 4228 | // If debug flood the screen. |
4027 | - if ($is_debug) |
|
4028 | - echo ' |
|
4229 | + if ($is_debug) { |
|
4230 | + echo ' |
|
4029 | 4231 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
4030 | 4232 | |
4031 | 4233 | if (document.getElementById(\'debug_section\').scrollHeight) |
4032 | 4234 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
4235 | + } |
|
4033 | 4236 | |
4034 | 4237 | echo ' |
4035 | 4238 | // Get the next update... |
@@ -4062,8 +4265,9 @@ discard block |
||
4062 | 4265 | { |
4063 | 4266 | global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt; |
4064 | 4267 | |
4065 | - if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) |
|
4066 | - $is_debug = true; |
|
4268 | + if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) { |
|
4269 | + $is_debug = true; |
|
4270 | + } |
|
4067 | 4271 | |
4068 | 4272 | echo ' |
4069 | 4273 | <h3>', $txt['upgrade_db_changes'], '</h3> |
@@ -4078,8 +4282,9 @@ discard block |
||
4078 | 4282 | { |
4079 | 4283 | foreach ($upcontext['actioned_items'] as $num => $item) |
4080 | 4284 | { |
4081 | - if ($num != 0) |
|
4082 | - echo ' Successful!'; |
|
4285 | + if ($num != 0) { |
|
4286 | + echo ' Successful!'; |
|
4287 | + } |
|
4083 | 4288 | echo '<br>' . $item; |
4084 | 4289 | } |
4085 | 4290 | if (!empty($upcontext['changes_complete'])) |
@@ -4092,28 +4297,32 @@ discard block |
||
4092 | 4297 | $seconds = intval($active % 60); |
4093 | 4298 | |
4094 | 4299 | $totalTime = ''; |
4095 | - if ($hours > 0) |
|
4096 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
4097 | - if ($minutes > 0) |
|
4098 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
4099 | - if ($seconds > 0) |
|
4100 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
4300 | + if ($hours > 0) { |
|
4301 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
4302 | + } |
|
4303 | + if ($minutes > 0) { |
|
4304 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
4305 | + } |
|
4306 | + if ($seconds > 0) { |
|
4307 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
4308 | + } |
|
4101 | 4309 | } |
4102 | 4310 | |
4103 | - if ($is_debug && !empty($totalTime)) |
|
4104 | - echo ' Successful! Completed in ', $totalTime, '<br><br>'; |
|
4105 | - else |
|
4106 | - echo ' Successful!<br><br>'; |
|
4311 | + if ($is_debug && !empty($totalTime)) { |
|
4312 | + echo ' Successful! Completed in ', $totalTime, '<br><br>'; |
|
4313 | + } else { |
|
4314 | + echo ' Successful!<br><br>'; |
|
4315 | + } |
|
4107 | 4316 | |
4108 | 4317 | echo '<span id="commess" style="font-weight: bold;">', $txt['upgrade_db_complete'], '</span><br>'; |
4109 | 4318 | } |
4110 | - } |
|
4111 | - else |
|
4319 | + } else |
|
4112 | 4320 | { |
4113 | 4321 | // Tell them how many files we have in total. |
4114 | - if ($upcontext['file_count'] > 1) |
|
4115 | - echo ' |
|
4322 | + if ($upcontext['file_count'] > 1) { |
|
4323 | + echo ' |
|
4116 | 4324 | <strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>'; |
4325 | + } |
|
4117 | 4326 | |
4118 | 4327 | echo ' |
4119 | 4328 | <h3 id="info2"><strong>', $txt['upgrade_executing'], '</strong> "<span id="cur_item_name">', $upcontext['current_item_name'], '</span>" (<span id="item_num">', $upcontext['current_item_num'], '</span> ', $txt['upgrade_of'], ' <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3> |
@@ -4129,19 +4338,23 @@ discard block |
||
4129 | 4338 | $seconds = intval($active % 60); |
4130 | 4339 | |
4131 | 4340 | $totalTime = ''; |
4132 | - if ($hours > 0) |
|
4133 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
4134 | - if ($minutes > 0) |
|
4135 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
4136 | - if ($seconds > 0) |
|
4137 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
4341 | + if ($hours > 0) { |
|
4342 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
4343 | + } |
|
4344 | + if ($minutes > 0) { |
|
4345 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
4346 | + } |
|
4347 | + if ($seconds > 0) { |
|
4348 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
4349 | + } |
|
4138 | 4350 | } |
4139 | 4351 | |
4140 | 4352 | echo ' |
4141 | 4353 | <br><span id="upgradeCompleted">'; |
4142 | 4354 | |
4143 | - if (!empty($totalTime)) |
|
4144 | - echo 'Completed in ', $totalTime, '<br>'; |
|
4355 | + if (!empty($totalTime)) { |
|
4356 | + echo 'Completed in ', $totalTime, '<br>'; |
|
4357 | + } |
|
4145 | 4358 | |
4146 | 4359 | echo '</span> |
4147 | 4360 | <div id="debug_section" style="height: 59px; overflow: auto;"> |
@@ -4178,9 +4391,10 @@ discard block |
||
4178 | 4391 | var getData = ""; |
4179 | 4392 | var debugItems = ', $upcontext['debug_items'], ';'; |
4180 | 4393 | |
4181 | - if ($is_debug) |
|
4182 | - echo ' |
|
4394 | + if ($is_debug) { |
|
4395 | + echo ' |
|
4183 | 4396 | var upgradeStartTime = ' . $upcontext['started'] . ';'; |
4397 | + } |
|
4184 | 4398 | |
4185 | 4399 | echo ' |
4186 | 4400 | function getNextItem() |
@@ -4220,9 +4434,10 @@ discard block |
||
4220 | 4434 | document.getElementById("error_block").style.display = ""; |
4221 | 4435 | setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));'; |
4222 | 4436 | |
4223 | - if ($is_debug) |
|
4224 | - echo ' |
|
4437 | + if ($is_debug) { |
|
4438 | + echo ' |
|
4225 | 4439 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
4440 | + } |
|
4226 | 4441 | |
4227 | 4442 | echo ' |
4228 | 4443 | } |
@@ -4243,9 +4458,10 @@ discard block |
||
4243 | 4458 | document.getElementById("error_block").style.display = ""; |
4244 | 4459 | setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);'; |
4245 | 4460 | |
4246 | - if ($is_debug) |
|
4247 | - echo ' |
|
4461 | + if ($is_debug) { |
|
4462 | + echo ' |
|
4248 | 4463 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
4464 | + } |
|
4249 | 4465 | |
4250 | 4466 | echo ' |
4251 | 4467 | } |
@@ -4304,8 +4520,8 @@ discard block |
||
4304 | 4520 | if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ') |
4305 | 4521 | {'; |
4306 | 4522 | |
4307 | - if ($is_debug) |
|
4308 | - echo ' |
|
4523 | + if ($is_debug) { |
|
4524 | + echo ' |
|
4309 | 4525 | document.getElementById(\'debug_section\').style.display = "none"; |
4310 | 4526 | |
4311 | 4527 | var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue); |
@@ -4323,6 +4539,7 @@ discard block |
||
4323 | 4539 | totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : ""); |
4324 | 4540 | |
4325 | 4541 | setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);'; |
4542 | + } |
|
4326 | 4543 | |
4327 | 4544 | echo ' |
4328 | 4545 | |
@@ -4330,9 +4547,10 @@ discard block |
||
4330 | 4547 | document.getElementById(\'contbutt\').disabled = 0; |
4331 | 4548 | document.getElementById(\'database_done\').value = 1;'; |
4332 | 4549 | |
4333 | - if ($upcontext['file_count'] > 1) |
|
4334 | - echo ' |
|
4550 | + if ($upcontext['file_count'] > 1) { |
|
4551 | + echo ' |
|
4335 | 4552 | document.getElementById(\'info1\').style.display = "none";'; |
4553 | + } |
|
4336 | 4554 | |
4337 | 4555 | echo ' |
4338 | 4556 | document.getElementById(\'info2\').style.display = "none"; |
@@ -4345,9 +4563,10 @@ discard block |
||
4345 | 4563 | lastItem = 0; |
4346 | 4564 | prevFile = curFile;'; |
4347 | 4565 | |
4348 | - if ($is_debug) |
|
4349 | - echo ' |
|
4566 | + if ($is_debug) { |
|
4567 | + echo ' |
|
4350 | 4568 | setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');'; |
4569 | + } |
|
4351 | 4570 | |
4352 | 4571 | echo ' |
4353 | 4572 | getNextItem(); |
@@ -4355,8 +4574,8 @@ discard block |
||
4355 | 4574 | }'; |
4356 | 4575 | |
4357 | 4576 | // If debug scroll the screen. |
4358 | - if ($is_debug) |
|
4359 | - echo ' |
|
4577 | + if ($is_debug) { |
|
4578 | + echo ' |
|
4360 | 4579 | if (iLastSubStepProgress == -1) |
4361 | 4580 | { |
4362 | 4581 | // Give it consistent dots. |
@@ -4375,6 +4594,7 @@ discard block |
||
4375 | 4594 | |
4376 | 4595 | if (document.getElementById(\'debug_section\').scrollHeight) |
4377 | 4596 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
4597 | + } |
|
4378 | 4598 | |
4379 | 4599 | echo ' |
4380 | 4600 | // Update the page. |
@@ -4435,9 +4655,10 @@ discard block |
||
4435 | 4655 | }'; |
4436 | 4656 | |
4437 | 4657 | // Start things off assuming we've not errored. |
4438 | - if (empty($upcontext['error_message'])) |
|
4439 | - echo ' |
|
4658 | + if (empty($upcontext['error_message'])) { |
|
4659 | + echo ' |
|
4440 | 4660 | getNextItem();'; |
4661 | + } |
|
4441 | 4662 | |
4442 | 4663 | echo ' |
4443 | 4664 | //# sourceURL=dynamicScript-dbch.js |
@@ -4455,18 +4676,21 @@ discard block |
||
4455 | 4676 | <item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item> |
4456 | 4677 | <debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>'; |
4457 | 4678 | |
4458 | - if (!empty($upcontext['error_message'])) |
|
4459 | - echo ' |
|
4679 | + if (!empty($upcontext['error_message'])) { |
|
4680 | + echo ' |
|
4460 | 4681 | <error>', $upcontext['error_message'], '</error>'; |
4682 | + } |
|
4461 | 4683 | |
4462 | - if (!empty($upcontext['error_string'])) |
|
4463 | - echo ' |
|
4684 | + if (!empty($upcontext['error_string'])) { |
|
4685 | + echo ' |
|
4464 | 4686 | <sql>', $upcontext['error_string'], '</sql>'; |
4687 | + } |
|
4465 | 4688 | |
4466 | - if ($is_debug) |
|
4467 | - echo ' |
|
4689 | + if ($is_debug) { |
|
4690 | + echo ' |
|
4468 | 4691 | <curtime>', time(), '</curtime>'; |
4469 | -} |
|
4692 | + } |
|
4693 | + } |
|
4470 | 4694 | |
4471 | 4695 | // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications.... |
4472 | 4696 | function template_convert_utf8() |
@@ -4485,18 +4709,20 @@ discard block |
||
4485 | 4709 | </div>'; |
4486 | 4710 | |
4487 | 4711 | // Done any tables so far? |
4488 | - if (!empty($upcontext['previous_tables'])) |
|
4489 | - foreach ($upcontext['previous_tables'] as $table) |
|
4712 | + if (!empty($upcontext['previous_tables'])) { |
|
4713 | + foreach ($upcontext['previous_tables'] as $table) |
|
4490 | 4714 | echo ' |
4491 | 4715 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
4716 | + } |
|
4492 | 4717 | |
4493 | 4718 | echo ' |
4494 | 4719 | <h3 id="current_tab_div">', $txt['upgrade_current_table'], ' "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3>'; |
4495 | 4720 | |
4496 | 4721 | // If we dropped their index, let's let them know |
4497 | - if ($upcontext['dropping_index']) |
|
4498 | - echo ' |
|
4722 | + if ($upcontext['dropping_index']) { |
|
4723 | + echo ' |
|
4499 | 4724 | <br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_fulltext'], '</span>'; |
4725 | + } |
|
4500 | 4726 | |
4501 | 4727 | // Completion notification |
4502 | 4728 | echo ' |
@@ -4533,12 +4759,13 @@ discard block |
||
4533 | 4759 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
4534 | 4760 | |
4535 | 4761 | // If debug flood the screen. |
4536 | - if ($is_debug) |
|
4537 | - echo ' |
|
4762 | + if ($is_debug) { |
|
4763 | + echo ' |
|
4538 | 4764 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
4539 | 4765 | |
4540 | 4766 | if (document.getElementById(\'debug_section\').scrollHeight) |
4541 | 4767 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
4768 | + } |
|
4542 | 4769 | |
4543 | 4770 | echo ' |
4544 | 4771 | // Get the next update... |
@@ -4586,19 +4813,21 @@ discard block |
||
4586 | 4813 | </div>'; |
4587 | 4814 | |
4588 | 4815 | // Dont any tables so far? |
4589 | - if (!empty($upcontext['previous_tables'])) |
|
4590 | - foreach ($upcontext['previous_tables'] as $table) |
|
4816 | + if (!empty($upcontext['previous_tables'])) { |
|
4817 | + foreach ($upcontext['previous_tables'] as $table) |
|
4591 | 4818 | echo ' |
4592 | 4819 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
4820 | + } |
|
4593 | 4821 | |
4594 | 4822 | echo ' |
4595 | 4823 | <h3 id="current_tab_div">', $txt['upgrade_current_table'], ' "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3> |
4596 | 4824 | <br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</span>'; |
4597 | 4825 | |
4598 | 4826 | // Try to make sure substep was reset. |
4599 | - if ($upcontext['cur_table_num'] == $upcontext['table_count']) |
|
4600 | - echo ' |
|
4827 | + if ($upcontext['cur_table_num'] == $upcontext['table_count']) { |
|
4828 | + echo ' |
|
4601 | 4829 | <input type="hidden" name="substep" id="substep" value="0">'; |
4830 | + } |
|
4602 | 4831 | |
4603 | 4832 | // Continue please! |
4604 | 4833 | $upcontext['continue'] = $support_js ? 2 : 1; |
@@ -4631,12 +4860,13 @@ discard block |
||
4631 | 4860 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
4632 | 4861 | |
4633 | 4862 | // If debug flood the screen. |
4634 | - if ($is_debug) |
|
4635 | - echo ' |
|
4863 | + if ($is_debug) { |
|
4864 | + echo ' |
|
4636 | 4865 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
4637 | 4866 | |
4638 | 4867 | if (document.getElementById(\'debug_section\').scrollHeight) |
4639 | 4868 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
4869 | + } |
|
4640 | 4870 | |
4641 | 4871 | echo ' |
4642 | 4872 | // Get the next update... |
@@ -4672,8 +4902,8 @@ discard block |
||
4672 | 4902 | <h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>. ', $txt['upgrade_done3'], '</h3> |
4673 | 4903 | <form action="', $boardurl, '/index.php">'; |
4674 | 4904 | |
4675 | - if (!empty($upcontext['can_delete_script'])) |
|
4676 | - echo ' |
|
4905 | + if (!empty($upcontext['can_delete_script'])) { |
|
4906 | + echo ' |
|
4677 | 4907 | <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '</label> <em>', $txt['upgrade_delete_server'], '</em> |
4678 | 4908 | <script> |
4679 | 4909 | function doTheDelete(theCheck) |
@@ -4685,6 +4915,7 @@ discard block |
||
4685 | 4915 | } |
4686 | 4916 | </script> |
4687 | 4917 | <img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>'; |
4918 | + } |
|
4688 | 4919 | |
4689 | 4920 | $active = time() - $upcontext['started']; |
4690 | 4921 | $hours = floor($active / 3600); |
@@ -4694,16 +4925,20 @@ discard block |
||
4694 | 4925 | if ($is_debug) |
4695 | 4926 | { |
4696 | 4927 | $totalTime = ''; |
4697 | - if ($hours > 0) |
|
4698 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
4699 | - if ($minutes > 0) |
|
4700 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
4701 | - if ($seconds > 0) |
|
4702 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
4928 | + if ($hours > 0) { |
|
4929 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
4930 | + } |
|
4931 | + if ($minutes > 0) { |
|
4932 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
4933 | + } |
|
4934 | + if ($seconds > 0) { |
|
4935 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
4936 | + } |
|
4703 | 4937 | } |
4704 | 4938 | |
4705 | - if ($is_debug && !empty($totalTime)) |
|
4706 | - echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>'; |
|
4939 | + if ($is_debug && !empty($totalTime)) { |
|
4940 | + echo '<br> ', $txt['upgrade_completed_time'], ' ', $totalTime, '<br><br>'; |
|
4941 | + } |
|
4707 | 4942 | |
4708 | 4943 | echo '<br> |
4709 | 4944 | ', sprintf($txt['upgrade_problems'], 'http://simplemachines.org'), '<br> |
@@ -4730,8 +4965,9 @@ discard block |
||
4730 | 4965 | |
4731 | 4966 | $current_substep = $_GET['substep']; |
4732 | 4967 | |
4733 | - if (empty($_GET['a'])) |
|
4734 | - $_GET['a'] = 0; |
|
4968 | + if (empty($_GET['a'])) { |
|
4969 | + $_GET['a'] = 0; |
|
4970 | + } |
|
4735 | 4971 | $step_progress['name'] = 'Converting ips'; |
4736 | 4972 | $step_progress['current'] = $_GET['a']; |
4737 | 4973 | |
@@ -4774,16 +5010,19 @@ discard block |
||
4774 | 5010 | 'empty' => '', |
4775 | 5011 | 'limit' => $limit, |
4776 | 5012 | )); |
4777 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
4778 | - $arIp[] = $row[$oldCol]; |
|
5013 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
5014 | + $arIp[] = $row[$oldCol]; |
|
5015 | + } |
|
4779 | 5016 | $smcFunc['db_free_result']($request); |
4780 | 5017 | |
4781 | 5018 | // Special case, null ip could keep us in a loop. |
4782 | - if (is_null($arIp[0])) |
|
4783 | - unset($arIp[0]); |
|
5019 | + if (is_null($arIp[0])) { |
|
5020 | + unset($arIp[0]); |
|
5021 | + } |
|
4784 | 5022 | |
4785 | - if (empty($arIp)) |
|
4786 | - $is_done = true; |
|
5023 | + if (empty($arIp)) { |
|
5024 | + $is_done = true; |
|
5025 | + } |
|
4787 | 5026 | |
4788 | 5027 | $updates = array(); |
4789 | 5028 | $cases = array(); |
@@ -4792,16 +5031,18 @@ discard block |
||
4792 | 5031 | { |
4793 | 5032 | $arIp[$i] = trim($arIp[$i]); |
4794 | 5033 | |
4795 | - if (empty($arIp[$i])) |
|
4796 | - continue; |
|
5034 | + if (empty($arIp[$i])) { |
|
5035 | + continue; |
|
5036 | + } |
|
4797 | 5037 | |
4798 | 5038 | $updates['ip' . $i] = $arIp[$i]; |
4799 | 5039 | $cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}'; |
4800 | 5040 | |
4801 | 5041 | if ($setSize > 0 && $i % $setSize === 0) |
4802 | 5042 | { |
4803 | - if (count($updates) == 1) |
|
4804 | - continue; |
|
5043 | + if (count($updates) == 1) { |
|
5044 | + continue; |
|
5045 | + } |
|
4805 | 5046 | |
4806 | 5047 | $updates['whereSet'] = array_values($updates); |
4807 | 5048 | $smcFunc['db_query']('', ' |
@@ -4835,8 +5076,7 @@ discard block |
||
4835 | 5076 | 'ip' => $ip |
4836 | 5077 | )); |
4837 | 5078 | } |
4838 | - } |
|
4839 | - else |
|
5079 | + } else |
|
4840 | 5080 | { |
4841 | 5081 | $updates['whereSet'] = array_values($updates); |
4842 | 5082 | $smcFunc['db_query']('', ' |
@@ -4850,9 +5090,9 @@ discard block |
||
4850 | 5090 | $updates |
4851 | 5091 | ); |
4852 | 5092 | } |
5093 | + } else { |
|
5094 | + $is_done = true; |
|
4853 | 5095 | } |
4854 | - else |
|
4855 | - $is_done = true; |
|
4856 | 5096 | |
4857 | 5097 | $_GET['a'] += $limit; |
4858 | 5098 | $step_progress['current'] = $_GET['a']; |
@@ -4878,10 +5118,11 @@ discard block |
||
4878 | 5118 | |
4879 | 5119 | $columns = $smcFunc['db_list_columns']($targetTable, true); |
4880 | 5120 | |
4881 | - if (isset($columns[$column])) |
|
4882 | - return $columns[$column]; |
|
4883 | - else |
|
4884 | - return null; |
|
4885 | -} |
|
5121 | + if (isset($columns[$column])) { |
|
5122 | + return $columns[$column]; |
|
5123 | + } else { |
|
5124 | + return null; |
|
5125 | + } |
|
5126 | + } |
|
4886 | 5127 | |
4887 | 5128 | ?> |
4888 | 5129 | \ No newline at end of file |